smalruby-editor 0.0.12 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of smalruby-editor might be problematic. Click here for more details.

Files changed (179) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -0
  3. data/.travis.yml +2 -0
  4. data/LEGAL +32 -0
  5. data/Rakefile +1 -1
  6. data/app/assets/demos/default.xml +126 -0
  7. data/app/assets/demos/rgb_led_anode.xml +83 -0
  8. data/app/assets/images/favicon.ico +0 -0
  9. data/app/assets/javascripts/application.js +18 -1
  10. data/app/assets/javascripts/block_mode.js.coffee.erb +10 -0
  11. data/app/assets/javascripts/blocks/blockly.js.coffee.erb +34 -0
  12. data/app/assets/javascripts/blocks/character.js.coffee.erb +76 -0
  13. data/app/assets/javascripts/blocks/control.js.coffee.erb +180 -0
  14. data/app/assets/javascripts/blocks/data.js.coffee.erb +6 -0
  15. data/app/assets/javascripts/blocks/etc.js.coffee.erb +6 -0
  16. data/app/assets/javascripts/blocks/events.js.coffee.erb +82 -0
  17. data/app/assets/javascripts/blocks/hardware.js.coffee.erb +313 -0
  18. data/app/assets/javascripts/blocks/looks.js.coffee.erb +163 -0
  19. data/app/assets/javascripts/blocks/motion.js.coffee.erb +297 -0
  20. data/app/assets/javascripts/blocks/operators.js.coffee.erb +279 -0
  21. data/app/assets/javascripts/blocks/pen.js.coffee.erb +6 -0
  22. data/app/assets/javascripts/blocks/ruby.js.coffee.erb +74 -0
  23. data/app/assets/javascripts/blocks/sensing.js.coffee.erb +241 -0
  24. data/app/assets/javascripts/blocks/sound.js.coffee.erb +75 -0
  25. data/{public/favicon.ico → app/assets/javascripts/collections/.keep} +0 -0
  26. data/app/assets/javascripts/collections/character_set.js.coffee +12 -0
  27. data/app/assets/javascripts/generators/ruby.js.coffee.erb +188 -0
  28. data/app/assets/javascripts/models/.keep +0 -0
  29. data/app/assets/javascripts/models/character.js.coffee +66 -0
  30. data/app/assets/javascripts/models/scene.js.coffee +5 -0
  31. data/app/assets/javascripts/models/source_code.js.coffee +64 -0
  32. data/app/assets/javascripts/routers/.keep +0 -0
  33. data/app/assets/javascripts/ruby_mode.js.coffee.erb +12 -0
  34. data/app/assets/javascripts/smalruby.js.coffee +97 -0
  35. data/app/assets/javascripts/views/.keep +0 -0
  36. data/app/assets/javascripts/views/character_modal_view.js.coffee +148 -0
  37. data/app/assets/javascripts/views/character_selector_view.js.coffee +109 -0
  38. data/app/assets/javascripts/views/main_menu_view.js.coffee +264 -0
  39. data/app/assets/stylesheets/editor.css.scss +318 -2
  40. data/app/assets/stylesheets/toolbox.css.scss.erb +62 -0
  41. data/app/assets/templates/.keep +0 -0
  42. data/app/controllers/application_controller.rb +19 -0
  43. data/app/controllers/editor_controller.rb +4 -0
  44. data/app/controllers/source_codes_controller.rb +8 -2
  45. data/app/helpers/application_helper.rb +1 -0
  46. data/app/helpers/editor_helper.rb +46 -0
  47. data/app/models/source_code.rb +49 -6
  48. data/app/views/editor/_block_tab.html.haml +53 -0
  49. data/app/views/editor/_character_modal.html.haml +53 -0
  50. data/app/views/editor/_toolbox.html.haml +384 -0
  51. data/app/views/editor/demo.html.erb +16 -0
  52. data/app/views/editor/index.html.haml +60 -0
  53. data/app/views/layouts/application.html.erb +7 -0
  54. data/config/application.rb +1 -0
  55. data/config/initializers/teaspoon.rb +79 -0
  56. data/config/routes.rb +4 -0
  57. data/lib/smalruby_editor/version.rb +1 -1
  58. data/lib/tasks/gem.rake +7 -4
  59. data/lib/tasks/release.rake +43 -0
  60. data/public/apple-touch-icon.png +0 -0
  61. data/public/blockly/media/1x1.gif +0 -0
  62. data/public/blockly/media/click.mp3 +0 -0
  63. data/public/blockly/media/click.ogg +0 -0
  64. data/public/blockly/media/click.wav +0 -0
  65. data/public/blockly/media/delete.mp3 +0 -0
  66. data/public/blockly/media/delete.ogg +0 -0
  67. data/public/blockly/media/delete.wav +0 -0
  68. data/public/blockly/media/handclosed.cur +0 -0
  69. data/public/blockly/media/handopen.cur +0 -0
  70. data/public/blockly/media/quote0.png +0 -0
  71. data/public/blockly/media/quote1.png +0 -0
  72. data/public/blockly/media/trashbody.png +0 -0
  73. data/public/blockly/media/trashlid.png +0 -0
  74. data/public/blockly/media/tree.png +0 -0
  75. data/public/browserconfig.xml +1 -0
  76. data/public/large.png +0 -0
  77. data/public/smalruby/assets/ball1.png +0 -0
  78. data/public/smalruby/assets/ball2.png +0 -0
  79. data/public/smalruby/assets/ball3.png +0 -0
  80. data/public/smalruby/assets/ball4.png +0 -0
  81. data/public/smalruby/assets/ball5.png +0 -0
  82. data/public/smalruby/assets/ball6.png +0 -0
  83. data/public/smalruby/assets/car1.png +0 -0
  84. data/public/smalruby/assets/car2.png +0 -0
  85. data/public/smalruby/assets/car3.png +0 -0
  86. data/public/smalruby/assets/car4.png +0 -0
  87. data/public/smalruby/assets/cat1.png +0 -0
  88. data/public/smalruby/assets/cat2.png +0 -0
  89. data/public/smalruby/assets/cat3.png +0 -0
  90. data/public/smalruby/assets/frog1.png +0 -0
  91. data/public/smalruby/assets/piano_do.wav +0 -0
  92. data/public/smalruby/assets/piano_do_2.wav +0 -0
  93. data/public/smalruby/assets/piano_fa.wav +0 -0
  94. data/public/smalruby/assets/piano_mi.wav +0 -0
  95. data/public/smalruby/assets/piano_ra.wav +0 -0
  96. data/public/smalruby/assets/piano_re.wav +0 -0
  97. data/public/smalruby/assets/piano_si.wav +0 -0
  98. data/public/smalruby/assets/piano_so.wav +0 -0
  99. data/public/square.png +0 -0
  100. data/public/tiny.png +0 -0
  101. data/public/wide.png +0 -0
  102. data/smalruby-editor.gemspec +4 -0
  103. data/spec/acceptance/block_mode/blocks/character/new.feature +136 -0
  104. data/spec/acceptance/block_mode/blocks/control/await.feature +20 -0
  105. data/spec/acceptance/block_mode/blocks/control/await_until.feature +39 -0
  106. data/spec/acceptance/block_mode/blocks/control/break.feature +20 -0
  107. data/spec/acceptance/block_mode/blocks/control/if.feature +68 -0
  108. data/spec/acceptance/block_mode/blocks/control/if_else.feature +78 -0
  109. data/spec/acceptance/block_mode/blocks/control/loop.feature +45 -0
  110. data/spec/acceptance/block_mode/blocks/control/next.feature +20 -0
  111. data/spec/acceptance/block_mode/blocks/control/redo.feature +20 -0
  112. data/spec/acceptance/block_mode/blocks/control/sleep.feature +41 -0
  113. data/spec/acceptance/block_mode/blocks/control/times.feature +72 -0
  114. data/spec/acceptance/block_mode/blocks/control/until.feature +68 -0
  115. data/spec/acceptance/block_mode/blocks/events/on_click.feature +75 -0
  116. data/spec/acceptance/block_mode/blocks/events/on_hit.feature +83 -0
  117. data/spec/acceptance/block_mode/blocks/events/on_key_push_or_down.feature +171 -0
  118. data/spec/acceptance/block_mode/blocks/events/on_start.feature +75 -0
  119. data/spec/acceptance/block_mode/blocks/hardware/init_hardware.feature +44 -0
  120. data/spec/acceptance/block_mode/blocks/hardware/led_off.feature +75 -0
  121. data/spec/acceptance/block_mode/blocks/hardware/led_on.feature +75 -0
  122. data/spec/acceptance/block_mode/blocks/hardware/on_sensor_change.feature +81 -0
  123. data/spec/acceptance/block_mode/blocks/hardware/rgb_led_off.feature +81 -0
  124. data/spec/acceptance/block_mode/blocks/hardware/rgb_led_on.feature +87 -0
  125. data/spec/acceptance/block_mode/blocks/hardware/sensor_value.feature +100 -0
  126. data/spec/acceptance/block_mode/blocks/looks/hide.feature +69 -0
  127. data/spec/acceptance/block_mode/blocks/looks/say.feature +106 -0
  128. data/spec/acceptance/block_mode/blocks/looks/show.feature +69 -0
  129. data/spec/acceptance/block_mode/blocks/looks/vanish.feature +69 -0
  130. data/spec/acceptance/block_mode/blocks/motion/change_x_by.feature +81 -0
  131. data/spec/acceptance/block_mode/blocks/motion/change_y_by.feature +81 -0
  132. data/spec/acceptance/block_mode/blocks/motion/move.feature +81 -0
  133. data/spec/acceptance/block_mode/blocks/motion/reach_wall.feature +98 -0
  134. data/spec/acceptance/block_mode/blocks/motion/rotate_left.feature +81 -0
  135. data/spec/acceptance/block_mode/blocks/motion/rotate_right.feature +81 -0
  136. data/spec/acceptance/block_mode/blocks/motion/self_angle.feature +92 -0
  137. data/spec/acceptance/block_mode/blocks/motion/self_x.feature +92 -0
  138. data/spec/acceptance/block_mode/blocks/motion/self_y.feature +92 -0
  139. data/spec/acceptance/block_mode/blocks/motion/set_angle.feature +81 -0
  140. data/spec/acceptance/block_mode/blocks/motion/set_x.feature +81 -0
  141. data/spec/acceptance/block_mode/blocks/motion/set_x_y.feature +95 -0
  142. data/spec/acceptance/block_mode/blocks/motion/set_y.feature +81 -0
  143. data/spec/acceptance/block_mode/blocks/motion/turn.feature +69 -0
  144. data/spec/acceptance/block_mode/blocks/motion/turn_if_reach_wall.feature +69 -0
  145. data/spec/acceptance/block_mode/blocks/sensing/character_property.feature +114 -0
  146. data/spec/acceptance/block_mode/blocks/sensing/hit.feature +110 -0
  147. data/spec/acceptance/block_mode/blocks/sensing/input_key_push_or_down.feature +91 -0
  148. data/spec/acceptance/block_mode/blocks/sensing/input_mouse_pos_x.feature +39 -0
  149. data/spec/acceptance/block_mode/blocks/sensing/input_mouse_pos_y.feature +39 -0
  150. data/spec/acceptance/block_mode/blocks/sensing/input_mouse_push_or_down.feature +91 -0
  151. data/spec/acceptance/block_mode/blocks/sensing/time_now.feature +43 -0
  152. data/spec/acceptance/block_mode/blocks/sound/play.feature +81 -0
  153. data/spec/acceptance/block_mode/demo.feature +49 -0
  154. data/spec/acceptance/{text_editor → ruby_mode}/base.feature +11 -2
  155. data/spec/acceptance/{standalone → ruby_mode}/check.feature +8 -9
  156. data/spec/acceptance/ruby_mode/download.feature +33 -0
  157. data/spec/acceptance/{text_editor → ruby_mode}/load.feature +13 -13
  158. data/spec/acceptance/standalone/run.feature +17 -0
  159. data/spec/acceptance/standalone/save.feature +6 -6
  160. data/spec/helpers/editor_helper_spec.rb +110 -10
  161. data/spec/javascripts/collections/character_set_spec.coffee +41 -0
  162. data/spec/javascripts/models/character_spec.coffee +146 -0
  163. data/spec/javascripts/models/scene_spec.coffee +15 -0
  164. data/spec/javascripts/spec_helper.js +29 -0
  165. data/spec/spec_helper.rb +3 -8
  166. data/spec/steps/block_mode_steps.rb +37 -0
  167. data/spec/steps/global_variable.rb +30 -6
  168. data/spec/steps/text_editor_steps.rb +20 -2
  169. data/spec/teaspoon_env.rb +46 -0
  170. data/vendor/assets/javascripts/blockly/blockly_compressed.js +992 -0
  171. data/vendor/assets/javascripts/blockly/blocks_compressed.js +129 -0
  172. data/vendor/assets/javascripts/blockly/msg/js/ja.js +377 -0
  173. data/vendor/assets/javascripts/jquery.blockUI.js +619 -0
  174. metadata +290 -23
  175. data/app/assets/javascripts/editor.js.coffee.erb +0 -137
  176. data/app/views/editor/index.html.erb +0 -22
  177. data/spec/acceptance/text_editor/check.feature +0 -29
  178. data/spec/acceptance/text_editor/save.feature +0 -34
  179. data/spec/support/assets.rb +0 -18
@@ -0,0 +1,180 @@
1
+ # 「制御」ジャンル
2
+
3
+ <%
4
+ category = 'control'
5
+ color = 43
6
+ %>
7
+
8
+ # ( )秒待つ
9
+ <% n = "#{category}_sleep" %>
10
+ Blockly.Blocks['<%= n %>'] =
11
+ init: ()->
12
+ @setHelpUrl('')
13
+ @setColour(<%= color %>)
14
+ @interpolateMsg('%1秒待つ',
15
+ ['SEC', ['Number'], Blockly.ALIGN_RIGHT],
16
+ Blockly.ALIGN_RIGHT)
17
+ @setInputsInline(true)
18
+ @setPreviousStatement(true)
19
+ @setNextStatement(true)
20
+ @setTooltip('')
21
+
22
+ Blockly.Ruby['<%= n %>'] = (block) ->
23
+ arg = Blockly.Ruby.valueToCode(@, 'SEC', Blockly.Ruby.ORDER_FUNCTION_CALL) || '0'
24
+ "sleep(#{arg})\n"
25
+
26
+ # ずっと
27
+ <% n = "#{category}_loop" %>
28
+ Blockly.Blocks['<%= n %>'] =
29
+ init: ()->
30
+ @setHelpUrl('')
31
+ @setColour(<%= color %>)
32
+ @appendDummyInput().appendField('ずっと')
33
+ @appendStatementInput('DO')
34
+ @appendDummyInput().appendField('を繰り返す')
35
+ @setPreviousStatement(true)
36
+ @setNextStatement(true)
37
+ @setTooltip('')
38
+
39
+ Blockly.Ruby['<%= n %>'] = (block) ->
40
+ branch = Blockly.Ruby.statementToCode(block, 'DO') || '\n'
41
+ 'loop do\n' + branch + 'end\n'
42
+
43
+ <%
44
+ [
45
+ ['break', '繰り返しから脱出する'],
46
+ ['next', '次の繰り返しにジャンプする'],
47
+ ['redo', '現在の繰り返しをやり直す'],
48
+ ].each do |suffix, label|
49
+ n = "#{category}_#{suffix}"
50
+ %>
51
+
52
+ Blockly.Blocks['<%= n %>'] =
53
+ init: ()->
54
+ @setHelpUrl('')
55
+ @setColour(<%= color %>)
56
+ @appendDummyInput().appendField('<%= label %>')
57
+ @setPreviousStatement(true)
58
+ @setNextStatement(true)
59
+ @setTooltip('')
60
+
61
+ Blockly.Ruby['<%= n %>'] = (block) ->
62
+ '<%= suffix %>\n'
63
+ <% end %>
64
+
65
+ # もし< >なら
66
+ <% n = "#{category}_if" %>
67
+ Blockly.Blocks['<%= n %>'] =
68
+ init: ()->
69
+ @setHelpUrl('')
70
+ @setColour(<%= color %>)
71
+ @appendValueInput('COND').setCheck('Boolean').appendField('もし')
72
+ @appendDummyInput().appendField('ならば')
73
+ @appendStatementInput('THEN')
74
+ @setPreviousStatement(true)
75
+ @setNextStatement(true)
76
+ @setInputsInline(true)
77
+ @setTooltip('')
78
+
79
+ Blockly.Ruby['<%= n %>'] = (block) ->
80
+ cond = Blockly.Ruby.valueToCode(block, 'COND', Blockly.Ruby.ORDER_CONDITIONAL) || 'false'
81
+ branch = Blockly.Ruby.statementToCode(block, 'THEN') || '\n'
82
+ 'if ' + cond + '\n' + branch + 'end\n'
83
+
84
+ # もし< >なら~でなければ
85
+ <% n = "#{category}_if_else" %>
86
+ Blockly.Blocks['<%= n %>'] =
87
+ init: ()->
88
+ @setHelpUrl('')
89
+ @setColour(<%= color %>)
90
+ @appendValueInput('COND').setCheck('Boolean').appendField('もし')
91
+ @appendDummyInput().appendField('ならば')
92
+ @appendStatementInput('THEN')
93
+ @appendDummyInput().appendField('でなければ')
94
+ @appendStatementInput('ELSE')
95
+ @setPreviousStatement(true)
96
+ @setNextStatement(true)
97
+ @setInputsInline(true)
98
+ @setTooltip('')
99
+
100
+ Blockly.Ruby['<%= n %>'] = (block) ->
101
+ cond = Blockly.Ruby.valueToCode(block, 'COND', Blockly.Ruby.ORDER_CONDITIONAL) || 'false'
102
+ branch0 = Blockly.Ruby.statementToCode(block, 'THEN') || '\n'
103
+ branch1 = Blockly.Ruby.statementToCode(block, 'ELSE') || '\n'
104
+ 'if ' + cond + '\n' + branch0 + 'else\n' + branch1 + 'end\n'
105
+
106
+ # ( )回繰り返す
107
+ <% n = "#{category}_times" %>
108
+ Blockly.Blocks['<%= n %>'] =
109
+ init: ()->
110
+ @setHelpUrl('')
111
+ @setColour(<%= color %>)
112
+ @interpolateMsg('%1回繰り返す',
113
+ ['COUNT', ['Number'], Blockly.ALIGN_RIGHT],
114
+ Blockly.ALIGN_RIGHT)
115
+ @appendStatementInput('DO')
116
+ @setInputsInline(true)
117
+ @setPreviousStatement(true)
118
+ @setNextStatement(true)
119
+ @setTooltip('')
120
+
121
+ Blockly.Ruby['<%= n %>'] = (block) ->
122
+ count = Blockly.Ruby.valueToCode(@, 'COUNT', Blockly.Ruby.ORDER_NONE) || 0
123
+ branch = Blockly.Ruby.statementToCode(block, 'DO') || '\n'
124
+ "#{count}.times do\n" + branch + 'end\n'
125
+
126
+ # < >まで待つ
127
+ <% n = "#{category}_await_until" %>
128
+ Blockly.Blocks['<%= n %>'] =
129
+ init: ()->
130
+ @setHelpUrl('')
131
+ @setColour(<%= color %>)
132
+ @interpolateMsg('%1まで待つ',
133
+ ['COND', ['Boolean'], Blockly.ALIGN_RIGHT],
134
+ Blockly.ALIGN_RIGHT)
135
+ @setInputsInline(true)
136
+ @setPreviousStatement(true)
137
+ @setNextStatement(true)
138
+ @setTooltip('')
139
+
140
+ Blockly.Ruby['<%= n %>'] = (block) ->
141
+ cond = Blockly.Ruby.valueToCode(@, 'COND', Blockly.Ruby.ORDER_CONDITIONAL) || 'true'
142
+ "await until #{cond}\n"
143
+
144
+ # < >まで繰り返す
145
+ <% n = "#{category}_until" %>
146
+ Blockly.Blocks['<%= n %>'] =
147
+ init: ()->
148
+ @setHelpUrl('')
149
+ @setColour(<%= color %>)
150
+ @interpolateMsg('%1まで',
151
+ ['COND', ['Boolean'], Blockly.ALIGN_RIGHT],
152
+ Blockly.ALIGN_RIGHT)
153
+ @appendStatementInput('DO')
154
+ @appendDummyInput()
155
+ .appendField('を繰り返す')
156
+ .setAlign(Blockly.ALIGN_RIGHT)
157
+ @setInputsInline(true)
158
+ @setPreviousStatement(true)
159
+ @setNextStatement(true)
160
+ @setTooltip('')
161
+
162
+ Blockly.Ruby['<%= n %>'] = (block) ->
163
+ cond = Blockly.Ruby.valueToCode(@, 'COND', Blockly.Ruby.ORDER_CONDITIONAL) || 'true'
164
+ branch = Blockly.Ruby.statementToCode(block, 'DO') || '\n'
165
+ "until #{cond}\n" + branch + 'end\n'
166
+
167
+ # 1フレーム待つ
168
+ <% n = "#{category}_await" %>
169
+ Blockly.Blocks['<%= n %>'] =
170
+ init: ()->
171
+ @setHelpUrl('')
172
+ @setColour(<%= color %>)
173
+ @appendDummyInput()
174
+ .appendField('1フレーム待つ')
175
+ @setPreviousStatement(true)
176
+ @setNextStatement(true)
177
+ @setTooltip('')
178
+
179
+ Blockly.Ruby['<%= n %>'] = (block) ->
180
+ 'await\n'
@@ -0,0 +1,6 @@
1
+ # 「データ」ジャンル
2
+
3
+ <%
4
+ category = 'data'
5
+ color = 29
6
+ %>
@@ -0,0 +1,6 @@
1
+ # 「その他」ジャンル
2
+
3
+ <%
4
+ category = 'etc'
5
+ color = 270
6
+ %>
@@ -0,0 +1,82 @@
1
+ # 「イベント」ジャンル
2
+
3
+ <%
4
+ category = 'events'
5
+ color = 33
6
+ %>
7
+
8
+ # まずは
9
+ <% n = "#{category}_on_start" %>
10
+ Blockly.Blocks['<%= n %>'] =
11
+ init: ()->
12
+ @setHelpUrl('')
13
+ @setColour(<%= color %>)
14
+ @appendDummyInput()
15
+ .appendField('まずは')
16
+ @appendStatementInput('DO')
17
+ @setPreviousStatement(true)
18
+ @setNextStatement(true)
19
+ @setTooltip('')
20
+
21
+ Blockly.Ruby['<%= n %>'] = (block) ->
22
+ Blockly.Ruby.characterEvent_(block, 'DO', 'start')
23
+
24
+ # キーボードの[▼キー]が[▼押された/押され続けている]とき
25
+ <% n = "#{category}_on_key_push_or_down" %>
26
+ Blockly.Blocks['<%= n %>'] =
27
+ init: ()->
28
+ keyDropdown = window.SmalrubyEditor.Sensing.KeyDropdown
29
+ podDropdown = window.SmalrubyEditor.Sensing.PushOrDownDropdown
30
+
31
+ @setHelpUrl('')
32
+ @setColour(<%= color %>)
33
+ @appendDummyInput()
34
+ .appendField('キーボードの')
35
+ .appendField(new Blockly.FieldDropdown(keyDropdown), 'KEY')
36
+ .appendField('が')
37
+ .appendField(new Blockly.FieldDropdown(podDropdown), 'POD')
38
+ .appendField('とき')
39
+ @appendStatementInput('DO')
40
+ @setPreviousStatement(true)
41
+ @setNextStatement(true)
42
+ @setTooltip('')
43
+
44
+ Blockly.Ruby['<%= n %>'] = (block) ->
45
+ key = @getFieldValue('KEY')
46
+ pod = @getFieldValue('POD')
47
+ Blockly.Ruby.characterEvent_(block, 'DO', "key_#{pod}", key)
48
+
49
+ # キャラクターがクリックされたとき
50
+ <% n = "#{category}_on_click" %>
51
+ Blockly.Blocks['<%= n %>'] =
52
+ init: ()->
53
+ @setHelpUrl('')
54
+ @setColour(<%= color %>)
55
+ @appendDummyInput()
56
+ .appendField('キャラクターがクリックされたとき')
57
+ @appendStatementInput('DO')
58
+ @setPreviousStatement(true)
59
+ @setNextStatement(true)
60
+ @setTooltip('')
61
+
62
+ Blockly.Ruby['<%= n %>'] = (block) ->
63
+ Blockly.Ruby.characterEvent_(block, 'DO', 'click')
64
+
65
+ # [▼キャラクター]にぶつかったとき
66
+ <% n = "#{category}_on_hit" %>
67
+ Blockly.Blocks['<%= n %>'] =
68
+ init: ()->
69
+ @setHelpUrl('')
70
+ @setColour(<%= color %>)
71
+ @appendDummyInput()
72
+ .appendField(new Blockly.FieldVariable('car1'), 'CHAR') # TODO
73
+ .appendField('にぶつかったとき')
74
+ @appendStatementInput('DO')
75
+ @setPreviousStatement(true)
76
+ @setNextStatement(true)
77
+ @setTooltip('')
78
+
79
+ Blockly.Ruby['<%= n %>'] = (block) ->
80
+ char = Blockly.Ruby.variableDB_
81
+ .getName(block.getFieldValue('CHAR'), Blockly.Variables.NAME_TYPE)
82
+ Blockly.Ruby.characterEvent_(block, 'DO', 'hit', char)
@@ -0,0 +1,313 @@
1
+ # 「ハードウェア」ジャンル
2
+
3
+ <%
4
+ category = 'hardware'
5
+ color = 208
6
+ %>
7
+
8
+ # ハードウェアの環境設定
9
+ window.SmalrubyEditor.Hardware =
10
+ Type: 'Arduino' # 種別
11
+ DioPins: [2..13] # デジタルIOピン
12
+ AiPins: [0..5] # アナログ入力ピン
13
+
14
+ dioPinDropdown =
15
+ (["D#{n}", "D#{n}"] for n in window.SmalrubyEditor.Hardware.DioPins)
16
+
17
+ pwmPinDropdown =
18
+ (["D#{n}", "D#{n}"] for n in [3, 9])
19
+
20
+ aiPinDropdown =
21
+ (["A#{n}", "A#{n}"] for n in window.SmalrubyEditor.Hardware.AiPins)
22
+
23
+ acDropdown = [
24
+ ['アノード', 'anode']
25
+ ['カソード', 'cathode']
26
+ ]
27
+
28
+ # ハードウェアを準備する
29
+ <% n = "#{category}_init_hardware" %>
30
+ Blockly.Blocks['<%= n %>'] =
31
+ init: ()->
32
+ @setHelpUrl('')
33
+ @setColour(<%= color %>)
34
+ @appendDummyInput().appendField('ハードウェアを準備する')
35
+ @setTooltip('')
36
+
37
+ Blockly.Ruby['<%= n %>'] = (block) ->
38
+ Blockly.Ruby.definitions_['init_hardware'] = 'init_hardware'
39
+ ''
40
+
41
+ # 「LED」サブジャンル
42
+
43
+ # LED[▼ピン]をオンにする
44
+ # LED[▼ピン]をオフにする
45
+ <%
46
+ [
47
+ ['on', 'オン'],
48
+ ['off', 'オフ'],
49
+ ].each do |method, label|
50
+ n = "#{category}_led_#{method}"
51
+ %>
52
+
53
+ Blockly.Blocks['<%= n %>'] =
54
+ init: ()->
55
+ @setHelpUrl('')
56
+ @setColour(<%= color %>)
57
+ @appendDummyInput()
58
+ .appendField('LED')
59
+ .appendField(new Blockly.FieldDropdown(dioPinDropdown), 'PIN')
60
+ .appendField('を<%= label %>にする')
61
+ @setPreviousStatement(true)
62
+ @setNextStatement(true)
63
+ @setTooltip('')
64
+
65
+ @setFieldValue('D2', 'PIN')
66
+
67
+ Blockly.Ruby['<%= n %>'] = (block) ->
68
+ pin = @getFieldValue('PIN')
69
+ Blockly.Ruby.characterMethodCall_("led(#{Blockly.Ruby.quote_(pin)}).<%= method %>")
70
+ <% end %>
71
+
72
+ # 「RGB LED」サブジャンル
73
+
74
+ # RGB LED[▼アノード]コモン[▼ピン]を[カラー]にする
75
+ <% n = "#{category}_rgb_led_on" %>
76
+ Blockly.Blocks['<%= n %>'] =
77
+ init: ()->
78
+ @setHelpUrl('')
79
+ @setColour(<%= color %>)
80
+ @appendDummyInput()
81
+ .appendField('RGB LED')
82
+ .appendField(new Blockly.FieldDropdown(acDropdown), 'AC')
83
+ .appendField('コモン')
84
+ .appendField(new Blockly.FieldDropdown(pwmPinDropdown), 'PIN')
85
+ .appendField('を')
86
+ .appendField(new Blockly.FieldColour('#ff0000'), 'COLOUR')
87
+ .appendField('にする')
88
+ @setPreviousStatement(true)
89
+ @setNextStatement(true)
90
+ @setTooltip('')
91
+
92
+ Blockly.Ruby['<%= n %>'] = (block) ->
93
+ ac = @getFieldValue('AC')
94
+ pin = @getFieldValue('PIN')
95
+ c = block.getFieldValue('COLOUR')
96
+ red = parseInt(c[1..2], 16)
97
+ green = parseInt(c[3..4], 16)
98
+ blue = parseInt(c[5..6], 16)
99
+ Blockly.Ruby.characterMethodCall_("rgb_led_#{ac}(#{Blockly.Ruby.quote_(pin)}).on",
100
+ "color: [#{red}, #{green}, #{blue}]")
101
+
102
+ # RGB LED[▼アノード]コモン[▼ピン]をオフにする
103
+ <% n = "#{category}_rgb_led_off" %>
104
+ Blockly.Blocks['<%= n %>'] =
105
+ init: ()->
106
+ @setHelpUrl('')
107
+ @setColour(<%= color %>)
108
+ @appendDummyInput()
109
+ .appendField('RGB LED')
110
+ .appendField(new Blockly.FieldDropdown(acDropdown), 'AC')
111
+ .appendField('コモン')
112
+ .appendField(new Blockly.FieldDropdown(pwmPinDropdown), 'PIN')
113
+ .appendField('をオフにする')
114
+ @setPreviousStatement(true)
115
+ @setNextStatement(true)
116
+ @setTooltip('')
117
+
118
+ Blockly.Ruby['<%= n %>'] = (block) ->
119
+ ac = @getFieldValue('AC')
120
+ pin = @getFieldValue('PIN')
121
+ Blockly.Ruby.characterMethodCall_("rgb_led_#{ac}(#{Blockly.Ruby.quote_(pin)}).off")
122
+
123
+ # 「7セグディスプレイ」サブジャンル
124
+
125
+ # 7セグディスプレイに[▼0-9]を表示する
126
+ <% n = "#{category}_seven_segment_display_show" %>
127
+ Blockly.Blocks['<%= n %>'] =
128
+ init: ()->
129
+ dropdown = ([String(n), String(n)] for n in [0..9])
130
+
131
+ @setHelpUrl('')
132
+ @setColour(<%= color %>)
133
+ @appendDummyInput()
134
+ .appendField('7セグディスプレイに')
135
+ .appendField(new Blockly.FieldDropdown(dropdown), 'NUM')
136
+ .appendField('を表示する')
137
+ @setPreviousStatement(true)
138
+ @setNextStatement(true)
139
+ @setTooltip('')
140
+
141
+ Blockly.Ruby['<%= n %>'] = (block) ->
142
+ num = parseInt(@getFieldValue('NUM'))
143
+ "seven_segment_display.show(#{num})\n"
144
+
145
+ # 7セグディスプレイをオフにする
146
+ <% n = "#{category}_seven_segment_display_off" %>
147
+ Blockly.Blocks['<%= n %>'] =
148
+ init: ()->
149
+ @setHelpUrl('')
150
+ @setColour(<%= color %>)
151
+ @appendDummyInput()
152
+ .appendField('7セグディスプレイをオフにする')
153
+ @setPreviousStatement(true)
154
+ @setNextStatement(true)
155
+ @setTooltip('')
156
+
157
+ Blockly.Ruby['<%= n %>'] = (block) ->
158
+ "seven_segment_display.off\n"
159
+
160
+ # 「LCD」サブジャンル
161
+
162
+ # LCDに( )を表示する
163
+ <% n = "#{category}_lcd_puts" %>
164
+ Blockly.Blocks['<%= n %>'] =
165
+ init: ()->
166
+ @setHelpUrl('')
167
+ @setColour(<%= color %>)
168
+ @appendValueInput('TEXT')
169
+ .appendField('LCDに')
170
+ .setCheck('String')
171
+ @appendDummyInput()
172
+ .appendField('を表示する')
173
+ @setInputsInline(true)
174
+ @setPreviousStatement(true)
175
+ @setNextStatement(true)
176
+ @setTooltip('')
177
+
178
+ Blockly.Ruby['<%= n %>'] = (block) ->
179
+ text = Blockly.Ruby.valueToCode(@, 'TEXT', Blockly.Ruby.ORDER_NONE) || ''
180
+ "lcd.puts(#{text})\n"
181
+
182
+ # LCDをクリアする
183
+ <% n = "#{category}_lcd_clear" %>
184
+ Blockly.Blocks['<%= n %>'] =
185
+ init: ()->
186
+ @setHelpUrl('')
187
+ @setColour(<%= color %>)
188
+ @appendDummyInput()
189
+ .appendField('LCDをクリアする')
190
+ @setPreviousStatement(true)
191
+ @setNextStatement(true)
192
+ @setTooltip('')
193
+
194
+ Blockly.Ruby['<%= n %>'] = (block) ->
195
+ "lcd.clear\n"
196
+
197
+ # 7セグディスプレイをオフにする
198
+ <% n = "#{category}_seven_segment_display_off" %>
199
+ Blockly.Blocks['<%= n %>'] =
200
+ init: ()->
201
+ @setHelpUrl('')
202
+ @setColour(<%= color %>)
203
+ @appendDummyInput()
204
+ .appendField('7セグディスプレイをオフにする')
205
+ @setPreviousStatement(true)
206
+ @setNextStatement(true)
207
+ @setTooltip('')
208
+
209
+ Blockly.Ruby['<%= n %>'] = (block) ->
210
+ "seven_segment_display.off\n"
211
+
212
+ # 「ボタン」サブジャンル
213
+
214
+ # 条件:ボタン[▼]を押している
215
+ # 条件:ボタン[▼]を離している
216
+ <%
217
+ [
218
+ ['down', '押している'],
219
+ ['up', '離している'],
220
+ ].each do |method, label|
221
+ n = "#{category}_button_#{method}"
222
+ %>
223
+
224
+ Blockly.Blocks['<%= n %>'] =
225
+ init: ()->
226
+ @setHelpUrl('')
227
+ @setColour(<%= color %>)
228
+ @appendDummyInput()
229
+ .appendField('ボタン')
230
+ .appendField(new Blockly.FieldDropdown(dioPinDropdown), 'PIN')
231
+ .appendField('を<%= label %>')
232
+ @setOutput(true, 'Boolean')
233
+ @setTooltip('')
234
+
235
+ Blockly.Ruby['<%= n %>'] = (block) ->
236
+ pin = @getFieldValue('PIN')
237
+ ["button(#{pin}).<%= method %>?", Blockly.Ruby.ORDER_ATOMIC]
238
+ <% end %>
239
+
240
+ # ボタン[▼]を押したとき
241
+ # ボタン[▼]を離したとき
242
+ <%
243
+ [
244
+ ['down', '押した'],
245
+ ['up', '離した'],
246
+ ].each do |name, label|
247
+ n = "#{category}_on_button_#{name}"
248
+ %>
249
+
250
+ Blockly.Blocks['<%= n %>'] =
251
+ init: ()->
252
+ @setHelpUrl('')
253
+ @setColour(<%= color %>)
254
+ @appendDummyInput()
255
+ .appendField('ボタン')
256
+ .appendField(new Blockly.FieldDropdown(dioPinDropdown), 'PIN')
257
+ .appendField('を<%= label %>とき')
258
+ @appendStatementInput('DO')
259
+ @setPreviousStatement(true)
260
+ @setNextStatement(true)
261
+ @setTooltip('')
262
+
263
+ Blockly.Ruby['<%= n %>'] = (block) ->
264
+ if (var0 = Blockly.Ruby.receiverName())
265
+ pin = @getFieldValue('PIN')
266
+ branch = Blockly.Ruby.statementToCode(block, 'DO') || '\n'
267
+ """
268
+
269
+
270
+ #{var0}.on(:button_<%= name %>, #{pin}) do
271
+ #{branch}end
272
+
273
+ """
274
+ else
275
+ ''
276
+ <% end %>
277
+
278
+ # 「センサー」サブジャンル
279
+
280
+ # センサー[▼PIN]
281
+ <% n = "#{category}_sensor_value" %>
282
+ Blockly.Blocks['<%= n %>'] =
283
+ init: ()->
284
+ @setHelpUrl('')
285
+ @setColour(<%= color %>)
286
+ @appendDummyInput()
287
+ .appendField('センサー')
288
+ .appendField(new Blockly.FieldDropdown(aiPinDropdown), 'PIN')
289
+ @setOutput(true, 'Number')
290
+ @setTooltip('')
291
+
292
+ Blockly.Ruby['<%= n %>'] = (block) ->
293
+ pin = @getFieldValue('PIN')
294
+ Blockly.Ruby.characterMethodCallInput_("sensor(#{Blockly.Ruby.quote_(pin)}).value")
295
+
296
+ # センサー[▼PIN]が変化したとき
297
+ <% n = "#{category}_on_sensor_change" %>
298
+ Blockly.Blocks['<%= n %>'] =
299
+ init: ()->
300
+ @setHelpUrl('')
301
+ @setColour(<%= color %>)
302
+ @appendDummyInput()
303
+ .appendField('センサー')
304
+ .appendField(new Blockly.FieldDropdown(aiPinDropdown), 'PIN')
305
+ .appendField('が変化したとき')
306
+ @appendStatementInput('DO')
307
+ @setPreviousStatement(true)
308
+ @setNextStatement(true)
309
+ @setTooltip('')
310
+
311
+ Blockly.Ruby['<%= n %>'] = (block) ->
312
+ pin = @getFieldValue('PIN')
313
+ Blockly.Ruby.characterEvent_(block, 'DO', 'sensor_change', Blockly.Ruby.quote_(pin))