@wildshard/engine 0.1.19 → 0.1.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/lint/engine-sides.json +5 -0
  3. package/package.json +5 -2
  4. package/scripts/app-build/gen.ts +11 -0
  5. package/scripts/cell-mem-bench.mjs +2 -0
  6. package/scripts/chaos-proxy-core.mjs +14 -1
  7. package/scripts/chaos-proxy-proof.mjs +22 -0
  8. package/scripts/check-devserver.mjs +1 -1
  9. package/scripts/failmode-cases.d.mts +8 -0
  10. package/scripts/failmode-cases.mjs +97 -0
  11. package/scripts/failmode-proof.mjs +532 -0
  12. package/scripts/grid-crossing-nightly.mjs +5 -4
  13. package/scripts/grid-crossing-report.mjs +5 -2
  14. package/scripts/grid-crossing-tour.mjs +36 -12
  15. package/scripts/grid-crossing-walk-proof.mjs +4 -2
  16. package/scripts/hover-speed-probe.mjs +136 -0
  17. package/scripts/land.mjs +2 -1
  18. package/scripts/loading-flow/benchmax.mjs +34 -11
  19. package/scripts/loading-flow/deskbench.mjs +276 -0
  20. package/scripts/loading-flow/stalls.d.mts +17 -3
  21. package/scripts/loading-flow/stalls.mjs +82 -3
  22. package/scripts/net-lag-proof.mjs +3 -2
  23. package/scripts/nightly-model.ts +9 -6
  24. package/scripts/offline-proof.mjs +7 -1
  25. package/scripts/online-rig.mjs +9 -7
  26. package/scripts/parity/boot-smoke.mjs +13 -2
  27. package/scripts/pin-format.ts +5 -2
  28. package/scripts/pins-reuse.d.mts +1 -0
  29. package/scripts/pins-reuse.mjs +22 -0
  30. package/scripts/release-cook.mjs +109 -0
  31. package/scripts/scratch-dir.mjs +95 -0
  32. package/scripts/scratch-sweep.mjs +182 -0
  33. package/scripts/tsconfig.json +2 -12
  34. package/scripts/vps/harden-prometheus.sh +3 -0
  35. package/scripts/vps/rebuild.sh +35 -9
  36. package/scripts/vps/wildshard-apply.mjs +5 -1
  37. package/scripts/vps/wildshard-config +117 -1
  38. package/scripts/worktree-reap.mjs +54 -8
  39. package/scripts/worktree.mjs +19 -5
  40. package/src/client/engine/anim/rigParser.ts +2 -2
  41. package/src/client/engine/boot/contentRead.ts +54 -5
  42. package/src/client/engine/boot/gpuFiles.ts +3 -3
  43. package/src/client/engine/boot/leaveAfterPaint.ts +4 -1
  44. package/src/client/engine/core/Game.ts +63 -19
  45. package/src/client/engine/core/gpuOnly.ts +10 -0
  46. package/src/client/engine/core/renderBudget.ts +134 -0
  47. package/src/client/engine/core/shadowLayer.ts +18 -0
  48. package/src/client/engine/explore/pick.ts +13 -1
  49. package/src/client/engine/net/predictor.ts +12 -4
  50. package/src/client/engine/net/redial.ts +40 -5
  51. package/src/client/engine/player/TouchControls.ts +3 -2
  52. package/src/client/engine/render/dataLook.ts +70 -7
  53. package/src/client/engine/render/families/pbr.ts +2 -0
  54. package/src/client/engine/render/families/registry.ts +11 -2
  55. package/src/client/engine/render/families/sceneSurface.ts +118 -0
  56. package/src/client/engine/render/look.ts +7 -1
  57. package/src/client/engine/render/precompile.ts +4 -2
  58. package/src/client/engine/render/tiers.ts +4 -1
  59. package/src/client/engine/telemetry/browserErrors.ts +3 -1
  60. package/src/client/engine/ui/ErrorModal.ts +1 -1
  61. package/src/client/engine/ui/Loading.ts +14 -2
  62. package/src/client/engine/ui/errorScreen.ts +51 -9
  63. package/src/client/engine/ui/hoverBoost.ts +31 -4
  64. package/src/client/engine/ui/styles/touch.css +6 -0
  65. package/src/client/engine/world/declaredProps.ts +5 -1
  66. package/src/client/engine/world/skyRig.ts +4 -1
  67. package/src/client/engine/world/terrainTileView.ts +64 -23
  68. package/src/client/game/boot/spawnDownload.ts +44 -6
  69. package/src/client/game/devScene/hook.ts +149 -12
  70. package/src/client/game/devScene/liveLook.ts +21 -0
  71. package/src/client/game/grid/live.ts +47 -10
  72. package/src/client/game/grid/liveSession.ts +25 -6
  73. package/src/client/game/grid/pageEntry.ts +12 -1
  74. package/src/client/game/grid/productInputs.ts +22 -11
  75. package/src/client/game/grid/session.ts +15 -4
  76. package/src/client/game/grid/shardfileFar.ts +13 -2
  77. package/src/client/game/session/finish.ts +4 -1
  78. package/src/client/game/shardfile/client.ts +24 -7
  79. package/src/client/game/shardfile/clientPropMaterials.ts +4 -1
  80. package/src/client/game/shardfile/clientSource.ts +7 -3
  81. package/src/client/game/shardfile/clientViews.ts +36 -8
  82. package/src/client/game/shardfile/clientWorker.ts +4 -4
  83. package/src/client/game/shardfile/constructionCheckpoint.ts +2 -2
  84. package/src/client/game/shardfile/groundMerge.ts +59 -5
  85. package/src/client/game/shardfile/hybrid.ts +2 -0
  86. package/src/client/game/shardfile/look.ts +1 -1
  87. package/src/client/game/shardfile/slabLibrary.ts +115 -49
  88. package/src/client/game/shardfile/tileContent.ts +1 -1
  89. package/src/client/game/shardfile/tileDriver.ts +38 -11
  90. package/src/client/game/shardfile/wirePage.ts +7 -3
  91. package/src/client/game/shardfile/worldScenes.ts +17 -10
  92. package/src/client/host/online/doctor.ts +20 -7
  93. package/src/client/host/online/doctorView.ts +2 -0
  94. package/src/client/host/online/linkScreens.ts +95 -11
  95. package/src/client/host/online/reconnectStrip.ts +3 -2
  96. package/src/client/host/online/release.ts +87 -16
  97. package/src/client/host/online/releaseScreens.ts +108 -0
  98. package/src/client/host/online/shell.ts +24 -5
  99. package/src/client/host/online/voice.ts +45 -1
  100. package/src/client/host/online/voiceUi.ts +24 -6
  101. package/src/client/host/standalone/shell.ts +37 -1
  102. package/src/server/engine/sim/playerSim.ts +1 -1
  103. package/src/server/game/grid/simulation.ts +12 -6
  104. package/src/server/game/quest/eliteDrops.ts +7 -3
  105. package/src/server/game/riding/nativeTaming.ts +13 -2
  106. package/src/server/host/dedicated/cellHost.ts +21 -2
  107. package/src/server/host/dedicated/cellProtocol.ts +2 -0
  108. package/src/server/host/dedicated/cellWorker.ts +1 -1
  109. package/src/server/host/dedicated/dedicatedRoom.ts +38 -8
  110. package/src/server/host/dedicated/roadRoom.ts +3 -0
  111. package/src/server/host/dedicated/serverMetrics.ts +9 -0
  112. package/src/server/host/dedicated/workerTable.ts +31 -24
  113. package/src/server/host/standalone/gridServer.ts +1 -1
  114. package/src/server/host/standalone/serverHost.ts +56 -10
  115. package/src/server/host/standalone/serverProduct.ts +9 -7
  116. package/src/server/host/standalone/serverRuntime.ts +1 -1
  117. package/src/shared/engine/boot/loadingWaits.ts +10 -2
  118. package/src/shared/engine/core/config.ts +3 -0
  119. package/src/shared/engine/core/framePacing.ts +12 -1
  120. package/src/shared/engine/physics/terrainTiles.ts +20 -4
  121. package/src/shared/engine/player/hoverSpeed.ts +3 -3
  122. package/src/shared/engine/strings.ts +12 -1
  123. package/src/shared/game/devColliders.ts +60 -0
  124. package/src/shared/game/devGameplay.ts +41 -0
  125. package/src/shared/game/grid/rules.ts +12 -0
