Skip to content

Commit 1602f8b

Browse files
committed
範囲外の設置禁止
1 parent d0dd7cd commit 1602f8b

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/ability.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ export function canPlaceMovableObject(cx: Context, x: number, y: number, object:
176176
const positionX = x + i.x;
177177
const positionY = y + i.y;
178178
const target = grid.getBlock(cx, positionX, positionY);
179-
if (target && target !== Block.switch) {
180-
// すでに何かある場合は、ペーストできない
179+
if (target === undefined || (target && target !== Block.switch)) {
180+
// すでに何かある場合or範囲外は、ペーストできない
181181
return false;
182182
}
183183
}

src/grid.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,10 @@ export class Grid {
295295
}
296296
this.oobFallableSprites = [];
297297
}
298-
getBlock(cx: Context, x: number, y: number): Block | null {
298+
getBlock(cx: Context, x: number, y: number): Block | null | undefined {
299+
const cells = get(cx.state).cells;
300+
if (y < 0 || y >= cells.length) return undefined;
301+
if (x < 0 || x >= cells[y].length) return undefined;
299302
return get(cx.state).cells[y]?.[x]?.block ?? null;
300303
}
301304
// satisfies: every(MovableObject.relativePositions, (pos) => pos.x >= 0)

0 commit comments

Comments
 (0)