From a55eb310b0bdf3de21e2e0d554ca0b0f1e84c4be Mon Sep 17 00:00:00 2001 From: HyperOnion <> Date: Wed, 28 Jun 2023 15:03:22 +0200 Subject: [PATCH] recursively update tiles within boxes. --- js/main.mjs | 4 ++-- js/tile_update.mjs | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/js/main.mjs b/js/main.mjs index c7840c2..1713631 100644 --- a/js/main.mjs +++ b/js/main.mjs @@ -1,5 +1,5 @@ import * as graphics from "./graphics.mjs"; -import { BOX_SIZE, get_tile } from "./world.mjs"; +import { BOX_SIZE, get_tile, get_root } from "./world.mjs"; import { get_player_box } from "./player.mjs"; import { save_in_browser, load_from_browser } from "./save_load.mjs"; import { tick } from "/js/tile_update.mjs"; @@ -21,7 +21,7 @@ function main (timestamp) { const delta = dt_ms / 1000; render(delta); - tick(delta); + tick(get_root(), delta); requestAnimationFrame(main); } diff --git a/js/tile_update.mjs b/js/tile_update.mjs index 1b9ba76..d95f146 100644 --- a/js/tile_update.mjs +++ b/js/tile_update.mjs @@ -6,8 +6,7 @@ import * as random from "/js/utils/random.mjs"; // lots of this code is very hacky temporary for testing things out & getting started with tile updates. -export function tick (delta_time) { - const box = get_player_box(); +export function tick (box, delta_time) { world.for_each_tile(box, (x, y, tile) => { if (tile_tickers.has(tile.type)) { tile_tickers.get(tile.type)(box, x, y, delta_time); @@ -24,6 +23,11 @@ const dirs = [ [ 0, 1 ], ]; +// this might become terrible for performance eventually. +tile_tickers.set("box", (box, x, y, delta_time) => { + tick(world.get_tile(box, x, y).box, delta_time); +}); + tile_tickers.set("grass", (box, x, y, delta_time) => { const tile = world.get_tile(box, x, y); if (Math.random() > 0.8 ** delta_time) {