smalruby-editor 0.2.6 → 0.2.7

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 (97) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -0
  3. data/Guardfile +2 -0
  4. data/app/assets/javascripts/blocks/hardware.js.coffee.erb +1 -1
  5. data/app/assets/javascripts/fix_blockly.js.erb +0 -50
  6. data/app/assets/javascripts/generators/ruby.js.coffee.erb +18 -4
  7. data/app/assets/javascripts/models/source_code.js +1 -1
  8. data/app/assets/javascripts/msg/en_us.js +1 -0
  9. data/app/assets/javascripts/msg/ja.js +4 -0
  10. data/app/assets/javascripts/smalruby.js.coffee.erb +50 -6
  11. data/app/assets/javascripts/views/main_menu_view.js.coffee.erb +14 -4
  12. data/app/assets/javascripts/views/preference_modal_view.js.coffee.erb +71 -0
  13. data/app/assets/javascripts/views/signin_modal_view.js.coffee.erb +5 -4
  14. data/app/assets/stylesheets/application.css +1 -0
  15. data/app/assets/stylesheets/preference-modal.css.scss +22 -0
  16. data/app/assets/stylesheets/toolbox.css.scss.erb +36 -0
  17. data/app/controllers/application_controller.rb +20 -4
  18. data/app/controllers/editor_controller.rb +4 -0
  19. data/app/controllers/sessions_controller.rb +7 -4
  20. data/app/controllers/source_codes_controller.rb +2 -2
  21. data/app/controllers/users_controller.rb +22 -0
  22. data/app/helpers/application_helper.rb +4 -4
  23. data/app/helpers/sessions_helper.rb +0 -0
  24. data/app/helpers/users_helper.rb +10 -0
  25. data/app/models/concerns/ruby_to_block/block/hardware_init_hardware.rb +0 -6
  26. data/app/models/concerns/ruby_to_block/block/hardware_operation.rb +0 -0
  27. data/app/models/preference.rb +71 -0
  28. data/app/models/source_code.rb +4 -0
  29. data/app/models/user.rb +26 -0
  30. data/app/views/editor/_block_tab.html.haml +5 -6
  31. data/app/views/editor/_load_modal.html.haml +2 -2
  32. data/app/views/editor/_preference_modal.html.haml +16 -0
  33. data/app/views/editor/_signin_modal.html.haml +1 -1
  34. data/app/views/editor/_toolbox_default.html.haml +86 -79
  35. data/app/views/editor/{_toolbox_raspberrypi.html.haml → _toolbox_smalrubot.html.haml} +72 -105
  36. data/app/views/editor/_toolbox_smalrubot_s1.html.haml +1 -196
  37. data/app/views/editor/_toolbox_smalrubot_v3.html.haml +1 -196
  38. data/app/views/editor/index.html.haml +11 -4
  39. data/app/views/editor/toolbox.html.haml +1 -0
  40. data/app/views/layouts/application.html.erb +1 -1
  41. data/app/views/users/preferences.html.haml +34 -0
  42. data/config/application.rb +1 -1
  43. data/config/locales/en.yml +30 -0
  44. data/config/locales/ja.yml +30 -0
  45. data/config/routes.rb +4 -57
  46. data/db/migrate/20150513061200_create_users.rb +10 -0
  47. data/db/migrate/20150513061250_add_index_name_on_users.rb +9 -0
  48. data/db/schema.rb +10 -1
  49. data/lib/smalruby_editor.rb +22 -24
  50. data/lib/smalruby_editor/version.rb +1 -1
  51. data/smalruby-editor.gemspec +0 -0
  52. data/spec/acceptance/block_mode/blocks/hardware/button_pressed_or_released.feature +2 -0
  53. data/spec/acceptance/block_mode/blocks/hardware/init_hardware.feature +1 -0
  54. data/spec/acceptance/block_mode/blocks/hardware/led_turn_off.feature +11 -1
  55. data/spec/acceptance/block_mode/blocks/hardware/led_turn_on.feature +11 -1
  56. data/spec/acceptance/block_mode/blocks/hardware/motor_driver.feature +7 -1
  57. data/spec/acceptance/block_mode/blocks/hardware/motor_driver_speed.feature +2 -0
  58. data/spec/acceptance/block_mode/blocks/hardware/rgb_led_set_color.feature +9 -12
  59. data/spec/acceptance/block_mode/blocks/hardware/rgb_led_turn_off.feature +9 -12
  60. data/spec/acceptance/block_mode/blocks/hardware/sensor_value.feature +59 -60
  61. data/spec/acceptance/block_mode/blocks/hardware/servo_set_position.feature +76 -67
  62. data/spec/acceptance/block_mode/blocks/hardware/smalrubot_s1_action.feature +9 -12
  63. data/spec/acceptance/block_mode/blocks/hardware/smalrubot_s1_action_with_sec.feature +9 -11
  64. data/spec/acceptance/block_mode/blocks/hardware/smalrubot_s1_dc_motor_power_ratio.feature +11 -12
  65. data/spec/acceptance/block_mode/blocks/hardware/smalrubot_s1_led_turn_on_or_off.feature +9 -10
  66. data/spec/acceptance/block_mode/blocks/hardware/smalrubot_v3_action.feature +9 -12
  67. data/spec/acceptance/block_mode/blocks/hardware/smalrubot_v3_action_with_sec.feature +9 -11
  68. data/spec/acceptance/block_mode/blocks/hardware/smalrubot_v3_dc_motor_power_ratio.feature +11 -12
  69. data/spec/acceptance/block_mode/blocks/hardware/smalrubot_v3_led_turn_on_or_off.feature +9 -12
  70. data/spec/acceptance/block_mode/blocks/hardware/smalrubot_v3_sensor_value.feature +11 -12
  71. data/spec/acceptance/block_mode/blocks/hardware/two_wheel_drive_car.feature +7 -1
  72. data/spec/acceptance/block_mode/blocks/hardware/two_wheel_drive_car_speed.feature +2 -0
  73. data/spec/acceptance/standalone/preference.feature +92 -0
  74. data/{demos → spec/fixtures/files}/hardware_led.rb.xml +0 -0
  75. data/spec/javascripts/models/source_code_spec.coffee +0 -0
  76. data/spec/models/concerns/ruby_to_block/block/hardware__smalrubot_spec.rb +1 -1
  77. data/spec/models/concerns/ruby_to_block/block/hardware_spec.rb +4 -4
  78. data/spec/models/concerns/ruby_to_block_spec.rb +1 -1
  79. data/spec/models/source_code_spec.rb +1 -11
  80. data/spec/spec_helper.rb +8 -0
  81. data/spec/steps/base_steps.rb +68 -16
  82. data/spec/steps/standalone_steps.rb +21 -0
  83. data/spec/steps/text_editor_steps.rb +8 -8
  84. data/spec/support/feature_helper.rb +13 -0
  85. data/vendor/assets/javascripts/blockly/blockly_compressed.js +500 -454
  86. data/vendor/assets/javascripts/blockly/blocks_compressed.js +29 -28
  87. data/vendor/assets/javascripts/blockly/msg/js/ja.js +2 -1
  88. metadata +33 -35
  89. data/app/assets/stylesheets/toolbox_default.css.scss.erb +0 -34
  90. data/app/assets/stylesheets/toolbox_raspberrypi.css.scss.erb +0 -32
  91. data/app/assets/stylesheets/toolbox_smalrubot_s1.css.scss.erb +0 -32
  92. data/app/assets/stylesheets/toolbox_smalrubot_v3.css.scss.erb +0 -32
  93. data/demos/adjust_2wd_car.rb.xml +0 -179
  94. data/lib/smalruby_editor/config.rb +0 -24
  95. data/spec/controllers/editor_controller_spec.rb +0 -12
  96. data/spec/controllers/sessions_controller_spec.rb +0 -74
  97. data/spec/helpers/sessions_helper_spec.rb +0 -15
@@ -12,6 +12,7 @@
12
12
  *= require_self
13
13
  *= require editor
14
14
  *= require load-modal
15
+ *= require preference-modal
15
16
  *= require toolbox
16
17
  */
17
18
 
@@ -0,0 +1,22 @@
1
+ #preference-modal {
2
+ width: 700px;
3
+ margin-left: -(700px / 2);
4
+
5
+ .modal-body {
6
+ form {
7
+ margin-bottom: 0;
8
+
9
+ .control-group {
10
+ margin-bottom: 8px;
11
+
12
+ .control-label {
13
+ /*width: 100px;*/
14
+ }
15
+
16
+ .controls {
17
+ /*margin-left: 100px;*/
18
+ }
19
+ }
20
+ }
21
+ }
22
+ }
@@ -1,3 +1,7 @@
1
+ <%
2
+ require 'smalruby_editor'
3
+ colors = SmalrubyEditor::COLORS
4
+ %>
1
5
  div.blocklyTreeRoot {
2
6
  padding: 0;
3
7
 
@@ -16,3 +20,35 @@ div.blocklyTreeRoot {
16
20
  font-weight: bold;
17
21
  }
18
22
  }
23
+
24
+ <%
25
+ hues = [
26
+ colors[:motion],
27
+ colors[:looks],
28
+ colors[:sound],
29
+ colors[:pen],
30
+ colors[:data],
31
+ colors[:events],
32
+ colors[:control],
33
+ colors[:sensing],
34
+ colors[:operators],
35
+ colors[:etc],
36
+ ]
37
+
38
+ colors = hues.map { |h|
39
+ [SmalrubyEditor.hsv_to_rgb(h, 100, 80),
40
+ SmalrubyEditor.hsv_to_rgb(h, 100, 100)]
41
+ }
42
+
43
+ colors.each.with_index(1) do |(color, active_color), index|
44
+ %>
45
+ div.blocklyTreeRoot > div:nth-child(2) > div:nth-child(<%= index %>)[aria-level="1"] {
46
+ .blocklyTreeRow {
47
+ background-color: #<%= color %> !important;
48
+ }
49
+
50
+ .blocklyTreeRow.blocklyTreeSelected {
51
+ background-color: #<%= active_color %> !important;
52
+ }
53
+ }
54
+ <% end %>
@@ -7,10 +7,11 @@ class ApplicationController < ActionController::Base
7
7
  # For APIs, you may want to use :null_session instead.
