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.
@@ -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 @@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";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
import { dynamicLightAtTile, dynamicDarknessAtTile, lightIntensity } from "/shared/lighting/raycast.js";2
import { dynamicLightAtTile, dynamicDarknessAtTile, lightIntensity } from "/shared/lighting/raycast.js";3
import { makeSnapshotLightOcclusion } from "/shared/lighting/tilePassable.js";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
import { smoothLitCorner } from "/shared/lighting/lightCorners.js";5
import { smoothLitCorner } from "/shared/lighting/lightCorners.js";6
import { bloomCompanionName, spriteImageName } from "/shared/definitions/tileSprites.js";6
import { bloomCompanionName, spriteImageName } from "/shared/definitions/tileSprites.js";7
import { EQUIPMENT_SLOT, itemEquipSprite, itemSpriteName, itemSpriteNameForStack, itemDefinition } from "/shared/definitions/items.js";7
import { EQUIPMENT_SLOT, itemEquipSprite, itemSpriteName, itemSpriteNameForStack, itemDefinition } from "/shared/definitions/items.js";@@ -15,7 +15,7 @@ import15
} from "/shared/render/tint.js";15
} from "/shared/render/tint.js";16
import { layersFromSpawnerConfig } from "/shared/appearance/layers.js";16
import { layersFromSpawnerConfig } from "/shared/appearance/layers.js";17
import { chargeSpriteFrameIndex, itemMaxCharges } from "/shared/items/charges.js";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
import { doorSortSubOrder } from "/shared/world/doors.js";19
import { doorSortSubOrder } from "/shared/world/doors.js";20
import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer, flightSortLayer } from "/shared/render/pivot.js";20
import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer, flightSortLayer } from "/shared/render/pivot.js";21
import { bakeChunkAtlases, tileBlockSpriteEntry } from "./chunkBake.js";21
import { bakeChunkAtlases, tileBlockSpriteEntry } from "./chunkBake.js";@@ -633,10 +633,7 @@ export class WorldView633
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 WorldView1842
{ 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
else1847
{ 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 WorldView4119
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)@@ -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 {9
import { tileToChunk, tileToLocal, tileKey, parseTileKey } from "../world/coordinates.js";9
import { tileToChunk, tileToLocal, tileKey, parseTileKey } from "../world/coordinates.js";10
import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";10
import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";11
import { OVERWORLD_ID } from "../../../shared/world/dimensions.js";11
import { OVERWORLD_ID } from "../../../shared/world/dimensions.js";12
import { tileLightOcclusionAt } from "../../../shared/lighting/chunkOcclusion.js";12
13
13
export function isDoorTypeId (typeId)14
export function isDoorTypeId (typeId)14
{15
{@@ -74,6 +75,8 @@ function writeDoorState (world, tileX, tileY, state, config, dimensionId = OVERW74
config: config ?? prev.config ?? null75
config: config ?? prev.config ?? null75
};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,@@ -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 WorkerWorld479
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 WorkerWorld856
{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 WorkerWorld880
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)@@ -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.def72
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.def106
light,105
light,107
spawners106
spawners108
};107
};109
decoded.occlusion = occlusionRaw?.length === tileCount108
decoded.occlusion = bakeChunkOcclusion(decoded);110
? occlusionRaw.map((value) => value | 0)111
: bakeChunkOcclusion(decoded);112
return decoded;109
return decoded;113
}110
}114
111
@@ -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";2
import assert from "node:assert/strict";2
import assert from "node:assert/strict";3
import { fileURLToPath } from "node:url";3
import { fileURLToPath } from "node:url";4
import { join } from "node:path";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
import { WOOD_TIER_ORDER } from "../../shared/definitions/materialTiers.js";6
import { WOOD_TIER_ORDER } from "../../shared/definitions/materialTiers.js";7
import { MobId } from "../../shared/definitions/mobs.js";7
import { MobId } from "../../shared/definitions/mobs.js";8
import {8
import {@@ -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
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
test("door sort sub-order puts N-closed behind and S-closed in front", () =>83
test("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);