smalruby-editor 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


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

Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/LEGAL +4 -3
  3. data/app/assets/javascripts/blocks/character.js.coffee.erb +7 -3
  4. data/app/assets/javascripts/blocks/events.js.coffee.erb +7 -10
  5. data/app/assets/javascripts/blocks/hardware.js.coffee.erb +119 -31
  6. data/app/assets/javascripts/blocks/motion.js.coffee.erb +16 -20
  7. data/app/assets/javascripts/blocks/operators.js.coffee.erb +1 -1
  8. data/app/assets/javascripts/blocks/pen.js.coffee.erb +2 -1
  9. data/app/assets/javascripts/blocks/ruby.js.coffee.erb +3 -3
  10. data/app/assets/javascripts/blocks/sensing.js.coffee.erb +8 -8
  11. data/app/assets/javascripts/blocks/sound.js.coffee.erb +3 -1
  12. data/app/assets/javascripts/fix_blockly.js.erb +105 -0
  13. data/app/assets/javascripts/generators/ruby.js.coffee.erb +3 -0
  14. data/app/assets/javascripts/msg/en_us.js +67 -17
  15. data/app/assets/javascripts/msg/ja.js +151 -95
  16. data/app/assets/javascripts/{smalruby.js.coffee → smalruby.js.coffee.erb} +35 -16
  17. data/app/assets/javascripts/views/character_selector_view.js.coffee +2 -2
  18. data/app/assets/javascripts/views/{load_modal_view.js.coffee → load_modal_view.js.coffee.erb} +8 -2
  19. data/app/assets/javascripts/views/main_menu_view.js.coffee.erb +33 -48
  20. data/app/assets/javascripts/views/signin_modal_view.js.coffee.erb +43 -0
  21. data/app/assets/stylesheets/application.css +3 -1
  22. data/app/assets/stylesheets/toolbox.css.scss.erb +2 -56
  23. data/app/assets/stylesheets/toolbox_default.css.scss.erb +34 -0
  24. data/app/assets/stylesheets/toolbox_smalrubot_s1.css.scss.erb +31 -0
  25. data/app/assets/stylesheets/toolbox_smalrubot_v3.css.scss.erb +32 -0
  26. data/app/controllers/application_controller.rb +5 -0
  27. data/app/controllers/source_codes_controller.rb +6 -3
  28. data/app/helpers/application_helper.rb +12 -0
  29. data/app/helpers/editor_helper.rb +25 -0
  30. data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_s1_action.rb +13 -0
  31. data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_s1_action_with_sec.rb +14 -0
  32. data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_s1_ir_photoreflector_value.rb +29 -0
  33. data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_s1_led_turn_on_or_off.rb +22 -0
  34. data/app/views/editor/_block_tab.html.haml +7 -6
  35. data/app/views/editor/_reset_modal.html.haml +4 -4
  36. data/app/views/editor/_signin_modal.html.haml +8 -9
  37. data/app/views/editor/_toolbox_default.html.haml +504 -0
  38. data/app/views/editor/_toolbox_smalrubot_s1.html.haml +171 -0
  39. data/app/views/editor/_toolbox_smalrubot_v3.html.haml +177 -0
  40. data/app/views/editor/index.html.haml +12 -2
  41. data/app/views/layouts/application.html.erb +1 -0
  42. data/config/environments/production.rb +1 -0
  43. data/config/locales/en.yml +19 -16
  44. data/config/locales/ja.yml +28 -25
  45. data/demos/hardware_led.rb.xml +79 -79
  46. data/lib/smalruby_editor.rb +58 -0
  47. data/lib/smalruby_editor/config.rb +22 -0
  48. data/lib/smalruby_editor/version.rb +1 -1
  49. data/public/blockly/media/anon.jpeg +0 -0
  50. data/public/blockly/media/handclosed.cur +0 -0
  51. data/public/blockly/media/handdelete.cur +0 -0
  52. data/public/blockly/media/progress.gif +0 -0
  53. data/public/blockly/media/sprites.png +0 -0
  54. data/smalruby-editor.gemspec +2 -1
  55. data/spec/acceptance/base.feature +3 -3
  56. data/spec/acceptance/block_mode/blocks/hardware/smalrubot_s1_action.feature +107 -0
  57. data/spec/acceptance/block_mode/blocks/hardware/smalrubot_s1_action_with_sec.feature +151 -0
  58. data/spec/acceptance/block_mode/blocks/hardware/smalrubot_s1_ir_photoreflector_value.feature +100 -0
  59. data/spec/acceptance/block_mode/blocks/hardware/smalrubot_s1_led_turn_on_or_off.feature +73 -0
  60. data/spec/acceptance/ruby_mode/translate.feature +6 -6
  61. data/spec/acceptance/standalone/save.feature +3 -3
  62. data/spec/acceptance/standalone/signin.feature +1 -2
  63. data/spec/lib/smalruby_editor_spec.rb +21 -11
  64. data/spec/models/concerns/ruby_to_block/block/hardware__smalrubot_s1_spec.rb +279 -0
  65. data/vendor/assets/javascripts/blockly/blockly_compressed.js +995 -668
  66. data/vendor/assets/javascripts/blockly/blocks_compressed.js +138 -114
  67. data/vendor/assets/javascripts/blockly/msg/js/en_us.js +6 -6
  68. data/vendor/assets/javascripts/blockly/msg/js/ja.js +42 -28
  69. metadata +66 -25
  70. data/app/assets/javascripts/fix_blockly.js +0 -128
  71. data/app/assets/javascripts/views/signin_modal_view.js.coffee +0 -33
  72. data/app/views/editor/_toolbox.html.haml +0 -496
  73. data/public/blockly/media/trashbody.png +0 -0
  74. data/public/blockly/media/trashlid.png +0 -0
  75. data/public/blockly/media/tree.png +0 -0
