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,279 @@
1
+ # 「演算」ジャンル
2
+
3
+ <%
4
+ category = 'operators'
5
+ color = 93
6
+ %>
7
+
8
+ # 変数:( ) + ( )
9
+ # 変数:( ) - ( )
10
+ # 変数:( ) * ( )
11
+ # 変数:( ) / ( )
12
+ <%
13
+ [
14
+ ['add', '+', 'ADDITIVE', '+'],
15
+ ['minus', 'ー', 'ADDITIVE', '-'],
16
+ ['multiply', '×', 'MULTIPLICATIVE', '*'],
17
+ ['divide', '÷', 'MULTIPLICATIVE', '/'],
18
+ ].each do |suffix, operator_label, order_suffix, operator|
19
+ n = "#{category}_#{suffix}"
20
+ %>
21
+
22
+ Blockly.Blocks['<%= n %>'] =
23
+ init: ()->
24
+ @setHelpUrl('')
25
+ @setColour(<%= color %>)
26
+ @interpolateMsg('%1<%= operator_label %>%2',
27
+ ['A', null, Blockly.ALIGN_RIGHT],
28
+ ['B', null, Blockly.ALIGN_RIGHT],
29
+ Blockly.ALIGN_RIGHT)
30
+ @setInputsInline(true)
31
+ @setOutput(true, null)
32
+ @setTooltip('')
33
+
34
+ Blockly.Ruby['<%= n %>'] = (block) ->
35
+ order = Blockly.Ruby.ORDER_<%= order_suffix %>
36
+ a = Blockly.Ruby.valueToCode(block, 'A', order) || '0'
37
+ b = Blockly.Ruby.valueToCode(block, 'B', order) || '0'
38
+ [a + ' <%= operator %> ' + b, order]
39
+ <% end %>
40
+
41
+ # 条件:( ) < ( )
42
+ # 条件:( ) <= ( )
43
+ # 条件:( ) = ( )
44
+ # 条件:( ) => ( )
45
+ # 条件:( ) > ( )
46
+ <%
47
+ [
48
+ ['compare_gt', '<', '<'],
49
+ ['compare_gte', '≦', '<='],
50
+ ['compare_eq', '=', '=='],
51
+ ['compare_lte', '≧', '>='],
52
+ ['compare_lt', '>', '>'],
53
+ ].each do |suffix, operator_label, operator|
54
+ n = "#{category}_#{suffix}"
55
+ %>
56
+
57
+ Blockly.Blocks['<%= n %>'] =
58
+ init: ()->
59
+ @setHelpUrl('')
60
+ @setColour(<%= color %>)
61
+ @interpolateMsg('%1<%= operator_label %>%2',
62
+ ['A', null, Blockly.ALIGN_RIGHT],
63
+ ['B', null, Blockly.ALIGN_RIGHT],
64
+ Blockly.ALIGN_RIGHT)
65
+ @setInputsInline(true)
66
+ @setOutput(true, 'Boolean')
67
+ @setTooltip('')
68
+
69
+ Blockly.Ruby['<%= n %>'] = (block) ->
70
+ order = Blockly.Ruby.ORDER_RELATIONAL;
71
+ a = Blockly.Ruby.valueToCode(block, 'A', order) || '0'
72
+ b = Blockly.Ruby.valueToCode(block, 'B', order) || '0'
73
+ [a + ' <%= operator %> ' + b, order]
74
+ <% end %>
75
+
76
+ # 変数:( )から( )までの乱数
77
+ <% n = "#{category}_rand" %>
78
+ Blockly.Blocks['<%= n %>'] =
79
+ init: ()->
80
+ @setHelpUrl('')
81
+ @setColour(<%= color %>)
82
+ @interpolateMsg('%1から%2までの乱数',
83
+ ['A', ['Number'], Blockly.ALIGN_RIGHT],
84
+ ['B', ['Number'], Blockly.ALIGN_RIGHT],
85
+ Blockly.ALIGN_RIGHT)
86
+ @setInputsInline(true)
87
+ @setOutput(true, 'Number')
88
+ @setTooltip('')
89
+
90
+ Blockly.Ruby['<%= n %>'] = (block) ->
91
+ order = Blockly.Ruby.ORDER_FUNCTION_CALL
92
+ a = Blockly.Ruby.valueToCode(block, 'A', order) || '0'
93
+ b = Blockly.Ruby.valueToCode(block, 'B', order) || '0'
94
+ ["rand(#{a}..#{b})", order]
95
+
96
+ # 条件:< > かつ < >
97
+ # 条件:< > または < >
98
+ <%
99
+ [
100
+ ['and', 'かつ', '&&'],
101
+ ['or', 'または', '||'],
102
+ ].each do |suffix, label, operator|
103
+ n = "#{category}_#{suffix}"
104
+ %>
105
+
106
+ Blockly.Blocks['<%= n %>'] =
107
+ init: ()->
108
+ @setHelpUrl('')
109
+ @setColour(<%= color %>)
110
+ @interpolateMsg('%1<%= label %>%2',
111
+ ['A', ['Boolean'], Blockly.ALIGN_RIGHT],
112
+ ['B', ['Boolean'], Blockly.ALIGN_RIGHT],
113
+ Blockly.ALIGN_RIGHT)
114
+ @setInputsInline(true)
115
+ @setOutput(true, 'Boolean')
116
+ @setTooltip('')
117
+
118
+ Blockly.Ruby['<%= n %>'] = (block) ->
119
+ order = Blockly.Ruby.ORDER_LOGICAL_<%= suffix.upcase %>
120
+ a = Blockly.Ruby.valueToCode(block, 'A', order) || 'true'
121
+ b = Blockly.Ruby.valueToCode(block, 'B', order) || 'true'
122
+ ["#{a} <%= operator %> #{b}", order]
123
+ <% end %>
124
+
125
+ # 条件:< > ではない
126
+ <% n = "#{category}_negate" %>
127
+ Blockly.Blocks['<%= n %>'] =
128
+ init: ()->
129
+ @setHelpUrl('')
130
+ @setColour(<%= color %>)
131
+ @interpolateMsg('%1ではない',
132
+ ['A', ['Boolean'], Blockly.ALIGN_RIGHT],
133
+ Blockly.ALIGN_RIGHT)
134
+ @setInputsInline(true)
135
+ @setOutput(true, 'Boolean')
136
+ @setTooltip('')
137
+
138
+ Blockly.Ruby['<%= n %>'] = (block) ->
139
+ order = Blockly.Ruby.ORDER_LOGICAL_NOT
140
+ a = Blockly.Ruby.valueToCode(block, 'A', order) || 'true'
141
+ ["!#{a}", order]
142
+
143
+ # 変数:( )の[ ]番目
144
+ <% n = "#{category}_index_of" %>
145
+ Blockly.Blocks['<%= n %>'] =
146
+ init: ()->
147
+ @setHelpUrl('')
148
+ @setColour(<%= color %>)
149
+ @interpolateMsg('%1の%2番目',
150
+ ['A', null, Blockly.ALIGN_RIGHT],
151
+ ['INDEX', ['Number'], Blockly.ALIGN_RIGHT],
152
+ Blockly.ALIGN_RIGHT)
153
+ @setInputsInline(true)
154
+ @setOutput(true, null)
155
+ @setTooltip('')
156
+
157
+ Blockly.Ruby['<%= n %>'] = (block) ->
158
+ order = Blockly.Ruby.ORDER_FUNCTION_CALL
159
+ a = Blockly.Ruby.valueToCode(block, 'A', order) || '""'
160
+ index = Blockly.Ruby.valueToCode(block, 'INDEX', order) || '0'
161
+ ["#{a}[#{index}]", order]
162
+
163
+ # 変数:[ ]の長さ
164
+ <% n = "#{category}_length" %>
165
+ Blockly.Blocks['<%= n %>'] =
166
+ init: ()->
167
+ @setHelpUrl('')
168
+ @setColour(<%= color %>)
169
+ @interpolateMsg('%1の長さ',
170
+ ['A', null, Blockly.ALIGN_RIGHT],
171
+ Blockly.ALIGN_RIGHT)
172
+ @setInputsInline(true)
173
+ @setOutput(true, null)
174
+ @setTooltip('')
175
+
176
+ Blockly.Ruby['<%= n %>'] = (block) ->
177
+ order = Blockly.Ruby.ORDER_FUNCTION_CALL
178
+ a = Blockly.Ruby.valueToCode(block, 'A', order) || '""'
179
+ ["#{a}.length", order]
180
+
181
+ # 変数:( )を( )で割った余り
182
+ <% n = "#{category}_modulo" %>
183
+ Blockly.Blocks['<%= n %>'] =
184
+ init: ()->
185
+ @setHelpUrl('')
186
+ @setColour(<%= color %>)
187
+ @interpolateMsg('%1を%2で割った余り',
188
+ ['A', ['Number'], Blockly.ALIGN_RIGHT],
189
+ ['B', ['Number'], Blockly.ALIGN_RIGHT],
190
+ Blockly.ALIGN_RIGHT)
191
+ @setInputsInline(true)
192
+ @setOutput(true, 'Number')
193
+ @setTooltip('')
194
+
195
+ Blockly.Ruby['<%= n %>'] = (block) ->
196
+ order = Blockly.Ruby.ORDER_MULTIPLICATIVE
197
+ a = Blockly.Ruby.valueToCode(block, 'A', order) || '5'
198
+ b = Blockly.Ruby.valueToCode(block, 'B', order) || '2'
199
+ ["#{a} % #{b}", order]
200
+
201
+ # 変数:( )を丸める
202
+ <% n = "#{category}_round" %>
203
+ Blockly.Blocks['<%= n %>'] =
204
+ init: ()->
205
+ @setHelpUrl('')
206
+ @setColour(<%= color %>)
207
+ @interpolateMsg('%1を丸める',
208
+ ['A', ['Number'], Blockly.ALIGN_RIGHT],
209
+ Blockly.ALIGN_RIGHT)
210
+ @setInputsInline(true)
211
+ @setOutput(true, 'Number')
212
+ @setTooltip('')
213
+
214
+ Blockly.Ruby['<%= n %>'] = (block) ->
215
+ order = Blockly.Ruby.ORDER_FUNCTION_CALL
216
+ a = Blockly.Ruby.valueToCode(block, 'A', order) || '0'
217
+ ["#{a}.round", order]
218
+
219
+ # 変数:( )の[▼数学関数]
220
+ <% n = "#{category}_math_method" %>
221
+ Blockly.Blocks['<%= n %>'] =
222
+ init: ()->
223
+ dropdown = [
224
+ ['絶対値', '%num%.abs'],
225
+ ['切り上げ', '%num%.floor'],
226
+ ['切り下げ', '%num%.ceil'],
227
+ ['平方根', 'Math.sqrt(%num%)'],
228
+ ['sin', 'Math.sin(%num%)'],
229
+ ['cos', 'Math.cos(%num%)'],
230
+ ['tan', 'Math.tan(%num%)'],
231
+ ['asin', 'Math.asin(%num%)'],
232
+ ['acos', 'Math.acos(%num%)'],
233
+ ['atan', 'Math.atan(%num%)'],
234
+ ['log', 'Math.log(%num%)'],
235
+ ['log10', 'Math.log10(%num%)'],
236
+ ['e^', 'Math::E ** %num%'],
237
+ ['10^', '10 ** %num%'],
238
+ ]
239
+
240
+ @setHelpUrl('')
241
+ @setColour(<%= color %>)
242
+ @appendValueInput('NUM')
243
+ .setCheck('Number')
244
+ @appendDummyInput()
245
+ .appendField('の')
246
+ .appendField(new Blockly.FieldDropdown(dropdown), 'METHOD')
247
+ @setInputsInline(true)
248
+ @setOutput(true, 'Number')
249
+ @setTooltip('')
250
+
251
+ Blockly.Ruby['<%= n %>'] = (block) ->
252
+ order = Blockly.Ruby.ORDER_FUNCTION_CALL
253
+ method = @getFieldValue('METHOD')
254
+ num = Blockly.Ruby.valueToCode(block, 'NUM', order) || '0'
255
+ [method.replace(/%num%/, num), order]
256
+
257
+ # 条件:真
258
+ # 条件:偽
259
+ <%
260
+ [
261
+ ['true', '真'],
262
+ ['false', '偽'],
263
+ ].each do |val, label|
264
+ n = "#{category}_#{val}"
265
+ %>
266
+
267
+ Blockly.Blocks['<%= n %>'] =
268
+ init: ()->
269
+ @setHelpUrl('')
270
+ @setColour(<%= color %>)
271
+ @appendDummyInput()
272
+ .appendField('<%= label %>')
273
+ @setInputsInline(true)
274
+ @setOutput(true, 'Boolean')
275
+ @setTooltip('')
276
+
277
+ Blockly.Ruby['<%= n %>'] = (block) ->
278
+ ['<%= val %>', Blockly.Ruby.ORDER_ATOMIC]
279
+ <% end %>
@@ -0,0 +1,6 @@
1
+ # 「ペン」ジャンル
2
+
3
+ <%
4
+ category = 'pen'
5
+ color = 160
6
+ %>
@@ -0,0 +1,74 @@
1
+ # 「Ruby」ジャンル
2
+
3
+ <%
4
+ category = 'ruby'
5
+ color = 340
6
+ %>
7
+
8
+ # 文
9
+ <% n = "#{category}_statement" %>
10
+ Blockly.Blocks['<%= n %>'] =
11
+ init: ()->
12
+ @setHelpUrl('')
13
+ @setColour(<%= color %>)
14
+ @appendDummyInput()
15
+ .appendField('文')
16
+ .appendField(new Blockly.FieldTextInput(''), 'STATEMENT')
17
+ @setPreviousStatement(true)
18
+ @setNextStatement(true)
19
+ @setTooltip('')
20
+
21
+ Blockly.Ruby['<%= n %>'] = (block) ->
22
+ statement = @getFieldValue('STATEMENT')
23
+ "#{statement}\n"
24
+
25
+ # 式
26
+ <% n = "#{category}_expression" %>
27
+ Blockly.Blocks['<%= n %>'] =
28
+ init: ()->
29
+ @setHelpUrl('')
30
+ @setColour(<%= color %>)
31
+ @appendDummyInput()
32
+ .appendField('式')
33
+ .appendField(new Blockly.FieldTextInput(''), 'EXP')
34
+ @setOutput(true, null)
35
+ @setTooltip('')
36
+
37
+ Blockly.Ruby['<%= n %>'] = (block) ->
38
+ exp = @getFieldValue('EXP')
39
+ ["(#{exp})", Blockly.Ruby.ORDER_ATOMIC]
40
+
41
+ # コメント
42
+ <% n = "#{category}_comment" %>
43
+ Blockly.Blocks['<%= n %>'] =
44
+ init: ()->
45
+ @setHelpUrl('')
46
+ @setColour(<%= color %>)
47
+ @appendDummyInput()
48
+ .appendField('コメント')
49
+ .appendField(new Blockly.FieldTextInput(''), 'COMMENT')
50
+ @setPreviousStatement(true)
51
+ @setNextStatement(true)
52
+ @setTooltip('')
53
+
54
+ Blockly.Ruby['<%= n %>'] = (block) ->
55
+ comment = @getFieldValue('COMMENT')
56
+ "# #{comment}\n"
57
+
58
+ # p
59
+ <% n = "#{category}_p" %>
60
+ Blockly.Blocks['<%= n %>'] =
61
+ init: ()->
62
+ @setHelpUrl('')
63
+ @setColour(<%= color %>)
64
+ @interpolateMsg('p %1',
65
+ ['ARG', null, Blockly.ALIGN_RIGHT],
66
+ Blockly.ALIGN_RIGHT)
67
+ @setInputsInline(true)
68
+ @setPreviousStatement(true)
69
+ @setNextStatement(true)
70
+ @setTooltip('')
71
+
72
+ Blockly.Ruby['<%= n %>'] = (block) ->
73
+ arg = Blockly.Ruby.valueToCode(@, 'ARG', Blockly.Ruby.ORDER_NONE) || '""'
74
+ "p(#{arg})\n"
@@ -0,0 +1,241 @@
1
+ # 「調べる」ジャンル
2
+
3
+ <%
4
+ category = 'sensing'
5
+ color = 200
6
+ %>
7
+
8
+ # 調べるの環境設定
9
+ window.SmalrubyEditor.Sensing =
10
+ KeyDropdown: [
11
+ ['↑', 'K_UP'],
12
+ ['↓', 'K_DOWN'],
13
+ ['←', 'K_LEFT'],
14
+ ['→', 'K_RIGHT'],
15
+ ['スペース', 'K_SPACE'],
16
+ <% (('a'..'z').to_a + ('0'..'9').to_a).each do |k| %>
17
+ ['<%= k %>', 'K_<%= k.upcase %>'],
18
+ <% end %>
19
+ ]
20
+ PushOrDownDropdown: [
21
+ ['押された', 'push'],
22
+ ['押され続けている', 'down'],
23
+ ]
24
+ MouseButtonDropdown: [
25
+ ['左ボタン', 'M_LBUTTON'],
26
+ ['中ボタン', 'M_MBUTTON'],
27
+ ['右ボタン', 'M_RBUTTON'],
28
+ ]
29
+
30
+ # 条件:キーボードの[▼キー]が[▼押された]
31
+ <% n = "#{category}_input_key_push_or_down" %>
32
+ Blockly.Blocks['<%= n %>'] =
33
+ init: ()->
34
+ keyDropdown = window.SmalrubyEditor.Sensing.KeyDropdown
35
+ podDropdown = window.SmalrubyEditor.Sensing.PushOrDownDropdown
36
+
37
+ @setHelpUrl('')
38
+ @setColour(<%= color %>)
39
+ @appendDummyInput()
40
+ .appendField('キーボードの')
41
+ .appendField(new Blockly.FieldDropdown(keyDropdown), 'KEY')
42
+ .appendField('が')
43
+ .appendField(new Blockly.FieldDropdown(podDropdown), 'POD')
44
+ @setOutput(true, 'Boolean')
45
+ @setTooltip('')
46
+
47
+ Blockly.Ruby['<%= n %>'] = (block) ->
48
+ key = @getFieldValue('KEY')
49
+ pod = @getFieldValue('POD')
50
+ ["Input.key_#{pod}?(#{key})", Blockly.Ruby.ORDER_ATOMIC]
51
+
52
+ # 条件:マウスの[▼左ボタン]が[▼押された]
53
+ <% n = "#{category}_input_mouse_push_or_down" %>
54
+ Blockly.Blocks['<%= n %>'] =
55
+ init: ()->
56
+ mbDropdown = window.SmalrubyEditor.Sensing.MouseButtonDropdown
57
+ podDropdown = window.SmalrubyEditor.Sensing.PushOrDownDropdown
58
+
59
+ @setHelpUrl('')
60
+ @setColour(<%= color %>)
61
+ @appendDummyInput()
62
+ .appendField('マウスの')
63
+ .appendField(new Blockly.FieldDropdown(mbDropdown), 'MOUSE_BUTTON')
64
+ .appendField('が')
65
+ .appendField(new Blockly.FieldDropdown(podDropdown), 'POD')
66
+ @setOutput(true, 'Boolean')
67
+ @setTooltip('')
68
+
69
+ Blockly.Ruby['<%= n %>'] = (block) ->
70
+ mb = @getFieldValue('MOUSE_BUTTON')
71
+ pod = @getFieldValue('POD')
72
+ ["Input.mouse_#{pod}?(#{mb})", Blockly.Ruby.ORDER_ATOMIC]
73
+
74
+ # 変数:マウスのx座標
75
+ # 変数:マウスのy座標
76
+ <%
77
+ %w(x y).each do |suffix|
78
+ n = "#{category}_input_mouse_pos_#{suffix}"
79
+ %>
80
+
81
+ Blockly.Blocks['<%= n %>'] =
82
+ init: ()->
83
+ @setHelpUrl('')
84
+ @setColour(<%= color %>)
85
+ @appendDummyInput()
86
+ .appendField('マウスの<%= suffix %>座標')
87
+ @setOutput(true, 'Number')
88
+ @setTooltip('')
89
+
90
+ Blockly.Ruby['<%= n %>'] = (block) ->
91
+ ['Input.mouse_pos_<%= suffix %>', Blockly.Ruby.ORDER_ATOMIC]
92
+ <% end %>
93
+
94
+ # 条件:[▼キャラクター]に触れた
95
+ <% n = "#{category}_hit" %>
96
+ Blockly.Blocks['<%= n %>'] =
97
+ init: ()->
98
+ @setHelpUrl('')
99
+ @setColour(<%= color %>)
100
+ @appendDummyInput()
101
+ .appendField(new Blockly.FieldVariable('car1'), 'CHAR')
102
+ .appendField('に触れた')
103
+ @setOutput(true, 'Boolean')
104
+ @setTooltip('')
105
+
106
+ Blockly.Ruby['<%= n %>'] = (block) ->
107
+ char = Blockly.Ruby.variableDB_
108
+ .getName(block.getFieldValue('CHAR'), Blockly.Variables.NAME_TYPE)
109
+ Blockly.Ruby.characterMethodCallInput_('hit?', char)
110
+
111
+ # [ ]と聞いて待つ
112
+ <% n = "#{category}_ask" %>
113
+ Blockly.Blocks['<%= n %>'] =
114
+ init: ()->
115
+ @setHelpUrl('')
116
+ @setColour(<%= color %>)
117
+ @interpolateMsg('%1と聞いて待つ',
118
+ ['TEXT', ['String'], Blockly.ALIGN_RIGHT],
119
+ Blockly.ALIGN_RIGHT)
120
+ @setInputsInline(true)
121
+ @setPreviousStatement(true)
122
+ @setNextStatement(true)
123
+ @setTooltip('')
124
+
125
+ Blockly.Ruby['<%= n %>'] = (block) ->
126
+ text = Blockly.Ruby.valueToCode(@, 'TEXT', Blockly.Ruby.ORDER_NONE) || '""'
127
+ "ask(#{text})\n"
128
+
129
+ # 変数:答え
130
+ <% n = "#{category}_answer" %>
131
+ Blockly.Blocks['<%= n %>'] =
132
+ init: ()->
133
+ @setHelpUrl('')
134
+ @setColour(<%= color %>)
135
+ @appendDummyInput()
136
+ .appendField('答え')
137
+ @setOutput(true, 'String')
138
+ @setTooltip('')
139
+
140
+ Blockly.Ruby['<%= n %>'] = (block) ->
141
+ ['answer', Blockly.Ruby.ORDER_ATOMIC]
142
+
143
+ # 変数:タイマー
144
+ <% n = "#{category}_timer_count" %>
145
+ Blockly.Blocks['<%= n %>'] =
146
+ init: ()->
147
+ @setHelpUrl('')
148
+ @setColour(<%= color %>)
149
+ @appendDummyInput()
150
+ .appendField('タイマー')
151
+ @setOutput(true, 'Number')
152
+ @setTooltip('')
153
+
154
+ Blockly.Ruby['<%= n %>'] = (block) ->
155
+ ['timer.count', Blockly.Ruby.ORDER_ATOMIC]
156
+
157
+ # タイマーをリセット
158
+ <% n = "#{category}_timer_reset" %>
159
+ Blockly.Blocks['<%= n %>'] =
160
+ init: ()->
161
+ @setHelpUrl('')
162
+ @setColour(<%= color %>)
163
+ @appendDummyInput()
164
+ .appendField('タイマーをリセット')
165
+ @setPreviousStatement(true)
166
+ @setNextStatement(true)
167
+ @setTooltip('')
168
+
169
+ Blockly.Ruby['<%= n %>'] = (block) ->
170
+ 'timer.reset\n'
171
+
172
+ # 変数:[▼キャラクター]の[▼プロパティ]
173
+ <% n = "#{category}_character_property" %>
174
+ Blockly.Blocks['<%= n %>'] =
175
+ init: ()->
176
+ dropdown = [
177
+ ['x座標', 'x'],
178
+ ['y座標', 'y'],
179
+ ['向き', 'angle'],
180
+ ['コスチューム番号', 'costume_index'],
181
+ ['コスチューム名', 'costume'],
182
+ ['大きさ', 'scale'],
183
+ ['ボリューム', 'volume'],
184
+ ]
185
+
186
+ @setHelpUrl('')
187
+ @setColour(<%= color %>)
188
+ @appendDummyInput()
189
+ .appendField(new Blockly.FieldVariable('car1'), 'CHAR')
190
+ .appendField('の')
191
+ .appendField(new Blockly.FieldDropdown(dropdown), 'PROPERTY')
192
+ @setOutput(true, ['Number', 'String'])
193
+ @setTooltip('')
194
+
195
+ Blockly.Ruby['<%= n %>'] = (block) ->
196
+ char = Blockly.Ruby.variableDB_
197
+ .getName(block.getFieldValue('CHAR'), Blockly.Variables.NAME_TYPE)
198
+ property = @getFieldValue('PROPERTY')
199
+ c = Smalruby.Collections.CharacterSet.findWhere({ name: char })
200
+ Blockly.Ruby.characterMethodCallInput_(property, null, { object: c })
201
+
202
+ # 変数:現在の[▼時]
203
+ <% n = "#{category}_time_now" %>
204
+ Blockly.Blocks['<%= n %>'] =
205
+ init: ()->
206
+ dropdown = [
207
+ ['年', 'year'],
208
+ ['月', 'month'],
209
+ ['日付', 'day'],
210
+ ['曜日', 'wday'],
211
+ ['時', 'hour'],
212
+ ['分', 'min'],
213
+ ['秒', 'sec'],
214
+ ]
215
+
216
+ @setHelpUrl('')
217
+ @setColour(<%= color %>)
218
+ @appendDummyInput()
219
+ .appendField('現在の')
220
+ .appendField(new Blockly.FieldDropdown(dropdown), 'METHOD')
221
+ @setOutput(true, 'Number')
222
+ @setTooltip('')
223
+
224
+ Blockly.Ruby['<%= n %>'] = (block) ->
225
+ method = @getFieldValue('METHOD')
226
+ ["Time.now.#{method}", Blockly.Ruby.ORDER_ATOMIC]
227
+
228
+ # 変数:2000年からの日数
229
+ <% n = "#{category}_days_since_2000" %>
230
+ Blockly.Blocks['<%= n %>'] =
231
+ init: ()->
232
+ @setHelpUrl('')
233
+ @setColour(<%= color %>)
234
+ @appendDummyInput()
235
+ .appendField('2000年からの日数')
236
+ @setOutput(true, 'Number')
237
+ @setTooltip('')
238
+
239
+ Blockly.Ruby['<%= n %>'] = (block) ->
240
+ ['(Time.now - Time.mktime(2000, 1, 1)).to_i / 1.day',
241
+ Blockly.Ruby.ORDER_ATOMIC]