@@ -189,12 +189,16 @@ export async function installDeclaredProps(props: DeclaredProps, ports: {
189
189
  // TEMPLATE-E2E LF1-2: an unlit (emissive) surface is its declared colour × intensity, so it takes the mesh's
190
190
  // vertex colours only when it declares them: a lamp baked grey beside measure stone still glows its own amber
191
191
  const unlit = base instanceof MeshBasicMaterial;
192
+ const seeThrough = base.userData['sceneAlpha'] === true;
192
193
  const m = acquireVariant(base, { colour: glb?.color ?? null, roughness: standard?.roughness ?? null, metalness: standard?.metalness ?? null, map: undefined, vertexColours: unlit ? base.vertexColors && vertexColours : vertexColours, flat,
193
- side: source?.side ?? base.side, transparent: source?.transparent ?? base.transparent, opacity: source?.opacity ?? base.opacity,
194
+ // SHARD-SOURCE AP10: a see-through family entry (`blend: 'alpha'`, an alpha card) stays see-through whatever the GLB says
195
+ side: source?.side ?? base.side, transparent: seeThrough || (source?.transparent ?? base.transparent), opacity: seeThrough ? base.opacity : source?.opacity ?? base.opacity,
194
196
  named: { maps: binding.maps, emissive: glb?.emissive ?? null } });
195
197
  source?.dispose(); held.push(m); bases.set(m, base); return m;
196
198
  };
197
199
  o.material = Array.isArray(o.material) ? original.map(convert) : convert(original[0]);
200
+ // SHARD-SOURCE AP11: a card's corners and rise live in the shader, past the seats its bounds hold: never culled
201
+ if ((Array.isArray(o.material) ? o.material : [o.material]).some((m) => m.userData['sceneCard'] === true)) o.frustumCulled = false;
198
202
  o.castShadow = o.userData['castShadow'] !== false; o.receiveShadow = o.userData['receiveShadow'] !== false;
199
203
  });
200
204
  if (disposed) { releaseAll(); throw new Error('Props level unloaded while parsing'); }
