BlueGit

timfa questward

Files

questward / shared / lighting / tilePassable.js

tilePassable.js

rweaks
timfa Tim Falken · pushed by timfa · 2 months ago
2b34e2dd History
tilePassable.js 1013 B Download Raw
1import { CHUNK_SIZE } from "../protocol/constants.js";
2import {
3 isBlockOccludingLight,
4 isGroundPassable,
5 normalizeGround
6} from "../definitions/tiles.js";
7
8/**
9 * Light-ray clearance from a chunk snapshot map keyed by "chunkX,chunkY".
10 * Uses {@link isBlockOccludingLight} (not movement passability), so furniture
11 * with `blocksLight: false` does not cast night shade shadows.
12 */
13export function makeSnapshotPassable (chunks)
14{
15 return (tileX, tileY) =>
16 {
17 const chunkX = Math.floor(tileX / CHUNK_SIZE);
18 const chunkY = Math.floor(tileY / CHUNK_SIZE);
19 const snapshot = chunks.get(`${chunkX},${chunkY}`);
20 if (!snapshot)
21 { return true; }
22 const localX = tileX - chunkX * CHUNK_SIZE;
23 const localY = tileY - chunkY * CHUNK_SIZE;
24 const index = localY * CHUNK_SIZE + localX;
25 const ground = normalizeGround(snapshot.grounds?.[index]);
26 if (!isGroundPassable(ground.typeId))
27 { return false; }
28 const block = snapshot.blocks?.[index];
29 return !isBlockOccludingLight(block?.typeId ?? null);
30 };
31}