smalruby-editor 0.2.4 → 0.2.5
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +8 -0
- data/Guardfile +8 -1
- data/app/assets/javascripts/blocks/hardware.js.coffee.erb +11 -152
- data/app/assets/javascripts/msg/en_us.js +5 -5
- data/app/assets/javascripts/msg/ja.js +5 -5
- data/app/assets/javascripts/views/signin_modal_view.js.coffee.erb +0 -0
- data/app/controllers/sessions_controller.rb +0 -0
- data/app/helpers/sessions_helper.rb +4 -0
- data/app/models/concerns/ruby_to_block/block/hardware_operation.rb +11 -0
- data/app/models/concerns/ruby_to_block/block/{hardware_smalrubot_s1_led_turn_on_or_off.rb → hardware_smalrubot_action.rb} +8 -5
- data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_action_with_sec.rb +25 -0
- data/app/models/concerns/ruby_to_block/block/{hardware_smalrubot_v3_motor_speed.rb → hardware_smalrubot_dc_motor_power_ratio.rb} +8 -5
- data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_dc_motor_set_power_ratio.rb +23 -0
- data/app/models/concerns/ruby_to_block/block/{hardware_smalrubot_v3_led_turn_on_or_off.rb → hardware_smalrubot_led_turn_on_or_off.rb} +8 -5
- data/app/models/concerns/ruby_to_block/block/{hardware_smalrubot_s1_ir_photoreflector_value.rb → hardware_smalrubot_sensor_value.rb} +8 -6
- data/app/views/editor/_toolbox_default.html.haml +4 -7
- data/app/views/editor/index.html.haml +7 -18
- data/bin/spring +0 -0
- data/config/application.rb +1 -0
- data/lib/smalruby_editor/version.rb +1 -1
- data/smalruby-editor.gemspec +1 -1
- data/spec/acceptance/block_mode/blocks/hardware/smalrubot_s1_led_turn_on_or_off.feature +8 -8
- data/spec/acceptance/block_mode/blocks/hardware/{smalrubot_v3_motor_speed.feature → smalrubot_v3_dc_motor_power_ratio.feature} +12 -12
- data/spec/acceptance/block_mode/blocks/hardware/smalrubot_v3_led_turn_on_or_off.feature +8 -8
- data/spec/acceptance/block_mode/blocks/hardware/{smalrubot_s1_ir_photoreflector_value.feature → smalrubot_v3_sensor_value.feature} +7 -7
- data/spec/models/concerns/ruby_to_block/block/{hardware__smalrubot_s1_spec.rb → hardware__smalrubot_spec.rb} +88 -84
- data/spec/spec_helper.rb +0 -0
- data/spec/steps/base_steps.rb +0 -0
- data/spec/steps/text_editor_steps.rb +0 -0
- metadata +23 -36
- data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_s1_action.rb +0 -13
- data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_s1_action_with_sec.rb +0 -14
- data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_s1_dc_motor_power_ratio.rb +0 -26
- data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_s1_dc_motor_set_power_ratio.rb +0 -21
- data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_v3_action.rb +0 -22
- data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_v3_action_with_sec.rb +0 -24
- data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_v3_light_sensor_value.rb +0 -28
- data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_v3_motor_set_speed.rb +0 -21
- data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_v3_touch_sensor_pressed_or_released.rb +0 -29
- data/spec/acceptance/block_mode/blocks/hardware/smalrubot_v3_light_sensor_value.feature +0 -92
- data/spec/acceptance/block_mode/blocks/hardware/smalrubot_v3_touch_sensor_pressed_or_released.feature +0 -108
- data/spec/models/concerns/ruby_to_block/block/hardware__smalrubot_v3_spec.rb +0 -433
@@ -1,19 +1,22 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
module RubyToBlock
|
3
3
|
module Block
|
4
|
-
class
|
4
|
+
class HardwareSmalrubotLedTurnOnOrOff < CharacterMethodCall
|
5
5
|
include HardwareOperation
|
6
6
|
|
7
7
|
# rubocop:disable LineLength
|
8
|
-
blocknize '^\s*'
|
9
|
-
|
10
|
-
|
8
|
+
blocknize ['^\s*',
|
9
|
+
CHAR_RE,
|
10
|
+
SMALRUBOT_RE, '\.',
|
11
|
+
ON_OFF_RE, '_', LOR_RE, '_led',
|
12
|
+
'\s*$'].join(''),
|
11
13
|
statement: true, inline: true
|
12
14
|
# rubocop:enable LineLength
|
13
15
|
|
14
16
|
def self.process_match_data(md, context)
|
15
17
|
md2 = regexp.match(md[type])
|
16
|
-
block = new(fields: {
|
18
|
+
block = new(fields: { LOR: md2[4], OOO: md2[3] })
|
19
|
+
block.smalrubot_name = md2[2]
|
17
20
|
add_character_method_call_block(context, md2[1], block)
|
18
21
|
true
|
19
22
|
end
|
@@ -1,14 +1,15 @@
|
|
1
1
|
module RubyToBlock
|
2
2
|
module Block
|
3
|
-
class
|
3
|
+
class HardwareSmalrubotSensorValue < Value
|
4
4
|
include CharacterOperation
|
5
5
|
include HardwareOperation
|
6
6
|
|
7
7
|
# rubocop:disable LineLength
|
8
|
-
blocknize '^\s*'
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
blocknize ['^\s*',
|
9
|
+
CHAR_RE,
|
10
|
+
SMALRUBOT_RE, '.',
|
11
|
+
LOR_RE, '_sensor_value',
|
12
|
+
'\s*$'].join(''),
|
12
13
|
value: true
|
13
14
|
# rubocop:enable LineLength
|
14
15
|
|
@@ -18,7 +19,8 @@ module RubyToBlock
|
|
18
19
|
character = get_character(context, md2[1])
|
19
20
|
return false if context.receiver && context.receiver != character
|
20
21
|
|
21
|
-
block = new(fields: { LOR: md2[
|
22
|
+
block = new(fields: { LOR: md2[3] })
|
23
|
+
block.smalrubot_name = md2[2]
|
22
24
|
context.add_value(block)
|
23
25
|
block.character = character
|
24
26
|
|
@@ -146,7 +146,7 @@
|
|
146
146
|
forward
|
147
147
|
= toolbox_number_value('SEC', 0.5)
|
148
148
|
|
149
|
-
%block{type: "#{category}_#{subcategory}
|
149
|
+
%block{type: "#{category}_#{subcategory}_dc_motor_set_power_ratio"}
|
150
150
|
= toolbox_number_value('SPEED', 100)
|
151
151
|
|
152
152
|
- if SmalrubyEditor::Config.enabled?('enabled_smalrubot_s1_blocks_on_default')
|
@@ -240,8 +240,6 @@
|
|
240
240
|
- if SmalrubyEditor::Config.enabled?('enabled_smalrubot_v3_blocks_on_default')
|
241
241
|
- subcategory = 'smalrubot_v3'
|
242
242
|
%block{type: "#{category}_#{subcategory}_led_turn_on_or_off"}
|
243
|
-
%field{name: 'COLOUR'}<
|
244
|
-
red
|
245
243
|
%field{name: 'OOO'}<
|
246
244
|
turn_on
|
247
245
|
|
@@ -395,14 +393,13 @@
|
|
395
393
|
|
396
394
|
- if SmalrubyEditor::Config.enabled?('enabled_smalrubot_v3_blocks_on_default')
|
397
395
|
- subcategory = 'smalrubot_v3'
|
398
|
-
%block{type: "#{category}_#{subcategory}
|
399
|
-
%block{type: "#{category}_#{subcategory}
|
400
|
-
%block{type: "#{category}_#{subcategory}_motor_speed"}
|
396
|
+
%block{type: "#{category}_#{subcategory}_sensor_value"}
|
397
|
+
%block{type: "#{category}_#{subcategory}_dc_motor_power_ratio"}
|
401
398
|
|
402
399
|
- if SmalrubyEditor::Config.enabled?('enabled_smalrubot_s1_blocks_on_default')
|
403
400
|
- category = 'hardware'
|
404
401
|
- subcategory = 'smalrubot_s1'
|
405
|
-
%block{type: "#{category}_#{subcategory}
|
402
|
+
%block{type: "#{category}_#{subcategory}_sensor_value"}
|
406
403
|
%block{type: "#{category}_#{subcategory}_dc_motor_power_ratio"}
|
407
404
|
|
408
405
|
- category = 'operators'
|
@@ -43,14 +43,9 @@
|
|
43
43
|
%i.icon-off
|
44
44
|
= t('.reset')
|
45
45
|
- if standalone?
|
46
|
-
-
|
47
|
-
%
|
48
|
-
|
49
|
-
= t('.logout')
|
50
|
-
- else
|
51
|
-
%button#signout-button.btn{class: "btn-primary", style: "display: none"}<
|
52
|
-
%i.icon-eject
|
53
|
-
= t('.logout')
|
46
|
+
%button#signout-button.btn{class: "btn-primary", style: "display: #{signed_in? ? '' : 'none'}"}<
|
47
|
+
%i.icon-eject
|
48
|
+
= t('.logout')
|
54
49
|
|
55
50
|
- else
|
56
51
|
.btn-group
|
@@ -84,16 +79,10 @@
|
|
84
79
|
= t('.reset')
|
85
80
|
- if standalone?
|
86
81
|
%li
|
87
|
-
-
|
88
|
-
%
|
89
|
-
%
|
90
|
-
|
91
|
-
= t('.logout')
|
92
|
-
- else
|
93
|
-
%a#signout-button{style: "display: none"}
|
94
|
-
%h4
|
95
|
-
%i.icon-eject
|
96
|
-
= t('.logout')
|
82
|
+
%a#signout-button{style: "display: #{signed_in? ? '' : 'none'}"}
|
83
|
+
%h4
|
84
|
+
%i.icon-eject
|
85
|
+
= t('.logout')
|
97
86
|
|
98
87
|
- if standalone?
|
99
88
|
- if session[:username]
|
data/bin/spring
CHANGED
File without changes
|
data/config/application.rb
CHANGED
@@ -10,6 +10,7 @@ Bundler.require(:default, Rails.env) unless Rails.env == 'standalone'
|
|
10
10
|
module SmalrubyEditor
|
11
11
|
class Application < Rails::Application
|
12
12
|
config.time_zone = 'Tokyo'
|
13
|
+
I18n.enforce_available_locales = true
|
13
14
|
config.i18n.default_locale = :ja
|
14
15
|
config.colorize_logging = false
|
15
16
|
config.filter_parameters += [:data]
|
data/smalruby-editor.gemspec
CHANGED
@@ -10,8 +10,8 @@ Feature: hardware_smalrubot_s1_led_turn_on_or_off block
|
|
10
10
|
When 次のブロックを配置する:
|
11
11
|
"""
|
12
12
|
%block{:type => "hardware_smalrubot_s1_led_turn_on_or_off", :x => "0", :y => "0"}
|
13
|
-
%field{:name => "
|
14
|
-
|
13
|
+
%field{:name => "LOR"}<
|
14
|
+
right
|
15
15
|
%field{:name => "OOO"}<
|
16
16
|
turn_off
|
17
17
|
"""
|
@@ -27,8 +27,8 @@ Feature: hardware_smalrubot_s1_led_turn_on_or_off block
|
|
27
27
|
car1
|
28
28
|
%statement{:name => "DO"}
|
29
29
|
%block{:type => "hardware_smalrubot_s1_led_turn_on_or_off", :x => "0", :y => "0"}
|
30
|
-
%field{:name => "
|
31
|
-
|
30
|
+
%field{:name => "LOR"}<
|
31
|
+
right
|
32
32
|
%field{:name => "OOO"}<
|
33
33
|
turn_off
|
34
34
|
"""
|
@@ -39,7 +39,7 @@ Feature: hardware_smalrubot_s1_led_turn_on_or_off block
|
|
39
39
|
require "smalruby"
|
40
40
|
|
41
41
|
car1 = Character.new(costume: "car1.png", x: 0, y: 0, angle: 0)
|
42
|
-
car1.smalrubot_s1.
|
42
|
+
car1.smalrubot_s1.turn_off_right_led
|
43
43
|
|
44
44
|
"""
|
45
45
|
|
@@ -53,8 +53,8 @@ Feature: hardware_smalrubot_s1_led_turn_on_or_off block
|
|
53
53
|
%block{:type => "events_on_start"}
|
54
54
|
%statement{:name => "DO"}
|
55
55
|
%block{:type => "hardware_smalrubot_s1_led_turn_on_or_off", :x => "0", :y => "0"}
|
56
|
-
%field{:name => "
|
57
|
-
|
56
|
+
%field{:name => "LOR"}<
|
57
|
+
left
|
58
58
|
%field{:name => "OOO"}<
|
59
59
|
turn_on
|
60
60
|
"""
|
@@ -67,7 +67,7 @@ Feature: hardware_smalrubot_s1_led_turn_on_or_off block
|
|
67
67
|
car1 = Character.new(costume: "car1.png", x: 0, y: 0, angle: 0)
|
68
68
|
|
69
69
|
car1.on(:start) do
|
70
|
-
smalrubot_s1.
|
70
|
+
smalrubot_s1.turn_on_left_led
|
71
71
|
end
|
72
72
|
|
73
73
|
"""
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# language: en
|
3
3
|
@javascript
|
4
|
-
Feature:
|
4
|
+
Feature: hardware_smalrubot_v3_dc_motor_{,set_}power_ratio block
|
5
5
|
Background:
|
6
6
|
Given "ブロック" タブを表示する
|
7
7
|
And キャラクターcar1を追加する
|
@@ -9,7 +9,7 @@ Feature: hardware_smalrubot_v3_motor_{speed,set_speed} block
|
|
9
9
|
Scenario: ブロックのみ配置する
|
10
10
|
When 次のブロックを配置する:
|
11
11
|
"""
|
12
|
-
%block{:type => "
|
12
|
+
%block{:type => "hardware_smalrubot_v3_dc_motor_power_ratio"}
|
13
13
|
%field{:name => "LOR"}<
|
14
14
|
right
|
15
15
|
"""
|
@@ -22,11 +22,11 @@ Feature: hardware_smalrubot_v3_motor_{speed,set_speed} block
|
|
22
22
|
"""
|
23
23
|
%block{:type => "ruby_p", :x => "0", :y => "0", :inline => "true" }
|
24
24
|
%value{:name => "ARG"}
|
25
|
-
%block{:type => "
|
25
|
+
%block{:type => "hardware_smalrubot_v3_dc_motor_power_ratio"}
|
26
26
|
%field{:name => "LOR"}<
|
27
27
|
right
|
28
28
|
%next
|
29
|
-
%block{:type => "
|
29
|
+
%block{:type => "hardware_smalrubot_v3_dc_motor_set_power_ratio"}
|
30
30
|
%field{:name => "LOR"}<
|
31
31
|
left
|
32
32
|
%value{:name => "SPEED"}
|
@@ -53,11 +53,11 @@ Feature: hardware_smalrubot_v3_motor_{speed,set_speed} block
|
|
53
53
|
%statement{:name => "DO"}
|
54
54
|
%block{:type => "ruby_p", :x => "0", :y => "0", :inline => "true" }
|
55
55
|
%value{:name => "ARG"}
|
56
|
-
%block{:type => "
|
56
|
+
%block{:type => "hardware_smalrubot_v3_dc_motor_power_ratio"}
|
57
57
|
%field{:name => "LOR"}<
|
58
58
|
right
|
59
59
|
%next
|
60
|
-
%block{:type => "
|
60
|
+
%block{:type => "hardware_smalrubot_v3_dc_motor_set_power_ratio"}
|
61
61
|
%field{:name => "LOR"}<
|
62
62
|
left
|
63
63
|
%value{:name => "SPEED"}
|
@@ -72,8 +72,8 @@ Feature: hardware_smalrubot_v3_motor_{speed,set_speed} block
|
|
72
72
|
require "smalruby"
|
73
73
|
|
74
74
|
car1 = Character.new(costume: "car1.png", x: 0, y: 0, angle: 0)
|
75
|
-
p(car1.smalrubot_v3.
|
76
|
-
car1.smalrubot_v3.
|
75
|
+
p(car1.smalrubot_v3.right_dc_motor_power_ratio)
|
76
|
+
car1.smalrubot_v3.left_dc_motor_power_ratio = 50
|
77
77
|
|
78
78
|
"""
|
79
79
|
|
@@ -88,11 +88,11 @@ Feature: hardware_smalrubot_v3_motor_{speed,set_speed} block
|
|
88
88
|
%statement{:name => "DO"}
|
89
89
|
%block{:type => "ruby_p", :x => "0", :y => "0", :inline => "true" }
|
90
90
|
%value{:name => "ARG"}
|
91
|
-
%block{:type => "
|
91
|
+
%block{:type => "hardware_smalrubot_v3_dc_motor_power_ratio"}
|
92
92
|
%field{:name => "LOR"}<
|
93
93
|
right
|
94
94
|
%next
|
95
|
-
%block{:type => "
|
95
|
+
%block{:type => "hardware_smalrubot_v3_dc_motor_set_power_ratio"}
|
96
96
|
%field{:name => "LOR"}<
|
97
97
|
left
|
98
98
|
%value{:name => "SPEED"}
|
@@ -109,8 +109,8 @@ Feature: hardware_smalrubot_v3_motor_{speed,set_speed} block
|
|
109
109
|
car1 = Character.new(costume: "car1.png", x: 0, y: 0, angle: 0)
|
110
110
|
|
111
111
|
car1.on(:start) do
|
112
|
-
p(smalrubot_v3.
|
113
|
-
self.smalrubot_v3.
|
112
|
+
p(smalrubot_v3.right_dc_motor_power_ratio)
|
113
|
+
self.smalrubot_v3.left_dc_motor_power_ratio = 50
|
114
114
|
end
|
115
115
|
|
116
116
|
"""
|
@@ -10,8 +10,8 @@ Feature: hardware_smalrubot_v3_led_turn_on_or_off block
|
|
10
10
|
When 次のブロックを配置する:
|
11
11
|
"""
|
12
12
|
%block{:type => "hardware_smalrubot_v3_led_turn_on_or_off", :x => "0", :y => "0"}
|
13
|
-
%field{:name => "
|
14
|
-
|
13
|
+
%field{:name => "LOR"}<
|
14
|
+
left
|
15
15
|
%field{:name => "OOO"}<
|
16
16
|
turn_off
|
17
17
|
"""
|
@@ -27,8 +27,8 @@ Feature: hardware_smalrubot_v3_led_turn_on_or_off block
|
|
27
27
|
car1
|
28
28
|
%statement{:name => "DO"}
|
29
29
|
%block{:type => "hardware_smalrubot_v3_led_turn_on_or_off", :x => "0", :y => "0"}
|
30
|
-
%field{:name => "
|
31
|
-
|
30
|
+
%field{:name => "LOR"}<
|
31
|
+
left
|
32
32
|
%field{:name => "OOO"}<
|
33
33
|
turn_off
|
34
34
|
"""
|
@@ -39,7 +39,7 @@ Feature: hardware_smalrubot_v3_led_turn_on_or_off block
|
|
39
39
|
require "smalruby"
|
40
40
|
|
41
41
|
car1 = Character.new(costume: "car1.png", x: 0, y: 0, angle: 0)
|
42
|
-
car1.smalrubot_v3.
|
42
|
+
car1.smalrubot_v3.turn_off_left_led
|
43
43
|
|
44
44
|
"""
|
45
45
|
|
@@ -53,8 +53,8 @@ Feature: hardware_smalrubot_v3_led_turn_on_or_off block
|
|
53
53
|
%block{:type => "events_on_start"}
|
54
54
|
%statement{:name => "DO"}
|
55
55
|
%block{:type => "hardware_smalrubot_v3_led_turn_on_or_off", :x => "0", :y => "0"}
|
56
|
-
%field{:name => "
|
57
|
-
|
56
|
+
%field{:name => "LOR"}<
|
57
|
+
right
|
58
58
|
%field{:name => "OOO"}<
|
59
59
|
turn_on
|
60
60
|
"""
|
@@ -67,7 +67,7 @@ Feature: hardware_smalrubot_v3_led_turn_on_or_off block
|
|
67
67
|
car1 = Character.new(costume: "car1.png", x: 0, y: 0, angle: 0)
|
68
68
|
|
69
69
|
car1.on(:start) do
|
70
|
-
smalrubot_v3.
|
70
|
+
smalrubot_v3.turn_on_right_led
|
71
71
|
end
|
72
72
|
|
73
73
|
"""
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# language: en
|
3
3
|
@javascript
|
4
|
-
Feature:
|
4
|
+
Feature: hardware_smalrubot_v3_sensor_value block
|
5
5
|
Scenario: ブロックのみ配置する
|
6
6
|
Given "ブロック" タブを表示する
|
7
7
|
|
8
8
|
When 次のブロックを配置する:
|
9
9
|
"""
|
10
|
-
%block{:type => "
|
10
|
+
%block{:type => "hardware_smalrubot_v3_sensor_value", :x => "0", :y => "0"}
|
11
11
|
%field{:name => "LOR"}<
|
12
12
|
right
|
13
13
|
"""
|
@@ -22,7 +22,7 @@ Feature: hardware_smalrubot_s1_ir_photoreflector_value block
|
|
22
22
|
"""
|
23
23
|
%block{:type => "ruby_p", :x => "0", :y => "0", :inline => "true" }
|
24
24
|
%value{:name => "ARG"}
|
25
|
-
%block{:type => "
|
25
|
+
%block{:type => "hardware_smalrubot_v3_sensor_value", :x => "0", :y => "0"}
|
26
26
|
%field{:name => "LOR"}<
|
27
27
|
right
|
28
28
|
"""
|
@@ -50,7 +50,7 @@ Feature: hardware_smalrubot_s1_ir_photoreflector_value block
|
|
50
50
|
%statement{:name => "DO"}
|
51
51
|
%block{:type => "ruby_p", :x => "0", :y => "0", :inline => "true" }
|
52
52
|
%value{:name => "ARG"}
|
53
|
-
%block{:type => "
|
53
|
+
%block{:type => "hardware_smalrubot_v3_sensor_value", :x => "0", :y => "0"}
|
54
54
|
%field{:name => "LOR"}<
|
55
55
|
right
|
56
56
|
"""
|
@@ -61,7 +61,7 @@ Feature: hardware_smalrubot_s1_ir_photoreflector_value block
|
|
61
61
|
require "smalruby"
|
62
62
|
|
63
63
|
car1 = Character.new(costume: "car1.png", x: 0, y: 0, angle: 0)
|
64
|
-
p(car1.
|
64
|
+
p(car1.smalrubot_v3.right_sensor_value)
|
65
65
|
|
66
66
|
"""
|
67
67
|
|
@@ -81,7 +81,7 @@ Feature: hardware_smalrubot_s1_ir_photoreflector_value block
|
|
81
81
|
%statement{:name => "DO"}
|
82
82
|
%block{:type => "ruby_p", :x => "0", :y => "0", :inline => "true" }
|
83
83
|
%value{:name => "ARG"}
|
84
|
-
%block{:type => "
|
84
|
+
%block{:type => "hardware_smalrubot_v3_sensor_value", :x => "0", :y => "0"}
|
85
85
|
%field{:name => "LOR"}<
|
86
86
|
left
|
87
87
|
"""
|
@@ -94,7 +94,7 @@ Feature: hardware_smalrubot_s1_ir_photoreflector_value block
|
|
94
94
|
car1 = Character.new(costume: "car1.png", x: 0, y: 0, angle: 0)
|
95
95
|
|
96
96
|
car1.on(:start) do
|
97
|
-
p(
|
97
|
+
p(smalrubot_v3.left_sensor_value)
|
98
98
|
end
|
99
99
|
|
100
100
|
"""
|
@@ -4,68 +4,70 @@ require_relative 'shared/block_examples'
|
|
4
4
|
|
5
5
|
# rubocop:disable EmptyLines, LineLength
|
6
6
|
|
7
|
-
describe RubyToBlock::Block, 'Smalrubot
|
8
|
-
|
7
|
+
describe RubyToBlock::Block, 'Smalrubot blocks', to_blocks: true do
|
8
|
+
%w(s1 v3).each do |smalrubot_version|
|
9
|
+
describe smalrubot_version do
|
10
|
+
parts = <<-EOS
|
9
11
|
require "smalruby"
|
10
12
|
|
11
13
|
init_hardware
|
12
14
|
car1 = Character.new(costume: "car1.png", x: 0, y: 0, angle: 0)
|
13
15
|
|
14
16
|
car1.on(:start) do
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
smalrubot_#{smalrubot_version}.forward
|
18
|
+
smalrubot_#{smalrubot_version}.backward
|
19
|
+
smalrubot_#{smalrubot_version}.turn_left
|
20
|
+
smalrubot_#{smalrubot_version}.turn_right
|
21
|
+
smalrubot_#{smalrubot_version}.stop
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
smalrubot_#{smalrubot_version}.forward(sec: 0.5)
|
24
|
+
smalrubot_#{smalrubot_version}.backward(sec: 0.4)
|
25
|
+
smalrubot_#{smalrubot_version}.turn_left(sec: 0.3)
|
26
|
+
smalrubot_#{smalrubot_version}.turn_right(sec: 0.2)
|
27
|
+
smalrubot_#{smalrubot_version}.stop(sec: 0.1)
|
26
28
|
|
27
|
-
p(
|
28
|
-
p(
|
29
|
+
p(smalrubot_#{smalrubot_version}.left_sensor_value)
|
30
|
+
p(smalrubot_#{smalrubot_version}.right_sensor_value)
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
+
smalrubot_#{smalrubot_version}.turn_on_left_led
|
33
|
+
smalrubot_#{smalrubot_version}.turn_off_right_led
|
32
34
|
|
33
|
-
p(
|
34
|
-
p(
|
35
|
+
p(smalrubot_#{smalrubot_version}.left_dc_motor_power_ratio)
|
36
|
+
p(smalrubot_#{smalrubot_version}.right_dc_motor_power_ratio)
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
+
smalrubot_#{smalrubot_version}.left_dc_motor_power_ratio = 10
|
39
|
+
smalrubot_#{smalrubot_version}.right_dc_motor_power_ratio = 90
|
38
40
|
end
|
39
|
-
car1.
|
40
|
-
car1.
|
41
|
-
car1.
|
42
|
-
car1.
|
43
|
-
car1.
|
41
|
+
car1.smalrubot_#{smalrubot_version}.forward
|
42
|
+
car1.smalrubot_#{smalrubot_version}.backward
|
43
|
+
car1.smalrubot_#{smalrubot_version}.turn_left
|
44
|
+
car1.smalrubot_#{smalrubot_version}.turn_right
|
45
|
+
car1.smalrubot_#{smalrubot_version}.stop
|
44
46
|
|
45
|
-
car1.
|
46
|
-
car1.
|
47
|
-
car1.
|
48
|
-
car1.
|
49
|
-
car1.
|
47
|
+
car1.smalrubot_#{smalrubot_version}.forward(sec: 0.5)
|
48
|
+
car1.smalrubot_#{smalrubot_version}.backward(sec: 0.4)
|
49
|
+
car1.smalrubot_#{smalrubot_version}.turn_left(sec: 0.3)
|
50
|
+
car1.smalrubot_#{smalrubot_version}.turn_right(sec: 0.2)
|
51
|
+
car1.smalrubot_#{smalrubot_version}.stop(sec: 0.1)
|
50
52
|
|
51
|
-
p(car1.
|
52
|
-
p(car1.
|
53
|
+
p(car1.smalrubot_#{smalrubot_version}.left_sensor_value)
|
54
|
+
p(car1.smalrubot_#{smalrubot_version}.right_sensor_value)
|
53
55
|
|
54
|
-
car1.
|
55
|
-
car1.
|
56
|
+
car1.smalrubot_#{smalrubot_version}.turn_on_left_led
|
57
|
+
car1.smalrubot_#{smalrubot_version}.turn_off_right_led
|
56
58
|
|
57
|
-
p(car1.
|
58
|
-
p(car1.
|
59
|
+
p(car1.smalrubot_#{smalrubot_version}.left_dc_motor_power_ratio)
|
60
|
+
p(car1.smalrubot_#{smalrubot_version}.right_dc_motor_power_ratio)
|
59
61
|
|
60
|
-
car1.
|
61
|
-
car1.
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
62
|
+
car1.smalrubot_#{smalrubot_version}.left_dc_motor_power_ratio = 10
|
63
|
+
car1.smalrubot_#{smalrubot_version}.right_dc_motor_power_ratio = 90
|
64
|
+
EOS
|
65
|
+
describe compact_source_code(parts) do
|
66
|
+
_parts = parts
|
67
|
+
let(:data) { _parts }
|
66
68
|
|
67
|
-
|
68
|
-
|
69
|
+
it '結果が正しいこと' do
|
70
|
+
should eq_block_xml(<<-XML)
|
69
71
|
<character name="car1" x="0" y="0" angle="0" costumes="car1.png" />
|
70
72
|
<block type="hardware_init_hardware" />
|
71
73
|
<block type="character_new">
|
@@ -73,22 +75,22 @@ car1.smalrubot_s1.right_dc_motor_power_ratio = 90
|
|
73
75
|
<statement name="DO">
|
74
76
|
<block type="events_on_start">
|
75
77
|
<statement name="DO">
|
76
|
-
<block type="
|
78
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_action" inline="true">
|
77
79
|
<field name="ACTION">forward</field>
|
78
80
|
<next>
|
79
|
-
<block type="
|
81
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_action" inline="true">
|
80
82
|
<field name="ACTION">backward</field>
|
81
83
|
<next>
|
82
|
-
<block type="
|
84
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_action" inline="true">
|
83
85
|
<field name="ACTION">turn_left</field>
|
84
86
|
<next>
|
85
|
-
<block type="
|
87
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_action" inline="true">
|
86
88
|
<field name="ACTION">turn_right</field>
|
87
89
|
<next>
|
88
|
-
<block type="
|
90
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_action" inline="true">
|
89
91
|
<field name="ACTION">stop</field>
|
90
92
|
<next>
|
91
|
-
<block type="
|
93
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_action_with_sec" inline="true">
|
92
94
|
<field name="ACTION">forward</field>
|
93
95
|
<value name="SEC">
|
94
96
|
<block type="math_number">
|
@@ -96,7 +98,7 @@ car1.smalrubot_s1.right_dc_motor_power_ratio = 90
|
|
96
98
|
</block>
|
97
99
|
</value>
|
98
100
|
<next>
|
99
|
-
<block type="
|
101
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_action_with_sec" inline="true">
|
100
102
|
<field name="ACTION">backward</field>
|
101
103
|
<value name="SEC">
|
102
104
|
<block type="math_number">
|
@@ -104,7 +106,7 @@ car1.smalrubot_s1.right_dc_motor_power_ratio = 90
|
|
104
106
|
</block>
|
105
107
|
</value>
|
106
108
|
<next>
|
107
|
-
<block type="
|
109
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_action_with_sec" inline="true">
|
108
110
|
<field name="ACTION">turn_left</field>
|
109
111
|
<value name="SEC">
|
110
112
|
<block type="math_number">
|
@@ -112,7 +114,7 @@ car1.smalrubot_s1.right_dc_motor_power_ratio = 90
|
|
112
114
|
</block>
|
113
115
|
</value>
|
114
116
|
<next>
|
115
|
-
<block type="
|
117
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_action_with_sec" inline="true">
|
116
118
|
<field name="ACTION">turn_right</field>
|
117
119
|
<value name="SEC">
|
118
120
|
<block type="math_number">
|
@@ -120,7 +122,7 @@ car1.smalrubot_s1.right_dc_motor_power_ratio = 90
|
|
120
122
|
</block>
|
121
123
|
</value>
|
122
124
|
<next>
|
123
|
-
<block type="
|
125
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_action_with_sec" inline="true">
|
124
126
|
<field name="ACTION">stop</field>
|
125
127
|
<value name="SEC">
|
126
128
|
<block type="math_number">
|
@@ -130,41 +132,41 @@ car1.smalrubot_s1.right_dc_motor_power_ratio = 90
|
|
130
132
|
<next>
|
131
133
|
<block type="ruby_p" inline="true">
|
132
134
|
<value name="ARG">
|
133
|
-
<block type="
|
135
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_sensor_value">
|
134
136
|
<field name="LOR">left</field>
|
135
137
|
</block>
|
136
138
|
</value>
|
137
139
|
<next>
|
138
140
|
<block type="ruby_p" inline="true">
|
139
141
|
<value name="ARG">
|
140
|
-
<block type="
|
142
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_sensor_value">
|
141
143
|
<field name="LOR">right</field>
|
142
144
|
</block>
|
143
145
|
</value>
|
144
146
|
<next>
|
145
|
-
<block type="
|
146
|
-
<field name="
|
147
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_led_turn_on_or_off" inline="true">
|
148
|
+
<field name="LOR">left</field>
|
147
149
|
<field name="OOO">turn_on</field>
|
148
150
|
<next>
|
149
|
-
<block type="
|
150
|
-
<field name="
|
151
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_led_turn_on_or_off" inline="true">
|
152
|
+
<field name="LOR">right</field>
|
151
153
|
<field name="OOO">turn_off</field>
|
152
154
|
<next>
|
153
155
|
<block type="ruby_p" inline="true">
|
154
156
|
<value name="ARG">
|
155
|
-
<block type="
|
157
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_dc_motor_power_ratio">
|
156
158
|
<field name="LOR">left</field>
|
157
159
|
</block>
|
158
160
|
</value>
|
159
161
|
<next>
|
160
162
|
<block type="ruby_p" inline="true">
|
161
163
|
<value name="ARG">
|
162
|
-
<block type="
|
164
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_dc_motor_power_ratio">
|
163
165
|
<field name="LOR">right</field>
|
164
166
|
</block>
|
165
167
|
</value>
|
166
168
|
<next>
|
167
|
-
<block type="
|
169
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_dc_motor_set_power_ratio" inline="true">
|
168
170
|
<field name="LOR">left</field>
|
169
171
|
<value name="SPEED">
|
170
172
|
<block type="math_number">
|
@@ -172,7 +174,7 @@ car1.smalrubot_s1.right_dc_motor_power_ratio = 90
|
|
172
174
|
</block>
|
173
175
|
</value>
|
174
176
|
<next>
|
175
|
-
<block type="
|
177
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_dc_motor_set_power_ratio" inline="true">
|
176
178
|
<field name="LOR">right</field>
|
177
179
|
<value name="SPEED">
|
178
180
|
<block type="math_number">
|
@@ -216,22 +218,22 @@ car1.smalrubot_s1.right_dc_motor_power_ratio = 90
|
|
216
218
|
</block>
|
217
219
|
</statement>
|
218
220
|
<next>
|
219
|
-
<block type="
|
221
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_action" inline="true">
|
220
222
|
<field name="ACTION">forward</field>
|
221
223
|
<next>
|
222
|
-
<block type="
|
224
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_action" inline="true">
|
223
225
|
<field name="ACTION">backward</field>
|
224
226
|
<next>
|
225
|
-
<block type="
|
227
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_action" inline="true">
|
226
228
|
<field name="ACTION">turn_left</field>
|
227
229
|
<next>
|
228
|
-
<block type="
|
230
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_action" inline="true">
|
229
231
|
<field name="ACTION">turn_right</field>
|
230
232
|
<next>
|
231
|
-
<block type="
|
233
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_action" inline="true">
|
232
234
|
<field name="ACTION">stop</field>
|
233
235
|
<next>
|
234
|
-
<block type="
|
236
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_action_with_sec" inline="true">
|
235
237
|
<field name="ACTION">forward</field>
|
236
238
|
<value name="SEC">
|
237
239
|
<block type="math_number">
|
@@ -239,7 +241,7 @@ car1.smalrubot_s1.right_dc_motor_power_ratio = 90
|
|
239
241
|
</block>
|
240
242
|
</value>
|
241
243
|
<next>
|
242
|
-
<block type="
|
244
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_action_with_sec" inline="true">
|
243
245
|
<field name="ACTION">backward</field>
|
244
246
|
<value name="SEC">
|
245
247
|
<block type="math_number">
|
@@ -247,7 +249,7 @@ car1.smalrubot_s1.right_dc_motor_power_ratio = 90
|
|
247
249
|
</block>
|
248
250
|
</value>
|
249
251
|
<next>
|
250
|
-
<block type="
|
252
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_action_with_sec" inline="true">
|
251
253
|
<field name="ACTION">turn_left</field>
|
252
254
|
<value name="SEC">
|
253
255
|
<block type="math_number">
|
@@ -255,7 +257,7 @@ car1.smalrubot_s1.right_dc_motor_power_ratio = 90
|
|
255
257
|
</block>
|
256
258
|
</value>
|
257
259
|
<next>
|
258
|
-
<block type="
|
260
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_action_with_sec" inline="true">
|
259
261
|
<field name="ACTION">turn_right</field>
|
260
262
|
<value name="SEC">
|
261
263
|
<block type="math_number">
|
@@ -263,7 +265,7 @@ car1.smalrubot_s1.right_dc_motor_power_ratio = 90
|
|
263
265
|
</block>
|
264
266
|
</value>
|
265
267
|
<next>
|
266
|
-
<block type="
|
268
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_action_with_sec" inline="true">
|
267
269
|
<field name="ACTION">stop</field>
|
268
270
|
<value name="SEC">
|
269
271
|
<block type="math_number">
|
@@ -273,41 +275,41 @@ car1.smalrubot_s1.right_dc_motor_power_ratio = 90
|
|
273
275
|
<next>
|
274
276
|
<block type="ruby_p" inline="true">
|
275
277
|
<value name="ARG">
|
276
|
-
<block type="
|
278
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_sensor_value">
|
277
279
|
<field name="LOR">left</field>
|
278
280
|
</block>
|
279
281
|
</value>
|
280
282
|
<next>
|
281
283
|
<block type="ruby_p" inline="true">
|
282
284
|
<value name="ARG">
|
283
|
-
<block type="
|
285
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_sensor_value">
|
284
286
|
<field name="LOR">right</field>
|
285
287
|
</block>
|
286
288
|
</value>
|
287
289
|
<next>
|
288
|
-
<block type="
|
289
|
-
<field name="
|
290
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_led_turn_on_or_off" inline="true">
|
291
|
+
<field name="LOR">left</field>
|
290
292
|
<field name="OOO">turn_on</field>
|
291
293
|
<next>
|
292
|
-
<block type="
|
293
|
-
<field name="
|
294
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_led_turn_on_or_off" inline="true">
|
295
|
+
<field name="LOR">right</field>
|
294
296
|
<field name="OOO">turn_off</field>
|
295
297
|
<next>
|
296
298
|
<block type="ruby_p" inline="true">
|
297
299
|
<value name="ARG">
|
298
|
-
<block type="
|
300
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_dc_motor_power_ratio">
|
299
301
|
<field name="LOR">left</field>
|
300
302
|
</block>
|
301
303
|
</value>
|
302
304
|
<next>
|
303
305
|
<block type="ruby_p" inline="true">
|
304
306
|
<value name="ARG">
|
305
|
-
<block type="
|
307
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_dc_motor_power_ratio">
|
306
308
|
<field name="LOR">right</field>
|
307
309
|
</block>
|
308
310
|
</value>
|
309
311
|
<next>
|
310
|
-
<block type="
|
312
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_dc_motor_set_power_ratio" inline="true">
|
311
313
|
<field name="LOR">left</field>
|
312
314
|
<value name="SPEED">
|
313
315
|
<block type="math_number">
|
@@ -315,7 +317,7 @@ car1.smalrubot_s1.right_dc_motor_power_ratio = 90
|
|
315
317
|
</block>
|
316
318
|
</value>
|
317
319
|
<next>
|
318
|
-
<block type="
|
320
|
+
<block type="hardware_smalrubot_#{smalrubot_version}_dc_motor_set_power_ratio" inline="true">
|
319
321
|
<field name="LOR">right</field>
|
320
322
|
<value name="SPEED">
|
321
323
|
<block type="math_number">
|
@@ -362,6 +364,8 @@ car1.smalrubot_s1.right_dc_motor_power_ratio = 90
|
|
362
364
|
</statement>
|
363
365
|
</block>
|
364
366
|
XML
|
367
|
+
end
|
368
|
+
end
|
365
369
|
end
|
366
370
|
end
|
367
371
|
end
|