8
8
  protect_from_forgery with: :exception
9
9
 
10
- helper_method :standalone?, :raspberrypi?
10
+ helper_method :standalone?, :raspberrypi?, :current_user,
11
+ :current_preferences
11
12
 
12
13
  before_filter :set_locale
13
- before_filter :reload_config if Rails.env.development?
14
+ before_filter :reload_preference if Rails.env.development?
14
15
 
15
16
  private
16
17
 
@@ -53,7 +54,22 @@ class ApplicationController < ActionController::Base
53
54
  end
54
55
  end
55
56
 
56
- def reload_config
57
- SmalrubyEditor::Config.reload!
57
+ def reload_preference
58
+ Preference.reload!
59
+ end
60
+
61
+ def require_auth
62
+ if session[:username].blank?
63
+ head :unauthorized
64
+ return false
65
+ end
66
+ end
67
+
68
+ def current_user
69
+ @current_user ||= User.where(name: session[:username]).first
70
+ end
71
+
72
+ def current_preferences
73
+ current_user.try(:preferences) || Preference.to_hash
58
74
  end
59
75
  end
@@ -6,4 +6,8 @@ class EditorController < ApplicationController
6
6
  def demo
7
7
  @filename = (File.basename(params[:filename]) || 'car_chase') + '.rb.xml'
8
8
  end
9
+
10
+ def toolbox
11
+ render :toolbox, layout: false
12
+ end
9
13
  end
@@ -6,14 +6,17 @@ class SessionsController < ApplicationController
6
6
  def create
7
7
  return head :bad_request if params[:username].blank?
8
8
 
9
- session[:username] = params[:username].to_s
9
+ user = User.find_or_create_by(name: params[:username].to_s) { |u|
10
+ u.set_default_preferences
11
+ }
12
+ session[:username] = user.name
10
13
 
11
- render text: session[:username]
14
+ render json: current_preferences
12
15
  end
13
16
 
14
17
  def destroy
15
- session[:username] = nil
18
+ session[:username] = @current_user = nil
16
19
 
17
- render nothing: true
20
+ render json: current_preferences
18
21
  end
