castle-web-cli 0.4.238 → 0.4.240
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent.js +5 -1
- package/dist/api.d.ts +20 -0
- package/dist/api.js +57 -0
- package/dist/bundle.d.ts +38 -1
- package/dist/bundle.js +309 -13
- package/dist/castle-host/host.js +218 -11
- package/dist/castleJson.d.ts +10 -0
- package/dist/castleJson.js +46 -2
- package/dist/check.js +5 -2
- package/dist/devSessionServer.js +4 -1
- package/dist/devSessionStorage.d.ts +1 -0
- package/dist/devSessionStorage.js +32 -7
- package/dist/importOrder.d.ts +2 -0
- package/dist/importOrder.js +29 -0
- package/dist/index.js +22 -3
- package/dist/init.js +24 -2
- package/dist/multiplayerDoc.d.ts +1 -1
- package/dist/multiplayerDoc.js +9 -0
- package/dist/platformDoc.js +4 -2
- package/dist/playPagePolicy.d.ts +1 -0
- package/dist/playPagePolicy.js +12 -3
- package/dist/resetLeaderboards.d.ts +8 -1
- package/dist/resetLeaderboards.js +43 -8
- package/dist/roomLogs.d.ts +39 -0
- package/dist/roomLogs.js +166 -0
- package/dist/save-deck.d.ts +32 -2
- package/dist/save-deck.js +240 -39
- package/kits/base/CLAUDE.md +2 -1
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +240 -8
- package/kits/base/sdk/analytics.d.ts +8 -0
- package/kits/base/sdk/analytics.js +92 -0
- package/kits/base/sdk/castle.d.ts +8 -2
- package/kits/base/sdk/castle.js +3 -0
- package/kits/base/sdk/commands.d.ts +79 -0
- package/kits/base/sdk/commands.js +1 -0
- package/kits/base/sdk/debugConsole.d.ts +17 -0
- package/kits/base/sdk/debugConsole.js +154 -0
- package/kits/base/sdk/experiments.js +24 -1
- package/kits/base/sdk/hostRetry.d.ts +7 -0
- package/kits/base/sdk/hostRetry.js +57 -0
- package/kits/base/sdk/hub.d.ts +20 -2
- package/kits/base/sdk/hub.js +99 -13
- package/kits/base/sdk/multiplayer.d.ts +2 -0
- package/kits/base/sdk/multiplayer.js +198 -26
- package/kits/base/sdk/reconnectBudget.d.ts +6 -0
- package/kits/base/sdk/reconnectBudget.js +41 -1
- package/kits/base/sdk/rooms.d.ts +11 -0
- package/kits/base/sdk/rooms.js +22 -0
- package/kits/base/sdk/runtime.js +36 -19
- package/kits/base/sdk/server/hub.d.ts +19 -0
- package/kits/base/sdk/server/hub.js +12 -0
- package/kits/base/sdk/server/platformHandle.d.ts +1 -0
- package/kits/base/sdk/server/wrapper.d.ts +1 -1
- package/kits/base/sdk/server/wrapper.js +26 -1
- package/kits/base/sdk/store.d.ts +8 -2
- package/kits/base/sdk/store.js +5 -1
- package/kits/base/sdk/transport.d.ts +2 -1
- package/kits/base/sdk/transport.js +35 -0
- package/kits/hub-game/CLAUDE.md +66 -19
- package/kits/hub-game/castle.json +4 -4
- package/kits/hub-game/code/client/act.js +9 -6
- package/kits/hub-game/code/client/actCore.js +26 -6
- package/kits/hub-game/code/client/actGateLog.js +36 -0
- package/kits/hub-game/code/client/actionOverflow.js +29 -8
- package/kits/hub-game/code/client/actionRailSurface.js +186 -0
- package/kits/hub-game/code/client/actionRailTree.js +173 -0
- package/kits/hub-game/code/client/askSurface.js +85 -0
- package/kits/hub-game/code/client/askTree.js +51 -0
- package/kits/hub-game/code/client/attention.js +31 -6
- package/kits/hub-game/code/client/ballot.js +42 -5
- package/kits/hub-game/code/client/ballotSurface.js +115 -0
- package/kits/hub-game/code/client/ballotTree.js +180 -0
- package/kits/hub-game/code/client/catchingUp.js +19 -0
- package/kits/hub-game/code/client/celebrate.js +66 -0
- package/kits/hub-game/code/client/chrome.js +474 -53
- package/kits/hub-game/code/client/companion.js +93 -23
- package/kits/hub-game/code/client/companionDress.js +1 -1
- package/kits/hub-game/code/client/cornerSurface.js +106 -0
- package/kits/hub-game/code/client/cornerTree.js +83 -0
- package/kits/hub-game/code/client/decor.js +20 -11
- package/kits/hub-game/code/client/deviceStorage.js +121 -0
- package/kits/hub-game/code/client/disguise.js +23 -0
- package/kits/hub-game/code/client/disguiseDraw.js +87 -0
- package/kits/hub-game/code/client/dockSurface.js +206 -0
- package/kits/hub-game/code/client/dockTree.js +232 -0
- package/kits/hub-game/code/client/earned.js +29 -0
- package/kits/hub-game/code/client/emoteSurface.js +188 -0
- package/kits/hub-game/code/client/emoteTree.js +264 -0
- package/kits/hub-game/code/client/farAvatars.js +4 -3
- package/kits/hub-game/code/client/fpsTelemetry.js +3 -1
- package/kits/hub-game/code/client/grab.js +121 -50
- package/kits/hub-game/code/client/holdShow.js +19 -0
- package/kits/hub-game/code/client/hookLayer.js +96 -12
- package/kits/hub-game/code/client/hubControls.js +7 -1
- package/kits/hub-game/code/client/hudSurface.js +11 -3
- package/kits/hub-game/code/client/hudTree.js +7 -4
- package/kits/hub-game/code/client/idle.js +21 -3
- package/kits/hub-game/code/client/invites.js +24 -3
- package/kits/hub-game/code/client/keys.js +15 -0
- package/kits/hub-game/code/client/labelsNear.js +8 -1
- package/kits/hub-game/code/client/layoutCache.js +57 -8
- package/kits/hub-game/code/client/loadingCover.js +53 -4
- package/kits/hub-game/code/client/menuIcons.js +15 -0
- package/kits/hub-game/code/client/menuRows.js +8 -2
- package/kits/hub-game/code/client/menuSurface.js +102 -0
- package/kits/hub-game/code/client/menuTree.js +135 -0
- package/kits/hub-game/code/client/modelLook.js +41 -0
- package/kits/hub-game/code/client/pickerSurface.js +152 -0
- package/kits/hub-game/code/client/pickerTree.js +163 -0
- package/kits/hub-game/code/client/pushVisit.js +4 -2
- package/kits/hub-game/code/client/quality.js +188 -29
- package/kits/hub-game/code/client/qualityEntry.js +10 -1
- package/kits/hub-game/code/client/quickChatSurface.js +222 -0
- package/kits/hub-game/code/client/quickChatTree.js +201 -0
- package/kits/hub-game/code/client/rehello.js +75 -0
- package/kits/hub-game/code/client/renderVisibility.js +17 -0
- package/kits/hub-game/code/client/replay.js +118 -0
- package/kits/hub-game/code/client/role.js +3 -0
- package/kits/hub-game/code/client/safeLayout.js +441 -56
- package/kits/hub-game/code/client/safeStyle.js +13 -10
- package/kits/hub-game/code/client/say.js +2 -0
- package/kits/hub-game/code/client/soundSurface.js +77 -0
- package/kits/hub-game/code/client/soundTree.js +74 -0
- package/kits/hub-game/code/client/soundscape.js +12 -9
- package/kits/hub-game/code/client/soundscapeCues.js +1 -1
- package/kits/hub-game/code/client/state.js +67 -1
- package/kits/hub-game/code/client/stuckSurface.js +76 -0
- package/kits/hub-game/code/client/stuckTree.js +67 -0
- package/kits/hub-game/code/client/talk.js +42 -12
- package/kits/hub-game/code/client/talkTree.js +4 -2
- package/kits/hub-game/code/client/textAskSurface.js +147 -0
- package/kits/hub-game/code/client/textAskTree.js +67 -0
- package/kits/hub-game/code/client/tiers.js +252 -27
- package/kits/hub-game/code/client/together.js +4 -1
- package/kits/hub-game/code/client/uiDom.js +86 -8
- package/kits/hub-game/code/client/uiTree.js +33 -4
- package/kits/hub-game/code/client/vehicle.js +75 -52
- package/kits/hub-game/code/client/weakestTier.js +75 -31
- package/kits/hub-game/code/client/wear.js +159 -5
- package/kits/hub-game/code/client/worldLabels.js +215 -26
- package/kits/hub-game/code/companionSpec.js +4 -2
- package/kits/hub-game/code/server/act.js +3 -0
- package/kits/hub-game/code/server/actGate.js +83 -0
- package/kits/hub-game/code/server/actions.js +71 -15
- package/kits/hub-game/code/server/actors.js +20 -5
- package/kits/hub-game/code/server/analytics.js +40 -15
- package/kits/hub-game/code/server/ask.js +39 -3
- package/kits/hub-game/code/server/ballot.js +167 -4
- package/kits/hub-game/code/server/celebrate.js +64 -0
- package/kits/hub-game/code/server/companion.js +17 -2
- package/kits/hub-game/code/server/decor.js +11 -2
- package/kits/hub-game/code/server/disguise.js +63 -0
- package/kits/hub-game/code/server/doorAnalytics.js +2 -5
- package/kits/hub-game/code/server/earned.js +6 -2
- package/kits/hub-game/code/server/friendBests.js +13 -4
- package/kits/hub-game/code/server/friendsAmong.js +67 -8
- package/kits/hub-game/code/server/grab.js +12 -2
- package/kits/hub-game/code/server/heldOffers.js +142 -0
- package/kits/hub-game/code/server/holdShow.js +98 -0
- package/kits/hub-game/code/server/hub.js +854 -45
- package/kits/hub-game/code/server/idle.js +110 -9
- package/kits/hub-game/code/server/index.js +9 -0
- package/kits/hub-game/code/server/labels.js +13 -3
- package/kits/hub-game/code/server/loadAbandon.js +2 -5
- package/kits/hub-game/code/server/manifest.js +94 -6
- package/kits/hub-game/code/server/menu.js +26 -3
- package/kits/hub-game/code/server/npcs.js +55 -9
- package/kits/hub-game/code/server/observe.js +67 -6
- package/kits/hub-game/code/server/players.js +8 -1
- package/kits/hub-game/code/server/replay.js +135 -0
- package/kits/hub-game/code/server/storageLimit.js +4 -1
- package/kits/hub-game/code/server/townDay.js +74 -0
- package/kits/hub-game/code/server/trackQueue.js +29 -0
- package/kits/hub-game/code/server/vehicle.js +3 -0
- package/kits/hub-game/code/server/vis.js +26 -4
- package/kits/hub-game/code/server/wallet.js +677 -0
- package/kits/hub-game/code/server/wear.js +13 -3
- package/kits/hub-game/code/server/writerLease.js +191 -0
- package/kits/hub-game/code/shared/act.js +1 -1
- package/kits/hub-game/code/shared/expression.js +6 -0
- package/kits/hub-game/code/shared/replay.js +37 -0
- package/kits/hub-game/code/systems/hub.js +437 -57
- package/kits/hub-game/docs/analytics.md +20 -3
- package/kits/hub-game/docs/contract.md +942 -99
- package/kits/hub-game/docs/home-pieces.md +5 -6
- package/kits/hub-game/docs/observed-progress.md +49 -1
- package/kits/hub-game/docs/vehicle-preset.md +23 -0
- package/kits/hub-game/index.html +1 -0
- package/kits/hub-game/models/hats/baker-cap.pxmodel +3 -3
- package/kits/hub-game/models/hats/bat-clip.pxmodel +3 -3
- package/kits/hub-game/models/hats/beekeeper.pxmodel +3 -3
- package/kits/hub-game/models/hats/cap.pxmodel +3 -3
- package/kits/hub-game/models/hats/captain.pxmodel +3 -3
- package/kits/hub-game/models/hats/chef-toque.pxmodel +3 -3
- package/kits/hub-game/models/hats/crooked-top.pxmodel +3 -3
- package/kits/hub-game/models/hats/delivery-cap.pxmodel +3 -3
- package/kits/hub-game/models/hats/fire-helmet.pxmodel +3 -3
- package/kits/hub-game/models/hats/flower-crown.pxmodel +3 -3
- package/kits/hub-game/models/hats/foam-crown.pxmodel +3 -3
- package/kits/hub-game/models/hats/hard-hat.pxmodel +3 -3
- package/kits/hub-game/models/hats/lantern.pxmodel +3 -3
- package/kits/hub-game/models/hats/laurel.pxmodel +3 -3
- package/kits/hub-game/models/hats/lighthouse.pxmodel +3 -3
- package/kits/hub-game/models/hats/nurse-cap.pxmodel +3 -3
- package/kits/hub-game/models/hats/police-cap.pxmodel +3 -3
- package/kits/hub-game/models/hats/sailor.pxmodel +3 -3
- package/kits/hub-game/models/hats/souwester.pxmodel +3 -3
- package/kits/hub-game/models/hats/straw.pxmodel +3 -3
- package/kits/hub-game/models/hats/sunflower.pxmodel +3 -3
- package/kits/hub-game/models/hats/sweatband.pxmodel +3 -3
- package/kits/hub-game/models/hats/teacher-beret.pxmodel +3 -3
- package/kits/hub-game/models/hats/witch.pxmodel +3 -3
- package/kits/hub-game/models/hold-show/daisy.pxmodel +231 -0
- package/kits/hub-game/models/hold-show/moonflower.pxmodel +171 -0
- package/kits/hub-game/models/hold-show/rose.pxmodel +191 -0
- package/kits/hub-game/models/hold-show/square/daisy.pxmodel +233 -0
- package/kits/hub-game/models/hold-show/square/moonflower.pxmodel +173 -0
- package/kits/hub-game/models/hold-show/square/rose.pxmodel +193 -0
- package/kits/hub-game/models/hold-show/square/sunflower.pxmodel +313 -0
- package/kits/hub-game/models/hold-show/square/tulip.pxmodel +133 -0
- package/kits/hub-game/models/hold-show/sunflower.pxmodel +311 -0
- package/kits/hub-game/models/hold-show/tulip.pxmodel +131 -0
- package/kits/hub-game/package-lock.json +3 -3
- package/kits/hub-game/package.json +4 -3
- package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +1 -0
- package/kits/hub-game/scripts/fixtures/hud-surface.json +12 -12
- package/kits/hub-game/scripts/fixtures/talk-surface.json +8 -8
- package/kits/hub-game/scripts/gen-hats.mjs +1 -1
- package/kits/hub-game/scripts/gen-hold-show.mjs +27 -0
- package/kits/hub-game/scripts/pack.mjs +89 -23
- package/kits/hub-game/scripts/test-act-client.mjs +5 -0
- package/kits/hub-game/scripts/test-act-core.mjs +32 -0
- package/kits/hub-game/scripts/test-act-gate.mjs +186 -0
- package/kits/hub-game/scripts/test-action-rail-crowded-dom.mjs +7 -1
- package/kits/hub-game/scripts/test-action-rail-default-dom.mjs +102 -0
- package/kits/hub-game/scripts/test-action-rail-never-silent-dom.mjs +50 -0
- package/kits/hub-game/scripts/test-action-rail-surface.mjs +368 -0
- package/kits/hub-game/scripts/test-action-rail-town-jobs-dom.mjs +118 -0
- package/kits/hub-game/scripts/test-actions-client.mjs +5 -3
- package/kits/hub-game/scripts/test-actions.mjs +24 -0
- package/kits/hub-game/scripts/test-actors.mjs +19 -0
- package/kits/hub-game/scripts/test-again-corner-dom.mjs +59 -0
- package/kits/hub-game/scripts/test-analytics.mjs +80 -1
- package/kits/hub-game/scripts/test-arrival-pose-server.mjs +25 -8
- package/kits/hub-game/scripts/test-ask-client.mjs +9 -0
- package/kits/hub-game/scripts/test-ask-surface.mjs +188 -0
- package/kits/hub-game/scripts/test-attention.mjs +43 -1
- package/kits/hub-game/scripts/test-ballot-sheet-dom.mjs +71 -0
- package/kits/hub-game/scripts/test-ballot-surface.mjs +276 -0
- package/kits/hub-game/scripts/test-ballot.mjs +420 -3
- package/kits/hub-game/scripts/test-ban-join.mjs +1 -1
- package/kits/hub-game/scripts/test-celebrate-client.mjs +62 -0
- package/kits/hub-game/scripts/test-celebrate.mjs +116 -0
- package/kits/hub-game/scripts/test-chat.mjs +73 -0
- package/kits/hub-game/scripts/test-companion-client.mjs +203 -21
- package/kits/hub-game/scripts/test-companion.mjs +110 -3
- package/kits/hub-game/scripts/test-control-layout-dom.mjs +57 -10
- package/kits/hub-game/scripts/test-corner-surface.mjs +268 -0
- package/kits/hub-game/scripts/test-decor-client.mjs +59 -3
- package/kits/hub-game/scripts/test-decor.mjs +27 -0
- package/kits/hub-game/scripts/test-device-class.mjs +4 -1
- package/kits/hub-game/scripts/test-disguise-client.mjs +281 -0
- package/kits/hub-game/scripts/test-disguise.mjs +176 -0
- package/kits/hub-game/scripts/test-dock-surface.mjs +404 -0
- package/kits/hub-game/scripts/test-door-analytics.mjs +1 -1
- package/kits/hub-game/scripts/test-door-stay-client.mjs +602 -0
- package/kits/hub-game/scripts/test-door-stay.mjs +613 -0
- package/kits/hub-game/scripts/test-earned-client.mjs +119 -0
- package/kits/hub-game/scripts/test-emote-surface.mjs +616 -0
- package/kits/hub-game/scripts/test-fps-telemetry.mjs +39 -4
- package/kits/hub-game/scripts/test-friend-bests.mjs +38 -12
- package/kits/hub-game/scripts/test-ghost-click-dom.mjs +75 -0
- package/kits/hub-game/scripts/test-grab-client.mjs +29 -2
- package/kits/hub-game/scripts/test-grab-orbit.mjs +260 -11
- package/kits/hub-game/scripts/test-grab.mjs +10 -1
- package/kits/hub-game/scripts/test-hats.mjs +28 -0
- package/kits/hub-game/scripts/test-held-offers.mjs +394 -0
- package/kits/hub-game/scripts/test-high-only.mjs +3 -3
- package/kits/hub-game/scripts/test-hold-show-client.mjs +175 -0
- package/kits/hub-game/scripts/test-hold-show.mjs +355 -0
- package/kits/hub-game/scripts/test-hub-controls.mjs +3 -1
- package/kits/hub-game/scripts/test-hub-idle.mjs +348 -0
- package/kits/hub-game/scripts/test-hub-leaving.mjs +21 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +147 -0
- package/kits/hub-game/scripts/test-hub-trip.mjs +260 -5
- package/kits/hub-game/scripts/test-hud-clear.mjs +83 -0
- package/kits/hub-game/scripts/test-hud-rate.mjs +2 -1
- package/kits/hub-game/scripts/test-idle.mjs +160 -0
- package/kits/hub-game/scripts/test-invites-client.mjs +53 -0
- package/kits/hub-game/scripts/test-labels.mjs +11 -0
- package/kits/hub-game/scripts/test-landscape-layout.mjs +20 -0
- package/kits/hub-game/scripts/test-load-abandon.mjs +2 -2
- package/kits/hub-game/scripts/test-loading-cover.mjs +67 -1
- package/kits/hub-game/scripts/test-manifest.mjs +27 -0
- package/kits/hub-game/scripts/test-menu-client.mjs +55 -6
- package/kits/hub-game/scripts/test-menu-surface.mjs +236 -0
- package/kits/hub-game/scripts/test-npcs.mjs +128 -0
- package/kits/hub-game/scripts/test-observed.mjs +171 -3
- package/kits/hub-game/scripts/test-pack.mjs +166 -0
- package/kits/hub-game/scripts/test-picker-surface.mjs +321 -0
- package/kits/hub-game/scripts/test-placeat-server.mjs +395 -0
- package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
- package/kits/hub-game/scripts/test-pointer-clear-dom.mjs +82 -0
- package/kits/hub-game/scripts/test-progress-reset.mjs +184 -6
- package/kits/hub-game/scripts/test-push-visit.mjs +9 -0
- package/kits/hub-game/scripts/test-quality.mjs +312 -9
- package/kits/hub-game/scripts/test-quick-chat-surface.mjs +511 -0
- package/kits/hub-game/scripts/test-rehello.mjs +237 -0
- package/kits/hub-game/scripts/test-rejoin-yaw.mjs +138 -0
- package/kits/hub-game/scripts/test-relations-among.mjs +13 -7
- package/kits/hub-game/scripts/test-relations-refresh.mjs +90 -2
- package/kits/hub-game/scripts/test-replay-client.mjs +110 -0
- package/kits/hub-game/scripts/test-replay.mjs +178 -0
- package/kits/hub-game/scripts/test-resume-held.mjs +13 -0
- package/kits/hub-game/scripts/test-resume-pose-server.mjs +43 -5
- package/kits/hub-game/scripts/test-resync.mjs +13 -0
- package/kits/hub-game/scripts/test-role-client.mjs +10 -3
- package/kits/hub-game/scripts/test-safe-act.mjs +233 -0
- package/kits/hub-game/scripts/test-safe-caption.mjs +364 -0
- package/kits/hub-game/scripts/test-safe-layout.mjs +79 -0
- package/kits/hub-game/scripts/test-safe-prompt.mjs +163 -0
- package/kits/hub-game/scripts/test-sound-surface.mjs +256 -0
- package/kits/hub-game/scripts/test-soundscape.mjs +85 -2
- package/kits/hub-game/scripts/test-stuck-surface.mjs +174 -0
- package/kits/hub-game/scripts/test-stuck.mjs +31 -0
- package/kits/hub-game/scripts/test-talk-surface.mjs +23 -6
- package/kits/hub-game/scripts/test-talk-walk-dom.mjs +123 -0
- package/kits/hub-game/scripts/test-text-ask-surface.mjs +273 -0
- package/kits/hub-game/scripts/test-tiers.mjs +453 -3
- package/kits/hub-game/scripts/test-toast-no-row-dom.mjs +71 -0
- package/kits/hub-game/scripts/test-together.mjs +11 -0
- package/kits/hub-game/scripts/test-town-day.mjs +90 -0
- package/kits/hub-game/scripts/test-track-queue.mjs +64 -0
- package/kits/hub-game/scripts/test-try-on.mjs +39 -0
- package/kits/hub-game/scripts/test-ui-dom-dom.mjs +49 -2
- package/kits/hub-game/scripts/test-ui-tree.mjs +28 -0
- package/kits/hub-game/scripts/test-vehicle-client.mjs +77 -1
- package/kits/hub-game/scripts/test-vis.mjs +145 -0
- package/kits/hub-game/scripts/test-wallet.mjs +650 -0
- package/kits/hub-game/scripts/test-weakest-tier.mjs +135 -1
- package/kits/hub-game/scripts/test-world-labels.mjs +380 -0
- package/kits/hub-game/scripts/test-writer-lease-server.mjs +234 -0
- package/kits/hub-game/scripts/test-writer-lease.mjs +281 -0
- package/kits/hub-game/scripts/writer-storage-fixture.mjs +37 -0
- package/kits/hub-game/tools/hubScene/export.mjs +6 -5
- package/kits/hub-game/tools/hubScene/hubdata.mjs +10 -0
- package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +48 -2
- package/kits/hub-game/tools/hubScene/validate-manifest.mjs +21 -3
- package/kits/multiplayer-3d/castle.json +5 -5
- package/kits/multiplayer-3d/code/client/resumeGate.js +49 -2
- package/kits/multiplayer-3d/code/server/ownership.js +25 -6
- package/kits/multiplayer-3d/code/server/world.js +19 -4
- package/kits/multiplayer-3d/code/systems/multiplayer.js +67 -11
- package/kits/multiplayer-3d/package-lock.json +1 -1
- package/kits/multiplayer-3d/package.json +2 -1
- package/kits/multiplayer-3d/scripts/test-ground-half.mjs +56 -0
- package/kits/multiplayer-3d/scripts/test-join-watchdog.mjs +54 -3
- package/kits/multiplayer-3d/scripts/test-owned-moves.mjs +190 -0
- package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +191 -5
- package/kits/multiplayer-3d/scripts/test-resync-reconnect.mjs +68 -0
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/scene.js +10 -2
- package/kits/physics-3d/CLAUDE.md +14 -0
- package/kits/physics-3d/behaviors/Player.jsx +39 -3
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/docs/engine-model-cache.md +109 -0
- package/kits/physics-3d/docs/engine-player.md +76 -0
- package/kits/physics-3d/docs/engine-skip-work.md +16 -0
- package/kits/physics-3d/docs/pxmodel-format.md +5 -1
- package/kits/physics-3d/engine3d/gait.js +16 -8
- package/kits/physics-3d/engine3d/groundsize.js +23 -0
- package/kits/physics-3d/engine3d/kithooks.js +50 -0
- package/kits/physics-3d/engine3d/look.js +110 -17
- package/kits/physics-3d/engine3d/lookbake.js +19 -1
- package/kits/physics-3d/engine3d/materialpresets.js +3 -2
- package/kits/physics-3d/engine3d/modelcache.js +280 -0
- package/kits/physics-3d/engine3d/modelcachedigest.js +37 -0
- package/kits/physics-3d/engine3d/modelcachegate.js +69 -0
- package/kits/physics-3d/engine3d/modelrefs.js +13 -0
- package/kits/physics-3d/engine3d/optimize.js +20 -9
- package/kits/physics-3d/engine3d/playerRun.js +26 -1
- package/kits/physics-3d/engine3d/pxmodel.js +7 -3
- package/kits/physics-3d/engine3d/templatecache.js +722 -0
- package/kits/physics-3d/engine3d/world3d.js +211 -17
- package/kits/physics-3d/package-lock.json +1 -1
- package/kits/physics-3d/package.json +2 -1
- package/kits/physics-3d/play/behaviors/Player.js +43 -3
- package/kits/physics-3d/scripts/render.mjs +56 -8
- package/kits/physics-3d/scripts/template-cache-fixtures.mjs +37 -0
- package/kits/physics-3d/scripts/template-cache-v1-bytes.json +49 -0
- package/kits/physics-3d/scripts/test-gait.mjs +53 -9
- package/kits/physics-3d/scripts/test-ground-half.mjs +120 -0
- package/kits/physics-3d/scripts/test-model-cache.mjs +600 -0
- package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1 -0
- package/kits/physics-3d/scripts/test-sleeping-models.mjs +384 -0
- package/kits/physics-3d/scripts/test-template-cache-minified.mjs +106 -0
- package/kits/physics-3d/scripts/test-template-cache.mjs +519 -0
- package/kits/physics-3d/scripts/test-wall-slide.mjs +272 -0
- package/kits/physics-3d/systems/physics3d.js +51 -2
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/client/connection.js +3 -0
- package/package.json +2 -2
- package/vendor/three/examples/jsm/libs/fflate.module.js +2672 -0
|
@@ -465,6 +465,416 @@ const FACES = [{ playerId: 'p1' }, { playerId: 'p2', note: 'on the bench' }, { p
|
|
|
465
465
|
n += 1;
|
|
466
466
|
}
|
|
467
467
|
|
|
468
|
+
// --- v1.179 `ballot.keepAway` ---------------------------------------------
|
|
469
|
+
|
|
470
|
+
// The manifest: only true or absent, only where a dropped visit is retained,
|
|
471
|
+
// and never on the client's place.
|
|
472
|
+
{
|
|
473
|
+
const KEEP = { resume: { keep: true } };
|
|
474
|
+
const { manifest } = readManifest(deck({ lines: LINES, keepAway: true }, KEEP), scenes);
|
|
475
|
+
assert.deepEqual(manifest.places.main.ballot, { lines: LINES, keepAway: true });
|
|
476
|
+
assert.deepEqual(publicPlace('main', manifest.places.main).ballot, { lines: LINES });
|
|
477
|
+
assert.deepEqual(readManifest(deck({ keepAway: true }, KEEP), scenes).manifest.places.main.ballot, { lines: [], keepAway: true });
|
|
478
|
+
assert.deepEqual(readManifest(deck({ lines: LINES }, KEEP), scenes).manifest.places.main.ballot, { lines: LINES });
|
|
479
|
+
for (const bad of [false, 'yes', 1, null, {}]) {
|
|
480
|
+
assert.match(readManifest(deck({ lines: LINES, keepAway: bad }, KEEP), scenes).errors.join(), /ballot\.keepAway must be true or absent/, String(bad));
|
|
481
|
+
}
|
|
482
|
+
// A game that keeps no dropped visit: no result-place keep, `resume: true` alone.
|
|
483
|
+
for (const extra of [{}, { resume: true }]) {
|
|
484
|
+
assert.match(readManifest(deck({ lines: LINES, keepAway: true }, extra), scenes).errors.join(), /ballot\.keepAway needs a place that retains a dropped visit/);
|
|
485
|
+
}
|
|
486
|
+
// A place without result: resumePose, houseResume and a plain one (a host's
|
|
487
|
+
// pinned reconnect window) retain; resumeArrivalPose does not.
|
|
488
|
+
const at = (keys) => readManifest(deck(undefined, { places: { meet: { title: 'Meeting', scene: 'scenes/meet.scene', ballot: { keepAway: true }, ...keys } } }), scenes);
|
|
489
|
+
for (const keys of [{}, { resumePose: true }, { houseResume: true }]) {
|
|
490
|
+
assert.deepEqual(at(keys).errors, [], JSON.stringify(keys));
|
|
491
|
+
assert.equal(at(keys).manifest.places.meet.ballot.keepAway, true);
|
|
492
|
+
}
|
|
493
|
+
assert.match(at({ resumeArrivalPose: true }).errors.join(), /places\.meet\.ballot\.keepAway needs a place that retains/);
|
|
494
|
+
n += 1;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
const KEEP_AWAY = { ballot: { lines: LINES, keepAway: true }, extra: { resume: { keep: true } } };
|
|
498
|
+
const drop = (b, id) => {
|
|
499
|
+
b.world.players.delete(id);
|
|
500
|
+
b.session.players = b.session.players.filter((p) => p.playerId !== id);
|
|
501
|
+
b.h.place(b.world, []);
|
|
502
|
+
b.tick();
|
|
503
|
+
};
|
|
504
|
+
const lastCard = (b, id) => deliveredTo(b, id);
|
|
505
|
+
|
|
506
|
+
// A retained player keeps their face, marked away, on every card for the
|
|
507
|
+
// others, a card made while they are away included; a tap on it is taken as
|
|
508
|
+
// any; their own card is not sent while they are gone.
|
|
509
|
+
{
|
|
510
|
+
const leaves = [];
|
|
511
|
+
const b = withCtx({ ...KEEP_AWAY, hooks: { leave: (hub, playerId) => leaves.push(playerId) } });
|
|
512
|
+
b.hub.ballot(null, { mode: 'vote', faces: FACES });
|
|
513
|
+
b.tick();
|
|
514
|
+
b.sent.length = 0;
|
|
515
|
+
drop(b, 'p2');
|
|
516
|
+
assert.deepEqual(leaves, []);
|
|
517
|
+
assert.deepEqual(cards(b).map(([to]) => to), ['p1', 'p3', 'p4']);
|
|
518
|
+
const card = lastCard(b, 'p1');
|
|
519
|
+
assert.deepEqual(card.faces, [{ id: 'p1' }, { id: 'p2', note: 'on the bench', away: true }, { id: 'p3', note: 'out', off: true }, { id: 'p4', mark: '#ff0000' }]);
|
|
520
|
+
assert.deepEqual(card.who.p2, { name: 'bo', avatar: 4 });
|
|
521
|
+
tapAs(b, 'p1', { face: 'p2' });
|
|
522
|
+
assert.deepEqual(b.calls, [['p1', { face: 'p2', line: null, option: null, mode: 'vote' }]]);
|
|
523
|
+
// A new card while they are away still has them; an `off` stays off.
|
|
524
|
+
b.hub.ballot(null, { mode: 'vote', faces: [{ playerId: 'p2', votes: 1 }, { playerId: 'p3' }], picked: { face: 'p2' } });
|
|
525
|
+
b.tick();
|
|
526
|
+
assert.deepEqual(lastCard(b, 'p3').faces, [{ id: 'p2', votes: 1, away: true }, { id: 'p3' }]);
|
|
527
|
+
assert.deepEqual(lastCard(b, 'p3').picked, { face: 'p2' });
|
|
528
|
+
b.hub.ballot(null, { mode: 'talk', faces: [{ playerId: 'p2', off: true }] });
|
|
529
|
+
b.tick();
|
|
530
|
+
assert.deepEqual(lastCard(b, 'p4').faces, [{ id: 'p2', off: true, away: true }]);
|
|
531
|
+
tapAs(b, 'p4', { face: 'p2', line: 'boat' });
|
|
532
|
+
assert.equal(b.calls.length, 1);
|
|
533
|
+
assert.ok(!b.sent.some(([to]) => to === 'p2'));
|
|
534
|
+
n += 1;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
// When the retention ends the face goes and the leave hook runs, as for any
|
|
538
|
+
// leave; a tap on it from then is refused.
|
|
539
|
+
{
|
|
540
|
+
const leaves = [];
|
|
541
|
+
const b = withCtx({ ...KEEP_AWAY, hooks: { leave: (hub, playerId) => leaves.push(playerId) } });
|
|
542
|
+
b.hub.ballot(null, { mode: 'vote', faces: FACES });
|
|
543
|
+
b.tick();
|
|
544
|
+
drop(b, 'p2');
|
|
545
|
+
assert.ok(lastCard(b, 'p1').faces.some((f) => f.id === 'p2' && f.away));
|
|
546
|
+
const v = lastCard(b, 'p1').v;
|
|
547
|
+
const realNow = Date.now;
|
|
548
|
+
Date.now = () => realNow() + 61_000;
|
|
549
|
+
b.h.place(b.world, []);
|
|
550
|
+
b.tick();
|
|
551
|
+
Date.now = realNow;
|
|
552
|
+
assert.deepEqual(leaves, ['p2']);
|
|
553
|
+
assert.deepEqual(lastCard(b, 'p1').faces.map((f) => f.id), ['p1', 'p3', 'p4']);
|
|
554
|
+
assert.equal(lastCard(b, 'p1').v, v);
|
|
555
|
+
tapAs(b, 'p1', { face: 'p2' });
|
|
556
|
+
assert.equal(b.calls.length, 0);
|
|
557
|
+
n += 1;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
// Back inside the window: their own card is replayed as ever, and the others'
|
|
561
|
+
// faces of them lose the mark.
|
|
562
|
+
{
|
|
563
|
+
const b = withCtx(KEEP_AWAY);
|
|
564
|
+
b.hub.ballot(null, { title: 'Shared', faces: FACES });
|
|
565
|
+
b.tick();
|
|
566
|
+
drop(b, 'p2');
|
|
567
|
+
assert.equal(lastCard(b, 'p1').faces[1].away, true);
|
|
568
|
+
b.sent.length = 0;
|
|
569
|
+
b.world.players.set('p2', { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
|
|
570
|
+
b.session.players = ROSTER;
|
|
571
|
+
b.h.place(b.world, []);
|
|
572
|
+
b.h.message(b.session, { playerId: 'p2' }, { k: 'hub-hello', avatar: 4, resume: true });
|
|
573
|
+
b.tick();
|
|
574
|
+
assert.equal(lastCard(b, 'p2').title, 'Shared');
|
|
575
|
+
assert.deepEqual(lastCard(b, 'p1').faces[1], { id: 'p2', note: 'on the bench' });
|
|
576
|
+
n += 1;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
// Blocks hold while one of the pair is away, by the last send they were here
|
|
580
|
+
// together: a block that hid them keeps hiding, and a viewer who came after
|
|
581
|
+
// the drop (the host cannot say) is not shown the face.
|
|
582
|
+
{
|
|
583
|
+
const b = withCtx({ ...KEEP_AWAY, hiddenPair: (x, y) => [x, y].sort().join() === 'p1,p2' });
|
|
584
|
+
b.hub.ballot(null, { faces: FACES });
|
|
585
|
+
b.tick();
|
|
586
|
+
drop(b, 'p2');
|
|
587
|
+
assert.deepEqual(lastCard(b, 'p1').faces.map((f) => f.id), ['p1', 'p3', 'p4']);
|
|
588
|
+
assert.ok(!JSON.stringify(lastCard(b, 'p1')).includes('p2'));
|
|
589
|
+
assert.equal(lastCard(b, 'p3').faces[1].away, true);
|
|
590
|
+
tapAs(b, 'p1', { face: 'p2', line: 'boat' });
|
|
591
|
+
assert.equal(b.calls.length, 0);
|
|
592
|
+
b.world.players.set('p5', { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
|
|
593
|
+
b.session.players = [...b.session.players, { playerId: 'p5', userId: '105', username: 'ed' }];
|
|
594
|
+
b.h.message(b.session, { playerId: 'p5' }, { k: 'hub-hello', avatar: 2 });
|
|
595
|
+
b.h.place(b.world, []);
|
|
596
|
+
b.tick();
|
|
597
|
+
assert.ok(lastCard(b, 'p5'));
|
|
598
|
+
assert.ok(!lastCard(b, 'p5').faces.some((f) => f.id === 'p2'));
|
|
599
|
+
n += 1;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
// Review: the record of who was here together is bound to the signed-in
|
|
603
|
+
// accounts then. A viewer id that now carries another account gets no away
|
|
604
|
+
// face, its tap on one is refused, even before the next send.
|
|
605
|
+
{
|
|
606
|
+
const b = withCtx(KEEP_AWAY);
|
|
607
|
+
b.hub.ballot(null, { mode: 'vote', faces: FACES });
|
|
608
|
+
b.tick();
|
|
609
|
+
drop(b, 'p2');
|
|
610
|
+
assert.equal(lastCard(b, 'p1').faces[1].away, true);
|
|
611
|
+
// p1's id switches to an account that was never here with bo.
|
|
612
|
+
b.session.players = b.session.players.map((p) => (p.playerId === 'p1' ? { playerId: 'p1', userId: '201', username: 'zed' } : p));
|
|
613
|
+
tapAs(b, 'p1', { face: 'p2' });
|
|
614
|
+
assert.equal(b.calls.length, 0);
|
|
615
|
+
b.tick();
|
|
616
|
+
assert.deepEqual(lastCard(b, 'p1').faces.map((f) => f.id), ['p1', 'p3', 'p4']);
|
|
617
|
+
assert.ok(!JSON.stringify(lastCard(b, 'p1')).includes('"bo"'));
|
|
618
|
+
// Another viewer, unchanged, still sees and votes on the face.
|
|
619
|
+
assert.equal(lastCard(b, 'p3').faces[1].away, true);
|
|
620
|
+
tapAs(b, 'p3', { face: 'p2' });
|
|
621
|
+
assert.equal(b.calls.length, 1);
|
|
622
|
+
n += 1;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
// Review: across a viewer's own drop and resume, the same account sees the
|
|
626
|
+
// away face again; another account on the returning id does not.
|
|
627
|
+
for (const account of ['101', '201']) {
|
|
628
|
+
const b = withCtx(KEEP_AWAY);
|
|
629
|
+
b.hub.ballot(null, { mode: 'vote', faces: FACES });
|
|
630
|
+
b.tick();
|
|
631
|
+
drop(b, 'p2');
|
|
632
|
+
drop(b, 'p1');
|
|
633
|
+
b.sent.length = 0;
|
|
634
|
+
b.world.players.set('p1', { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
|
|
635
|
+
b.session.players = [{ playerId: 'p1', userId: account, username: account === '101' ? 'amy' : 'zed' }, ...b.session.players];
|
|
636
|
+
b.h.place(b.world, []);
|
|
637
|
+
b.h.message(b.session, { playerId: 'p1' }, { k: 'hub-hello', avatar: 3, resume: true });
|
|
638
|
+
b.h.place(b.world, []);
|
|
639
|
+
b.tick();
|
|
640
|
+
const card = lastCard(b, 'p1');
|
|
641
|
+
if (account === '101') {
|
|
642
|
+
assert.equal(card.faces.find((f) => f.id === 'p2')?.away, true, 'same account');
|
|
643
|
+
tapAs(b, 'p1', { face: 'p2' });
|
|
644
|
+
assert.equal(b.calls.length, 1);
|
|
645
|
+
} else {
|
|
646
|
+
assert.ok(card, 'the other account is sent a card');
|
|
647
|
+
assert.ok(!card.faces.some((f) => f.id === 'p2'), 'another account');
|
|
648
|
+
assert.ok(!JSON.stringify(card).includes('"bo"'));
|
|
649
|
+
tapAs(b, 'p1', { face: 'p2', v: card.v });
|
|
650
|
+
assert.equal(b.calls.length, 0);
|
|
651
|
+
}
|
|
652
|
+
n += 1;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
// Review 2: a target that switches accounts without another hello and then
|
|
656
|
+
// drops leaves no away face at all: the profile its visit holds belongs to
|
|
657
|
+
// the old account, so no record is written under the new one, and nothing
|
|
658
|
+
// of bo (name or avatar) reaches anyone. Once a hello is made under the new
|
|
659
|
+
// account, its own profile is what the away face shows.
|
|
660
|
+
for (const hello of [false, true]) {
|
|
661
|
+
let b;
|
|
662
|
+
const accountOf = (id) => b.session.players.find((p) => p.playerId === id)?.userId;
|
|
663
|
+
b = withCtx({ ...KEEP_AWAY, hiddenPair: (x, y) => [accountOf(x), accountOf(y)].sort().join() === '101,102' });
|
|
664
|
+
b.hub.ballot(null, { mode: 'vote', faces: FACES });
|
|
665
|
+
b.tick();
|
|
666
|
+
b.session.players = b.session.players.map((p) => (p.playerId === 'p2' ? { playerId: 'p2', userId: '202', username: 'zed' } : p));
|
|
667
|
+
if (hello) {
|
|
668
|
+
b.h.message(b.session, { playerId: 'p2' }, { k: 'hub-hello', avatar: 9 });
|
|
669
|
+
}
|
|
670
|
+
b.tick();
|
|
671
|
+
b.tick();
|
|
672
|
+
b.sent.length = 0;
|
|
673
|
+
drop(b, 'p2');
|
|
674
|
+
const p1 = lastCard(b, 'p1');
|
|
675
|
+
const p3 = lastCard(b, 'p3');
|
|
676
|
+
if (!hello) {
|
|
677
|
+
for (const card of [p1, p3]) {
|
|
678
|
+
assert.ok(!card.faces.some((f) => f.id === 'p2'), 'no away face without a profile under the new account');
|
|
679
|
+
}
|
|
680
|
+
assert.ok(!JSON.stringify(cards(b)).includes('"bo"'));
|
|
681
|
+
assert.ok(!JSON.stringify(cards(b)).includes('"avatar":4'));
|
|
682
|
+
tapAs(b, 'p1', { face: 'p2', v: p1.v });
|
|
683
|
+
assert.equal(b.calls.length, 0);
|
|
684
|
+
} else {
|
|
685
|
+
assert.deepEqual(p1.faces.find((f) => f.id === 'p2'), { id: 'p2', note: 'on the bench', away: true });
|
|
686
|
+
assert.deepEqual(p1.who.p2, { name: 'zed', avatar: 9 });
|
|
687
|
+
assert.ok(!JSON.stringify(cards(b)).includes('"bo"'));
|
|
688
|
+
}
|
|
689
|
+
n += 1;
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
// Review 2: a tap is judged by the invariant now, never by the card's flag.
|
|
693
|
+
// (a) The target drops and the viewer's id switches accounts before the next
|
|
694
|
+
// send: the card still shows the face as present, and the tap is refused.
|
|
695
|
+
{
|
|
696
|
+
const b = withCtx(KEEP_AWAY);
|
|
697
|
+
b.hub.ballot(null, { mode: 'vote', faces: FACES });
|
|
698
|
+
b.tick();
|
|
699
|
+
assert.equal(lastCard(b, 'p1').faces[1].away, undefined);
|
|
700
|
+
b.world.players.delete('p2');
|
|
701
|
+
b.session.players = b.session.players.filter((p) => p.playerId !== 'p2')
|
|
702
|
+
.map((p) => (p.playerId === 'p1' ? { playerId: 'p1', userId: '201', username: 'zed' } : p));
|
|
703
|
+
tapAs(b, 'p1', { face: 'p2' });
|
|
704
|
+
assert.equal(b.calls.length, 0);
|
|
705
|
+
// The same drop with the viewer's account unchanged is still taken.
|
|
706
|
+
tapAs(b, 'p3', { face: 'p2' });
|
|
707
|
+
assert.equal(b.calls.length, 1);
|
|
708
|
+
n += 1;
|
|
709
|
+
}
|
|
710
|
+
// (b) An away target resumes on the same account before the next send: the
|
|
711
|
+
// card still marks them away, and the tap counts (they are present now).
|
|
712
|
+
{
|
|
713
|
+
const b = withCtx(KEEP_AWAY);
|
|
714
|
+
b.hub.ballot(null, { mode: 'vote', faces: FACES });
|
|
715
|
+
b.tick();
|
|
716
|
+
drop(b, 'p2');
|
|
717
|
+
assert.equal(lastCard(b, 'p1').faces[1].away, true);
|
|
718
|
+
b.world.players.set('p2', { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
|
|
719
|
+
b.session.players = ROSTER;
|
|
720
|
+
tapAs(b, 'p1', { face: 'p2' });
|
|
721
|
+
assert.equal(b.calls.length, 1);
|
|
722
|
+
n += 1;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
// Review 3. A town-like place (no result, resumePose) for the Back cases.
|
|
726
|
+
const TOWN_AWAY = { ballot: { lines: LINES, keepAway: true }, extra: { result: undefined, resumePose: true } };
|
|
727
|
+
assert.equal(readManifest(deck(TOWN_AWAY.ballot, TOWN_AWAY.extra), scenes).manifest.places.main.result, null);
|
|
728
|
+
const switchTo = (b, id, row) => {
|
|
729
|
+
b.session.players = b.session.players.map((p) => (p.playerId === id ? { playerId: id, ...row } : p));
|
|
730
|
+
};
|
|
731
|
+
|
|
732
|
+
// (1) A present target switches to an account that blocks the viewer: a tap
|
|
733
|
+
// before the next tick is refused (blocks are never read from a cache made
|
|
734
|
+
// under the old account); another viewer's tap still counts.
|
|
735
|
+
{
|
|
736
|
+
let b;
|
|
737
|
+
const accountOf = (id) => b.session.players.find((p) => p.playerId === id)?.userId;
|
|
738
|
+
b = withCtx({ ...KEEP_AWAY, hiddenPair: (x, y) => [accountOf(x), accountOf(y)].sort().join() === '101,202' });
|
|
739
|
+
b.hub.ballot(null, { mode: 'vote', faces: FACES });
|
|
740
|
+
b.tick();
|
|
741
|
+
switchTo(b, 'p2', { userId: '202', username: 'zed' });
|
|
742
|
+
tapAs(b, 'p1', { face: 'p2' });
|
|
743
|
+
assert.equal(b.calls.length, 0);
|
|
744
|
+
tapAs(b, 'p3', { face: 'p2' });
|
|
745
|
+
assert.equal(b.calls.length, 1);
|
|
746
|
+
n += 1;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
// (2) A target switches account, says hello under it, and drops before the
|
|
750
|
+
// next send: the switch was seen at the hello, so the old account's record
|
|
751
|
+
// is gone and nobody gets bo's name or avatar as an away face.
|
|
752
|
+
{
|
|
753
|
+
const b = withCtx(KEEP_AWAY);
|
|
754
|
+
b.hub.ballot(null, { mode: 'vote', faces: FACES });
|
|
755
|
+
b.tick();
|
|
756
|
+
b.sent.length = 0;
|
|
757
|
+
switchTo(b, 'p2', { userId: '202', username: 'zed' });
|
|
758
|
+
b.h.message(b.session, { playerId: 'p2' }, { k: 'hub-hello', avatar: 9 });
|
|
759
|
+
drop(b, 'p2');
|
|
760
|
+
for (const id of ['p1', 'p3']) {
|
|
761
|
+
assert.ok(!lastCard(b, id).faces.some((f) => f.id === 'p2'), id);
|
|
762
|
+
}
|
|
763
|
+
assert.ok(!JSON.stringify(cards(b)).includes('"bo"'));
|
|
764
|
+
tapAs(b, 'p1', { face: 'p2' });
|
|
765
|
+
assert.equal(b.calls.length, 0);
|
|
766
|
+
n += 1;
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
// (3) Generations are never reused: a viewer whose id switched A -> B, then
|
|
770
|
+
// left by their own Back and was forgotten, comes back as A on the same id
|
|
771
|
+
// and is not given back the away face the switch invalidated.
|
|
772
|
+
{
|
|
773
|
+
const b = withCtx(TOWN_AWAY);
|
|
774
|
+
b.hub.ballot(null, { mode: 'vote', faces: FACES });
|
|
775
|
+
b.tick();
|
|
776
|
+
drop(b, 'p2');
|
|
777
|
+
assert.equal(lastCard(b, 'p1').faces[1].away, true);
|
|
778
|
+
switchTo(b, 'p1', { userId: '201', username: 'zed' });
|
|
779
|
+
b.tick();
|
|
780
|
+
assert.ok(!lastCard(b, 'p1').faces.some((f) => f.id === 'p2'));
|
|
781
|
+
b.h.message(b.session, { playerId: 'p1' }, { k: 'hub-back' });
|
|
782
|
+
drop(b, 'p1');
|
|
783
|
+
b.h.place(b.world, []);
|
|
784
|
+
b.tick();
|
|
785
|
+
b.world.players.set('p1', { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
|
|
786
|
+
b.session.players = [{ playerId: 'p1', userId: '101', username: 'amy' }, ...b.session.players];
|
|
787
|
+
b.h.message(b.session, { playerId: 'p1' }, { k: 'hub-hello', avatar: 3 });
|
|
788
|
+
b.h.place(b.world, []);
|
|
789
|
+
b.tick();
|
|
790
|
+
const card = lastCard(b, 'p1');
|
|
791
|
+
assert.ok(card && card.faces.some((f) => f.id === 'p1'), 'p1 has a card again');
|
|
792
|
+
assert.ok(!card.faces.some((f) => f.id === 'p2'), 'no away face from a reused generation');
|
|
793
|
+
tapAs(b, 'p1', { face: 'p2', v: card.v });
|
|
794
|
+
assert.equal(b.calls.length, 0);
|
|
795
|
+
n += 1;
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
// (4) The deadline and a fresh own Back are read at the tap and at the send,
|
|
799
|
+
// not only when reconcile runs: past the window, or dropped right after their
|
|
800
|
+
// Back, the target's face takes no tap and is not sent; an ordinary drop
|
|
801
|
+
// inside the window still is.
|
|
802
|
+
{
|
|
803
|
+
const b = withCtx(KEEP_AWAY);
|
|
804
|
+
b.hub.ballot(null, { mode: 'vote', faces: FACES });
|
|
805
|
+
b.tick();
|
|
806
|
+
drop(b, 'p2');
|
|
807
|
+
assert.equal(lastCard(b, 'p1').faces[1].away, true);
|
|
808
|
+
const realNow = Date.now;
|
|
809
|
+
Date.now = () => realNow() + 61_000;
|
|
810
|
+
tapAs(b, 'p1', { face: 'p2' });
|
|
811
|
+
assert.equal(b.calls.length, 0);
|
|
812
|
+
b.tick();
|
|
813
|
+
Date.now = realNow;
|
|
814
|
+
assert.ok(!lastCard(b, 'p1').faces.some((f) => f.id === 'p2'), 'past the deadline at a send');
|
|
815
|
+
n += 1;
|
|
816
|
+
}
|
|
817
|
+
for (const back of [true, false]) {
|
|
818
|
+
const b = withCtx(TOWN_AWAY);
|
|
819
|
+
b.hub.ballot(null, { mode: 'vote', faces: FACES });
|
|
820
|
+
b.tick();
|
|
821
|
+
if (back) {
|
|
822
|
+
b.h.message(b.session, { playerId: 'p2' }, { k: 'hub-back' });
|
|
823
|
+
}
|
|
824
|
+
b.world.players.delete('p2');
|
|
825
|
+
b.session.players = b.session.players.filter((p) => p.playerId !== 'p2');
|
|
826
|
+
tapAs(b, 'p1', { face: 'p2' });
|
|
827
|
+
assert.equal(b.calls.length, back ? 0 : 1, `tap, back ${back}`);
|
|
828
|
+
b.tick();
|
|
829
|
+
assert.equal(lastCard(b, 'p3').faces.some((f) => f.id === 'p2' && f.away), !back, `send, back ${back}`);
|
|
830
|
+
n += 1;
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
// (5) Guests, dev guests included, are never in a record: neither a guest's
|
|
834
|
+
// own face nor an away face for a guest viewer.
|
|
835
|
+
{
|
|
836
|
+
const b = withCtx(KEEP_AWAY);
|
|
837
|
+
switchTo(b, 'p2', { userId: 'dev-guest-7', username: 'guest7', isAnonymous: true });
|
|
838
|
+
b.h.message(b.session, { playerId: 'p2' }, { k: 'hub-hello', avatar: 4 });
|
|
839
|
+
switchTo(b, 'p1', { userId: 'dev-guest-8', username: 'guest8', isAnonymous: true });
|
|
840
|
+
b.h.message(b.session, { playerId: 'p1' }, { k: 'hub-hello', avatar: 3 });
|
|
841
|
+
b.hub.ballot(null, { mode: 'vote', faces: FACES });
|
|
842
|
+
b.tick();
|
|
843
|
+
b.tick();
|
|
844
|
+
drop(b, 'p2');
|
|
845
|
+
drop(b, 'p4');
|
|
846
|
+
assert.ok(!lastCard(b, 'p3').faces.some((f) => f.id === 'p2'), 'a guest has no away face');
|
|
847
|
+
assert.equal(lastCard(b, 'p3').faces.find((f) => f.id === 'p4')?.away, true, 'a signed-in one does');
|
|
848
|
+
assert.ok(!lastCard(b, 'p1').faces.some((f) => f.id === 'p4'), 'a guest viewer sees no away face');
|
|
849
|
+
tapAs(b, 'p1', { face: 'p4' });
|
|
850
|
+
assert.equal(b.calls.length, 0);
|
|
851
|
+
n += 1;
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
// Absent: the same drop leaves no face and no mark, a tap on it is refused,
|
|
855
|
+
// and every card a viewer is sent is the same bytes as
|
|
856
|
+
// with the key (versions aside) while nobody is away.
|
|
857
|
+
{
|
|
858
|
+
const b = withCtx({ ballot: { lines: LINES }, extra: { resume: { keep: true } } });
|
|
859
|
+
b.hub.ballot(null, { mode: 'vote', faces: FACES });
|
|
860
|
+
b.tick();
|
|
861
|
+
drop(b, 'p2');
|
|
862
|
+
assert.deepEqual(lastCard(b, 'p1').faces.map((f) => f.id), ['p1', 'p3', 'p4']);
|
|
863
|
+
assert.ok(!JSON.stringify(cards(b)).includes('"away"'));
|
|
864
|
+
tapAs(b, 'p1', { face: 'p2' });
|
|
865
|
+
assert.equal(b.calls.length, 0);
|
|
866
|
+
const run = (options) => {
|
|
867
|
+
const c = withCtx(options);
|
|
868
|
+
c.hub.ballot(null, { mode: 'vote', title: 'Meeting', faces: FACES, options: [{ id: 'skip', text: 'Skip' }] });
|
|
869
|
+
c.tick();
|
|
870
|
+
c.hub.ballot(['p3'], { faces: FACES, feed: [{ from: 'p1', to: 'p2', line: 'boat' }] });
|
|
871
|
+
c.tick();
|
|
872
|
+
return JSON.stringify(c.sent).replace(/"v":"[0-9a-z]+-/g, '"v":"');
|
|
873
|
+
};
|
|
874
|
+
assert.equal(run({ ballot: { lines: LINES }, extra: { resume: { keep: true } } }), run(KEEP_AWAY));
|
|
875
|
+
n += 1;
|
|
876
|
+
}
|
|
877
|
+
|
|
468
878
|
// (c) One gate on the client. A card that comes ahead of the WORLD snapshot
|
|
469
879
|
// (the server's first tick sends it before WORLD) is held, pending, with its
|
|
470
880
|
// connection; WORLD keeps it for a place with `ballot` or drops it for one
|
|
@@ -534,7 +944,8 @@ const FACES = [{ playerId: 'p1' }, { playerId: 'p2', note: 'on the bench' }, { p
|
|
|
534
944
|
'this.idle.frame(scene, mp, local, !this.trip && this.pendingEnd === null && !this.talk.talking() && !decorating && !this.carded && !this.actionInput, this.sceneKey);',
|
|
535
945
|
// v1.160: a car's Horn is not offered while a card is up.
|
|
536
946
|
'if (myCar?.horn && !this.trip && this.pendingEnd === null && !this.talk.talking() && !decorating && !this.carded) {',
|
|
537
|
-
'
|
|
947
|
+
'const can = !this.trip && this.pendingEnd === null && !talking && !decorating && !this.actionInput && !this.askInput && !this.menuInput && !this.carded;',
|
|
948
|
+
'actionInput: this.actionInput, askInput: this.askInput, menuInput: this.menuInput, carded: this.carded }));',
|
|
538
949
|
'}, !this.signIn.pending() && !this.trip && this.pendingEnd === null && !this.talk.talking() && !decorating && !this.carded && !this.askInput && !this.menuInput,',
|
|
539
950
|
'if (this.ballot) {',
|
|
540
951
|
'const box = this.carded ? this.chrome.hudClearBox?.() : null;',
|
|
@@ -543,6 +954,7 @@ const FACES = [{ playerId: 'p1' }, { playerId: 'p2', note: 'on the bench' }, { p
|
|
|
543
954
|
// A new player id on the same net drops a held card (only one held).
|
|
544
955
|
'if (ballotHeld) {',
|
|
545
956
|
'forgetBallot();',
|
|
957
|
+
'const sheet = Boolean(this.talk?.talking()) || this.carded || Boolean(this.askInput || this.menuInput);',
|
|
546
958
|
'const eligible = !this.trip && place && !place.result && this.pendingEnd === null && !this.talk?.talking?.() && !this.carded &&',
|
|
547
959
|
'const free = idle && place !== null && this.pendingEnd === null && !this.talk.talking() && !this.carded;',
|
|
548
960
|
'place?.id, this.trip?.phase, this.pendingEnd !== null, this.carded, this.decor?.opened() === true,',
|
|
@@ -565,9 +977,12 @@ const FACES = [{ playerId: 'p1' }, { playerId: 'p2', note: 'on the bench' }, { p
|
|
|
565
977
|
]);
|
|
566
978
|
assert.deepEqual(lines('../code/server/hub.js'), [
|
|
567
979
|
"import * as Ballot from './ballot.js';",
|
|
980
|
+
// v1.179: a keepAway place notes account changes from any message.
|
|
981
|
+
'if (h.place?.ballot?.keepAway === true && h.ballotSeen) {Ballot.observe(h, ballotDeps(h), player?.playerId);}',
|
|
568
982
|
"if (h.place?.ballot && data?.k === 'hub-ballot') {",
|
|
569
|
-
'Ballot.message(h, player, data, h.place.ballot.lines);',
|
|
570
|
-
|
|
983
|
+
'Ballot.message(h, player, data, h.place.ballot.lines, h.place.ballot.keepAway === true ? ballotDeps(h) : undefined);',
|
|
984
|
+
// v1.179: a keepAway place notes who is here from its first tick.
|
|
985
|
+
'if (h.ballotState || h.place.ballot?.keepAway === true) {',
|
|
571
986
|
'Ballot.send(h, ballotDeps(h));',
|
|
572
987
|
'if (manifest.ballot) {',
|
|
573
988
|
'h.ctx.ballot = (playerIds, spec) => Ballot.ballot(h, playerIds, spec);',
|
|
@@ -578,7 +993,9 @@ const FACES = [{ playerId: 'p1' }, { playerId: 'p2', note: 'on the bench' }, { p
|
|
|
578
993
|
'h.ballotState.sent.set(player.playerId, STALE);',
|
|
579
994
|
'if (h.ballotState) {',
|
|
580
995
|
'Ballot.forget(h, playerId);',
|
|
996
|
+
'h.ballotSeen?.records.delete(playerId);',
|
|
581
997
|
'function ballotDeps(h) {',
|
|
998
|
+
'...(h.place.ballot?.keepAway === true ? {',
|
|
582
999
|
]);
|
|
583
1000
|
assert.deepEqual(lines('../code/client/state.js'), []);
|
|
584
1001
|
// A keyless manifest carries no ballot anywhere.
|
|
@@ -124,7 +124,7 @@ for (const code of ['MULTIPLAYER_UNAVAILABLE', 'CAULDRON_HUB_INVITE_NOT_IN_SESSI
|
|
|
124
124
|
attempts = 0;
|
|
125
125
|
answer = () => Promise.reject(castleError(code));
|
|
126
126
|
assert.equal(joinErrorText(code), null);
|
|
127
|
-
// A frame gap over
|
|
127
|
+
// A frame gap over JOIN_STALL_MS (10 s) clears backoff as a visible return. These
|
|
128
128
|
// checks exercise ordinary backoff, so the page must keep stepping.
|
|
129
129
|
const advance = async (ms) => {
|
|
130
130
|
const until = pageMs + ms;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { Scene } from 'three';
|
|
3
|
+
import { receive, frame, clear } from '../code/client/celebrate.js';
|
|
4
|
+
import { readFileSync } from 'node:fs';
|
|
5
|
+
const local = { components: { Transform: { x: 0, y: 0, z: 0 } } };
|
|
6
|
+
const other = { components: { Transform: { x: 5, y: 0, z: 0 } } };
|
|
7
|
+
const scene = { three: { scene: new Scene() }, multiplayer: { net: { selfId: () => 'self' }, avatars: { actors: new Map([['winner', 'avatar']]) } }, getActor: (id) => id === 'avatar' ? other : null };
|
|
8
|
+
const options = { now: 0, low: false, live: true, doors: [{ id: 'race', title: 'Foot Race' }], cam: {}, view: {}, project: (cam, x, y, z) => ({ x, y }) };
|
|
9
|
+
const msg = { k: 'celebrate', player: 'winner', kind: 'win', door: 'race', tokens: 25 };
|
|
10
|
+
assert.deepEqual(frame(scene, local, options), []); assert.equal(scene.three.scene.children.length, 0);
|
|
11
|
+
assert.equal(receive(scene, { ...msg, kind: 'lose' }, 0), false);
|
|
12
|
+
assert.equal(receive(scene, { ...msg, tokens: 41 }, 0), false);
|
|
13
|
+
assert.equal(receive(scene, msg, 0), true);
|
|
14
|
+
let labels = frame(scene, local, { ...options, low: true, now: 100 });
|
|
15
|
+
assert.equal(labels[0].text, 'won Foot Race · +25');
|
|
16
|
+
assert.equal(scene.three.scene.children.length, 0, 'Low makes no emitter');
|
|
17
|
+
labels = frame(scene, local, { ...options, now: 200 });
|
|
18
|
+
assert.equal(scene.three.scene.children.length, 1); const emitter = scene.three.scene.children[0];
|
|
19
|
+
assert.equal(emitter.geometry.attributes.position.count, 24);
|
|
20
|
+
assert.equal(emitter.position.x, 5, 'burst follows the celebrating avatar');
|
|
21
|
+
other.components.Transform.x = 7; frame(scene, local, { ...options, now: 300 }); assert.equal(emitter.position.x, 7);
|
|
22
|
+
receive(scene, msg, 400); frame(scene, local, { ...options, now: 500 }); assert.equal(scene.three.scene.children[0], emitter, 'one pooled emitter across wins');
|
|
23
|
+
frame(scene, local, { ...options, low: true, now: 600 }); assert.equal(emitter.visible, false);
|
|
24
|
+
frame(scene, local, { ...options, now: 2900 }); assert.equal(emitter.visible, false, 'burst lasts 2.5 seconds');
|
|
25
|
+
assert.equal(frame(scene, local, { ...options, now: 20399 }).length, 1);
|
|
26
|
+
assert.equal(frame(scene, local, { ...options, now: 20400 }).length, 0, 'public ribbon lasts exactly 20 seconds');
|
|
27
|
+
receive(scene, { ...msg, player: 'self' }, 21000);
|
|
28
|
+
assert.equal(frame(scene, local, { ...options, now: 21100 }).length, 0, 'winner keeps the private ribbon');
|
|
29
|
+
let geometryDisposed = false, materialDisposed = false;
|
|
30
|
+
emitter.geometry.addEventListener('dispose', () => geometryDisposed = true); emitter.material.addEventListener('dispose', () => materialDisposed = true);
|
|
31
|
+
frame(scene, local, { ...options, live: false, now: 21200 });
|
|
32
|
+
assert.equal(scene.three.scene.children.length, 0); assert(geometryDisposed && materialDisposed);
|
|
33
|
+
clear();
|
|
34
|
+
// Cap-zero wins use the same burst and ribbon lifetime, without a +0 suffix.
|
|
35
|
+
assert(receive(scene, { ...msg, tokens: 0 }, 22000));
|
|
36
|
+
assert.equal(frame(scene, local, { ...options, low: true, now: 22100 })[0].text, 'won Foot Race');
|
|
37
|
+
assert.equal(scene.three.scene.children.length, 0, 'Low still skips the zero-token burst');
|
|
38
|
+
assert.equal(frame(scene, local, { ...options, now: 22200 })[0].text, 'won Foot Race');
|
|
39
|
+
const zeroEmitter = scene.three.scene.children[0]; assert(zeroEmitter?.visible, 'zero-token wins still burst');
|
|
40
|
+
assert.equal(frame(scene, local, { ...options, now: 24500 })[0].text, 'won Foot Race');
|
|
41
|
+
assert.equal(zeroEmitter.visible, false, 'zero-token burst keeps its 2.5 second lifetime');
|
|
42
|
+
assert.equal(frame(scene, local, { ...options, now: 41999 }).length, 1);
|
|
43
|
+
assert.equal(frame(scene, local, { ...options, now: 42000 }).length, 0);
|
|
44
|
+
clear();
|
|
45
|
+
const source = readFileSync(new URL('../code/systems/hub.js', import.meta.url), 'utf8');
|
|
46
|
+
assert.match(source, /const RIBBON_MS = 60000/, 'private ribbon retains its 60 seconds');
|
|
47
|
+
const hook = readFileSync(new URL('../code/client/hookLayer.js', import.meta.url), 'utf8');
|
|
48
|
+
assert.match(hook, /case 'celebrate':[\s\S]*cue: 'token'/, 'coin chime uses existing audio gates');
|
|
49
|
+
// Exercise the real chrome setter with a tiny DOM stand-in: pool bounds,
|
|
50
|
+
// text safety, hiding, and one HUD-clearance batch independent of self ribbon.
|
|
51
|
+
const chrome = readFileSync(new URL('../code/client/chrome.js', import.meta.url), 'utf8');
|
|
52
|
+
const start = chrome.indexOf(' setWinRibbons(items) {'), end = chrome.indexOf(' setRibbon(pos, text) {', start);
|
|
53
|
+
const nodes = [], clearance = [];
|
|
54
|
+
const publicChrome = new Function('el', 'root', 'keepClearOfHud', `let winRibbons = null; const hudClear = true; return {${chrome.slice(start, end)}};`)(
|
|
55
|
+
(tag, style, root) => { const node = { style: { ...style }, textContent: '' }; root.push(node); return node; }, nodes, (...args) => clearance.push(args));
|
|
56
|
+
publicChrome.setWinRibbons([]); assert.equal(nodes.length, 0);
|
|
57
|
+
publicChrome.setWinRibbons([{ x: 1, y: 2, text: '<winner>' }, { x: 3, y: 4, text: 'second' }]);
|
|
58
|
+
assert.equal(nodes.length, 2); assert.equal(nodes[0].textContent, '<winner>');
|
|
59
|
+
assert.equal(clearance.at(-1)[0], 'win-ribbons'); assert.equal(clearance.at(-1)[1].length, 2);
|
|
60
|
+
publicChrome.setWinRibbons(Array.from({ length: 12 }, (_, i) => ({ x: i, y: i, text: 'win' }))); assert.equal(nodes.length, 8);
|
|
61
|
+
publicChrome.setWinRibbons([]); assert(nodes.every((node) => node.style.display === 'none'));
|
|
62
|
+
console.log('Celebration client: lazy pooled emitter, Low skip, following pose, ribbons, audio hook and disposal: ok');
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// Celebration v1.205: real hub layer, fake transport/body, no Rapier needed.
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { register } from 'node:module';
|
|
4
|
+
const sceneStub = 'export const readScene = () => globalThis.__hubTestActors ?? [];';
|
|
5
|
+
register(`data:text/javascript,${encodeURIComponent(`
|
|
6
|
+
export async function resolve(specifier, context, next) {
|
|
7
|
+
if (specifier === '@imports/castle.multiplayer-3d/code/server/sceneBodies.js') return { url: ${JSON.stringify('data:text/javascript,' + encodeURIComponent(sceneStub))}, shortCircuit: true };
|
|
8
|
+
if (specifier === '@imports/castle.multiplayer-3d/code/server/players.js') return { url: 'data:text/javascript,export function setPose(sim,id,msg){sim.reports.push([id,msg])}', shortCircuit: true };
|
|
9
|
+
if (specifier === '@imports/castle.multiplayer-3d/code/server/limits.js') return { url: 'data:text/javascript,export const readPoint=()=>null', shortCircuit: true };
|
|
10
|
+
return next(specifier, context);
|
|
11
|
+
}
|
|
12
|
+
`)}`);
|
|
13
|
+
const { layer } = await import('../code/server/hub.js');
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
let clock = 1_800_000_000_000;
|
|
17
|
+
const realNow = Date.now;
|
|
18
|
+
Date.now = () => clock;
|
|
19
|
+
function boot({ retained = false, count = 3, arrived = true, grab = false, grabHook } = {}) {
|
|
20
|
+
globalThis.__hubTestActors = [
|
|
21
|
+
{ id: 'spawn', components: { Player: {}, Transform: { x: 0, y: 1, z: 0 } } },
|
|
22
|
+
{ id: 'car', components: { Model: { file: 'car.pxmodel' }, Transform: {} } },
|
|
23
|
+
{ id: 'bench', components: { HubSeat: {}, Transform: {}, Shape: { kind: 'box', height: 0.3 } } },
|
|
24
|
+
{ id: 'door', components: { HubDoor: { id: 'game', to: 'game' }, Transform: {} } },
|
|
25
|
+
...(grab ? [{ id: 'crate', components: { Transform: { x: 0, y: 1, z: 1 }, Shape: { kind: 'box' }, Body: { type: 'dynamic' } } }] : []),
|
|
26
|
+
];
|
|
27
|
+
const sent = [], broadcast = [], left = [];
|
|
28
|
+
const players = Array.from({ length: count }, (_, i) => ({ playerId: `p${i + 1}`, username: `user${i}`, userId: `${i + 1}` }));
|
|
29
|
+
const session = { sessionId: 'dev', players: [...players], send: (id, msg) => sent.push([id, msg]), broadcast: msg => broadcast.push(msg) };
|
|
30
|
+
const body = () => ({ at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
|
|
31
|
+
const sim = { timeMs: 0, scenePath: retained ? 'scenes/game.scene' : 'scenes/main.scene', players: new Map(players.map(p => [p.playerId, body()])), objects: new Map(), bodies: new Map(), reports: [] };
|
|
32
|
+
let hub;
|
|
33
|
+
const opts = { title: 'Town', contract: 1, stuck: true, unlocks: [{ id: 'stadium-pin', class: 'pin', shape: 'pin-round', color: '#e5484d', name: 'Stadium pin', deed: 'Win in Stadium' }], idle: { seats: true, sounds: ['sounds/horn.wav'] }, places: { game: { title: 'Game', scene: 'scenes/game.scene', result: {}, ...(retained ? { resume: { keep: true } } : {}) } } };
|
|
34
|
+
if (grab) {opts.grab = grab;}
|
|
35
|
+
if (retained) {session.place = 'game'; opts.places.game.idle = opts.idle;}
|
|
36
|
+
// resolvePlace reads session's authoritative place field.
|
|
37
|
+
const hooks = { ready(ctx) {hub = ctx;}, leave(ctx, id) {left.push(id);}, grab: grabHook };
|
|
38
|
+
const server = layer({ server: { maxPlayers: Math.max(8, count) }, hub: opts }, hooks, { game: hooks }, () => true);
|
|
39
|
+
server.sceneFor(session); server.ready(sim);
|
|
40
|
+
const say = (id, data) => server.message(session, { playerId: id }, data);
|
|
41
|
+
const tick = (ms = 50) => {sim.timeMs += ms; clock += ms; server.place(sim); server.step(sim, []);};
|
|
42
|
+
if (arrived) {players.forEach(p => say(p.playerId, { k: 'hub-hello', avatar: 0, party: 1 }));
|
|
43
|
+
tick(2000); tick(5000);}
|
|
44
|
+
for (const p of sim.players.values()) {p.at = { x: 0, y: 1, z: 0 };}
|
|
45
|
+
const drop = id => {session.players.splice(session.players.findIndex(p => p.playerId === id), 1); sim.players.delete(id);};
|
|
46
|
+
const back = id => {session.players.push(players.find(p => p.playerId === id)); sim.players.set(id, body()); say(id, { k: 'hub-hello', avatar: 0, party: 1, resume: true });};
|
|
47
|
+
return { hub, server, sim, session, sent, broadcast, say, tick, drop, back, left };
|
|
48
|
+
}
|
|
49
|
+
const win = (tokens = 25, extra = {}) => ({ kind: 'win', door: 'game', tokens, ...extra });
|
|
50
|
+
const moments = (r) => r.sent.filter(([, m]) => m.k === 'celebrate');
|
|
51
|
+
let tests = 0;
|
|
52
|
+
async function test(name, fn) { await fn(); tests++; console.log(`ok: ${name}`); }
|
|
53
|
+
try {
|
|
54
|
+
await test('unused snapshot/delta/messages are byte-identical and no empty field is added', async () => {
|
|
55
|
+
const a = boot(), b = boot();
|
|
56
|
+
delete b.hub.celebrate;
|
|
57
|
+
assert.equal(JSON.stringify(a.server.join()), JSON.stringify(b.server.join()));
|
|
58
|
+
a.server.delta(); b.server.delta(); a.sent.length = b.sent.length = 0;
|
|
59
|
+
a.tick(); b.tick();
|
|
60
|
+
assert.equal(JSON.stringify(a.server.delta()), JSON.stringify(b.server.delta()));
|
|
61
|
+
assert.equal(JSON.stringify(a.sent), JSON.stringify(b.sent));
|
|
62
|
+
assert(!JSON.stringify(a.server.join()).includes('celebrat'));
|
|
63
|
+
const snapshot = JSON.stringify(a.server.join());
|
|
64
|
+
await a.hub.celebrate('p1', win());
|
|
65
|
+
assert.equal(JSON.stringify(a.server.join()), snapshot, 'moment never changes snapshot bytes');
|
|
66
|
+
assert.equal(a.server.delta(), null, 'moment never changes delta bytes');
|
|
67
|
+
});
|
|
68
|
+
await test('Town-only capability, server-only transport, validated ids and numeric bounds', async () => {
|
|
69
|
+
const r = boot();
|
|
70
|
+
r.sent.length = 0; r.say('p1', { k: 'celebrate', ...win(), player: 'p2' });
|
|
71
|
+
assert.equal(moments(r).length, 0, 'a client cannot forge a moment');
|
|
72
|
+
for (const spec of [null, [], win(NaN), win(Infinity), win('20'), win(2, { kind: 'lose' }), win(2, { streak: 4 }), win(2, { door: 'missing' }), win(2, { unlock: 'invented' }), win(2, { player: 'p2' })]) assert.equal(await r.hub.celebrate('p1', spec), false);
|
|
73
|
+
assert.equal(await r.hub.celebrate('missing', win()), false);
|
|
74
|
+
assert.equal(await r.hub.celebrate('p1', win(99.5, { streak: 3, unlock: 'stadium-pin' })), true);
|
|
75
|
+
assert.deepEqual(moments(r)[0][1], { k: 'celebrate', player: 'p1', kind: 'win', door: 'game', tokens: 40, streak: 3, unlock: 'stadium-pin' });
|
|
76
|
+
const game = boot({ retained: true }); assert.equal(game.hub.celebrate, undefined);
|
|
77
|
+
const lower = boot(); await lower.hub.celebrate('p1', win(-5)); assert.equal(moments(lower)[0][1].tokens, 0);
|
|
78
|
+
});
|
|
79
|
+
await test('25 m at send time, connected players only and hidden pairs excluded', async () => {
|
|
80
|
+
const r = boot(); r.sim.players.get('p2').at.x = 25; r.sim.players.get('p3').at.x = 25.001;
|
|
81
|
+
r.sent.length = 0; await r.hub.celebrate('p1', win());
|
|
82
|
+
assert.deepEqual(moments(r).map(([id]) => id), ['p1', 'p2']);
|
|
83
|
+
r.session.hub = { readResults: async () => ({ players: {} }), readBoards: async () => ({ doors: {} }), hiddenPair: (a, b) => a === 'p1' && b === 'p2' };
|
|
84
|
+
await r.hub.celebrate('p1', win()); r.sim.players.get('p3').at.x = 1;
|
|
85
|
+
r.tick(4000); assert.deepEqual(moments(r).slice(2).map(([id]) => id), ['p1', 'p3']);
|
|
86
|
+
});
|
|
87
|
+
await test('one per layer per 4 s, three queued and oldest beyond three dropped', async () => {
|
|
88
|
+
const r = boot(); r.sent.length = 0;
|
|
89
|
+
for (let i = 0; i < 6; i++) assert.equal(await r.hub.celebrate('p1', win(i)), true);
|
|
90
|
+
assert.equal(await r.hub.celebrate('p1', win(6)), false, 'six/day even if queue drops some');
|
|
91
|
+
const own = () => moments(r).filter(([id]) => id === 'p1').map(([, m]) => m.tokens);
|
|
92
|
+
assert.deepEqual(own(), [0]); r.tick(3999); assert.deepEqual(own(), [0]);
|
|
93
|
+
r.tick(1); assert.deepEqual(own(), [0, 3]); r.tick(4000); r.tick(4000); assert.deepEqual(own(), [0, 3, 4, 5]);
|
|
94
|
+
r.drop('p1'); r.back('p1'); assert.equal(await r.hub.celebrate('p1', win()), false);
|
|
95
|
+
clock += 86400000; assert.equal(await r.hub.celebrate('p1', win()), true, 'LA day resets the daily limit');
|
|
96
|
+
});
|
|
97
|
+
await test('atomic daily cap is shared across layers; ambiguous reservations fail closed', async () => {
|
|
98
|
+
const data = new Map();
|
|
99
|
+
const store = { async increment(k) { const n = (data.get(k) ?? 0) + 1; data.set(k, n); return n; } };
|
|
100
|
+
const a = boot(), b = boot(); a.session.storage = b.session.storage = { deck: store };
|
|
101
|
+
const accepted = await Promise.all(Array.from({ length: 12 }, (_, i) => (i % 2 ? a : b).hub.celebrate('p1', win())));
|
|
102
|
+
assert.equal(accepted.filter(Boolean).length, 6); assert.equal(data.size, 1);
|
|
103
|
+
const failed = boot(); failed.session.storage = { deck: { increment: async () => { throw Error('lost'); } } };
|
|
104
|
+
assert.equal(await failed.hub.celebrate('p1', win()), false); assert.equal(moments(failed).length, 0);
|
|
105
|
+
});
|
|
106
|
+
await test('queued leave, changed account and LA midnight never deliver stale moments', async () => {
|
|
107
|
+
for (const change of ['leave', 'account', 'day']) {
|
|
108
|
+
const r = boot(); await r.hub.celebrate('p1', win(1)); await r.hub.celebrate('p1', win(2));
|
|
109
|
+
if (change === 'leave') r.drop('p1');
|
|
110
|
+
if (change === 'account') r.session.players[0].userId = '99';
|
|
111
|
+
if (change === 'day') clock += 86400000;
|
|
112
|
+
r.tick(4000); assert.equal(moments(r).filter(([, m]) => m.tokens === 2).length, 0, change);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
} finally { Date.now = realNow; }
|
|
116
|
+
console.log(`${tests} celebration server checks passed`);
|