handle out of bounds positions in tile manipulation functions.
This commit is contained in:
parent
9668b8a8d2
commit
e40eede84d
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue