@wildshard/engine 0.1.15 → 0.1.18
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.
- package/CHANGELOG.md +23 -0
- package/index.html +157 -11
- package/lint/engine-sides.json +23 -0
- package/lint/host-callback-syntax.mjs +2 -1
- package/lint/host-callbacks.mjs +3 -3
- package/lint/host-files.mjs +5 -4
- package/lint/host-register.json +496 -0
- package/lint/no-base64.mjs +3 -1
- package/lint/ratchet.json +2 -2
- package/lint/shard-imports.d.mts +1 -0
- package/lint/shard-imports.mjs +60 -13
- package/lint/shard-source.d.mts +9 -0
- package/lint/shard-source.mjs +91 -0
- package/lint/shardfile-boundaries.mjs +10 -8
- package/lint/sim-closure.mjs +6 -3
- package/lint/wildshard-plugin.d.ts +4 -0
- package/lint/wildshard-plugin.js +44 -27
- package/package.json +24 -6
- package/scripts/app-build/buildIdentity.d.mts +3 -1
- package/scripts/app-build/buildIdentity.mjs +25 -5
- package/scripts/app-build/builtAt.d.mts +4 -0
- package/scripts/app-build/builtAt.mjs +21 -0
- package/scripts/app-build/outputProducts.d.mts +3 -0
- package/scripts/app-build/outputProducts.mjs +31 -0
- package/scripts/app-build/serviceWorker.ts +16 -2
- package/scripts/app-build/versionFiles.ts +2 -1
- package/scripts/app-build-pipeline.mjs +7 -1
- package/scripts/audio-download-proof.mjs +843 -0
- package/scripts/build-app.mjs +4 -0
- package/scripts/build-mirror.d.mts +2 -0
- package/scripts/build-mirror.mjs +5 -4
- package/scripts/built-product.mjs +3 -3
- package/scripts/cell-mem/metrics-preload.mjs +65 -0
- package/scripts/cell-mem-bench.mjs +130 -0
- package/scripts/check-chunks.mjs +2 -1
- package/scripts/check-devserver.mjs +1 -1
- package/scripts/chromium-keychain-check.mjs +4 -2
- package/scripts/chromium-keychain.mjs +3 -1
- package/scripts/cook.mjs +7 -3
- package/scripts/devices.d.mts +4 -0
- package/scripts/devices.mjs +39 -0
- package/scripts/devserver-client.d.mts +7 -0
- package/scripts/devserver-client.mjs +85 -0
- package/scripts/doctor-proof.mjs +1 -1
- package/scripts/e2e-faults.mjs +159 -0
- package/scripts/engine-ci-budget.ts +7 -1
- package/scripts/format-lock.mjs +20 -11
- package/scripts/generate-title-launch.mjs +3 -2
- package/scripts/grid-crossing-walk-proof.mjs +30 -11
- package/scripts/heavy-lane.py +25 -1
- package/scripts/host-ruler/register-migrate.mjs +242 -0
- package/scripts/host-ruler/register.d.mts +36 -0
- package/scripts/host-ruler/register.mjs +116 -0
- package/scripts/host-ruler/roots.d.mts +29 -0
- package/scripts/host-ruler/roots.mjs +333 -0
- package/scripts/host-ruler/server-roots.d.mts +23 -0
- package/scripts/host-ruler/server-roots.mjs +272 -0
- package/scripts/main-watch.d.mts +1 -1
- package/scripts/main-watch.mjs +10 -6
- package/scripts/map-hash.mjs +3 -6
- package/scripts/memory-proof.mjs +158 -0
- package/scripts/mmo-bots.mjs +2 -2
- package/scripts/offline-proof-rules.d.mts +5 -2
- package/scripts/offline-proof-rules.mjs +43 -6
- package/scripts/offline-proof.mjs +15 -6
- package/scripts/online-rig.mjs +4 -4
- package/scripts/page-release/flow.d.mts +1 -0
- package/scripts/page-release/flow.mjs +6 -2
- package/scripts/page-release.mjs +5 -1
- package/scripts/physics-route.json +0 -71
- package/scripts/pins-catalogue.ts +103 -0
- package/scripts/pins-reuse.mjs +3 -1
- package/scripts/pins.ts +22 -14
- package/scripts/preview-grid.ts +203 -0
- package/scripts/road-preload-proof.mjs +167 -0
- package/scripts/server-release/publish.mjs +2 -2
- package/scripts/server-release/served-slug.d.mts +2 -0
- package/scripts/server-release/served-slug.mjs +10 -0
- package/scripts/server-release/sign.d.mts +1 -0
- package/scripts/server-release/sign.mjs +3 -7
- package/scripts/shard-components.mjs +0 -2
- package/scripts/shard-outputs.d.mts +8 -0
- package/scripts/shard-outputs.mjs +45 -11
- package/scripts/side-parity.d.mts +2 -1
- package/scripts/side-parity.mjs +25 -4
- package/scripts/test-amber.d.mts +1 -0
- package/scripts/test-amber.mjs +10 -0
- package/scripts/test-products.json +3 -3
- package/scripts/tier-textures-proof.mjs +101 -0
- package/scripts/tier-textures.mjs +60 -0
- package/scripts/tracked-public.d.mts +1 -0
- package/scripts/tracked-public.mjs +17 -0
- package/scripts/tsconfig.json +1 -0
- package/scripts/vps/wildshard-config +79 -23
- package/scripts/worker-client-play.mjs +1 -0
- package/scripts/worker-client-proof.mjs +1 -1
- package/scripts/worker-client-slug.mjs +44 -0
- package/src/cli/engine.mjs +8 -0
- package/src/client/app/bootRoute.ts +4 -1
- package/src/client/app/dropModal.ts +15 -2
- package/src/client/app/entry.ts +96 -13
- package/src/client/app/slugPath.ts +5 -0
- package/src/client/engine/audio/Audio.ts +20 -2
- package/src/client/engine/boot/bakedTextures.ts +3 -2
- package/src/client/engine/boot/bootTrace.ts +6 -1
- package/src/client/engine/boot/bytes.ts +4 -3
- package/src/client/engine/boot/clearDownloads.ts +1 -1
- package/src/client/engine/boot/contentRead.ts +4 -0
- package/src/client/engine/boot/dropNotice.ts +20 -6
- package/src/client/engine/boot/gpuFiles.ts +25 -2
- package/src/client/engine/boot/lastEnd.ts +8 -2
- package/src/client/engine/boot/parsedPages.ts +127 -58
- package/src/client/engine/boot/shardPrefetch.ts +7 -1
- package/src/client/engine/boot/sw.ts +19 -0
- package/src/client/engine/build.d.ts +2 -0
- package/src/client/engine/core/Game.ts +29 -3
- package/src/client/engine/core/GpuRecovery.ts +7 -0
- package/src/client/engine/core/Volumetrics.ts +5 -0
- package/src/client/engine/core/assets.ts +27 -20
- package/src/client/engine/core/bootstrap.ts +5 -3
- package/src/client/engine/core/ktx2.ts +84 -11
- package/src/client/engine/debug/probe.ts +18 -1
- package/src/client/engine/explore/Compare.ts +2 -2
- package/src/client/engine/explore/TouchFly.ts +3 -5
- package/src/client/engine/fx/LightPool.ts +41 -1
- package/src/client/engine/input/dom.ts +12 -0
- package/src/client/engine/net/predictor.ts +6 -2
- package/src/client/engine/player/Player.ts +10 -2
- package/src/client/engine/player/TouchControls.ts +12 -4
- package/src/client/engine/pwa/sw.js +59 -11
- package/src/client/engine/render/drawCheck.ts +96 -0
- package/src/client/engine/render/precompile.ts +20 -14
- package/src/client/engine/saves/staleBuildNote.ts +46 -0
- package/src/client/engine/telemetry/browserErrors.ts +161 -21
- package/src/client/engine/telemetry/deviceSnapshot.ts +155 -0
- package/src/client/engine/telemetry/screenOutbox.ts +61 -0
- package/src/client/engine/telemetry/staleBuildReport.ts +12 -0
- package/src/client/engine/ui/DeathFade.ts +99 -11
- package/src/client/engine/ui/ErrorModal.ts +13 -6
- package/src/client/engine/ui/Feedback.ts +2 -1
- package/src/client/engine/ui/Loading.ts +10 -6
- package/src/client/engine/ui/Map.ts +2 -1
- package/src/client/engine/ui/WeaponStrip.ts +2 -1
- package/src/client/engine/ui/backGuard.ts +104 -0
- package/src/client/engine/ui/hudAdapters.ts +30 -4
- package/src/client/engine/ui/loading.css +17 -0
- package/src/client/engine/ui/namePrompt.ts +6 -5
- package/src/client/engine/ui/styles/combat.css +12 -0
- package/src/client/engine/ui/styles/namePrompt.css +4 -2
- package/src/client/game/boot/audio.generated.ts +0 -396
- package/src/client/game/boot/bytes.generated.ts +42 -71
- package/src/client/game/boot/versions.generated.ts +0 -13
- package/src/client/game/compendium/keepsakes.ts +16 -6
- package/src/client/game/grapple/tool.ts +10 -7
- package/src/client/game/grid/area.ts +38 -0
- package/src/client/game/grid/cellLoading.ts +23 -12
- package/src/client/game/grid/cellScreens.ts +39 -74
- package/src/client/game/grid/live.ts +28 -2
- package/src/client/game/grid/liveSession.ts +54 -10
- package/src/client/game/grid/menu.ts +4 -0
- package/src/client/game/grid/nearPlaceholderPlan.ts +8 -0
- package/src/client/game/grid/nearPlaceholderView.ts +9 -3
- package/src/client/game/grid/neighbourPanels.ts +10 -1
- package/src/client/game/grid/oneWayIn.ts +92 -27
- package/src/client/game/grid/pageEntry.ts +19 -0
- package/src/client/game/grid/pageShell.ts +1 -1
- package/src/client/game/grid/placedCards.ts +55 -0
- package/src/client/game/grid/placedCells.ts +131 -0
- package/src/client/game/grid/plotAudio.ts +114 -0
- package/src/client/game/grid/products.ts +55 -5
- package/src/client/game/grid/regionalRuntime.ts +6 -0
- package/src/client/game/grid/regionalWorld.ts +15 -2
- package/src/client/game/grid/roadCull.ts +44 -14
- package/src/client/game/grid/roadLookPlatform.ts +2 -2
- package/src/client/game/grid/roadTileBacking.ts +13 -3
- package/src/client/game/grid/session.ts +47 -22
- package/src/client/game/grid/shardfileFar.ts +9 -3
- package/src/client/game/grid/spawnGround.ts +68 -0
- package/src/client/game/grid/voidLook.ts +29 -23
- package/src/client/game/loot/runtime.ts +3 -1
- package/src/client/game/mainMenu.ts +14 -6
- package/src/client/game/riding/hud.ts +6 -4
- package/src/client/game/session/finish.ts +22 -4
- package/src/client/game/session/play.ts +8 -2
- package/src/client/game/session/session.ts +4 -1
- package/src/client/game/shard/titleList.ts +6 -2
- package/src/client/game/shardfile/clientWorker.ts +43 -13
- package/src/client/game/shardfile/serverRoute.ts +10 -22
- package/src/client/game/slugPage.css +11 -0
- package/src/client/game/slugPage.ts +84 -0
- package/src/client/game/systems/viewmodel/heldView.ts +6 -3
- package/src/client/game/titleDeck.ts +56 -32
- package/src/client/host/online/doctor.ts +7 -6
- package/src/client/host/online/linkScreens.ts +16 -0
- package/src/client/host/online/release.ts +51 -5
- package/src/client/host/online/shell.ts +62 -27
- package/src/client/host/standalone/shell.ts +7 -3
- package/src/cook/game/audioReport.ts +57 -0
- package/src/cook/game/entryTotals.ts +26 -6
- package/src/cook/game/installedRuntimeReads.ts +3 -0
- package/src/cook/game/shardCook.ts +38 -8
- package/src/cook/game/tierTextures.ts +276 -0
- package/src/e2e/smoke/game.ts +19 -14
- package/src/e2e/smoke/page-globals.d.ts +9 -8
- package/src/e2e/smoke/template2.spec.ts +8 -7
- package/src/server/engine/sim/respawn.ts +6 -1
- package/src/server/engine/sim.ts +3 -0
- package/src/server/game/grid/simulation.ts +35 -0
- package/src/server/game/loot/harvest.ts +2 -0
- package/src/server/game/loot/keepsakeProgression.ts +40 -0
- package/src/server/game/loot/playerOwned.ts +5 -1
- package/src/server/game/plugin/simulation.ts +4 -0
- package/src/server/game/population/nativeBake.ts +2 -1
- package/src/server/game/quest/chapterRecords.ts +2 -0
- package/src/server/game/quest/serverChapters.ts +4 -0
- package/src/server/game/quest/serverDoors.ts +11 -5
- package/src/server/game/roomRespawn.ts +4 -0
- package/src/server/game/shardfile/installedSides.ts +18 -0
- package/src/server/game/shardfile/nativeAssemblyHosts.ts +19 -10
- package/src/server/game/shardfile/nativeAssemblyInput.ts +1 -4
- package/src/server/host/bake/headlessWorker.ts +5 -1
- package/src/server/host/dedicated/cellHost.ts +98 -29
- package/src/server/host/dedicated/cellProtocol.ts +11 -1
- package/src/server/host/dedicated/cellWorker.ts +9 -3
- package/src/server/host/dedicated/crossing.ts +6 -2
- package/src/server/host/dedicated/dedicatedRoom.ts +21 -8
- package/src/server/host/dedicated/gridCells.ts +52 -9
- package/src/server/host/dedicated/main.ts +31 -12
- package/src/server/host/dedicated/placementFile.ts +56 -0
- package/src/server/host/dedicated/releaseFile.ts +17 -10
- package/src/server/host/dedicated/roadRoom.ts +21 -5
- package/src/server/host/dedicated/socketTransport.ts +2 -1
- package/src/server/host/dedicated/workerTable.ts +13 -1
- package/src/server/host/dedicated/world.ts +111 -10
- package/src/server/host/headlessRuntime.ts +10 -5
- package/src/server/host/installers.ts +62 -0
- package/src/server/host/openWorld.ts +59 -0
- package/src/server/host/ropeDecks.ts +2 -0
- package/src/server/host/standalone/cellWorld.ts +25 -19
- package/src/server/host/standalone/fallFloor.ts +2 -2
- package/src/server/host/standalone/gridServer.ts +7 -4
- package/src/server/host/standalone/roadWorld.ts +41 -4
- package/src/shared/engine/audio/bootAudio.ts +33 -0
- package/src/shared/engine/level/spec.ts +3 -3
- package/src/shared/engine/net/acts.ts +3 -0
- package/src/shared/engine/net/deviceWord.ts +138 -0
- package/src/shared/engine/net/socketFrames.ts +7 -4
- package/src/shared/engine/physics/query.ts +27 -0
- package/src/shared/engine/physics/terrain.ts +19 -28
- package/src/shared/engine/saves/saves.lock.json +15 -0
- package/src/shared/engine/sim/actRoutes.ts +2 -0
- package/src/shared/game/compendium/keepsakeProgression.ts +24 -0
- package/src/shared/game/grid/catalogue.ts +12 -5
- package/src/shared/game/grid/catalogueSlot.ts +18 -0
- package/src/shared/game/grid/farProxy.ts +6 -5
- package/src/shared/game/grid/pageMode.ts +1 -1
- package/src/shared/game/grid/placementRows.ts +33 -0
- package/src/shared/game/grid/roadLayout.ts +26 -3
- package/src/shared/game/grid/singleplayer.json +0 -13
- package/src/shared/game/grid/voidFloor.ts +122 -0
- package/src/shared/game/strings.ts +15 -0
- package/src/shared/host/standalone/netInput.ts +2 -1
|
@@ -73,6 +73,11 @@ const DODGE_ROLL = 0.122; // rad of camera lean into a fully sideway
|
|
|
73
73
|
const DODGE_FOV_KICK = 5; // ° wider while a dodge runs …
|
|
74
74
|
const LUNGE_FOV_KICK = 7; // … and a lunge (Sword.ts reads `fovKick`)
|
|
75
75
|
|
|
76
|
+
/** touch play: the touch layer is up (`#hud.touch`, from a coarse pointer or `?touch`) or the primary pointer is coarse.
|
|
77
|
+
* Pointer lock is a mouse feature; a touch device never asks for it (QA-FEEDBACK-2026-11-13 row 6). */
|
|
78
|
+
export const touchPlay = (): boolean => (typeof document !== 'undefined' && document.getElementById('hud')?.classList.contains('touch') === true)
|
|
79
|
+
|| (typeof matchMedia === 'function' && matchMedia('(pointer: coarse)').matches);
|
|
80
|
+
|
|
76
81
|
export class Player {
|
|
77
82
|
/** The step's plain state (player/motionState.ts). The fields below that read and write it are the Player's public view:
|
|
78
83
|
* weapons, shards and the camera read them, and a predictor captures and restores the state itself. */
|
|
@@ -333,8 +338,11 @@ export class Player {
|
|
|
333
338
|
y: Math.max(-1, Math.min(1, Number(k.has('KeyW')) - Number(k.has('KeyS')) + this.touchMove.y)) };
|
|
334
339
|
}
|
|
335
340
|
// absent on iOS Safari; present but rejecting ("UnknownError") in the Android WebView — touch input never needs it,
|
|
336
|
-
// and an unhandled rejection would raise the uncaught-exception modal on ENTER WORLD
|
|
337
|
-
|
|
341
|
+
// and an unhandled rejection would raise the uncaught-exception modal on ENTER WORLD. Never asked for in touch play:
|
|
342
|
+
// Chrome on Android grants it, then sends every touch to the canvas (stick, Jump and Look go dead and their
|
|
343
|
+
// setPointerCapture throws, WILDSHARD-GAME-2M), and Chrome 145 can crash the whole app in requestPointerLock
|
|
344
|
+
// (QA-FEEDBACK-2026-11-13 row 6).
|
|
345
|
+
lock(): void { if (!touchPlay() && 'requestPointerLock' in this.canvas) this.canvas.requestPointerLock().catch(() => { /* refused: the pause menu takes over */ }); }
|
|
338
346
|
|
|
339
347
|
/** step on / off the hoverboard. Off: the board fades and gravity lands you; on: the spring lifts you to ride height. */
|
|
340
348
|
setHover(on: boolean): void {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { mountUi } from '../ui/ownership';
|
|
2
2
|
import { mountBoostLook } from '../ui/hoverBoost';
|
|
3
3
|
import { app } from '../app/runtime';
|
|
4
|
-
import { listenDom } from '../input/dom';
|
|
4
|
+
import { capturePointer, listenDom, listenPage } from '../input/dom';
|
|
5
5
|
import type { Action, TouchStack, TouchVerbSpec } from '../input/InputService';
|
|
6
6
|
import { engineString } from '../../../shared/engine/strings';
|
|
7
7
|
/**
|
|
@@ -123,6 +123,8 @@ export class TouchControls {
|
|
|
123
123
|
private readonly scope = (app.levelScope ?? app.engineScope).child('touch');
|
|
124
124
|
readonly active: boolean;
|
|
125
125
|
private stickPointer = -1; private lookPointer = -1; private attackPointer = -1;
|
|
126
|
+
/** fingers the stick, look or attack hold whose capture the browser refused (capturePointer): released from the window too */
|
|
127
|
+
private readonly uncaptured = new Set<number>();
|
|
126
128
|
private stickBase = { x: 0, y: 0 };
|
|
127
129
|
private lookLast = { x: 0, y: 0 };
|
|
128
130
|
private attackLast = { x: 0, y: 0 }; private attackPath = 0; private attackT0 = 0; // the ATTACK touch: last spot, px travelled, start time
|
|
@@ -299,7 +301,7 @@ export class TouchControls {
|
|
|
299
301
|
this.flick.begin(e.clientX, e.clientY, this.lookT0);
|
|
300
302
|
lookpad.classList.toggle('active', inBar);
|
|
301
303
|
} else return;
|
|
302
|
-
root.
|
|
304
|
+
if (!capturePointer(root, e.pointerId)) this.uncaptured.add(e.pointerId);
|
|
303
305
|
e.preventDefault();
|
|
304
306
|
});
|
|
305
307
|
listenDom(this.scope, root, 'pointermove', (e) => {
|
|
@@ -348,6 +350,12 @@ export class TouchControls {
|
|
|
348
350
|
};
|
|
349
351
|
listenDom(this.scope, root, 'pointerup', release);
|
|
350
352
|
listenDom(this.scope, root, 'pointercancel', release);
|
|
353
|
+
// WILDSHARD-GAME-2M (QA 2026-11-13 row 6): Android Chrome can refuse a capture (the touch already handed to the browser).
|
|
354
|
+
// That finger's lift can then land outside the layer, and the stick, look or attack stayed held: the next touch on it
|
|
355
|
+
// was ignored ("couldn't control anything"). An uncaptured finger is released from the window as well.
|
|
356
|
+
for (const type of ['pointerup', 'pointercancel'] as const) {
|
|
357
|
+
listenPage(this.scope, type, (e) => { if (this.uncaptured.delete(e.pointerId)) release(e); }, { capture: true });
|
|
358
|
+
}
|
|
351
359
|
|
|
352
360
|
// ── ATTACK / FIRE: fires on touch-down; the disc then captures the touch (its move / up events bubble to the layer's
|
|
353
361
|
// handlers above), so a drag from it turns the camera while the finger is held and a still hold (melee) becomes the
|
|
@@ -359,7 +367,7 @@ export class TouchControls {
|
|
|
359
367
|
if (this.attackPointer >= 0) return; // one finger on the disc at a time
|
|
360
368
|
this.attackPointer = e.pointerId;
|
|
361
369
|
this.attackLast = { x: e.clientX, y: e.clientY }; this.attackPath = 0; this.attackT0 = performance.now();
|
|
362
|
-
attack.
|
|
370
|
+
if (!capturePointer(attack, e.pointerId)) this.uncaptured.add(e.pointerId);
|
|
363
371
|
attack.classList.add('down');
|
|
364
372
|
if (!this.weapons.enabled) return;
|
|
365
373
|
this.weapons.tryFire(); // the bow: only the dry click on an empty quiver — its draw is the hold
|
|
@@ -458,7 +466,7 @@ export class TouchControls {
|
|
|
458
466
|
const own = button; root.append(own); this.verbs.set(slot, own);
|
|
459
467
|
const pointers = new Set<number>();
|
|
460
468
|
listenDom(this.scope, own, 'pointerdown', (event) => {
|
|
461
|
-
event.preventDefault(); event.stopPropagation(); pointers.add(event.pointerId); own
|
|
469
|
+
event.preventDefault(); event.stopPropagation(); pointers.add(event.pointerId); capturePointer(own, event.pointerId);
|
|
462
470
|
const current = this.verbActions[slot]; if (current === undefined || pointers.size !== 1) return;
|
|
463
471
|
const live = this.verbSpecs[slot];
|
|
464
472
|
if (live?.hold === true) { this.heldVerbs.set(slot, current); app.input.setHeld(current, true); } else app.input.press(current);
|
|
@@ -8,7 +8,13 @@ const ASSETS = '__ASSET_CACHE__';
|
|
|
8
8
|
const BOOKS = 'ws-builds-v1';
|
|
9
9
|
const SHELL_PREFIX = 'ws-shell-v3-';
|
|
10
10
|
const SHELL = `${SHELL_PREFIX}${BUILD}`;
|
|
11
|
+
/** OFFLINE OF5 (J298): a world build (its document stamped with `__WS_WORLD__`; play, staging) never runs the in-page solo
|
|
12
|
+
* server, so it never precaches the solo server's code or its server book. Read at run time: a deploy stamps the document. */
|
|
13
|
+
const WORLD = /\bglobalThis\.__WS_WORLD__=/u.test(DOCUMENT);
|
|
14
|
+
const SOLO_ONLY = /\/standalone\/(?:serverWorker|serverRuntime)-[^/]+\.js$|\/assets\/spawn\/server-[^/]+\.json$/u;
|
|
11
15
|
const FILES = JSON.parse('__FILES__');
|
|
16
|
+
/** What this build precaches and records as its generation: its files, less the solo server's on a world build. */
|
|
17
|
+
const PRECACHE_FILES = FILES.filter(path => !WORLD || !SOLO_ONLY.test(path));
|
|
12
18
|
const SHELL_FILES = JSON.parse('__SHELL_FILES__');
|
|
13
19
|
const NAMED = new Set(FILES);
|
|
14
20
|
const MATCH = { ignoreVary: true };
|
|
@@ -16,8 +22,11 @@ const abs = path => new URL(path, self.registration.scope).href;
|
|
|
16
22
|
const bookKey = build => abs(`/__ws_build__/${encodeURIComponent(build)}`);
|
|
17
23
|
const CONTENT = /-[a-f0-9]{8,64}\.[a-z0-9]+$|\/[a-f0-9]{64}\.[a-z0-9]+$/;
|
|
18
24
|
const HASH = /\/([a-f0-9]{64})\.[a-z0-9]+$/;
|
|
25
|
+
/** OF5: a spawn manifest's code list (`code/<sha16>.json`) is named by its own bytes too, so it is kept across builds: an
|
|
26
|
+
* update's first offline launch still reads the route's code list. */
|
|
27
|
+
const OWN_NAMED = /^\/assets\/spawn\/code\/[a-f0-9]{16}\.json$/;
|
|
19
28
|
/** @param {URL} url */
|
|
20
|
-
const immutable = url => NAMED.has(url.pathname) || url.pathname.startsWith('/b/') || CONTENT.test(url.pathname)
|
|
29
|
+
const immutable = url => NAMED.has(url.pathname) || url.pathname.startsWith('/b/') || CONTENT.test(url.pathname) || OWN_NAMED.test(url.pathname)
|
|
21
30
|
|| /^[a-f0-9]{8,64}$/.test(url.searchParams.get('v') ?? '');
|
|
22
31
|
const isHtml = response => /\btext\/html\b/i.test(response.headers.get('content-type') ?? '');
|
|
23
32
|
/* PAGE-SIZE PZ10 (J276): content on the content base (`https://packs.wildshard.io/content/<set>/`, baked from the boot
|
|
@@ -26,6 +35,8 @@ const isHtml = response => /\btext\/html\b/i.test(response.headers.get('content-
|
|
|
26
35
|
* kept: an opaque body cannot be checked and is padded against quota, and a range never stands for the whole file. */
|
|
27
36
|
/** @type {{ base: string, files: string[] }} one parsed value: the bundler would fold a literal base into its origin */
|
|
28
37
|
const { base: CONTENT_BASE, files: CONTENT_FILES } = JSON.parse('__CONTENT__');
|
|
38
|
+
/** OF5: the server book on the content base is solo-only too (a URL there, its path under the base's folder). */
|
|
39
|
+
const CONTENT_PRECACHE = CONTENT_FILES.filter(href => !WORLD || !SOLO_ONLY.test(new URL(href).pathname));
|
|
29
40
|
const CONTENT_CACHE = 'ws-content-v1';
|
|
30
41
|
const CONTENT_URL = CONTENT_BASE === '' ? undefined : new URL(CONTENT_BASE);
|
|
31
42
|
/** A base on the page's own origin (contentBase.ts allows one) owns its folder only; the rest of the origin is the page's. */
|
|
@@ -129,15 +140,24 @@ const inflight = new Set(), controlled = new Set(), loading = new Set(), nonLoad
|
|
|
129
140
|
const isDoctorDocument = url => url.origin === self.location.origin
|
|
130
141
|
&& (url.pathname === '/doctor' || url.pathname === '/doctor/' || url.pathname === '/doctor/index.html'
|
|
131
142
|
|| (url.pathname === '/' || url.pathname === '/index.html') && url.searchParams.has('doctor'));
|
|
143
|
+
// OF6: only a page we can see loads. A client `clients.get` doesn't list (a dedicated worker some browsers don't) is not one.
|
|
132
144
|
function isNonLoadingClient(id) {
|
|
133
145
|
if (typeof self.clients?.get !== 'function') return Promise.resolve(false);
|
|
134
146
|
let known = nonLoadingClients.get(id);
|
|
135
|
-
if (known === undefined) {
|
|
136
|
-
|
|
147
|
+
if (known === undefined) {
|
|
148
|
+
known = self.clients.get(id).then(client => {
|
|
149
|
+
// unseen now may be a page a browser lists late: not kept, so its next read asks again
|
|
150
|
+
if (client === undefined) { nonLoadingClients.delete(id); return true; }
|
|
151
|
+
return client.type === 'worker' || client.type === 'sharedworker' || client.type === 'window' && isDoctorDocument(new URL(client.url));
|
|
152
|
+
}, () => false);
|
|
153
|
+
nonLoadingClients.set(id, known);
|
|
154
|
+
}
|
|
137
155
|
return known;
|
|
138
156
|
}
|
|
157
|
+
// OF6: a read with no client id (a worker's own script) is no loading page; a navigation pauses through its own branch. Before,
|
|
158
|
+
// such reads paused the precache and aborted its fetches on every read, so a page's workers held it paused while they read.
|
|
139
159
|
async function pauseForClient(id) {
|
|
140
|
-
if (typeof id
|
|
160
|
+
if (typeof id !== 'string' || id === '' || await isNonLoadingClient(id)) return;
|
|
141
161
|
pausePrecache(id);
|
|
142
162
|
}
|
|
143
163
|
function pausePrecache(client) {
|
|
@@ -203,15 +223,35 @@ function precacheGeneration() {
|
|
|
203
223
|
precaching ??= (async () => {
|
|
204
224
|
try {
|
|
205
225
|
const [assets, books] = await Promise.all([store(ASSETS), caches.open(BOOKS)]);
|
|
206
|
-
await precacheQueue(assets,
|
|
226
|
+
await precacheQueue(assets, PRECACHE_FILES);
|
|
207
227
|
// PZ10: this build's books on the content base; a build is a generation (and adoptable) only once they are held
|
|
208
|
-
if (
|
|
209
|
-
await books.put(bookKey(BUILD), Response.json({ files:
|
|
228
|
+
if (CONTENT_PRECACHE.length > 0) await precacheQueue(await store(CONTENT_CACHE), CONTENT_PRECACHE, true);
|
|
229
|
+
await books.put(bookKey(BUILD), Response.json({ files: PRECACHE_FILES.map(abs) }));
|
|
210
230
|
} catch (error) { precaching = undefined; throw error; }
|
|
211
231
|
})();
|
|
212
232
|
return precaching;
|
|
213
233
|
}
|
|
214
234
|
|
|
235
|
+
/** OFFLINE OF7 (PZ15): the build's network-first reads (`/programs/`, `/shardfiles/`) are kept in its shell, which activate
|
|
236
|
+
* deletes. Copy them into this build's shell first, so the first offline launch after an update still has them; a copy this
|
|
237
|
+
* shell holds wins, and the newest older shell wins over older ones. Online they are still read from the network first.
|
|
238
|
+
* Chosen over content-naming those files (OF7's other fix): this changes no URL, no cook and no reader. */
|
|
239
|
+
/** OF5: the deck's draft cards (`/drafts/`, named by their source art, not their bytes) are read the same way. */
|
|
240
|
+
const NETWORK_FIRST = /^\/(?:programs|shardfiles|drafts)\//;
|
|
241
|
+
async function carryNetworkFirst() {
|
|
242
|
+
const shell = await store(SHELL);
|
|
243
|
+
for (const name of (await caches.keys()).reverse()) {
|
|
244
|
+
if (name === SHELL || !name.startsWith(SHELL_PREFIX)) continue;
|
|
245
|
+
const old = await caches.open(name);
|
|
246
|
+
// in parallel within one shell (its keys are distinct): activate holds the first launch after an update
|
|
247
|
+
await Promise.all((await old.keys()).map(async request => {
|
|
248
|
+
if (!NETWORK_FIRST.test(new URL(request.url).pathname) || await shell.match(request, MATCH) !== undefined) return;
|
|
249
|
+
const response = await old.match(request, MATCH);
|
|
250
|
+
if (response !== undefined && !isHtml(response)) await shell.put(request, response);
|
|
251
|
+
}));
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
215
255
|
workerScope.listen(self, 'activate', event => {
|
|
216
256
|
event.waitUntil((async () => {
|
|
217
257
|
const books = await caches.open(BOOKS), current = bookKey(BUILD);
|
|
@@ -228,6 +268,7 @@ workerScope.listen(self, 'activate', event => {
|
|
|
228
268
|
if (record !== undefined) for (const file of (await record.json()).files) if (!kept.has(file)) await assets.delete(file);
|
|
229
269
|
await books.delete(key);
|
|
230
270
|
}
|
|
271
|
+
await carryNetworkFirst().catch(() => undefined);
|
|
231
272
|
for (const name of await caches.keys()) {
|
|
232
273
|
if (name === SHELL) continue;
|
|
233
274
|
if (name.startsWith('ws-shell-') || name.startsWith('ws-static-') || name === 'ws-immutable') await caches.delete(name);
|
|
@@ -372,7 +413,7 @@ workerScope.listen(self, 'fetch', event => {
|
|
|
372
413
|
}
|
|
373
414
|
if (/^\/(?:assets|basis|fonts)\//.test(url.pathname) || url.pathname === '/manifest.webmanifest') {
|
|
374
415
|
event.respondWith(cached(request, SHELL, event));
|
|
375
|
-
} else if (
|
|
416
|
+
} else if (NETWORK_FIRST.test(url.pathname)) event.respondWith(networkFirst(request, SHELL, event));
|
|
376
417
|
});
|
|
377
418
|
|
|
378
419
|
workerScope.listen(self, 'message', event => {
|
|
@@ -384,11 +425,18 @@ workerScope.listen(self, 'message', event => {
|
|
|
384
425
|
// Adoption waits on this reply: a build is offered as the next document's worker only once its code is held.
|
|
385
426
|
// A page asks once it reaches control, so it no longer counts as loading, and the precache resumes.
|
|
386
427
|
const port = event.ports?.[0], client = event.source?.id;
|
|
387
|
-
|
|
388
|
-
|
|
428
|
+
// OF5a: a title asks too (`update`), so a build update seen only on the title holds its code before the first offline
|
|
429
|
+
// launch. Only on a device that holds another build's generation: a first visit's title still reads nothing (S2, DL1),
|
|
430
|
+
// and a title that is turned down neither counts as a page past loading nor resumes another page's pause.
|
|
431
|
+
const update = event.data?.update === true;
|
|
432
|
+
const settle = () => { if (typeof client === 'string') controlled.add(client); resumePrecache(); };
|
|
433
|
+
if (!update) settle();
|
|
389
434
|
event.waitUntil((async () => {
|
|
390
435
|
let ok = true;
|
|
391
|
-
try {
|
|
436
|
+
try {
|
|
437
|
+
if (update && (await (await caches.open(BOOKS)).keys()).every(key => key.url === bookKey(BUILD))) ok = false;
|
|
438
|
+
else { if (update) settle(); await precacheGeneration(); }
|
|
439
|
+
} catch { ok = false; }
|
|
392
440
|
port?.postMessage({ type, ok, build: BUILD });
|
|
393
441
|
})());
|
|
394
442
|
return;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QA-FEEDBACK-2026-11-13 row 6 (Jake's friend, Android Chrome, staging v0.1.16): the game joined and played, the HUD and
|
|
3
|
+
* the minimap drew, but the world was the page's own background, and nothing reached Sentry. The world draws through
|
|
4
|
+
* the composer's half-float targets (RGBA16F); WebGL2 can only draw into those where the GPU offers
|
|
5
|
+
* EXT_color_buffer_float or EXT_color_buffer_half_float. Without either the targets are incomplete framebuffers: every
|
|
6
|
+
* draw into them is dropped without a throw, and the screen pass copies their empty (transparent) texels to the canvas.
|
|
7
|
+
*
|
|
8
|
+
* So the engine's HDR targets take `hdrTargetType`: half float where the GPU can draw into it, else 8-bit (the same
|
|
9
|
+
* passes, less headroom for bloom), and `DrawCheck` makes a world that still draws nothing loud: twice after the first
|
|
10
|
+
* frames, in the same task as the draw (the drawing buffer is not preserved), it reads the composer's input framebuffer
|
|
11
|
+
* status and a 3×3 grid of the canvas. An incomplete target, or a canvas that stayed fully transparent at both checks,
|
|
12
|
+
* is reported once as a fault (Sentry, and the error card) naming the GPU and what it lacks.
|
|
13
|
+
*/
|
|
14
|
+
import * as THREE from 'three';
|
|
15
|
+
import type { Renderer } from './renderer';
|
|
16
|
+
|
|
17
|
+
/** whether this renderer's GPU can draw into half-float colour targets (asking also enables the extension) */
|
|
18
|
+
export function halfFloatTargets(renderer: Pick<Renderer, 'extensions'>): boolean {
|
|
19
|
+
return renderer.extensions.has('EXT_color_buffer_float') || renderer.extensions.has('EXT_color_buffer_half_float');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** the type of the engine's HDR targets (the composer; volumetrics through fitHdrTarget): half float where it can be drawn into, else
|
|
23
|
+
* 8-bit. Not yet: keyedSky's environment equirect (game layer) and staticCapture, which stay half float (a darker world, not a black one). */
|
|
24
|
+
export function hdrTargetType(renderer: Pick<Renderer, 'extensions'>): THREE.TextureDataType {
|
|
25
|
+
return halfFloatTargets(renderer) ? THREE.HalfFloatType : THREE.UnsignedByteType;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** A half-float target made before the renderer was known, retyped to 8-bit (and reallocated) where the GPU cannot draw into half float. */
|
|
29
|
+
export function fitHdrTarget(renderer: Pick<Renderer, 'extensions'>, target: THREE.WebGLRenderTarget): void {
|
|
30
|
+
if (target.texture.type !== THREE.HalfFloatType || halfFloatTargets(renderer)) return;
|
|
31
|
+
target.texture.type = THREE.UnsignedByteType; target.dispose();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** what a draw report names about the GPU: its model (no player identifier), and the limits a phone GPU runs short of */
|
|
35
|
+
export function gpuSummary(gl: WebGLRenderingContext | WebGL2RenderingContext): string {
|
|
36
|
+
const info = gl.getExtension('WEBGL_debug_renderer_info');
|
|
37
|
+
const name = String(info === null ? gl.getParameter(gl.RENDERER) : gl.getParameter(info.UNMASKED_RENDERER_WEBGL));
|
|
38
|
+
const has = (ext: string): string => (gl.getSupportedExtensions() ?? []).includes(ext) ? 'yes' : 'no';
|
|
39
|
+
const n = (p: number): string => String(gl.getParameter(p));
|
|
40
|
+
return `GPU ${name} · color_buffer_float ${has('EXT_color_buffer_float')} · color_buffer_half_float ${has('EXT_color_buffer_half_float')}`
|
|
41
|
+
+ ` · frag uniforms ${n(gl.MAX_FRAGMENT_UNIFORM_VECTORS)} · varyings ${n(gl.MAX_VARYING_VECTORS)} · textures ${n(gl.MAX_TEXTURE_IMAGE_UNITS)}`
|
|
42
|
+
+ ` · max texture ${n(gl.MAX_TEXTURE_SIZE)}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** true when every sample of a 3×3 grid of the bound framebuffer is fully transparent (nothing drawn: the page shows through) */
|
|
46
|
+
export function blankFramebuffer(gl: Pick<WebGLRenderingContext, 'readPixels' | 'RGBA' | 'UNSIGNED_BYTE' | 'drawingBufferWidth' | 'drawingBufferHeight'>): boolean {
|
|
47
|
+
const px = new Uint8Array(4), w = gl.drawingBufferWidth, h = gl.drawingBufferHeight;
|
|
48
|
+
for (const fx of [0.2, 0.5, 0.8]) for (const fy of [0.2, 0.5, 0.8]) {
|
|
49
|
+
gl.readPixels(Math.floor(w * fx), Math.floor(h * fy), 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, px);
|
|
50
|
+
if (px[3] !== 0) return false;
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** the frames (counted from the loop's start) a draw check runs on */
|
|
56
|
+
export const DRAW_CHECK_FRAMES: readonly number[] = [60, 300];
|
|
57
|
+
|
|
58
|
+
export interface DrawCheckHost {
|
|
59
|
+
renderer: { getContext: () => WebGLRenderingContext | WebGL2RenderingContext; getRenderTarget: () => THREE.WebGLRenderTarget | null; setRenderTarget: (target: THREE.WebGLRenderTarget | null) => void };
|
|
60
|
+
/** the composer's input buffer (where the world draws), null before the composer exists */
|
|
61
|
+
target: () => THREE.WebGLRenderTarget | null;
|
|
62
|
+
/** `certain`: the target is incomplete (nothing can draw); otherwise the canvas only read transparent twice */
|
|
63
|
+
report: (error: Error, certain: boolean) => void;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The world's draw check: `afterDraw(frame)` right after each loop draw, in the same task. Reports at most once. */
|
|
67
|
+
export class DrawCheck {
|
|
68
|
+
private blank = 0;
|
|
69
|
+
private done = false;
|
|
70
|
+
private readonly host: DrawCheckHost;
|
|
71
|
+
constructor(host: DrawCheckHost) { this.host = host; }
|
|
72
|
+
|
|
73
|
+
afterDraw(frame: number): void {
|
|
74
|
+
if (this.done || !DRAW_CHECK_FRAMES.includes(frame)) return;
|
|
75
|
+
const { renderer } = this.host, gl = renderer.getContext();
|
|
76
|
+
if (gl.isContextLost()) return; // GpuRecovery owns a lost context
|
|
77
|
+
const prev = renderer.getRenderTarget();
|
|
78
|
+
let why = '', certain = false;
|
|
79
|
+
try {
|
|
80
|
+
const target = this.host.target();
|
|
81
|
+
if (target !== null) {
|
|
82
|
+
renderer.setRenderTarget(target);
|
|
83
|
+
const status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
|
|
84
|
+
if (status !== gl.FRAMEBUFFER_COMPLETE) { certain = true; why = `the world's target is incomplete (status 0x${status.toString(16)})`; }
|
|
85
|
+
}
|
|
86
|
+
renderer.setRenderTarget(null);
|
|
87
|
+
if (why === '' && blankFramebuffer(gl) && ++this.blank === DRAW_CHECK_FRAMES.length) why = `the canvas stayed transparent at frames ${DRAW_CHECK_FRAMES.join(' and ')}`;
|
|
88
|
+
} catch { return; } finally { renderer.setRenderTarget(prev); }
|
|
89
|
+
if (why === '' && frame !== DRAW_CHECK_FRAMES.at(-1)) return;
|
|
90
|
+
this.done = true;
|
|
91
|
+
if (why === '') return;
|
|
92
|
+
let gpu = '';
|
|
93
|
+
try { gpu = gpuSummary(gl); } catch { gpu = 'GPU unknown'; }
|
|
94
|
+
this.host.report(new Error(`World drew nothing: ${why} · ${gpu}`), certain);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -158,9 +158,13 @@ function* exteriorJobSteps(scene: THREE.Scene, rt: THREE.WebGLRenderTarget | nul
|
|
|
158
158
|
const target = createCompileScene(scene);
|
|
159
159
|
const lights = new CompileLights();
|
|
160
160
|
// the road draws with the page's own environment (a layer swaps a cell's in only while it renders, `BackdropLayer.apply`):
|
|
161
|
-
//
|
|
162
|
-
//
|
|
163
|
-
|
|
161
|
+
// the declared one keys the exterior variant, and the live one (a cell's PMREM, swapped in by its layer at half weight, so
|
|
162
|
+
// drawn on the road beside the cell; G639: Driftwood's road programs linked on the first road frame without it) one more
|
|
163
|
+
// below. RP4: keyed with the live PMREM alone, between frames inside a cell, a grid page (declared none) had no variant
|
|
164
|
+
// for the road past the layer's half weight, and every program of the cell linked again 2 m before its edge (Driftwood's
|
|
165
|
+
// west edge: about 17 links in one frame, 2.5 to 4.3 s in Chromium)
|
|
166
|
+
target.fog = scene.fog; target.environment = state.environment;
|
|
167
|
+
const live = scene.environment;
|
|
164
168
|
const pending: THREE.Object3D[] = [scene];
|
|
165
169
|
while (pending.length > 0) {
|
|
166
170
|
const object = pending.pop();
|
|
@@ -183,17 +187,19 @@ function* exteriorJobSteps(scene: THREE.Scene, rt: THREE.WebGLRenderTarget | nul
|
|
|
183
187
|
: exterior;
|
|
184
188
|
// Passes with their own scene keep their authored state. Only the page world/depth variants transition outside.
|
|
185
189
|
for (const job of jobs) if (job.target === scene) { job.target = target; job.lights = lights; }
|
|
186
|
-
//
|
|
187
|
-
// height
|
|
188
|
-
//
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
190
|
+
// Also the variant for every other environment the road may draw with, one per cube height (three keys a program by the
|
|
191
|
+
// PMREM's height, and by none): the live one, and for a view root's warm-up (`roots`) every one the page recorded (a
|
|
192
|
+
// cell's layer swaps its PMREM in by weight; G639: Driftwood's, Nalati's and Pine's ring and road views linked their
|
|
193
|
+
// 256 / 512 / 1024 variants on the first road frame beside each, 150-270 ms each with a cold shader cache)
|
|
194
|
+
const height = (t: THREE.Texture | null): unknown => (t === null ? null : Reflect.get(t.image ?? {}, 'height'));
|
|
195
|
+
const keyed = new Set<unknown>([height(target.environment)]);
|
|
196
|
+
for (const environment of [...live === null ? [] : [live], ...roots === undefined ? [] : pageEnvironments()]) {
|
|
197
|
+
if (keyed.has(height(environment))) continue;
|
|
198
|
+
keyed.add(height(environment));
|
|
199
|
+
const lit = [...(yield* sceneJobSteps(scene, rt, roots === undefined ? per : 1, roots ?? [scene], state.roots, undefined, from)).jobs,
|
|
200
|
+
...roots === undefined ? familyCompileJobs(scene, rt, per, excludedMaterials) : []];
|
|
201
|
+
for (const job of lit) if (job.target === scene) { job.target = target; job.lights = lights; job.environment = environment; }
|
|
202
|
+
jobs.push(...lit);
|
|
197
203
|
}
|
|
198
204
|
return jobs;
|
|
199
205
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* STALE-BUILD SB6: index.html's `data-stale-build` script runs before any module, so it has no save service; when it stops a
|
|
3
|
+
* stale build and sends the player to update, it leaves its note in localStorage `ws-stale-build` (build, built-at, the server's
|
|
4
|
+
* build, tries, when). The next build that boots takes the note here, once: read, then removed. Its report then waits in the
|
|
5
|
+
* device's screen outbox (`screen.reports`, telemetry/browserErrors.ts) until Sentry acknowledges it.
|
|
6
|
+
*/
|
|
7
|
+
export interface StaleBuildNote {
|
|
8
|
+
readonly build: string;
|
|
9
|
+
/** the stale build's own stamp (ms) */
|
|
10
|
+
readonly at: number;
|
|
11
|
+
/** the build the server named, '' when it named none */
|
|
12
|
+
readonly server: string;
|
|
13
|
+
readonly tries: number;
|
|
14
|
+
/** when the stale screen last wrote the note (ms) */
|
|
15
|
+
readonly seen: number;
|
|
16
|
+
}
|
|
17
|
+
export const STALE_BUILD_NOTE_KEY = 'ws-stale-build';
|
|
18
|
+
|
|
19
|
+
/** a time a Date can hold (ms); anything else is not the inline script's */
|
|
20
|
+
const time = (value: unknown): value is number => typeof value === 'number' && Number.isFinite(value) && Math.abs(value) <= 8.64e15;
|
|
21
|
+
|
|
22
|
+
/** The note as the inline script wrote it, or null for anything else. */
|
|
23
|
+
export function parseStaleBuildNote(raw: string | null): StaleBuildNote | null {
|
|
24
|
+
if (raw === null) return null;
|
|
25
|
+
let value: unknown;
|
|
26
|
+
try { value = JSON.parse(raw); } catch { return null; }
|
|
27
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) return null;
|
|
28
|
+
const { build, at, server, tries, seen } = value as Record<string, unknown>;
|
|
29
|
+
if (typeof build !== 'string' || typeof server !== 'string' || typeof tries !== 'number' || !time(at) || !time(seen)) return null;
|
|
30
|
+
return { build: build.slice(0, 200), at, server: server.slice(0, 200), tries, seen };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type NoteStore = Pick<Storage, 'getItem' | 'removeItem'>;
|
|
34
|
+
function pageStore(): NoteStore | null {
|
|
35
|
+
try { return typeof localStorage === 'undefined' ? null : localStorage; } catch { return null; }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Take the note once: it is removed as it is read, and a malformed one is dropped too. Null when there is none. */
|
|
39
|
+
export function takeStaleBuildNote(store: NoteStore | null = pageStore()): StaleBuildNote | null {
|
|
40
|
+
if (store === null) return null;
|
|
41
|
+
let raw: string | null = null;
|
|
42
|
+
try { raw = store.getItem(STALE_BUILD_NOTE_KEY); } catch { return null; }
|
|
43
|
+
if (raw === null) return null;
|
|
44
|
+
try { store.removeItem(STALE_BUILD_NOTE_KEY); } catch { return null; } // a note that can't be removed would report on every boot
|
|
45
|
+
return parseStaleBuildNote(raw);
|
|
46
|
+
}
|