@@ -0,0 +1,34 @@
1
+ <%
2
+ require 'smalruby_editor'
3
+ colors = SmalrubyEditor::COLORS
4
+
5
+ hues = [
6
+ colors[:motion],
7
+ colors[:looks],
8
+ colors[:sound],
9
+ colors[:pen],
10
+ colors[:data],
11
+ colors[:events],
12
+ colors[:control],
13
+ colors[:sensing],
14
+ colors[:operators],
15
+ colors[:etc],
16
+ ]
17
+
18
+ colors = hues.map { |h|
19
+ [SmalrubyEditor.hsv_to_rgb(h, 100, 80),
20
+ SmalrubyEditor.hsv_to_rgb(h, 100, 100)]
21
+ }
22
+
23
+ colors.each.with_index(1) do |(color, active_color), index|
24
+ %>
25
+ div[aria-level="1"][aria-posinset="<%= index %>"] {
26
+ .blocklyTreeRow {
27
+ background-color: #<%= color %> !important;
28
+ }
29
+
30
+ .blocklyTreeRow.blocklyTreeSelected {
31
+ background-color: #<%= active_color %> !important;
32
+ }
33
+ }
34
+ <% end %>
@@ -0,0 +1,31 @@
1
+ <%
2
+ require 'smalruby_editor'
3
+ colors = SmalrubyEditor::COLORS
4
+
5
+ hues = [
6
+ colors[:motion],
7
+ colors[:looks],
8
+ colors[:data],
9
+ colors[:events],
10
+ colors[:control],
11
+ colors[:sensing],
12
+ colors[:operators],
13
+ ]
14
+
15
+ colors = hues.map { |h|
16
+ [SmalrubyEditor.hsv_to_rgb(h, 100, 80),
17
+ SmalrubyEditor.hsv_to_rgb(h, 100, 100)]
18
+ }
19
+
20
+ colors.each.with_index(1) do |(color, active_color), index|
21
+ %>
22
+ div[aria-level="1"][aria-posinset="<%= index %>"] {
23
+ .blocklyTreeRow {
24
+ background-color: #<%= color %> !important;
25
+ }
26
+
27
+ .blocklyTreeRow.blocklyTreeSelected {
28
+ background-color: #<%= active_color %> !important;
29
+ }
30
+ }
31
+ <% end %>
@@ -0,0 +1,32 @@
1
+ <%
2
+ require 'smalruby_editor'
3
+ colors = SmalrubyEditor::COLORS
4
+
5
+ hues = [
6
+ colors[:motion],
7
+ colors[:looks],
8
+ colors[:data],
9
+ colors[:events],
10
+ colors[:control],
11
+ colors[:sensing],
12
+ colors[:operators],
13
+ colors[:etc],
14
+ ]
15
+
16
+ colors = hues.map { |h|
17
+ [SmalrubyEditor.hsv_to_rgb(h, 100, 80),
18
+ SmalrubyEditor.hsv_to_rgb(h, 100, 100)]
19
+ }
20
+
21
+ colors.each.with_index(1) do |(color, active_color), index|
22
+ %>
23
+ div[aria-level="1"][aria-posinset="<%= index %>"] {
24
+ .blocklyTreeRow {
25
+ background-color: #<%= color %> !important;
26
+ }
27
+
28
+ .blocklyTreeRow.blocklyTreeSelected {
29
+ background-color: #<%= active_color %> !important;
30
+ }
31
+ }
32
+ <% end %>
@@ -10,6 +10,7 @@ class ApplicationController < ActionController::Base
10
10
  helper_method :standalone?, :raspberrypi?
11
11
 
12
12
  before_filter :set_locale
13
+ before_filter :reload_config if Rails.env.development?
13
14
 
14
15
  private
15
16
 
@@ -51,4 +52,8 @@ class ApplicationController < ActionController::Base
51
52
  fail "#{self.class.name}##{action_name}はstandaloneモードのみの機能です"
52
53
  end
53
54
  end
55
+
56
+ def reload_config
57
+ SmalrubyEditor::Config.reload!
58
+ end
54
59
  end
@@ -69,7 +69,8 @@ class SourceCodesController < ApplicationController
69
69
  if /\Atext\/plain/ =~ info[:type]
70
70
  info[:data] = NKF.nkf('-w', f.read)
71
71
  else
72
- info[:error] = 'Rubyのプログラムではありません'
72
+ info[:error] = I18n.t('.not_ruby_program',
73
+ scope: 'controllers.source_codes')
73
74
  end
