castle-web-cli 0.4.238 → 0.4.240
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/dist/agent.js +5 -1
- package/dist/api.d.ts +20 -0
- package/dist/api.js +57 -0
- package/dist/bundle.d.ts +38 -1
- package/dist/bundle.js +309 -13
- package/dist/castle-host/host.js +218 -11
- package/dist/castleJson.d.ts +10 -0
- package/dist/castleJson.js +46 -2
- package/dist/check.js +5 -2
- package/dist/devSessionServer.js +4 -1
- package/dist/devSessionStorage.d.ts +1 -0
- package/dist/devSessionStorage.js +32 -7
- package/dist/importOrder.d.ts +2 -0
- package/dist/importOrder.js +29 -0
- package/dist/index.js +22 -3
- package/dist/init.js +24 -2
- package/dist/multiplayerDoc.d.ts +1 -1
- package/dist/multiplayerDoc.js +9 -0
- package/dist/platformDoc.js +4 -2
- package/dist/playPagePolicy.d.ts +1 -0
- package/dist/playPagePolicy.js +12 -3
- package/dist/resetLeaderboards.d.ts +8 -1
- package/dist/resetLeaderboards.js +43 -8
- package/dist/roomLogs.d.ts +39 -0
- package/dist/roomLogs.js +166 -0
- package/dist/save-deck.d.ts +32 -2
- package/dist/save-deck.js +240 -39
- package/kits/base/CLAUDE.md +2 -1
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +240 -8
- package/kits/base/sdk/analytics.d.ts +8 -0
- package/kits/base/sdk/analytics.js +92 -0
- package/kits/base/sdk/castle.d.ts +8 -2
- package/kits/base/sdk/castle.js +3 -0
- package/kits/base/sdk/commands.d.ts +79 -0
- package/kits/base/sdk/commands.js +1 -0
- package/kits/base/sdk/debugConsole.d.ts +17 -0
- package/kits/base/sdk/debugConsole.js +154 -0
- package/kits/base/sdk/experiments.js +24 -1
- package/kits/base/sdk/hostRetry.d.ts +7 -0
- package/kits/base/sdk/hostRetry.js +57 -0
- package/kits/base/sdk/hub.d.ts +20 -2
- package/kits/base/sdk/hub.js +99 -13
- package/kits/base/sdk/multiplayer.d.ts +2 -0
- package/kits/base/sdk/multiplayer.js +198 -26
- package/kits/base/sdk/reconnectBudget.d.ts +6 -0
- package/kits/base/sdk/reconnectBudget.js +41 -1
- package/kits/base/sdk/rooms.d.ts +11 -0
- package/kits/base/sdk/rooms.js +22 -0
- package/kits/base/sdk/runtime.js +36 -19
- package/kits/base/sdk/server/hub.d.ts +19 -0
- package/kits/base/sdk/server/hub.js +12 -0
- package/kits/base/sdk/server/platformHandle.d.ts +1 -0
- package/kits/base/sdk/server/wrapper.d.ts +1 -1
- package/kits/base/sdk/server/wrapper.js +26 -1
- package/kits/base/sdk/store.d.ts +8 -2
- package/kits/base/sdk/store.js +5 -1
- package/kits/base/sdk/transport.d.ts +2 -1
- package/kits/base/sdk/transport.js +35 -0
- package/kits/hub-game/CLAUDE.md +66 -19
- package/kits/hub-game/castle.json +4 -4
- package/kits/hub-game/code/client/act.js +9 -6
- package/kits/hub-game/code/client/actCore.js +26 -6
- package/kits/hub-game/code/client/actGateLog.js +36 -0
- package/kits/hub-game/code/client/actionOverflow.js +29 -8
- package/kits/hub-game/code/client/actionRailSurface.js +186 -0
- package/kits/hub-game/code/client/actionRailTree.js +173 -0
- package/kits/hub-game/code/client/askSurface.js +85 -0
- package/kits/hub-game/code/client/askTree.js +51 -0
- package/kits/hub-game/code/client/attention.js +31 -6
- package/kits/hub-game/code/client/ballot.js +42 -5
- package/kits/hub-game/code/client/ballotSurface.js +115 -0
- package/kits/hub-game/code/client/ballotTree.js +180 -0
- package/kits/hub-game/code/client/catchingUp.js +19 -0
- package/kits/hub-game/code/client/celebrate.js +66 -0
- package/kits/hub-game/code/client/chrome.js +474 -53
- package/kits/hub-game/code/client/companion.js +93 -23
- package/kits/hub-game/code/client/companionDress.js +1 -1
- package/kits/hub-game/code/client/cornerSurface.js +106 -0
- package/kits/hub-game/code/client/cornerTree.js +83 -0
- package/kits/hub-game/code/client/decor.js +20 -11
- package/kits/hub-game/code/client/deviceStorage.js +121 -0
- package/kits/hub-game/code/client/disguise.js +23 -0
- package/kits/hub-game/code/client/disguiseDraw.js +87 -0
- package/kits/hub-game/code/client/dockSurface.js +206 -0
- package/kits/hub-game/code/client/dockTree.js +232 -0
- package/kits/hub-game/code/client/earned.js +29 -0
- package/kits/hub-game/code/client/emoteSurface.js +188 -0
- package/kits/hub-game/code/client/emoteTree.js +264 -0
- package/kits/hub-game/code/client/farAvatars.js +4 -3
- package/kits/hub-game/code/client/fpsTelemetry.js +3 -1
- package/kits/hub-game/code/client/grab.js +121 -50
- package/kits/hub-game/code/client/holdShow.js +19 -0
- package/kits/hub-game/code/client/hookLayer.js +96 -12
- package/kits/hub-game/code/client/hubControls.js +7 -1
- package/kits/hub-game/code/client/hudSurface.js +11 -3
- package/kits/hub-game/code/client/hudTree.js +7 -4
- package/kits/hub-game/code/client/idle.js +21 -3
- package/kits/hub-game/code/client/invites.js +24 -3
- package/kits/hub-game/code/client/keys.js +15 -0
- package/kits/hub-game/code/client/labelsNear.js +8 -1
- package/kits/hub-game/code/client/layoutCache.js +57 -8
- package/kits/hub-game/code/client/loadingCover.js +53 -4
- package/kits/hub-game/code/client/menuIcons.js +15 -0
- package/kits/hub-game/code/client/menuRows.js +8 -2
- package/kits/hub-game/code/client/menuSurface.js +102 -0
- package/kits/hub-game/code/client/menuTree.js +135 -0
- package/kits/hub-game/code/client/modelLook.js +41 -0
- package/kits/hub-game/code/client/pickerSurface.js +152 -0
- package/kits/hub-game/code/client/pickerTree.js +163 -0
- package/kits/hub-game/code/client/pushVisit.js +4 -2
- package/kits/hub-game/code/client/quality.js +188 -29
- package/kits/hub-game/code/client/qualityEntry.js +10 -1
- package/kits/hub-game/code/client/quickChatSurface.js +222 -0
- package/kits/hub-game/code/client/quickChatTree.js +201 -0
- package/kits/hub-game/code/client/rehello.js +75 -0
- package/kits/hub-game/code/client/renderVisibility.js +17 -0
- package/kits/hub-game/code/client/replay.js +118 -0
- package/kits/hub-game/code/client/role.js +3 -0
- package/kits/hub-game/code/client/safeLayout.js +441 -56
- package/kits/hub-game/code/client/safeStyle.js +13 -10
- package/kits/hub-game/code/client/say.js +2 -0
- package/kits/hub-game/code/client/soundSurface.js +77 -0
- package/kits/hub-game/code/client/soundTree.js +74 -0
- package/kits/hub-game/code/client/soundscape.js +12 -9
- package/kits/hub-game/code/client/soundscapeCues.js +1 -1
- package/kits/hub-game/code/client/state.js +67 -1
- package/kits/hub-game/code/client/stuckSurface.js +76 -0
- package/kits/hub-game/code/client/stuckTree.js +67 -0
- package/kits/hub-game/code/client/talk.js +42 -12
- package/kits/hub-game/code/client/talkTree.js +4 -2
- package/kits/hub-game/code/client/textAskSurface.js +147 -0
- package/kits/hub-game/code/client/textAskTree.js +67 -0
- package/kits/hub-game/code/client/tiers.js +252 -27
- package/kits/hub-game/code/client/together.js +4 -1
- package/kits/hub-game/code/client/uiDom.js +86 -8
- package/kits/hub-game/code/client/uiTree.js +33 -4
- package/kits/hub-game/code/client/vehicle.js +75 -52
- package/kits/hub-game/code/client/weakestTier.js +75 -31
- package/kits/hub-game/code/client/wear.js +159 -5
- package/kits/hub-game/code/client/worldLabels.js +215 -26
- package/kits/hub-game/code/companionSpec.js +4 -2
- package/kits/hub-game/code/server/act.js +3 -0
- package/kits/hub-game/code/server/actGate.js +83 -0
- package/kits/hub-game/code/server/actions.js +71 -15
- package/kits/hub-game/code/server/actors.js +20 -5
- package/kits/hub-game/code/server/analytics.js +40 -15
- package/kits/hub-game/code/server/ask.js +39 -3
- package/kits/hub-game/code/server/ballot.js +167 -4
- package/kits/hub-game/code/server/celebrate.js +64 -0
- package/kits/hub-game/code/server/companion.js +17 -2
- package/kits/hub-game/code/server/decor.js +11 -2
- package/kits/hub-game/code/server/disguise.js +63 -0
- package/kits/hub-game/code/server/doorAnalytics.js +2 -5
- package/kits/hub-game/code/server/earned.js +6 -2
- package/kits/hub-game/code/server/friendBests.js +13 -4
- package/kits/hub-game/code/server/friendsAmong.js +67 -8
- package/kits/hub-game/code/server/grab.js +12 -2
- package/kits/hub-game/code/server/heldOffers.js +142 -0
- package/kits/hub-game/code/server/holdShow.js +98 -0
- package/kits/hub-game/code/server/hub.js +854 -45
- package/kits/hub-game/code/server/idle.js +110 -9
- package/kits/hub-game/code/server/index.js +9 -0
- package/kits/hub-game/code/server/labels.js +13 -3
- package/kits/hub-game/code/server/loadAbandon.js +2 -5
- package/kits/hub-game/code/server/manifest.js +94 -6
- package/kits/hub-game/code/server/menu.js +26 -3
- package/kits/hub-game/code/server/npcs.js +55 -9
- package/kits/hub-game/code/server/observe.js +67 -6
- package/kits/hub-game/code/server/players.js +8 -1
- package/kits/hub-game/code/server/replay.js +135 -0
- package/kits/hub-game/code/server/storageLimit.js +4 -1
- package/kits/hub-game/code/server/townDay.js +74 -0
- package/kits/hub-game/code/server/trackQueue.js +29 -0
- package/kits/hub-game/code/server/vehicle.js +3 -0
- package/kits/hub-game/code/server/vis.js +26 -4
- package/kits/hub-game/code/server/wallet.js +677 -0
- package/kits/hub-game/code/server/wear.js +13 -3
- package/kits/hub-game/code/server/writerLease.js +191 -0
- package/kits/hub-game/code/shared/act.js +1 -1
- package/kits/hub-game/code/shared/expression.js +6 -0
- package/kits/hub-game/code/shared/replay.js +37 -0
- package/kits/hub-game/code/systems/hub.js +437 -57
- package/kits/hub-game/docs/analytics.md +20 -3
- package/kits/hub-game/docs/contract.md +942 -99
- package/kits/hub-game/docs/home-pieces.md +5 -6
- package/kits/hub-game/docs/observed-progress.md +49 -1
- package/kits/hub-game/docs/vehicle-preset.md +23 -0
- package/kits/hub-game/index.html +1 -0
- package/kits/hub-game/models/hats/baker-cap.pxmodel +3 -3
- package/kits/hub-game/models/hats/bat-clip.pxmodel +3 -3
- package/kits/hub-game/models/hats/beekeeper.pxmodel +3 -3
- package/kits/hub-game/models/hats/cap.pxmodel +3 -3
- package/kits/hub-game/models/hats/captain.pxmodel +3 -3
- package/kits/hub-game/models/hats/chef-toque.pxmodel +3 -3
- package/kits/hub-game/models/hats/crooked-top.pxmodel +3 -3
- package/kits/hub-game/models/hats/delivery-cap.pxmodel +3 -3
- package/kits/hub-game/models/hats/fire-helmet.pxmodel +3 -3
- package/kits/hub-game/models/hats/flower-crown.pxmodel +3 -3
- package/kits/hub-game/models/hats/foam-crown.pxmodel +3 -3
- package/kits/hub-game/models/hats/hard-hat.pxmodel +3 -3
- package/kits/hub-game/models/hats/lantern.pxmodel +3 -3
- package/kits/hub-game/models/hats/laurel.pxmodel +3 -3
- package/kits/hub-game/models/hats/lighthouse.pxmodel +3 -3
- package/kits/hub-game/models/hats/nurse-cap.pxmodel +3 -3
- package/kits/hub-game/models/hats/police-cap.pxmodel +3 -3
- package/kits/hub-game/models/hats/sailor.pxmodel +3 -3
- package/kits/hub-game/models/hats/souwester.pxmodel +3 -3
- package/kits/hub-game/models/hats/straw.pxmodel +3 -3
- package/kits/hub-game/models/hats/sunflower.pxmodel +3 -3
- package/kits/hub-game/models/hats/sweatband.pxmodel +3 -3
- package/kits/hub-game/models/hats/teacher-beret.pxmodel +3 -3
- package/kits/hub-game/models/hats/witch.pxmodel +3 -3
- package/kits/hub-game/models/hold-show/daisy.pxmodel +231 -0
- package/kits/hub-game/models/hold-show/moonflower.pxmodel +171 -0
- package/kits/hub-game/models/hold-show/rose.pxmodel +191 -0
- package/kits/hub-game/models/hold-show/square/daisy.pxmodel +233 -0
- package/kits/hub-game/models/hold-show/square/moonflower.pxmodel +173 -0
- package/kits/hub-game/models/hold-show/square/rose.pxmodel +193 -0
- package/kits/hub-game/models/hold-show/square/sunflower.pxmodel +313 -0
- package/kits/hub-game/models/hold-show/square/tulip.pxmodel +133 -0
- package/kits/hub-game/models/hold-show/sunflower.pxmodel +311 -0
- package/kits/hub-game/models/hold-show/tulip.pxmodel +131 -0
- package/kits/hub-game/package-lock.json +3 -3
- package/kits/hub-game/package.json +4 -3
- package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +1 -0
- package/kits/hub-game/scripts/fixtures/hud-surface.json +12 -12
- package/kits/hub-game/scripts/fixtures/talk-surface.json +8 -8
- package/kits/hub-game/scripts/gen-hats.mjs +1 -1
- package/kits/hub-game/scripts/gen-hold-show.mjs +27 -0
- package/kits/hub-game/scripts/pack.mjs +89 -23
- package/kits/hub-game/scripts/test-act-client.mjs +5 -0
- package/kits/hub-game/scripts/test-act-core.mjs +32 -0
- package/kits/hub-game/scripts/test-act-gate.mjs +186 -0
- package/kits/hub-game/scripts/test-action-rail-crowded-dom.mjs +7 -1
- package/kits/hub-game/scripts/test-action-rail-default-dom.mjs +102 -0
- package/kits/hub-game/scripts/test-action-rail-never-silent-dom.mjs +50 -0
- package/kits/hub-game/scripts/test-action-rail-surface.mjs +368 -0
- package/kits/hub-game/scripts/test-action-rail-town-jobs-dom.mjs +118 -0
- package/kits/hub-game/scripts/test-actions-client.mjs +5 -3
- package/kits/hub-game/scripts/test-actions.mjs +24 -0
- package/kits/hub-game/scripts/test-actors.mjs +19 -0
- package/kits/hub-game/scripts/test-again-corner-dom.mjs +59 -0
- package/kits/hub-game/scripts/test-analytics.mjs +80 -1
- package/kits/hub-game/scripts/test-arrival-pose-server.mjs +25 -8
- package/kits/hub-game/scripts/test-ask-client.mjs +9 -0
- package/kits/hub-game/scripts/test-ask-surface.mjs +188 -0
- package/kits/hub-game/scripts/test-attention.mjs +43 -1
- package/kits/hub-game/scripts/test-ballot-sheet-dom.mjs +71 -0
- package/kits/hub-game/scripts/test-ballot-surface.mjs +276 -0
- package/kits/hub-game/scripts/test-ballot.mjs +420 -3
- package/kits/hub-game/scripts/test-ban-join.mjs +1 -1
- package/kits/hub-game/scripts/test-celebrate-client.mjs +62 -0
- package/kits/hub-game/scripts/test-celebrate.mjs +116 -0
- package/kits/hub-game/scripts/test-chat.mjs +73 -0
- package/kits/hub-game/scripts/test-companion-client.mjs +203 -21
- package/kits/hub-game/scripts/test-companion.mjs +110 -3
- package/kits/hub-game/scripts/test-control-layout-dom.mjs +57 -10
- package/kits/hub-game/scripts/test-corner-surface.mjs +268 -0
- package/kits/hub-game/scripts/test-decor-client.mjs +59 -3
- package/kits/hub-game/scripts/test-decor.mjs +27 -0
- package/kits/hub-game/scripts/test-device-class.mjs +4 -1
- package/kits/hub-game/scripts/test-disguise-client.mjs +281 -0
- package/kits/hub-game/scripts/test-disguise.mjs +176 -0
- package/kits/hub-game/scripts/test-dock-surface.mjs +404 -0
- package/kits/hub-game/scripts/test-door-analytics.mjs +1 -1
- package/kits/hub-game/scripts/test-door-stay-client.mjs +602 -0
- package/kits/hub-game/scripts/test-door-stay.mjs +613 -0
- package/kits/hub-game/scripts/test-earned-client.mjs +119 -0
- package/kits/hub-game/scripts/test-emote-surface.mjs +616 -0
- package/kits/hub-game/scripts/test-fps-telemetry.mjs +39 -4
- package/kits/hub-game/scripts/test-friend-bests.mjs +38 -12
- package/kits/hub-game/scripts/test-ghost-click-dom.mjs +75 -0
- package/kits/hub-game/scripts/test-grab-client.mjs +29 -2
- package/kits/hub-game/scripts/test-grab-orbit.mjs +260 -11
- package/kits/hub-game/scripts/test-grab.mjs +10 -1
- package/kits/hub-game/scripts/test-hats.mjs +28 -0
- package/kits/hub-game/scripts/test-held-offers.mjs +394 -0
- package/kits/hub-game/scripts/test-high-only.mjs +3 -3
- package/kits/hub-game/scripts/test-hold-show-client.mjs +175 -0
- package/kits/hub-game/scripts/test-hold-show.mjs +355 -0
- package/kits/hub-game/scripts/test-hub-controls.mjs +3 -1
- package/kits/hub-game/scripts/test-hub-idle.mjs +348 -0
- package/kits/hub-game/scripts/test-hub-leaving.mjs +21 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +147 -0
- package/kits/hub-game/scripts/test-hub-trip.mjs +260 -5
- package/kits/hub-game/scripts/test-hud-clear.mjs +83 -0
- package/kits/hub-game/scripts/test-hud-rate.mjs +2 -1
- package/kits/hub-game/scripts/test-idle.mjs +160 -0
- package/kits/hub-game/scripts/test-invites-client.mjs +53 -0
- package/kits/hub-game/scripts/test-labels.mjs +11 -0
- package/kits/hub-game/scripts/test-landscape-layout.mjs +20 -0
- package/kits/hub-game/scripts/test-load-abandon.mjs +2 -2
- package/kits/hub-game/scripts/test-loading-cover.mjs +67 -1
- package/kits/hub-game/scripts/test-manifest.mjs +27 -0
- package/kits/hub-game/scripts/test-menu-client.mjs +55 -6
- package/kits/hub-game/scripts/test-menu-surface.mjs +236 -0
- package/kits/hub-game/scripts/test-npcs.mjs +128 -0
- package/kits/hub-game/scripts/test-observed.mjs +171 -3
- package/kits/hub-game/scripts/test-pack.mjs +166 -0
- package/kits/hub-game/scripts/test-picker-surface.mjs +321 -0
- package/kits/hub-game/scripts/test-placeat-server.mjs +395 -0
- package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
- package/kits/hub-game/scripts/test-pointer-clear-dom.mjs +82 -0
- package/kits/hub-game/scripts/test-progress-reset.mjs +184 -6
- package/kits/hub-game/scripts/test-push-visit.mjs +9 -0
- package/kits/hub-game/scripts/test-quality.mjs +312 -9
- package/kits/hub-game/scripts/test-quick-chat-surface.mjs +511 -0
- package/kits/hub-game/scripts/test-rehello.mjs +237 -0
- package/kits/hub-game/scripts/test-rejoin-yaw.mjs +138 -0
- package/kits/hub-game/scripts/test-relations-among.mjs +13 -7
- package/kits/hub-game/scripts/test-relations-refresh.mjs +90 -2
- package/kits/hub-game/scripts/test-replay-client.mjs +110 -0
- package/kits/hub-game/scripts/test-replay.mjs +178 -0
- package/kits/hub-game/scripts/test-resume-held.mjs +13 -0
- package/kits/hub-game/scripts/test-resume-pose-server.mjs +43 -5
- package/kits/hub-game/scripts/test-resync.mjs +13 -0
- package/kits/hub-game/scripts/test-role-client.mjs +10 -3
- package/kits/hub-game/scripts/test-safe-act.mjs +233 -0
- package/kits/hub-game/scripts/test-safe-caption.mjs +364 -0
- package/kits/hub-game/scripts/test-safe-layout.mjs +79 -0
- package/kits/hub-game/scripts/test-safe-prompt.mjs +163 -0
- package/kits/hub-game/scripts/test-sound-surface.mjs +256 -0
- package/kits/hub-game/scripts/test-soundscape.mjs +85 -2
- package/kits/hub-game/scripts/test-stuck-surface.mjs +174 -0
- package/kits/hub-game/scripts/test-stuck.mjs +31 -0
- package/kits/hub-game/scripts/test-talk-surface.mjs +23 -6
- package/kits/hub-game/scripts/test-talk-walk-dom.mjs +123 -0
- package/kits/hub-game/scripts/test-text-ask-surface.mjs +273 -0
- package/kits/hub-game/scripts/test-tiers.mjs +453 -3
- package/kits/hub-game/scripts/test-toast-no-row-dom.mjs +71 -0
- package/kits/hub-game/scripts/test-together.mjs +11 -0
- package/kits/hub-game/scripts/test-town-day.mjs +90 -0
- package/kits/hub-game/scripts/test-track-queue.mjs +64 -0
- package/kits/hub-game/scripts/test-try-on.mjs +39 -0
- package/kits/hub-game/scripts/test-ui-dom-dom.mjs +49 -2
- package/kits/hub-game/scripts/test-ui-tree.mjs +28 -0
- package/kits/hub-game/scripts/test-vehicle-client.mjs +77 -1
- package/kits/hub-game/scripts/test-vis.mjs +145 -0
- package/kits/hub-game/scripts/test-wallet.mjs +650 -0
- package/kits/hub-game/scripts/test-weakest-tier.mjs +135 -1
- package/kits/hub-game/scripts/test-world-labels.mjs +380 -0
- package/kits/hub-game/scripts/test-writer-lease-server.mjs +234 -0
- package/kits/hub-game/scripts/test-writer-lease.mjs +281 -0
- package/kits/hub-game/scripts/writer-storage-fixture.mjs +37 -0
- package/kits/hub-game/tools/hubScene/export.mjs +6 -5
- package/kits/hub-game/tools/hubScene/hubdata.mjs +10 -0
- package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +48 -2
- package/kits/hub-game/tools/hubScene/validate-manifest.mjs +21 -3
- package/kits/multiplayer-3d/castle.json +5 -5
- package/kits/multiplayer-3d/code/client/resumeGate.js +49 -2
- package/kits/multiplayer-3d/code/server/ownership.js +25 -6
- package/kits/multiplayer-3d/code/server/world.js +19 -4
- package/kits/multiplayer-3d/code/systems/multiplayer.js +67 -11
- package/kits/multiplayer-3d/package-lock.json +1 -1
- package/kits/multiplayer-3d/package.json +2 -1
- package/kits/multiplayer-3d/scripts/test-ground-half.mjs +56 -0
- package/kits/multiplayer-3d/scripts/test-join-watchdog.mjs +54 -3
- package/kits/multiplayer-3d/scripts/test-owned-moves.mjs +190 -0
- package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +191 -5
- package/kits/multiplayer-3d/scripts/test-resync-reconnect.mjs +68 -0
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/scene.js +10 -2
- package/kits/physics-3d/CLAUDE.md +14 -0
- package/kits/physics-3d/behaviors/Player.jsx +39 -3
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/docs/engine-model-cache.md +109 -0
- package/kits/physics-3d/docs/engine-player.md +76 -0
- package/kits/physics-3d/docs/engine-skip-work.md +16 -0
- package/kits/physics-3d/docs/pxmodel-format.md +5 -1
- package/kits/physics-3d/engine3d/gait.js +16 -8
- package/kits/physics-3d/engine3d/groundsize.js +23 -0
- package/kits/physics-3d/engine3d/kithooks.js +50 -0
- package/kits/physics-3d/engine3d/look.js +110 -17
- package/kits/physics-3d/engine3d/lookbake.js +19 -1
- package/kits/physics-3d/engine3d/materialpresets.js +3 -2
- package/kits/physics-3d/engine3d/modelcache.js +280 -0
- package/kits/physics-3d/engine3d/modelcachedigest.js +37 -0
- package/kits/physics-3d/engine3d/modelcachegate.js +69 -0
- package/kits/physics-3d/engine3d/modelrefs.js +13 -0
- package/kits/physics-3d/engine3d/optimize.js +20 -9
- package/kits/physics-3d/engine3d/playerRun.js +26 -1
- package/kits/physics-3d/engine3d/pxmodel.js +7 -3
- package/kits/physics-3d/engine3d/templatecache.js +722 -0
- package/kits/physics-3d/engine3d/world3d.js +211 -17
- package/kits/physics-3d/package-lock.json +1 -1
- package/kits/physics-3d/package.json +2 -1
- package/kits/physics-3d/play/behaviors/Player.js +43 -3
- package/kits/physics-3d/scripts/render.mjs +56 -8
- package/kits/physics-3d/scripts/template-cache-fixtures.mjs +37 -0
- package/kits/physics-3d/scripts/template-cache-v1-bytes.json +49 -0
- package/kits/physics-3d/scripts/test-gait.mjs +53 -9
- package/kits/physics-3d/scripts/test-ground-half.mjs +120 -0
- package/kits/physics-3d/scripts/test-model-cache.mjs +600 -0
- package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1 -0
- package/kits/physics-3d/scripts/test-sleeping-models.mjs +384 -0
- package/kits/physics-3d/scripts/test-template-cache-minified.mjs +106 -0
- package/kits/physics-3d/scripts/test-template-cache.mjs +519 -0
- package/kits/physics-3d/scripts/test-wall-slide.mjs +272 -0
- package/kits/physics-3d/systems/physics3d.js +51 -2
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/client/connection.js +3 -0
- package/package.json +2 -2
- package/vendor/three/examples/jsm/libs/fflate.module.js +2672 -0
|
@@ -161,6 +161,57 @@ const before = legacy();
|
|
|
161
161
|
if (previous === undefined) {delete globalThis.getComputedStyle;} else {globalThis.getComputedStyle = previous;}
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
|
+
// A goal chip on the Act/Jump pair was moved only down out from under it,
|
|
165
|
+
// capped at the bottom edge, onto the chat button below (a landscape phone).
|
|
166
|
+
// A move that ends on a control takes a place clear of them; a move clear of
|
|
167
|
+
// the controls, and every other kind (the stuck chip here), is kept exactly.
|
|
168
|
+
{
|
|
169
|
+
const dom = fakeDom({ viewW: 844, viewH: 390 });
|
|
170
|
+
const root = document.createElement('div'); dom.body.append(root);
|
|
171
|
+
root.contains = (node) => { for (let p = node; p; p = p.parent) {if (p === root) {return true;}} return false; };
|
|
172
|
+
const box = (node, at) => {
|
|
173
|
+
node.at = at;
|
|
174
|
+
node.getBoundingClientRect = () => {
|
|
175
|
+
const [dx, dy] = (node.style.translate || '0 0').split(' ').map(Number.parseFloat);
|
|
176
|
+
const w = Math.min(node.at.w, Number.parseFloat(node.style.maxWidth) || Infinity);
|
|
177
|
+
const h = Math.min(node.at.h, Number.parseFloat(node.style.maxHeight) || Infinity);
|
|
178
|
+
return { ...rectangle({ x: node.at.x + dx, y: node.at.y + dy, w, h }), width: w, height: h };
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
const pair = document.createElement('div'), chat = document.createElement('button');
|
|
182
|
+
const goal = document.createElement('div'), stuck = document.createElement('div');
|
|
183
|
+
for (const node of [pair, chat, goal, stuck]) {root.append(node);}
|
|
184
|
+
box(pair, { x: 696, y: 286, w: 134, h: 48 }); box(chat, { x: 772, y: 338, w: 52, h: 46 });
|
|
185
|
+
box(goal, { x: 740, y: 300, w: 90, h: 18 }); box(stuck, { x: 740, y: 300, w: 90, h: 18 });
|
|
186
|
+
const previous = globalThis.getComputedStyle;
|
|
187
|
+
globalThis.getComputedStyle = (element) => ({ ...element.styles, paddingLeft: '0px', paddingRight: '0px', paddingTop: '0px', paddingBottom: '0px' });
|
|
188
|
+
try {
|
|
189
|
+
let entries = [{ id: 'act-pair', node: pair, kind: 'control' }, { id: 'quick-chat', node: chat, kind: 'control' },
|
|
190
|
+
{ id: 'pointer:goal:house', node: goal, kind: 'pointer', transient: true }];
|
|
191
|
+
const controller = makeSafeLayout({ root, entries: () => entries });
|
|
192
|
+
const at = (report, id) => rectangle(report.boxes.find((b) => b.id === id));
|
|
193
|
+
let report = controller.report();
|
|
194
|
+
const chip = at(report, 'pointer:goal:house');
|
|
195
|
+
assert(!overlaps(chip, at(report, 'act-pair')) && !overlaps(chip, at(report, 'quick-chat')), `the goal chip is on no control: ${JSON.stringify(chip)}`);
|
|
196
|
+
assert.equal(chip.bottom - chip.top, 18, 'whole');
|
|
197
|
+
// The stuck chip keeps the old rule (down, capped at the bottom, here onto chat).
|
|
198
|
+
entries = [entries[0], entries[1], { id: 'stuck', node: stuck, kind: 'pointer', transient: true }];
|
|
199
|
+
report = controller.report();
|
|
200
|
+
const old = safePlacement(rectangle(stuck.at), report.view, {}, [...reservedCorners(report.view).map(rectangle), at(report, 'act-pair'), at(report, 'quick-chat')]);
|
|
201
|
+
assert.deepEqual(report.boxes.find((b) => b.id === 'stuck'), { id: 'stuck', kind: 'pointer', ...old });
|
|
202
|
+
assert(overlaps(rectangle(old), at(report, 'quick-chat')), 'the old rule lands on chat');
|
|
203
|
+
// A goal chip whose push down is clear of every control keeps that place exactly.
|
|
204
|
+
chat.at = { x: 772, y: 20, w: 52, h: 46 };
|
|
205
|
+
entries = [entries[0], entries[1], { id: 'pointer:goal:house', node: goal, kind: 'pointer', transient: true }];
|
|
206
|
+
report = controller.report();
|
|
207
|
+
const kept = safePlacement(rectangle(goal.at), report.view, {}, [...reservedCorners(report.view).map(rectangle), at(report, 'quick-chat'), at(report, 'act-pair')]);
|
|
208
|
+
assert.deepEqual(report.boxes.find((b) => b.id === 'pointer:goal:house'), { id: 'pointer:goal:house', kind: 'pointer', ...kept });
|
|
209
|
+
assert.equal(kept.y, 340, 'pushed below the pair');
|
|
210
|
+
controller.dispose();
|
|
211
|
+
} finally {
|
|
212
|
+
if (previous === undefined) {delete globalThis.getComputedStyle;} else {globalThis.getComputedStyle = previous;}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
164
215
|
console.log('safe layout: insets, both host corners, clipping, overflow parity, no drift and dormant DOM passed');
|
|
165
216
|
|
|
166
217
|
{
|
|
@@ -223,6 +274,34 @@ console.log('safe layout/loading cover: hide invalidates before next engine fram
|
|
|
223
274
|
chrome.dispose();
|
|
224
275
|
}
|
|
225
276
|
|
|
277
|
+
// An inset that changes at an unchanged view size (an Android keyboard or nav
|
|
278
|
+
// bar) raises no window resize; the probe's own resize re-reads the insets.
|
|
279
|
+
{
|
|
280
|
+
const { document: doc } = fakeDom({ viewW: 844, viewH: 390 });
|
|
281
|
+
const root = (doc ?? document).createElement('div');
|
|
282
|
+
const prior = { ResizeObserver: globalThis.ResizeObserver, getComputedStyle: globalThis.getComputedStyle };
|
|
283
|
+
let notify = null;
|
|
284
|
+
globalThis.ResizeObserver = class { constructor(callback) {notify = callback;} observe() {} disconnect() {} };
|
|
285
|
+
let right = 0;
|
|
286
|
+
globalThis.getComputedStyle = (element) => ({ ...element.styles, paddingLeft: '0px', paddingRight: `${right}px`, paddingTop: '0px', paddingBottom: '0px' });
|
|
287
|
+
try {
|
|
288
|
+
const controller = makeSafeLayout({ root, entries: () => [] });
|
|
289
|
+
const probe = root.children[0];
|
|
290
|
+
notify([{ target: probe, contentRect: { width: 844, height: 390 } }]);
|
|
291
|
+
assert.equal(controller.report().view.insets.right, 0);
|
|
292
|
+
right = 30;
|
|
293
|
+
notify([{ target: root, contentRect: { width: 844, height: 390 } }]);
|
|
294
|
+
assert.equal(controller.report().view.insets.right, 0, 'nothing says the insets moved yet');
|
|
295
|
+
notify([{ target: probe, contentRect: { width: 814, height: 390 } }]);
|
|
296
|
+
assert.equal(controller.report().view.insets.right, 30, 'the probe resizing re-reads the insets at the same view size');
|
|
297
|
+
assert.equal(controller.report().view.w, 844);
|
|
298
|
+
controller.dispose();
|
|
299
|
+
} finally {
|
|
300
|
+
globalThis.ResizeObserver = prior.ResizeObserver;
|
|
301
|
+
if (prior.getComputedStyle === undefined) {delete globalThis.getComputedStyle;} else {globalThis.getComputedStyle = prior.getComputedStyle;}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
226
305
|
// An Act row is placed once but reports its two leaf hit targets. Removing
|
|
227
306
|
// the row reconciles the same registry used by placement/debug/F observers.
|
|
228
307
|
{
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { besideColumn, makeSafeLayout, overlaps, reservedCorners, safePlacement } from '../code/client/safeLayout.js';
|
|
3
|
+
import { fakeDom } from './fixtures/fake-dom.mjs';
|
|
4
|
+
|
|
5
|
+
// The HUD prompt ("Tap Rowan and tell him what you like.") stands beside the
|
|
6
|
+
// bottom-right column, but only the column and the host's corners moved it:
|
|
7
|
+
// on a landscape phone at 740x360 (a 492x211 deck frame) it lay over People in
|
|
8
|
+
// the dock. Covering a control, it takes the look caption's lane rule; clear,
|
|
9
|
+
// it keeps its old place exactly. Toast, ribbon, world labels and chips are
|
|
10
|
+
// placed as before. Boxes are #4365's Metal measurements of Town at both sizes.
|
|
11
|
+
const rectangle = ({ x, y, w, h }) => ({ left: x, top: y, right: x + w, bottom: y + h });
|
|
12
|
+
const layOut = ({ view, controls, prompt, words, others = [], onLayout, inspect }) => {
|
|
13
|
+
const dom = fakeDom({ viewW: view.w, viewH: view.h });
|
|
14
|
+
const root = document.createElement('div'); dom.body.append(root);
|
|
15
|
+
root.contains = (node) => { for (let p = node; p; p = p.parent) {if (p === root) {return true;}} return false; };
|
|
16
|
+
// A wrapped line is one 26 px row while its words fit, two rows otherwise.
|
|
17
|
+
const box = (node, at, height = () => at.h) => {
|
|
18
|
+
node.getBoundingClientRect = () => {
|
|
19
|
+
const [dx, dy] = (node.style.translate || '0 0').split(' ').map(Number.parseFloat);
|
|
20
|
+
const w = Math.min(at.w, Number.parseFloat(node.style.maxWidth) || Infinity);
|
|
21
|
+
const h = height(w);
|
|
22
|
+
return { ...rectangle({ x: at.x + dx, y: at.y + dy, w, h }), width: w, height: h };
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
const title = document.createElement('div'); root.append(title); box(title, controls.hud);
|
|
26
|
+
const entries = Object.entries(controls).filter(([id]) => id !== 'hud').map(([id, at]) => {
|
|
27
|
+
const node = document.createElement('button'); root.append(node); box(node, at);
|
|
28
|
+
return { id, node, kind: 'control' };
|
|
29
|
+
});
|
|
30
|
+
const text = document.createElement('div'); root.append(text);
|
|
31
|
+
text.ownerDocument = { createRange: () => ({ selectNodeContents() {}, getBoundingClientRect: () => ({ width: words }) }) };
|
|
32
|
+
box(text, prompt, (w) => w >= words ? 26 : 44);
|
|
33
|
+
const rest = others.map(({ at, ...entry }) => {
|
|
34
|
+
const node = document.createElement('div'); root.append(node); box(node, at);
|
|
35
|
+
return { ...entry, node };
|
|
36
|
+
});
|
|
37
|
+
const previous = globalThis.getComputedStyle;
|
|
38
|
+
globalThis.getComputedStyle = (element) => ({ ...element.style, paddingLeft: '0px', paddingRight: '0px', paddingTop: '0px', paddingBottom: '0px' });
|
|
39
|
+
try {
|
|
40
|
+
// The prompt is listed first, as chrome.js lists it, ahead of the dock.
|
|
41
|
+
const at = Object.fromEntries(others.map((entry) => [entry.id, entry.at]));
|
|
42
|
+
const controller = makeSafeLayout({ root, hud: () => title, onLayout: () => onLayout?.(at), entries: () => [{ id: 'hud', node: title, kind: 'hud', margin: { top: 12 } },
|
|
43
|
+
{ id: 'hud-prompt', node: text, kind: 'text', transient: false, margin: { bottom: 54 } }, ...entries, ...rest] });
|
|
44
|
+
const report = controller.report();
|
|
45
|
+
const held = controller.heldPrompt();
|
|
46
|
+
controller.dispose();
|
|
47
|
+
return { report, text, held };
|
|
48
|
+
} finally {
|
|
49
|
+
if (previous === undefined) {delete globalThis.getComputedStyle;} else {globalThis.getComputedStyle = previous;}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const find = (report, id) => report.boxes.find((b) => b.id === id);
|
|
53
|
+
const dock = { people: { x: 10, y: 118, w: 100, h: 38 }, doors: { x: 10, y: 162, w: 73, h: 38 }, 'companion-badge': { x: 10, y: 68, w: 44, h: 44 } };
|
|
54
|
+
|
|
55
|
+
// 740x360: the prompt lay over People. Now it is drawn whole, clear of every
|
|
56
|
+
// control, the HUD and the host's corners, and is never hidden.
|
|
57
|
+
{
|
|
58
|
+
const view = { w: 492, h: 211, insets: { top: 0, right: 0, bottom: 0, left: 0 } };
|
|
59
|
+
const controls = { hud: { x: 154, y: 12, w: 185, h: 25 }, ...dock,
|
|
60
|
+
character: { x: 139, y: 164, w: 101, h: 38 }, jump: { x: 246, y: 153, w: 64, h: 48 }, act: { x: 316, y: 153, w: 64, h: 48 },
|
|
61
|
+
emote: { x: 386, y: 157, w: 44, h: 44 }, 'quick-chat': { x: 436, y: 157, w: 44, h: 44 }, sound: { x: 440, y: 64, w: 40, h: 40 },
|
|
62
|
+
'action-overflow:0': { x: 315, y: 101, w: 117, h: 44 } };
|
|
63
|
+
const prompt = { x: 98, y: 113, w: 295, h: 44 };
|
|
64
|
+
// The old rule: beside the column, against the corners only. It covers People.
|
|
65
|
+
const corners = reservedCorners(view).map(rectangle);
|
|
66
|
+
const old = besideColumn(safePlacement(rectangle(prompt), view, { bottom: 54 }, corners), view, { bottom: 54 }, []);
|
|
67
|
+
assert(overlaps(rectangle(old), rectangle(dock.people)), 'the old place covers People');
|
|
68
|
+
const { report, text } = layOut({ view, controls, prompt, words: 252 });
|
|
69
|
+
const drawn = find(report, 'hud-prompt');
|
|
70
|
+
assert(drawn, 'the prompt is drawn');
|
|
71
|
+
assert.notEqual(text.style.display, 'none');
|
|
72
|
+
for (const [id, at] of [...Object.entries(controls), ...corners.map((c, i) => [`corner:${i}`, { x: c.left, y: c.top, w: c.right - c.left, h: c.bottom - c.top }])]) {
|
|
73
|
+
assert(!overlaps(rectangle(drawn), rectangle(at)), `prompt clear of ${id}`);
|
|
74
|
+
}
|
|
75
|
+
assert.deepEqual({ w: drawn.w, h: drawn.h }, { w: 295, h: 26 }, 'its whole pill, one line');
|
|
76
|
+
assert(drawn.y >= 6 && drawn.y + drawn.h <= 211 - 54, 'inside the view above its bottom margin');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// 844x390: clear of every control already, so it keeps its old place exactly.
|
|
80
|
+
{
|
|
81
|
+
const view = { w: 562, h: 241, insets: { top: 0, right: 0, bottom: 0, left: 0 } };
|
|
82
|
+
const controls = { hud: { x: 189, y: 12, w: 185, h: 25 }, ...dock,
|
|
83
|
+
character: { x: 399, y: 140, w: 101, h: 38 }, jump: { x: 366, y: 183, w: 64, h: 48 }, act: { x: 436, y: 183, w: 64, h: 48 },
|
|
84
|
+
emote: { x: 506, y: 137, w: 44, h: 44 }, 'quick-chat': { x: 506, y: 187, w: 44, h: 44 }, sound: { x: 510, y: 64, w: 40, h: 40 },
|
|
85
|
+
'act-prompt:greeter': { x: 226, y: 43, w: 208, h: 44 } };
|
|
86
|
+
const prompt = { x: 150, y: 112, w: 261, h: 26 };
|
|
87
|
+
const { report } = layOut({ view, controls, prompt, words: 252 });
|
|
88
|
+
const corners = reservedCorners(view).map(rectangle);
|
|
89
|
+
const old = besideColumn(safePlacement(rectangle(prompt), view, { bottom: 54 }, corners), view, { bottom: 54 }, []);
|
|
90
|
+
const drawn = find(report, 'hud-prompt');
|
|
91
|
+
assert.deepEqual({ x: drawn.x, y: drawn.y, w: drawn.w, h: drawn.h }, old, 'unchanged where it was clear');
|
|
92
|
+
for (const [id, at] of Object.entries(controls)) {assert(!overlaps(rectangle(drawn), rectangle(at)), `prompt clear of ${id}`);}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Nowhere to go: a wall of controls. The prompt keeps its old place and is
|
|
96
|
+
// drawn, unlike the look caption; nothing else moves for it.
|
|
97
|
+
{
|
|
98
|
+
const view = { w: 492, h: 211, insets: { top: 0, right: 0, bottom: 0, left: 0 } };
|
|
99
|
+
const controls = { hud: { x: 154, y: 12, w: 185, h: 25 }, wall: { x: 6, y: 62, w: 480, h: 143 } };
|
|
100
|
+
const prompt = { x: 98, y: 113, w: 295, h: 26 };
|
|
101
|
+
const { report, text } = layOut({ view, controls, prompt, words: 252 });
|
|
102
|
+
const corners = reservedCorners(view).map(rectangle);
|
|
103
|
+
const old = besideColumn(safePlacement(rectangle(prompt), view, { bottom: 54 }, corners), view, { bottom: 54 }, []);
|
|
104
|
+
const drawn = find(report, 'hud-prompt');
|
|
105
|
+
assert.notEqual(text.style.display, 'none', 'never hidden');
|
|
106
|
+
assert.deepEqual({ x: drawn.x, y: drawn.y }, { x: old.x, y: old.y });
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// World labels, pointers, the toast, the feed, the ribbon, a card and the
|
|
110
|
+
// action chips are placed as before: a run where the prompt had to move gives
|
|
111
|
+
// them the same boxes as a run where it was clear. (Review: the prompt's new
|
|
112
|
+
// lane is chosen off their unplaced boxes, so the toast at 196,43 stays.)
|
|
113
|
+
{
|
|
114
|
+
const view = { w: 492, h: 211, insets: { top: 0, right: 0, bottom: 0, left: 0 } };
|
|
115
|
+
const others = [
|
|
116
|
+
{ id: 'label:rowan', kind: 'label', transient: true, at: { x: 250, y: 60, w: 80, h: 22 } },
|
|
117
|
+
{ id: 'pointer:door', kind: 'pointer', transient: true, at: { x: 330, y: 60, w: 70, h: 22 } },
|
|
118
|
+
{ id: 'toast', kind: 'toast', transient: true, margin: { top: 12 }, at: { x: 196, y: 43, w: 100, h: 30 } },
|
|
119
|
+
{ id: 'feed', kind: 'text', transient: true, margin: { left: 10 }, at: { x: 130, y: 150, w: 100, h: 30 } },
|
|
120
|
+
{ id: 'people-card', kind: 'card', at: { x: 420, y: 100, w: 60, h: 40 } },
|
|
121
|
+
{ id: 'stats', kind: 'text', transient: true, margin: { right: 8, top: 8 }, at: { x: 150, y: 125, w: 60, h: 20 } },
|
|
122
|
+
{ id: 'ribbon', kind: 'ribbon', transient: true, at: { x: 250, y: 160, w: 120, h: 30 } },
|
|
123
|
+
{ id: 'actions', kind: 'control', at: { x: 380, y: 150, w: 100, h: 44 } },
|
|
124
|
+
];
|
|
125
|
+
const run = (people) => layOut({ view, controls: { hud: { x: 154, y: 12, w: 185, h: 25 }, people }, prompt: { x: 98, y: 113, w: 295, h: 26 }, words: 252, others }).report;
|
|
126
|
+
const moved = run({ x: 10, y: 118, w: 100, h: 38 });
|
|
127
|
+
const clear = run({ x: 10, y: 190, w: 30, h: 16 });
|
|
128
|
+
assert.notDeepEqual(find(moved, 'hud-prompt'), find(clear, 'hud-prompt'), 'the prompt moved off People in one run');
|
|
129
|
+
for (const { id } of others) {assert.deepEqual(find(moved, id), find(clear, id), `${id} placed as before`);}
|
|
130
|
+
const placed = find(moved, 'hud-prompt');
|
|
131
|
+
for (const { id } of others) {assert(!overlaps(rectangle(placed), rectangle(find(moved, id))), `the moved prompt is clear of ${id}`);}
|
|
132
|
+
}
|
|
133
|
+
// Review: a card placed after the prompt could land on its new lane (a card
|
|
134
|
+
// at 0,0 placed at 6,62). The card is placed as before and the prompt is
|
|
135
|
+
// never left under it: its lane keeps off the card, or it goes back.
|
|
136
|
+
{
|
|
137
|
+
const view = { w: 492, h: 211, insets: { top: 0, right: 0, bottom: 0, left: 0 } };
|
|
138
|
+
const others = [{ id: 'people-card', kind: 'card', at: { x: 0, y: 0, w: 100, h: 30 } }];
|
|
139
|
+
const run = (people) => layOut({ view, controls: { hud: { x: 154, y: 12, w: 185, h: 25 }, people }, prompt: { x: 98, y: 113, w: 295, h: 26 }, words: 252, others });
|
|
140
|
+
const moved = run({ x: 10, y: 118, w: 100, h: 38 }), clear = run({ x: 10, y: 190, w: 30, h: 16 });
|
|
141
|
+
const card = find(moved.report, 'people-card'), prompt = find(moved.report, 'hud-prompt');
|
|
142
|
+
assert.deepEqual(card, find(clear.report, 'people-card'), 'the card is placed as before');
|
|
143
|
+
assert(!overlaps(rectangle(card), rectangle(prompt)), 'the prompt is not under the card');
|
|
144
|
+
for (const id of ['people']) {assert(!overlaps(rectangle(prompt), rectangle({ x: 10, y: 118, w: 100, h: 38 })), `clear of ${id}`);}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// The rail settles in onLayout against the prompt's old box (heldPrompt);
|
|
148
|
+
// a rail that settles onto the prompt's lane sends the prompt back too.
|
|
149
|
+
{
|
|
150
|
+
const view = { w: 492, h: 211, insets: { top: 0, right: 0, bottom: 0, left: 0 } };
|
|
151
|
+
const controls = { hud: { x: 154, y: 12, w: 185, h: 25 }, people: { x: 10, y: 118, w: 100, h: 38 } };
|
|
152
|
+
const prompt = { x: 98, y: 113, w: 295, h: 26 };
|
|
153
|
+
const stay = layOut({ view, controls, prompt, words: 252, others: [{ id: 'action-overflow:0', kind: 'control', at: { x: 400, y: 160, w: 80, h: 40 } }] });
|
|
154
|
+
const lane = find(stay.report, 'hud-prompt');
|
|
155
|
+
assert.notDeepEqual({ x: lane.x, y: lane.y }, { x: 98, y: 113 }, 'moved off People');
|
|
156
|
+
assert(stay.held && overlaps(stay.held, rectangle(controls.people)), 'the rail is told the old box');
|
|
157
|
+
const onto = layOut({ view, controls, prompt, words: 252, others: [{ id: 'action-overflow:0', kind: 'control', at: { x: 400, y: 160, w: 80, h: 40 } }],
|
|
158
|
+
onLayout: (at) => {Object.assign(at['action-overflow:0'], { x: lane.x + 20, y: lane.y, w: 80, h: 26 });} });
|
|
159
|
+
const back = find(onto.report, 'hud-prompt');
|
|
160
|
+
assert.deepEqual({ x: back.x, y: back.y }, { x: 98, y: 113 }, 'back at its old place');
|
|
161
|
+
assert.equal(onto.held, null);
|
|
162
|
+
}
|
|
163
|
+
console.log('safe prompt: the HUD prompt leaves the controls for the nearest clear lane at 740x360 and keeps its place at 844x390');
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
// The sound control surface (`code/client/soundSurface.js`), its tree
|
|
2
|
+
// (`soundTree.js`) and the UI tree's slider node (v1.198): the speaker button
|
|
3
|
+
// and its card as the `sound` UI tree root, with no DOM, for a native host.
|
|
4
|
+
// Checks that the trees validate; that bytes and binding ids do not move
|
|
5
|
+
// across rebuilds with fresh closures; that a tree without a slider is the
|
|
6
|
+
// same bytes as before the slider; that the button opens and closes the card
|
|
7
|
+
// and hiding it closes the card; that Mute and the slider reach the
|
|
8
|
+
// soundscape's handlers only while the card is open; that the glyph, words
|
|
9
|
+
// and readout placement follow chrome.js `soundControl`; and that the web
|
|
10
|
+
// renderer draws the slider as chrome.js drew its range input.
|
|
11
|
+
import assert from 'node:assert/strict';
|
|
12
|
+
import { fakeDom } from './fixtures/fake-dom.mjs';
|
|
13
|
+
import { dispatchUiEvent, h, resetUiTrees, serialize, setUiTreeSink, sliderValue, validate } from '../code/client/uiTree.js';
|
|
14
|
+
import { cssFor, mountUiTree } from '../code/client/uiDom.js';
|
|
15
|
+
import { SOUND_CARD_DROP, SOUND_TOP, buildSound, soundLabel } from '../code/client/soundTree.js';
|
|
16
|
+
import { makeSoundSurface } from '../code/client/soundSurface.js';
|
|
17
|
+
|
|
18
|
+
let passed = 0;
|
|
19
|
+
const test = async (name, fn) => {
|
|
20
|
+
try {await fn();} catch (error) {error.message = `${name}: ${error.message}`; throw error;}
|
|
21
|
+
passed += 1;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const ON = { toggle() {}, mute() {}, volume() {} };
|
|
25
|
+
const STATES = [
|
|
26
|
+
{ show: false },
|
|
27
|
+
{ view: { safeInsets: true }, show: true, open: false, volume: 0.6, muted: false, below: null },
|
|
28
|
+
{ view: { safeInsets: true }, show: true, open: true, volume: 0.6, muted: false, below: null },
|
|
29
|
+
{ view: { safeInsets: false }, show: true, open: true, volume: 0.6, muted: true, below: 90 },
|
|
30
|
+
{ view: { safeInsets: true }, show: true, open: true, volume: 0, muted: false, below: 20 },
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
function makeHost(view = { safeInsets: true }) {
|
|
34
|
+
resetUiTrees();
|
|
35
|
+
const host = { roots: [], calls: [] };
|
|
36
|
+
setUiTreeSink((name, wire, handlers) => {host.roots.push({ name, wire, handlers });}, { dom: false });
|
|
37
|
+
host.surface = makeSoundSurface({ view: () => view });
|
|
38
|
+
host.wire = () => host.roots.filter((r) => r.name === 'sound').at(-1)?.wire ?? null;
|
|
39
|
+
host.node = (key) => (host.wire()?.c ?? []).find((n) => n.k === key) ?? null;
|
|
40
|
+
host.card = (key) => (host.node('card')?.c ?? []).find((n) => n.k === key) ?? null;
|
|
41
|
+
host.handlers = { onVolume: (v) => host.calls.push(['volume', v]), onMuted: (m) => host.calls.push(['muted', m]) };
|
|
42
|
+
host.tap = (path) => dispatchUiEvent('sound', `sound/${path}#tap`, {});
|
|
43
|
+
host.slide = (value) => dispatchUiEvent('sound', 'sound/card/volume#input', { value });
|
|
44
|
+
return host;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
await test('slider: type, fields and events validate; unknown slider fields do not', () => {
|
|
48
|
+
const ok = h('stack', { key: 'r' }, h('slider', { key: 's', value: 3, min: 0, max: 10, step: 1, disabled: false, tint: 'gold', label: 'L', on: { input() {}, release() {} } }));
|
|
49
|
+
assert.deepEqual(validate(ok), []);
|
|
50
|
+
assert.deepEqual(validate(h('stack', { key: 'r' }, h('slider', { key: 's', text: 'x' }))), ['r/s: unknown field text']);
|
|
51
|
+
assert.deepEqual(validate({ t: 'slider', c: [{ t: 'text', text: 'x' }] }), ['#0: slider has children']);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
await test('sliderValue: defaults, clamping and a bad range', () => {
|
|
55
|
+
assert.deepEqual(sliderValue({ t: 'slider' }), { min: 0, max: 1, step: 0, value: 0 });
|
|
56
|
+
assert.deepEqual(sliderValue({ value: 0.4 }), { min: 0, max: 1, step: 0, value: 0.4 });
|
|
57
|
+
assert.equal(sliderValue({ value: 140, max: 100 }).value, 100);
|
|
58
|
+
assert.equal(sliderValue({ value: -3, min: 0, max: 100 }).value, 0);
|
|
59
|
+
assert.equal(sliderValue({ value: 'x', min: 5, max: 9 }).value, 5);
|
|
60
|
+
assert.deepEqual(sliderValue({ value: 7, min: 10, max: 2 }), { min: 10, max: 10, step: 0, value: 10 });
|
|
61
|
+
assert.equal(sliderValue({ step: -1 }).step, 0);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
await test('a tree without a slider serializes to the bytes it always did', () => {
|
|
65
|
+
const tree = h('stack', { key: 'r' }, h('button', { key: 'b', fire: 'down', on: { tap() {} } }, 'Go'), h('field', { key: 'f', value: 'x', ver: 1 }));
|
|
66
|
+
assert.equal(serialize(tree).json, '{"t":"stack","k":"r","c":[{"t":"button","k":"b","fire":"down","on":{"tap":"r/b#tap"},"c":[{"t":"text","text":"Go"}]},{"t":"field","k":"f","value":"x","ver":1}]}');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
await test('sound trees validate: hidden, closed, open, muted, under the readout, at 0%', () => {
|
|
70
|
+
for (const state of STATES) {
|
|
71
|
+
assert.deepEqual(validate(buildSound(state, ON), 'sound'), [], JSON.stringify(state));
|
|
72
|
+
assert.deepEqual(validate(buildSound(state), 'sound'), []);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
await test('bytes and binding ids do not move across rebuilds with fresh closures', () => {
|
|
77
|
+
const state = STATES[2];
|
|
78
|
+
const one = serialize(buildSound(state, { toggle: () => 1, mute: () => 1, volume: () => 1 }), 'sound');
|
|
79
|
+
const two = serialize(buildSound(state, { toggle: () => 2, mute: () => 2, volume: () => 2 }), 'sound');
|
|
80
|
+
assert.equal(one.json, two.json);
|
|
81
|
+
assert.deepEqual([...one.handlers.keys()], ['sound/button#tap', 'sound/card/mute#tap', 'sound/card/volume#input']);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
await test('the DOM soundControl: glyph, words, places, card styles, slider range', () => {
|
|
85
|
+
assert.deepEqual(soundLabel(0.6, false), { glyph: '🔊', label: 'Sound: 60%' });
|
|
86
|
+
assert.deepEqual(soundLabel(0.6, true), { glyph: '🔇', label: 'Sound: off' });
|
|
87
|
+
assert.deepEqual(soundLabel(0.004, false), { glyph: '🔇', label: 'Sound: off' });
|
|
88
|
+
const open = serialize(buildSound(STATES[2], ON), 'sound').wire;
|
|
89
|
+
const [button, card] = open.c;
|
|
90
|
+
assert.equal(button.hub, 'sound');
|
|
91
|
+
assert.deepEqual(button.at, { anchor: 'topRight', right: [12, 0], top: SOUND_TOP });
|
|
92
|
+
assert.equal(button.c[0].text, '🔊');
|
|
93
|
+
assert.equal(card.hub, 'sound-card');
|
|
94
|
+
assert.deepEqual(card.at.top, [SOUND_TOP[0] + SOUND_CARD_DROP, SOUND_TOP[1] + SOUND_CARD_DROP]);
|
|
95
|
+
assert.equal(card.s.gone, false);
|
|
96
|
+
const [mute, slider] = card.c;
|
|
97
|
+
assert.equal(mute.c[0].text, 'Mute');
|
|
98
|
+
assert.deepEqual({ t: slider.t, value: slider.value, min: slider.min, max: slider.max, step: slider.step, tint: slider.tint, label: slider.label },
|
|
99
|
+
{ t: 'slider', value: 60, min: 0, max: 100, step: 1, tint: 'gold', label: 'Volume' });
|
|
100
|
+
assert.equal(slider.s.opacity, 1);
|
|
101
|
+
const muted = serialize(buildSound(STATES[3], ON), 'sound').wire;
|
|
102
|
+
assert.equal(muted.c[0].at.right, 12, 'no safe insets: a plain 12 px');
|
|
103
|
+
assert.deepEqual(muted.c[0].at.top, [90, 64], 'under the readout: max(readout bottom + 6, its own top)');
|
|
104
|
+
assert.deepEqual(muted.c[1].at.top, [136, 110]);
|
|
105
|
+
assert.equal(muted.c[1].c[0].c[0].text, 'Unmute');
|
|
106
|
+
assert.equal(muted.c[1].c[1].s.opacity, 0.5);
|
|
107
|
+
assert.deepEqual(serialize(buildSound(STATES[4], ON), 'sound').wire.c[0].at.top, SOUND_TOP, 'a readout above 64 px changes nothing');
|
|
108
|
+
assert.equal(serialize(buildSound(STATES[1], ON), 'sound').wire.c[1].s.gone, true, 'closed card');
|
|
109
|
+
assert.equal(serialize(buildSound(STATES[0], ON), 'sound').wire.c, undefined, 'no button, no card');
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
await test('surface: the button opens and closes the card; hiding the button closes it', () => {
|
|
113
|
+
const host = makeHost();
|
|
114
|
+
assert.equal(host.wire().c, undefined, 'nothing until shown');
|
|
115
|
+
host.surface.soundControl(true, { volume: 0.5, muted: false }, host.handlers);
|
|
116
|
+
assert.equal(host.node('card').s.gone, true);
|
|
117
|
+
assert.equal(host.tap('button'), true);
|
|
118
|
+
assert.equal(host.node('card').s.gone, false);
|
|
119
|
+
assert.equal(host.surface.isOpen(), true);
|
|
120
|
+
host.tap('button');
|
|
121
|
+
assert.equal(host.node('card').s.gone, true);
|
|
122
|
+
host.tap('button');
|
|
123
|
+
host.surface.soundControl(false, { volume: 0.5, muted: false });
|
|
124
|
+
assert.equal(host.wire().c, undefined);
|
|
125
|
+
host.surface.soundControl(true, { volume: 0.5, muted: false });
|
|
126
|
+
assert.equal(host.node('card').s.gone, true, 'shown again, closed');
|
|
127
|
+
host.surface.dispose();
|
|
128
|
+
assert.equal(host.roots.at(-1).wire, null);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
await test('surface: Mute and the slider reach the soundscape only while the card is open', () => {
|
|
132
|
+
const host = makeHost();
|
|
133
|
+
host.surface.soundControl(true, { volume: 0.5, muted: false }, host.handlers);
|
|
134
|
+
host.tap('card/mute');
|
|
135
|
+
host.slide(30);
|
|
136
|
+
assert.deepEqual(host.calls, [], 'closed card: nothing');
|
|
137
|
+
host.tap('button');
|
|
138
|
+
host.tap('card/mute');
|
|
139
|
+
assert.deepEqual(host.calls, [['muted', true]]);
|
|
140
|
+
host.surface.soundControl(true, { volume: 0.5, muted: true });
|
|
141
|
+
assert.equal(host.card('mute').c[0].text, 'Unmute');
|
|
142
|
+
host.tap('card/mute');
|
|
143
|
+
assert.deepEqual(host.calls.at(-1), ['muted', false]);
|
|
144
|
+
host.slide(30);
|
|
145
|
+
assert.deepEqual(host.calls.at(-1), ['volume', 0.3]);
|
|
146
|
+
host.slide(250);
|
|
147
|
+
assert.deepEqual(host.calls.at(-1), ['volume', 1], 'clamped');
|
|
148
|
+
host.slide('x');
|
|
149
|
+
assert.equal(host.calls.length, 4, 'a non-number value is dropped');
|
|
150
|
+
host.surface.soundControl(true, { volume: 0.3, muted: false });
|
|
151
|
+
assert.equal(host.card('volume').value, 30);
|
|
152
|
+
assert.equal(host.node('button').label, 'Sound: 30%');
|
|
153
|
+
host.surface.place(100);
|
|
154
|
+
assert.deepEqual(host.node('button').at.top, [100, 64]);
|
|
155
|
+
host.surface.place(null);
|
|
156
|
+
assert.deepEqual(host.node('button').at.top, SOUND_TOP);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
await test('surface: an unchanged state sends nothing', () => {
|
|
160
|
+
const host = makeHost();
|
|
161
|
+
host.surface.soundControl(true, { volume: 0.5, muted: false }, host.handlers);
|
|
162
|
+
const sent = host.roots.length;
|
|
163
|
+
host.surface.soundControl(true, { volume: 0.5, muted: false }, { onVolume() {}, onMuted() {} });
|
|
164
|
+
host.surface.place(null);
|
|
165
|
+
assert.equal(host.roots.length, sent);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
await test('uiDom: the slider is a range input with the chrome\'s look; events; the player\'s value while held', () => {
|
|
169
|
+
fakeDom({ viewW: 390, viewH: 844 });
|
|
170
|
+
const container = document.createElement('div');
|
|
171
|
+
document.body.appendChild(container);
|
|
172
|
+
const ui = mountUiTree(container);
|
|
173
|
+
const events = [];
|
|
174
|
+
const tree = (value, extra = {}) => h('stack', { key: 'r' }, h('slider', {
|
|
175
|
+
key: 's', label: 'Volume', value, min: 0, max: 100, step: 1, ...extra, style: { flex: 1, minW: 0, h: 28 },
|
|
176
|
+
on: { input: (e) => events.push(['input', e.value]), release: (e) => events.push(['release', e.value]) },
|
|
177
|
+
}));
|
|
178
|
+
ui.render(tree(40));
|
|
179
|
+
let el = ui.nodeFor('r/s');
|
|
180
|
+
assert.equal(el.type, 'range');
|
|
181
|
+
assert.deepEqual([el.min, el.max, el.step, el.value, el.disabled], ['0', '100', '1', '40', false]);
|
|
182
|
+
assert.equal(el.attrs['aria-label'], 'Volume');
|
|
183
|
+
const css = cssFor({ t: 'slider', s: { flex: 1, minW: 0, h: 28 } }, 'row');
|
|
184
|
+
assert.deepEqual({ margin: css.margin, accentColor: css.accentColor, cursor: css.cursor, pointerEvents: css.pointerEvents, height: css.height, flex: css.flex },
|
|
185
|
+
{ margin: '0', accentColor: '#e9c48f', cursor: 'pointer', pointerEvents: 'auto', height: '28px', flex: '1' });
|
|
186
|
+
assert.equal(cssFor({ t: 'slider', tint: '#123456' }, 'row').accentColor, '#123456');
|
|
187
|
+
assert.equal(cssFor({ t: 'slider', disabled: true }, 'row').cursor, 'default');
|
|
188
|
+
// The page's own pointer listeners (the stand-in DOM has no window).
|
|
189
|
+
const page = {};
|
|
190
|
+
globalThis.addEventListener = (type, fn) => {(page[type] ??= new Set()).add(fn);};
|
|
191
|
+
globalThis.removeEventListener = (type, fn) => {page[type]?.delete(fn);};
|
|
192
|
+
const pageUp = (type = 'pointerup') => [...(page[type] ?? [])].forEach((fn) => fn({}));
|
|
193
|
+
let stopped = false;
|
|
194
|
+
el.handlers.pointerdown({ stopPropagation: () => {stopped = true;} });
|
|
195
|
+
assert.equal(stopped, true, 'the scene never sees the drag');
|
|
196
|
+
ui.render(tree(20));
|
|
197
|
+
assert.equal(el.value, '40', 'held (pointer down, not yet focused): the player\'s value');
|
|
198
|
+
el.value = '55';
|
|
199
|
+
el.handlers.input({});
|
|
200
|
+
pageUp();
|
|
201
|
+
el.handlers.change({});
|
|
202
|
+
assert.deepEqual(events, [['input', 55], ['release', 55]], 'one release per hold');
|
|
203
|
+
// A press let go off the slider with no move: still a release, and let go.
|
|
204
|
+
el.handlers.pointerdown({});
|
|
205
|
+
pageUp('pointercancel');
|
|
206
|
+
assert.deepEqual(events.at(-1), ['release', 55]);
|
|
207
|
+
assert.equal(events.length, 3);
|
|
208
|
+
assert.equal(page.pointerup?.size ?? 0, 0, 'listeners removed');
|
|
209
|
+
// A keyboard change, no pointer held: released at once.
|
|
210
|
+
el.handlers.keydown({});
|
|
211
|
+
el.handlers.change({});
|
|
212
|
+
assert.equal(events.length, 4);
|
|
213
|
+
// A browser that fires change before pointerup: still one release.
|
|
214
|
+
el.handlers.pointerdown({});
|
|
215
|
+
el.value = '60';
|
|
216
|
+
el.handlers.change({});
|
|
217
|
+
pageUp();
|
|
218
|
+
assert.deepEqual(events.slice(4), [['release', 60]]);
|
|
219
|
+
// A slider removed, or its renderer disposed, mid-hold: no listeners
|
|
220
|
+
// left on the page and no release from the removed slider.
|
|
221
|
+
el.handlers.pointerdown({});
|
|
222
|
+
ui.render(h('stack', { key: 'r' }));
|
|
223
|
+
assert.equal((page.pointerup?.size ?? 0) + (page.pointercancel?.size ?? 0), 0, 'removed: listeners gone');
|
|
224
|
+
pageUp();
|
|
225
|
+
assert.equal(events.length, 5, 'removed: no release');
|
|
226
|
+
ui.render(tree(40));
|
|
227
|
+
const again = ui.nodeFor('r/s');
|
|
228
|
+
again.handlers.pointerdown({});
|
|
229
|
+
ui.dispose();
|
|
230
|
+
assert.equal((page.pointerup?.size ?? 0) + (page.pointercancel?.size ?? 0), 0, 'disposed: listeners gone');
|
|
231
|
+
pageUp();
|
|
232
|
+
assert.equal(events.length, 5, 'disposed: no release');
|
|
233
|
+
ui.render(tree(70));
|
|
234
|
+
el = ui.nodeFor('r/s');
|
|
235
|
+
assert.equal(el.value, '70', 'adopted when not held');
|
|
236
|
+
document.activeElement = el;
|
|
237
|
+
ui.render(tree(10));
|
|
238
|
+
assert.equal(el.value, '70', 'held: the player\'s value');
|
|
239
|
+
document.activeElement = null;
|
|
240
|
+
ui.render(tree(150, { step: 0 }));
|
|
241
|
+
assert.deepEqual([el.value, el.step], ['100', 'any'], 'clamped; step 0 is continuous');
|
|
242
|
+
ui.render(tree(10, { disabled: true }));
|
|
243
|
+
assert.equal(el.disabled, true);
|
|
244
|
+
// A field at the same key is a new element (a text input, not a range).
|
|
245
|
+
ui.render(h('stack', { key: 'r' }, h('field', { key: 's', value: 'x', ver: 1 })));
|
|
246
|
+
const field = ui.nodeFor('r/s');
|
|
247
|
+
assert.notEqual(field, el);
|
|
248
|
+
assert.equal(field.type, 'text');
|
|
249
|
+
ui.render(h('stack', { key: 'r' }, h('slider', { key: 's', value: 0.5 })));
|
|
250
|
+
assert.notEqual(ui.nodeFor('r/s'), field);
|
|
251
|
+
assert.equal(ui.nodeFor('r/s').type, 'range');
|
|
252
|
+
delete globalThis.addEventListener;
|
|
253
|
+
delete globalThis.removeEventListener;
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
console.log(`hub-game sound surface: ${passed} tests passed`);
|
|
@@ -184,6 +184,10 @@ function fakeStorage(initial = {}) {
|
|
|
184
184
|
calls.set += 1;
|
|
185
185
|
kept[key] = String(value);
|
|
186
186
|
},
|
|
187
|
+
// As a page's Storage (deviceStorage.js probes with a set and a remove).
|
|
188
|
+
removeItem: (key) => {
|
|
189
|
+
delete kept[key];
|
|
190
|
+
},
|
|
187
191
|
};
|
|
188
192
|
}
|
|
189
193
|
|
|
@@ -262,6 +266,7 @@ register(
|
|
|
262
266
|
|
|
263
267
|
const { readManifest } = await import('../code/server/manifest.js');
|
|
264
268
|
const S = await import('../code/client/soundscape.js');
|
|
269
|
+
const { CACHE_PREFIX, makeCachedStorage } = await import('../code/client/deviceStorage.js');
|
|
265
270
|
const Voice = await import('../code/client/soundscapeVoice.js');
|
|
266
271
|
const { CUE_NAMES } = await import('../code/shared/cues.js');
|
|
267
272
|
const Busker = await import('../code/client/soundscapeBusker.js');
|
|
@@ -1269,13 +1274,12 @@ function world() {
|
|
|
1269
1274
|
return { actors, add, avatars, scene, mp, local: actors.get('me') };
|
|
1270
1275
|
}
|
|
1271
1276
|
|
|
1272
|
-
function rig({ options = { babble: true, steps: true }, kept = {}, active = true, loudestLoop, cueVoices, createOfflineContext, context, lowMemory = false } = {}) {
|
|
1277
|
+
function rig({ options = { babble: true, steps: true }, kept = {}, storage = fakeStorage(kept), active = true, loudestLoop, cueVoices, createOfflineContext, context, lowMemory = false } = {}) {
|
|
1273
1278
|
State.clear();
|
|
1274
1279
|
const from = audio.contexts.length;
|
|
1275
1280
|
const doc = fakeTarget();
|
|
1276
1281
|
doc.hidden = false;
|
|
1277
1282
|
const page = fakeTarget();
|
|
1278
|
-
const storage = fakeStorage(kept);
|
|
1279
1283
|
const hides = [];
|
|
1280
1284
|
const nav = { userActivation: { hasBeenActive: active } };
|
|
1281
1285
|
const made = S.makeSoundscape(options, { storage, doc, win: page, nav, random: () => 0.5, onHide: () => hides.push(1), loudestLoop, cueVoices, createOfflineContext, lowMemory, ...(context ? { audio: { getAudioContext: () => context } } : {}) });
|
|
@@ -1854,6 +1858,85 @@ test('mute and volume: applied at once, kept in storage, read back by the next v
|
|
|
1854
1858
|
none.dispose();
|
|
1855
1859
|
});
|
|
1856
1860
|
|
|
1861
|
+
// A frame without localStorage (castle.xyz's sandboxed player frame): the
|
|
1862
|
+
// settings live in memory and are written through to LocalCache
|
|
1863
|
+
// (`code/client/deviceStorage.js`), here a stand-in kept across "reloads".
|
|
1864
|
+
function fakeCache(entries = {}) {
|
|
1865
|
+
const kept = new Map(Object.entries(entries).map(([k, v]) => [CACHE_PREFIX + k, v]));
|
|
1866
|
+
const waiting = [];
|
|
1867
|
+
const cache = {
|
|
1868
|
+
kept,
|
|
1869
|
+
hold: false,
|
|
1870
|
+
release: () => {
|
|
1871
|
+
cache.hold = false;
|
|
1872
|
+
waiting.splice(0).forEach((go) => go());
|
|
1873
|
+
},
|
|
1874
|
+
async getText(key) {
|
|
1875
|
+
if (cache.hold) {
|
|
1876
|
+
await new Promise((go) => waiting.push(go));
|
|
1877
|
+
}
|
|
1878
|
+
return kept.has(key) ? kept.get(key) : null;
|
|
1879
|
+
},
|
|
1880
|
+
async set(key, value) {
|
|
1881
|
+
kept.set(key, value);
|
|
1882
|
+
},
|
|
1883
|
+
async remove(key) {
|
|
1884
|
+
kept.delete(key);
|
|
1885
|
+
},
|
|
1886
|
+
};
|
|
1887
|
+
return cache;
|
|
1888
|
+
}
|
|
1889
|
+
const settle = () => new Promise((go) => setTimeout(go, 0));
|
|
1890
|
+
|
|
1891
|
+
await asyncTest('no localStorage: mute and volume come back after a reload through LocalCache, applied once they arrive', async () => {
|
|
1892
|
+
const cache = fakeCache();
|
|
1893
|
+
const r = rig({ storage: makeCachedStorage(() => cache) });
|
|
1894
|
+
running(r);
|
|
1895
|
+
r.made.setVolume(0.3);
|
|
1896
|
+
r.made.setMuted(true);
|
|
1897
|
+
await settle();
|
|
1898
|
+
assert.deepEqual(JSON.parse(cache.kept.get(CACHE_PREFIX + S.SETTINGS_KEY)), { volume: 0.3, muted: true });
|
|
1899
|
+
r.made.dispose();
|
|
1900
|
+
const next = rig({ storage: makeCachedStorage(() => cache) });
|
|
1901
|
+
running(next);
|
|
1902
|
+
assert.deepEqual(next.made.settings(), { volume: S.DEFAULT_VOLUME, muted: false }, 'the defaults until the cache answers');
|
|
1903
|
+
await settle();
|
|
1904
|
+
assert.deepEqual(next.made.settings(), { volume: 0.3, muted: true });
|
|
1905
|
+
assert.equal(next.frame(), 0, 'and the mute is in effect');
|
|
1906
|
+
next.made.dispose();
|
|
1907
|
+
});
|
|
1908
|
+
|
|
1909
|
+
await asyncTest('no localStorage: a volume set before the kept settings arrive wins over them', async () => {
|
|
1910
|
+
const cache = fakeCache({ [S.SETTINGS_KEY]: JSON.stringify({ volume: 0.25, muted: true }) });
|
|
1911
|
+
cache.hold = true;
|
|
1912
|
+
const r = rig({ storage: makeCachedStorage(() => cache) });
|
|
1913
|
+
running(r);
|
|
1914
|
+
await settle();
|
|
1915
|
+
r.made.setVolume(0.6);
|
|
1916
|
+
cache.release();
|
|
1917
|
+
await settle();
|
|
1918
|
+
assert.deepEqual(r.made.settings(), { volume: 0.6, muted: false });
|
|
1919
|
+
assert.deepEqual(JSON.parse(cache.kept.get(CACHE_PREFIX + S.SETTINGS_KEY)), { volume: 0.6, muted: false });
|
|
1920
|
+
r.made.dispose();
|
|
1921
|
+
});
|
|
1922
|
+
|
|
1923
|
+
test('a working localStorage is read and written as it was, with no LocalCache path', () => {
|
|
1924
|
+
const previous = Object.getOwnPropertyDescriptor(globalThis, 'localStorage');
|
|
1925
|
+
const page = fakeStorage({ [S.SETTINGS_KEY]: JSON.stringify({ volume: 0.4, muted: false }) });
|
|
1926
|
+
Object.defineProperty(globalThis, 'localStorage', { configurable: true, value: page });
|
|
1927
|
+
try {
|
|
1928
|
+
const made = S.makeSoundscape(true, { doc: null, nav: null });
|
|
1929
|
+
assert.deepEqual(made.settings(), { volume: 0.4, muted: false });
|
|
1930
|
+
made.setMuted(true);
|
|
1931
|
+
assert.deepEqual(JSON.parse(page.kept[S.SETTINGS_KEY]), { volume: 0.4, muted: true });
|
|
1932
|
+
assert.deepEqual(Object.keys(page.kept), [S.SETTINGS_KEY], 'the probe left nothing');
|
|
1933
|
+
assert.equal('prime' in page, false);
|
|
1934
|
+
made.dispose();
|
|
1935
|
+
} finally {
|
|
1936
|
+
Object.defineProperty(globalThis, 'localStorage', previous);
|
|
1937
|
+
}
|
|
1938
|
+
});
|
|
1939
|
+
|
|
1857
1940
|
test('put away: every line and step is stopped, the graph is disconnected, the listener is gone, and a second one starts clean', () => {
|
|
1858
1941
|
const r = rig();
|
|
1859
1942
|
running(r);
|