BlueGit

timfa questward

Files

questward / shared / lighting / tilePassable.js

tilePassable.js

tilePassable.js 842 B Download Raw
1import { CHUNK_SIZE } from "../protocol/constants.js";
2import { isBlockPassable, isGroundPassable, normalizeGround } from "../definitions/tiles.js";
3
4/** Passability from a chunk snapshot map keyed by "chunkX,chunkY". */
5export function makeSnapshotPassable (chunks)
6{
7 return (tileX, tileY) =>
8 {
9 const chunkX = Math.floor(tileX / CHUNK_SIZE);
10 const chunkY = Math.floor(tileY / CHUNK_SIZE);
11 const snapshot = chunks.get(`${chunkX},${chunkY}`);
12 if (!snapshot)
13 { return true; }
14 const localX = tileX - chunkX * CHUNK_SIZE;
15 const localY = tileY - chunkY * CHUNK_SIZE;
16 const index = localY * CHUNK_SIZE + localX;
17 const ground = normalizeGround(snapshot.grounds?.[index]);
18 if (!isGroundPassable(ground.typeId))
19 { return false; }
20 const block = snapshot.blocks?.[index];
21 return isBlockPassable(block?.typeId ?? null);
22 };
23}