Skip to content

Commit

Permalink
fix: support nil some methods
Browse files Browse the repository at this point in the history
  • Loading branch information
takaokouji committed Aug 25, 2024
1 parent 0a44828 commit 30ec3da
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/lib/ruby-to-blocks-converter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,10 @@ class RubyToBlocksConverter {
return value === false || (value && value.type === 'false');
}

isNil (value) {
return value === Opal.nil || (value && value.type === 'nil');
}

_isArray (value) {
return _.isArray(value) || (value && value.type === 'array');
}
Expand Down Expand Up @@ -1274,6 +1278,10 @@ class RubyToBlocksConverter {
return new Primitive('hash', new Map(node.children.map(childNode => this._process(childNode))), node);
}

_onNil (node) {
return new Primitive('nil', Opal.nil, node);
}

_onPair (node) {
this._checkNumChildren(node, 2);

Expand Down
8 changes: 4 additions & 4 deletions src/lib/ruby-to-blocks-converter/koshien.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ const KoshienConverter = {

if (!checkPosition(src)) return null;
if (!checkPosition(dst)) return null;
if (!converter.isListBlock(exceptCells)) return null;
if (!converter.isListBlock(result)) return null;
if (!converter.isListBlock(exceptCells) && !converter.isNil(exceptCells)) return null;
if (!converter.isListBlock(result) && !converter.isNil(result)) return null;

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

if (!checkPosition(args[0])) return null;
if (!converter.isVariableBlock(args[1])) return null;
if (!converter.isVariableBlock(args[1]) && !converter.isNil(args[1])) return null;

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

const block = converter.changeRubyExpressionBlock(receiver, 'koshien_locateObjects', 'statement');
converter.addNumberInput(block, 'SQ_SIZE', 'math_number', sqSize, 0);
Expand Down
3 changes: 3 additions & 0 deletions test/integration/ruby-tab/extension_koshien.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ describe('Ruby Tab: Koshien extension blocks', () => {
koshien.get_map_area("0:1")
koshien.move_to("2:3")
koshien.calc_route(result: list("$最短経路"), src: "4:5", dst: "6:7", except_cells: list("$通らない座標"))
koshien.calc_route(result: nil, src: "4:5", dst: "6:7", except_cells: nil)
koshien.set_dynamite("8:9")
koshien.set_bomb("10:11")
$マップ情報 = koshien.map("12:13")
$すべてのマップ情報 = koshien.map_all
$マップ情報 = koshien.map_from("14:0", $すべてのマップ情報)
$マップ情報 = koshien.map_from("14:0", nil)
koshien.locate_objects(result: list("$地形・アイテム"), sq_size: 3, cent: "1:2", objects: "A B C D")
koshien.locate_objects(result: nil, sq_size: 3, cent: "1:2", objects: "A B C D")
koshien.turn_over
koshien.position_of_x("0:1")
Expand Down

0 comments on commit 30ec3da

Please sign in to comment.