BlueGit

timfa questward

Fix door open replication, light, and spell LoS.

Doors stay per-tile (not atlas); open on path-set when adjacent; closed doors solid-block light and ranged LoS with live occlusion updates.

timfa Tim Falken · pushed by timfa

Authored 2026-09-02 · 2 months ago

Hash
8a3825f30282cd37f1b41317d4b55cadb76a51a3
Parent
f1dda02b
7 files changed +49 −21
client/src/render/worldView.js +11 −9
@@ -1,7 +1,7 @@
1 1 import { CHUNK_SIZE, SPRITE_SIZE_PX, GAIT, DEFAULT_WORLD_SETTINGS, PIVOT_FROM_BOTTOM_PX, ENTITY_STACK_SPREAD_DIAMETER_PX } from "/shared/protocol/constants.js";
2 2 import { dynamicLightAtTile, dynamicDarknessAtTile, lightIntensity } from "/shared/lighting/raycast.js";
3 3 import { makeSnapshotLightOcclusion } from "/shared/lighting/tilePassable.js";
4 import { bakeChunkOcclusion } from "/shared/lighting/chunkOcclusion.js";
4 import { bakeChunkOcclusion, tileLightOcclusionAt } from "/shared/lighting/chunkOcclusion.js";
5 5 import { smoothLitCorner } from "/shared/lighting/lightCorners.js";
6 6 import { bloomCompanionName, spriteImageName } from "/shared/definitions/tileSprites.js";
7 7 import { EQUIPMENT_SLOT, itemEquipSprite, itemSpriteName, itemSpriteNameForStack, itemDefinition } from "/shared/definitions/items.js";
@@ -15,7 +15,7 @@ import
15 15 } from "/shared/render/tint.js";
16 16 import { layersFromSpawnerConfig } from "/shared/appearance/layers.js";
17 17 import { chargeSpriteFrameIndex, itemMaxCharges } from "/shared/items/charges.js";
18 import { normalizeGround, normalizeBlock, isWadeGroundInSeason, isWaterGround, isLiquidWaterGround, isGroundPassable, isBlockOccludingLight, LightOcclusion, blockDefinition } from "/shared/definitions/tiles.js";
18 import { normalizeGround, normalizeBlock, isWadeGroundInSeason, isWaterGround, isLiquidWaterGround, isGroundPassable, LightOcclusion, blockDefinition, blockLightOcclusionForBlock } from "/shared/definitions/tiles.js";
19 19 import { doorSortSubOrder } from "/shared/world/doors.js";
20 20 import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer, flightSortLayer } from "/shared/render/pivot.js";
21 21 import { bakeChunkAtlases, tileBlockSpriteEntry } from "./chunkBake.js";
@@ -633,10 +633,7 @@ export class WorldView
633 633 if (normalizeDimensionId(this.dimensionId) !== snapDim)
634 634 { return; }
635 635 const key = `${snapshot.chunkX},${snapshot.chunkY}`;
636 if (!Array.isArray(snapshot.occlusion) || snapshot.occlusion.length < CHUNK_SIZE * CHUNK_SIZE)
637 {
638 snapshot.occlusion = bakeChunkOcclusion(snapshot);
639 }
636 snapshot.occlusion = bakeChunkOcclusion(snapshot);
640 637 this.chunks.set(key, snapshot);
641 638 this.#scheduleChunkRebuild(snapshot);
642 639 this.#redrawPreview();
@@ -1842,6 +1839,13 @@ export class WorldView
1842 1839 { snapshot.blocks[index] = block; }
1843 1840 if (light !== undefined)
1844 1841 { snapshot.light[index] = light; }
1842 if (ground !== undefined || block !== undefined)
1843 {
1844 if (!Array.isArray(snapshot.occlusion) || snapshot.occlusion.length < CHUNK_SIZE * CHUNK_SIZE)
1845 { snapshot.occlusion = bakeChunkOcclusion(snapshot); }
1846 else
1847 { snapshot.occlusion[index] = tileLightOcclusionAt(snapshot.grounds, snapshot.blocks, localX, localY); }
1848 }
1845 1849 const tileX = chunkX * CHUNK_SIZE + localX;
1846 1850 const tileY = chunkY * CHUNK_SIZE + localY;
1847 1851 if (block !== undefined)
@@ -4119,12 +4123,10 @@ export class WorldView
4119 4123 if (localX < 0 || localY < 0 || localX >= CHUNK_SIZE || localY >= CHUNK_SIZE)
4120 4124 { return false; }
4121 4125 const index = localY * CHUNK_SIZE + localX;
4122 if (Array.isArray(snapshot.occlusion) && snapshot.occlusion.length > index)
4123 { return (snapshot.occlusion[index] | 0) >= LightOcclusion.solid; }
4124 4126 const ground = normalizeGround(snapshot.grounds?.[index]);
4125 4127 if (!isGroundPassable(ground.typeId))
4126 4128 { return true; }
4127 return isBlockOccludingLight(snapshot.blocks?.[index]?.typeId ?? null);
4129 return blockLightOcclusionForBlock(snapshot.blocks?.[index]) === LightOcclusion.solid;
4128 4130 }
4129 4131
4130 4132 #fillChunkLightGrids (baked, activeLights, lightOcclusion, ambientDark)
@@ -1,7 +1,7 @@
1import { CHUNK_SIZE, SPRITE_SIZE_PX, GAIT, DEFAULT_WORLD_SETTINGS, PIVOT_FROM_BOTTOM_PX, ENTITY_STACK_SPREAD_DIAMETER_PX } from "/shared/protocol/constants.js";
1import { CHUNK_SIZE, SPRITE_SIZE_PX, GAIT, DEFAULT_WORLD_SETTINGS, PIVOT_FROM_BOTTOM_PX, ENTITY_STACK_SPREAD_DIAMETER_PX } from "/shared/protocol/constants.js";
2import { dynamicLightAtTile, dynamicDarknessAtTile, lightIntensity } from "/shared/lighting/raycast.js";
2import { dynamicLightAtTile, dynamicDarknessAtTile, lightIntensity } from "/shared/lighting/raycast.js";
3import { makeSnapshotLightOcclusion } from "/shared/lighting/tilePassable.js";
3import { makeSnapshotLightOcclusion } from "/shared/lighting/tilePassable.js";
4import { bakeChunkOcclusion } from "/shared/lighting/chunkOcclusion.js";
4import { bakeChunkOcclusion, tileLightOcclusionAt } from "/shared/lighting/chunkOcclusion.js";
5import { smoothLitCorner } from "/shared/lighting/lightCorners.js";
5import { smoothLitCorner } from "/shared/lighting/lightCorners.js";
6import { bloomCompanionName, spriteImageName } from "/shared/definitions/tileSprites.js";
6import { bloomCompanionName, spriteImageName } from "/shared/definitions/tileSprites.js";
7import { EQUIPMENT_SLOT, itemEquipSprite, itemSpriteName, itemSpriteNameForStack, itemDefinition } from "/shared/definitions/items.js";
7import { EQUIPMENT_SLOT, itemEquipSprite, itemSpriteName, itemSpriteNameForStack, itemDefinition } from "/shared/definitions/items.js";
@@ -15,7 +15,7 @@ import
15} from "/shared/render/tint.js";
15} from "/shared/render/tint.js";
16import { layersFromSpawnerConfig } from "/shared/appearance/layers.js";
16import { layersFromSpawnerConfig } from "/shared/appearance/layers.js";
17import { chargeSpriteFrameIndex, itemMaxCharges } from "/shared/items/charges.js";
17import { chargeSpriteFrameIndex, itemMaxCharges } from "/shared/items/charges.js";
18import { normalizeGround, normalizeBlock, isWadeGroundInSeason, isWaterGround, isLiquidWaterGround, isGroundPassable, isBlockOccludingLight, LightOcclusion, blockDefinition } from "/shared/definitions/tiles.js";
18import { normalizeGround, normalizeBlock, isWadeGroundInSeason, isWaterGround, isLiquidWaterGround, isGroundPassable, LightOcclusion, blockDefinition, blockLightOcclusionForBlock } from "/shared/definitions/tiles.js";
19import { doorSortSubOrder } from "/shared/world/doors.js";
19import { doorSortSubOrder } from "/shared/world/doors.js";
20import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer, flightSortLayer } from "/shared/render/pivot.js";
20import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer, flightSortLayer } from "/shared/render/pivot.js";
21import { bakeChunkAtlases, tileBlockSpriteEntry } from "./chunkBake.js";
21import { bakeChunkAtlases, tileBlockSpriteEntry } from "./chunkBake.js";
@@ -633,10 +633,7 @@ export class WorldView
633 if (normalizeDimensionId(this.dimensionId) !== snapDim)
633 if (normalizeDimensionId(this.dimensionId) !== snapDim)
634 { return; }
634 { return; }
635 const key = `${snapshot.chunkX},${snapshot.chunkY}`;
635 const key = `${snapshot.chunkX},${snapshot.chunkY}`;
636 if (!Array.isArray(snapshot.occlusion) || snapshot.occlusion.length < CHUNK_SIZE * CHUNK_SIZE)
636 snapshot.occlusion = bakeChunkOcclusion(snapshot);
637 {
638 snapshot.occlusion = bakeChunkOcclusion(snapshot);
639 }
640 this.chunks.set(key, snapshot);
637 this.chunks.set(key, snapshot);
641 this.#scheduleChunkRebuild(snapshot);
638 this.#scheduleChunkRebuild(snapshot);
642 this.#redrawPreview();
639 this.#redrawPreview();
@@ -1842,6 +1839,13 @@ export class WorldView
1842 { snapshot.blocks[index] = block; }
1839 { snapshot.blocks[index] = block; }
1843 if (light !== undefined)
1840 if (light !== undefined)
1844 { snapshot.light[index] = light; }
1841 { snapshot.light[index] = light; }
1842 if (ground !== undefined || block !== undefined)
1843 {
1844 if (!Array.isArray(snapshot.occlusion) || snapshot.occlusion.length < CHUNK_SIZE * CHUNK_SIZE)
1845 { snapshot.occlusion = bakeChunkOcclusion(snapshot); }
1846 else
1847 { snapshot.occlusion[index] = tileLightOcclusionAt(snapshot.grounds, snapshot.blocks, localX, localY); }
1848 }
1845 const tileX = chunkX * CHUNK_SIZE + localX;
1849 const tileX = chunkX * CHUNK_SIZE + localX;
1846 const tileY = chunkY * CHUNK_SIZE + localY;
1850 const tileY = chunkY * CHUNK_SIZE + localY;
1847 if (block !== undefined)
1851 if (block !== undefined)
@@ -4119,12 +4123,10 @@ export class WorldView
4119 if (localX < 0 || localY < 0 || localX >= CHUNK_SIZE || localY >= CHUNK_SIZE)
4123 if (localX < 0 || localY < 0 || localX >= CHUNK_SIZE || localY >= CHUNK_SIZE)
4120 { return false; }
4124 { return false; }
4121 const index = localY * CHUNK_SIZE + localX;
4125 const index = localY * CHUNK_SIZE + localX;
4122 if (Array.isArray(snapshot.occlusion) && snapshot.occlusion.length > index)
4123 { return (snapshot.occlusion[index] | 0) >= LightOcclusion.solid; }
4124 const ground = normalizeGround(snapshot.grounds?.[index]);
4126 const ground = normalizeGround(snapshot.grounds?.[index]);
4125 if (!isGroundPassable(ground.typeId))
4127 if (!isGroundPassable(ground.typeId))
4126 { return true; }
4128 { return true; }
4127 return isBlockOccludingLight(snapshot.blocks?.[index]?.typeId ?? null);
4129 return blockLightOcclusionForBlock(snapshot.blocks?.[index]) === LightOcclusion.solid;
4128 }
4130 }
4129
4131
4130 #fillChunkLightGrids (baked, activeLights, lightOcclusion, ambientDark)
4132 #fillChunkLightGrids (baked, activeLights, lightOcclusion, ambientDark)
server/src/doors/service.js +3 −0
@@ -9,6 +9,7 @@ import {
9 9 import { tileToChunk, tileToLocal, tileKey, parseTileKey } from "../world/coordinates.js";
10 10 import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";
11 11 import { OVERWORLD_ID } from "../../../shared/world/dimensions.js";
12 import { tileLightOcclusionAt } from "../../../shared/lighting/chunkOcclusion.js";
12 13
13 14 export function isDoorTypeId (typeId)
14 15 {
@@ -74,6 +75,8 @@ function writeDoorState (world, tileX, tileY, state, config, dimensionId = OVERW
74 75 config: config ?? prev.config ?? null
75 76 };
76 77 data.blocks[index] = block;
78 if (Array.isArray(data.occlusion) && data.occlusion.length > index)
79 { data.occlusion[index] = tileLightOcclusionAt(data.grounds, data.blocks, localX, localY); }
77 80 return {
78 81 type: "chunk-delta",
79 82 chunkX,
@@ -9,6 +9,7 @@ import {
9import { tileToChunk, tileToLocal, tileKey, parseTileKey } from "../world/coordinates.js";
9import { tileToChunk, tileToLocal, tileKey, parseTileKey } from "../world/coordinates.js";
10import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";
10import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";
11import { OVERWORLD_ID } from "../../../shared/world/dimensions.js";
11import { OVERWORLD_ID } from "../../../shared/world/dimensions.js";
12import { tileLightOcclusionAt } from "../../../shared/lighting/chunkOcclusion.js";
12
13
13export function isDoorTypeId (typeId)
14export function isDoorTypeId (typeId)
14{
15{
@@ -74,6 +75,8 @@ function writeDoorState (world, tileX, tileY, state, config, dimensionId = OVERW
74 config: config ?? prev.config ?? null
75 config: config ?? prev.config ?? null
75 };
76 };
76 data.blocks[index] = block;
77 data.blocks[index] = block;
78 if (Array.isArray(data.occlusion) && data.occlusion.length > index)
79 { data.occlusion[index] = tileLightOcclusionAt(data.grounds, data.blocks, localX, localY); }
77 return {
80 return {
78 type: "chunk-delta",
81 type: "chunk-delta",
79 chunkX,
82 chunkX,
server/src/simulation/workerWorld.js +12 −3
@@ -479,8 +479,7 @@ export class WorkerWorld
479 479 switch (command.type)
480 480 {
481 481 case "move-to":
482 this.#moveTo(sessionId, command.characterId, command.tileX, command.tileY);
483 return { events: [] };
482 return this.#moveTo(sessionId, command.characterId, command.tileX, command.tileY);
484 483 case "set-gait":
485 484 return this.#setGait(sessionId, command.characterId, command.gait);
486 485 case "attack":
@@ -856,7 +855,7 @@ export class WorkerWorld
856 855 {
857 856 const { handle, entityId } = this.#requireOwnedEntity(sessionId, characterId);
858 857 if (this.frozen.has(entityId))
859 { return; }
858 { return { events: [] }; }
860 859 clearEngage(this.ecs, entityId);
861 860 clearFollow(this.ecs, entityId);
862 861 cancelGather(this.ecs, handle);
@@ -880,6 +879,16 @@ export class WorkerWorld
880 879 this.pathfindOptions({ preferVertical: true, preferPaths: true })
881 880 );
882 881 movement.walkCarry = 0;
882 const events = [];
883 /** Open immediately when the next step is a door (player already adjacent). */
884 const first = path.tiles[0];
885 if (first)
886 {
887 const doorDelta = maybeOpenDoorOnApproach(this, entityId, first.x, first.y);
888 if (doorDelta)
889 { events.push(doorDelta); }
890 }
891 return { events };
883 892 }
884 893
885 894 #attack (sessionId, characterId, targetEntityId, now)
@@ -479,8 +479,7 @@ export class WorkerWorld
479 switch (command.type)
479 switch (command.type)
480 {
480 {
481 case "move-to":
481 case "move-to":
482 this.#moveTo(sessionId, command.characterId, command.tileX, command.tileY);
482 return this.#moveTo(sessionId, command.characterId, command.tileX, command.tileY);
483 return { events: [] };
484 case "set-gait":
483 case "set-gait":
485 return this.#setGait(sessionId, command.characterId, command.gait);
484 return this.#setGait(sessionId, command.characterId, command.gait);
486 case "attack":
485 case "attack":
@@ -856,7 +855,7 @@ export class WorkerWorld
856 {
855 {
857 const { handle, entityId } = this.#requireOwnedEntity(sessionId, characterId);
856 const { handle, entityId } = this.#requireOwnedEntity(sessionId, characterId);
858 if (this.frozen.has(entityId))
857 if (this.frozen.has(entityId))
859 { return; }
858 { return { events: [] }; }
860 clearEngage(this.ecs, entityId);
859 clearEngage(this.ecs, entityId);
861 clearFollow(this.ecs, entityId);
860 clearFollow(this.ecs, entityId);
862 cancelGather(this.ecs, handle);
861 cancelGather(this.ecs, handle);
@@ -880,6 +879,16 @@ export class WorkerWorld
880 this.pathfindOptions({ preferVertical: true, preferPaths: true })
879 this.pathfindOptions({ preferVertical: true, preferPaths: true })
881 );
880 );
882 movement.walkCarry = 0;
881 movement.walkCarry = 0;
882 const events = [];
883 /** Open immediately when the next step is a door (player already adjacent). */
884 const first = path.tiles[0];
885 if (first)
886 {
887 const doorDelta = maybeOpenDoorOnApproach(this, entityId, first.x, first.y);
888 if (doorDelta)
889 { events.push(doorDelta); }
890 }
891 return { events };
883 }
892 }
884
893
885 #attack (sessionId, characterId, targetEntityId, now)
894 #attack (sessionId, characterId, targetEntityId, now)
server/src/world/chunkData.js +1 −4
@@ -72,7 +72,6 @@ export function decodeChunkBlob (blob, groundTypeId = DEFAULT_WORLD_SETTINGS.def
72 72 const grounds = Array.isArray(parsed.grounds) ? parsed.grounds.slice(0, tileCount) : fallback.grounds;
73 73 const blocks = Array.isArray(parsed.blocks) ? parsed.blocks.slice(0, tileCount) : fallback.blocks.slice();
74 74 const light = Array.isArray(parsed.light) ? parsed.light.slice(0, tileCount) : fallback.light;
75 const occlusionRaw = Array.isArray(parsed.occlusion) ? parsed.occlusion.slice(0, tileCount) : null;
76 75
77 76 while (grounds.length < tileCount)
78 77 { grounds.push(normalizeGround(groundTypeId, groundTypeId)); }
@@ -106,9 +105,7 @@ export function decodeChunkBlob (blob, groundTypeId = DEFAULT_WORLD_SETTINGS.def
106 105 light,
107 106 spawners
108 107 };
109 decoded.occlusion = occlusionRaw?.length === tileCount
110 ? occlusionRaw.map((value) => value | 0)
111 : bakeChunkOcclusion(decoded);
108 decoded.occlusion = bakeChunkOcclusion(decoded);
112 109 return decoded;
113 110 }
114 111
@@ -72,7 +72,6 @@ export function decodeChunkBlob (blob, groundTypeId = DEFAULT_WORLD_SETTINGS.def
72 const grounds = Array.isArray(parsed.grounds) ? parsed.grounds.slice(0, tileCount) : fallback.grounds;
72 const grounds = Array.isArray(parsed.grounds) ? parsed.grounds.slice(0, tileCount) : fallback.grounds;
73 const blocks = Array.isArray(parsed.blocks) ? parsed.blocks.slice(0, tileCount) : fallback.blocks.slice();
73 const blocks = Array.isArray(parsed.blocks) ? parsed.blocks.slice(0, tileCount) : fallback.blocks.slice();
74 const light = Array.isArray(parsed.light) ? parsed.light.slice(0, tileCount) : fallback.light;
74 const light = Array.isArray(parsed.light) ? parsed.light.slice(0, tileCount) : fallback.light;
75 const occlusionRaw = Array.isArray(parsed.occlusion) ? parsed.occlusion.slice(0, tileCount) : null;
76
75
77 while (grounds.length < tileCount)
76 while (grounds.length < tileCount)
78 { grounds.push(normalizeGround(groundTypeId, groundTypeId)); }
77 { grounds.push(normalizeGround(groundTypeId, groundTypeId)); }
@@ -106,9 +105,7 @@ export function decodeChunkBlob (blob, groundTypeId = DEFAULT_WORLD_SETTINGS.def
106 light,
105 light,
107 spawners
106 spawners
108 };
107 };
109 decoded.occlusion = occlusionRaw?.length === tileCount
108 decoded.occlusion = bakeChunkOcclusion(decoded);
110 ? occlusionRaw.map((value) => value | 0)
111 : bakeChunkOcclusion(decoded);
112 return decoded;
109 return decoded;
113}
110}
114
111
server/tests/doors.test.js +9 −1
@@ -2,7 +2,7 @@ import test from "node:test";
2 2 import assert from "node:assert/strict";
3 3 import { fileURLToPath } from "node:url";
4 4 import { join } from "node:path";
5 import { BlockType, isBlockPassable, isChunkAtlasBakedBlock } from "../../shared/definitions/tiles.js";
5 import { BlockType, isBlockPassable, isChunkAtlasBakedBlock, blockLightOcclusionForBlock, blockBlocksRangedAttacks, LightOcclusion } from "../../shared/definitions/tiles.js";
6 6 import { WOOD_TIER_ORDER } from "../../shared/definitions/materialTiers.js";
7 7 import { MobId } from "../../shared/definitions/mobs.js";
8 8 import {
@@ -72,6 +72,14 @@ test("closed doors block passability unless opener; open doors do not", () =>
72 72 assert.equal(isDoorTraversable({ state: "pine-s-open" }, { canOpenDoors: false }), true);
73 73 });
74 74
75 test("closed doors block light and ranged LoS; open doors do not", () =>
76 {
77 assert.equal(blockLightOcclusionForBlock({ typeId: BlockType.door, state: "pine-s-closed" }), LightOcclusion.solid);
78 assert.equal(blockLightOcclusionForBlock({ typeId: BlockType.door, state: "pine-s-open" }), LightOcclusion.clear);
79 assert.equal(blockBlocksRangedAttacks(BlockType.door, "pine-s-closed"), true);
80 assert.equal(blockBlocksRangedAttacks(BlockType.door, "pine-s-open"), false);
81 });
82
75 83 test("door sort sub-order puts N-closed behind and S-closed in front", () =>
76 84 {
77 85 assert.equal(doorSortSubOrder("pine-n-closed", 3), 1);
@@ -2,7 +2,7 @@ import test from "node:test";
2import assert from "node:assert/strict";
2import assert from "node:assert/strict";
3import { fileURLToPath } from "node:url";
3import { fileURLToPath } from "node:url";
4import { join } from "node:path";
4import { join } from "node:path";
5import { BlockType, isBlockPassable, isChunkAtlasBakedBlock } from "../../shared/definitions/tiles.js";
5import { BlockType, isBlockPassable, isChunkAtlasBakedBlock, blockLightOcclusionForBlock, blockBlocksRangedAttacks, LightOcclusion } from "../../shared/definitions/tiles.js";
6import { WOOD_TIER_ORDER } from "../../shared/definitions/materialTiers.js";
6import { WOOD_TIER_ORDER } from "../../shared/definitions/materialTiers.js";
7import { MobId } from "../../shared/definitions/mobs.js";
7import { MobId } from "../../shared/definitions/mobs.js";
8import {
8import {
@@ -72,6 +72,14 @@ test("closed doors block passability unless opener; open doors do not", () =>
72 assert.equal(isDoorTraversable({ state: "pine-s-open" }, { canOpenDoors: false }), true);
72 assert.equal(isDoorTraversable({ state: "pine-s-open" }, { canOpenDoors: false }), true);
73});
73});
74
74
75test("closed doors block light and ranged LoS; open doors do not", () =>
76{
77 assert.equal(blockLightOcclusionForBlock({ typeId: BlockType.door, state: "pine-s-closed" }), LightOcclusion.solid);
78 assert.equal(blockLightOcclusionForBlock({ typeId: BlockType.door, state: "pine-s-open" }), LightOcclusion.clear);
79 assert.equal(blockBlocksRangedAttacks(BlockType.door, "pine-s-closed"), true);
80 assert.equal(blockBlocksRangedAttacks(BlockType.door, "pine-s-open"), false);
81});
82
75test("door sort sub-order puts N-closed behind and S-closed in front", () =>
83test("door sort sub-order puts N-closed behind and S-closed in front", () =>
76{
84{
77 assert.equal(doorSortSubOrder("pine-n-closed", 3), 1);
85 assert.equal(doorSortSubOrder("pine-n-closed", 3), 1);
shared/definitions/tiles.js +11 −1
@@ -736,7 +736,11 @@ export const BLOCK_DEFINITIONS = Object.freeze({
736 736 displayName: "Door",
737 737 /** Closed by default; open state is passable (see isBlockPassable). */
738 738 passable: false,
739 blocksLight: false,
739 /**
740 * Light/LoS follow open vs closed via {@link blockLightOcclusionForBlock} /
741 * {@link blockBlocksRangedAttacks} — not this static flag.
742 */
743 blocksLight: true,
740 744 lightRangeTiles: 0,
741 745 frames: 1,
742 746 framesPerRow: 1,
@@ -745,6 +749,7 @@ export const BLOCK_DEFINITIONS = Object.freeze({
745 749 /** Wooden door — not a dimension portal (`doorway`). */
746 750 door: true,
747 751 tintFromTier: true,
752 /** Tall tinted sprite; state flips at runtime — never chunk-atlas baked. */
748 753 perTileBlock: true,
749 754 defaultState: "pine-s-closed"
750 755 }),
@@ -877,6 +882,8 @@ export function isChunkAtlasBakedBlock (block)
877 882 { return false; }
878 883 if (def.perTileBlock)
879 884 { return false; }
885 if (def.door)
886 { return false; }
880 887 /** Cliff tops need a dedicated per-tile ground-sample shader, not the row atlas. */
881 888 if (def.cliffGroundTop)
882 889 { return false; }
@@ -1112,6 +1119,9 @@ export function blockLightOcclusionForBlock (block)
1112 1119 { return LightOcclusion.clear; }
1113 1120 if (isSeasonalStumpState(block.state))
1114 1121 { return LightOcclusion.clear; }
1122 const def = blockDefinition(block.typeId ?? null);
1123 if (def?.door)
1124 { return isDoorOpenState(block.state) ? LightOcclusion.clear : LightOcclusion.solid; }
1115 1125 return blockLightOcclusion(block.typeId ?? null);
1116 1126 }
1117 1127
@@ -736,7 +736,11 @@ export const BLOCK_DEFINITIONS = Object.freeze({
736 displayName: "Door",
736 displayName: "Door",
737 /** Closed by default; open state is passable (see isBlockPassable). */
737 /** Closed by default; open state is passable (see isBlockPassable). */
738 passable: false,
738 passable: false,
739 blocksLight: false,
739 /**
740 * Light/LoS follow open vs closed via {@link blockLightOcclusionForBlock} /
741 * {@link blockBlocksRangedAttacks} — not this static flag.
742 */
743 blocksLight: true,
740 lightRangeTiles: 0,
744 lightRangeTiles: 0,
741 frames: 1,
745 frames: 1,
742 framesPerRow: 1,
746 framesPerRow: 1,
@@ -745,6 +749,7 @@ export const BLOCK_DEFINITIONS = Object.freeze({
745 /** Wooden door — not a dimension portal (`doorway`). */
749 /** Wooden door — not a dimension portal (`doorway`). */
746 door: true,
750 door: true,
747 tintFromTier: true,
751 tintFromTier: true,
752 /** Tall tinted sprite; state flips at runtime — never chunk-atlas baked. */
748 perTileBlock: true,
753 perTileBlock: true,
749 defaultState: "pine-s-closed"
754 defaultState: "pine-s-closed"
750 }),
755 }),
@@ -877,6 +882,8 @@ export function isChunkAtlasBakedBlock (block)
877 { return false; }
882 { return false; }
878 if (def.perTileBlock)
883 if (def.perTileBlock)
879 { return false; }
884 { return false; }
885 if (def.door)
886 { return false; }
880 /** Cliff tops need a dedicated per-tile ground-sample shader, not the row atlas. */
887 /** Cliff tops need a dedicated per-tile ground-sample shader, not the row atlas. */
881 if (def.cliffGroundTop)
888 if (def.cliffGroundTop)
882 { return false; }
889 { return false; }
@@ -1112,6 +1119,9 @@ export function blockLightOcclusionForBlock (block)
1112 { return LightOcclusion.clear; }
1119 { return LightOcclusion.clear; }
1113 if (isSeasonalStumpState(block.state))
1120 if (isSeasonalStumpState(block.state))
1114 { return LightOcclusion.clear; }
1121 { return LightOcclusion.clear; }
1122 const def = blockDefinition(block.typeId ?? null);
1123 if (def?.door)
1124 { return isDoorOpenState(block.state) ? LightOcclusion.clear : LightOcclusion.solid; }
1115 return blockLightOcclusion(block.typeId ?? null);
1125 return blockLightOcclusion(block.typeId ?? null);
1116}
1126}
1117
1127
shared/lighting/tilePassable.js +2 −3
@@ -9,7 +9,8 @@ import {
9 9 /**
10 10 * Light occlusion lookup from a chunk snapshot map keyed by "chunkX,chunkY".
11 11 * Returns {@link LightOcclusion} levels (not movement passability).
12 * Uses pre-baked {@link snapshot.occlusion} when present (see editor save / decodeChunkBlob).
12 * Prefers live block/ground state so runtime door flips are not stuck on a
13 * stale baked occlusion row.
13 14 */
14 15 export function makeSnapshotLightOcclusion (chunks)
15 16 {
@@ -25,8 +26,6 @@ export function makeSnapshotLightOcclusion (chunks)
25 26 if (localX < 0 || localY < 0 || localX >= CHUNK_SIZE || localY >= CHUNK_SIZE)
26 27 { return LightOcclusion.clear; }
27 28 const index = localY * CHUNK_SIZE + localX;
28 if (Array.isArray(snapshot.occlusion) && snapshot.occlusion.length > index)
29 { return snapshot.occlusion[index] | 0; }
30 29 const ground = normalizeGround(snapshot.grounds?.[index]);
31 30 if (!isGroundPassable(ground.typeId))
32 31 { return LightOcclusion.solid; }
@@ -9,7 +9,8 @@ import {
9/**
9/**
10 * Light occlusion lookup from a chunk snapshot map keyed by "chunkX,chunkY".
10 * Light occlusion lookup from a chunk snapshot map keyed by "chunkX,chunkY".
11 * Returns {@link LightOcclusion} levels (not movement passability).
11 * Returns {@link LightOcclusion} levels (not movement passability).
12 * Uses pre-baked {@link snapshot.occlusion} when present (see editor save / decodeChunkBlob).
12 * Prefers live block/ground state so runtime door flips are not stuck on a
13 * stale baked occlusion row.
13 */
14 */
14export function makeSnapshotLightOcclusion (chunks)
15export function makeSnapshotLightOcclusion (chunks)
15{
16{
@@ -25,8 +26,6 @@ export function makeSnapshotLightOcclusion (chunks)
25 if (localX < 0 || localY < 0 || localX >= CHUNK_SIZE || localY >= CHUNK_SIZE)
26 if (localX < 0 || localY < 0 || localX >= CHUNK_SIZE || localY >= CHUNK_SIZE)
26 { return LightOcclusion.clear; }
27 { return LightOcclusion.clear; }
27 const index = localY * CHUNK_SIZE + localX;
28 const index = localY * CHUNK_SIZE + localX;
28 if (Array.isArray(snapshot.occlusion) && snapshot.occlusion.length > index)
29 { return snapshot.occlusion[index] | 0; }
30 const ground = normalizeGround(snapshot.grounds?.[index]);
29 const ground = normalizeGround(snapshot.grounds?.[index]);
31 if (!isGroundPassable(ground.typeId))
30 if (!isGroundPassable(ground.typeId))
32 { return LightOcclusion.solid; }
31 { return LightOcclusion.solid; }