Skip to content

Commit 30ec3da

Browse files
committed
fix: support nil some methods
1 parent 0a44828 commit 30ec3da

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,10 @@ class RubyToBlocksConverter {
509509
return value === false || (value && value.type === 'false');
510510
}
511511

512+
isNil (value) {
513+
return value === Opal.nil || (value && value.type === 'nil');
514+
}
515+
512516
_isArray (value) {
513517
return _.isArray(value) || (value && value.type === 'array');
514518
}
@@ -1274,6 +1278,10 @@ class RubyToBlocksConverter {
12741278
return new Primitive('hash', new Map(node.children.map(childNode => this._process(childNode))), node);
12751279
}
12761280

1281+
_onNil (node) {
1282+
return new Primitive('nil', Opal.nil, node);
1283+
}
1284+
12771285
_onPair (node) {
12781286
this._checkNumChildren(node, 2);
12791287

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ const KoshienConverter = {
6868

6969
if (!checkPosition(src)) return null;
7070
if (!checkPosition(dst)) return null;
71-
if (!converter.isListBlock(exceptCells)) return null;
72-
if (!converter.isListBlock(result)) return null;
71+
if (!converter.isListBlock(exceptCells) && !converter.isNil(exceptCells)) return null;
72+
if (!converter.isListBlock(result) && !converter.isNil(result)) return null;
7373

7474
const block = converter.changeRubyExpressionBlock(receiver, 'koshien_calcRoute', 'statement');
7575
converter.addTextInput(block, 'SRC', src, '0:0');
@@ -113,7 +113,7 @@ const KoshienConverter = {
113113
const {receiver, args} = params;
114114

115115
if (!checkPosition(args[0])) return null;
116-
if (!converter.isVariableBlock(args[1])) return null;
116+
if (!converter.isVariableBlock(args[1]) && !converter.isNil(args[1])) return null;
117117

118118
const block = converter.changeRubyExpressionBlock(receiver, 'koshien_mapFrom', 'value');
119119
converter.addTextInput(block, 'POSITION', args[0], '0:0');
@@ -133,7 +133,7 @@ const KoshienConverter = {
133133
if (!converter.isNumberOrBlock(sqSize)) return null;
134134
if (!checkPosition(cent)) return null;
135135
if (!converter.isStringOrBlock(objects)) return null;
136-
if (!converter.isListBlock(result)) return null;
136+
if (!converter.isListBlock(result) && !converter.isNil(result)) return null;
137137

138138
const block = converter.changeRubyExpressionBlock(receiver, 'koshien_locateObjects', 'statement');
139139
converter.addNumberInput(block, 'SQ_SIZE', 'math_number', sqSize, 0);

test/integration/ruby-tab/extension_koshien.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@ describe('Ruby Tab: Koshien extension blocks', () => {
3333
koshien.get_map_area("0:1")
3434
koshien.move_to("2:3")
3535
koshien.calc_route(result: list("$最短経路"), src: "4:5", dst: "6:7", except_cells: list("$通らない座標"))
36+
koshien.calc_route(result: nil, src: "4:5", dst: "6:7", except_cells: nil)
3637
koshien.set_dynamite("8:9")
3738
koshien.set_bomb("10:11")
3839
$マップ情報 = koshien.map("12:13")
3940
$すべてのマップ情報 = koshien.map_all
4041
$マップ情報 = koshien.map_from("14:0", $すべてのマップ情報)
42+
$マップ情報 = koshien.map_from("14:0", nil)
4143
koshien.locate_objects(result: list("$地形・アイテム"), sq_size: 3, cent: "1:2", objects: "A B C D")
44+
koshien.locate_objects(result: nil, sq_size: 3, cent: "1:2", objects: "A B C D")
4245
koshien.turn_over
4346
4447
koshien.position_of_x("0:1")

0 commit comments

Comments
 (0)