19
22
  end
@@ -21,7 +21,6 @@ class SourceCodesController < ApplicationController
21
21
  local_program_paths.map(&select_and_get_summary).compact
22
22
  end
23
23
 
24
- demo_program_paths = Pathname.glob(Rails.root.join('demos/*.rb.xml'))
25
24
  res[:demoPrograms] =
26
25
  demo_program_paths.map(&select_and_get_summary).compact
27
26
 
@@ -180,7 +179,8 @@ class SourceCodesController < ApplicationController
180
179
  end
181
180
 
182
181
  def demo_program_paths
183
- Pathname.glob(Rails.root.join('demos/*.rb.xml'))
182
+ Pathname.glob(Rails.root.join('demos/*.rb.xml')) +
183
+ Pathname.glob(SmalrubyEditor.home_directory.join('.demos/*.rb.xml'))
184
184
  end
185
185
 
186
186
  def rb_basename(path)
@@ -0,0 +1,22 @@
1
+ class UsersController < ApplicationController
2
+ before_filter :check_whether_standalone
3
+ before_filter :require_auth
4
+
5
+ layout false
6
+
7
+ def preferences
8
+ end
9
+
10
+ def update
11
+ current_user.update_attributes!(user_params)
12
+
13
+ render json: current_user.preferences
14
+ end
15
+
16
+ private
17
+
18
+ def user_params
19
+ params.require(:user)
20
+ .permit(preferences: [Preference.whole_preference_names])
21
+ end
22
+ end
@@ -22,13 +22,13 @@ module ApplicationHelper
22
22
 
23
23
  # name of Toolbox
24
24
  def toolbox_name
25
- SmalrubyEditor::Config.toolbox_name || 'default'
25
+ current_preferences["toolbox_name"] || "default"
26
26
  end
27
27
 
28
28
  # css name of Toolbox
29
29
  def toolbox_css_name
30
- SmalrubyEditor::Config.toolbox_css_name ||
31
- SmalrubyEditor::Config.toolbox_name ||
32
- 'default'
30
+ current_preferences["toolbox_css_name"] ||
31
+ current_preferences["toolbox_name"] ||
32
+ "default"
33
33
  end
34
34
  end
File without changes
@@ -0,0 +1,10 @@
1
+ module UsersHelper
2
+ def preferences_field(form, name)
3
+ case name
4
+ when Preference::BOOLEAN_FIELD_REGEXP
5
+ form.check_box(name)
6
+ else
7
+ form.text_field(name)
8
+ end
9
+ end
10
+ end
@@ -3,12 +3,6 @@ module RubyToBlock
3
3
  module Block
4
4
  class HardwareInitHardware < Base
5
5
  blocknize '^\s*init_hardware\s*$', statement: true
6
-
7
- def self.process_match_data(md, context)
8
- context.blocks.push(new)
9
-
10
- true
11
- end
12
6
  end
13
7
  end
14
8
  end
@@ -0,0 +1,71 @@
1
+ require "smalruby_editor"
2
+
3
+ class Preference < Settingslogic
4
+ BOOLEAN_FIELD_REGEXP = /(enabled|disabled)/
5
+
6
+ def self.toolbox_names
7
+ %w(
8
+ default
9
+ smalrubot_v3
10
+ smalrubot_s1
11
+ )
12
+ end
13
+
14
+ def self.toolbox_preference_names
15
+ %w(
16
+ toolbox__default__enabled_hardware_blocks
17
+ toolbox__default__enabled_smalrubot_v3_blocks
18
+ toolbox__default__enabled_smalrubot_s1_blocks
19
+ )
20
+ end
21
+
22
+ def self.general_preference_names
23
+ %w(
24
+ disabled_add_character_from_beginning
25
+ disabled_new_character
26
+ enabled_auto_init_hardware
27
+ enabled_readonly_ruby_mode
28
+ )
29
+ end
30
+
31
+ def self.admin_preference_names
32
+ %w(
33
+ enabled_must_signin
34
+ )
35
+ end
36
+
37
+ def self.whole_preference_names
38
+ ["toolbox_name"] + toolbox_preference_names +
39
+ general_preference_names + admin_preference_names
40
+ end
41
+
42
+ def self.defaults
43
+ (toolbox_preference_names +
44
+ general_preference_names).map { |n|
45
+ [n, false]
46
+ }.to_h.merge("toolbox_name" => "default")
47
+ end
48
+
49
+ def self.make_toolbox_name_to_preference_names_hash
50
+ toolbox_preference_names.group_by { |n|
51
+ n.slice(/^toolbox__(.+?)__/, 1)
52
+ }
53
+ end
54
+
55
+ def initialize(hash_or_file = self.class.source, section = nil)
56
+ super
57
+ rescue NoMethodError
58
+ replace({})
59
+ @section = section || self.class.source
60
+ create_accessors!
61
+ end
62
+
63
+ path = SmalrubyEditor.home_directory.join("config", "config.yml")
64
+ if path.exist?
65
+ source(path)
66
+ else
67
+ source({})
68
+ end
69
+ load!
70
+ suppress_errors(true)
71
+ end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'tempfile'
4
4
  require 'open3'
