castle-web-cli 0.4.239 → 0.4.241
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 +163 -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 +6 -3
- package/dist/init.js +24 -2
- package/dist/multiplayerDoc.d.ts +1 -1
- package/dist/multiplayerDoc.js +2 -0
- package/dist/platformDoc.js +3 -2
- package/dist/playPagePolicy.js +5 -1
- package/dist/resetLeaderboards.d.ts +8 -1
- package/dist/resetLeaderboards.js +43 -8
- package/dist/roomLogs.d.ts +1 -0
- package/dist/roomLogs.js +30 -6
- package/dist/save-deck.d.ts +32 -2
- package/dist/save-deck.js +240 -39
- package/kits/base/CLAUDE.md +1 -1
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +174 -6
- package/kits/base/sdk/analytics.d.ts +8 -0
- package/kits/base/sdk/analytics.js +92 -0
- package/kits/base/sdk/castle.d.ts +5 -1
- package/kits/base/sdk/castle.js +2 -0
- package/kits/base/sdk/commands.d.ts +48 -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 +168 -26
- package/kits/base/sdk/reconnectBudget.d.ts +6 -0
- package/kits/base/sdk/reconnectBudget.js +41 -1
- 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/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/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 +481 -57
- 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/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/padCues.js +11 -7
- package/kits/hub-game/code/client/padReadability.js +3 -3
- 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 +72 -51
- 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 +205 -25
- 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 +35 -3
- 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/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 +991 -72
- 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/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 +14 -2
- package/kits/hub-game/code/server/replay.js +135 -0
- package/kits/hub-game/code/server/standing.js +7 -3
- 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/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 +429 -55
- package/kits/hub-game/docs/analytics.md +16 -2
- package/kits/hub-game/docs/contract.md +956 -101
- 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 +79 -0
- 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 +421 -4
- 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-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 +119 -0
- package/kits/hub-game/scripts/test-hub-trip.mjs +240 -4
- 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-loading-cover.mjs +67 -1
- package/kits/hub-game/scripts/test-manifest.mjs +27 -0
- package/kits/hub-game/scripts/test-menu-client.mjs +54 -5
- 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-pad-cues.mjs +39 -0
- package/kits/hub-game/scripts/test-picker-surface.mjs +321 -0
- package/kits/hub-game/scripts/test-placeat-server.mjs +648 -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 +242 -3
- 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-role-client.mjs +2 -1
- 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-standing.mjs +135 -2
- package/kits/hub-game/scripts/test-stuck-surface.mjs +174 -0
- package/kits/hub-game/scripts/test-stuck.mjs +36 -1
- 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-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 +68 -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 +340 -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 +36 -2
- package/kits/hub-game/tools/hubScene/validate-manifest.mjs +10 -2
- package/kits/multiplayer-3d/castle.json +5 -5
- package/kits/multiplayer-3d/code/client/resumeGate.js +66 -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 +108 -18
- 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 +417 -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-coaxial-escape.mjs +176 -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 +59 -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
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { makeSafeLayout, overlaps, reservedCorners } from '../code/client/safeLayout.js';
|
|
3
|
+
import { makeWorldLayout } from '../code/client/worldLabels.js';
|
|
4
|
+
import { fakeDom } from './fixtures/fake-dom.mjs';
|
|
5
|
+
|
|
6
|
+
// The act prompt ("Talk to Rowan, the greeter") was placed by safePlacement,
|
|
7
|
+
// which only moves down: on a landscape phone it sat over Character, Jump and
|
|
8
|
+
// Act at 740x360 and over Jump and the look caption at 844x390. Covering
|
|
9
|
+
// something, its whole pill takes the caption's lane rule, and it is not drawn
|
|
10
|
+
// while no lane fits; clear, it keeps its place exactly. World labels,
|
|
11
|
+
// pointers, chips, the toast, the ribbon and the action rail are placed as
|
|
12
|
+
// before. Boxes are #4369's Metal measurements of Town at both sizes.
|
|
13
|
+
const rectangle = ({ x, y, w, h }) => ({ left: x, top: y, right: x + w, bottom: y + h });
|
|
14
|
+
const layOut = ({ view, controls, act, others = [], acts = {}, onLayout }) => {
|
|
15
|
+
const dom = fakeDom({ viewW: view.w, viewH: view.h });
|
|
16
|
+
const root = document.createElement('div'); dom.body.append(root);
|
|
17
|
+
root.contains = (node) => { for (let p = node; p; p = p.parent) {if (p === root) {return true;}} return false; };
|
|
18
|
+
const box = (node, at) => {
|
|
19
|
+
node.getBoundingClientRect = () => {
|
|
20
|
+
if (node.style.display === 'none') {return { left: 0, top: 0, right: 0, bottom: 0, width: 0, height: 0 };}
|
|
21
|
+
const [dx, dy] = (node.style.translate || '0 0').split(' ').map(Number.parseFloat);
|
|
22
|
+
const w = Math.min(at.w, Number.parseFloat(node.style.maxWidth) || Infinity);
|
|
23
|
+
const h = Math.min(at.h, Number.parseFloat(node.style.maxHeight) || Infinity);
|
|
24
|
+
return { ...rectangle({ x: at.x + dx, y: at.y + dy, w, h }), width: w, height: h };
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
const make = (tag, at) => {const node = document.createElement(tag); root.append(node); box(node, at); return node;};
|
|
28
|
+
const title = make('div', controls.hud);
|
|
29
|
+
const entries = Object.entries(controls).filter(([id]) => id !== 'hud').map(([id, at]) => ({ id, node: make('button', at), kind: 'control' }));
|
|
30
|
+
const rest = others.map(({ at, words, ...entry }) => {
|
|
31
|
+
const node = make('div', at);
|
|
32
|
+
// A centred caption's words are narrower than its box.
|
|
33
|
+
if (words) {node.ownerDocument = { createRange: () => ({ selectNodeContents() {}, getBoundingClientRect: () => ({ width: words }) }) };}
|
|
34
|
+
return { ...entry, node };
|
|
35
|
+
});
|
|
36
|
+
const prompts = Object.entries({ greeter: act, ...acts }).map(([id, at]) => ({ id: `act-prompt:${id}`, node: make('button', at), kind: 'control', transient: true }));
|
|
37
|
+
const previous = globalThis.getComputedStyle;
|
|
38
|
+
globalThis.getComputedStyle = (element) => ({ ...element.style, paddingLeft: '0px', paddingRight: '0px', paddingTop: '0px', paddingBottom: '0px' });
|
|
39
|
+
try {
|
|
40
|
+
const at = Object.fromEntries([...Object.entries(controls), ...others.map((entry) => [entry.id, entry.at])]);
|
|
41
|
+
const held = {};
|
|
42
|
+
const controller = makeSafeLayout({ root, hud: () => title, entries: () => [{ id: 'hud', node: title, kind: 'hud', margin: { top: 12 } }, ...entries, ...rest, ...prompts],
|
|
43
|
+
onLayout: () => {
|
|
44
|
+
for (const prompt of prompts) {held[prompt.id] = controller.heldAct(prompt.node);}
|
|
45
|
+
onLayout?.(at, held);
|
|
46
|
+
} });
|
|
47
|
+
const report = controller.report();
|
|
48
|
+
// The display each act prompt was left with, read before dispose restores it.
|
|
49
|
+
const nodes = Object.fromEntries(prompts.map((prompt) => [prompt.id, { style: { display: prompt.node.style.display } }]));
|
|
50
|
+
controller.dispose();
|
|
51
|
+
return { report, nodes, held };
|
|
52
|
+
} finally {
|
|
53
|
+
if (previous === undefined) {delete globalThis.getComputedStyle;} else {globalThis.getComputedStyle = previous;}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
// The place it was drawn before: its box, kept 6 px above the view's bottom.
|
|
57
|
+
const edges = (b) => b && { left: b.left, top: b.top, right: b.right, bottom: b.bottom };
|
|
58
|
+
const OLD_740 = { left: 147, top: 161, right: 355, bottom: 205 };
|
|
59
|
+
const find = (report, id) => report.boxes.find((b) => b.id === id);
|
|
60
|
+
const clearOfAll = (drawn, boxes, what) => {
|
|
61
|
+
for (const [id, at] of Object.entries(boxes)) {assert(!overlaps(rectangle(drawn), rectangle(at)), `${what} clear of ${id}`);}
|
|
62
|
+
};
|
|
63
|
+
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 } };
|
|
64
|
+
|
|
65
|
+
// 740x360: over Character, Jump and Act. No row has a lane 208 px wide clear
|
|
66
|
+
// of the dock, the moved HUD prompt, the look caption, the action chips and
|
|
67
|
+
// the rail, so it is not drawn; the rail still makes way for its old place.
|
|
68
|
+
{
|
|
69
|
+
const view = { w: 492, h: 211, insets: { top: 0, right: 0, bottom: 0, left: 0 } };
|
|
70
|
+
const controls = { hud: { x: 154, y: 12, w: 185, h: 25 }, ...dock, 'hud-prompt': { x: 134, y: 69, w: 261, h: 26 },
|
|
71
|
+
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 },
|
|
72
|
+
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 },
|
|
73
|
+
'action-overflow:0': { x: 315, y: 101, w: 117, h: 44 } };
|
|
74
|
+
const look = { id: 'engine-look', kind: 'text', transient: true, at: { x: 180, y: 43, w: 132, h: 21 }, words: 130 };
|
|
75
|
+
const act = { x: 147, y: 163, w: 208, h: 44 };
|
|
76
|
+
const hidden = layOut({ view, controls, act, others: [look] });
|
|
77
|
+
assert.equal(find(hidden.report, 'act-prompt:greeter'), undefined, 'not drawn over Character, Jump and Act');
|
|
78
|
+
assert.equal(hidden.nodes['act-prompt:greeter'].style.display, 'none');
|
|
79
|
+
assert.deepEqual(edges(hidden.held['act-prompt:greeter']), OLD_740, 'the rail is told its old place');
|
|
80
|
+
assert.deepEqual(find(hidden.report, 'engine-look'), { id: 'engine-look', kind: 'text', ...look.at }, 'the caption is placed as before');
|
|
81
|
+
// With room for it (no action chips), it is drawn whole on the nearest lane.
|
|
82
|
+
const { 'action-overflow:0': chips, ...rest } = controls; void chips;
|
|
83
|
+
const { report } = layOut({ view, controls: rest, act, others: [look] });
|
|
84
|
+
const drawn = find(report, 'act-prompt:greeter');
|
|
85
|
+
assert(drawn, 'the act prompt is drawn');
|
|
86
|
+
assert.deepEqual({ w: drawn.w, h: drawn.h }, { w: 208, h: 44 }, 'its whole pill');
|
|
87
|
+
const corners = Object.fromEntries(reservedCorners(view).map((c) => [c.id, c]));
|
|
88
|
+
clearOfAll(drawn, { ...rest, ...corners, 'engine-look': find(report, 'engine-look') }, 'act prompt');
|
|
89
|
+
assert(drawn.y >= 6 && drawn.y + drawn.h <= 211 - 6 && drawn.x >= 6 && drawn.x + drawn.w <= 492 - 6, 'inside the view');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// 844x390: over Jump and the look caption. Now clear of both.
|
|
93
|
+
{
|
|
94
|
+
const view = { w: 562, h: 241, insets: { top: 0, right: 0, bottom: 0, left: 0 } };
|
|
95
|
+
const controls = { hud: { x: 189, y: 12, w: 185, h: 25 }, ...dock, 'hud-prompt': { x: 150, y: 112, w: 261, h: 26 },
|
|
96
|
+
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 },
|
|
97
|
+
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 },
|
|
98
|
+
'action-overflow:0': { x: 373, y: 60, w: 117, h: 44 } };
|
|
99
|
+
const look = { id: 'engine-look', kind: 'text', transient: true, at: { x: 6, y: 214, w: 550, h: 21 }, words: 130 };
|
|
100
|
+
const { report } = layOut({ view, controls, act: { x: 185, y: 191, w: 208, h: 44 }, others: [look] });
|
|
101
|
+
const drawn = find(report, 'act-prompt:greeter');
|
|
102
|
+
assert(drawn, 'the act prompt is drawn');
|
|
103
|
+
clearOfAll(drawn, { ...controls, 'engine-look': find(report, 'engine-look') }, 'act prompt');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Clear already: it keeps its place exactly, and the rail is told nothing.
|
|
107
|
+
{
|
|
108
|
+
const view = { w: 562, h: 241, insets: { top: 0, right: 0, bottom: 0, left: 0 } };
|
|
109
|
+
const controls = { hud: { x: 189, y: 12, w: 185, h: 25 }, jump: { x: 366, y: 183, w: 64, h: 48 } };
|
|
110
|
+
const act = { x: 120, y: 60, w: 208, h: 44 };
|
|
111
|
+
const { report, held } = layOut({ view, controls, act });
|
|
112
|
+
const drawn = find(report, 'act-prompt:greeter');
|
|
113
|
+
assert.deepEqual({ x: drawn.x, y: drawn.y, w: drawn.w, h: drawn.h }, act);
|
|
114
|
+
assert.equal(held['act-prompt:greeter'], null);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Nowhere to go: a wall of controls. It is not drawn; the rail still makes
|
|
118
|
+
// way for its old place.
|
|
119
|
+
{
|
|
120
|
+
const view = { w: 492, h: 211, insets: { top: 0, right: 0, bottom: 0, left: 0 } };
|
|
121
|
+
const controls = { hud: { x: 154, y: 12, w: 185, h: 25 }, wall: { x: 6, y: 62, w: 480, h: 143 } };
|
|
122
|
+
const act = { x: 147, y: 120, w: 208, h: 44 };
|
|
123
|
+
const { report, nodes, held } = layOut({ view, controls, act });
|
|
124
|
+
assert.equal(find(report, 'act-prompt:greeter'), undefined, 'not drawn');
|
|
125
|
+
assert.equal(nodes['act-prompt:greeter'].style.display, 'none');
|
|
126
|
+
assert.deepEqual(edges(held['act-prompt:greeter']), OLD_740, 'pushed down under the wall, as before');
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// World labels, pointers, the toast, the feed, the ribbon, a card, the action
|
|
130
|
+
// chips and the rail are placed as before: a run where the act prompt had to
|
|
131
|
+
// move gives them the same boxes as one where it was clear. Only Character
|
|
132
|
+
// differs between the runs, and only the act prompt's place touches it.
|
|
133
|
+
{
|
|
134
|
+
const view = { w: 492, h: 211, insets: { top: 0, right: 0, bottom: 0, left: 0 } };
|
|
135
|
+
const others = [
|
|
136
|
+
{ id: 'label:rowan', kind: 'label', transient: true, at: { x: 250, y: 90, w: 80, h: 22 } },
|
|
137
|
+
{ id: 'pointer:door', kind: 'pointer', transient: true, at: { x: 330, y: 90, w: 70, h: 22 } },
|
|
138
|
+
{ id: 'toast', kind: 'toast', transient: true, margin: { top: 12 }, at: { x: 196, y: 43, w: 100, h: 30 } },
|
|
139
|
+
{ id: 'feed', kind: 'text', transient: true, margin: { left: 10 }, at: { x: 20, y: 150, w: 100, h: 30 } },
|
|
140
|
+
{ id: 'people-card', kind: 'card', at: { x: 420, y: 100, w: 60, h: 40 } },
|
|
141
|
+
{ id: 'ribbon', kind: 'ribbon', transient: true, at: { x: 250, y: 120, w: 120, h: 30 } },
|
|
142
|
+
{ id: 'actions', kind: 'control', at: { x: 380, y: 150, w: 100, h: 44 } },
|
|
143
|
+
{ id: 'action-overflow:0', kind: 'control', at: { x: 420, y: 62, w: 60, h: 30 } },
|
|
144
|
+
];
|
|
145
|
+
const act = { x: 147, y: 163, w: 208, h: 44 };
|
|
146
|
+
const run = (character) => layOut({ view, controls: { hud: { x: 154, y: 12, w: 185, h: 25 }, character }, act, others });
|
|
147
|
+
const moved = run({ x: 139, y: 164, w: 101, h: 38 });
|
|
148
|
+
const clear = run({ x: 6, y: 62, w: 30, h: 20 });
|
|
149
|
+
assert.notDeepEqual(find(moved.report, 'act-prompt:greeter'), find(clear.report, 'act-prompt:greeter'), 'the act prompt moved in one run');
|
|
150
|
+
assert.deepEqual(find(clear.report, 'act-prompt:greeter'), { id: 'act-prompt:greeter', kind: 'control', x: 147, y: 161, w: 208, h: 44 }, 'kept where clear (6 px above the bottom, as before)');
|
|
151
|
+
for (const { id } of others) {assert.deepEqual(find(moved.report, id), find(clear.report, id), `${id} placed as before`);}
|
|
152
|
+
const placed = find(moved.report, 'act-prompt:greeter');
|
|
153
|
+
assert(placed, 'drawn on a lane');
|
|
154
|
+
for (const { id } of others) {assert(!overlaps(rectangle(placed), rectangle(find(moved.report, id))), `the moved act prompt is clear of ${id}`);}
|
|
155
|
+
assert.deepEqual(edges(moved.held['act-prompt:greeter']), OLD_740, 'the rail settles around the same box');
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// A surface placed after it that lands on its new lane, or the rail settling
|
|
159
|
+
// onto it, means that lane is not clear: it is not drawn this pass.
|
|
160
|
+
{
|
|
161
|
+
const view = { w: 492, h: 211, insets: { top: 0, right: 0, bottom: 0, left: 0 } };
|
|
162
|
+
const controls = { hud: { x: 154, y: 12, w: 185, h: 25 }, character: { x: 139, y: 164, w: 101, h: 38 } };
|
|
163
|
+
const act = { x: 147, y: 163, w: 208, h: 44 };
|
|
164
|
+
const first = layOut({ view, controls, act });
|
|
165
|
+
const lane = find(first.report, 'act-prompt:greeter');
|
|
166
|
+
assert(lane, 'moved to a lane');
|
|
167
|
+
const settled = layOut({ view, controls, act, others: [{ id: 'action-overflow:0', kind: 'control', at: { x: 480, y: 190, w: 6, h: 6 } }],
|
|
168
|
+
onLayout: (at) => {Object.assign(at['action-overflow:0'], { x: lane.x + 10, y: lane.y, w: 60, h: 30 });} });
|
|
169
|
+
assert.equal(find(settled.report, 'act-prompt:greeter'), undefined, 'the rail settled onto the lane');
|
|
170
|
+
assert.equal(settled.nodes['act-prompt:greeter'].style.display, 'none');
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// A second act prompt keeps off the first's new place.
|
|
174
|
+
{
|
|
175
|
+
const view = { w: 492, h: 211, insets: { top: 0, right: 0, bottom: 0, left: 0 } };
|
|
176
|
+
const controls = { hud: { x: 154, y: 12, w: 185, h: 25 }, character: { x: 139, y: 164, w: 101, h: 38 } };
|
|
177
|
+
const act = { x: 147, y: 163, w: 208, h: 44 };
|
|
178
|
+
const { report } = layOut({ view, controls, act, acts: { door: { x: 150, y: 160, w: 120, h: 44 } } });
|
|
179
|
+
const a = find(report, 'act-prompt:greeter'), b = find(report, 'act-prompt:door');
|
|
180
|
+
assert(a && b, 'both drawn');
|
|
181
|
+
assert(!overlaps(rectangle(a), rectangle(b)), 'the act prompts do not cover each other');
|
|
182
|
+
clearOfAll(a, controls, 'greeter'); clearOfAll(b, controls, 'door');
|
|
183
|
+
}
|
|
184
|
+
// Review: a pill pushed below a low control and partly out of the view
|
|
185
|
+
// overlaps no band, but is not clear: it takes the lane rule too.
|
|
186
|
+
{
|
|
187
|
+
const view = { w: 492, h: 211, insets: { top: 0, right: 0, bottom: 0, left: 0 } };
|
|
188
|
+
const controls = { hud: { x: 154, y: 12, w: 185, h: 25 }, low: { x: 100, y: 140, w: 300, h: 40 } };
|
|
189
|
+
const { report, nodes } = layOut({ view, controls, act: { x: 147, y: 150, w: 208, h: 44 } });
|
|
190
|
+
const drawn = find(report, 'act-prompt:greeter');
|
|
191
|
+
assert(drawn, 'a lane above the low control fits it');
|
|
192
|
+
assert.notEqual(nodes['act-prompt:greeter'].style.display, 'none');
|
|
193
|
+
assert(drawn.y + drawn.h <= 211 - 6 && drawn.y >= 6, 'whole inside the view');
|
|
194
|
+
clearOfAll(drawn, controls, 'act prompt');
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Review round 2: a two-line 56 px pill pushed below a control ending at
|
|
198
|
+
// y=150 is shortened to 49 px to fit; shortened, it is not clear either.
|
|
199
|
+
{
|
|
200
|
+
const view = { w: 492, h: 211, insets: { top: 0, right: 0, bottom: 0, left: 0 } };
|
|
201
|
+
const controls = { hud: { x: 154, y: 12, w: 185, h: 25 }, low: { x: 100, y: 110, w: 300, h: 40 } };
|
|
202
|
+
const { report } = layOut({ view, controls, act: { x: 147, y: 120, w: 208, h: 56 } });
|
|
203
|
+
const drawn = find(report, 'act-prompt:greeter');
|
|
204
|
+
assert(drawn, 'a lane fits it whole');
|
|
205
|
+
assert.equal(drawn.h, 56, 'not shortened');
|
|
206
|
+
clearOfAll(drawn, controls, 'act prompt');
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// Review: projected world labels and pointers (the world layout pass) make
|
|
210
|
+
// way for the act prompt's held place, not its new lane: a label on the new
|
|
211
|
+
// lane is drawn exactly as when the prompt was still at its old place.
|
|
212
|
+
{
|
|
213
|
+
const rect = (left, top, w, h) => ({ left, top, right: left + w, bottom: top + h, width: w, height: h });
|
|
214
|
+
const node = (at) => ({ style: {}, getBoundingClientRect() {
|
|
215
|
+
const [dx, dy] = (this.style.translate || '0 0').split(' ').map(Number.parseFloat);
|
|
216
|
+
return rect(at.left + dx, at.top + dy, at.width, at.height);
|
|
217
|
+
} });
|
|
218
|
+
const run = (actAt, heldAt) => {
|
|
219
|
+
const label = node(rect(300, 40, 80, 22)), pointer = node(rect(120, 40, 70, 22)), act = node(actAt);
|
|
220
|
+
const entries = [{ kind: 'label', node: label, id: 'label:rowan' }, { kind: 'pointer', node: pointer, id: 'pointer:door' },
|
|
221
|
+
{ kind: 'control', node: act, id: 'act-prompt:greeter', transient: true }];
|
|
222
|
+
const layout = makeWorldLayout(() => entries, () => ({ w: 562, h: 241 }), () => [], undefined, (n) => n === act ? heldAt : null);
|
|
223
|
+
layout.flush();
|
|
224
|
+
return { label: [label.style.translate, label.style.visibility], pointer: [pointer.style.translate, pointer.style.visibility] };
|
|
225
|
+
};
|
|
226
|
+
const old = rect(185, 191, 208, 44);
|
|
227
|
+
const before = run(old, null);
|
|
228
|
+
assert.deepEqual(run(rect(110, 30, 280, 44), old), before, 'labels and pointers placed as before');
|
|
229
|
+
assert.deepEqual(before, { label: [undefined, undefined], pointer: [undefined, undefined] }, 'untouched where clear');
|
|
230
|
+
// A hidden act prompt (no live box) is still made way for at its old place.
|
|
231
|
+
assert.deepEqual(run(rect(0, 0, 0, 0), old), before, 'and while it is not drawn');
|
|
232
|
+
}
|
|
233
|
+
console.log('safe act: the act prompt leaves the controls for the nearest clear lane, or is not drawn; everything else is placed as before');
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { clearPlacement, makeSafeLayout, overlaps, reservedCorners, safePlacement } from '../code/client/safeLayout.js';
|
|
3
|
+
import { fakeDom } from './fixtures/fake-dom.mjs';
|
|
4
|
+
|
|
5
|
+
// The engine's look caption ("2 here · a boat shed") is a full-width line,
|
|
6
|
+
// centred, 22 px off the bottom. On a landscape phone the bottom controls lie
|
|
7
|
+
// across it; `safePlacement` only moves down, so it stayed under them. Its
|
|
8
|
+
// words go to the nearest clear lane, or are not drawn when none fits.
|
|
9
|
+
const rectangle = ({ x, y, w, h }) => ({ left: x, top: y, right: x + w, bottom: y + h });
|
|
10
|
+
const wordsOf = (placed) => rectangle(placed);
|
|
11
|
+
|
|
12
|
+
// 844x390: Doors/People bottom left, 'Actions (2)' and 'Talk to Rowan, the
|
|
13
|
+
// greeter' bottom centre, Character and Act/Jump in the bottom-right column.
|
|
14
|
+
{
|
|
15
|
+
const view = { w: 844, h: 390, insets: { top: 0, right: 0, bottom: 0, left: 0 } };
|
|
16
|
+
const bands = [...reservedCorners(view).map(rectangle),
|
|
17
|
+
rectangle({ x: 10, y: 336, w: 140, h: 44 }), // navigation
|
|
18
|
+
rectangle({ x: 212, y: 336, w: 120, h: 44 }), // Actions (2)
|
|
19
|
+
rectangle({ x: 338, y: 336, w: 220, h: 44 }), // Talk to Rowan, the greeter
|
|
20
|
+
rectangle({ x: 788, y: 282, w: 44, h: 44 }), // Character
|
|
21
|
+
rectangle({ x: 712, y: 332, w: 64, h: 48 }), rectangle({ x: 642, y: 332, w: 64, h: 48 })]; // Act, Jump
|
|
22
|
+
const caption = rectangle({ x: 0, y: 347, w: 844, h: 21 });
|
|
23
|
+
const placed = clearPlacement(caption, view, {}, bands, 140);
|
|
24
|
+
assert(placed, 'a lane is found');
|
|
25
|
+
assert.equal(placed.w, 140, 'narrowed to its words');
|
|
26
|
+
assert.equal(placed.h, 21);
|
|
27
|
+
assert(bands.every((band) => !overlaps(wordsOf(placed), band)), 'words clear of every control');
|
|
28
|
+
assert.equal(placed.y, 336 - 6 - 21, 'the row just above the bottom controls');
|
|
29
|
+
assert.equal(placed.x + placed.w / 2, 422, 'still centred');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 740x360: Character, Jump and Act stand in the bottom-right column and the
|
|
33
|
+
// caption's words ran under them; the dock and an action chip lie left of it.
|
|
34
|
+
{
|
|
35
|
+
const view = { w: 740, h: 360, insets: { top: 0, right: 0, bottom: 0, left: 0 } };
|
|
36
|
+
const bands = [...reservedCorners(view).map(rectangle),
|
|
37
|
+
rectangle({ x: 10, y: 306, w: 140, h: 44 }), // navigation
|
|
38
|
+
rectangle({ x: 160, y: 306, w: 200, h: 44 }), // Talk to Rowan
|
|
39
|
+
rectangle({ x: 684, y: 252, w: 44, h: 44 }), // Character
|
|
40
|
+
rectangle({ x: 608, y: 302, w: 64, h: 48 }), rectangle({ x: 538, y: 302, w: 64, h: 48 }), // Act, Jump
|
|
41
|
+
rectangle({ x: 370, y: 306, w: 160, h: 44 })]; // + Party
|
|
42
|
+
const caption = rectangle({ x: 0, y: 317, w: 740, h: 21 });
|
|
43
|
+
const placed = clearPlacement(caption, view, {}, bands, 180);
|
|
44
|
+
assert(placed);
|
|
45
|
+
assert.equal(placed.w, 180);
|
|
46
|
+
assert(bands.every((band) => !overlaps(wordsOf(placed), band)), 'words clear of Character, Jump and Act');
|
|
47
|
+
assert.equal(placed.y, 306 - 6 - 21, 'the row just above the controls it crossed');
|
|
48
|
+
assert.equal(placed.x + placed.w / 2, 370, 'still centred');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Words already clear keep `safePlacement` exactly (a desktop view: the
|
|
52
|
+
// controls sit either side of the centred words).
|
|
53
|
+
{
|
|
54
|
+
const view = { w: 1440, h: 900, insets: { top: 0, right: 0, bottom: 0, left: 0 } };
|
|
55
|
+
const bands = [rectangle({ x: 10, y: 846, w: 300, h: 44 }), rectangle({ x: 1200, y: 800, w: 230, h: 90 })];
|
|
56
|
+
const caption = rectangle({ x: 0, y: 857, w: 1440, h: 21 });
|
|
57
|
+
assert.deepEqual(clearPlacement(caption, view, {}, bands, 160), safePlacement(caption, view, {}, bands));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// No lane wide enough anywhere: not drawn.
|
|
61
|
+
{
|
|
62
|
+
const view = { w: 400, h: 200, insets: { top: 0, right: 0, bottom: 0, left: 0 } };
|
|
63
|
+
const bands = [rectangle({ x: 0, y: 0, w: 120, h: 200 }), rectangle({ x: 230, y: 0, w: 170, h: 200 })];
|
|
64
|
+
assert.equal(clearPlacement(rectangle({ x: 0, y: 160, w: 400, h: 21 }), view, {}, bands, 150), null);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// The controller narrows and moves the engine's caption node (outside the
|
|
68
|
+
// chrome root), and hides it while no lane fits; the next pass restores it.
|
|
69
|
+
{
|
|
70
|
+
const dom = fakeDom({ viewW: 844, viewH: 390 });
|
|
71
|
+
const root = document.createElement('div'); dom.body.append(root);
|
|
72
|
+
root.contains = (node) => { for (let p = node; p; p = p.parent) {if (p === root) {return true;}} return false; };
|
|
73
|
+
const box = (node, at) => {
|
|
74
|
+
node.getBoundingClientRect = () => {
|
|
75
|
+
const [dx, dy] = (node.style.translate || '0 0').split(' ').map(Number.parseFloat);
|
|
76
|
+
const w = Math.min(at.w, Number.parseFloat(node.style.maxWidth) || Infinity);
|
|
77
|
+
return { ...rectangle({ x: at.x + dx, y: at.y + dy, w, h: at.h }), width: w, height: at.h };
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
const talk = document.createElement('button'); root.append(talk);
|
|
81
|
+
const title = document.createElement('div'); root.append(title);
|
|
82
|
+
box(title, { x: 200, y: 8, w: 444, h: 44 });
|
|
83
|
+
const look = document.createElement('div'); dom.body.append(look);
|
|
84
|
+
look.ownerDocument = { createRange: () => ({ selectNodeContents() {}, getBoundingClientRect: () => ({ width: 138 }) }) };
|
|
85
|
+
const talkAt = { x: 338, y: 336, w: 220, h: 44 };
|
|
86
|
+
box(talk, talkAt); box(look, { x: 0, y: 347, w: 844, h: 21 });
|
|
87
|
+
const previous = globalThis.getComputedStyle;
|
|
88
|
+
globalThis.getComputedStyle = (element) => ({ ...element.style, paddingLeft: '0px', paddingRight: '0px', paddingTop: '0px', paddingBottom: '0px' });
|
|
89
|
+
try {
|
|
90
|
+
const controller = makeSafeLayout({ root, hud: () => title, entries: () => [{ id: 'talk', node: talk, kind: 'control' },
|
|
91
|
+
{ id: 'engine-look', node: look, kind: 'text', transient: true }] });
|
|
92
|
+
const report = controller.report();
|
|
93
|
+
const caption = report.boxes.find((b) => b.id === 'engine-look');
|
|
94
|
+
assert.deepEqual(caption, { id: 'engine-look', kind: 'text', x: 352, y: 309, w: 140, h: 21 });
|
|
95
|
+
assert(!overlaps(rectangle(caption), rectangle(report.boxes.find((b) => b.id === 'talk'))));
|
|
96
|
+
// The talk button grows to fill every row under the HUD title and the
|
|
97
|
+
// host's corners: nowhere is left.
|
|
98
|
+
Object.assign(talkAt, { x: 6, y: 62, w: 832, h: 322 });
|
|
99
|
+
assert.equal(controller.report().boxes.find((b) => b.id === 'engine-look'), undefined);
|
|
100
|
+
assert.equal(look.style.display, 'none');
|
|
101
|
+
Object.assign(talkAt, { x: 338, y: 336, w: 220, h: 44 });
|
|
102
|
+
assert.deepEqual(controller.report().boxes.find((b) => b.id === 'engine-look'), caption, 'drawn again where a lane fits');
|
|
103
|
+
assert.notEqual(look.style.display, 'none');
|
|
104
|
+
controller.dispose();
|
|
105
|
+
} finally {
|
|
106
|
+
if (previous === undefined) {delete globalThis.getComputedStyle;} else {globalThis.getComputedStyle = previous;}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// Only the transient caption family, the toast and the result ribbon move by
|
|
110
|
+
// this rule. A world label, a pointer and the action chips over the same
|
|
111
|
+
// controls, with no lane left anywhere, are placed exactly as `safePlacement`
|
|
112
|
+
// places them and are never hidden; the toast and the ribbon, like the
|
|
113
|
+
// caption, are not drawn while no lane fits their whole pill.
|
|
114
|
+
{
|
|
115
|
+
const dom = fakeDom({ viewW: 844, viewH: 390 });
|
|
116
|
+
const root = document.createElement('div'); dom.body.append(root);
|
|
117
|
+
root.contains = (node) => { for (let p = node; p; p = p.parent) {if (p === root) {return true;}} return false; };
|
|
118
|
+
const box = (node, at) => {
|
|
119
|
+
node.getBoundingClientRect = () => {
|
|
120
|
+
const [dx, dy] = (node.style.translate || '0 0').split(' ').map(Number.parseFloat);
|
|
121
|
+
const w = Math.min(at.w, Number.parseFloat(node.style.maxWidth) || Infinity);
|
|
122
|
+
return { ...rectangle({ x: at.x + dx, y: at.y + dy, w, h: at.h }), width: w, height: at.h };
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
const view = { w: 844, h: 390, insets: { top: 0, right: 0, bottom: 0, left: 0 } };
|
|
126
|
+
const title = document.createElement('div'); root.append(title); box(title, { x: 200, y: 8, w: 444, h: 44 });
|
|
127
|
+
const wall = document.createElement('button'); root.append(wall); box(wall, { x: 6, y: 62, w: 832, h: 322 });
|
|
128
|
+
const others = [
|
|
129
|
+
{ id: 'label:rowan', kind: 'label', transient: true, at: { x: 300, y: 200, w: 160, h: 24 } },
|
|
130
|
+
{ id: 'pointer:door', kind: 'pointer', transient: true, at: { x: 500, y: 150, w: 120, h: 30 } },
|
|
131
|
+
{ id: 'toast', kind: 'toast', transient: true, margin: { top: 12 }, at: { x: 250, y: 300, w: 340, h: 36 } },
|
|
132
|
+
{ id: 'ribbon', kind: 'ribbon', transient: true, at: { x: 100, y: 250, w: 640, h: 40 } },
|
|
133
|
+
{ id: 'actions', kind: 'control', at: { x: 212, y: 336, w: 346, h: 44 } },
|
|
134
|
+
].map((entry) => {
|
|
135
|
+
const node = document.createElement('div'); root.append(node); box(node, entry.at);
|
|
136
|
+
return { ...entry, node };
|
|
137
|
+
});
|
|
138
|
+
const look = document.createElement('div'); dom.body.append(look); box(look, { x: 0, y: 347, w: 844, h: 21 });
|
|
139
|
+
const previous = globalThis.getComputedStyle;
|
|
140
|
+
globalThis.getComputedStyle = (element) => ({ ...element.style, paddingLeft: '0px', paddingRight: '0px', paddingTop: '0px', paddingBottom: '0px' });
|
|
141
|
+
try {
|
|
142
|
+
const controller = makeSafeLayout({ root, hud: () => title, entries: () => [{ id: 'wall', node: wall, kind: 'control' },
|
|
143
|
+
...others.map(({ at, ...entry }) => entry), { id: 'engine-look', node: look, kind: 'text', transient: true }] });
|
|
144
|
+
const report = controller.report();
|
|
145
|
+
assert.equal(look.style.display, 'none', 'the caption, with no lane, is hidden');
|
|
146
|
+
for (const entry of others.filter((other) => other.kind === 'toast' || other.kind === 'ribbon')) {
|
|
147
|
+
assert.equal(entry.node.style.display, 'none', `${entry.id}, with no lane, is hidden`);
|
|
148
|
+
}
|
|
149
|
+
for (const entry of others.filter((other) => other.kind !== 'toast' && other.kind !== 'ribbon')) {
|
|
150
|
+
assert.notEqual(entry.node.style.display, 'none', `${entry.id} is never hidden`);
|
|
151
|
+
const drawn = report.boxes.find((b) => b.id === entry.id);
|
|
152
|
+
assert(drawn, `${entry.id} is drawn`);
|
|
153
|
+
assert.notEqual(drawn.w, 140, `${entry.id} is not narrowed to words`);
|
|
154
|
+
}
|
|
155
|
+
// Each is where the old rule put it: safePlacement against the same bands.
|
|
156
|
+
const label = others[0];
|
|
157
|
+
const drawnLabel = report.boxes.find((b) => b.id === label.id);
|
|
158
|
+
const bands = [...reservedCorners(view).map(rectangle), rectangle({ x: 200, y: 8, w: 444, h: 44 }),
|
|
159
|
+
...report.boxes.filter((b) => b.id === 'wall' || b.id === 'actions').map(rectangle)];
|
|
160
|
+
const old = safePlacement(rectangle(label.at), view, {}, bands);
|
|
161
|
+
assert.deepEqual({ x: drawnLabel.x, y: drawnLabel.y }, { x: old.x, y: old.y }, 'a world label keeps the old placement');
|
|
162
|
+
controller.dispose();
|
|
163
|
+
} finally {
|
|
164
|
+
if (previous === undefined) {delete globalThis.getComputedStyle;} else {globalThis.getComputedStyle = previous;}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
// Review: a caption narrowed to a lane narrower than its words wraps taller;
|
|
168
|
+
// the lane is chosen again for that height (never clipped by maxHeight), and
|
|
169
|
+
// a rail that settles onto the caption after placement hides it for that pass
|
|
170
|
+
// only, the next pass placing it around the settled rail.
|
|
171
|
+
{
|
|
172
|
+
const dom = fakeDom({ viewW: 844, viewH: 390 });
|
|
173
|
+
const root = document.createElement('div'); dom.body.append(root);
|
|
174
|
+
root.contains = (node) => { for (let p = node; p; p = p.parent) {if (p === root) {return true;}} return false; };
|
|
175
|
+
const box = (node, at, height = () => at.h) => {
|
|
176
|
+
node.getBoundingClientRect = () => {
|
|
177
|
+
const [dx, dy] = (node.style.translate || '0 0').split(' ').map(Number.parseFloat);
|
|
178
|
+
const w = Math.min(at.w, Number.parseFloat(node.style.maxWidth) || Infinity);
|
|
179
|
+
const h = height(w);
|
|
180
|
+
return { ...rectangle({ x: at.x + dx, y: at.y + dy, w, h }), width: w, height: h };
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
const previous = globalThis.getComputedStyle;
|
|
184
|
+
globalThis.getComputedStyle = (element) => ({ ...element.style, paddingLeft: '0px', paddingRight: '0px', paddingTop: '0px', paddingBottom: '0px' });
|
|
185
|
+
try {
|
|
186
|
+
const talk = document.createElement('button'); root.append(talk); box(talk, { x: 338, y: 336, w: 220, h: 44 });
|
|
187
|
+
const look = document.createElement('div'); dom.body.append(look);
|
|
188
|
+
look.ownerDocument = { createRange: () => ({ selectNodeContents() {}, getBoundingClientRect: () => ({ width: 900 }) }) };
|
|
189
|
+
box(look, { x: 0, y: 347, w: 844, h: 21 }, (w) => w < 844 ? 42 : 21);
|
|
190
|
+
const controller = makeSafeLayout({ root, entries: () => [{ id: 'talk', node: talk, kind: 'control' },
|
|
191
|
+
{ id: 'engine-look', node: look, kind: 'text', transient: true }] });
|
|
192
|
+
const wrapped = controller.report().boxes.find((b) => b.id === 'engine-look');
|
|
193
|
+
assert.equal(look.style.maxHeight ?? '', '', 'not clipped');
|
|
194
|
+
assert.deepEqual(wrapped, { id: 'engine-look', kind: 'text', x: 6, y: 336 - 6 - 42, w: 832, h: 42 });
|
|
195
|
+
controller.dispose();
|
|
196
|
+
} finally {
|
|
197
|
+
if (previous === undefined) {delete globalThis.getComputedStyle;} else {globalThis.getComputedStyle = previous;}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
{
|
|
201
|
+
const dom = fakeDom({ viewW: 844, viewH: 390 });
|
|
202
|
+
const root = document.createElement('div'); dom.body.append(root);
|
|
203
|
+
root.contains = (node) => { for (let p = node; p; p = p.parent) {if (p === root) {return true;}} return false; };
|
|
204
|
+
const box = (node, at) => {
|
|
205
|
+
node.getBoundingClientRect = () => {
|
|
206
|
+
const [dx, dy] = (node.style.translate || '0 0').split(' ').map(Number.parseFloat);
|
|
207
|
+
const w = Math.min(at.w, Number.parseFloat(node.style.maxWidth) || Infinity);
|
|
208
|
+
return { ...rectangle({ x: at.x + dx, y: at.y + dy, w, h: at.h }), width: w, height: at.h };
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
const previous = globalThis.getComputedStyle;
|
|
212
|
+
globalThis.getComputedStyle = (element) => ({ ...element.style, paddingLeft: '0px', paddingRight: '0px', paddingTop: '0px', paddingBottom: '0px' });
|
|
213
|
+
try {
|
|
214
|
+
const talk = document.createElement('button'); root.append(talk); box(talk, { x: 338, y: 336, w: 220, h: 44 });
|
|
215
|
+
const rail = document.createElement('div'); root.append(rail);
|
|
216
|
+
const railAt = { x: 600, y: 120, w: 100, h: 44 }; box(rail, railAt);
|
|
217
|
+
const look = document.createElement('div'); dom.body.append(look);
|
|
218
|
+
look.ownerDocument = { createRange: () => ({ selectNodeContents() {}, getBoundingClientRect: () => ({ width: 138 }) }) };
|
|
219
|
+
box(look, { x: 0, y: 347, w: 844, h: 21 });
|
|
220
|
+
// The rail settles onto the row the caption chose (309..330).
|
|
221
|
+
const onLayout = () => {Object.assign(railAt, { x: 380, y: 300, w: 100, h: 30 });};
|
|
222
|
+
const controller = makeSafeLayout({ root, onLayout, entries: () => [{ id: 'talk', node: talk, kind: 'control' },
|
|
223
|
+
{ id: 'action-overflow:0', node: rail, kind: 'control' }, { id: 'engine-look', node: look, kind: 'text', transient: true }] });
|
|
224
|
+
assert.equal(controller.report().boxes.find((b) => b.id === 'engine-look'), undefined, 'covered by the settled rail: not drawn');
|
|
225
|
+
assert.equal(look.style.display, 'none');
|
|
226
|
+
const next = controller.report().boxes.find((b) => b.id === 'engine-look');
|
|
227
|
+
assert(next, 'the next pass draws it');
|
|
228
|
+
assert(!overlaps(rectangle(next), rectangle(railAt)) && !overlaps(rectangle(next), rectangle({ x: 338, y: 336, w: 220, h: 44 })), 'around the settled rail');
|
|
229
|
+
controller.dispose();
|
|
230
|
+
} finally {
|
|
231
|
+
if (previous === undefined) {delete globalThis.getComputedStyle;} else {globalThis.getComputedStyle = previous;}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
// The embedded Town at 844x390 (the deck about 562x240 inside the page),
|
|
235
|
+
// back from a scored door: the result ribbon over the player and the
|
|
236
|
+
// "Back from" toast were only pushed down, onto Jump, the caption and each
|
|
237
|
+
// other. Each pill now keeps its whole box clear of the controls, the
|
|
238
|
+
// last-played card, the HUD and the other pill, or is not drawn.
|
|
239
|
+
{
|
|
240
|
+
const dom = fakeDom({ viewW: 562, viewH: 240 });
|
|
241
|
+
const root = document.createElement('div'); dom.body.append(root);
|
|
242
|
+
root.contains = (node) => { for (let p = node; p; p = p.parent) {if (p === root) {return true;}} return false; };
|
|
243
|
+
const box = (node, at) => {
|
|
244
|
+
node.getBoundingClientRect = () => {
|
|
245
|
+
const [dx, dy] = (node.style.translate || '0 0').split(' ').map(Number.parseFloat);
|
|
246
|
+
const w = Math.min(at.w, Number.parseFloat(node.style.maxWidth) || Infinity);
|
|
247
|
+
return { ...rectangle({ x: at.x + dx, y: at.y + dy, w, h: at.h }), width: w, height: at.h };
|
|
248
|
+
};
|
|
249
|
+
};
|
|
250
|
+
const previous = globalThis.getComputedStyle;
|
|
251
|
+
globalThis.getComputedStyle = (element) => ({ ...element.style, paddingLeft: '0px', paddingRight: '0px', paddingTop: '0px', paddingBottom: '0px' });
|
|
252
|
+
try {
|
|
253
|
+
const made = (at, parent = root) => {const node = document.createElement('div'); parent.append(node); box(node, at); return node;};
|
|
254
|
+
const title = made({ x: 216, y: 12, w: 130, h: 26 });
|
|
255
|
+
const controls = [
|
|
256
|
+
['card', { x: 152, y: 52, w: 352, h: 48 }, 'card'], // ♥ Color Call · Go · Not now
|
|
257
|
+
['people', { x: 10, y: 120, w: 100, h: 36 }], ['doors', { x: 10, y: 162, w: 76, h: 36 }],
|
|
258
|
+
['character', { x: 400, y: 140, w: 100, h: 36 }], ['emote', { x: 508, y: 138, w: 44, h: 44 }],
|
|
259
|
+
['jump', { x: 368, y: 184, w: 62, h: 46 }], ['act', { x: 438, y: 184, w: 62, h: 46 }], ['chat', { x: 508, y: 188, w: 44, h: 44 }],
|
|
260
|
+
].map(([id, at, kind = 'control']) => ({ id, kind, node: made(at), at }));
|
|
261
|
+
const toast = made({ x: 141, y: 190, w: 280, h: 30 });
|
|
262
|
+
const ribbon = made({ x: 195, y: 205, w: 170, h: 24 });
|
|
263
|
+
const controller = makeSafeLayout({ root, hud: () => title, entries: () => [
|
|
264
|
+
{ id: 'hud', node: title, kind: 'hud', margin: { top: 12 } }, ...controls,
|
|
265
|
+
{ id: 'toast', node: toast, kind: 'toast', transient: true, margin: { top: 12 } },
|
|
266
|
+
{ id: 'ribbon', node: ribbon, kind: 'ribbon', transient: true }] });
|
|
267
|
+
const report = controller.report();
|
|
268
|
+
const drawn = ['toast', 'ribbon'].map((id) => report.boxes.find((b) => b.id === id)).filter(Boolean);
|
|
269
|
+
assert(drawn.length, 'at least one pill finds a lane');
|
|
270
|
+
for (const pill of drawn) {
|
|
271
|
+
for (const other of report.boxes.filter((b) => b.id !== pill.id)) {
|
|
272
|
+
assert(!overlaps(rectangle(pill), rectangle(other)), `${pill.id} clear of ${other.id}`);
|
|
273
|
+
}
|
|
274
|
+
assert(pill.w === (pill.id === 'toast' ? 280 : 170), `${pill.id} keeps its whole pill`);
|
|
275
|
+
}
|
|
276
|
+
for (const id of ['toast', 'ribbon']) {
|
|
277
|
+
const node = id === 'toast' ? toast : ribbon;
|
|
278
|
+
assert.equal(Boolean(report.boxes.find((b) => b.id === id)), node.style.display !== 'none', `${id} drawn or hidden, never under a control`);
|
|
279
|
+
}
|
|
280
|
+
controller.dispose();
|
|
281
|
+
} finally {
|
|
282
|
+
if (previous === undefined) {delete globalThis.getComputedStyle;} else {globalThis.getComputedStyle = previous;}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
console.log('safe caption: transient text, the toast and the ribbon leave the controls for the nearest clear lane at 844x390, 740x360 and the embedded view, or are not drawn');
|
|
286
|
+
|
|
287
|
+
// The Town in a standalone page at 844x390 (Oct 25, #4469): the deck's stage
|
|
288
|
+
// is a card inset 20 px, which clips the engine's caption, while the chrome
|
|
289
|
+
// is the whole page. The caption took the row under the prompt, 363-384,
|
|
290
|
+
// below the card's edge at 370, and its words were cut off; its full-width
|
|
291
|
+
// box also spanned Quick chat. It now keeps inside the card, and its box is
|
|
292
|
+
// its words.
|
|
293
|
+
{
|
|
294
|
+
const dom = fakeDom({ viewW: 844, viewH: 390 });
|
|
295
|
+
const root = document.createElement('div'); dom.body.append(root);
|
|
296
|
+
root.contains = (node) => { for (let p = node; p; p = p.parent) {if (p === root) {return true;}} return false; };
|
|
297
|
+
const box = (node, at) => {
|
|
298
|
+
node.getBoundingClientRect = () => {
|
|
299
|
+
const [dx, dy] = (node.style.translate || '0 0').split(' ').map(Number.parseFloat);
|
|
300
|
+
const w = Math.min(at.w, Number.parseFloat(node.style.maxWidth) || Infinity);
|
|
301
|
+
return { ...rectangle({ x: at.x + dx, y: at.y + dy, w, h: at.h }), width: w, height: at.h };
|
|
302
|
+
};
|
|
303
|
+
};
|
|
304
|
+
const title = document.createElement('div'); root.append(title); box(title, { x: 312, y: 12, w: 220, h: 30 });
|
|
305
|
+
const say = document.createElement('button'); root.append(say); box(say, { x: 788, y: 336, w: 44, h: 44 });
|
|
306
|
+
const prompt = document.createElement('div'); root.append(prompt); box(prompt, { x: 272, y: 290, w: 300, h: 26 });
|
|
307
|
+
const card = document.createElement('div'); dom.body.append(card); card.style.overflow = 'hidden';
|
|
308
|
+
card.getBoundingClientRect = () => ({ ...rectangle({ x: 20, y: 20, w: 804, h: 350 }), width: 804, height: 350 });
|
|
309
|
+
const look = document.createElement('div'); card.append(look); look.style.textAlign = 'center';
|
|
310
|
+
look.ownerDocument = { body: dom.body, createRange: () => ({ selectNodeContents() {}, getBoundingClientRect: () => ({ width: 360 }) }) };
|
|
311
|
+
box(look, { x: 20, y: 327, w: 804, h: 21 });
|
|
312
|
+
const previous = globalThis.getComputedStyle;
|
|
313
|
+
globalThis.getComputedStyle = (element) => ({ ...element.style, paddingLeft: '0px', paddingRight: '0px', paddingTop: '0px', paddingBottom: '0px' });
|
|
314
|
+
try {
|
|
315
|
+
const controller = makeSafeLayout({ root, hud: () => title, entries: () => [{ id: 'quick-chat', node: say, kind: 'control' },
|
|
316
|
+
{ id: 'hud-prompt', node: prompt, kind: 'control' }, { id: 'engine-look', node: look, kind: 'text', transient: true }] });
|
|
317
|
+
const report = controller.report();
|
|
318
|
+
const caption = report.boxes.find((b) => b.id === 'engine-look');
|
|
319
|
+
assert(caption, 'the caption is drawn');
|
|
320
|
+
assert(caption.y >= 26 && caption.y + caption.h <= 364, 'inside the card, not cut off at its edge');
|
|
321
|
+
for (const id of ['quick-chat', 'hud-prompt']) {
|
|
322
|
+
assert(!overlaps(rectangle(caption), rectangle(report.boxes.find((b) => b.id === id))), `its box is clear of ${id}`);
|
|
323
|
+
}
|
|
324
|
+
assert.equal(caption.x + caption.w / 2, 422, 'still centred');
|
|
325
|
+
controller.dispose();
|
|
326
|
+
} finally {
|
|
327
|
+
if (previous === undefined) {delete globalThis.getComputedStyle;} else {globalThis.getComputedStyle = previous;}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// A 179x250 game view (castle.xyz in a short desktop window, Nestlings RPG):
|
|
332
|
+
// the centred HUD lay under Sound at the right edge. With `hub.safeInsets` it
|
|
333
|
+
// is laid out in the lane left of the control, under the host's corner where
|
|
334
|
+
// the lane beside the corner is too narrow.
|
|
335
|
+
{
|
|
336
|
+
const dom = fakeDom({ viewW: 179, viewH: 250 });
|
|
337
|
+
globalThis.innerWidth = 179; globalThis.innerHeight = 250;
|
|
338
|
+
const root = document.createElement('div'); dom.body.append(root);
|
|
339
|
+
root.contains = (node) => { for (let p = node; p; p = p.parent) {if (p === root) {return true;}} return false; };
|
|
340
|
+
const box = (node, at) => {
|
|
341
|
+
node.getBoundingClientRect = () => {
|
|
342
|
+
const [dx, dy] = (node.style.translate || '0 0').split(' ').map(Number.parseFloat);
|
|
343
|
+
const w = Math.min(at.w, Number.parseFloat(node.style.maxWidth) || Infinity);
|
|
344
|
+
return { ...rectangle({ x: at.x + dx, y: at.y + dy, w, h: at.h }), width: w, height: at.h };
|
|
345
|
+
};
|
|
346
|
+
};
|
|
347
|
+
const hud = document.createElement('div'); root.append(hud); box(hud, { x: 27, y: 12, w: 125, h: 90 });
|
|
348
|
+
const sound = document.createElement('button'); root.append(sound); box(sound, { x: 127, y: 64, w: 40, h: 40 });
|
|
349
|
+
const previous = globalThis.getComputedStyle;
|
|
350
|
+
globalThis.getComputedStyle = (element) => ({ ...element.style, paddingLeft: '0px', paddingRight: '0px', paddingTop: '0px', paddingBottom: '0px' });
|
|
351
|
+
try {
|
|
352
|
+
const controller = makeSafeLayout({ root, hud: () => hud, entries: () => [{ id: 'hud', node: hud, kind: 'hud', margin: { top: 12 } },
|
|
353
|
+
{ id: 'sound', node: sound, kind: 'control', margin: { right: 12, top: 64 } }] });
|
|
354
|
+
const report = controller.report();
|
|
355
|
+
const placed = report.boxes.find((b) => b.id === 'hud'), control = report.boxes.find((b) => b.id === 'sound');
|
|
356
|
+
assert(placed && control);
|
|
357
|
+
assert(!overlaps(rectangle(placed), rectangle(control)), 'the HUD is clear of Sound');
|
|
358
|
+
assert(placed.x >= 6 && placed.x + placed.w <= control.x - 6 + 0.5, 'in the lane left of it');
|
|
359
|
+
assert(placed.y >= 62, "under the host's corner");
|
|
360
|
+
controller.dispose();
|
|
361
|
+
} finally {
|
|
362
|
+
if (previous === undefined) {delete globalThis.getComputedStyle;} else {globalThis.getComputedStyle = previous;}
|
|
363
|
+
}
|
|
364
|
+
}
|