74
75
 
75
76
  render json: { source_code: info }, content_type: request.format
@@ -152,7 +153,9 @@ class SourceCodesController < ApplicationController
152
153
  end
153
154
  path = Pathname(s).expand_path.to_s
154
155
 
155
- fail 'すでに同じ名前のプログラムがあります' if File.exist?(path) && params[:force].blank?
156
+ if File.exist?(path) && params[:force].blank?
157
+ fail I18n.t('.exist', scope: 'controllers.source_codes')
158
+ end
156
159
 
157
160
  FileUtils.mkdir_p(File.dirname(path))
158
161
  File.open(path, 'w') do |f|
@@ -203,7 +206,7 @@ class SourceCodesController < ApplicationController
203
206
  else
204
207
  info = {
205
208
  filename: source_code_params[:filename],
206
- error: 'ありません',
209
+ error: I18n.t('.not_exist', scope: 'controllers.source_codes'),
207
210
  }
208
211
  end
209
212
 
@@ -14,4 +14,16 @@ module ApplicationHelper
14
14
  I18n.locale
15
15
  end
16
16
  end
17
+
18
+ # name of Toolbox
19
+ def toolbox_name
20
+ SmalrubyEditor::Config.toolbox_name || 'default'
21
+ end
22
+
23
+ # css name of Toolbox
24
+ def toolbox_css_name
25
+ SmalrubyEditor::Config.toolbox_css_name ||
26
+ SmalrubyEditor::Config.toolbox_name ||
27
+ 'default'
28
+ end
17
29
  end