5
+ require 'nkf'
5
6
  require 'digest/sha2'
6
7
  require 'bundler'
7
8
  require 'smalruby_editor'
@@ -152,6 +153,9 @@ class SourceCode < ActiveRecord::Base
152
153
  end
153
154
 
154
155
  def parse_ruby_error_messages(stderr_str)
156
+ if SmalrubyEditor.windows?
157
+ stderr_str = NKF.nkf("-w", stderr_str)
158
+ end
155
159
  stderr_str.lines.each.with_object([]) { |line, res|
156
160
  if (md = /^\tfrom .*:(\d+):(in .*)$/.match(line))
157
161
  res << { row: md[1].to_i, column: 0, message: md[2] }
@@ -0,0 +1,26 @@
1
+ class User < ActiveRecord::Base
2
+ serialize :preferences
3
+
4
+ before_save do
5
+ preferences.each do |key, value|
6
+ case key
7
+ when Preference::BOOLEAN_FIELD_REGEXP
8
+ if !value.is_a?(TrueClass) && !value.is_a?(FalseClass)
9
+ if %w(true 1).include?(value)
10
+ preferences[key] = true
11
+ else
12
+ preferences[key] = false
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ # set default preferences from SMALRUBY_HOME/config/config.yml
20
+ def set_default_preferences
21
+ self.preferences = Preference.defaults
22
+ Preference.to_h.each do |key, value|
23
+ preferences[key] = value
24
+ end
25
+ end
26
+ end
@@ -16,12 +16,11 @@
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
- - 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')
19
+ #add-character-item.item
20
+ %a#add-character-button{:class => 'character'}
21
+ %i.icon-plus-sign-alt
22
+ %br
23
+ = t('.new_character')
25
24
 
26
25
  #scene-selector-tab{:class => 'tab-pane selector-tab'}
27
26
  .item
@@ -5,14 +5,14 @@
5
5
  :class => "list-programs"}
6
6
 
7
7
  .page-header
8
- %h3<
8
+ %h3
9
9
  %i.icon-th-large
10
10
  = t('.preset_programs')
11
11
  %ul.thumbnails{:id => "load-modal-demo-programs",
12
12
  :class => "list-programs"}
13
13
 
14
14
  .page-header
15
- %h3<
15
+ %h3
16
16
  %i.icon-search
17
17
  = t('.find_program')
18
18
  %ul.thumbnails{:class => "list-programs"}
@@ -0,0 +1,16 @@
1
+ #preference-modal{class: "#{modal_css_class}", tabindex: "-1",
2
+ role: "dialog", "aria-hidden" => "true"}
3
+ .modal-header
4
+ %h3
5
+ %i.icon-cog
6
+ = t('.title')
7
+
8
+ .modal-body#preference-modal-content
9
+
10
+ .modal-footer
11
+ %button.btn{:"data-dismiss" => "modal", :"aria-hidden" => "true"}<
12
+ %i.icon-remove
13
+ = t('common.cancel')
14
+ %button#preference-modal-ok-button{:class => "btn btn-primary"}<
15
+ %i.icon-circle-blank
16
+ = t('common.ok')
@@ -12,7 +12,7 @@
12
12
  %input#signin-modal-username.input-large{name: "username", type: "text", placeholder: t('.username_placeholder')}
