Skip to content

Commit 201ed94

Browse files
committed
Smalrubot S1 extension block -> ruby.
1 parent 367e3fa commit 201ed94

File tree

5 files changed

+70
-3
lines changed

5 files changed

+70
-3
lines changed

src/lib/ruby-generator/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import EV3Blocks from './ev3.js';
2828
import WeDo2Blocks from './wedo2.js';
2929
import GdxForBlocks from './gdx_for.js';
3030
import MeshBlocks from './mesh.js';
31+
import SmalrubotS1Blocks from './smalrubot_s1.js';
3132

3233
const SCALAR_TYPE = '';
3334
const LIST_TYPE = 'list';
@@ -457,5 +458,6 @@ EV3Blocks(RubyGenerator);
457458
WeDo2Blocks(RubyGenerator);
458459
GdxForBlocks(RubyGenerator);
459460
MeshBlocks(RubyGenerator);
461+
SmalrubotS1Blocks(RubyGenerator);
460462

461463
export default RubyGenerator;
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* Define Ruby code generator for Smalrubot S1 Blocks
3+
* @param {RubyGenerator} Generator The RubyGenerator
4+
* @return {RubyGenerator} same as param.
5+
*/
6+
export default function (Generator) {
7+
Generator.smalrubotS1_action = function (block) {
8+
const action = Generator.quote_(
9+
Generator.getFieldValue(block, 'ACTION', Generator.ORDER_NONE) || 'forward'
10+
);
11+
return `smalrubot_s1.action(${action})\n`;
12+
};
13+
14+
Generator.smalrubotS1_actionAndStopAfter = function (block) {
15+
const action = Generator.quote_(
16+
Generator.getFieldValue(block, 'ACTION', Generator.ORDER_NONE) || 'forward'
17+
);
18+
const secs = Generator.valueToCode(block, 'SECS', Generator.ORDER_NONE) || 1;
19+
return `smalrubot_s1.action(${action}, ${secs})\n`;
20+
};
21+
22+
Generator.smalrubotS1_bendArm = function (block) {
23+
const degree = Generator.valueToCode(block, 'DEGREE', Generator.ORDER_NONE) || 90;
24+
const secs = Generator.valueToCode(block, 'SECS', Generator.ORDER_NONE) || 1;
25+
return `smalrubot_s1.bend_arm(${degree}, ${secs})\n`;
26+
};
27+
28+
Generator.smalrubotS1_getSensorValue = function (block) {
29+
const position = Generator.quote_(
30+
Generator.getFieldValue(block, 'POSITION', Generator.ORDER_NONE) || 'left'
31+
);
32+
return [`smalrubot_s1.sensor_value(${position})`, Generator.ORDER_ATOMIC];
33+
};
34+
35+
Generator.smalrubotS1_turnLedOn = function (block) {
36+
const position = Generator.quote_(
37+
Generator.getFieldValue(block, 'POSITION', Generator.ORDER_NONE) || 'left'
38+
);
39+
return `smalrubot_s1.led(${position}, true)\n`;
40+
};
41+
42+
Generator.smalrubotS1_turnLedOff = function (block) {
43+
const position = Generator.quote_(
44+
Generator.getFieldValue(block, 'POSITION', Generator.ORDER_NONE) || 'left'
45+
);
46+
return `smalrubot_s1.led(${position}, false)\n`;
47+
};
48+
49+
Generator.smalrubotS1_getMotorSpeed = function (block) {
50+
const position = Generator.quote_(
51+
Generator.getFieldValue(block, 'POSITION', Generator.ORDER_NONE) || 'left'
52+
);
53+
return [`smalrubot_s1.get_motor_speed(${position})`, Generator.ORDER_ATOMIC];
54+
};
55+
56+
Generator.smalrubotS1_setMotorSpeed = function (block) {
57+
const position = Generator.quote_(
58+
Generator.getFieldValue(block, 'POSITION', Generator.ORDER_NONE) || 'left'
59+
);
60+
const speed = Generator.valueToCode(block, 'SPEED', Generator.ORDER_NONE) || 1;
61+
return `smalrubot_s1.set_motor_speed(${position}, ${speed})\n`;
62+
};
63+
64+
return Generator;
65+
}

src/locales/en.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default {
3030
'gui.smalruby3.extension.smalrubotS1.connectingMessage': 'Connecting the Smalrubot S1',
3131
'smalrubotS1.categoryName': 'Smalrubot S1',
3232
'smalrubotS1.action': '[ACTION]',
33-
'smalrubotS1.actionAndStopAfter': '[ACTION] for [SEC] seconds',
33+
'smalrubotS1.actionAndStopAfter': '[ACTION] for [SECS] seconds',
3434
'smalrubotS1.bendArm': 'bend arm [DEGREE] degrees in [SECS] seconds',
3535
'smalrubotS1.getSensorValue': '[POSITION] sensor value',
3636
'smalrubotS1.turnLedOn': 'turn [POSITION] LED on',

src/locales/ja-Hira.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default {
3232
'gui.smalruby3.extension.smalrubotS1.connectingMessage': 'スモウルボットS1 (エス1) にせつぞくしています。',
3333
'smalrubotS1.categoryName': 'スモウルボットS1 (エス1)',
3434
'smalrubotS1.action': '[ACTION]',
35-
'smalrubotS1.actionAndStopAfter': '[SEC] びょう [ACTION]',
35+
'smalrubotS1.actionAndStopAfter': '[SECS] びょう [ACTION]',
3636
'smalrubotS1.bendArm': '[SECS] びょうでアームを [DEGREE] どにまげる',
3737
'smalrubotS1.getSensorValue': '[POSITION] のセンサー',
3838
'smalrubotS1.turnLedOn': '[POSITION] のLED (エルイーディー) をオンにする',

src/locales/ja.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default {
3232
'gui.smalruby3.extension.smalrubotS1.connectingMessage': 'スモウルボットS1に接続しています。',
3333
'smalrubotS1.categoryName': 'スモウルボットS1',
3434
'smalrubotS1.action': '[ACTION]',
35-
'smalrubotS1.actionAndStopAfter': '[SEC] 秒 [ACTION]',
35+
'smalrubotS1.actionAndStopAfter': '[SECS] 秒 [ACTION]',
3636
'smalrubotS1.bendArm': '[SECS] 秒でアームを [DEGREE] 度に曲げる',
3737
'smalrubotS1.getSensorValue': '[POSITION] のセンサー',
3838
'smalrubotS1.turnLedOn': '[POSITION] のLEDをオンにする',

0 commit comments

Comments
 (0)