From cc2ae41bb561f2d60084e0b17abafd59899839ab Mon Sep 17 00:00:00 2001 From: Tangent Wantwight Date: Fri, 12 Jan 2024 23:45:19 -0500 Subject: [PATCH] refactor --- island.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/island.ts b/island.ts index 2265905..d4964eb 100644 --- a/island.ts +++ b/island.ts @@ -157,13 +157,19 @@ export function IslandApplet() { } } + function dropWithin(tiles: number[]) { + if (tiles.length > 0) { + drop(tiles[islands.rng() % tiles.length]); + } + } + function tick() { const islandTiles = islands.floodSearch(basePos, (tile) => tile > 0); - drop(islandTiles[islands.rng() % islandTiles.length]); - drop(islandTiles[islands.rng() % islandTiles.length]); + dropWithin(islandTiles); + dropWithin(islandTiles); const mountainTiles = islands.floodSearch(basePos - 8, (tile) => tile > 4); - drop(mountainTiles[islands.rng() % mountainTiles.length]); + dropWithin(mountainTiles); // const erodePos = islandTiles[islands.rng() % islandTiles.length]; // islands.data[erodePos] = Math.max(islands.data[erodePos] - 1, 0);