13
13
 
14
14
  .modal-footer
15
- - if !SmalrubyEditor::Config.enabled?('must_signin')
15
+ - if !current_preferences["enabled_must_signin"]
16
16
  %button#signin-modal-cancel-button.cancel-button{class: "btn", :"data-dismiss" => "modal", :"aria-hidden" => "true"}<
17
17
  %i.icon-remove
18
18
  = t('common.cancel')
@@ -77,13 +77,26 @@
77
77
  -# 変数:向き
78
78
  %block{:type => "#{category}_self_angle"}
79
79
 
80
- - if SmalrubyEditor::Config.enabled?('enabled_hardware_blocks_on_default')
80
+ - if current_preferences["toolbox__default__enabled_hardware_blocks"]
81
81
  - category = 'hardware'
82
82
  - subcategory = 'servo'
83
83
  -# サーボ[▼PIN]を( )度(5~180)にする
84
84
  %block{:type => "#{category}_#{subcategory}_set_position"}
85
85
  = toolbox_number_value('POS', 90)
86
86
 
87
+ - subcategory = 'motor_driver'
88
+ -# (モータードライバ[▼PIN]で)モーターを[▼正転させる]
89
+ %block{:type => "#{category}_#{subcategory}"}
90
+ = toolbox_pin_field('D6')
91
+ %field{:name => 'METHOD'}<
92
+ forward
93
+
94
+ -# (モータードライバ[▼PIN]の)モーターの速度を<SPEED>%にする
95
+ %block{:type => "#{category}_#{subcategory}_set_speed"}
96
+ = toolbox_pin_field('D6')
97
+ = toolbox_number_value('SPEED', 100)
98
+
99
+ - if current_preferences["toolbox__default__enabled_2wd_car_blocks"]
87
100
  - subcategory = 'two_wheel_drive_car'
88
101
  -# 2WD車[▼PIN]を( )秒[▼コマンド]
89
102
  %block{:type => "#{category}_#{subcategory}_run"}
@@ -97,71 +110,60 @@
97
110
  %field{:name => 'COMMAND'}<
98
111
  forward
99
112
 
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')
113
+ -# 2WD車[▼PIN]を進める
114
+ %block{:type => "#{category}_#{subcategory}_forward"}
115
+ = toolbox_pin_field('D5')
112
116
 
113
- -# 2WD車[▼PIN]を右に曲げる
114
- %block{:type => "#{category}_#{subcategory}_turn_right"}
115
- = toolbox_pin_field('D5')
117
+ -# 2WD車[▼PIN]をバックさせる
118
+ %block{:type => "#{category}_#{subcategory}_backward"}
119
+ = toolbox_pin_field('D5')
116
120
 
117
- -# 2WD車[▼PIN]を止める
118
- %block{:type => "#{category}_#{subcategory}_stop"}
119
- = toolbox_pin_field('D5')
121
+ -# 2WD車[▼PIN]を左に曲げる
122
+ %block{:type => "#{category}_#{subcategory}_turn_left"}
123
+ = toolbox_pin_field('D5')
120
124
 
121
- -# 2WD車[▼PIN]の[▼LOR]の速度を<SPEED>%にする
122
- %block{:type => "#{category}_#{subcategory}_set_speed"}
123
- = toolbox_pin_field('D5')
124
- = toolbox_number_value('SPEED', 100)
125
+ -# 2WD車[▼PIN]を右に曲げる
126
+ %block{:type => "#{category}_#{subcategory}_turn_right"}
127
+ = toolbox_pin_field('D5')
125
128
 
126
- - subcategory = 'motor_driver'
127
- -# (モータードライバ[▼PIN]で)モーターを[▼正転させる]
128
- %block{:type => "#{category}_#{subcategory}"}
129
- = toolbox_pin_field('D6')
130
- %field{:name => 'METHOD'}<
131
- forward
129
+ -# 2WD車[▼PIN]を止める
130
+ %block{:type => "#{category}_#{subcategory}_stop"}
131
+ = toolbox_pin_field('D5')
132
132
 
