# 「見た目」ジャンル <% category = 'looks' require 'smalruby_editor' color = SmalrubyEditor::COLORS[category.to_sym] %> # [ ]と( )秒言う # [ ]と言う # [ ]と( )秒考える # [ ]と考える <% [ ['say', '言う'], ['think', '考える'], ].each do |method, label_suffix| %> <% n = "#{category}_#{method}_second" %> Blockly.Blocks['<%= n %>'] = init: ()-> @setHelpUrl('') @setColour(<%= color %>) @interpolateMsg('%1と%2秒<%= label_suffix %>', ['TEXT', null, Blockly.ALIGN_RIGHT], ['SEC', ['Number'], Blockly.ALIGN_RIGHT], Blockly.ALIGN_RIGHT) @setInputsInline(true) @setPreviousStatement(true) @setNextStatement(true) @setTooltip('') Blockly.Ruby['<%= n %>'] = (block) -> sec = Blockly.Ruby.valueToCode(@, 'SEC', Blockly.Ruby.ORDER_NONE) || '0' text = Blockly.Ruby.valueToCode(@, 'TEXT', Blockly.Ruby.ORDER_NONE) || Blockly.Ruby.quote_('') Blockly.Ruby.characterMethodCall_('<%= method %>', "message: #{text}, second: #{sec}") <% n = "#{category}_#{method}" %> Blockly.Blocks['<%= n %>'] = init: ()-> @setHelpUrl('') @setColour(<%= color %>) @interpolateMsg('%1と<%= label_suffix %>', ['TEXT', null, Blockly.ALIGN_RIGHT], Blockly.ALIGN_RIGHT) @setInputsInline(true) @setPreviousStatement(true) @setNextStatement(true) @setTooltip('') Blockly.Ruby['<%= n %>'] = (block) -> text = Blockly.Ruby.valueToCode(@, 'TEXT', Blockly.Ruby.ORDER_NONE) || Blockly.Ruby.quote_('') Blockly.Ruby.characterMethodCall_('<%= method %>', "message: #{text}") <% end %> # 表示する # 隠す <% [ ['show', '表示する', 'true'], ['hide', '隠す', 'false'], ].each do |suffix, label, val| n = "#{category}_#{suffix}" %> Blockly.Blocks['<%= n %>'] = init: ()-> @setHelpUrl('') @setColour(<%= color %>) @appendDummyInput().appendField('<%= label %>') @setPreviousStatement(true) @setNextStatement(true) @setTooltip('') Blockly.Ruby['<%= n %>'] = (block) -> Blockly.Ruby.characterSetVariable_('visible', '<%= val %>') <% end %> # 消滅する <% n = "#{category}_vanish" %> Blockly.Blocks['<%= n %>'] = init: ()-> @setHelpUrl('') @setColour(<%= color %>) @appendDummyInput().appendField('消滅する') @setPreviousStatement(true) @setNextStatement(true) @setTooltip('') Blockly.Ruby['<%= n %>'] = (block) -> Blockly.Ruby.characterMethodCall_('vanish') # 大きさを( )%ずつ変える # 大きさを( )%にする <% [ ['change_scale_by', 'ずつ変える', '+='], ['set_scale', 'にする', '='], ].each do |suffix, label_suffix, operator| n = "#{category}_#{suffix}" %> Blockly.Blocks['<%= n %>'] = init: ()-> @setHelpUrl('') @setColour(<%= color %>) @interpolateMsg('大きさを%1%<%= label_suffix %>', ['SCALE', ['Number'], Blockly.ALIGN_RIGHT], Blockly.ALIGN_RIGHT) @setInputsInline(true) @setPreviousStatement(true) @setNextStatement(true) @setTooltip('') Blockly.Ruby['<%= n %>'] = (block) -> scale = Blockly.Ruby.valueToCode(@, 'SCALE', Blockly.Ruby.ORDER_NONE) || '0' scale = parseInt(scale) / 100 "self.scale <%= operator %> #{scale}\n" <% end %> # 変数:大きさ <% n = "#{category}_self_scale" %> Blockly.Blocks['<%= n %>'] = init: ()-> @setHelpUrl('') @setColour(<%= color %>) @appendDummyInput(). appendField('大きさ') @setOutput(true, 'Number') @setTooltip('') Blockly.Ruby['<%= n %>'] = (block) -> ['scale', Blockly.Ruby.ORDER_ATOMIC] # [▼プリセット画像] <% n = "#{category}_preset_images" %> Blockly.Blocks['<%= n %>'] = init: ()-> images = [ ['車1', 'car1.png'], ['車2', 'car2.png'], ['車3', 'car3.png'], ['車4', 'car4.png'], ['ボール1', 'ball1.png'], ['ボール2', 'ball2.png'], ['ボール3', 'ball3.png'], ['ボール4', 'ball4.png'], ['ボール5', 'ball5.png'], ['ボール6', 'ball6.png'], ['猫1', 'cat1.png'], ['猫2', 'cat2.png'], ['猫3', 'cat3.png'], ['かえる1', 'frog1.png'], ['コウガ リュウ1', 'ryu1.png'], ['コウガ リュウ2', 'ryu2.png'], ['イタチのタイチ', 'taichi1.png'], ['イタチのタイチ', 'taichi2.png'], ] @setHelpUrl('') @setColour(<%= color %>) @appendDummyInput().appendField(new Blockly.FieldDropdown(images), 'NAME') @setOutput(true, 'String') @setTooltip('') Blockly.Ruby['<%= n %>'] = (block) -> code = Blockly.Ruby.quote_(@getFieldValue('NAME')) [code, Blockly.Ruby.ORDER_ATOMIC]