castle-web-cli 0.4.239 → 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 +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/platformDoc.js +2 -1
- package/dist/playPagePolicy.js +5 -1
- package/dist/resetLeaderboards.d.ts +8 -1
- package/dist/resetLeaderboards.js +43 -8
- 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 +473 -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/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 +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 +851 -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/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/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 +427 -54
- package/kits/hub-game/docs/analytics.md +16 -2
- 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 +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 +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-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-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-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-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-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 +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
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
// Quick chat (contract v1.11 reactions and phrases, v1.12 typed chat) as a
|
|
2
|
+
// UI tree (schema v0): what `chrome.js` `setSay`, `setFeed` and
|
|
3
|
+
// `setChatModeration` draw in the DOM -- the round 💬 "Quick chat" button,
|
|
4
|
+
// the card it opens (a row of reaction emoji, the place's phrases, and where
|
|
5
|
+
// the host has chat the note line and the typed-chat field with Send), and
|
|
6
|
+
// the feed of what was just said, where another player's chat line asks
|
|
7
|
+
// whether to report it (and block, where the scene opts in to moderation).
|
|
8
|
+
// The same words, labels and states. Pure: no DOM, no window; the web chrome
|
|
9
|
+
// still draws its own DOM.
|
|
10
|
+
//
|
|
11
|
+
// state = {
|
|
12
|
+
// view: { landscape, safeInsets, lift, slot } (CSS px): `lift` the shift
|
|
13
|
+
// lock's reserve under the corner (chrome.js `lockLift`), `slot`
|
|
14
|
+
// null or the button's place { right, bottom, width } in a
|
|
15
|
+
// landscape rail the host laid out (chrome.js
|
|
16
|
+
// `layoutLandscapeRail`) or, upright in a safe-inset place, in
|
|
17
|
+
// the corner column its safe layout stacked (`stackPlacement`);
|
|
18
|
+
// an upright slot without safe insets is not read;
|
|
19
|
+
// say: null (no button) or what `setSay` takes: { reactions: [emoji],
|
|
20
|
+
// phrases: [[id, words]], chat: null | { input, note, placeholder?,
|
|
21
|
+
// label? } };
|
|
22
|
+
// open: the card is open;
|
|
23
|
+
// covered: the Character sheet is open (the button is out of sight, the
|
|
24
|
+
// card shut);
|
|
25
|
+
// field: { value, ver, focus }: the chat field's words as of its version
|
|
26
|
+
// `ver` (a renderer applies `value` only when `ver` moves) and its
|
|
27
|
+
// focus request (a positive count focuses, a negative one blurs);
|
|
28
|
+
// feed: { lines: [{ text, id, userId? }], moderation, hidden,
|
|
29
|
+
// confirming: [id], reported: [id] }: the lines oldest first (an
|
|
30
|
+
// `id` is another player's chat line, which can be reported),
|
|
31
|
+
// `moderation` the scene's opt-in to Report & block, `hidden` a
|
|
32
|
+
// Doors or People list is open, `confirming` the lines tapped and
|
|
33
|
+
// asking "Report this message?", `reported` the lines reported
|
|
34
|
+
// (gone until the feed changes);
|
|
35
|
+
// }
|
|
36
|
+
// on = { toggle(), close(), react(index), phrase(id), input(e), submit(e),
|
|
37
|
+
// send(), focus(), blur(), ask(id), report(id), block(id),
|
|
38
|
+
// unask(id) }.
|
|
39
|
+
import { h } from './uiTree.js';
|
|
40
|
+
|
|
41
|
+
const ROUND = { box: 'border', pad: 0, border: { w: 2, c: 'rgba(255,255,255,0.5)' }, bg: 'copy', color: '#fff', size: 22, weight: 400, lh: 'normal' };
|
|
42
|
+
// chrome.js `smallButton`, plain and primary.
|
|
43
|
+
const SMALL = { pad: [5, 12], radius: 12, border: { w: 1, c: 'line35' }, bg: 'transparent', color: '#fff', size: 13, weight: 700, lh: 'normal' };
|
|
44
|
+
const PRIMARY = { ...SMALL, border: 'none', bg: 'gold', color: 'onGold' };
|
|
45
|
+
// An edge kept clear of the safe area only where the place asks for it.
|
|
46
|
+
const edge = (safeInsets, px) => (safeInsets ? [px, 0] : px);
|
|
47
|
+
|
|
48
|
+
// The words the field shows with none typed, and its spoken label (only a
|
|
49
|
+
// chat part that names its own placeholder gives one, as the DOM's).
|
|
50
|
+
export const chatPlaceholder = (chat) => chat?.placeholder ?? 'Message…';
|
|
51
|
+
export const chatLabel = (chat) => (chat?.placeholder ? chat.label ?? chat.placeholder : undefined);
|
|
52
|
+
|
|
53
|
+
// What decides whether the DOM rebuilds the card (and so drops a line being
|
|
54
|
+
// typed): the reactions, the phrase ids, and whether chat is there and usable.
|
|
55
|
+
export const sayKey = (say) => (say ? `${say.reactions.join('')}|${say.phrases.map(([id]) => id).join(',')}|${say.chat ? (say.chat.input ? 1 : 0) : '-'}` : '');
|
|
56
|
+
|
|
57
|
+
// Where the button and the card stand: the corner stack (portrait, or a
|
|
58
|
+
// landscape view whose rail the host did not lay out) or the host's rail slot.
|
|
59
|
+
export function quickChatPlace(view = {}) {
|
|
60
|
+
const lift = Number(view.lift) || 0;
|
|
61
|
+
const given = view.slot && Number.isFinite(view.slot.right) && Number.isFinite(view.slot.bottom) ? view.slot : null;
|
|
62
|
+
if (given && view.safeInsets && !view.landscape) {
|
|
63
|
+
// Upright in a safe-inset place, chrome.js's safe layout stacks the
|
|
64
|
+
// corner's round buttons in one bottom-up column (`stackPlacement`), 💬
|
|
65
|
+
// lowest, so the button no longer stands at its own corner spot. The
|
|
66
|
+
// host's box for it is that placement, safe area included, kept to its
|
|
67
|
+
// bottom right corner. The card is not moved with it: the safe layout
|
|
68
|
+
// places it as a card, from its own corner spot moved only clear of the
|
|
69
|
+
// other controls, as the emote row's.
|
|
70
|
+
return {
|
|
71
|
+
button: { anchor: 'bottomRight', right: given.right, bottom: given.bottom },
|
|
72
|
+
card: { anchor: 'bottomRight', right: edge(true, 80), bottom: [146 + lift, 136 + lift], ime: true },
|
|
73
|
+
cardMaxH: null,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const slot = view.landscape ? given : null;
|
|
77
|
+
if (slot) {
|
|
78
|
+
// The host's box is measured on the page, so it already stands where the
|
|
79
|
+
// chrome put it, any safe area included: taken as it is, never as an edge
|
|
80
|
+
// the safe area would lift again.
|
|
81
|
+
const bottom = slot.bottom;
|
|
82
|
+
return {
|
|
83
|
+
button: { anchor: 'bottomRight', right: slot.right, bottom },
|
|
84
|
+
card: { anchor: 'bottomRight', right: Math.max(184, slot.right + (Number(slot.width) || 0) + 6), bottom, ime: true },
|
|
85
|
+
// Below the card is the measured slot, safe area included: only the
|
|
86
|
+
// top's safe area is taken off again.
|
|
87
|
+
cardMaxH: [{ dvh: 100, px: -(slot.bottom + 12), safe: 't' }],
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
const safe = Boolean(view.safeInsets);
|
|
91
|
+
return {
|
|
92
|
+
button: { anchor: 'bottomRight', right: edge(safe, view.landscape ? 18 : 20), bottom: [206 + lift, 196 + lift] },
|
|
93
|
+
card: { anchor: 'bottomRight', right: edge(safe, view.landscape ? 68 : 80), bottom: [146 + lift, 136 + lift], ime: true },
|
|
94
|
+
cardMaxH: view.landscape ? [{ dvh: 100, px: -24, safe: 'tb' }] : null,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function chatLine(chat, field, on) {
|
|
99
|
+
const enabled = chat.input === true;
|
|
100
|
+
return [
|
|
101
|
+
h('text', { key: 'note', text: String(chat.note ?? ''), style: { size: 11, weight: 500, opacity: 0.7 } }),
|
|
102
|
+
h('row', { key: 'line', style: { gap: 6, opacity: enabled ? 1 : 0.5 } },
|
|
103
|
+
h('field', {
|
|
104
|
+
key: 'message', name: 'message', label: chatLabel(chat),
|
|
105
|
+
value: String(field?.value ?? ''), ver: Number(field?.ver) || 0, focus: Number(field?.focus) || 0,
|
|
106
|
+
ph: chatPlaceholder(chat), max: 200, maxUnit: 'utf16', enter: 'send', cap: 'sentences', spell: true,
|
|
107
|
+
// Shown even when it cannot be used, so chat can be found; the note says why.
|
|
108
|
+
disabled: !enabled,
|
|
109
|
+
style: { flex: 1, minW: 0, pad: [7, 9], radius: 8, border: { w: 1, c: 'fieldLine' }, bg: 'field', color: '#fff', size: 14, weight: 500, lh: 'normal' },
|
|
110
|
+
on: enabled ? { input: on.input, submit: on.submit, cancel: on.close, focus: on.focus, blur: on.blur } : undefined,
|
|
111
|
+
}),
|
|
112
|
+
h('button', {
|
|
113
|
+
key: 'send', disabled: !enabled,
|
|
114
|
+
style: { pad: [7, 12], radius: 8, border: 'none', bg: 'gold', color: 'onGold', size: 13, weight: 700, lh: 'normal' },
|
|
115
|
+
on: enabled ? { tap: on.send } : undefined,
|
|
116
|
+
}, 'Send')),
|
|
117
|
+
];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function card(state, place, on) {
|
|
121
|
+
const { say } = state;
|
|
122
|
+
const landscape = Boolean(state.view?.landscape);
|
|
123
|
+
return h(landscape ? 'scroll' : 'column', {
|
|
124
|
+
key: 'card', hub: 'quick-chat-card', ...(landscape ? { axis: 'y' } : {}),
|
|
125
|
+
at: place.card,
|
|
126
|
+
style: {
|
|
127
|
+
w: [{ vw: 70 }, { px: 236 }], ...(place.cardMaxH ? { maxH: place.cardMaxH } : {}),
|
|
128
|
+
gap: 6, pad: 8, radius: 14, bg: 'card', shadow: 'card', hit: 'auto',
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
h('row', { key: 'reactions', style: { justify: 'between' } },
|
|
132
|
+
say.reactions.map((emoji, r) => h('button', {
|
|
133
|
+
key: `r${r}`, label: `React ${emoji}`, fire: 'down',
|
|
134
|
+
style: { box: 'border', w: 34, h: 34, pad: 0, border: 'none', bg: 'transparent', size: 22, weight: 400, lh: 'normal' },
|
|
135
|
+
on: { tap: () => on.react?.(r) },
|
|
136
|
+
}, emoji))),
|
|
137
|
+
h('row', { key: 'phrases', style: { wrap: true, gap: 5 } },
|
|
138
|
+
say.phrases.map(([id, words]) => h('button', {
|
|
139
|
+
key: `p:${id}`, fire: 'down', data: { id: String(id) },
|
|
140
|
+
style: { ...SMALL, weight: 600 },
|
|
141
|
+
on: { tap: () => on.phrase?.(id) },
|
|
142
|
+
}, String(words ?? '')))),
|
|
143
|
+
say.chat ? chatLine(say.chat, state.field, on) : null);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function feedLine(line, index, feed, on) {
|
|
147
|
+
if (line.id === null || line.id === undefined) {
|
|
148
|
+
return h('text', { key: `l${index}`, text: String(line.text ?? '') });
|
|
149
|
+
}
|
|
150
|
+
const id = String(line.id);
|
|
151
|
+
if (!(feed.confirming ?? []).includes(id)) {
|
|
152
|
+
return h('button', {
|
|
153
|
+
key: `m:${id}`, label: String(line.text ?? ''), fire: 'down', data: { id },
|
|
154
|
+
style: { pad: 0, border: 'none', bg: 'transparent', talign: 'start', hit: 'auto' },
|
|
155
|
+
on: { tap: () => on.ask?.(id) },
|
|
156
|
+
}, String(line.text ?? ''));
|
|
157
|
+
}
|
|
158
|
+
return h('row', { key: `m:${id}`, data: { id }, style: { wrap: true, gap: 6, align: 'center', hit: 'auto' } },
|
|
159
|
+
h('text', { key: 'ask', text: 'Report this message?' }),
|
|
160
|
+
h('button', { key: 'report', fire: 'down', style: PRIMARY, on: { tap: () => on.report?.(id) } }, 'Report'),
|
|
161
|
+
feed.moderation && line.userId ? h('button', { key: 'block', fire: 'down', style: PRIMARY, on: { tap: () => on.block?.(id) } }, 'Report & block') : null,
|
|
162
|
+
h('button', { key: 'cancel', fire: 'down', style: SMALL, on: { tap: () => on.unask?.(id) } }, 'Cancel'));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// The feed's lines as drawn: none while a list is open, and none reported.
|
|
166
|
+
export function feedShown(feed) {
|
|
167
|
+
if (!feed || feed.hidden) {return [];}
|
|
168
|
+
const reported = feed.reported ?? [];
|
|
169
|
+
return (feed.lines ?? []).filter((line) => line.id === null || line.id === undefined || !reported.includes(String(line.id)));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function buildQuickChat(state, on = {}) {
|
|
173
|
+
const view = state.view ?? {};
|
|
174
|
+
const say = state.say ?? null;
|
|
175
|
+
const open = Boolean(say) && Boolean(state.open) && !state.covered;
|
|
176
|
+
const place = quickChatPlace(view);
|
|
177
|
+
const size = view.landscape ? { w: 44, h: 44, radius: 22 } : { w: 52, h: 52, radius: 26 };
|
|
178
|
+
const feed = state.feed ?? {};
|
|
179
|
+
const lines = feedShown(feed);
|
|
180
|
+
return h('stack', {
|
|
181
|
+
key: 'quickchat', style: { font: 'ui', size: 15, weight: 600, lh: 1.3, color: '#fff' },
|
|
182
|
+
// Esc / Back shuts an open card.
|
|
183
|
+
on: { cancel: open ? on.close : undefined },
|
|
184
|
+
},
|
|
185
|
+
lines.length
|
|
186
|
+
? h('column', {
|
|
187
|
+
key: 'feed', hub: 'feed',
|
|
188
|
+
at: { anchor: 'bottomLeft', left: edge(Boolean(view.safeInsets), 10), bottom: [70, 60] },
|
|
189
|
+
style: { maxW: [{ vw: 62 }], gap: 2, size: 12, weight: 500, lh: 1.3, tshadow: 'outline', opacity: 0.92, hit: 'none' },
|
|
190
|
+
}, lines.map((line, index) => feedLine(line, index, feed, on)))
|
|
191
|
+
: null,
|
|
192
|
+
say
|
|
193
|
+
? h('button', {
|
|
194
|
+
key: 'button', hub: 'quick-chat', label: 'Quick chat', fire: 'down',
|
|
195
|
+
at: place.button,
|
|
196
|
+
style: { ...ROUND, ...size, hidden: Boolean(state.covered) },
|
|
197
|
+
on: { tap: state.covered ? undefined : on.toggle },
|
|
198
|
+
}, '💬')
|
|
199
|
+
: null,
|
|
200
|
+
open ? card(state, place, on) : null);
|
|
201
|
+
}
|
|
@@ -160,6 +160,81 @@ export function takesEnd(msg, pendingEnd, endSession, session) {
|
|
|
160
160
|
return !(msg?.again === true && pendingEnd !== null && endSession === session);
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
+
// v1.169: the door a `hub-end` names as the player's own (an end their own
|
|
164
|
+
// walk-in or press made), in a place without a result; else null. Only such
|
|
165
|
+
// an end, taken while the client was away, is cancelled rather than retried.
|
|
166
|
+
export function ownDoor(msg, place) {
|
|
167
|
+
return typeof msg?.door === 'string' && msg.door !== '' && !place?.result ? msg.door : null;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// The multiplayer kit's resume gate also arms on a frame stall alone (a gap
|
|
171
|
+
// over its STALL_MS, 1 s): a visible page on a connected socket whose frames
|
|
172
|
+
// stopped, as a low-memory phone's do while it loads the place. That is not an
|
|
173
|
+
// away, and a pad's or the place's own `hub-go` met under it goes as online:
|
|
174
|
+
// the first-room split's send (hub-town nux.js) arrives about 4 s after the
|
|
175
|
+
// join, inside the loading window, and was dropped as 'fired while offline'
|
|
176
|
+
// on such phones. A stall counts as an away only once it has lasted
|
|
177
|
+
// STALL_AWAY_MS, the multiplayer kit's own line between a frame hitch and an
|
|
178
|
+
// away (resumeGate.js RESYNC_AWAY_MS).
|
|
179
|
+
export const STALL_AWAY_MS = 5000;
|
|
180
|
+
|
|
181
|
+
// The page time the page was last hidden (`visibilitychange`), so an away
|
|
182
|
+
// that began as a stall and went on into a hide is still an away.
|
|
183
|
+
let lastHiddenAt = null;
|
|
184
|
+
export function notePageHidden(at) {
|
|
185
|
+
lastHiddenAt = at;
|
|
186
|
+
}
|
|
187
|
+
const pageHidden = () => typeof document !== 'undefined' && document.visibilityState === 'hidden';
|
|
188
|
+
if (typeof document !== 'undefined' && typeof document.addEventListener === 'function') {
|
|
189
|
+
document.addEventListener('visibilitychange', () => {
|
|
190
|
+
if (pageHidden()) {
|
|
191
|
+
notePageHidden(performance.now());
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Whether an armed resume gate is a real away at page time `now`: the
|
|
197
|
+
// connection dropped during it, the page is or was hidden since it began, it
|
|
198
|
+
// has lasted STALL_AWAY_MS, or the gate says nothing of when it began.
|
|
199
|
+
function gateAway(gate, now) {
|
|
200
|
+
if (gate.dropped === true || pageHidden() || !Number.isFinite(gate.since)) {
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
if (lastHiddenAt !== null && lastHiddenAt >= gate.since) {
|
|
204
|
+
return true;
|
|
205
|
+
}
|
|
206
|
+
return !(now - gate.since < STALL_AWAY_MS);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// v1.169: whether the connection is away right now: the multiplayer kit's
|
|
210
|
+
// resume gate armed (by a hide, a drop, or a stall of STALL_AWAY_MS or more;
|
|
211
|
+
// see above), or the transport not connected. Not the gate's return tail
|
|
212
|
+
// (`returning`), which an online walk-in just after a return falls in.
|
|
213
|
+
export function connectionAway(mp, now = typeof performance !== 'undefined' ? performance.now() : Date.now()) {
|
|
214
|
+
if (mp?.resume?.armed === true && gateAway(mp.resume, now)) {
|
|
215
|
+
return true;
|
|
216
|
+
}
|
|
217
|
+
try {
|
|
218
|
+
const state = mp?.net?.status?.()?.state;
|
|
219
|
+
return typeof state === 'string' && state !== 'connected';
|
|
220
|
+
} catch {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// A `hub-end` or `hub-go` drained while the connection was away, marked as it
|
|
226
|
+
// arrives: the drain that releases the gate still holds it armed, and the
|
|
227
|
+
// command is read on a later frame, after the release.
|
|
228
|
+
const arrivedAwayMsgs = new WeakSet();
|
|
229
|
+
export function noteArrival(msg, mp) {
|
|
230
|
+
if (msg && typeof msg === 'object' && connectionAway(mp)) {
|
|
231
|
+
arrivedAwayMsgs.add(msg);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
export function arrivedAway(msg) {
|
|
235
|
+
return Boolean(msg && typeof msg === 'object' && arrivedAwayMsgs.has(msg));
|
|
236
|
+
}
|
|
237
|
+
|
|
163
238
|
function selfIdOf(net) {
|
|
164
239
|
try {
|
|
165
240
|
return net.selfId?.() || null;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// v1.196: composable visibility saves: quality and disguise may hide the same material.
|
|
2
|
+
const owners = new WeakMap();
|
|
3
|
+
export function hideVisible(saved, object) {
|
|
4
|
+
if (saved.has(object)) {return;}
|
|
5
|
+
let entry = owners.get(object);
|
|
6
|
+
if (!entry) {entry = { visible: object.visible, saves: new Set() }; owners.set(object, entry);}
|
|
7
|
+
entry.saves.add(saved); saved.set(object, entry.visible); object.visible = false;
|
|
8
|
+
}
|
|
9
|
+
export function restoreVisible(saved) {
|
|
10
|
+
for (const object of saved.keys()) {
|
|
11
|
+
const entry = owners.get(object);
|
|
12
|
+
entry.saves.delete(saved);
|
|
13
|
+
object.visible = entry.saves.size ? false : entry.visible;
|
|
14
|
+
if (!entry.saves.size) {owners.delete(object);}
|
|
15
|
+
}
|
|
16
|
+
saved.clear();
|
|
17
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// v1.163: at most two private scene groups, outside the actor/physics graph.
|
|
2
|
+
import { Group, Mesh, MeshBasicMaterial, CapsuleGeometry, SphereGeometry, CanvasTexture, Sprite, SpriteMaterial } from 'three';
|
|
3
|
+
import { buildModelNode, parseModelCached } from '@imports/castle.physics-3d/engine3d/pxmodel';
|
|
4
|
+
import { copyModel, takeModel, releaseModel } from '@imports/castle.physics-3d/engine3d/optimize';
|
|
5
|
+
import { cleanTrace, sampleTrace } from '../shared/replay.js';
|
|
6
|
+
import { replayCleanup } from './state.js';
|
|
7
|
+
export { sampleTrace } from '../shared/replay.js';
|
|
8
|
+
|
|
9
|
+
const caches = new WeakMap(), noRaycast = () => {};
|
|
10
|
+
function disposeTree(root) {
|
|
11
|
+
const owned = new Set();
|
|
12
|
+
root.traverse(o => {for (const v of [o.geometry, ...[o.material].flat()]) {if (v) {owned.add(v);}}});
|
|
13
|
+
for (const v of owned) {v.dispose();}
|
|
14
|
+
}
|
|
15
|
+
function figure(scene, spec) {
|
|
16
|
+
const group = new Group(), owned = new Set();
|
|
17
|
+
let release = () => {};
|
|
18
|
+
const model = spec.look && scene.getActor?.(spec.look)?.components.Model;
|
|
19
|
+
const text = model && scene.files?.[model.file], parsed = typeof text === 'string' && parseModelCached(text);
|
|
20
|
+
if (parsed) {
|
|
21
|
+
let cache = caches.get(scene.three);
|
|
22
|
+
if (!cache) {cache = new Map(); caches.set(scene.three, cache);}
|
|
23
|
+
const key = `${model.file}:${text}`;
|
|
24
|
+
const template = takeModel(cache, key, () => buildModelNode(parsed, scene.sprites, scene.files, model.file, [model.file], { optimize: true }));
|
|
25
|
+
const copy = copyModel(template);
|
|
26
|
+
copy.scale.setScalar(model.scale ?? 1); copy.position.y = model.yOffset ?? 0;
|
|
27
|
+
group.add(copy);
|
|
28
|
+
release = () => releaseModel(cache, key, disposeTree);
|
|
29
|
+
// Materials must be private: opacity changes must never tint a live model.
|
|
30
|
+
const materials = new Map();
|
|
31
|
+
copy.traverse(o => {
|
|
32
|
+
if (o.material) {
|
|
33
|
+
const clone = m => {
|
|
34
|
+
if (!materials.has(m)) {const c = m.clone(); materials.set(m, c); owned.add(c);}
|
|
35
|
+
return materials.get(m);
|
|
36
|
+
};
|
|
37
|
+
o.material = Array.isArray(o.material) ? o.material.map(clone) : clone(o.material);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
} else {
|
|
41
|
+
const material = new MeshBasicMaterial({ color: spec.color ?? '#b4e6fa' });
|
|
42
|
+
const torso = new Mesh(new CapsuleGeometry(.23, .65, 4, 8), material);
|
|
43
|
+
const head = new Mesh(new SphereGeometry(.22, 10, 8), material);
|
|
44
|
+
torso.position.y = -.2; head.position.y = .58;
|
|
45
|
+
group.add(torso, head);
|
|
46
|
+
owned.add(material); owned.add(torso.geometry); owned.add(head.geometry);
|
|
47
|
+
}
|
|
48
|
+
if (spec.label && typeof document !== 'undefined') {
|
|
49
|
+
const canvas = document.createElement('canvas'); canvas.width = 512; canvas.height = 64;
|
|
50
|
+
const ctx = canvas.getContext('2d');
|
|
51
|
+
// The figure is faint; its name is not, so it reads against sky and track.
|
|
52
|
+
ctx.font = 'bold 34px sans-serif'; ctx.textAlign = 'center'; ctx.lineJoin = 'round';
|
|
53
|
+
ctx.lineWidth = 7; ctx.strokeStyle = 'rgba(0, 0, 0, 0.7)'; ctx.strokeText(spec.label, 256, 44, 500);
|
|
54
|
+
ctx.fillStyle = spec.color ?? '#b4e6fa'; ctx.fillText(spec.label, 256, 44, 500);
|
|
55
|
+
const texture = new CanvasTexture(canvas), material = new SpriteMaterial({ map: texture });
|
|
56
|
+
material.userData.label = true;
|
|
57
|
+
const label = new Sprite(material); label.position.y = 1.35; label.scale.set(4, .5, 1);
|
|
58
|
+
group.add(label); owned.add(texture); owned.add(material);
|
|
59
|
+
}
|
|
60
|
+
group.name = 'hub:replay';
|
|
61
|
+
const materials = new Map();
|
|
62
|
+
group.traverse(o => {
|
|
63
|
+
o.castShadow = false; o.receiveShadow = false; o.raycast = noRaycast;
|
|
64
|
+
for (const m of [o.material].flat()) {
|
|
65
|
+
if (!m) {continue;}
|
|
66
|
+
const base = m.userData?.label ? .95 : .4;
|
|
67
|
+
m.transparent = true; m.opacity = base; m.depthWrite = false;
|
|
68
|
+
if (spec.color && m.color && !m.userData?.label) {m.color.set(spec.color);}
|
|
69
|
+
materials.set(m, base);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
return { group, materials, release() {group.removeFromParent(); for (const v of owned) {v.dispose();} release();} };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// The server validated it; a client still draws nothing it cannot bound.
|
|
76
|
+
function validSpec(spec) {
|
|
77
|
+
const trace = spec && typeof spec === 'object' && cleanTrace(spec.trace);
|
|
78
|
+
if (!trace) {return false;}
|
|
79
|
+
if (spec.offsetMs !== undefined && (!Number.isSafeInteger(spec.offsetMs) || spec.offsetMs < 0 || spec.offsetMs > trace.ms)) {return false;}
|
|
80
|
+
if (spec.label !== undefined && (typeof spec.label !== 'string' || !spec.label.trim() || [...spec.label].length > 24)) {return false;}
|
|
81
|
+
if (spec.color !== undefined && (typeof spec.color !== 'string' || !/^#[0-9a-f]{6}$/i.test(spec.color))) {return false;}
|
|
82
|
+
return spec.look === undefined || typeof spec.look === 'string';
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function makeReplay() {
|
|
86
|
+
const slots = new Map();
|
|
87
|
+
const api = {
|
|
88
|
+
clear() {for (const entry of slots.values()) {entry.release();} slots.clear();},
|
|
89
|
+
receive(scene, slot, spec, time = performance.now()) {
|
|
90
|
+
if (slot !== 0 && slot !== 1) {return;}
|
|
91
|
+
if (spec !== null && !validSpec(spec)) {return;}
|
|
92
|
+
api.frame(scene, time);
|
|
93
|
+
slots.get(slot)?.release(); slots.delete(slot);
|
|
94
|
+
if (spec === null || !scene.three?.scene) {return;}
|
|
95
|
+
const entry = { ...figure(scene, spec), trace: spec.trace, offset: spec.offsetMs ?? 0, began: time, scene,
|
|
96
|
+
path: scene.currentScenePath, key: scene.sceneKey, net: scene.multiplayer?.net, generation: scene.multiplayer?.generation };
|
|
97
|
+
slots.set(slot, entry); scene.three.scene.add(entry.group);
|
|
98
|
+
api.frame(scene, time);
|
|
99
|
+
},
|
|
100
|
+
frame(scene, time = performance.now()) {
|
|
101
|
+
for (const [slot, e] of slots) {
|
|
102
|
+
const t = time - e.began + e.offset;
|
|
103
|
+
if (scene !== e.scene || scene.currentScenePath !== e.path || scene.sceneKey !== e.key || scene.multiplayer?.net !== e.net || scene.multiplayer?.generation !== e.generation ||
|
|
104
|
+
e.net?.closed?.() || (e.net?.status && e.net.status().state !== 'connected') || t >= e.trace.ms + 1000) {
|
|
105
|
+
e.release(); slots.delete(slot); continue;
|
|
106
|
+
}
|
|
107
|
+
const pose = sampleTrace(e.trace, t);
|
|
108
|
+
e.group.position.set(pose.x, pose.y, pose.z); e.group.rotation.y = pose.yaw * Math.PI / 180;
|
|
109
|
+
for (const [m, base] of e.materials) {m.opacity = base * Math.max(0, 1 - Math.max(0, t - e.trace.ms) / 1000);}
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
return api;
|
|
114
|
+
}
|
|
115
|
+
export const replays = makeReplay();
|
|
116
|
+
|
|
117
|
+
replayCleanup.clear = replays.clear;
|
|
118
|
+
replayCleanup.receive = replays.receive;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// Visit-only role outfits and chips (contract §11, v1.157). Pure catalogue
|
|
2
2
|
// and descriptions, also read by the server; no resources without a role.
|
|
3
|
+
import { disguiseTags } from './disguise.js';
|
|
4
|
+
|
|
3
5
|
export const ROLE_TOPS = ['vest', 'scrubs', 'coat', 'apron', 'cardigan', 'tabard'];
|
|
4
6
|
export const ROLE_TOOLS = ['torch', 'bag', 'hose', 'tray', 'bell', 'parcel'];
|
|
5
7
|
export const ROLE_MAIN = '#3aa0d8';
|
|
@@ -55,6 +57,7 @@ export function roleItems(scene, local, cam, view, roles, project) {
|
|
|
55
57
|
const self = mp?.net?.selfId?.();
|
|
56
58
|
const out = [];
|
|
57
59
|
for (const [playerId, role] of roles) {
|
|
60
|
+
if (disguiseTags(self, playerId)) {continue;}
|
|
58
61
|
const actorId = playerId === self ? local?.id : mp?.avatars?.actors?.get(playerId);
|
|
59
62
|
const node = actorId ? scene.three?.nodes?.get(actorId)?.node : null;
|
|
60
63
|
let visible = Boolean(node);
|