Skip to content

Commit e92732f

Browse files
committed
wedo2.0を追加
1 parent 73ab44d commit e92732f

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

src/lib/ruby-generator/wedo2.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,89 @@
44
* @return {RubyGenerator} same as param.
55
*/
66
export default function (Generator) {
7+
Generator.wedo2_menu_MOTOR_ID = function (block) {
8+
const motor_id = Generator.quote_(Generator.getFieldValue(block, 'MOTOR_ID') || 'motor');
9+
return [motor_id, Generator.ORDER_ATOMIC]
10+
};
11+
Generator.wedo2_motorOnFor = function (block) {
12+
const motor_id = Generator.valueToCode(block, 'MOTOR_ID', Generator.ORDER_NONE) || null;
13+
const duration = Generator.valueToCode(block, 'DURATION', Generator.ORDER_NONE) || null;
14+
return `wedo2_turn_motor_on_for(${motor_id}, ${duration})\n`;
15+
};
16+
17+
Generator.wedo2_motorOn = function (block) {
18+
const motor_id = Generator.valueToCode(block, 'MOTOR_ID', Generator.ORDER_NONE) || null;
19+
return `wedo2_trun_motor_on(${motor_id})\n`;
20+
};
21+
22+
Generator.wedo2_motorOff = function (block) {
23+
const motor_id = Generator.valueToCode(block, 'MOTOR_ID', Generator.ORDER_NONE) || null;
24+
return `wedo2_trun_motor_off(${motor_id})\n`;
25+
};
26+
27+
Generator.wedo2_startMotorPower = function (block) {
28+
const motor_id = Generator.valueToCode(block, 'MOTOR_ID', Generator.ORDER_NONE) || null;
29+
const power =Generator.valueToCode(block, 'POWER', Generator.ORDER_NONE) || null;
30+
return `wedo2_set_motor_power(${motor_id}, ${power})\n`;
31+
};
32+
33+
Generator.wedo2_menu_MOTOR_DIRECTION = function (block) {
34+
const motor_direction = Generator.quote_(Generator.getFieldValue(block, 'MOTOR_DIRECTION') || 'this way');
35+
return [motor_direction, Generator.ORDER_ATOMIC];
36+
};
37+
38+
Generator.wedo2_setMotorDirection = function (block) {
39+
const motor_id = Generator.valueToCode(block, 'MOTOR_ID', Generator.ORDER_NONE) || null;
40+
const motor_direction = Generator.valueToCode(block, 'MOTOR_DIRECTION', Generator.ORDER_NONE) || null;
41+
return `wedo2_set_motor_direction(${motor_id}, ${motor_direction})\n`;
42+
};
43+
44+
Generator.wedo2_setLightHue = function (block) {
45+
const hue = Generator.valueToCode(block, 'HUE', Generator.ORDER_NONE) || null;
46+
return `wedo2_set_light_color(${hue})\n`;
47+
};
48+
49+
Generator.wedo2_menu_OP = function (block) {
50+
const op = Generator.quote_(Generator.getFieldValue(block, 'OP') || '<');
51+
return [op, Generator.ORDER_ATOMIC];
52+
};
53+
54+
Generator.wedo2_whenDistance = function (block) {
55+
block.isStatement = true;
56+
const op = Generator.valueToCode(block, 'OP', Generator.ORDER_NONE) || null;
57+
const reference = Generator.valueToCode(block, 'REFERENCE', Generator.ORDER_NONE) || null;
58+
return `wedo2_when_distance(${op}, ${reference}) do\n`;
59+
};
60+
61+
Generator.wedo2_menu_TILT_DIRECTION_ANY = function (block) {
62+
const tilt_direction_any = Generator.quote_(Generator.getFieldValue(block, 'TILT_DIRECTION_ANY') || 'any');
63+
return [tilt_direction_any, Generator.ORDER_ATOMIC];
64+
};
65+
66+
Generator.wedo2_whenTilted = function (block) {
67+
block.isStatement = true;
68+
const tilt_direction_any = Generator.valueToCode(block, 'TILT_DIRECTION_ANY', Generator.ORDER_NONE) || null;
69+
return `wedo2_when_tilted(${tilt_direction_any}) do\n`;
70+
};
71+
772
Generator.wedo2_getDistance = function (block) {
873
return [`wedo2_distance`, Generator.ORDER_ATOMIC];
974
};
1075

76+
Generator.wedo2_isTilted = function (block) {
77+
const tilt_direction_any = Generator.valueToCode(block, 'TILT_DIRECTION_ANY', Generator.ORDER_NONE) || null;
78+
return `wedo2_tilted(${tilt_direction_any})\n`;
79+
};
80+
81+
Generator.wedo2_menu_TILT_DIRECTION = function (block) {
82+
const tilt_direction = Generator.quote_(Generator.getFieldValue(block, 'TILT_DIRECTION') || 'up');
83+
return [tilt_direction, Generator.ORDER_ATOMIC];
84+
};
85+
86+
Generator.wedo2_getTiltAngle = function (block) {
87+
const tilt_direction = Generator.valueToCode(block, 'TILT_DIRECTION', Generator.ORDER_NONE) || null;
88+
return [`wedo2_tilt_angle(${tilt_direction})`, Generator.ORDER_ATOMIC];
89+
};
90+
1191
return Generator;
1292
}

0 commit comments

Comments
 (0)