handle out of bounds positions in tile manipulation functions.

This commit is contained in:
HyperOnion 2023-06-24 12:46:52 +02:00 committed by transoptimal
parent 9668b8a8d2
commit e40eede84d
1 changed files with 7 additions and 1 deletions

View File

@ -11,10 +11,12 @@ function create_world (size) {
const world = create_world(BOX_SIZE);
export function set_tile (world, x, y, tile) {
if (out_of_bounds(x, y)) return;
world.tiles[x][y] = tile;
}
export function get_tile (world, x, y) {
if (out_of_bounds(x, y)) return { type: "out_of_bounds" };
return world.tiles[x][y];
}
@ -25,7 +27,11 @@ export function create_box (parent) {
};
}
export function get_root () {
return world;
}
export function out_of_bounds (x, y) {
return x < 0 || x >= BOX_SIZE ||
y < 0 || y >= BOX_SIZE
}