BlueGit

timfa questward

Play: draw world-border red only on walkable edge tiles.

Editor keeps full chunk bars. In play, each closed-neighbor edge is
segmented per tile and shown only where the open-side tile is walkable.

timfa Tim Falken · pushed by timfa

Authored 2026-09-13 · 2 months ago

Hash
98ea78ec45d60914690f316c84ffc71b2854b4a9
Parent
3799e533
2 files changed +131 −15
client/src/play/main.js +1 −0
@@ -1789,6 +1789,7 @@ function startPlay (payload)
1789 1789 if (!view)
1790 1790 {
1791 1791 view = new WorldView(game, scene, catalog);
1792 view.worldBorderWalkableOnly = true;
1792 1793 graphicsSettingsUi?.apply();
1793 1794 const ticker = new GameObject(0, 0, null, 10);
1794 1795 ticker.update = (dt) =>
@@ -1789,6 +1789,7 @@ function startPlay (payload)
1789 if (!view)
1789 if (!view)
1790 {
1790 {
1791 view = new WorldView(game, scene, catalog);
1791 view = new WorldView(game, scene, catalog);
1792 view.worldBorderWalkableOnly = true;
1792 graphicsSettingsUi?.apply();
1793 graphicsSettingsUi?.apply();
1793 const ticker = new GameObject(0, 0, null, 10);
1794 const ticker = new GameObject(0, 0, null, 10);
1794 ticker.update = (dt) =>
1795 ticker.update = (dt) =>
client/src/render/worldView.js +130 −15
@@ -19,8 +19,8 @@ import
19 19 import { layersFromSpawnerConfig } from "/shared/appearance/layers.js";
20 20 import { normalizeSpawnerConfig } from "/shared/definitions/mobs.js";
21 21 import { chargeSpriteFrameIndex, itemMaxCharges } from "/shared/items/charges.js";
22 import { normalizeGround, normalizeBlock, isWadeGroundInSeason, isWaterGround, isLavaGround, isLiquidWaterGround, isGroundPassable, groundLightOcclusion, LightOcclusion, blockDefinition, blockLightOcclusionForBlock, GroundType, GROUND_DEFINITIONS, fluidCoastContinues } from "/shared/definitions/tiles.js";
23 import { doorSortSubOrder, doorRestingState } from "/shared/world/doors.js";
22 import { normalizeGround, normalizeBlock, isWadeGroundInSeason, isWaterGround, isLavaGround, isLiquidWaterGround, isGroundPassable, isBlockPassable, groundLightOcclusion, LightOcclusion, blockDefinition, blockLightOcclusionForBlock, GroundType, GROUND_DEFINITIONS, fluidCoastContinues } from "/shared/definitions/tiles.js";
23 import { doorSortSubOrder, doorRestingState, isDoorTraversable } from "/shared/world/doors.js";
24 24 import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer, flightSortLayer } from "/shared/render/pivot.js";
25 25 import { bakeChunkAtlases, tileBlockSpriteEntry } from "./chunkBake.js";
26 26 import { createChunkAtlasCache } from "./chunkAtlasCache.js";
@@ -1108,6 +1108,8 @@ export class WorldView
1108 1108 this.worldSeason = seasonIdAt();
1109 1109 this.nightPreview = null;
1110 1110 this.followPlayer = true;
1111 /** Play: only draw world-border segments on walkable tiles. Editor keeps full bars. */
1112 this.worldBorderWalkableOnly = false;
1111 1113 this.dynamicLights = [];
1112 1114 /** Persistent Light-spell tile lights (server-driven). */
1113 1115 this.spellLights = new Map();
@@ -2728,6 +2730,11 @@ export class WorldView
2728 2730 { snapshot.occlusion = bakeChunkOcclusion(snapshot); }
2729 2731 else
2730 2732 { snapshot.occlusion[index] = tileLightOcclusionAt(snapshot.grounds, snapshot.blocks, localX, localY); }
2733 if (
2734 this.worldBorderWalkableOnly
2735 && (localX === 0 || localY === 0 || localX === CHUNK_SIZE - 1 || localY === CHUNK_SIZE - 1)
2736 )
2737 { this.#scheduleEdgeRebuild(); }
2731 2738 }
2732 2739 const tileX = chunkX * CHUNK_SIZE + localX;
2733 2740 const tileY = chunkY * CHUNK_SIZE + localY;
@@ -5626,9 +5633,21 @@ export class WorldView
5626 5633 let bars = this.edges.get(key);
5627 5634 if (!bars)
5628 5635 {
5629 bars = {};
5636 bars = { north: [], south: [], west: [], east: [], full: {} };
5630 5637 this.edges.set(key, bars);
5631 5638 }
5639 if (!Array.isArray(bars.north))
5640 {
5641 // Migrate legacy single-bar shape from earlier sessions.
5642 for (const dir of ["north", "south", "west", "east"])
5643 {
5644 const legacy = bars[dir];
5645 if (legacy && !Array.isArray(legacy))
5646 { legacy.destroy?.(); }
5647 bars[dir] = [];
5648 }
5649 bars.full = bars.full ?? {};
5650 }
5632 5651
5633 5652 const size = this.tileSize();
5634 5653 const chunkPx = CHUNK_SIZE * size;
@@ -5638,15 +5657,103 @@ export class WorldView
5638 5657 const centerY = top + chunkPx / 2;
5639 5658 const thickness = Math.max(2, Math.round(2 * this.zoom));
5640 5659 const draw = snapshot.open === true;
5660 const walkableOnly = this.worldBorderWalkableOnly === true;
5661
5662 const northClosed = draw && this.#neighborClosed(snapshot, "north", 0, -1);
5663 const southClosed = draw && this.#neighborClosed(snapshot, "south", 0, 1);
5664 const westClosed = draw && this.#neighborClosed(snapshot, "west", -1, 0);
5665 const eastClosed = draw && this.#neighborClosed(snapshot, "east", 1, 0);
5666
5667 if (!walkableOnly)
5668 {
5669 this.#hideEdgeList(bars.north);
5670 this.#hideEdgeList(bars.south);
5671 this.#hideEdgeList(bars.west);
5672 this.#hideEdgeList(bars.east);
5673 bars.full.north = this.#edgeBar(bars.full.north, northClosed,
5674 centerX, top, chunkPx, thickness, true);
5675 bars.full.south = this.#edgeBar(bars.full.south, southClosed,
5676 centerX, top + chunkPx, chunkPx, thickness, true);
5677 bars.full.west = this.#edgeBar(bars.full.west, westClosed,
5678 left, centerY, chunkPx, thickness, false);
5679 bars.full.east = this.#edgeBar(bars.full.east, eastClosed,
5680 left + chunkPx, centerY, chunkPx, thickness, false);
5681 return;
5682 }
5683
5684 for (const dir of ["north", "south", "west", "east"])
5685 {
5686 if (bars.full?.[dir])
5687 {
5688 bars.full[dir].renderer.visible = false;
5689 }
5690 }
5691
5692 bars.north = this.#edgeTileBars(bars.north, northClosed, snapshot, "north", left, top, size, thickness);
5693 bars.south = this.#edgeTileBars(bars.south, southClosed, snapshot, "south", left, top, size, thickness);
5694 bars.west = this.#edgeTileBars(bars.west, westClosed, snapshot, "west", left, top, size, thickness);
5695 bars.east = this.#edgeTileBars(bars.east, eastClosed, snapshot, "east", left, top, size, thickness);
5696 }
5641 5697
5642 bars.north = this.#edgeBar(bars.north, draw && this.#neighborClosed(snapshot, "north", 0, -1),
5643 centerX, top, chunkPx, thickness, true);
5644 bars.south = this.#edgeBar(bars.south, draw && this.#neighborClosed(snapshot, "south", 0, 1),
5645 centerX, top + chunkPx, chunkPx, thickness, true);
5646 bars.west = this.#edgeBar(bars.west, draw && this.#neighborClosed(snapshot, "west", -1, 0),
5647 left, centerY, chunkPx, thickness, false);
5648 bars.east = this.#edgeBar(bars.east, draw && this.#neighborClosed(snapshot, "east", 1, 0),
5649 left + chunkPx, centerY, chunkPx, thickness, false);
5698 /** True when a player can walk the authored tile (doors closed = blocked). */
5699 #tileWalkableOnSnapshot (snapshot, localX, localY)
5700 {
5701 const index = localY * CHUNK_SIZE + localX;
5702 const ground = normalizeGround(snapshot.grounds?.[index]);
5703 if (!isGroundPassable(ground.typeId))
5704 { return false; }
5705 const block = snapshot.blocks?.[index];
5706 if (!block)
5707 { return true; }
5708 const def = blockDefinition(block.typeId);
5709 if (def?.door)
5710 { return isDoorTraversable(block, { canOpenDoors: false, requirementsAllow: true }); }
5711 return isBlockPassable(block.typeId, block.state);
5712 }
5713
5714 #edgeTileBars (list, active, snapshot, dir, left, top, size, thickness)
5715 {
5716 const out = Array.isArray(list) ? list : [];
5717 if (!active)
5718 {
5719 this.#hideEdgeList(out);
5720 return out;
5721 }
5722 let used = 0;
5723 for (let i = 0; i < CHUNK_SIZE; i++)
5724 {
5725 const localX = (dir === "north" || dir === "south") ? i : (dir === "west" ? 0 : CHUNK_SIZE - 1);
5726 const localY = (dir === "west" || dir === "east") ? i : (dir === "north" ? 0 : CHUNK_SIZE - 1);
5727 if (!this.#tileWalkableOnSnapshot(snapshot, localX, localY))
5728 { continue; }
5729 const horizontal = dir === "north" || dir === "south";
5730 const x = horizontal
5731 ? left + (localX + 0.5) * size
5732 : (dir === "west" ? left : left + CHUNK_SIZE * size);
5733 const y = horizontal
5734 ? (dir === "north" ? top : top + CHUNK_SIZE * size)
5735 : top + (localY + 0.5) * size;
5736 out[used] = this.#edgeBar(out[used], true, x, y, size, thickness, horizontal);
5737 used += 1;
5738 }
5739 for (let i = used; i < out.length; i++)
5740 {
5741 if (out[i])
5742 { out[i].renderer.visible = false; }
5743 }
5744 out.length = Math.max(used, out.length);
5745 return out;
5746 }
5747
5748 #hideEdgeList (list)
5749 {
5750 if (!Array.isArray(list))
5751 { return; }
5752 for (const bar of list)
5753 {
5754 if (bar)
5755 { bar.renderer.visible = false; }
5756 }
5650 5757 }
5651 5758
5652 5759 #edgeBar (existing, visible, x, y, length, thickness, horizontal)
@@ -5675,10 +5782,18 @@ export class WorldView
5675 5782 const bars = this.edges.get(key);
5676 5783 if (!bars)
5677 5784 { return; }
5678 bars.north?.destroy();
5679 bars.east?.destroy();
5680 bars.south?.destroy();
5681 bars.west?.destroy();
5785 for (const dir of ["north", "south", "west", "east"])
5786 {
5787 const entry = bars[dir];
5788 if (Array.isArray(entry))
5789 {
5790 for (const bar of entry)
5791 { bar?.destroy?.(); }
5792 }
5793 else
5794 { entry?.destroy?.(); }
5795 bars.full?.[dir]?.destroy?.();
5796 }
5682 5797 this.edges.delete(key);
5683 5798 }
5684 5799
@@ -19,8 +19,8 @@ import
19import { layersFromSpawnerConfig } from "/shared/appearance/layers.js";
19import { layersFromSpawnerConfig } from "/shared/appearance/layers.js";
20import { normalizeSpawnerConfig } from "/shared/definitions/mobs.js";
20import { normalizeSpawnerConfig } from "/shared/definitions/mobs.js";
21import { chargeSpriteFrameIndex, itemMaxCharges } from "/shared/items/charges.js";
21import { chargeSpriteFrameIndex, itemMaxCharges } from "/shared/items/charges.js";
22import { normalizeGround, normalizeBlock, isWadeGroundInSeason, isWaterGround, isLavaGround, isLiquidWaterGround, isGroundPassable, groundLightOcclusion, LightOcclusion, blockDefinition, blockLightOcclusionForBlock, GroundType, GROUND_DEFINITIONS, fluidCoastContinues } from "/shared/definitions/tiles.js";
22import { normalizeGround, normalizeBlock, isWadeGroundInSeason, isWaterGround, isLavaGround, isLiquidWaterGround, isGroundPassable, isBlockPassable, groundLightOcclusion, LightOcclusion, blockDefinition, blockLightOcclusionForBlock, GroundType, GROUND_DEFINITIONS, fluidCoastContinues } from "/shared/definitions/tiles.js";
23import { doorSortSubOrder, doorRestingState } from "/shared/world/doors.js";
23import { doorSortSubOrder, doorRestingState, isDoorTraversable } from "/shared/world/doors.js";
24import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer, flightSortLayer } from "/shared/render/pivot.js";
24import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer, flightSortLayer } from "/shared/render/pivot.js";
25import { bakeChunkAtlases, tileBlockSpriteEntry } from "./chunkBake.js";
25import { bakeChunkAtlases, tileBlockSpriteEntry } from "./chunkBake.js";
26import { createChunkAtlasCache } from "./chunkAtlasCache.js";
26import { createChunkAtlasCache } from "./chunkAtlasCache.js";
@@ -1108,6 +1108,8 @@ export class WorldView
1108 this.worldSeason = seasonIdAt();
1108 this.worldSeason = seasonIdAt();
1109 this.nightPreview = null;
1109 this.nightPreview = null;
1110 this.followPlayer = true;
1110 this.followPlayer = true;
1111 /** Play: only draw world-border segments on walkable tiles. Editor keeps full bars. */
1112 this.worldBorderWalkableOnly = false;
1111 this.dynamicLights = [];
1113 this.dynamicLights = [];
1112 /** Persistent Light-spell tile lights (server-driven). */
1114 /** Persistent Light-spell tile lights (server-driven). */
1113 this.spellLights = new Map();
1115 this.spellLights = new Map();
@@ -2728,6 +2730,11 @@ export class WorldView
2728 { snapshot.occlusion = bakeChunkOcclusion(snapshot); }
2730 { snapshot.occlusion = bakeChunkOcclusion(snapshot); }
2729 else
2731 else
2730 { snapshot.occlusion[index] = tileLightOcclusionAt(snapshot.grounds, snapshot.blocks, localX, localY); }
2732 { snapshot.occlusion[index] = tileLightOcclusionAt(snapshot.grounds, snapshot.blocks, localX, localY); }
2733 if (
2734 this.worldBorderWalkableOnly
2735 && (localX === 0 || localY === 0 || localX === CHUNK_SIZE - 1 || localY === CHUNK_SIZE - 1)
2736 )
2737 { this.#scheduleEdgeRebuild(); }
2731 }
2738 }
2732 const tileX = chunkX * CHUNK_SIZE + localX;
2739 const tileX = chunkX * CHUNK_SIZE + localX;
2733 const tileY = chunkY * CHUNK_SIZE + localY;
2740 const tileY = chunkY * CHUNK_SIZE + localY;
@@ -5626,9 +5633,21 @@ export class WorldView
5626 let bars = this.edges.get(key);
5633 let bars = this.edges.get(key);
5627 if (!bars)
5634 if (!bars)
5628 {
5635 {
5629 bars = {};
5636 bars = { north: [], south: [], west: [], east: [], full: {} };
5630 this.edges.set(key, bars);
5637 this.edges.set(key, bars);
5631 }
5638 }
5639 if (!Array.isArray(bars.north))
5640 {
5641 // Migrate legacy single-bar shape from earlier sessions.
5642 for (const dir of ["north", "south", "west", "east"])
5643 {
5644 const legacy = bars[dir];
5645 if (legacy && !Array.isArray(legacy))
5646 { legacy.destroy?.(); }
5647 bars[dir] = [];
5648 }
5649 bars.full = bars.full ?? {};
5650 }
5632
5651
5633 const size = this.tileSize();
5652 const size = this.tileSize();
5634 const chunkPx = CHUNK_SIZE * size;
5653 const chunkPx = CHUNK_SIZE * size;
@@ -5638,15 +5657,103 @@ export class WorldView
5638 const centerY = top + chunkPx / 2;
5657 const centerY = top + chunkPx / 2;
5639 const thickness = Math.max(2, Math.round(2 * this.zoom));
5658 const thickness = Math.max(2, Math.round(2 * this.zoom));
5640 const draw = snapshot.open === true;
5659 const draw = snapshot.open === true;
5660 const walkableOnly = this.worldBorderWalkableOnly === true;
5661
5662 const northClosed = draw && this.#neighborClosed(snapshot, "north", 0, -1);
5663 const southClosed = draw && this.#neighborClosed(snapshot, "south", 0, 1);
5664 const westClosed = draw && this.#neighborClosed(snapshot, "west", -1, 0);
5665 const eastClosed = draw && this.#neighborClosed(snapshot, "east", 1, 0);
5666
5667 if (!walkableOnly)
5668 {
5669 this.#hideEdgeList(bars.north);
5670 this.#hideEdgeList(bars.south);
5671 this.#hideEdgeList(bars.west);
5672 this.#hideEdgeList(bars.east);
5673 bars.full.north = this.#edgeBar(bars.full.north, northClosed,
5674 centerX, top, chunkPx, thickness, true);
5675 bars.full.south = this.#edgeBar(bars.full.south, southClosed,
5676 centerX, top + chunkPx, chunkPx, thickness, true);
5677 bars.full.west = this.#edgeBar(bars.full.west, westClosed,
5678 left, centerY, chunkPx, thickness, false);
5679 bars.full.east = this.#edgeBar(bars.full.east, eastClosed,
5680 left + chunkPx, centerY, chunkPx, thickness, false);
5681 return;
5682 }
5683
5684 for (const dir of ["north", "south", "west", "east"])
5685 {
5686 if (bars.full?.[dir])
5687 {
5688 bars.full[dir].renderer.visible = false;
5689 }
5690 }
5691
5692 bars.north = this.#edgeTileBars(bars.north, northClosed, snapshot, "north", left, top, size, thickness);
5693 bars.south = this.#edgeTileBars(bars.south, southClosed, snapshot, "south", left, top, size, thickness);
5694 bars.west = this.#edgeTileBars(bars.west, westClosed, snapshot, "west", left, top, size, thickness);
5695 bars.east = this.#edgeTileBars(bars.east, eastClosed, snapshot, "east", left, top, size, thickness);
5696 }
5641
5697
5642 bars.north = this.#edgeBar(bars.north, draw && this.#neighborClosed(snapshot, "north", 0, -1),
5698 /** True when a player can walk the authored tile (doors closed = blocked). */
5643 centerX, top, chunkPx, thickness, true);
5699 #tileWalkableOnSnapshot (snapshot, localX, localY)
5644 bars.south = this.#edgeBar(bars.south, draw && this.#neighborClosed(snapshot, "south", 0, 1),
5700 {
5645 centerX, top + chunkPx, chunkPx, thickness, true);
5701 const index = localY * CHUNK_SIZE + localX;
5646 bars.west = this.#edgeBar(bars.west, draw && this.#neighborClosed(snapshot, "west", -1, 0),
5702 const ground = normalizeGround(snapshot.grounds?.[index]);
5647 left, centerY, chunkPx, thickness, false);
5703 if (!isGroundPassable(ground.typeId))
5648 bars.east = this.#edgeBar(bars.east, draw && this.#neighborClosed(snapshot, "east", 1, 0),
5704 { return false; }
5649 left + chunkPx, centerY, chunkPx, thickness, false);
5705 const block = snapshot.blocks?.[index];
5706 if (!block)
5707 { return true; }
5708 const def = blockDefinition(block.typeId);
5709 if (def?.door)
5710 { return isDoorTraversable(block, { canOpenDoors: false, requirementsAllow: true }); }
5711 return isBlockPassable(block.typeId, block.state);
5712 }
5713
5714 #edgeTileBars (list, active, snapshot, dir, left, top, size, thickness)
5715 {
5716 const out = Array.isArray(list) ? list : [];
5717 if (!active)
5718 {
5719 this.#hideEdgeList(out);
5720 return out;
5721 }
5722 let used = 0;
5723 for (let i = 0; i < CHUNK_SIZE; i++)
5724 {
5725 const localX = (dir === "north" || dir === "south") ? i : (dir === "west" ? 0 : CHUNK_SIZE - 1);
5726 const localY = (dir === "west" || dir === "east") ? i : (dir === "north" ? 0 : CHUNK_SIZE - 1);
5727 if (!this.#tileWalkableOnSnapshot(snapshot, localX, localY))
5728 { continue; }
5729 const horizontal = dir === "north" || dir === "south";
5730 const x = horizontal
5731 ? left + (localX + 0.5) * size
5732 : (dir === "west" ? left : left + CHUNK_SIZE * size);
5733 const y = horizontal
5734 ? (dir === "north" ? top : top + CHUNK_SIZE * size)
5735 : top + (localY + 0.5) * size;
5736 out[used] = this.#edgeBar(out[used], true, x, y, size, thickness, horizontal);
5737 used += 1;
5738 }
5739 for (let i = used; i < out.length; i++)
5740 {
5741 if (out[i])
5742 { out[i].renderer.visible = false; }
5743 }
5744 out.length = Math.max(used, out.length);
5745 return out;
5746 }
5747
5748 #hideEdgeList (list)
5749 {
5750 if (!Array.isArray(list))
5751 { return; }
5752 for (const bar of list)
5753 {
5754 if (bar)
5755 { bar.renderer.visible = false; }
5756 }
5650 }
5757 }
5651
5758
5652 #edgeBar (existing, visible, x, y, length, thickness, horizontal)
5759 #edgeBar (existing, visible, x, y, length, thickness, horizontal)
@@ -5675,10 +5782,18 @@ export class WorldView
5675 const bars = this.edges.get(key);
5782 const bars = this.edges.get(key);
5676 if (!bars)
5783 if (!bars)
5677 { return; }
5784 { return; }
5678 bars.north?.destroy();
5785 for (const dir of ["north", "south", "west", "east"])
5679 bars.east?.destroy();
5786 {
5680 bars.south?.destroy();
5787 const entry = bars[dir];
5681 bars.west?.destroy();
5788 if (Array.isArray(entry))
5789 {
5790 for (const bar of entry)
5791 { bar?.destroy?.(); }
5792 }
5793 else
5794 { entry?.destroy?.(); }
5795 bars.full?.[dir]?.destroy?.();
5796 }
5682 this.edges.delete(key);
5797 this.edges.delete(key);
5683 }
5798 }
5684
5799