Skip to content

Commit af350d5

Browse files
authored
Merge pull request #258 from stonesaw/wedo
wedo2のRubyからブロックを追加
2 parents 5c770e8 + 4370118 commit af350d5

File tree

1 file changed

+60
-5
lines changed
  • src/lib/ruby-to-blocks-converter

1 file changed

+60
-5
lines changed

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

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const Wedo2Converter = {
1111
if ((this._isSelf(receiver) || receiver === Opal.nil) && !rubyBlock) {
1212
switch (name) {
1313
case 'wedo2_turn_motor_on_for':
14-
if (args.length === 2 && this._isString(args[0]) && this._isNumberOrBlock(args[1])) {
14+
if (args.length === 2 && this._isStringOrBlock(args[0]) && this._isNumberOrBlock(args[1])) {
1515
block = this._createBlock('wedo2_motorOnFor', 'statement');
1616
this._addInput(
1717
block,
@@ -22,7 +22,7 @@ const Wedo2Converter = {
2222
}
2323
break;
2424
case 'wedo2_trun_motor_on':
25-
if (args.length === 1 && this._isString(args[0])) {
25+
if (args.length === 1 && this._isStringOrBlock(args[0])) {
2626
block = this._createBlock('wedo2_motorOn', 'statement');
2727
this._addInput(
2828
block,
@@ -32,7 +32,7 @@ const Wedo2Converter = {
3232
}
3333
break;
3434
case 'wedo2_trun_motor_off':
35-
if (args.length === 1 && this._isString(args[0])) {
35+
if (args.length === 1 && this._isStringOrBlock(args[0])) {
3636
block = this._createBlock('wedo2_motorOff', 'statement');
3737
this._addInput(
3838
block,
@@ -42,7 +42,7 @@ const Wedo2Converter = {
4242
}
4343
break;
4444
case 'wedo2_set_motor_power':
45-
if (args.length === 2 && this._isString(args[0]) && this._isNumberOrBlock(args[1])) {
45+
if (args.length === 2 && this._isStringOrBlock(args[0]) && this._isNumberOrBlock(args[1])) {
4646
block = this._createBlock('wedo2_startMotorPower', 'statement');
4747
this._addInput(
4848
block,
@@ -53,7 +53,7 @@ const Wedo2Converter = {
5353
}
5454
break;
5555
case 'wedo2_set_motor_direction':
56-
if (args.length === 2 && this._isString(args[0]) && this._isString(args[1])){
56+
if (args.length === 2 && this._isStringOrBlock(args[0]) && this._isStringOrBlock(args[1])){
5757
block = this._createBlock('wedo2_setMotorDirection', 'statement');
5858
this._addInput(
5959
block,
@@ -73,6 +73,61 @@ const Wedo2Converter = {
7373
this._addNumberInput(block, 'HUE', 'math_number', args[0], 50);
7474
}
7575
break;
76+
case 'wedo2_distance':
77+
if (args.length === 0) {
78+
block = this._createBlock('wedo2_getDistance', 'value');
79+
}
80+
break;
81+
case 'wedo2_tilted':
82+
if (args.length === 1 && this._isStringOrBlock(args[0])) {
83+
block = this._createBlock('wedo2_isTilted', 'value');
84+
this._addInput(
85+
block,
86+
'TILT_DIRECTION_ANY',
87+
this._createFieldBlock('wedo2_menu_TILT_DIRECTION_ANY', 'TILT_DIRECTION_ANY', args[0])
88+
);
89+
}
90+
break;
91+
case 'wedo2_tilt_angle':
92+
if (args.length === 1 && this._isStringOrBlock(args[0])) {
93+
block = this._createBlock('wedo2_getTiltAngle', 'value');
94+
this._addInput(
95+
block,
96+
'TILT_DIRECTION',
97+
this._createFieldBlock('wedo2_menu_TILT_DIRECTION', 'TILT_DIRECTION', args[0])
98+
);
99+
}
100+
break;
101+
}
102+
} else if ((this._isSelf(receiver) || receiver === Opal.nil) &&
103+
name === 'when' &&
104+
args.length >= 1 && args[0].type === 'sym' &&
105+
rubyBlockArgs && rubyBlockArgs.length === 0 &&
106+
rubyBlock) {
107+
switch (name) {
108+
case 'wedo2_when_tilted':
109+
if (args.length === 1 && this._isStringOrBlock(args[0])) {
110+
block = this._createBlock('wedo2_whenTilted', 'hat');
111+
this._addInput(
112+
block,
113+
'TILT_DIRECTION_ANY',
114+
this._createFieldBlock('wedo2_menu_TILT_DIRECTION_ANY', 'TILT_DIRECTION_ANY', args[0])
115+
);
116+
this._setParent(rubyBlock, block);
117+
}
118+
break;
119+
case 'wedo2_when_distance':
120+
if (args.length === 2 && this._isStringOrBlock(args[0]) && this._isNumberOrBlock(args[1])) {
121+
block = this._createBlock('wedo2_whenDistance', 'hat');
122+
this._addInput(
123+
block,
124+
'OP',
125+
this._createFieldBlock('wedo2_menu_OP', 'OP', args[0])
126+
);
127+
this._addNumberInput(block, 'REFERENCE', 'math_number', args[1], 50);
128+
this._setParent(rubyBlock, block);
129+
}
130+
break;
76131
}
77132
}
78133
return block;

0 commit comments

Comments
 (0)