@@ -17,6 +17,20 @@ module EditorHelper
17
17
  %(<field name="#{h name}">#{h value}</field>).html_safe
18
18
  end
19
19
 
20
+ # push or down field for Toolbox
21
+ #
22
+ # @param [String] name field name
23
+ # @param [String] value :push or :down
24
+ # @return [String] XML
25
+ def toolbox_pod_field(name = 'POD', value = :down)
26
+ if value == :down
27
+ pod = 'down'
28
+ else
29
+ pod = 'push'
30
+ end
31
+ %(<field name="#{h name}">#{pod}</field>).html_safe
32
+ end
33
+
20
34
  # ツールボックスのブロックに対して、PINの入力フィールドの値を設定する
21
35
  #
22
36
  # @param [String] value ピン
@@ -56,4 +70,15 @@ module EditorHelper
56
70
  </value>
57
71
  XML
58
72
  end
73
+
74
+ # I18n.t wrapper for Toolbox that's defualt scope is
75
+ # 'editor.toolbox'.
76
+ def toolbox_t(*args)
77
+ if args.length == 1 && args.first[0] == '.'
78
+ t(args.first[1..-1], scope: 'editor.toolbox')
79
+ else
80
+ t(*args)
81
+ end
82
+ end
83
+ alias_method :tt, :toolbox_t
59
84
  end
@@ -0,0 +1,13 @@
1
+ # -*- coding: utf-8 -*-
2
+ module RubyToBlock
3
+ module Block
4
+ class HardwareSmalrubotS1Action < HardwareSmalrubotV3Action
5
+ # rubocop:disable LineLength
6
+ blocknize '^\s*' + CHAR_RE +
7
+ 'smalrubot_s1\.' + ACTION_RE +
8
+ '\s*$',
9
+ statement: true, inline: true
10
+ # rubocop:enable LineLength
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ # -*- coding: utf-8 -*-
2
+ module RubyToBlock
3
+ module Block
4
+ class HardwareSmalrubotS1ActionWithSec < HardwareSmalrubotV3ActionWithSec
5
+ # rubocop:disable LineLength
6
+ blocknize '^\s*' + CHAR_RE +
7
+ 'smalrubot_s1\.' + ACTION_RE +
8
+ '\(\s*sec:\s*(\d+(?:\.\d+)?)\)' +
9
+ '\s*$',
10
+ statement: true, inline: true
11
+ # rubocop:enable LineLength
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,29 @@
1
+ module RubyToBlock
2
+ module Block
3
+ class HardwareSmalrubotS1IrPhotoreflectorValue < Value
4
+ include CharacterOperation
5
+ include HardwareOperation
6
+
7
+ # rubocop:disable LineLength
8
+ blocknize '^\s*' + CHAR_RE +
9
+ 'smalrubot_s1\.' +
10
+ LOR_RE + '_ir_photoreflector_value' +
11
+ '\s*$',
12
+ value: true
13
+ # rubocop:enable LineLength
14
+
15
+ def self.process_match_data(md, context)
16
+ md2 = regexp.match(md[type])
17
+
18
+ character = get_character(context, md2[1])
19
+ return false if context.receiver && context.receiver != character
20
+
21
+ block = new(fields: { LOR: md2[2] })
22
+ context.add_value(block)
23
+ block.character = character
24
+
25
+ true
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,22 @@
1
+ # -*- coding: utf-8 -*-
2
+ module RubyToBlock
3
+ module Block
4
+ class HardwareSmalrubotS1LedTurnOnOrOff < CharacterMethodCall
5
+ include HardwareOperation
6
+
7
+ # rubocop:disable LineLength
8
+ blocknize '^\s*' + CHAR_RE +
9
+ 'smalrubot_s1\.(turn_on|turn_off)_(blue|white)_led' +
10
+ '\s*$',
11
+ statement: true, inline: true
12
+ # rubocop:enable LineLength
13
+
14
+ def self.process_match_data(md, context)
15
+ md2 = regexp.match(md[type])
16
+ block = new(fields: { COLOUR: md2[3], OOO: md2[2] })
17
+ add_character_method_call_block(context, md2[1], block)
18
+ true
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,7 +1,7 @@
1
1
  #block-tab-right-pane{:class => 'right-pane'}
2
2
  #blockly-div
3
3
 
4
- = render 'toolbox'
4
+ = render "toolbox_#{toolbox_name}"
5
5
 
6
6
  #block-tab-left-pane{:class => 'left-pane'}
7
7
  #selectors-container
@@ -16,11 +16,12 @@
16
16
  #selectors-tab-content{:class => 'tab-content'}
17
17
  #character-selector-tab{:class => 'tab-pane active selector-tab'}
18
18
  #character-selector-character-set
19
- .item
20
- %a#add-character-button{:class => 'character'}
21
- %i.icon-plus-sign-alt
22
- %br
23
- = t('.new_character')
19
+ - if !SmalrubyEditor::Config.enabled?('disabled_new_character')
20
+ .item
21
+ %a#add-character-button{:class => 'character'}
22
+ %i.icon-plus-sign-alt
23
+ %br
24
+ = t('.new_character')
24
25
 
25
26
  #scene-selector-tab{:class => 'tab-pane selector-tab'}
26
27
  .item
@@ -2,14 +2,14 @@
2
2
  role: "dialog", :"aria-hidden" => "true"}
3
3
  .modal-header
4
4
  %h3
5
- 本当にリセットしますか?
5
+ = t('.title')
6
6
  .modal-body
7
7
  %p
8
- 作成中のプログラムが消えてしまうよ!
8
+ = t('.message')
9
9
  .modal-footer
10
10
  %button#reset-modal-cancel-button.btn{:"data-dismiss" => "modal", :"aria-hidden" => "true"}<
11
11
  %i.icon-remove
12
- やめる
12
+ = t('common.cancel')
13
13
  %button#reset-modal-ok-button.btn{class: "btn-primary"}<
14
14
  %i.icon-off
15
- リセット
15
+ = t('common.reset')
@@ -3,20 +3,19 @@
3
3
  .modal-body
4
4
  %h4
5
5
  %i.icon-info-sign
6
- あなたの名前をいれて、
7
- %br
8
- ほかの人のプログラムとまざらないようにしよう♪
6
+ = raw(t('.message'))
9
7
  %form#signin-modal-form.form-horizontal
10
8
  .control-group{for: "username"}
11
9
  %label.control-label{for: "signin-modal-username"}<
12
- 名前
10
+ = t('common.name')
13
11
  .controls
14
- %input#signin-modal-username.input-large{name: "username", type: "text", placeholder: "名前、生徒番号、ニックネームなど"}
12
+ %input#signin-modal-username.input-large{name: "username", type: "text", placeholder: t('.username_placeholder')}
15
13
 
16
14
  .modal-footer
17
- %button#signin-modal-cancel-button.cancel-button{class: "btn", :"data-dismiss" => "modal", :"aria-hidden" => "true"}<
18
- %i.icon-remove
19
- やめる
15
+ - if !SmalrubyEditor::Config.enabled?('must_signin')
16
+ %button#signin-modal-cancel-button.cancel-button{class: "btn", :"data-dismiss" => "modal", :"aria-hidden" => "true"}<
17
+ %i.icon-remove
18
+ = t('common.cancel')
20
19
  %button#signin-modal-ok-button.ok-button{class: "btn btn-primary"}<
21
20
  %i.icon-circle-blank
22
- ログイン
21
+ = t('common.login')
@@ -0,0 +1,504 @@
1
+ %xml{:id => 'toolbox', :style => 'display: none'}
2
+ - category = 'motion'
3
+ %category{:name => tt('.motion')}
4
+ -# ( )歩動かす
5
+ %block{:type => "#{category}_move"}
6
+ = toolbox_number_value('STEP', 10)
7
+
8
+ -# 時計回りに( )度回す
9
+ %block{:type => "#{category}_rotate_right"}
10
+ = toolbox_number_value('ANGLE', 15)
11
+
12
+ -# 反時計回りに( )度回す
13
+ %block{:type => "#{category}_rotate_left"}
14
+ = toolbox_number_value('ANGLE', 15)
15
+
16
+ -# ( )度に向ける
17
+ %block{:type => "#{category}_set_angle"}
18
+ = toolbox_number_value('ANGLE', 90)
19
+
20
+ -# [▼]へ向ける
21
+ %block{:type => "#{category}_point_towards_character"}
22
+
23
+ -# マウスポインターへ向ける
24
+ %block{:type => "#{category}_point_towards_mouse"}
25
+
26
+ -# x座標を( )、y座標を( )にする
27
+ %block{:type => "#{category}_set_x_y"}
28
+ = toolbox_number_value('X')
29
+ = toolbox_number_value('Y')
30
+
31
+ -# マウスポインターへ行く
32
+ %block{:type => "#{category}_go_to_mouse"}
33
+
34
+ -# [▼]へ行く
35
+ %block{:type => "#{category}_go_to_character"}
36
+
37
+ -# ( )秒でx座標を( )、y座標を( )に変える
38
+ -#%block{:type => "#{category}_glide_to_x_y"}
39
+ -# = toolbox_number_value('SEC', 1)
40
+ -# = toolbox_number_value('X')
41
+ -# = toolbox_number_value('Y')
42
+
43
+ -# x座標を( )ずつ変える
44
+ %block{:type => "#{category}_change_x_by"}
45
+ = toolbox_number_value('X', 10)
46
+
47
+ -# x座標を( )にする
48
+ %block{:type => "#{category}_set_x"}
49
+ = toolbox_number_value('X', 0)
50
+
51
+ -# y座標を( )ずつ変える
52
+ %block{:type => "#{category}_change_y_by"}
53
+ = toolbox_number_value('Y', 10)
54
+
55
+ -# y座標を( )にする
56
+ %block{:type => "#{category}_set_y"}
57
+ = toolbox_number_value('Y', 0)
58
+
59
+ -# もし端に着いたら、跳ね返る
60
+ %block{:type => "#{category}_turn_if_reach_wall"}
61
+
62
+ -# 跳ね返る
63
+ %block{:type => "#{category}_turn"}
64
+
65
+ -# [▼水平(X)]方向に跳ね返る
66
+ %block{:type => "#{category}_turn_xy"}
67
+
68
+ -# 回転方法を[▼]にする
69
+ %block{:type => "#{category}_set_rotation_style"}
70
+
71
+ -# 変数:x座標
72
+ %block{:type => "#{category}_self_x"}
73
+
74
+ -# 変数:y座標
75
+ %block{:type => "#{category}_self_y"}
76
+
77
+ -# 変数:向き
78
+ %block{:type => "#{category}_self_angle"}
79
+
80
+ - if SmalrubyEditor::Config.enabled?('enabled_hardware_blocks_on_default')
81
+ - category = 'hardware'
82
+ - subcategory = 'servo'
83
+ -# サーボ[▼PIN]を( )度(5~180)にする
84
+ %block{:type => "#{category}_#{subcategory}_set_position"}
85
+ = toolbox_number_value('POS', 90)
86
+
87
+ - subcategory = 'two_wheel_drive_car'
88
+ -# 2WD車[▼PIN]を( )秒[▼コマンド]
89
+ %block{:type => "#{category}_#{subcategory}_run"}
90
+ = toolbox_pin_field('D5')
91
+ = toolbox_number_value('SEC', 1)
92
+ %value{:name => 'COMMAND'}
93
+ %block{:type => "#{category}_#{subcategory}_commands"}
94
+
95
+ -# [▼コマンド]
96
+ %block{:type => "#{category}_#{subcategory}_commands"}
97
+ %field{:name => 'COMMAND'}<
98
+ forward
99
+
100
+ - if SmalrubyEditor::Config.enabled?('enabled_2wd_car_blocks_on_default')
101
+ -# 2WD車[▼PIN]を進める
102
+ %block{:type => "#{category}_#{subcategory}_forward"}
103
+ = toolbox_pin_field('D5')
104
+
105
+ -# 2WD車[▼PIN]をバックさせる
106
+ %block{:type => "#{category}_#{subcategory}_backward"}
107
+ = toolbox_pin_field('D5')
108
+
109
+ -# 2WD車[▼PIN]を左に曲げる
110
+ %block{:type => "#{category}_#{subcategory}_turn_left"}
111
+ = toolbox_pin_field('D5')
112
+
113
+ -# 2WD車[▼PIN]を右に曲げる
114
+ %block{:type => "#{category}_#{subcategory}_turn_right"}
115
+ = toolbox_pin_field('D5')
116
+
117
+ -# 2WD車[▼PIN]を止める
118
+ %block{:type => "#{category}_#{subcategory}_stop"}
119
+ = toolbox_pin_field('D5')
120
+
121
+ -# 2WD車[▼PIN]の[▼LOR]の速度を<SPEED>%にする
122
+ %block{:type => "#{category}_#{subcategory}_set_speed"}
123
+ = toolbox_pin_field('D5')
124
+ = toolbox_number_value('SPEED', 100)
125
+
126
+ - subcategory = 'motor_driver'
127
+ -# (モータードライバ[▼PIN]で)モーターを[▼正転させる]
128
+ %block{:type => "#{category}_#{subcategory}"}
129
+ = toolbox_pin_field('D6')
130
+ %field{:name => 'METHOD'}<
131
+ forward
132
+
133
+ -# (モータードライバ[▼PIN]の)モーターの速度を<SPEED>%にする
134
+ %block{:type => "#{category}_#{subcategory}_set_speed"}
135
+ = toolbox_pin_field('D6')
136
+ = toolbox_number_value('SPEED', 100)
137
+
138
+ - if SmalrubyEditor::Config.enabled?('enabled_smalrubot_v3_blocks_on_default')
139
+ - subcategory = 'smalrubot_v3'
140
+ %block{type: "#{category}_#{subcategory}_action"}
141
+ %field{name: 'ACTION'}<
142
+ forward
143
+
144
+ %block{type: "#{category}_#{subcategory}_action_with_sec"}
145
+ %field{name: 'ACTION'}<
146
+ forward
147
+ = toolbox_number_value('SEC', 0.5)
148
+
149
+ %block{type: "#{category}_#{subcategory}_motor_set_speed"}
150
+ = toolbox_number_value('SPEED', 100)
151
+
152
+ - if SmalrubyEditor::Config.enabled?('enabled_smalrubot_s1_blocks_on_default')
153
+ - subcategory = 'smalrubot_s1'
154
+ %block{type: "#{category}_#{subcategory}_action"}
155
+ %field{name: 'ACTION'}<
156
+ forward
157
+
158
+ %block{type: "#{category}_#{subcategory}_action_with_sec"}
159
+ %field{name: 'ACTION'}<
160
+ forward
161
+ = toolbox_number_value('SEC', 0.5)
162
+
163
+ - category = 'looks'
164
+ %category{:name => tt('.looks')}
165
+ -# [ ]と( )秒言う
166
+ -#%block{:type => "#{category}_say_second"}
167
+ -# = toolbox_text_value('TEXT', 'こんにちは!')
168
+ -# = toolbox_number_value('SEC', 2)
169
+
170
+ -# [ ]と言う
171
+ %block{:type => "#{category}_say"}
172
+ = toolbox_text_value('TEXT', tt('.hello'))
173
+
174
+ -# [ ]と( )秒考える
175
+ -#%block{:type => "#{category}_think_second"}
176
+ -# = toolbox_text_value('TEXT', 'ふーん')
177
+ -# = toolbox_number_value('SEC', 2)
178
+
179
+ -# [ ]と考える
180
+ -#%block{:type => "#{category}_think"}
181
+ -# = toolbox_text_value('TEXT', 'ふーん')
182
+
183
+ -# 表示する
184
+ %block{:type => "#{category}_show"}
185
+
186
+ -# 隠す
187
+ %block{:type => "#{category}_hide"}
188
+
189
+ -# 消滅する
190
+ %block{:type => "#{category}_vanish"}
191
+
192
+ -# 大きさを( )%ずつ変える
193
+ -#%block{:type => "#{category}_change_scale_by"}
194
+ -# = toolbox_number_value('SCALE', 10)
195
+
196
+ -# 大きさを( )%にする
197
+ -#%block{:type => "#{category}_set_scale"}
198
+ -# = toolbox_number_value('SCALE', 100)
199
+
200
+ -# 変数:大きさ
201
+ -#%block{:type => "#{category}_self_scale"}
202
+
203
+ -# [▼プリセット画像]
204
+ -#%block{:type => "#{category}_preset_images"}
205
+
206
+ - if SmalrubyEditor::Config.enabled?('enabled_hardware_blocks_on_default')
207
+ - category = 'hardware'
208
+ - subcategory = 'led'
209
+ -# LED[▼PIN]をオンにする
210
+ %block{:type => "#{category}_#{subcategory}_turn_on"}
211
+
212
+ -# LED[▼PIN]をオフにする
213
+ %block{:type => "#{category}_#{subcategory}_turn_off"}
214
+
215
+ - subcategory = 'rgb_led'
216
+ -# RGB LED[▼アノード]コモン[▼PIN]を[カラー]にする
217
+ %block{:type => "#{category}_#{subcategory}_set_color"}
218
+
219
+ -# RGB LED[▼アノード]コモン[▼PIN]をオフにする
220
+ %block{:type => "#{category}_#{subcategory}_turn_off"}
221
+
222
+ - subcategory = 'seven_segment_display'
223
+ -# 7セグディスプレイに[▼0-9]を表示する
224
+ %block{:type => "#{category}_#{subcategory}_show"}
225
+
226
+ -# 7セグディスプレイをオフにする
227
+ %block{:type => "#{category}_#{subcategory}_off"}
228
+
229
+ - subcategory = 'lcd'
230
+ -# LCDに( )を表示する
231
+ %block{:type => "#{category}_#{subcategory}_puts"}
232
+ = toolbox_text_value('TEXT', 'Hello')
233
+
234
+ -# LCDをクリアする
235
+ %block{:type => "#{category}_#{subcategory}_clear"}
236
+
237
+ - if SmalrubyEditor::Config.enabled?('enabled_smalrubot_v3_blocks_on_default')
238
+ - subcategory = 'smalrubot_v3'
239
+ %block{type: "#{category}_#{subcategory}_led_turn_on_or_off"}
240
+ %field{name: 'COLOUR'}<
241
+ red
242
+ %field{name: 'OOO'}<
243
+ turn_on
244
+
245
+ - if SmalrubyEditor::Config.enabled?('enabled_smalrubot_s1_blocks_on_default')
246
+ - subcategory = 'smalrubot_s1'
247
+ %block{type: "#{category}_#{subcategory}_led_turn_on_or_off"}
248
+ %field{name: 'OOO'}<
249
+ turn_on
250
+
251
+ - category = 'sound'
252
+ %category{:name => tt('.sound')}
253
+ -# [▼プリセット音声]の音を鳴らす
254
+ %block{:type => "#{category}_play"}
255
+ %value{:name => 'NAME'}
256
+ %block{:type => "#{category}_preset_sounds"}
257
+
258
+ -# すべての音を止める
259
+ -#%block{:type => "#{category}_stop"}
260
+
261
+ -# 変数:ボリューム
262
+ -#%block{:type => "#{category}_volume"}
263
+
264
+ - category = 'pen'
265
+ %category{:name => tt('.pen')}
266
+ -# ペンを下ろす
267
+ %block{:type => "#{category}_down_pen"}
268
+
269
+ -# ペンを上げる
270
+ %block{:type => "#{category}_up_pen"}
271
+
272
+ -# ペンの色を[カラー]にする
273
+ %block{:type => "#{category}_set_pen_color"}
274
+
275
+ %category{name: tt('.data'), custom: 'VARIABLE'}
276
+
277
+ - category = 'events'
278
+ %category{:name => tt('.events')}
279
+ -# まずは
280
+ %block{:type => "#{category}_on_start"}
281
+
282
+ -# キーボードの[▼キー]が[▼押された/押され続けている]とき
283
+ %block{:type => "#{category}_on_key_push_or_down"}
284
+ = toolbox_key_field
285
+ = toolbox_pod_field
286
+
287
+ -# キャラクターがクリックされたとき
288
+ %block{:type => "#{category}_on_click"}
289
+
290
+ -# [▼キャラクター]にぶつかったとき
291
+ %block{:type => "#{category}_on_hit"}
292
+
293
+ - category = 'control'
294
+ %category{:name => tt('.control')}
295
+ -# ( )秒待つ
296
+ %block{:type => "#{category}_sleep"}
297
+ = toolbox_number_value('SEC', 1)
298
+
299
+ -# ほんの少し待つ
300
+ %block{:type => "#{category}_await"}
301
+
302
+ -# ( )回繰り返す
303
+ %block{:type => "#{category}_times"}
304
+ = toolbox_number_value('COUNT', 10)
305
+
306
+ -# ずっと
307
+ %block{:type => "#{category}_loop"}
308
+
309
+ -# もし< >なら
310
+ %block{:type => "#{category}_if"}
311
+
312
+ -# もし< >なら~でなければ
313
+ %block{:type => "#{category}_if_else"}
314
+
315
+ -# < >まで待つ
316
+ %block{:type => "#{category}_await_until"}
317
+
318
+ -# < >まで繰り返す
319
+ %block{:type => "#{category}_until"}
320
+
321
+ -# 繰り返しから脱出する
322
+ %block{:type => "#{category}_break"}
323
+
324
+ -# 次の繰り返しにジャンプする
325
+ %block{:type => "#{category}_next"}
326
+
327
+ -# 現在の繰り返しをやり直す
328
+ %block{:type => "#{category}_redo"}
329
+
330
+ - category = 'sensing'
331
+ %category{:name => tt('.sensing')}
332
+ -# 条件:[▼キャラクター]に触れた
333
+ %block{:type => "#{category}_hit"}
334
+
335
+ -# 条件:端に触れた
336
+ %block{:type => "#{category}_reach_wall"}
337
+
338
+ -# [ ]と聞いて待つ
339
+ -#%block{:type => "#{category}_ask"}
340
+ -# = toolbox_text_value('TEXT', 'あなたのお名前は?')
341
+
342
+ -# 変数:答え
343
+ -#%block{:type => "#{category}_answer"}
344
+
345
+ -# 条件:キーボードの[▼キー]が[▼押された]
346
+ %block{:type => "#{category}_input_key_push_or_down"}
347
+ = toolbox_key_field
348
+ = toolbox_pod_field
349
+
350
+ -# 条件:マウスの[▼左ボタン]が[▼押された]
351
+ %block{:type => "#{category}_input_mouse_push_or_down"}
352
+ = toolbox_pod_field
353
+
354
+ -# 変数:マウスのx座標
355
+ %block{:type => "#{category}_input_mouse_pos_x"}
356
+
357
+ -# 変数:マウスのy座標
358
+ %block{:type => "#{category}_input_mouse_pos_y"}
359
+
360
+ -# 変数:タイマー
361
+ -#%block{:type => "#{category}_timer_count"}
362
+
363
+ -# タイマーをリセット
364
+ -#%block{:type => "#{category}_timer_reset"}
365
+
366
+ -# 変数:[▼キャラクター]の[▼プロパティ]
367
+ %block{:type => "#{category}_character_property"}
368
+
369
+ -# 変数:現在の[▼時]
370
+ %block{:type => "#{category}_time_now"}
371
+
372
+ -# 変数:2000年からの日数
373
+ %block{:type => "#{category}_days_since_2000"}
374
+
375
+ - if SmalrubyEditor::Config.enabled?('enabled_hardware_blocks_on_default')
376
+ - category = 'hardware'
377
+ -# センサー[▼PIN]
378
+ %block{:type => "#{category}_sensor_value"}
379
+ = toolbox_pin_field('A0')
380
+
381
+ -# 条件:ボタン[▼PIN]が[▼押された]
382
+ %block{:type => "#{category}_button_pressed_or_released"}
383
+ = toolbox_pin_field('D3')
384
+
385
+ -# 2WD車[▼PIN]の[▼LOR]の速度%
386
+ %block{:type => "#{category}_two_wheel_drive_car_speed"}
387
+ = toolbox_pin_field('D5')
388
+
389
+ -# (モータードライバ[▼PIN]の)モーターの速度(%)
390
+ %block{:type => "#{category}_motor_driver_speed"}
391
+ = toolbox_pin_field('D6')
392
+
393
+ - if SmalrubyEditor::Config.enabled?('enabled_smalrubot_v3_blocks_on_default')
394
+ - subcategory = 'smalrubot_v3'
395
+ %block{type: "#{category}_#{subcategory}_touch_sensor_pressed_or_released"}
396
+ %block{type: "#{category}_#{subcategory}_light_sensor_value"}
397
+ %block{type: "#{category}_#{subcategory}_motor_speed"}
398
+
399
+ - if SmalrubyEditor::Config.enabled?('enabled_smalrubot_s1_blocks_on_default')
400
+ - category = 'hardware'
401
+ - subcategory = 'smalrubot_s1'
402
+ %block{type: "#{category}_#{subcategory}_ir_photoreflector_value"}
403
+
404
+ - category = 'operators'
405
+ %category{:name => tt('.operators')}
406
+ -# 数値
407
+ %block{:type => 'math_number'}
408
+ %field{:name => 'NUM'}<
409
+ 0
410
+
411
+ -# テキスト
412
+ %block{:type => 'text'}
413
+ %field{:name => 'TEXT'}<
414
+ = tt('.text')
415
+
416
+ -# 変数:( ) + ( )
417
+ %block{:type => "#{category}_add"}
418
+
419
+ -# 変数:( ) - ( )
420
+ %block{:type => "#{category}_minus"}
421
+
422
+ -# 変数:( ) * ( )
423
+ %block{:type => "#{category}_multiply"}
424
+
425
+ -# 変数:( ) / ( )
426
+ %block{:type => "#{category}_divide"}
427
+
428
+ -# 変数:( )から( )までの乱数
429
+ %block{:type => "#{category}_rand"}
430
+ = toolbox_number_value('A', 1)
431
+ = toolbox_number_value('B', 10)
432
+
433
+ -# 条件:( ) < ( )
434
+ %block{:type => "#{category}_compare_lt"}
435
+
436
+ -# 条件:( ) <= ( )
437
+ %block{:type => "#{category}_compare_lte"}
438
+
439
+ -# 条件:( ) = ( )
440
+ %block{:type => "#{category}_compare_eq"}
441
+
442
+ -# 条件:( ) >= ( )
443
+ %block{:type => "#{category}_compare_gte"}
444
+
445
+ -# 条件:( ) > ( )
446
+ %block{:type => "#{category}_compare_gt"}
447
+
448
+ -# 条件:< > かつ < >
449
+ %block{:type => "#{category}_and"}
450
+
451
+ -# 条件:< > または < >
452
+ %block{:type => "#{category}_or"}
453
+
454
+ -# 条件:< > ではない
455
+ %block{:type => "#{category}_negate"}
456
+
457
+ -# 変数:( )の( )番目
458
+ %block{:type => "#{category}_index_of"}
459
+ = toolbox_text_value('A', tt('.world'))
460
+ = toolbox_number_value('INDEX', 1)
461
+
462
+ -# 変数:( )の長さ
463
+ %block{:type => "#{category}_length"}
464
+ = toolbox_text_value('A', tt('.world'))
465
+
466
+ -# 変数:( )を( )で割った余り
467
+ %block{:type => "#{category}_modulo"}
468
+ = toolbox_number_value('A', 5)
469
+ = toolbox_number_value('B', 2)
470
+
471
+ -# 変数:( )を四捨五入
472
+ %block{:type => "#{category}_round"}
473
+ = toolbox_number_value('A', 0.5)
474
+
475
+ -# 変数:( )の[▼数学関数]
476
+ %block{:type => "#{category}_math_method"}
477
+ = toolbox_number_value('NUM', 9)
478
+ %field{:name => 'METHOD'}<
479
+ Math.sqrt(%num%)
480
+
481
+ -# 条件:真
482
+ %block{:type => "#{category}_true"}
483
+
484
+ -# 条件:偽
485
+ %block{:type => "#{category}_false"}
486
+
487
+ %category{:name => tt('.etc')}
488
+ - category = 'ruby'
489
+ -# 文
490
+ %block{:type => "#{category}_statement"}
491
+
492
+ -# 式
493
+ %block{:type => "#{category}_expression"}
494
+
495
+ -# コメント
496
+ %block{:type => "#{category}_comment"}
497
+
498
+ -# p
499
+ %block{:type => "#{category}_p"}
500
+
501
+ - if SmalrubyEditor::Config.enabled?('enabled_hardware_blocks_on_default')
502
+ - category = 'hardware'
503
+ -# ハードウェアを準備する
504
+ %block{:type => "#{category}_init_hardware"}