133
- -# (モータードライバ[▼PIN]の)モーターの速度を<SPEED>%にする
133
+ -# 2WD車[▼PIN]の[▼LOR]の速度を<SPEED>%にする
134
134
  %block{:type => "#{category}_#{subcategory}_set_speed"}
135
- = toolbox_pin_field('D6')
135
+ = toolbox_pin_field('D5')
136
136
  = toolbox_number_value('SPEED', 100)
137
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
138
+ - if current_preferences["toolbox__default__enabled_smalrubot_v3_blocks"]
139
+ - category = 'hardware'
140
+ - subcategory = 'smalrubot_v3'
141
+ %block{type: "#{category}_#{subcategory}_action"}
142
+ %field{name: 'ACTION'}<
143
+ forward
143
144
 
144
- %block{type: "#{category}_#{subcategory}_action_with_sec"}
145
- %field{name: 'ACTION'}<
146
- forward
147
- = toolbox_number_value('SEC', 0.5)
145
+ %block{type: "#{category}_#{subcategory}_action_with_sec"}
146
+ %field{name: 'ACTION'}<
147
+ forward
148
+ = toolbox_number_value('SEC', 0.5)
148
149
 
149
- %block{type: "#{category}_#{subcategory}_dc_motor_set_power_ratio"}
150
- = toolbox_number_value('SPEED', 100)
150
+ %block{type: "#{category}_#{subcategory}_dc_motor_set_power_ratio"}
151
+ = toolbox_number_value('SPEED', 100)
151
152
 
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
153
+ - if current_preferences["toolbox__default__enabled_smalrubot_s1_blocks"]
154
+ - category = 'hardware'
155
+ - subcategory = 'smalrubot_s1'
156
+ %block{type: "#{category}_#{subcategory}_action"}
157
+ %field{name: 'ACTION'}<
158
+ forward
157
159
 
158
- %block{type: "#{category}_#{subcategory}_action_with_sec"}
159
- %field{name: 'ACTION'}<
160
- forward
161
- = toolbox_number_value('SEC', 0.5)
160
+ %block{type: "#{category}_#{subcategory}_action_with_sec"}
161
+ %field{name: 'ACTION'}<
162
+ forward
163
+ = toolbox_number_value('SEC', 0.5)
162
164
 
163
- %block{type: "#{category}_#{subcategory}_dc_motor_set_power_ratio"}
164
- = toolbox_number_value('SPEED', 100)
165
+ %block{type: "#{category}_#{subcategory}_dc_motor_set_power_ratio"}
166
+ = toolbox_number_value('SPEED', 100)
165
167
 
166
168
  - category = 'looks'
167
169
  %category{:name => tt('.looks')}
@@ -206,7 +208,7 @@
206
208
  -# [▼プリセット画像]
207
209
  -#%block{:type => "#{category}_preset_images"}
208
210
 
209
- - if SmalrubyEditor::Config.enabled?('enabled_hardware_blocks_on_default')
211
+ - if current_preferences["toolbox__default__enabled_hardware_blocks"]
210
212
  - category = 'hardware'
211
213
  - subcategory = 'led'
212
214
  -# LED[▼PIN]をオンにする
@@ -237,17 +239,19 @@
237
239
  -# LCDをクリアする
238
240
  %block{:type => "#{category}_#{subcategory}_clear"}
239
241
 
240
- - if SmalrubyEditor::Config.enabled?('enabled_smalrubot_v3_blocks_on_default')
241
- - subcategory = 'smalrubot_v3'
242
- %block{type: "#{category}_#{subcategory}_led_turn_on_or_off"}
243
- %field{name: 'OOO'}<
244
- turn_on
242
+ - if current_preferences["toolbox__default__enabled_smalrubot_v3_blocks"]
243
+ - category = 'hardware'
244
+ - subcategory = 'smalrubot_v3'
245
+ %block{type: "#{category}_#{subcategory}_led_turn_on_or_off"}
246
+ %field{name: 'OOO'}<
247
+ turn_on
245
248
 
