Skip to content

Commit f4a57e7

Browse files
committed
feat: wedo2 extension block
1 parent 327481a commit f4a57e7

File tree

5 files changed

+346
-213
lines changed

5 files changed

+346
-213
lines changed

src/lib/ruby-generator/wedo2.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,23 @@ export default function (Generator) {
1212
Generator.wedo2_motorOnFor = function (block) {
1313
const motorId = Generator.valueToCode(block, 'MOTOR_ID', Generator.ORDER_NONE) || null;
1414
const duration = Generator.valueToCode(block, 'DURATION', Generator.ORDER_NONE) || null;
15-
return `wedo2_turn_motor_on_for(${motorId}, ${duration})\n`;
15+
return `wedo2.turn_on_for(${motorId}, ${duration})\n`;
1616
};
1717

1818
Generator.wedo2_motorOn = function (block) {
1919
const motorId = Generator.valueToCode(block, 'MOTOR_ID', Generator.ORDER_NONE) || null;
20-
return `wedo2_trun_motor_on(${motorId})\n`;
20+
return `wedo2.turn_on(${motorId})\n`;
2121
};
2222

2323
Generator.wedo2_motorOff = function (block) {
2424
const motorId = Generator.valueToCode(block, 'MOTOR_ID', Generator.ORDER_NONE) || null;
25-
return `wedo2_trun_motor_off(${motorId})\n`;
25+
return `wedo2.turn_off(${motorId})\n`;
2626
};
2727

2828
Generator.wedo2_startMotorPower = function (block) {
2929
const motorId = Generator.valueToCode(block, 'MOTOR_ID', Generator.ORDER_NONE) || null;
3030
const power = Generator.valueToCode(block, 'POWER', Generator.ORDER_NONE) || null;
31-
return `wedo2_set_motor_power(${motorId}, ${power})\n`;
31+
return `wedo2.set_power(${motorId}, ${power})\n`;
3232
};
3333

3434
Generator.wedo2_menu_MOTOR_DIRECTION = function (block) {
@@ -39,12 +39,12 @@ export default function (Generator) {
3939
Generator.wedo2_setMotorDirection = function (block) {
4040
const motorId = Generator.valueToCode(block, 'MOTOR_ID', Generator.ORDER_NONE) || null;
4141
const motorDirection = Generator.valueToCode(block, 'MOTOR_DIRECTION', Generator.ORDER_NONE) || null;
42-
return `wedo2_set_motor_direction(${motorId}, ${motorDirection})\n`;
42+
return `wedo2.set_direction(${motorId}, ${motorDirection})\n`;
4343
};
4444

4545
Generator.wedo2_setLightHue = function (block) {
4646
const hue = Generator.valueToCode(block, 'HUE', Generator.ORDER_NONE) || null;
47-
return `wedo2_set_light_color(${hue})\n`;
47+
return `wedo2.light_color = ${hue}\n`;
4848
};
4949

5050
Generator.wedo2_menu_OP = function (block) {
@@ -56,7 +56,7 @@ export default function (Generator) {
5656
block.isStatement = true;
5757
const op = Generator.valueToCode(block, 'OP', Generator.ORDER_NONE) || null;
5858
const reference = Generator.valueToCode(block, 'REFERENCE', Generator.ORDER_NONE) || null;
59-
return `${Generator.spriteName()}.when(:wedo2_distance, ${op}, ${reference}) do\n`;
59+
return `wedo2.when_distance(${op}, ${reference}) do\n`;
6060
};
6161

6262
Generator.wedo2_menu_TILT_DIRECTION_ANY = function (block) {
@@ -67,16 +67,16 @@ export default function (Generator) {
6767
Generator.wedo2_whenTilted = function (block) {
6868
block.isStatement = true;
6969
const tiltDirectionAny = Generator.valueToCode(block, 'TILT_DIRECTION_ANY', Generator.ORDER_NONE) || null;
70-
return `${Generator.spriteName()}.when(:wedo2_tilted, ${tiltDirectionAny}) do\n`;
70+
return `wedo2.when_tilted(${tiltDirectionAny}) do\n`;
7171
};
7272

7373
Generator.wedo2_getDistance = function () {
74-
return [`wedo2_distance`, Generator.ORDER_ATOMIC];
74+
return [`wedo2.distance`, Generator.ORDER_ATOMIC];
7575
};
7676

7777
Generator.wedo2_isTilted = function (block) {
7878
const tiltDirectionAny = Generator.valueToCode(block, 'TILT_DIRECTION_ANY', Generator.ORDER_NONE) || null;
79-
return `wedo2_tilted(${tiltDirectionAny})\n`;
79+
return `wedo2.tilted?(${tiltDirectionAny})\n`;
8080
};
8181

8282
Generator.wedo2_menu_TILT_DIRECTION = function (block) {
@@ -86,7 +86,7 @@ export default function (Generator) {
8686

8787
Generator.wedo2_getTiltAngle = function (block) {
8888
const tiltDirection = Generator.valueToCode(block, 'TILT_DIRECTION', Generator.ORDER_NONE) || null;
89-
return [`wedo2_tilt_angle(${tiltDirection})`, Generator.ORDER_ATOMIC];
89+
return [`wedo2.tilt_angle(${tiltDirection})`, Generator.ORDER_ATOMIC];
9090
};
9191

9292
return Generator;

src/lib/ruby-to-blocks-converter/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ class RubyToBlocksConverter {
8787
PenConverter,
8888
MicroBitMoreConverter,
8989
EV3Converter,
90-
Wedo2Converter,
9190
GdxForConverter,
9291
MeshConverter,
9392
SmalrubotS1Converter,
@@ -112,7 +111,8 @@ class RubyToBlocksConverter {
112111
ControlConverter,
113112
MicroBitConverter,
114113
VideoConverter,
115-
Text2SpeechConverter
114+
Text2SpeechConverter,
115+
Wedo2Converter
116116
].forEach(x => x.register(this));
117117
}
118118

0 commit comments

Comments
 (0)