Skip to content

Commit 4152b91

Browse files
committed
gdx_forのhat型のブロックの例外処理を追加
1 parent 516e042 commit 4152b91

File tree

1 file changed

+38
-22
lines changed

1 file changed

+38
-22
lines changed

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

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ const GdxForConverter = {
88
// eslint-disable-next-line no-unused-vars
99
onSend: function (receiver, name, args, rubyBlockArgs, rubyBlock) {
1010
let block;
11+
console.log(rubyBlockArgs)
1112
if ((this._isSelf(receiver) || receiver === Opal.nil) && !rubyBlock) {
1213
switch (name) {
1314
case 'gdx_for_acceleration':
14-
if (args.length === 1) {
15+
if (args.length === 1 && this._isString(args[0])) {
1516
block = this._createBlock('gdxfor_getAcceleration', 'value');
1617
this._addInput(
1718
block,
@@ -21,37 +22,52 @@ const GdxForConverter = {
2122
}
2223
break;
2324
case 'gdx_for_force':
24-
block = this._createBlock('gdxfor_getForce', 'value');
25+
if (args.length === 0){
26+
block = this._createBlock('gdxfor_getForce', 'value');
27+
}
2528
break;
2629
case 'gdx_for_tilted?':
27-
block = this._createBlock('gdxfor_isTilted', 'value');
28-
this._addInput(
29-
block,
30-
'TILT',
31-
this._createFieldBlock('gdxfor_menu_tiltAnyOptions', 'tiltAnyOptions', args[0])
32-
);
30+
if (args.length === 1 && this._isString(args[0])) {
31+
block = this._createBlock('gdxfor_isTilted', 'value');
32+
this._addInput(
33+
block,
34+
'TILT',
35+
this._createFieldBlock('gdxfor_menu_tiltAnyOptions', 'tiltAnyOptions', args[0])
36+
);
37+
}
3338
break;
3439
case 'gdx_for_tilt_angle':
35-
block = this._createBlock('gdxfor_getTilt', 'value');
36-
this._addInput(
37-
block,
38-
'TILT',
39-
this._createFieldBlock('gdxfor_menu_tiltOptions', 'tiltOptions', args[0])
40-
);
40+
if (args.length === 1 && this._isString(args[0])) {
41+
block = this._createBlock('gdxfor_getTilt', 'value');
42+
this._addInput(
43+
block,
44+
'TILT',
45+
this._createFieldBlock('gdxfor_menu_tiltOptions', 'tiltOptions', args[0])
46+
);
47+
}
4148
break;
4249
case 'gdx_for_falling?':
43-
block = this._createBlock('gdxfor_isFreeFalling', 'value');
50+
if (args.length === 0) {
51+
block = this._createBlock('gdxfor_isFreeFalling', 'value');
52+
}
4453
break;
4554
case 'gdx_for_spin_speed':
46-
block = this._createBlock('gdxfor_getSpinSpeed', 'value');
47-
this._addInput(
48-
block,
49-
'DIRECTION',
50-
this._createFieldBlock('gdxfor_menu_axisOptions', 'axisOptions', args[0])
51-
);
55+
if (args.length === 1 && this._isString(args[0])){
56+
block = this._createBlock('gdxfor_getSpinSpeed', 'value');
57+
this._addInput(
58+
block,
59+
'DIRECTION',
60+
this._createFieldBlock('gdxfor_menu_axisOptions', 'axisOptions', args[0])
61+
);
62+
}
5263
break;
5364
}
54-
} else {
65+
} else if ((this._isSelf(receiver) || receiver === Opal.nil) &&
66+
name === 'when' &&
67+
args.length === 2 && args[0].type === "sym" &&
68+
this._isString(args[1]) &&
69+
rubyBlockArgs && rubyBlockArgs.length === 0 &&
70+
rubyBlock) {
5571
switch (args[0].value) {
5672
case 'gdx_for_gesture':
5773
block = this._createBlock('gdxfor_whenGesture', 'hat');

0 commit comments

Comments
 (0)