246
- - if SmalrubyEditor::Config.enabled?('enabled_smalrubot_s1_blocks_on_default')
247
- - subcategory = 'smalrubot_s1'
248
- %block{type: "#{category}_#{subcategory}_led_turn_on_or_off"}
249
- %field{name: 'OOO'}<
250
- turn_on
249
+ - if current_preferences["toolbox__default__enabled_smalrubot_s1_blocks"]
250
+ - category = 'hardware'
251
+ - subcategory = 'smalrubot_s1'
252
+ %block{type: "#{category}_#{subcategory}_led_turn_on_or_off"}
253
+ %field{name: 'OOO'}<
254
+ turn_on
251
255
 
252
256
  - category = 'sound'
253
257
  %category{:name => tt('.sound')}
@@ -373,7 +377,7 @@
373
377
  -# 変数:2000年からの日数
374
378
  %block{:type => "#{category}_days_since_2000"}
375
379
 
376
- - if SmalrubyEditor::Config.enabled?('enabled_hardware_blocks_on_default')
380
+ - if current_preferences["toolbox__default__enabled_hardware_blocks"]
377
381
  - category = 'hardware'
378
382
  -# センサー[▼PIN]
379
383
  %block{:type => "#{category}_sensor_value"}
@@ -383,24 +387,27 @@
383
387
  %block{:type => "#{category}_button_pressed_or_released"}
384
388
  = toolbox_pin_field('D3')
385
389
 
386
- -# 2WD車[▼PIN]の[▼LOR]の速度%
387
- %block{:type => "#{category}_two_wheel_drive_car_speed"}
388
- = toolbox_pin_field('D5')
389
-
390
390
  -# (モータードライバ[▼PIN]の)モーターの速度(%)
391
391
  %block{:type => "#{category}_motor_driver_speed"}
392
392
  = toolbox_pin_field('D6')
393
393
 
394
- - if SmalrubyEditor::Config.enabled?('enabled_smalrubot_v3_blocks_on_default')
395
- - subcategory = 'smalrubot_v3'
396
- %block{type: "#{category}_#{subcategory}_sensor_value"}
397
- %block{type: "#{category}_#{subcategory}_dc_motor_power_ratio"}
394
+ - if current_preferences["toolbox__default__enabled_2wd_car_blocks"]
395
+ - category = 'hardware'
396
+ -# 2WD車[▼PIN]の[▼LOR]の速度%
397
+ %block{:type => "#{category}_two_wheel_drive_car_speed"}
398
+ = toolbox_pin_field('D5')
399
+
400
+ - if current_preferences["toolbox__default__enabled_smalrubot_v3_blocks"]
401
+ - category = 'hardware'
402
+ - subcategory = 'smalrubot_v3'
403
+ %block{type: "#{category}_#{subcategory}_sensor_value"}
404
+ %block{type: "#{category}_#{subcategory}_dc_motor_power_ratio"}
398
405
 
399
- - if SmalrubyEditor::Config.enabled?('enabled_smalrubot_s1_blocks_on_default')
400
- - category = 'hardware'
401
- - subcategory = 'smalrubot_s1'
402
- %block{type: "#{category}_#{subcategory}_sensor_value"}
403
- %block{type: "#{category}_#{subcategory}_dc_motor_power_ratio"}
406
+ - if current_preferences["toolbox__default__enabled_smalrubot_s1_blocks"]
407
+ - category = 'hardware'
408
+ - subcategory = 'smalrubot_s1'
409
+ %block{type: "#{category}_#{subcategory}_sensor_value"}
410
+ %block{type: "#{category}_#{subcategory}_dc_motor_power_ratio"}
404
411
 
405
412
  - category = 'operators'
406
413
  %category{:name => tt('.operators')}
@@ -499,7 +506,7 @@
499
506
  -# p
500
507
  %block{:type => "#{category}_p"}
501
508
 
502
- - if SmalrubyEditor::Config.enabled?('enabled_hardware_blocks_on_default')
509
+ - if !current_preferences["enabled_auto_init_hardware"] && (current_preferences["toolbox__default__enabled_hardware_blocks"] || current_preferences["toolbox__default__enabled_smalrubot_v3_blocks"] || current_preferences["toolbox__default__enabled_smalrubot_s1_blocks"])
503
510
  - category = 'hardware'
504
511
  -# ハードウェアを準備する
505
512
  %block{:type => "#{category}_init_hardware"}