@@ -152,7 +152,10 @@ export class SkyRig {
152
152
  // a low sun (golden hour, dawn) grazes flat decks: a shadow style may take more normal bias, or the planks speckle with acne
153
153
  for (const l of this.csm.lights) { l.color.copy(this.sunColor); l.shadow.normalBias = shadows?.normalBias ?? 0.05; l.shadow.radius = shadows?.radius ?? 2; }
154
154
  this.texelBias = shadows?.texelBias === 'phone' && rig.phone;
155
- this.farEveryOther = this.texelBias && this.csm.lights.length > 1;
155
+ // NB5 (QA-FEEDBACK-2026-11-14 rows 2, 3, 5): the desktop's three 2048² cascades take the phone's staggered cadence too
156
+ // (BA-3's A / B, shadowCadence.ts): near every frame, middle every 2nd, far every 4th. Desktop frames run at 60-120, so a
157
+ // far moving caster steps at 15-30 Hz; the shadow pass was ~110 of Driftwood's ~320 draws a frame
158
+ this.farEveryOther = (this.texelBias || TIER_CONFIG.cascadeStagger) && this.csm.lights.length > 1;
156
159
  // E174: the phone rig's shadow maps are depth only at 16 bits (Jake's pick C; shadowVariants.ts): 40 MB, not three's 160
157
160
  if (shadows?.depth16 === 'phone' && rig.phone) {
158
161
  const maps = new ShadowMaps(this.renderer, this.csm, this.shadowFade?.ghosts ?? [], rig.size);
@@ -16,7 +16,7 @@
16
16
  */
17
17
  import { BufferAttribute, BufferGeometry, Mesh, type Material, type Object3D } from 'three';
18
18
  import type { Scope } from '../../../shared/engine/app/scope';
19
- import { gpuOnlyTrees } from '../core/gpuOnly';
19
+ import { gpuOnlyTrees, refillGpuOnly } from '../core/gpuOnly';
20
20
  import { decodeTerrainTile, type TerrainTileData } from '@wildshard/format/terrainTileBytes';
21
21
  import { keepShadowWhole } from './shadowChunks';
22
22
 
@@ -25,9 +25,12 @@ const COARSE = { resolution: 17, size: 125, half: 8 } as const;
25
25
 
26
26
  interface TileState { readonly indices: BufferAttribute; readonly resolution: number }
27
27
  const coarseTiles = new WeakMap<Mesh, TileState>();
28
+ /** Where each installed tile sits on the ground, for `refreshTerrainTile`. */
29
+ const shapes = new WeakMap<Mesh, Pick<TerrainTileData, 'resolution' | 'x' | 'z' | 'size'>>();
28
30
 
29
31
  /** True when this tile is a coarse tile whose quadrants refinement may hide. */
30
- function isCoarse(data: TerrainTileData): boolean { return data.resolution === COARSE.resolution && data.size === COARSE.size; }
32
+ /** a coarse (L1) terrain tile: no skirt, its quadrants masked under fine tiles */
33
+ export function isCoarse(data: TerrainTileData): boolean { return data.resolution === COARSE.resolution && data.size === COARSE.size; }
31
34
 
32
35
  /** A grid's slope along one axis at sample `at` of `n`: central inside, second-order one-sided on the grid's edge. Sample
33
36
  * `i` of the line is `heights[base + i * stride]` (no closure per vertex: a tile's normals run once per sample at boot). */
@@ -98,29 +101,17 @@ function perimeter(r: number): number[] {
98
101
  */
99
102
  export function installTerrainTile(bytes: Uint8Array | TerrainTileData, ports: { root: Object3D; scope: Scope; material: Material; shadow: boolean; lattice?: TerrainTileData }): Mesh {
100
103
  if (ports.scope.disposed) throw new Error('terrain tile: its scope is already disposed');
101
- const data = bytes instanceof Uint8Array ? decodeTerrainTile(bytes) : bytes, r = data.resolution, colours = data.colours;
102
- if (colours === undefined) throw new Error('terrain tile: a render tile needs vertex colours (a heights-only payload is a collider)');
103
- const coarse = isCoarse(data), ring = coarse ? [] : perimeter(r), grid = r * r, vertices = grid + ring.length;
104
- const gridIndices = (r - 1) ** 2 * 6, total = gridIndices + ring.length * 6;
105
- // a coarse tile has no skirt, so it draws the decoded colours as they are; a skirted tile extends a copy
106
- const positions = new Float32Array(vertices * 3), normals = new Float32Array(vertices * 3), colour = coarse ? colours : new Float32Array(vertices * 3);
107
- const indices = vertices > 65535 ? new Uint32Array(total) : new Uint16Array(total), cell = data.size / (r - 1);
108
- for (let z = 0; z < r; z++) for (let x = 0; x < r; x++) {
109
- const vertex = z * r + x, at = vertex * 3;
110
- positions[at] = x * cell; positions[at + 1] = data.heights[vertex] ?? 0; positions[at + 2] = z * cell;
104
+ const data = bytes instanceof Uint8Array ? decodeTerrainTile(bytes) : bytes, r = data.resolution, coarse = isCoarse(data);
105
+ const { positions, normals, colour, vertices } = tileVertices(data, ports.lattice);
106
+ const ring = coarse ? 0 : vertices - r * r, gridIndices = (r - 1) ** 2 * 6, total = gridIndices + ring * 6;
107
+ const indices = vertices > 65535 ? new Uint32Array(total) : new Uint16Array(total);
108
+ for (let z = 0; z < r - 1; z++) for (let x = 0; x < r - 1; x++) {
111
109
  // Rapier's split: the triangles (x, z) (x, z+1) (x+1, z) and (x+1, z) (x, z+1) (x+1, z+1), diagonal (x+1, z)–(x, z+1).
112
- if (x < r - 1 && z < r - 1) indices.set([vertex, vertex + r, vertex + 1, vertex + 1, vertex + r, vertex + r + 1], (z * (r - 1) + x) * 6);
110
+ const vertex = z * r + x;
111
+ indices.set([vertex, vertex + r, vertex + 1, vertex + 1, vertex + r, vertex + r + 1], (z * (r - 1) + x) * 6);
113
112
  }
114
- if (!coarse) colour.set(colours);
115
- if (ports.lattice === undefined || !latticeNormals(data, ports.lattice, normals)) gridNormals(data, normals);
116
- const depth = data.size / 16;
117
- ring.forEach((border, i) => {
118
- const skirt = grid + i, next = (i + 1) % ring.length, from = border * 3, to = skirt * 3;
119
- positions[to] = positions[from] ?? 0; positions[to + 1] = (positions[from + 1] ?? 0) - depth; positions[to + 2] = positions[from + 2] ?? 0;
120
- for (let c = 0; c < 3; c++) { normals[to + c] = normals[from + c] ?? 0; colour[to + c] = colour[from + c] ?? 0; }
121
- const b = ring[next] ?? border;
122
- indices.set([border, b, skirt, b, grid + next, skirt], gridIndices + i * 6);
123
- });
113
+ const edge = coarse ? [] : perimeter(r), grid = r * r;
114
+ edge.forEach((border, i) => { const next = (i + 1) % edge.length, b = edge[next] ?? border; indices.set([border, b, grid + i, b, grid + next, grid + i], gridIndices + i * 6); });
124
115
  const geometry = ports.scope.own(new BufferGeometry());
125
116
  geometry.setAttribute('position', new BufferAttribute(positions, 3));
126
117
  geometry.setAttribute('normal', new BufferAttribute(normals, 3));
@@ -135,10 +126,60 @@ export function installTerrainTile(bytes: Uint8Array | TerrainTileData, ports: {
135
126
  // a tile is already one shadow-culling piece, and the caller's shadow disc switches its castShadow: never split it (SF16)
136
127
  keepShadowWhole(mesh);
137
128
  if (coarse) coarseTiles.set(mesh, { indices: index, resolution: r });
129
+ shapes.set(mesh, { resolution: r, x: data.x, z: data.z, size: data.size });
138
130
  ports.root.add(mesh); ports.scope.onDispose(() => { mesh.removeFromParent(); coarseTiles.delete(mesh); });
139
131
  return mesh;
140
132
  }
141
133
 
134
+ /** A tile's vertex arrays, its skirt ring after the grid on a fine tile: what `installTerrainTile` uploads. */
135
+ function tileVertices(data: TerrainTileData, lattice: TerrainTileData | undefined): { positions: Float32Array; normals: Float32Array; colour: Float32Array; vertices: number } {
136
+ const r = data.resolution, colours = data.colours;
137
+ if (colours === undefined) throw new Error('terrain tile: a render tile needs vertex colours (a heights-only payload is a collider)');
138
+ const coarse = isCoarse(data), ring = coarse ? [] : perimeter(r), grid = r * r, vertices = grid + ring.length;
139
+ // a coarse tile has no skirt, so it draws the decoded colours as they are; a skirted tile extends a copy
140
+ const positions = new Float32Array(vertices * 3), normals = new Float32Array(vertices * 3), colour = coarse ? colours : new Float32Array(vertices * 3);
141
+ const cell = data.size / (r - 1);
142
+ for (let z = 0; z < r; z++) for (let x = 0; x < r; x++) {
143
+ const at = (z * r + x) * 3;
144
+ positions[at] = x * cell; positions[at + 1] = data.heights[z * r + x] ?? 0; positions[at + 2] = z * cell;
145
+ }
146
+ if (!coarse) colour.set(colours);
147
+ if (lattice === undefined || !latticeNormals(data, lattice, normals)) gridNormals(data, normals);
148
+ const depth = data.size / 16;
149
+ ring.forEach((border, i) => {
150
+ const from = border * 3, to = (grid + i) * 3;
151
+ positions[to] = positions[from] ?? 0; positions[to + 1] = (positions[from + 1] ?? 0) - depth; positions[to + 2] = positions[from + 2] ?? 0;
152
+ for (let c = 0; c < 3; c++) { normals[to + c] = normals[from + c] ?? 0; colour[to + c] = colour[from + c] ?? 0; }
153
+ });
154
+ return { positions, normals, colour, vertices };
155
+ }
156
+
157
+ /**
158
+ * SHARD-SOURCE AP18 (dev only: `wildshard watch`'s ground swap). Cut this installed tile again from a new whole-ground
159
+ * lattice (heights and colours, the 257² the tiles were baked from) and rewrite its vertices in their buffers: the same
160
+ * vertices `installTerrainTile` makes from a tile the bake cut from that lattice. False, and nothing written, when the tile
161
+ * is not one of this module's or its vertices are not the lattice's samples.
162
+ */
163
+ export function refreshTerrainTile(mesh: Mesh, lattice: TerrainTileData): boolean {
164
+ const shape = shapes.get(mesh), colours = lattice.colours;
165
+ if (shape === undefined || colours === undefined) return false;
166
+ const r = shape.resolution, n = lattice.resolution, step = lattice.size / (n - 1), cell = shape.size / (r - 1);
167
+ const heights = new Float32Array(r * r), colour = new Float32Array(r * r * 3);
168
+ for (let z = 0; z < r; z++) for (let x = 0; x < r; x++) {
169
+ const lx = latticeIndex(shape.x + x * cell, lattice.x, step, n), lz = latticeIndex(shape.z + z * cell, lattice.z, step, n);
170
+ if (lx < 0 || lz < 0) return false;
171
+ const at = lz * n + lx, i = z * r + x;
172
+ heights[i] = lattice.heights[at] ?? 0; colour.set(colours.subarray(at * 3, at * 3 + 3), i * 3);
173
+ }
174
+ const fresh = tileVertices({ ...shape, heights, colours: colour }, lattice);
175
+ const geometry = mesh.geometry, position = geometry.getAttribute('position'), normal = geometry.getAttribute('normal'), tint = geometry.getAttribute('color');
176
+ if (!(position instanceof BufferAttribute) || !(normal instanceof BufferAttribute) || !(tint instanceof BufferAttribute) || position.count !== fresh.vertices) return false;
177
+ position.array.set(fresh.positions); position.needsUpdate = true;
178
+ refillGpuOnly(normal, fresh.normals); refillGpuOnly(tint, fresh.colour);
179
+ geometry.computeBoundingBox(); geometry.computeBoundingSphere();
180
+ return true;
181
+ }
182
+
142
183
  /**
143
184
  * Hide a coarse tile's quadrants (0 = −x −z, 1 = +x −z, 2 = −x +z, 3 = +x +z) in place while fine tiles cover them.
144
185
  * The tile's one index buffer is rewritten and its draw range shortened, so no allocation, no extra draw and no
@@ -2,6 +2,9 @@ import {joinSpawnManifest, packsBookPath, readSpawnCodeList, readSpawnManifest,
2
2
  import {assetCacheName} from '@wildshard/engine/pwa/cacheNames';
3
3
  import {jsonSlot} from '@wildshard/engine/saves/slots';
4
4
  import { bootMark,bootProgress,bootTiming,downloadShown } from '@wildshard/engine/boot/timing';
5
+ import { beginLoadingWait, finishLoadingWait } from '@wildshard/engine/boot/loadingWaits';
6
+ import { diagnosticNow } from '@wildshard/engine/core/clock';
7
+ import { Scope } from '@wildshard/engine/app/scope';
5
8
  import {contentBase, contentURL, isContentOrigin, pageURL} from '@wildshard/engine/boot/contentBase';
6
9
  import {bareSlug} from '../../../shared/game/grid/catalogueSlot';
7
10
  import {placedLoose, placedSpawn} from './placedSpawn';
@@ -315,7 +318,8 @@ function isQuota(failure: unknown): boolean { return typeof failure === 'object'
315
318
  * worker-cache response credits immediately without reading/checksumming it. */
316
319
  export function downloadSpawnManifest(address: SpawnManifestAddress, ports: SpawnDownloadPorts, base: string, packs: string = base): SpawnDownload {
317
320
  const controller = new AbortController(), listeners = new Set<(snapshot: SpawnDownloadSnapshot) => void>(), aliases = new Map<string, string>();
318
- let cacheWriteDenied = false;
321
+ let cacheWriteDenied = false, storageFull: number | null = null;
322
+ const endStorageFull = (): void => { if (storageFull !== null) finishLoadingWait(storageFull); storageFull = null; };
319
323
  // Verified bytes remain usable when optional disk publication exhausts quota.
320
324
  // Do not retry the part, claim cached credit, or publish an index for unkept bytes.
321
325
  const keepCopy = async (write: SpawnDownloadPorts['store'], url: string, response: Response): Promise<boolean> => {
@@ -326,7 +330,10 @@ export function downloadSpawnManifest(address: SpawnManifestAddress, ports: Spaw
326
330
  await write(url, response); retained = true; return true;
327
331
  } catch (failure) {
328
332
  if (!isQuota(failure)) throw failure;
329
- cacheWriteDenied = true; bootMark('download:cache-write-quota'); return false;
333
+ cacheWriteDenied = true; bootMark('download:cache-write-quota');
334
+ // FM6 mode 43: the card says so while this download runs; the world plays on from the bytes in memory
335
+ storageFull ??= beginLoadingWait('Storage is full', { kind: 'work', failmode: 'storage-full', line: 'Storage is full · the world will load more slowly' });
336
+ return false;
330
337
  } finally { if (!retained) void response.body?.cancel().catch(() => undefined); }
331
338
  };
332
339
  let completedBytes = 0, cachedBytes = 0, filesDone = 0, complete = false, progressKnown = false, error: string | null = null;
@@ -690,11 +697,12 @@ export function downloadSpawnManifest(address: SpawnManifestAddress, ports: Spaw
690
697
  // The tap starts work before its composition root reaches the await. Keep
691
698
  // its original rejection for that await without a premature global report.
692
699
  void work.catch(() => undefined); void ready.catch(() => undefined);
700
+ void ready.finally(endStorageFull).catch(() => undefined);
693
701
  const listed = Promise.race([listedOnly, ready]);
694
702
  void listed.catch(() => undefined);
695
703
  return {ready, listed, snapshot, subscribe: listener => {listeners.add(listener); listener(snapshot()); return () => {listeners.delete(listener);};},
696
704
  resolve: input => {const url = new URL(input, base); return url.origin === new URL(base).origin ? aliases.get(url.pathname) ?? url.href : url.href;},
697
- cancel: () => {controller.abort(); releaseWaits(); nudge(); markStopped(controller.signal.reason); listeners.clear();}};
705
+ cancel: () => {controller.abort(); endStorageFull(); releaseWaits(); nudge(); markStopped(controller.signal.reason); listeners.clear();}};
698
706
  }
699
707
 
700
708
  let current: {key: string; download: SpawnDownload; foreground: boolean} | undefined;
@@ -847,6 +855,36 @@ function spawnSelection(slug: string, flow: 'client' | 'grid', tier: 'phone' | '
847
855
  declare const __BUILD_ID__: string;
848
856
  let packsBook: {readonly url: string; readonly book: Promise<unknown>} | undefined;
849
857
  const PACKS_BOOK_MS = 20_000;
858
+ /** FM6 mode 35 (meta MMO-FAILURE-MODES-PLAN): a server error or busy answer on the book is read again on content's ladder (a
859
+ * 429's Retry-After as told, at least 2 s) for up to BOOK_TRIES reads, the loading card saying `book-5xx` meanwhile, before the
860
+ * named refusal. FM3's proof found a single 503 refusing the whole start ("Something broke"). A 404 still refuses at once. */
861
+ const BOOK_LINE = 'The world\'s book didn\'t arrive';
862
+ const BOOK_TRIES = 6, BOOK_LADDER_MS: readonly number[] = [2000, 4000, 8000, 16_000, 30_000];
863
+ async function bookResponse(url: string, fresh: () => AbortSignal, stalled: (error: unknown) => never): Promise<Response> {
864
+ let wait: number | undefined, shellFoot: HTMLElement | null = null;
865
+ try {
866
+ for (let attempt = 0; ; attempt++) {
867
+ // each read has its own 20 s limit (DL21), body included; the waits between reads are the ladder's, not a stall
868
+ const response = await fetch(url, {signal: fresh()}).catch(stalled);
869
+ if (response.ok) return response;
870
+ const busy = response.status === 429 || response.status >= 500;
871
+ if (!busy || attempt + 1 >= BOOK_TRIES) throw new Error(`Packs book unavailable (${response.status})`);
872
+ void response.body?.cancel().catch(() => undefined);
873
+ const told = Number(response.headers.get('retry-after'));
874
+ const ms = Math.max(2000, response.status === 429 && Number.isFinite(told) && told > 0 ? Math.min(told, 60) * 1000 : BOOK_LADDER_MS[attempt] ?? 30_000);
875
+ // at START, before Loading owns the card, only the shell's foot is on screen: it says so too (Loading repaints it later)
876
+ const foot = document.querySelector?.<HTMLElement>('.ws-load [data-el="foot"]') ?? null;
877
+ if (foot !== null) { foot.textContent = BOOK_LINE; foot.dataset['failmode'] = 'book-5xx'; shellFoot = foot; }
878
+ if (wait === undefined) wait = beginLoadingWait('Packs book', {kind: 'file', resource: url, failmode: 'book-5xx', line: BOOK_LINE, dueAt: diagnosticNow() + ms});
879
+ else { finishLoadingWait(wait); wait = beginLoadingWait('Packs book', {kind: 'file', resource: url, failmode: 'book-5xx', line: BOOK_LINE, dueAt: diagnosticNow() + ms}); }
880
+ const pause = new Scope('packs-book-retry');
881
+ try { await new Promise<void>(resolve => { pause.timeout(ms, resolve); }); } finally { pause.dispose(); }
882
+ }
883
+ } finally {
884
+ if (wait !== undefined) finishLoadingWait(wait);
885
+ if (shellFoot?.dataset['failmode'] === 'book-5xx') { delete shellFoot.dataset['failmode']; shellFoot.textContent = ''; }
886
+ }
887
+ }
850
888
  function readPacksBook(): Promise<unknown> {
851
889
  const url = contentURL(new URL(`/${packsBookPath(__BUILD_ID__)}`, document.baseURI).href);
852
890
  if (packsBook?.url === url) return packsBook.book;
@@ -854,11 +892,11 @@ function readPacksBook(): Promise<unknown> {
854
892
  try {
855
893
  // DL21 (E526): a stalled book is a named refusal with the loading card's retry, never an endless wait.
856
894
  // The limit covers the body too (sp-x9): a stalled body is the same named refusal.
857
- const signal = AbortSignal.timeout(PACKS_BOOK_MS), stalled = (error: unknown): never => {
895
+ let signal = AbortSignal.timeout(PACKS_BOOK_MS);
896
+ const stalled = (error: unknown): never => {
858
897
  throw signal.aborted ? new Error(`Packs book did not arrive in ${PACKS_BOOK_MS / 1000} s`) : error;
859
898
  };
860
- const response = await fetch(url, {signal}).catch(stalled);
861
- if (!response.ok) throw new Error(`Packs book unavailable (${response.status})`);
899
+ const response = await bookResponse(url, () => (signal = AbortSignal.timeout(PACKS_BOOK_MS)), stalled);
862
900
  const value: unknown = await response.json().catch(stalled);
863
901
  // Bound to its purpose and this build: a valid default book or another build's book is refused (sp-x9).
864
902
  if (get(value, 'book') !== 'packs' || get(value, 'build') !== __BUILD_ID__) throw new Error('Packs book is not this build\'s whole-level book');
@@ -7,28 +7,56 @@ import { lampLights } from '@wildshard/engine/render/lookLight';
7
7
  import type { LookLamp } from '@wildshard/format/look-light';
8
8
  import type { ShardWater } from '@wildshard/format/water';
9
9
  import { installClientWater } from '../shardfile/clientWater';
10
- import { isDevColliders, swapDevBoxes, type DevBox } from '@wildshard/engine/game/devColliders';
10
+ import { shardfileLiveLook } from './liveLook';
11
+ import type { Shardfile } from '@wildshard/format/shardSchema';
12
+ import { devGroundHeight, isDevColliders, liftedFeet, swapDevBoxes, type DevBox, type DevGround } from '@wildshard/engine/game/devColliders';
13
+ import { swapTerrainCollider } from '@wildshard/engine/physics/terrainTiles';
14
+ import type { HeightfieldBinding } from '@wildshard/engine/world/Heightfield';
15
+ import { decodeTerrainTile, type TerrainTileData } from '@wildshard/format/terrainTileBytes';
16
+ import { refreshTerrainTile } from '@wildshard/engine/world/terrainTileView';
17
+ import type { DevGameplay, DevPlace, DevRestarted } from '@wildshard/engine/game/devGameplay';
18
+ import { diagnosticNow } from '@wildshard/engine/core/clock';
11
19
 
12
20
  /**
13
21
  * SHARD-SOURCE AP5 (J347: engine is the deployed client and server; dev tooling is sharddev's). The dev hook: the one thing
14
22
  * a DEVSERVER page carries for `wildshard watch`. sharddev owns the rest, its WebSocket server and protocol, the part diff
15
23
  * and a page script `watch` injects into the page it serves; that script owns one scope per part and the swap order, and
16
- * calls these five functions on `window.__wildshardDevHook`:
24
+ * calls these functions on `window.__wildshardDevHook`:
17
25
  *
18
26
  * addPart(name, part) draw a new part: meshes, sprites, lamps (the look's lamp lights) and water (the client's water)
19
27
  * replacePart(name, part) build the new part first, then dispose the old part's scope, in one call: no frame shows neither
20
28
  * removePart(name) dispose the part's scope (its boxes stay: the page script calls swapColliders(name, []))
21
- * setLook(look) the data look's day keys (sky, fog, sun, ambient) in place: true, or false when the page's look
22
- * can't take them live and the page must reload
29
+ * setLook(look) v2 (AP17): the look section in place, as the shardfile would carry it: day keys (sky, fog, sun,
30
+ * ambient), the sun's arc, exposure, tone, vignette and bloom (`shardfileLiveLook`); v1 sent
31
+ * the keys only. True, or false when the page's look can't take it live and the page must reload
23
32
  * swapColliders(name, boxes) the part's solid boxes, in the page's world and the in-page server's (the worker, by its
24
- * harness port), new set first, then the old one goes
33
+ * harness port), new set first, then the old one goes; a player inside a new box is lifted
34
+ * onto it (v3)
35
+ * setGround(bytes) v3 (AP18): the whole ground as one terrain tile's wire bytes (`encodeTerrainTile`: the 257²
36
+ * heights and colours the shard's tiles and collider are cut from). The page's heightfield
37
+ * collider, its terrain field (`heightAt`) and every drawn ground tile whose samples changed are
38
+ * swapped; the in-page server takes the same heights; a player under the new ground is lifted
39
+ * onto it. True, or false when the page's ground can't take it (the page must reload)
40
+ * restartGameplay(gameplay) v4 (AP19): the shard's quests, encounters, spawns or scripts changed (`DEV_GAMEPLAY_SECTIONS`,
41
+ * the new rows of each). The in-page server saves, puts its world down and boots it again on
42
+ * the new rows from that save, with the player where the page has it; the page's client rejoins
43
+ * it, the held boxes and ground go to it again, and the quest views are built again from the new
44
+ * quest section. Resolves to what ran, or `ok: false` when the page must reload
25
45
  *
26
46
  * `version` is `DEV_HOOK_VERSION`; sharddev refuses a page with another (its page script) and a client whose build flags
27
47
  * say another (`build-flags.json` `devHook`, written by `scripts/app-build-pipeline.mjs`). Bump it on any change to these
28
48
  * signatures or to `DevPart`. A production build has none of this: `finish.ts` imports it only behind `__DEVSERVER__`, and
29
49
  * `scripts/check-devserver.mjs` refuses a bundle that holds `DEV_HOOK_GLOBAL`.
30
50
  */
31
- export const DEV_HOOK_VERSION = 1;
51
+ export const DEV_HOOK_VERSION = 4;
52
+
53
+ // the in-page server's half of `setGround`, which the standalone shell puts on the window (client/host/standalone/shell.ts)
54
+ declare global { interface Window {
55
+ __workerClientDevGround?: (ground: DevGround) => void;
56
+ /** AP19: the in-page server's soft restart (client/host/standalone/shell.ts) and the quest views' (shardfile/client.ts) */
57
+ __workerClientDevRestart?: (gameplay: DevGameplay, at: DevPlace | null) => Promise<DevRestarted>;
58
+ __shardfileDevQuests?: (quests: NonNullable<DevGameplay['quests']>) => Promise<boolean>;
59
+ } }
32
60
  export const DEV_HOOK_GLOBAL = '__wildshardDevHook';
33
61
 
34
62
  export type Rgb = readonly [number, number, number];
@@ -94,8 +122,8 @@ export interface DevPart {
94
122
  readonly water: ShardWater;
95
123
  }
96
124
 
97
- /** The part of a shardfile look a watched page takes live. */
98
- export interface DevLook { readonly keys: readonly LookKey[] }
125
+ /** The look a watched page takes live: its day keys, and (v2, AP17) the whole look section the page's shardfile would carry. */
126
+ export interface DevLook { readonly keys: readonly LookKey[]; readonly look?: Shardfile['look'] }
99
127
 
100
128
  export interface DevHook {
101
129
  readonly version: number;
@@ -104,8 +132,16 @@ export interface DevHook {
104
132
  removePart: (name: string) => void;
105
133
  setLook: (look: DevLook) => boolean;
106
134
  swapColliders: (name: string, boxes: readonly DevBox[]) => void;
135
+ setGround: (ground: Uint8Array) => boolean;
136
+ restartGameplay: (gameplay: DevGameplay) => Promise<DevRestart>;
107
137
  }
108
138
 
139
+ /** What a soft restart did: the server's world restart and the page's quest views, and how long each took (ms). */
140
+ export interface DevRestart { readonly ok: boolean; readonly serverMs: number; readonly questsMs: number | null; readonly reason?: string }
141
+
142
+ /** The page's player, as a dev swap lifts it out of new solids. */
143
+ export interface DevPlayer { readonly position: { readonly x: number; readonly y: number; readonly z: number }; readonly yaw: number; pitch: number; spawn: (x: number, z: number, yaw: number, y?: number) => void }
144
+
109
145
  export interface DevHookPorts {
110
146
  readonly scope: Scope;
111
147
  readonly scene: THREE.Object3D;
@@ -116,6 +152,16 @@ export interface DevHookPorts {
116
152
  readonly look: () => LookStrategy | null;
117
153
  /** the in-page server's half of `swapColliders` (the worker page's harness port); null when the page has none */
118
154
  readonly server: () => ((name: string, boxes: readonly DevBox[]) => void) | null;
155
+ /** the in-page server's half of `setGround` (v3); null when the page has none */
156
+ readonly serverGround?: () => ((ground: DevGround) => void) | null;
157
+ /** the page's player now, for the lift out of new solids (v3); null on a page without one */
158
+ readonly player?: () => DevPlayer | null;
159
+ /** the page's terrain field now (`captureHeightfield`), which a new ground installs into (v3); absent in a test */
160
+ readonly terrainField?: () => HeightfieldBinding;
161
+ /** the in-page server's soft restart (v4); null when the page has none */
162
+ readonly restart?: () => ((gameplay: DevGameplay, at: DevPlace | null) => Promise<DevRestarted>) | null;
163
+ /** the page's quest views, built again from a new quest section (v4); null when the page can't */
164
+ readonly quests?: () => ((quests: NonNullable<DevGameplay['quests']>) => Promise<boolean>) | null;
119
165
  readonly watchFrames: (fn: (dt: number) => void) => () => void;
120
166
  }
121
167
 
@@ -222,8 +268,20 @@ export function createDevHook(ports: DevHookPorts): DevHook & { readonly root: T
222
268
  }
223
269
  const setLook = (look: DevLook): boolean => {
224
270
  const current = ports.look();
225
- return current !== null && 'liveKeys' in current && current.liveKeys !== undefined && current.liveKeys(look.keys);
271
+ if (current === null || !('liveKeys' in current)) return false;
272
+ if (look.look !== undefined) return current.liveLook !== undefined && current.liveLook(shardfileLiveLook(look.look));
273
+ return current.liveKeys !== undefined && current.liveKeys(look.keys);
274
+ };
275
+ /** A player now inside new solids stands on them (the server lifts its own: `swapDevGround`). */
276
+ const lift = (heightAt: ((x: number, z: number) => number) | null, boxes: readonly DevBox[]): void => {
277
+ const player = ports.player?.() ?? null;
278
+ if (player === null) return;
279
+ const { x, y, z } = player.position, feet = liftedFeet(x, y, z, heightAt, boxes);
280
+ if (feet === null) return;
281
+ const pitch = player.pitch;
282
+ player.spawn(x, z, player.yaw, feet); player.pitch = pitch;
226
283
  };
284
+
227
285
  // The boxes go into the page's world as it is now. After a grid crossing that is a new world: every held part's boxes
228
286
  // are made again in it, and the old world's sets are disposed (Physics skips removal from a freed world).
229
287
  const swapColliders = (name: string, boxes: readonly DevBox[]): void => {
@@ -239,19 +297,98 @@ export function createDevHook(ports: DevHookPorts): DevHook & { readonly root: T
239
297
  }
240
298
  if (physics !== null) swapDevBoxes(physics, scope, colliders, name, boxes);
241
299
  ports.server()?.(name, boxes);
300
+ lift(null, boxes);
301
+ };
302
+ // AP18: each drawn ground tile keeps a signature of the lattice samples it was last cut from; a swap cuts again only the
303
+ // tiles whose samples changed, and a tile the page streams in later (cut from the boot's bytes) is cut on the next frame.
304
+ let ground: TerrainTileData | null = null, groundScope: Scope | null = null, sweep = 0;
305
+ const cut = new WeakMap<THREE.Mesh, number>();
306
+ const tiles = (): THREE.Mesh[] => {
307
+ const out: THREE.Mesh[] = [];
308
+ ports.scene.traverse(object => { if (object instanceof THREE.Mesh && object.name.startsWith('terrain:')) out.push(object as THREE.Mesh); });
309
+ return out;
310
+ };
311
+ /** Cut every tile whose samples differ from the ones it holds; false when one can't be cut from this lattice. */
312
+ const recut = (lattice: TerrainTileData): boolean => {
313
+ let ok = true;
314
+ for (const mesh of tiles()) {
315
+ const signature = tileSignature(mesh, lattice);
316
+ if (signature === null) { ok = false; continue; }
317
+ if (cut.get(mesh) === signature) continue;
318
+ if (refreshTerrainTile(mesh, lattice)) cut.set(mesh, signature); else ok = false;
319
+ }
320
+ return ok;
321
+ };
322
+ const setGround = (bytes: Uint8Array): boolean => {
323
+ let lattice: TerrainTileData;
324
+ try { lattice = decodeTerrainTile(bytes); } catch { return false; }
325
+ if (lattice.colours === undefined) return false;
326
+ const heights: DevGround = { resolution: lattice.resolution, x: lattice.x, z: lattice.z, size: lattice.size, heights: lattice.heights };
327
+ if (!recut(lattice)) return false;
328
+ const physics = ports.physics(), next = scope.child('devGround');
329
+ if (physics !== null) swapTerrainCollider(physics, heights, next);
330
+ groundScope?.dispose(); groundScope = next;
331
+ const heightAt = devGroundHeight(heights), field = ports.terrainField?.();
332
+ const normalAt = (x: number, z: number, eps = 0.25): [number, number, number] => {
333
+ const dx = heightAt(x - eps, z) - heightAt(x + eps, z), dz = heightAt(x, z - eps) - heightAt(x, z + eps), length = Math.hypot(dx, 2 * eps, dz);
334
+ return [dx / length, 2 * eps / length, dz / length];
335
+ };
336
+ field?.install({ heightAt, normalAt, splatAt: field.field.splatAt });
337
+ ports.serverGround?.()?.(heights);
338
+ ground = lattice;
339
+ lift(heightAt, []);
340
+ return true;
341
+ };
342
+ // AP19: the server's world restarts on the new rows and the quest views are built again, side by side; then the new world
343
+ // takes the boxes and ground watch had swapped into the old one.
344
+ const restartGameplay = async (gameplay: DevGameplay): Promise<DevRestart> => {
345
+ const server = ports.restart?.() ?? null, views = gameplay.quests === undefined ? null : ports.quests?.() ?? null;
346
+ if (server === null) return { ok: false, serverMs: 0, questsMs: null, reason: 'the page has no in-page server' };
347
+ if (gameplay.quests !== undefined && views === null) return { ok: false, serverMs: 0, questsMs: null, reason: 'the page can\'t rebuild its quest views' };
348
+ const player = ports.player?.() ?? null, at = player === null ? null : { x: player.position.x, y: player.position.y, z: player.position.z, yaw: player.yaw };
349
+ const started = diagnosticNow();
350
+ const quests = views === null || gameplay.quests === undefined ? Promise.resolve(null) : views(gameplay.quests).then(ok => ok ? diagnosticNow() - started : -1);
351
+ const [restarted, questsMs] = await Promise.all([server(gameplay, at), quests]);
352
+ if (restarted.ok) {
353
+ for (const [name, boxes] of boxesOf) ports.server()?.(name, boxes);
354
+ if (ground !== null) ports.serverGround?.()?.({ resolution: ground.resolution, x: ground.x, z: ground.z, size: ground.size, heights: ground.heights });
355
+ }
356
+ const ok = restarted.ok && questsMs !== -1;
357
+ return { ok, serverMs: restarted.ms, questsMs: questsMs === null || questsMs < 0 ? null : Math.round(questsMs),
358
+ ...(restarted.reason !== undefined ? { reason: restarted.reason } : questsMs === -1 ? { reason: 'the quest views refused the new quests' } : {}) };
242
359
  };
360
+ scope.onDispose(ports.watchFrames(() => { if (ground !== null && ++sweep % 15 === 0) recut(ground); }));
243
361
  scope.onDispose(() => { for (const held of colliders.values()) held.dispose(); colliders.clear(); });
244
- return { version: DEV_HOOK_VERSION, root, addPart, replacePart, removePart, setLook, swapColliders,
362
+ return { version: DEV_HOOK_VERSION, root, addPart, replacePart, removePart, setLook, swapColliders, setGround, restartGameplay,
245
363
  held: () => ({ geometries: geometries.size, textures: textures.size }) };
246
364
  }
247
365
 
248
366
  /** Put the hook on the window for sharddev's page script, for the page's level. */
249
367
  export function installDevHook(ports: DevHookPorts): DevHook {
250
- const hook = createDevHook(ports), { version, addPart, replacePart, removePart, setLook, swapColliders } = hook;
251
- ports.scope.expose(window, DEV_HOOK_GLOBAL, Object.freeze({ version, addPart, replacePart, removePart, setLook, swapColliders } satisfies DevHook));
368
+ const hook = createDevHook(ports), { version, addPart, replacePart, removePart, setLook, swapColliders, setGround, restartGameplay } = hook;
369
+ ports.scope.expose(window, DEV_HOOK_GLOBAL, Object.freeze({ version, addPart, replacePart, removePart, setLook, swapColliders, setGround, restartGameplay } satisfies DevHook));
252
370
  return hook;
253
371
  }
254
372
 
373
+ /** A tile's lattice window (heights and colours), as one number: the samples a tile at its place and size is cut from. Null
374
+ * when the tile's corners are off the lattice. */
375
+ function tileSignature(mesh: THREE.Mesh, lattice: TerrainTileData): number | null {
376
+ const box = mesh.geometry.boundingBox, colours = lattice.colours;
377
+ if (box === null || colours === undefined) return null;
378
+ const n = lattice.resolution, step = lattice.size / (n - 1), size = box.max.x - box.min.x;
379
+ const x0 = Math.round((mesh.position.x - lattice.x) / step), z0 = Math.round((mesh.position.z - lattice.z) / step), span = Math.round(size / step);
380
+ // one sample more on each side: a tile's normals read its neighbours' heights
381
+ if (x0 < 0 || z0 < 0 || x0 + span >= n || z0 + span >= n) return null;
382
+ let hash = 2166136261;
383
+ const bits = new Uint32Array(1), float = new Float32Array(bits.buffer);
384
+ const mix = (value: number): void => { float[0] = value; hash = Math.imul(hash ^ (bits[0] ?? 0), 16777619); };
385
+ for (let z = Math.max(0, z0 - 1); z <= Math.min(n - 1, z0 + span + 1); z++) for (let x = Math.max(0, x0 - 1); x <= Math.min(n - 1, x0 + span + 1); x++) {
386
+ const at = z * n + x;
387
+ mix(lattice.heights[at] ?? 0); mix(colours[at * 3] ?? 0); mix(colours[at * 3 + 1] ?? 0); mix(colours[at * 3 + 2] ?? 0);
388
+ }
389
+ return hash >>> 0;
390
+ }
391
+
255
392
  function makeMaterial(row: DevMaterial, shared: THREE.DataTexture | null, owned: { dispose: () => void }[]): THREE.Material {
256
393
  let map: THREE.Texture | null = null;
257
394
  if (shared !== null) {
@@ -0,0 +1,21 @@
1
+ import { DATA_LOOK_DAY, type LiveLook } from '@wildshard/engine/render/dataLook';
2
+ import { lookLightManifest } from '@wildshard/engine/render/lookLight';
3
+ import { lookLightOn } from '@wildshard/engine/ui/lookLightOption';
4
+ import { TIER } from '@wildshard/engine/core/tier';
5
+ import type { Shardfile } from '@wildshard/format/shardSchema';
6
+ import { shardfileFileUrl } from '../shardfile/look';
7
+
8
+ /**
9
+ * SHARD-SOURCE AP17: a shardfile's look section as `shardfileLook` (`../shardfile/look.ts`) builds its data look, plus the
10
+ * engine bloom the level grade takes from it (`plugin/context.ts`), for the dev hook's `setLook`: a watched page's look set
11
+ * live from the same data a fresh shell would boot from. Kept beside the hook, not in `shardfile/`, so a dev-only change never
12
+ * moves the shardfile validation revision; `liveLook.test.ts` holds the two in step.
13
+ */
14
+ export function shardfileLiveLook(look: Shardfile['look'], light: boolean = lookLightOn()): LiveLook {
15
+ const resolved = lookLightManifest(look, light, TIER);
16
+ return { day: look.day ?? DATA_LOOK_DAY, dayOverride: look.dayOverride, keys: look.keys, lut: look.grade.lut === null ? null : shardfileFileUrl(look.grade.lut),
17
+ neutral: look.grade.tone === 'neutral', aces: look.grade.tone === 'aces', exposure: look.grade.exposure, vignette: look.grade.vignette ?? null, bloomRadius: resolved.bloom.radius,
18
+ bloom: resolved.bloom,
19
+ light: { rim: resolved.rim, pools: resolved.pools, heightFogDensity: resolved.atmosphere.fogHeightDensity, lamps: resolved.lamps, bounce: resolved.bounce, environment: resolved.environment,
20
+ shadow: resolved.shadow, motes: resolved.motes } };
21
+ }