castle-web-cli 0.4.231 → 0.4.233
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-failures.d.ts +8 -0
- package/dist/agent-failures.js +19 -2
- package/dist/agent-prompts.d.ts +1 -1
- package/dist/agent-prompts.js +10 -3
- package/dist/agent.d.ts +64 -3
- package/dist/agent.js +170 -81
- package/dist/castle-host/host.d.ts +1 -0
- package/dist/castle-host/host.js +51 -3
- package/dist/castleJson.d.ts +4 -2
- package/dist/castleJson.js +2 -0
- package/dist/check.d.ts +3 -1
- package/dist/check.js +11 -1
- package/dist/devSessionStorage.js +47 -1
- package/dist/importPinMismatch.d.ts +22 -0
- package/dist/importPinMismatch.js +77 -0
- package/dist/importRegression.js +3 -15
- package/dist/imports.d.ts +10 -3
- package/dist/imports.js +88 -20
- package/dist/index.js +5 -4
- package/dist/init.js +1 -1
- package/dist/platformDoc.js +22 -0
- package/dist/routerFences.d.ts +5 -0
- package/dist/routerFences.js +12 -2
- package/dist/save-deck.d.ts +5 -0
- package/dist/save-deck.js +37 -4
- package/dist/serve.js +3 -0
- package/dist/serverBundle.js +5 -3
- package/dist/shell/assets/{index-D2tWM896.js → index-BjOxR-lW.js} +4 -4
- package/dist/shell/assets/index-MVLfNYd9.css +1 -0
- package/dist/shell/index.html +2 -2
- package/dist/taskSteer.d.ts +13 -0
- package/dist/taskSteer.js +22 -2
- package/kits/base/castle.json +1 -1
- package/kits/base/package-lock.json +1 -1
- package/kits/base/sdk/README.md +79 -2
- package/kits/base/sdk/avatar.d.ts +6 -2
- package/kits/base/sdk/avatar.js +12 -4
- package/kits/base/sdk/castle.d.ts +1 -1
- package/kits/base/sdk/commands.d.ts +14 -0
- package/kits/base/sdk/hub.d.ts +6 -2
- package/kits/base/sdk/hub.js +13 -0
- package/kits/base/sdk/multiplayer.js +17 -1
- package/kits/base/sdk/save.js +2 -1
- package/kits/base/sdk/server/hub.d.ts +87 -0
- package/kits/base/sdk/server/hub.js +70 -0
- package/kits/base/sdk/server/platformHandle.d.ts +31 -1
- package/kits/base/sdk/server/storage.d.ts +13 -0
- package/kits/base/sdk/server/storage.js +46 -0
- package/kits/base/sdk/server/wrapper.d.ts +36 -5
- package/kits/base/sdk/server/wrapper.js +83 -8
- package/kits/hub-game/CLAUDE.md +352 -12
- package/kits/hub-game/blueprints/avatar-10.scene +28 -0
- package/kits/hub-game/blueprints/avatar-11.scene +28 -0
- package/kits/hub-game/blueprints/avatar-12.scene +28 -0
- package/kits/hub-game/blueprints/avatar-13.scene +28 -0
- package/kits/hub-game/blueprints/avatar-14.scene +28 -0
- package/kits/hub-game/blueprints/avatar-15.scene +28 -0
- package/kits/hub-game/blueprints/avatar-4.scene +28 -0
- package/kits/hub-game/blueprints/avatar-5.scene +28 -0
- package/kits/hub-game/blueprints/avatar-6.scene +28 -0
- package/kits/hub-game/blueprints/avatar-7.scene +28 -0
- package/kits/hub-game/blueprints/avatar-8.scene +28 -0
- package/kits/hub-game/blueprints/avatar-9.scene +28 -0
- package/kits/hub-game/code/client/actorBudget.js +47 -0
- package/kits/hub-game/code/client/attention.js +11 -2
- package/kits/hub-game/code/client/avatar.js +345 -32
- package/kits/hub-game/code/client/avatarCap.js +228 -0
- package/kits/hub-game/code/client/avatarColors.js +70 -0
- package/kits/hub-game/code/client/avatarFaces.js +21 -0
- package/kits/hub-game/code/client/avatarShare.js +251 -0
- package/kits/hub-game/code/client/ballot.js +467 -0
- package/kits/hub-game/code/client/build.js +22 -0
- package/kits/hub-game/code/client/chat.js +12 -0
- package/kits/hub-game/code/client/chrome.js +1334 -50
- package/kits/hub-game/code/client/companion.js +716 -0
- package/kits/hub-game/code/client/companionDress.js +99 -0
- package/kits/hub-game/code/client/decor.js +509 -0
- package/kits/hub-game/code/client/earned.js +131 -0
- package/kits/hub-game/code/client/emoteBubble.js +75 -0
- package/kits/hub-game/code/client/grab.js +363 -20
- package/kits/hub-game/code/client/hats.js +26 -0
- package/kits/hub-game/code/client/hookLayer.js +328 -15
- package/kits/hub-game/code/client/hudClear.js +126 -0
- package/kits/hub-game/code/client/idle.js +163 -22
- package/kits/hub-game/code/client/interestCap.js +81 -0
- package/kits/hub-game/code/client/keys.js +36 -0
- package/kits/hub-game/code/client/labelsNear.js +205 -0
- package/kits/hub-game/code/client/menuIcons.js +34 -0
- package/kits/hub-game/code/client/pack.js +6 -2
- package/kits/hub-game/code/client/packFormat.js +3 -3
- package/kits/hub-game/code/client/rehello.js +167 -0
- package/kits/hub-game/code/client/shot.js +92 -0
- package/kits/hub-game/code/client/sound.js +63 -8
- package/kits/hub-game/code/client/soundscape.js +1151 -0
- package/kits/hub-game/code/client/soundscapeActions.js +99 -0
- package/kits/hub-game/code/client/soundscapeAmbience.js +453 -0
- package/kits/hub-game/code/client/soundscapeBaked.js +143 -0
- package/kits/hub-game/code/client/soundscapeBusker.js +217 -0
- package/kits/hub-game/code/client/soundscapeCourt.js +200 -0
- package/kits/hub-game/code/client/soundscapeCrowd.js +331 -0
- package/kits/hub-game/code/client/soundscapeCues.js +362 -0
- package/kits/hub-game/code/client/soundscapeMap.js +181 -0
- package/kits/hub-game/code/client/soundscapeMarket.js +176 -0
- package/kits/hub-game/code/client/soundscapeMusic.js +126 -0
- package/kits/hub-game/code/client/soundscapeMusicEngine.js +460 -0
- package/kits/hub-game/code/client/soundscapeSimlish.js +737 -0
- package/kits/hub-game/code/client/soundscapeSongs.js +127 -0
- package/kits/hub-game/code/client/soundscapeSongsRound3.js +63 -0
- package/kits/hub-game/code/client/soundscapeSynthesis.js +168 -0
- package/kits/hub-game/code/client/soundscapeUi.js +211 -0
- package/kits/hub-game/code/client/soundscapeVoice.js +1209 -0
- package/kits/hub-game/code/client/soundscapeWaves.js +206 -0
- package/kits/hub-game/code/client/spin.js +101 -0
- package/kits/hub-game/code/client/state.js +131 -1
- package/kits/hub-game/code/client/stuck.js +259 -0
- package/kits/hub-game/code/client/talk.js +538 -47
- package/kits/hub-game/code/client/tiers.js +541 -27
- package/kits/hub-game/code/client/toastBand.js +37 -0
- package/kits/hub-game/code/client/together.js +98 -1
- package/kits/hub-game/code/client/visibility.js +43 -0
- package/kits/hub-game/code/client/wear.js +470 -97
- package/kits/hub-game/code/client/yours.js +199 -0
- package/kits/hub-game/code/companionSpec.js +45 -0
- package/kits/hub-game/code/privateText.js +7 -0
- package/kits/hub-game/code/server/actions.js +133 -0
- package/kits/hub-game/code/server/actors.js +14 -1
- package/kits/hub-game/code/server/ask.js +155 -0
- package/kits/hub-game/code/server/ballot.js +539 -0
- package/kits/hub-game/code/server/cells.js +100 -0
- package/kits/hub-game/code/server/companion.js +82 -0
- package/kits/hub-game/code/server/cues.js +70 -0
- package/kits/hub-game/code/server/decor.js +269 -0
- package/kits/hub-game/code/server/earned.js +461 -0
- package/kits/hub-game/code/server/friendBests.js +166 -0
- package/kits/hub-game/code/server/friendsAmong.js +232 -0
- package/kits/hub-game/code/server/grab.js +296 -11
- package/kits/hub-game/code/server/history.js +5 -0
- package/kits/hub-game/code/server/hub.js +1317 -52
- package/kits/hub-game/code/server/idle.js +30 -11
- package/kits/hub-game/code/server/index.js +2 -2
- package/kits/hub-game/code/server/labels.js +28 -2
- package/kits/hub-game/code/server/manifest.js +424 -8
- package/kits/hub-game/code/server/menu.js +133 -0
- package/kits/hub-game/code/server/npcs.js +830 -80
- package/kits/hub-game/code/server/party.js +13 -2
- package/kits/hub-game/code/server/players.js +22 -0
- package/kits/hub-game/code/server/say.js +8 -2
- package/kits/hub-game/code/server/shot.js +110 -0
- package/kits/hub-game/code/server/standing.js +124 -0
- package/kits/hub-game/code/server/vis.js +113 -0
- package/kits/hub-game/code/server/wear.js +128 -11
- package/kits/hub-game/code/server/yours.js +59 -0
- package/kits/hub-game/code/shared/cues.js +9 -0
- package/kits/hub-game/code/shared/decor.js +41 -0
- package/kits/hub-game/code/shared/shot.js +19 -0
- package/kits/hub-game/code/shared/spin.js +57 -0
- package/kits/hub-game/code/systems/hub.js +1083 -85
- package/kits/hub-game/docs/content-pack.md +1 -1
- package/kits/hub-game/docs/contract.md +2440 -61
- package/kits/hub-game/docs/home-pieces.md +64 -0
- package/kits/hub-game/models/avatar-10.pxmodel +28 -0
- package/kits/hub-game/models/avatar-11.pxmodel +28 -0
- package/kits/hub-game/models/avatar-12.pxmodel +27 -0
- package/kits/hub-game/models/avatar-13.pxmodel +24 -0
- package/kits/hub-game/models/avatar-14.pxmodel +29 -0
- package/kits/hub-game/models/avatar-15.pxmodel +24 -0
- package/kits/hub-game/models/avatar-4.pxmodel +29 -0
- package/kits/hub-game/models/avatar-5.pxmodel +27 -0
- package/kits/hub-game/models/avatar-6.pxmodel +26 -0
- package/kits/hub-game/models/avatar-7.pxmodel +25 -0
- package/kits/hub-game/models/avatar-8.pxmodel +24 -0
- package/kits/hub-game/models/avatar-9.pxmodel +30 -0
- package/kits/hub-game/models/earned/badge-round.pxmodel +100 -0
- package/kits/hub-game/models/earned/badge-shield.pxmodel +117 -0
- package/kits/hub-game/models/earned/badge-star.pxmodel +87 -0
- package/kits/hub-game/models/earned/belt-plain.pxmodel +72 -0
- package/kits/hub-game/models/earned/held-ball.pxmodel +43 -0
- package/kits/hub-game/models/earned/held-lantern.pxmodel +85 -0
- package/kits/hub-game/models/earned/held-net.pxmodel +57 -0
- package/kits/hub-game/models/earned/held-trophy.pxmodel +109 -0
- package/kits/hub-game/models/earned/pin-round.pxmodel +62 -0
- package/kits/hub-game/models/earned/sash-plain.pxmodel +66 -0
- package/kits/hub-game/models/earned/square/belt-plain.pxmodel +104 -0
- package/kits/hub-game/models/earned/square/sash-plain.pxmodel +98 -0
- package/kits/hub-game/models/hats/bat-clip.pxmodel +206 -0
- package/kits/hub-game/models/hats/beekeeper.pxmodel +149 -0
- package/kits/hub-game/models/hats/cap.pxmodel +162 -0
- package/kits/hub-game/models/hats/captain.pxmodel +178 -0
- package/kits/hub-game/models/hats/crooked-top.pxmodel +172 -0
- package/kits/hub-game/models/hats/flower-crown.pxmodel +451 -0
- package/kits/hub-game/models/hats/foam-crown.pxmodel +179 -0
- package/kits/hub-game/models/hats/lantern.pxmodel +230 -0
- package/kits/hub-game/models/hats/laurel.pxmodel +533 -0
- package/kits/hub-game/models/hats/lighthouse.pxmodel +96 -0
- package/kits/hub-game/models/hats/sailor.pxmodel +141 -0
- package/kits/hub-game/models/hats/souwester.pxmodel +131 -0
- package/kits/hub-game/models/hats/straw.pxmodel +139 -0
- package/kits/hub-game/models/hats/sunflower.pxmodel +406 -0
- package/kits/hub-game/models/hats/sweatband.pxmodel +112 -0
- package/kits/hub-game/models/hats/witch.pxmodel +147 -0
- package/kits/hub-game/package-lock.json +2 -0
- package/kits/hub-game/package.json +2 -1
- package/kits/hub-game/scripts/check.mjs +78 -11
- package/kits/hub-game/scripts/companion-follower-wire.json +1 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +121 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless.json +293 -0
- package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +23 -0
- package/kits/hub-game/scripts/fixtures/fake-dom.mjs +107 -0
- package/kits/hub-game/scripts/fixtures/interest-legacy.json +385 -0
- package/kits/hub-game/scripts/fixtures/npc-notes-v1.77.jsonl +4 -0
- package/kits/hub-game/scripts/fixtures/vis-shared-wire.json +1 -0
- package/kits/hub-game/scripts/gen-avatars.mjs +933 -16
- package/kits/hub-game/scripts/gen-earned.mjs +285 -0
- package/kits/hub-game/scripts/gen-hats.mjs +827 -0
- package/kits/hub-game/scripts/grab.before-orbit.mjs +400 -0
- package/kits/hub-game/scripts/soundscape-wave-analysis.mjs +125 -0
- package/kits/hub-game/scripts/test-actions-client.mjs +488 -0
- package/kits/hub-game/scripts/test-actions.mjs +298 -0
- package/kits/hub-game/scripts/test-actor-budget.mjs +44 -0
- package/kits/hub-game/scripts/test-actors.mjs +19 -17
- package/kits/hub-game/scripts/test-ask-client.mjs +358 -0
- package/kits/hub-game/scripts/test-ask.mjs +269 -0
- package/kits/hub-game/scripts/test-attention.mjs +10 -1
- package/kits/hub-game/scripts/test-avatar-cap.mjs +379 -0
- package/kits/hub-game/scripts/test-avatar-colors.mjs +72 -0
- package/kits/hub-game/scripts/test-avatar-models.mjs +181 -0
- package/kits/hub-game/scripts/test-avatar-share.mjs +318 -0
- package/kits/hub-game/scripts/test-avatar-wire.mjs +753 -0
- package/kits/hub-game/scripts/test-avatar.mjs +540 -7
- package/kits/hub-game/scripts/test-ballot.mjs +1001 -0
- package/kits/hub-game/scripts/test-build.mjs +31 -0
- package/kits/hub-game/scripts/test-cells.mjs +71 -0
- package/kits/hub-game/scripts/test-chat.mjs +694 -0
- package/kits/hub-game/scripts/test-classic.mjs +2 -0
- package/kits/hub-game/scripts/test-companion-chat.mjs +198 -0
- package/kits/hub-game/scripts/test-companion-client.mjs +1167 -0
- package/kits/hub-game/scripts/test-companion.mjs +259 -0
- package/kits/hub-game/scripts/test-decor-client.mjs +303 -0
- package/kits/hub-game/scripts/test-decor.mjs +457 -0
- package/kits/hub-game/scripts/test-earned-client.mjs +459 -0
- package/kits/hub-game/scripts/test-earned.mjs +1194 -0
- package/kits/hub-game/scripts/test-emote-bubble.mjs +110 -0
- package/kits/hub-game/scripts/test-friend-bests.mjs +435 -0
- package/kits/hub-game/scripts/test-grab-client.mjs +186 -3
- package/kits/hub-game/scripts/test-grab-orbit.mjs +918 -0
- package/kits/hub-game/scripts/test-grab.mjs +864 -3
- package/kits/hub-game/scripts/test-hats.mjs +483 -0
- package/kits/hub-game/scripts/test-hub-leaving.mjs +203 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +439 -2
- package/kits/hub-game/scripts/test-hub-trip.mjs +1228 -1
- package/kits/hub-game/scripts/test-hud-clear.mjs +1000 -0
- package/kits/hub-game/scripts/test-idle.mjs +361 -1
- package/kits/hub-game/scripts/test-interest-cap.mjs +36 -0
- package/kits/hub-game/scripts/test-interest-cells.mjs +493 -0
- package/kits/hub-game/scripts/test-interest-client.mjs +118 -0
- package/kits/hub-game/scripts/test-keys.mjs +46 -1
- package/kits/hub-game/scripts/test-labels.mjs +596 -0
- package/kits/hub-game/scripts/test-manifest.mjs +282 -0
- package/kits/hub-game/scripts/test-menu-client.mjs +480 -0
- package/kits/hub-game/scripts/test-menu.mjs +296 -0
- package/kits/hub-game/scripts/test-npcs.mjs +1718 -12
- package/kits/hub-game/scripts/test-object-entry.mjs +76 -0
- package/kits/hub-game/scripts/test-pack.mjs +7 -0
- package/kits/hub-game/scripts/test-party.mjs +22 -1
- package/kits/hub-game/scripts/test-picker.mjs +314 -0
- package/kits/hub-game/scripts/test-rehello.mjs +1039 -0
- package/kits/hub-game/scripts/test-relations-among.mjs +222 -0
- package/kits/hub-game/scripts/test-relations-refresh.mjs +188 -0
- package/kits/hub-game/scripts/test-say.mjs +59 -2
- package/kits/hub-game/scripts/test-shot.mjs +756 -0
- package/kits/hub-game/scripts/test-soundscape.mjs +5432 -0
- package/kits/hub-game/scripts/test-spin.mjs +314 -0
- package/kits/hub-game/scripts/test-standing.mjs +416 -0
- package/kits/hub-game/scripts/test-stuck.mjs +1903 -0
- package/kits/hub-game/scripts/test-tier-cells.mjs +706 -0
- package/kits/hub-game/scripts/test-tiers-render.mjs +339 -0
- package/kits/hub-game/scripts/test-tiers.mjs +666 -3
- package/kits/hub-game/scripts/test-toast-band.mjs +61 -0
- package/kits/hub-game/scripts/test-try-on.mjs +940 -0
- package/kits/hub-game/scripts/test-vis.mjs +343 -0
- package/kits/hub-game/scripts/test-visibility.mjs +134 -0
- package/kits/hub-game/scripts/test-yours-chrome.mjs +166 -0
- package/kits/hub-game/scripts/test-yours.mjs +372 -0
- package/kits/multiplayer-3d/CLAUDE.md +50 -0
- package/kits/multiplayer-3d/castle.json +5 -5
- package/kits/multiplayer-3d/code/client/avatars.js +7 -0
- package/kits/multiplayer-3d/code/client/gait.js +65 -0
- package/kits/multiplayer-3d/code/client/nameTags.js +59 -4
- package/kits/multiplayer-3d/code/options.js +5 -0
- package/kits/multiplayer-3d/code/server/ownership.js +10 -2
- package/kits/multiplayer-3d/code/server/sceneBodies.js +12 -0
- package/kits/multiplayer-3d/code/server/world.js +7 -0
- package/kits/multiplayer-3d/code/systems/multiplayer.js +74 -4
- package/kits/multiplayer-3d/package.json +2 -1
- package/kits/multiplayer-3d/scripts/fixtures/README.md +11 -0
- package/kits/multiplayer-3d/scripts/fixtures/ownership-legacy.json +2 -0
- package/kits/multiplayer-3d/scripts/ownership-harness.mjs +102 -0
- package/kits/multiplayer-3d/scripts/ownership-loader.mjs +46 -0
- package/kits/multiplayer-3d/scripts/ownership-worker.mjs +15 -0
- package/kits/multiplayer-3d/scripts/record-ownership-session.mjs +98 -0
- package/kits/multiplayer-3d/scripts/test-eligible-claims.mjs +167 -0
- package/kits/multiplayer-3d/scripts/test-own-name-tag.mjs +247 -0
- package/kits/physics-2d/CLAUDE.md +9 -0
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/scene.js +288 -1
- package/kits/physics-2d/engine/skyKey.js +129 -0
- package/kits/physics-2d/engine/stillClock.js +106 -0
- package/kits/physics-2d/engine/updateBudget.js +21 -0
- package/kits/physics-2d/scripts/test-skip-unchanged.mjs +370 -1
- package/kits/physics-3d/CLAUDE.md +1391 -0
- package/kits/physics-3d/behaviors/Player.jsx +921 -3
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/docs/pxmodel-format.md +12 -0
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +98 -10
- package/kits/physics-3d/engine3d/actornode.js +86 -0
- package/kits/physics-3d/engine3d/animationBudget.js +23 -0
- package/kits/physics-3d/engine3d/editorWorld.js +6 -0
- package/kits/physics-3d/engine3d/emptynodes.js +232 -0
- package/kits/physics-3d/engine3d/framecap.js +96 -0
- package/kits/physics-3d/engine3d/gait.js +118 -0
- package/kits/physics-3d/engine3d/kithooks.js +47 -0
- package/kits/physics-3d/engine3d/look.js +507 -48
- package/kits/physics-3d/engine3d/lookbake.js +208 -0
- package/kits/physics-3d/engine3d/materialpresets.js +2 -0
- package/kits/physics-3d/engine3d/motion.js +39 -10
- package/kits/physics-3d/engine3d/nearshadows.js +37 -19
- package/kits/physics-3d/engine3d/optimize.js +58 -5
- package/kits/physics-3d/engine3d/orbitinput.js +755 -0
- package/kits/physics-3d/engine3d/orbitlens.js +48 -0
- package/kits/physics-3d/engine3d/ownmodel.js +213 -0
- package/kits/physics-3d/engine3d/pxmodel.js +42 -11
- package/kits/physics-3d/engine3d/shadowfade.js +882 -0
- package/kits/physics-3d/engine3d/sky.js +547 -0
- package/kits/physics-3d/engine3d/skylife.js +306 -0
- package/kits/physics-3d/engine3d/unchanged.js +11 -0
- package/kits/physics-3d/engine3d/viewrange.js +52 -0
- package/kits/physics-3d/engine3d/world3d.js +870 -87
- package/kits/physics-3d/main.jsx +5 -0
- package/kits/physics-3d/package.json +1 -1
- package/kits/physics-3d/scripts/Player.before-orbit.mjs +310 -0
- package/kits/physics-3d/scripts/Scene3DPlayer.before-orbit.jsx +337 -0
- package/kits/physics-3d/scripts/look-baseline.mjs +155 -0
- package/kits/physics-3d/scripts/test-camera-follow.mjs +12 -2
- package/kits/physics-3d/scripts/test-camera-orbit.mjs +4588 -0
- package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +787 -0
- package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +435 -0
- package/kits/physics-3d/scripts/test-frame-cap.mjs +452 -0
- package/kits/physics-3d/scripts/test-gait.mjs +387 -0
- package/kits/physics-3d/scripts/test-look-bake.mjs +1056 -0
- package/kits/physics-3d/scripts/test-model-parse-cache.mjs +92 -0
- package/kits/physics-3d/scripts/test-near-shadows.mjs +3 -0
- package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1920 -0
- package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +545 -0
- package/kits/physics-3d/scripts/test-orbit-shot.mjs +583 -0
- package/kits/physics-3d/scripts/test-orbit-view.mjs +230 -0
- package/kits/physics-3d/scripts/test-skip-empty-nodes.mjs +845 -0
- package/kits/physics-3d/scripts/test-sky.mjs +2470 -0
- package/kits/physics-3d/scripts/test-static-actors.mjs +13 -1
- package/kits/physics-3d/scripts/test-static-passes.mjs +1 -1
- package/kits/physics-3d/scripts/test-static-scenery.mjs +2171 -0
- package/kits/physics-3d/scripts/test-steady-hover.mjs +635 -0
- package/kits/physics-3d/scripts/test-view-range.mjs +260 -0
- package/kits/physics-3d/systems/physics3d.js +474 -12
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/server/gameHooks.js +7 -0
- package/kits/real-time/code/server/session.js +97 -19
- package/package.json +2 -2
- package/dist/shell/assets/index-Cf61cNfT.css +0 -1
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import assert from 'node:assert/strict';
|
|
10
10
|
import { register } from 'node:module';
|
|
11
11
|
|
|
12
|
-
const sdkStub = 'export const Hub = globalThis.__tripHub;';
|
|
12
|
+
const sdkStub = 'export const Hub = globalThis.__tripHub; export const User = { getCurrent: async () => { globalThis.__yoursUserReads = (globalThis.__yoursUserReads ?? 0) + 1; return { userId: \"101\", isAnonymous: false }; } };';
|
|
13
13
|
const packStub = `
|
|
14
14
|
export const loadPack = (...args) => globalThis.__tripLoadPack(...args);
|
|
15
15
|
export const cachedPacks = () => [];
|
|
@@ -22,6 +22,8 @@ register(
|
|
|
22
22
|
'data:text/javascript,' +
|
|
23
23
|
encodeURIComponent(`
|
|
24
24
|
export async function resolve(specifier, context, next) {
|
|
25
|
+
if (['pxmodel', 'optimize', 'look', 'lookbake'].some((m) => specifier === '@imports/castle.physics-3d/engine3d/' + m)) return { url: ${JSON.stringify(new URL('./fixtures/engine-models-stub.mjs', import.meta.url).href)}, shortCircuit: true };
|
|
26
|
+
if (specifier === '@imports/castle.physics-3d/engine3d/orbitlens.js') return { url: ${JSON.stringify(new URL('../../physics-3d/engine3d/orbitlens.js', import.meta.url).href)}, shortCircuit: true };
|
|
25
27
|
if (specifier === 'castle-web-sdk') {
|
|
26
28
|
return { url: ${JSON.stringify('data:text/javascript,' + encodeURIComponent(sdkStub))}, shortCircuit: true };
|
|
27
29
|
}
|
|
@@ -90,6 +92,9 @@ globalThis.__tripLoadPack = async (sha, url) => {
|
|
|
90
92
|
|
|
91
93
|
const { installSystem, BANNED_TEXT } = await import('../code/systems/hub.js');
|
|
92
94
|
const HubState = await import('../code/client/state.js');
|
|
95
|
+
const ShotClient = await import('../code/client/shot.js');
|
|
96
|
+
const { receiveShot } = ShotClient;
|
|
97
|
+
const clearShot = () => ShotClient.clearShot();
|
|
93
98
|
const { makeTogether } = await import('../code/client/together.js');
|
|
94
99
|
|
|
95
100
|
const tick = () => new Promise((resolve) => setTimeout(resolve, 0));
|
|
@@ -1171,6 +1176,79 @@ await test('friends: asked from a place that is not a game; here and empty rows
|
|
|
1171
1176
|
}
|
|
1172
1177
|
});
|
|
1173
1178
|
|
|
1179
|
+
await test('friends wanted asks at once, after 20 s, then every 90 s, never a trip or keyless game', async () => {
|
|
1180
|
+
const { system, scene } = setup();
|
|
1181
|
+
const mp = { joinState: () => 'joined' };
|
|
1182
|
+
HubState.hub.place = { id: 'main', title: 'Game', result: { outcomes: ['win'] } };
|
|
1183
|
+
HubState.hub.friendsWanted = false;
|
|
1184
|
+
try {
|
|
1185
|
+
system.askFriends(scene, mp, 0);
|
|
1186
|
+
await flush();
|
|
1187
|
+
assert.deepEqual(calls, [], 'keyless game sends nothing');
|
|
1188
|
+
answers.friends = { status: 'ok', friends: [] };
|
|
1189
|
+
HubState.hub.friendsWanted = true;
|
|
1190
|
+
system.askFriends(scene, mp, 1);
|
|
1191
|
+
await flush();
|
|
1192
|
+
assert.deepEqual(calls, [['friends']], 'first idle tick on receipt');
|
|
1193
|
+
system.askFriends(scene, mp, 20000);
|
|
1194
|
+
await flush();
|
|
1195
|
+
assert.equal(calls.length, 1);
|
|
1196
|
+
system.trip = {};
|
|
1197
|
+
system.askFriends(scene, mp, 20001);
|
|
1198
|
+
await flush();
|
|
1199
|
+
assert.equal(calls.length, 1, 'trip sends nothing');
|
|
1200
|
+
system.trip = null;
|
|
1201
|
+
system.askFriends(scene, { joinState: () => 'joining' }, 20001);
|
|
1202
|
+
await flush();
|
|
1203
|
+
assert.equal(calls.length, 1, 'not yet joined');
|
|
1204
|
+
system.askFriends(scene, mp, 20001);
|
|
1205
|
+
await flush();
|
|
1206
|
+
assert.equal(calls.length, 2, 'warm-up ask after heartbeat roster');
|
|
1207
|
+
system.askFriends(scene, mp, 40001);
|
|
1208
|
+
system.askFriends(scene, mp, 110000);
|
|
1209
|
+
await flush();
|
|
1210
|
+
assert.equal(calls.length, 2, 'warm-up does not repeat');
|
|
1211
|
+
answers.friendsError = 'TIMEOUT';
|
|
1212
|
+
system.askFriends(scene, mp, 110001);
|
|
1213
|
+
await flush();
|
|
1214
|
+
assert.equal(system.friendsOff, false);
|
|
1215
|
+
answers.friendsError = 'UNKNOWN_COMMAND';
|
|
1216
|
+
system.askFriends(scene, mp, 200001);
|
|
1217
|
+
await flush();
|
|
1218
|
+
assert.equal(system.friendsOff, true);
|
|
1219
|
+
system.askFriends(scene, mp, 290001);
|
|
1220
|
+
await flush();
|
|
1221
|
+
assert.equal(calls.length, 4, 'unknown command stops all asks');
|
|
1222
|
+
} finally {
|
|
1223
|
+
HubState.hub.place = null;
|
|
1224
|
+
HubState.hub.friendsWanted = false;
|
|
1225
|
+
}
|
|
1226
|
+
});
|
|
1227
|
+
|
|
1228
|
+
await test('a failed first friends ask still warms up after 20 s', async () => {
|
|
1229
|
+
const { system, scene } = setup();
|
|
1230
|
+
const mp = { joinState: () => 'joined' };
|
|
1231
|
+
HubState.hub.place = { id: 'main', result: {} };
|
|
1232
|
+
HubState.hub.friendsWanted = true;
|
|
1233
|
+
try {
|
|
1234
|
+
answers.friendsError = 'TIMEOUT';
|
|
1235
|
+
system.askFriends(scene, mp, 0);
|
|
1236
|
+
await flush();
|
|
1237
|
+
assert.equal(system.friendsOff, false);
|
|
1238
|
+
answers.friendsError = null;
|
|
1239
|
+
answers.friends = { status: 'ok', friends: [] };
|
|
1240
|
+
system.askFriends(scene, mp, 19999);
|
|
1241
|
+
await flush();
|
|
1242
|
+
assert.equal(calls.length, 1);
|
|
1243
|
+
system.askFriends(scene, mp, 20000);
|
|
1244
|
+
await flush();
|
|
1245
|
+
assert.equal(calls.length, 2);
|
|
1246
|
+
} finally {
|
|
1247
|
+
HubState.hub.place = null;
|
|
1248
|
+
HubState.hub.friendsWanted = false;
|
|
1249
|
+
}
|
|
1250
|
+
});
|
|
1251
|
+
|
|
1174
1252
|
await test('a door refused because the player is barred from the hub says so, and is not asked again', async () => {
|
|
1175
1253
|
const { system, scene } = setup();
|
|
1176
1254
|
answers.goError = 'CAULDRON_HUB_BANNED';
|
|
@@ -1513,6 +1591,1155 @@ await test('start next to a friend: once, on walking in, when a friend is here a
|
|
|
1513
1591
|
HubState.hub.jumpedTo = null;
|
|
1514
1592
|
});
|
|
1515
1593
|
|
|
1594
|
+
// Cues (contract v1.23): everything below is behind `hub.cues` in the deck's
|
|
1595
|
+
// castle.json (`Hub.deck.cues`). Each test runs the same steps with it off
|
|
1596
|
+
// and asserts the kit does exactly what it did.
|
|
1597
|
+
|
|
1598
|
+
// A chrome that records what the hub system hands it.
|
|
1599
|
+
function cueChrome(system) {
|
|
1600
|
+
const seen = { toast: '', say: null, ask: null };
|
|
1601
|
+
system.chrome = {
|
|
1602
|
+
showBack() {}, showPicker() {}, setFriends() {}, setDoors() {}, setPeople() {}, setHud() {}, setLabels() {}, setRibbon() {},
|
|
1603
|
+
setToast(text, options) { seen.toast = text; seen.toastOptions = options; },
|
|
1604
|
+
setSay(say) { seen.say = say; },
|
|
1605
|
+
setAsk(ask) { seen.ask = ask; },
|
|
1606
|
+
};
|
|
1607
|
+
system.talk = { talking: () => false };
|
|
1608
|
+
globalThis.window ??= { innerWidth: 400, innerHeight: 800 };
|
|
1609
|
+
return seen;
|
|
1610
|
+
}
|
|
1611
|
+
// What is sent to the place, but for the once-a-second `hub-where`.
|
|
1612
|
+
function townNet(scene, roster, ids, sent = []) {
|
|
1613
|
+
scene.multiplayer.net = { others: () => roster, userId: (id) => ids[id] ?? null, send: (msg) => msg.k !== 'hub-where' && sent.push(msg), selfId: () => 'me' };
|
|
1614
|
+
return sent;
|
|
1615
|
+
}
|
|
1616
|
+
const resetTown = () => {
|
|
1617
|
+
HubState.deck.cues = false;
|
|
1618
|
+
HubState.hub.place = null;
|
|
1619
|
+
HubState.hub.doors = [];
|
|
1620
|
+
HubState.hub.arrivedFacing = null;
|
|
1621
|
+
HubState.hub.jumpedTo = null;
|
|
1622
|
+
HubState.hub.party = { members: null, away: 0, invite: null, proposal: null };
|
|
1623
|
+
HubState.hub.saidEvents.length = 0;
|
|
1624
|
+
};
|
|
1625
|
+
|
|
1626
|
+
// The host names a friend only once its heartbeat (about every 15 s) has told
|
|
1627
|
+
// it both players are in the town, so one ask made at first sight comes back
|
|
1628
|
+
// empty. A town driven a quarter second at a time: `script(now, roster, ids)`
|
|
1629
|
+
// changes who is here, `names(now)` is whom the host would name then.
|
|
1630
|
+
// `blocked(now)` is when no ask can be sent (the multiplayer join is pending).
|
|
1631
|
+
async function friendsRun({ cues, until, script = () => {}, names = () => [], roster = new Map(), ids = {}, blocked = () => false }) {
|
|
1632
|
+
const { system, scene } = setup();
|
|
1633
|
+
HubState.deck.cues = cues;
|
|
1634
|
+
HubState.hub.place = { id: 'main', title: 'Town' };
|
|
1635
|
+
const mp = mpStub(scene, 'joined');
|
|
1636
|
+
mp.net = { others: () => roster, userId: (id) => ids[id] ?? null, send() {} };
|
|
1637
|
+
const asks = [];
|
|
1638
|
+
const arrived = [];
|
|
1639
|
+
let n = 0;
|
|
1640
|
+
for (let now = 0; now <= until; now += 250) {
|
|
1641
|
+
script(now, roster, ids);
|
|
1642
|
+
answers.friends = { status: 'ok', friends: names(now) };
|
|
1643
|
+
mp.state = blocked(now) ? 'joining' : 'joined';
|
|
1644
|
+
system.askFriends(scene, mp, now);
|
|
1645
|
+
system.together.frame(mp, system.friendsAll, true, now);
|
|
1646
|
+
for (const who of system.together.arrivals()) {
|
|
1647
|
+
arrived.push([now, who.username, who.here === true]);
|
|
1648
|
+
}
|
|
1649
|
+
const made = calls.filter((c) => c[0] === 'friends').length;
|
|
1650
|
+
if (made > n) {
|
|
1651
|
+
asks.push(now);
|
|
1652
|
+
n = made;
|
|
1653
|
+
}
|
|
1654
|
+
await flush();
|
|
1655
|
+
}
|
|
1656
|
+
return { asks, arrived, system };
|
|
1657
|
+
}
|
|
1658
|
+
const amy = { userId: '104', username: 'amy', here: true };
|
|
1659
|
+
const comes = (at, playerId, name, userId) => (now, roster, ids) => {
|
|
1660
|
+
if (now === at) {
|
|
1661
|
+
roster.set(playerId, name);
|
|
1662
|
+
ids[playerId] = userId;
|
|
1663
|
+
}
|
|
1664
|
+
};
|
|
1665
|
+
|
|
1666
|
+
await test('cues: a friend the host names only once its heartbeat has run is announced on that answer (about 11 s in), not at the 20 s ask; without cues the 20 s cadence alone', async () => {
|
|
1667
|
+
try {
|
|
1668
|
+
// amy comes in at 21 s; the host knows she is here from 31 s.
|
|
1669
|
+
const late = { until: 61000, script: comes(21000, 'p4', 'amy', '104'), names: (now) => (now >= 31000 ? [amy] : []) };
|
|
1670
|
+
const on = await friendsRun({ cues: true, ...late });
|
|
1671
|
+
assert.deepEqual(on.asks, [0, 20000, 22000, 24000, 30000, 36000, 56000], 'asked again 1, 3, 9 and 15 s after she is seen; named on the last');
|
|
1672
|
+
assert.deepEqual(on.arrived, [[36250, 'amy', false]], 'announced on the answer that names her');
|
|
1673
|
+
const off = await friendsRun({ cues: false, ...late });
|
|
1674
|
+
assert.deepEqual(off.asks, [0, 20000, 40000, 60000]);
|
|
1675
|
+
assert.deepEqual(off.arrived, [[40250, 'amy', false]]);
|
|
1676
|
+
assert.equal(off.system.friendsEarlyAt, -Infinity);
|
|
1677
|
+
assert.equal(off.system.together.due([], 99999), false, 'without cues nothing is ever due');
|
|
1678
|
+
|
|
1679
|
+
// The player's own arrival: amy was here already, and it is the player's
|
|
1680
|
+
// presence the host lacks until 10 s in. Those here count from then.
|
|
1681
|
+
const here = { until: 40000, roster: new Map([['p4', 'amy']]), ids: { p4: '104' }, names: (now) => (now >= 10000 ? [amy] : []) };
|
|
1682
|
+
const mine = await friendsRun({ cues: true, ...here });
|
|
1683
|
+
assert.deepEqual(mine.asks, [0, 1000, 3000, 9000, 15000, 35000]);
|
|
1684
|
+
assert.deepEqual(mine.arrived, [[15250, 'amy', true]], 'the friend already here, told once the host names her');
|
|
1685
|
+
const plain = await friendsRun({ cues: false, ...here });
|
|
1686
|
+
assert.deepEqual([plain.asks, plain.arrived], [[0, 20000, 40000], []], 'without cues: the cadence, and one here all along is not announced');
|
|
1687
|
+
} finally {
|
|
1688
|
+
resetTown();
|
|
1689
|
+
}
|
|
1690
|
+
});
|
|
1691
|
+
|
|
1692
|
+
await test('cues: the extra friends asks are bounded: four for someone never named, two in any 8 s however many come in, none once they leave, none without a user id', async () => {
|
|
1693
|
+
try {
|
|
1694
|
+
// A stranger the host never names: four asks, then the 20 s cadence.
|
|
1695
|
+
const never = await friendsRun({ cues: true, until: 80000, script: comes(21000, 'p9', 'zed', '109') });
|
|
1696
|
+
assert.deepEqual(never.asks, [0, 20000, 22000, 24000, 30000, 36000, 56000, 76000]);
|
|
1697
|
+
assert.deepEqual(never.arrived, []);
|
|
1698
|
+
|
|
1699
|
+
// They leave mid-schedule: the asks stop with them.
|
|
1700
|
+
const gone = await friendsRun({
|
|
1701
|
+
cues: true,
|
|
1702
|
+
until: 50000,
|
|
1703
|
+
script: (now, roster, ids) => {
|
|
1704
|
+
comes(21000, 'p9', 'zed', '109')(now, roster, ids);
|
|
1705
|
+
if (now === 28000) {
|
|
1706
|
+
roster.delete('p9');
|
|
1707
|
+
}
|
|
1708
|
+
},
|
|
1709
|
+
});
|
|
1710
|
+
assert.deepEqual(gone.asks, [0, 20000, 22000, 24000, 44000]);
|
|
1711
|
+
|
|
1712
|
+
// A busy town, someone new every second for a minute: two extra asks in
|
|
1713
|
+
// any 8 s at most, 2 s apart, so 16 in a minute at the very most, never an
|
|
1714
|
+
// ask per arrival.
|
|
1715
|
+
const busy = await friendsRun({
|
|
1716
|
+
cues: true,
|
|
1717
|
+
until: 100000,
|
|
1718
|
+
script: (now, roster, ids) => {
|
|
1719
|
+
if (now >= 21000 && now < 81000 && now % 1000 === 0) {
|
|
1720
|
+
roster.set(`s${now}`, 'someone');
|
|
1721
|
+
ids[`s${now}`] = `u${now}`;
|
|
1722
|
+
}
|
|
1723
|
+
},
|
|
1724
|
+
});
|
|
1725
|
+
// (the first two are the cadence's own, at 0 and 20 s)
|
|
1726
|
+
const extra = busy.asks.slice(2);
|
|
1727
|
+
assert.ok(extra.slice(1).every((at, i) => at - extra[i] >= 2000), `never two extra asks inside 2 s: ${busy.asks}`);
|
|
1728
|
+
assert.ok(extra.slice(2).every((at, i) => at - extra[i] >= 8000), `never three extra asks inside 8 s: ${busy.asks}`);
|
|
1729
|
+
assert.ok(extra[0] - busy.asks[1] >= 1000, 'nor one on the heels of the cadence');
|
|
1730
|
+
assert.ok(busy.asks.filter((at) => at >= 21000 && at < 81000).length <= 16, `at most 16 in the minute: ${busy.asks}`);
|
|
1731
|
+
assert.ok(busy.asks.filter((at) => at >= 21000 && at < 81000).length >= 12, 'and it does keep asking through it');
|
|
1732
|
+
|
|
1733
|
+
// Seen just before the cadence's own ask: the extra one keeps 1 s clear of it.
|
|
1734
|
+
const heels = await friendsRun({ cues: true, until: 30000, script: comes(19500, 'p9', 'zed', '109') });
|
|
1735
|
+
assert.deepEqual(heels.asks, [0, 20000, 21000, 23000, 29000], `${heels.asks}`);
|
|
1736
|
+
// Seen a little earlier, the extra ask comes first and is the cadence's
|
|
1737
|
+
// own too: the next of those is 20 s after it, never on its heels.
|
|
1738
|
+
const first = await friendsRun({ cues: true, until: 30000, script: comes(18250, 'p9', 'zed', '109') });
|
|
1739
|
+
assert.deepEqual(first.asks, [0, 19250, 21250, 27250], `${first.asks}`);
|
|
1740
|
+
|
|
1741
|
+
// An ask that cannot be sent (a trip, a join pending) spends nothing: the
|
|
1742
|
+
// bounds are counted from the asks really made. Blocked from 1 to 4.5 s
|
|
1743
|
+
// with a stranger here from the start (the review's case), then for a
|
|
1744
|
+
// stretch in the middle of a later schedule.
|
|
1745
|
+
const spaced = (asks, regular) => {
|
|
1746
|
+
const extra = asks.filter((at) => !regular.includes(at));
|
|
1747
|
+
assert.ok(extra.slice(1).every((at, i) => at - extra[i] >= 2000), `two extra asks inside 2 s: ${asks}`);
|
|
1748
|
+
assert.ok(extra.slice(2).every((at, i) => at - extra[i] >= 8000), `three extra asks inside 8 s: ${asks}`);
|
|
1749
|
+
assert.ok(asks.slice(1).every((at, i) => at - asks[i] >= 1000), `two asks inside 1 s: ${asks}`);
|
|
1750
|
+
};
|
|
1751
|
+
const held = await friendsRun({ cues: true, until: 40000, roster: new Map([['p9', 'zed']]), ids: { p9: '109' }, blocked: (now) => now >= 1000 && now < 4500 });
|
|
1752
|
+
assert.deepEqual(held.asks, [0, 4500, 9000, 15000, 35000], `${held.asks}`);
|
|
1753
|
+
spaced(held.asks, [0, 35000]);
|
|
1754
|
+
const mid = await friendsRun({ cues: true, until: 62000, script: comes(21000, 'p9', 'zed', '109'), blocked: (now) => now >= 24000 && now < 33500 });
|
|
1755
|
+
assert.deepEqual(mid.asks, [0, 20000, 22000, 33500, 36000, 56000], `the steps missed are not owed: ${mid.asks}`);
|
|
1756
|
+
spaced(mid.asks, [0, 20000, 56000]);
|
|
1757
|
+
const off = await friendsRun({ cues: false, until: 45000, roster: new Map([['p9', 'zed']]), ids: { p9: '109' }, blocked: (now) => now >= 19000 && now < 22500 });
|
|
1758
|
+
assert.deepEqual(off.asks, [0, 22500, 42500], 'without cues: the cadence, late by the block, as it always was');
|
|
1759
|
+
|
|
1760
|
+
// Never while an ask is out, and no ask for a player with no user id.
|
|
1761
|
+
const guest = await friendsRun({ cues: true, until: 45000, script: (now, roster) => now === 21000 && roster.set('g1', 'guest') });
|
|
1762
|
+
assert.deepEqual(guest.asks, [0, 20000, 40000]);
|
|
1763
|
+
const { system, scene } = setup();
|
|
1764
|
+
HubState.deck.cues = true;
|
|
1765
|
+
HubState.hub.place = { id: 'main', title: 'Town' };
|
|
1766
|
+
const mp = mpStub(scene, 'joined');
|
|
1767
|
+
mp.net = { others: () => new Map([['p9', 'zed']]), userId: () => '109', send() {} };
|
|
1768
|
+
answers.friends = { status: 'ok', friends: [] };
|
|
1769
|
+
for (let now = 0; now <= 30000; now += 250) {
|
|
1770
|
+
system.askFriends(scene, mp, now);
|
|
1771
|
+
system.together.frame(mp, system.friendsAll, true, now);
|
|
1772
|
+
}
|
|
1773
|
+
assert.equal(calls.filter((c) => c[0] === 'friends').length, 1, 'the first ask never landed: nothing more is asked');
|
|
1774
|
+
await flush();
|
|
1775
|
+
} finally {
|
|
1776
|
+
resetTown();
|
|
1777
|
+
}
|
|
1778
|
+
});
|
|
1779
|
+
|
|
1780
|
+
await test('cues: a friend already here is told once the host names them, once, pointed to, never over another toast or "You\'re next to"; without cues not at all', async () => {
|
|
1781
|
+
const friends = [{ userId: '104', username: 'amy', here: true }];
|
|
1782
|
+
const boot = (cues) => {
|
|
1783
|
+
const { system, scene } = setup();
|
|
1784
|
+
HubState.deck.cues = cues;
|
|
1785
|
+
HubState.hub.place = { title: 'Town', result: null };
|
|
1786
|
+
HubState.hub.arrivedFacing = 0;
|
|
1787
|
+
const seen = cueChrome(system);
|
|
1788
|
+
const sent = townNet(scene, new Map([['p2', 'bo'], ['p4', 'amy']]), { p2: '102', p4: '104' });
|
|
1789
|
+
const pings = [];
|
|
1790
|
+
const ping = system.together.ping;
|
|
1791
|
+
system.together.ping = (...args) => (pings.push(args), ping(...args));
|
|
1792
|
+
const local = { components: { Transform: { x: 0, y: 1, z: 9 } } };
|
|
1793
|
+
const step = (now, list) => {
|
|
1794
|
+
system.together.frame(scene.multiplayer, list, true, now);
|
|
1795
|
+
system.drawChrome(scene, local, now);
|
|
1796
|
+
};
|
|
1797
|
+
return { system, scene, seen, sent, pings, step };
|
|
1798
|
+
};
|
|
1799
|
+
try {
|
|
1800
|
+
for (const cues of [true, false]) {
|
|
1801
|
+
// Came in by a door (no start beside a friend): amy was here already.
|
|
1802
|
+
const b = boot(cues);
|
|
1803
|
+
b.step(1000, null);
|
|
1804
|
+
assert.equal(b.seen.toast, '', 'the host has not said who the friends are');
|
|
1805
|
+
b.step(3000, friends);
|
|
1806
|
+
assert.equal(b.seen.toast, cues ? 'amy is here · People to join' : '', `cues ${cues}`);
|
|
1807
|
+
assert.deepEqual(b.pings, cues ? [['p4', 3000, true]] : []);
|
|
1808
|
+
// Once: not again while she stays, however often the host answers.
|
|
1809
|
+
b.system.toast = { text: '', until: 0 };
|
|
1810
|
+
b.step(9000, friends);
|
|
1811
|
+
b.step(30000, [...friends]);
|
|
1812
|
+
assert.equal(b.seen.toast, '');
|
|
1813
|
+
assert.equal(b.pings.length, cues ? 1 : 0);
|
|
1814
|
+
// bo is no friend: never told.
|
|
1815
|
+
assert.ok(!b.pings.some(([id]) => id === 'p2'));
|
|
1816
|
+
}
|
|
1817
|
+
|
|
1818
|
+
// Another toast is up (the result line of the game just left): it waits.
|
|
1819
|
+
const waits = boot(true);
|
|
1820
|
+
waits.system.toast = { text: 'Back from Foot Race', until: 5000 };
|
|
1821
|
+
waits.step(3000, friends);
|
|
1822
|
+
waits.step(4900, friends);
|
|
1823
|
+
assert.deepEqual([waits.seen.toast, waits.pings], ['Back from Foot Race', []]);
|
|
1824
|
+
waits.step(5100, friends);
|
|
1825
|
+
assert.equal(waits.seen.toast, 'amy is here · People to join');
|
|
1826
|
+
|
|
1827
|
+
// Walked in, and put beside her: "You're next to amy" says it, and "is here" never follows.
|
|
1828
|
+
const beside = boot(true);
|
|
1829
|
+
beside.system.startNear = { until: 12000, at: null, asked: false };
|
|
1830
|
+
beside.step(1000, null);
|
|
1831
|
+
beside.step(3000, friends);
|
|
1832
|
+
assert.deepEqual(beside.sent.filter((m) => m.k === 'hub-goto'), [{ k: 'hub-goto', player: 'p4' }]);
|
|
1833
|
+
assert.equal(beside.seen.toast, '');
|
|
1834
|
+
HubState.hub.jumpedTo = 'p4';
|
|
1835
|
+
beside.step(3300, friends);
|
|
1836
|
+
assert.equal(beside.seen.toast, "You're next to amy");
|
|
1837
|
+
beside.system.toast = { text: '', until: 0 };
|
|
1838
|
+
beside.step(8000, friends);
|
|
1839
|
+
beside.step(20000, friends);
|
|
1840
|
+
assert.deepEqual([beside.seen.toast, beside.pings], ['', []]);
|
|
1841
|
+
|
|
1842
|
+
// She left while another toast was up: nothing is said of someone not here.
|
|
1843
|
+
for (const gone of ['left', 'unfriended']) {
|
|
1844
|
+
const b = boot(true);
|
|
1845
|
+
b.system.toast = { text: 'Back from Foot Race', until: 5000 };
|
|
1846
|
+
b.step(3000, friends);
|
|
1847
|
+
assert.equal(b.system.hereCues.length, 1, 'queued behind the toast');
|
|
1848
|
+
if (gone === 'left') {
|
|
1849
|
+
b.scene.multiplayer.net.others = () => new Map([['p2', 'bo']]);
|
|
1850
|
+
}
|
|
1851
|
+
b.step(4000, gone === 'left' ? friends : []);
|
|
1852
|
+
b.step(5100, gone === 'left' ? friends : []);
|
|
1853
|
+
b.step(9000, gone === 'left' ? friends : []);
|
|
1854
|
+
assert.deepEqual([b.seen.toast, b.pings, b.system.hereCues], ['', [], []], gone);
|
|
1855
|
+
}
|
|
1856
|
+
|
|
1857
|
+
// Walked in, the place never answered the start beside her: told when that gives up.
|
|
1858
|
+
const lost = boot(true);
|
|
1859
|
+
lost.system.startNear = { until: 12000, at: null, asked: false };
|
|
1860
|
+
lost.step(1000, null);
|
|
1861
|
+
lost.step(3000, friends);
|
|
1862
|
+
lost.step(11000, friends);
|
|
1863
|
+
assert.equal(lost.seen.toast, '');
|
|
1864
|
+
lost.step(12100, friends);
|
|
1865
|
+
assert.equal(lost.seen.toast, 'amy is here · People to join');
|
|
1866
|
+
} finally {
|
|
1867
|
+
resetTown();
|
|
1868
|
+
}
|
|
1869
|
+
});
|
|
1870
|
+
|
|
1871
|
+
await test('cues (v1.29): back from a game the same game is offered again, with the party when there is one; without cues nothing is asked', async () => {
|
|
1872
|
+
try {
|
|
1873
|
+
for (const cues of [true, false]) {
|
|
1874
|
+
const { system, scene } = setup();
|
|
1875
|
+
HubState.deck.cues = cues;
|
|
1876
|
+
HubState.hub.place = { title: 'Town', result: null };
|
|
1877
|
+
HubState.hub.doors = [{ id: 'race', title: 'Foot Race' }, { id: 'solo', title: 'Summit Sprint', solo: true }];
|
|
1878
|
+
const seen = cueChrome(system);
|
|
1879
|
+
system.chrome.setCover = () => {};
|
|
1880
|
+
const sent = townNet(scene, new Map([['p2', 'bo']]), { p2: '102' });
|
|
1881
|
+
const back = (door, returning = true) => {
|
|
1882
|
+
scene.persistent.hubResult = { title: 'Foot Race', outcome: 'win' };
|
|
1883
|
+
const at = performance.now();
|
|
1884
|
+
system.finishTrip(scene, { n: 1, startedAt: at, marks: { covered: at, arrived: at, firstFrame: at, revealed: at }, target: { arrive: { door, party: 1, returning } } });
|
|
1885
|
+
system.drawChrome(scene, null, performance.now());
|
|
1886
|
+
};
|
|
1887
|
+
back('race');
|
|
1888
|
+
if (!cues) {
|
|
1889
|
+
assert.deepEqual([system.againAsk, seen.ask], [null, null]);
|
|
1890
|
+
continue;
|
|
1891
|
+
}
|
|
1892
|
+
assert.deepEqual([seen.ask.kind, seen.ask.text, seen.ask.yes, seen.ask.no], ['again', 'Play Foot Race again?', 'Play again', 'Not now']);
|
|
1893
|
+
// Not now: gone, and not put again.
|
|
1894
|
+
system.answer(scene, seen.ask, false);
|
|
1895
|
+
system.drawChrome(scene, null, performance.now());
|
|
1896
|
+
assert.deepEqual([seen.ask, sent], [null, []]);
|
|
1897
|
+
// Play again, alone: onto the pad.
|
|
1898
|
+
back('race');
|
|
1899
|
+
system.jumpSentAt = -Infinity;
|
|
1900
|
+
system.answer(scene, seen.ask, true);
|
|
1901
|
+
assert.deepEqual(sent.splice(0), [{ k: 'hub-door-jump', door: 'race' }]);
|
|
1902
|
+
assert.equal(system.againAsk, null);
|
|
1903
|
+
// In a party: the Doors list's Go together, which asks the party.
|
|
1904
|
+
HubState.hub.party = { members: ['p2'], away: 0, invite: null, proposal: null };
|
|
1905
|
+
back('race');
|
|
1906
|
+
assert.deepEqual([seen.ask.text, seen.ask.yes], ['Play Foot Race again together?', 'Go together']);
|
|
1907
|
+
system.answer(scene, seen.ask, true);
|
|
1908
|
+
assert.deepEqual(sent.splice(0), [{ k: 'hub-party', op: 'go', door: 'race' }]);
|
|
1909
|
+
// A solo game is never "together".
|
|
1910
|
+
back('solo');
|
|
1911
|
+
assert.deepEqual([seen.ask.text, seen.ask.yes], ['Play Summit Sprint again?', 'Play again']);
|
|
1912
|
+
// An invitation or a party's proposal is asked first.
|
|
1913
|
+
HubState.hub.party = { members: null, away: 0, invite: { from: 'p2', username: 'bo' }, proposal: null };
|
|
1914
|
+
system.drawChrome(scene, null, performance.now());
|
|
1915
|
+
assert.equal(seen.ask.kind, 'invite');
|
|
1916
|
+
HubState.hub.party = { members: null, away: 0, invite: null, proposal: null };
|
|
1917
|
+
// A door the town no longer has, an arrival that is not a return, and
|
|
1918
|
+
// an offer whose time is up: nothing.
|
|
1919
|
+
back('gone');
|
|
1920
|
+
assert.equal(seen.ask, null);
|
|
1921
|
+
system.againAsk = null;
|
|
1922
|
+
back('race', false);
|
|
1923
|
+
assert.deepEqual([system.againAsk, seen.ask], [null, null]);
|
|
1924
|
+
// An answer to an offer that is no longer the one up does nothing: its
|
|
1925
|
+
// time ran out, or a later return replaced it.
|
|
1926
|
+
back('race');
|
|
1927
|
+
const old = seen.ask;
|
|
1928
|
+
back('solo');
|
|
1929
|
+
system.jumpSentAt = -Infinity;
|
|
1930
|
+
system.answer(scene, old, true);
|
|
1931
|
+
assert.deepEqual([sent.splice(0), system.againAsk?.door], [[], 'solo']);
|
|
1932
|
+
const late = seen.ask;
|
|
1933
|
+
system.againAsk.until = performance.now() - 1;
|
|
1934
|
+
system.drawChrome(scene, null, performance.now());
|
|
1935
|
+
assert.equal(seen.ask, null);
|
|
1936
|
+
system.answer(scene, late, true);
|
|
1937
|
+
assert.deepEqual(sent.splice(0), []);
|
|
1938
|
+
// Back with no result to tell (Back before the game ended): still asked.
|
|
1939
|
+
scene.persistent.hubResult = null;
|
|
1940
|
+
const at = performance.now();
|
|
1941
|
+
system.finishTrip(scene, { n: 1, startedAt: at, marks: { covered: at, arrived: at, firstFrame: at, revealed: at }, target: { arrive: { door: 'race', party: 1, returning: true } } });
|
|
1942
|
+
system.drawChrome(scene, null, performance.now());
|
|
1943
|
+
assert.equal(seen.ask.text, 'Play Foot Race again?');
|
|
1944
|
+
}
|
|
1945
|
+
} finally {
|
|
1946
|
+
delete globalThis.__hubTrips;
|
|
1947
|
+
resetTown();
|
|
1948
|
+
}
|
|
1949
|
+
});
|
|
1950
|
+
|
|
1951
|
+
await test('cues: the chat field says who reads it or why it is off, and chat peers are asked for when someone comes in; without cues the chat part is what it was', async () => {
|
|
1952
|
+
try {
|
|
1953
|
+
for (const cues of [true, false]) {
|
|
1954
|
+
const { system, scene } = setup();
|
|
1955
|
+
HubState.deck.cues = cues;
|
|
1956
|
+
HubState.hub.place = { title: 'Town', result: null };
|
|
1957
|
+
const seen = cueChrome(system);
|
|
1958
|
+
const roster = new Map([['p2', 'bo'], ['p4', 'amy']]);
|
|
1959
|
+
townNet(scene, roster, { p2: '102', p4: '104' });
|
|
1960
|
+
const soon = [];
|
|
1961
|
+
const chat = { canChat: true, peers: ['104'], incoming: [], available: () => true, frame() {}, soon: (now) => soon.push(now) };
|
|
1962
|
+
system.chat = chat;
|
|
1963
|
+
const hint = (placeholder, label) => (cues ? { placeholder, label } : {});
|
|
1964
|
+
system.drawChrome(scene, null, 1000);
|
|
1965
|
+
assert.deepEqual(seen.say.chat, { input: true, note: 'Chat reaches amy', ...hint('To your follows…', 'Message · only players you follow each other with') });
|
|
1966
|
+
chat.peers = [];
|
|
1967
|
+
system.drawChrome(scene, null, 1100);
|
|
1968
|
+
// v1.29: with cues, one field and one sentence whatever the reason, so
|
|
1969
|
+
// neither tells which it is; without, the notes are what they were.
|
|
1970
|
+
const why = 'Typed chat is for friends who follow each other. Emotes work with everyone.';
|
|
1971
|
+
const nobody = 'Chat is for players who follow each other. None of yours are here now · the phrases above reach everyone.';
|
|
1972
|
+
assert.deepEqual(seen.say.chat, cues ? { input: false, note: why, placeholder: 'Friends only', label: why } : { input: false, note: nobody });
|
|
1973
|
+
chat.canChat = false;
|
|
1974
|
+
system.drawChrome(scene, null, 1200);
|
|
1975
|
+
const off = "Chat isn't available on this account";
|
|
1976
|
+
assert.deepEqual(seen.say.chat, cues ? { input: false, note: why, placeholder: 'Friends only', label: why } : { input: false, note: off });
|
|
1977
|
+
assert.ok(['To your follows…', 'Friends only'].every((text) => text.length <= 20), 'fits the field');
|
|
1978
|
+
assert.ok(!/\b(age|old|13|young|adult|child|kid)/i.test(why), 'never an age');
|
|
1979
|
+
|
|
1980
|
+
// The roster: everyone at the first frame, then only someone new.
|
|
1981
|
+
assert.deepEqual(soon, cues ? [1000] : []);
|
|
1982
|
+
roster.set('p9', 'zed');
|
|
1983
|
+
system.drawChrome(scene, null, 2000);
|
|
1984
|
+
system.drawChrome(scene, null, 2100);
|
|
1985
|
+
roster.delete('p2');
|
|
1986
|
+
system.drawChrome(scene, null, 2200);
|
|
1987
|
+
assert.deepEqual(soon, cues ? [1000, 2000] : [], `cues ${cues}`);
|
|
1988
|
+
|
|
1989
|
+
// A game behind one of the town's doors is drawn by the town's client:
|
|
1990
|
+
// its chat is left exactly as it was, cues or not.
|
|
1991
|
+
HubState.hub.place = { title: 'Foot Race', result: { outcomes: ['win'] } };
|
|
1992
|
+
chat.canChat = true;
|
|
1993
|
+
chat.peers = ['104'];
|
|
1994
|
+
roster.set('p7', 'eve');
|
|
1995
|
+
system.drawChrome(scene, null, 3000);
|
|
1996
|
+
assert.deepEqual(seen.say.chat, { input: true, note: 'Chat reaches amy' });
|
|
1997
|
+
assert.deepEqual(soon, cues ? [1000, 2000] : []);
|
|
1998
|
+
}
|
|
1999
|
+
} finally {
|
|
2000
|
+
resetTown();
|
|
2001
|
+
}
|
|
2002
|
+
});
|
|
2003
|
+
|
|
2004
|
+
// A phrase id the kit does not have.
|
|
2005
|
+
const GONE = 'join';
|
|
2006
|
+
await test('Doors > Go sends what it always did, cues or not: a jump alone, a proposal to a party here, a jump to a solo door; an unknown phrase heard is nothing', async () => {
|
|
2007
|
+
const friends = [{ userId: '104', username: 'amy', here: true }];
|
|
2008
|
+
try {
|
|
2009
|
+
for (const cues of [true, false]) {
|
|
2010
|
+
const { system, scene } = setup();
|
|
2011
|
+
HubState.deck.cues = cues;
|
|
2012
|
+
HubState.hub.place = { title: 'Town', result: null };
|
|
2013
|
+
HubState.hub.doors = [{ id: 'race', title: 'Foot Race' }, { id: 'summit', title: 'Summit Sprint', solo: true }];
|
|
2014
|
+
const seen = cueChrome(system);
|
|
2015
|
+
const sent = townNet(scene, new Map([['p2', 'bo'], ['p4', 'amy']]), { p2: '102', p4: '104' });
|
|
2016
|
+
HubState.hub.party = { members: null, away: 0, invite: null, proposal: null };
|
|
2017
|
+
system.together.frame(scene.multiplayer, friends, true, 1000);
|
|
2018
|
+
system.goDoor(scene, { id: 'race', title: 'Foot Race' });
|
|
2019
|
+
HubState.hub.party = { members: ['p2'], away: 0, invite: null, proposal: null };
|
|
2020
|
+
system.goDoor(scene, { id: 'race', title: 'Foot Race' });
|
|
2021
|
+
system.jumpSentAt = -Infinity;
|
|
2022
|
+
system.goDoor(scene, { id: 'summit', title: 'Summit Sprint', solo: true });
|
|
2023
|
+
assert.deepEqual(sent, [{ k: 'hub-door-jump', door: 'race' }, { k: 'hub-party', op: 'go', door: 'race' }, { k: 'hub-door-jump', door: 'summit' }], `cues ${cues}`);
|
|
2024
|
+
system.toast = { text: '', until: 0 };
|
|
2025
|
+
HubState.hub.saidEvents.push({ k: 'hub-said', player: 'p2', p: GONE, door: 'race' }, { k: 'hub-said', player: 'p4', p: GONE, door: 'race' });
|
|
2026
|
+
system.drawChrome(scene, null, performance.now());
|
|
2027
|
+
system.drawChrome(scene, null, performance.now());
|
|
2028
|
+
assert.deepEqual([seen.ask, system.say.feed()], [null, []]);
|
|
2029
|
+
}
|
|
2030
|
+
} finally {
|
|
2031
|
+
resetTown();
|
|
2032
|
+
}
|
|
2033
|
+
});
|
|
2034
|
+
|
|
2035
|
+
await test('cues: a party that gains a member says so; not the party a session is first told of, not a member back from a game; without cues nothing', async () => {
|
|
2036
|
+
const set = (members, away = 0, invite = null) => {
|
|
2037
|
+
HubState.hub.party = { members, away, invite, proposal: null };
|
|
2038
|
+
};
|
|
2039
|
+
try {
|
|
2040
|
+
for (const cues of [true, false]) {
|
|
2041
|
+
const { system, scene } = setup();
|
|
2042
|
+
HubState.deck.cues = cues;
|
|
2043
|
+
HubState.hub.place = { title: 'Town', result: null };
|
|
2044
|
+
const seen = cueChrome(system);
|
|
2045
|
+
const roster = new Map([['p2', 'bo'], ['p4', 'amy'], ['p9', 'zed']]);
|
|
2046
|
+
const sent = townNet(scene, roster, { p2: '102', p4: '104', p9: '109' });
|
|
2047
|
+
let now = performance.now();
|
|
2048
|
+
const draw = () => {
|
|
2049
|
+
now += 100;
|
|
2050
|
+
system.toast = { text: '', until: 0 };
|
|
2051
|
+
system.drawChrome(scene, null, now);
|
|
2052
|
+
return seen.toast;
|
|
2053
|
+
};
|
|
2054
|
+
const say = (text) => (cues ? text : '');
|
|
2055
|
+
|
|
2056
|
+
// The first word of a session is the party the player already had.
|
|
2057
|
+
set(['p2']);
|
|
2058
|
+
assert.equal(draw(), '', 'the first snapshot');
|
|
2059
|
+
set(['p2', 'p4']);
|
|
2060
|
+
assert.equal(draw(), say('amy joined your party'), `cues ${cues}`);
|
|
2061
|
+
assert.equal(draw(), '', 'once');
|
|
2062
|
+
// A member away in a game, and back (a new player id): no news.
|
|
2063
|
+
set(['p2'], 1);
|
|
2064
|
+
assert.equal(draw(), '');
|
|
2065
|
+
roster.set('p4b', 'amy');
|
|
2066
|
+
set(['p2', 'p4b'], 0);
|
|
2067
|
+
assert.equal(draw(), '', 'back from a game');
|
|
2068
|
+
set(null);
|
|
2069
|
+
assert.equal(draw(), '');
|
|
2070
|
+
|
|
2071
|
+
// Accepting an invitation: the player joined theirs.
|
|
2072
|
+
set(null, 0, { from: 'p2', username: 'bo' });
|
|
2073
|
+
assert.equal(draw(), '');
|
|
2074
|
+
assert.equal(seen.ask.text, 'bo invited you to their party');
|
|
2075
|
+
system.answer(scene, seen.ask, true);
|
|
2076
|
+
assert.deepEqual(sent.at(-1), { k: 'hub-party', op: 'accept', from: 'p2' });
|
|
2077
|
+
assert.equal(system.partyAccepted === null, !cues);
|
|
2078
|
+
set(['p2', 'p9']);
|
|
2079
|
+
assert.equal(draw(), say("You joined bo's party"));
|
|
2080
|
+
set(null);
|
|
2081
|
+
draw();
|
|
2082
|
+
// Someone accepted this player's: they joined.
|
|
2083
|
+
set(['p9']);
|
|
2084
|
+
assert.equal(draw(), say('zed joined your party'));
|
|
2085
|
+
set(null);
|
|
2086
|
+
draw();
|
|
2087
|
+
|
|
2088
|
+
// Inside a session's first moments, and for a party carried through a
|
|
2089
|
+
// door, the first members told are the ones the player had.
|
|
2090
|
+
system.partySettleUntil = now + 5000;
|
|
2091
|
+
set(['p2']);
|
|
2092
|
+
assert.equal(draw(), '', 'the first moments');
|
|
2093
|
+
set(null);
|
|
2094
|
+
now += 6000;
|
|
2095
|
+
draw();
|
|
2096
|
+
system.partyCarryUntil = now + 30000;
|
|
2097
|
+
set(['p2']);
|
|
2098
|
+
assert.equal(draw(), '', 'the party carried in');
|
|
2099
|
+
set(['p2', 'p9']);
|
|
2100
|
+
assert.equal(draw(), say('zed joined your party'), 'and a join after it is news');
|
|
2101
|
+
}
|
|
2102
|
+
} finally {
|
|
2103
|
+
resetTown();
|
|
2104
|
+
}
|
|
2105
|
+
});
|
|
2106
|
+
|
|
2107
|
+
await test('v1.52: Back, hub-end then Back, local doors and Hub.go capture the leaving line; cabinets do not', async () => {
|
|
2108
|
+
try {
|
|
2109
|
+
for (const way of ['back', 'end', 'door', 'hub', 'classic']) {
|
|
2110
|
+
HubState.clear();
|
|
2111
|
+
HubState.hub.place = { id: 'main', title: 'Town' };
|
|
2112
|
+
HubState.hub.leaving = 'Your lantern is waiting';
|
|
2113
|
+
const { system, scene } = setup();
|
|
2114
|
+
if (way === 'back') system.back(scene);
|
|
2115
|
+
if (way === 'end') {
|
|
2116
|
+
HubState.hub.commands.push({ k: 'hub-end', why: 'end' });
|
|
2117
|
+
system.runCommands(scene, 1000);
|
|
2118
|
+
system.stepEnd(scene, { joinState: () => 'joined' }, 2200);
|
|
2119
|
+
}
|
|
2120
|
+
if (way === 'door') system.go(scene, { door: 'race', key: 'hub.race', title: 'Foot Race' });
|
|
2121
|
+
if (way === 'hub') {
|
|
2122
|
+
answers.go = handoff();
|
|
2123
|
+
system.goHub(scene, { door: 'race', title: 'Foot Race' });
|
|
2124
|
+
await flush();
|
|
2125
|
+
}
|
|
2126
|
+
if (way === 'classic') system.startTrip(scene, { classic: true, title: 'Cabinet' });
|
|
2127
|
+
assert.equal(system.trip.leaving, way === 'classic' ? null : 'Your lantern is waiting', way);
|
|
2128
|
+
const captured = system.trip.leaving;
|
|
2129
|
+
HubState.clear();
|
|
2130
|
+
assert.equal(system.trip.leaving, captured, 'captured across Hub.clear');
|
|
2131
|
+
}
|
|
2132
|
+
} finally { HubState.clear(); }
|
|
2133
|
+
});
|
|
2134
|
+
|
|
2135
|
+
await test('v1.52: a fast trip shows the line as soon as the cover lifts, expires at 2800 ms, and never waits', async () => {
|
|
2136
|
+
const saved = globalThis.performance;
|
|
2137
|
+
let now = 1000;
|
|
2138
|
+
globalThis.performance = { now: () => now };
|
|
2139
|
+
try {
|
|
2140
|
+
HubState.clear();
|
|
2141
|
+
HubState.hub.leaving = 'Next time, the well';
|
|
2142
|
+
const { system, scene } = setup();
|
|
2143
|
+
const seen = cueChrome(system);
|
|
2144
|
+
const covers = [];
|
|
2145
|
+
system.chrome.setCover = (...args) => covers.push(args);
|
|
2146
|
+
system.startTrip(scene, { scene: 'scenes/next.scene', title: 'Next', join: { mode: 'public' } });
|
|
2147
|
+
const trip = system.trip;
|
|
2148
|
+
const mp = mpStub(scene, 'joined');
|
|
2149
|
+
mp.placed = () => true;
|
|
2150
|
+
system.stepTrip(scene, mp, null, 1650);
|
|
2151
|
+
assert.equal(trip.phase, 'loading');
|
|
2152
|
+
assert.deepEqual(covers.at(-1), [1, 'Next', 'Next time, the well']);
|
|
2153
|
+
assert.equal(HubState.hub.leaving, null, 'switch clears the old place line');
|
|
2154
|
+
scene.currentScenePath = scene.requestedScene;
|
|
2155
|
+
scene.requestedScene = null;
|
|
2156
|
+
HubState.hub.arrivedFacing = 0;
|
|
2157
|
+
system.stepTrip(scene, mp, null, 1651);
|
|
2158
|
+
assert.equal(trip.phase, 'revealing');
|
|
2159
|
+
now = 2071; // 60% of reveal: cover lifted, trip still moving.
|
|
2160
|
+
system.stepTrip(scene, mp, null, now);
|
|
2161
|
+
system.drawChrome(scene, null, now);
|
|
2162
|
+
assert.equal(seen.toast, 'Next time, the well');
|
|
2163
|
+
assert.deepEqual(seen.toastOptions, { wrap: true });
|
|
2164
|
+
assert.equal(system.trip, trip);
|
|
2165
|
+
now = 2351;
|
|
2166
|
+
system.stepTrip(scene, mp, null, now);
|
|
2167
|
+
assert.equal(system.trip, null, 'finished on the ordinary 700 ms reveal deadline');
|
|
2168
|
+
system.drawChrome(scene, null, 3799);
|
|
2169
|
+
assert.equal(seen.toast, 'Next time, the well');
|
|
2170
|
+
system.drawChrome(scene, null, 3800);
|
|
2171
|
+
assert.equal(seen.toast, '');
|
|
2172
|
+
assert.equal(seen.toastOptions, undefined, 'ordinary toasts keep the original call');
|
|
2173
|
+
} finally { globalThis.performance = saved; HubState.clear(); }
|
|
2174
|
+
});
|
|
2175
|
+
|
|
2176
|
+
await test('v1.52: return result and leaving line share one bounded toast; result survives the line deadline', async () => {
|
|
2177
|
+
const saved = globalThis.performance;
|
|
2178
|
+
globalThis.performance = { now: () => 2000 };
|
|
2179
|
+
try {
|
|
2180
|
+
HubState.clear();
|
|
2181
|
+
const { system, scene } = setup();
|
|
2182
|
+
const seen = cueChrome(system);
|
|
2183
|
+
system.chrome.setCover = () => {};
|
|
2184
|
+
scene.persistent.hubResult = { title: 'Foot Race', outcome: 'win' };
|
|
2185
|
+
const trip = { n: 1, startedAt: 1000, leaving: 'Your lantern is waiting', leavingUntil: 3800,
|
|
2186
|
+
target: { scene: 'scenes/main.scene', arrive: { returning: true } },
|
|
2187
|
+
marks: { covered: 1650, arrived: 1700, firstFrame: 1800, revealed: 2000 } };
|
|
2188
|
+
system.finishTrip(scene, trip);
|
|
2189
|
+
system.drawChrome(scene, null, 2000);
|
|
2190
|
+
assert.match(seen.toast, /^Back from Foot Race.* · Your lantern is waiting$/);
|
|
2191
|
+
const resultToast = system.toast;
|
|
2192
|
+
system.drawChrome(scene, null, 3799);
|
|
2193
|
+
assert.match(seen.toast, / · Your lantern is waiting$/);
|
|
2194
|
+
system.drawChrome(scene, null, 3800);
|
|
2195
|
+
assert.equal(system.toast, resultToast);
|
|
2196
|
+
assert.match(seen.toast, /^Back from Foot Race/);
|
|
2197
|
+
assert.doesNotMatch(seen.toast, /Your lantern/);
|
|
2198
|
+
scene.persistent.hubResult.title = 'X'.repeat(300);
|
|
2199
|
+
trip.leaving = 'y'.repeat(120);
|
|
2200
|
+
system.showLeaving(scene, trip, 2000);
|
|
2201
|
+
assert.ok(system.leavingToast.text.length <= 203);
|
|
2202
|
+
} finally { globalThis.performance = saved; HubState.clear(); }
|
|
2203
|
+
});
|
|
2204
|
+
|
|
2205
|
+
await test('v1.52: newer action feedback supersedes leaving, across reveal frames and the arrival result', async () => {
|
|
2206
|
+
const saved = globalThis.performance;
|
|
2207
|
+
let now = 2000;
|
|
2208
|
+
globalThis.performance = { now: () => now };
|
|
2209
|
+
try {
|
|
2210
|
+
for (const returning of [false, true]) {
|
|
2211
|
+
HubState.clear();
|
|
2212
|
+
const { system, scene } = setup();
|
|
2213
|
+
const seen = cueChrome(system);
|
|
2214
|
+
system.chrome.setCover = () => {};
|
|
2215
|
+
scene.persistent.hubResult = { title: 'Foot Race', outcome: 'win' };
|
|
2216
|
+
const trip = { n: 1, startedAt: 1000, leaving: 'Your lantern is waiting', leavingUntil: 3800,
|
|
2217
|
+
target: { scene: 'scenes/main.scene', arrive: { returning } },
|
|
2218
|
+
marks: { covered: 1650, arrived: 1700, firstFrame: 1800, revealed: 2200 } };
|
|
2219
|
+
system.toast = { text: 'Older feedback', until: 6000 };
|
|
2220
|
+
system.showLeaving(scene, trip, now);
|
|
2221
|
+
system.drawChrome(scene, null, now);
|
|
2222
|
+
assert.match(seen.toast, /Your lantern is waiting$/);
|
|
2223
|
+
// Real People-list action after the leaving toast starts.
|
|
2224
|
+
scene.multiplayer.net = { send() {} };
|
|
2225
|
+
now = 2100;
|
|
2226
|
+
system.join(scene, { playerId: 'ada', username: 'Ada' }, 'invite');
|
|
2227
|
+
const feedback = system.toast;
|
|
2228
|
+
system.drawChrome(scene, null, now);
|
|
2229
|
+
assert.equal(seen.toast, 'Invited Ada to your party');
|
|
2230
|
+
assert.equal(seen.toastOptions, undefined);
|
|
2231
|
+
now = 2200;
|
|
2232
|
+
system.showLeaving(scene, trip, now);
|
|
2233
|
+
system.finishTrip(scene, trip);
|
|
2234
|
+
system.drawChrome(scene, null, now);
|
|
2235
|
+
assert.equal(system.toast, feedback, 'arrival result does not overwrite newer feedback');
|
|
2236
|
+
assert.equal(seen.toast, 'Invited Ada to your party');
|
|
2237
|
+
// Expired newer feedback must not uncover the old leaving line again.
|
|
2238
|
+
feedback.until = 2300;
|
|
2239
|
+
system.drawChrome(scene, null, 2400);
|
|
2240
|
+
assert.equal(seen.toast, '');
|
|
2241
|
+
now = 2000;
|
|
2242
|
+
}
|
|
2243
|
+
} finally { globalThis.performance = saved; HubState.clear(); }
|
|
2244
|
+
});
|
|
2245
|
+
|
|
2246
|
+
await test('v1.52: replacement trips retain the first line and deadline after Hub.clear', async () => {
|
|
2247
|
+
const saved = globalThis.performance;
|
|
2248
|
+
let now = 1000;
|
|
2249
|
+
globalThis.performance = { now: () => now };
|
|
2250
|
+
try {
|
|
2251
|
+
for (const way of ['back', 'door', 'door-nested', 'jump', 'jump-nested', 'lost', 'mount']) {
|
|
2252
|
+
now = 1000;
|
|
2253
|
+
HubState.clear();
|
|
2254
|
+
HubState.hub.leaving = 'Next time, the well';
|
|
2255
|
+
const { system, scene } = setup();
|
|
2256
|
+
const mp = mpStub(scene);
|
|
2257
|
+
answers.go = handoff();
|
|
2258
|
+
answers.jump = handoff();
|
|
2259
|
+
answers.back = handoff();
|
|
2260
|
+
if (['back', 'door-nested', 'jump-nested'].includes(way)) {
|
|
2261
|
+
scene.persistent.hubDepth = 1;
|
|
2262
|
+
scene.persistent.hubTickets.push({ hub: true, scene: 'scenes/main.scene', title: 'Town', join: { mode: 'public' } });
|
|
2263
|
+
scene.multiplayer.target = { mode: 'hub', handoff: handoff({ nonce: 'spent' }) };
|
|
2264
|
+
}
|
|
2265
|
+
if (way === 'back') system.back(scene);
|
|
2266
|
+
else if (way.startsWith('jump')) system.jump(scene, { userId: 'ada', username: 'Ada' });
|
|
2267
|
+
else system.goHub(scene, { door: 'race', title: 'Foot Race' });
|
|
2268
|
+
await flush();
|
|
2269
|
+
const first = system.trip;
|
|
2270
|
+
assert.equal(first.leavingUntil, first.startedAt + 2800);
|
|
2271
|
+
system.stepTrip(scene, mp, null, 1650);
|
|
2272
|
+
assert.equal(first.phase, 'committing', way);
|
|
2273
|
+
assert.equal(HubState.hub.leaving, null);
|
|
2274
|
+
now = 1800;
|
|
2275
|
+
if (way === 'lost' || way === 'mount') {
|
|
2276
|
+
mp.state = 'joined';
|
|
2277
|
+
system.stepTrip(scene, mp, null, now);
|
|
2278
|
+
assert.equal(first.phase, 'loading');
|
|
2279
|
+
if (way === 'lost') mp.state = 'lost';
|
|
2280
|
+
else scene.mountError = new Error('could not mount');
|
|
2281
|
+
now = 1900;
|
|
2282
|
+
} else {
|
|
2283
|
+
mp.state = 'failed';
|
|
2284
|
+
}
|
|
2285
|
+
system.stepTrip(scene, mp, null, now);
|
|
2286
|
+
await flush();
|
|
2287
|
+
const replacement = system.trip;
|
|
2288
|
+
assert.notEqual(replacement, first, way);
|
|
2289
|
+
assert.equal(replacement.leaving, 'Next time, the well', way);
|
|
2290
|
+
assert.equal(replacement.leavingUntil, 3800, `${way}: deadline never restarts`);
|
|
2291
|
+
const covers = [];
|
|
2292
|
+
system.chrome.setCover = (...args) => covers.push(args);
|
|
2293
|
+
system.setTripCover(1, replacement);
|
|
2294
|
+
assert.equal(covers.at(-1)[2], first.leaving);
|
|
2295
|
+
system.showLeaving(scene, replacement, 3799);
|
|
2296
|
+
assert.equal(system.leavingToast.text, first.leaving);
|
|
2297
|
+
system.leavingToast = null;
|
|
2298
|
+
system.showLeaving(scene, replacement, 3800);
|
|
2299
|
+
assert.equal(system.leavingToast, null, `${way}: no toast beyond the original deadline`);
|
|
2300
|
+
}
|
|
2301
|
+
} finally { globalThis.performance = saved; HubState.clear(); }
|
|
2302
|
+
});
|
|
2303
|
+
|
|
2304
|
+
await test('v1.52: end-triggered Back retries after exhausted join attempts retain the original deadline', async () => {
|
|
2305
|
+
const saved = globalThis.performance;
|
|
2306
|
+
let now = 1000;
|
|
2307
|
+
globalThis.performance = { now: () => now };
|
|
2308
|
+
try {
|
|
2309
|
+
HubState.clear();
|
|
2310
|
+
HubState.hub.leaving = 'Next time, the well';
|
|
2311
|
+
const { system, scene } = setup();
|
|
2312
|
+
scene.persistent.hubDepth = 1;
|
|
2313
|
+
scene.persistent.hubTickets.push({ hub: true, scene: 'scenes/main.scene', title: 'Town', join: { mode: 'public' } });
|
|
2314
|
+
answers.back = handoff();
|
|
2315
|
+
HubState.hub.commands.push({ k: 'hub-end' });
|
|
2316
|
+
system.runCommands(scene, 0);
|
|
2317
|
+
system.back(scene);
|
|
2318
|
+
const first = system.trip;
|
|
2319
|
+
HubState.clear();
|
|
2320
|
+
now = 1800;
|
|
2321
|
+
system.uncommitted(scene, first, now);
|
|
2322
|
+
const retry = system.trip;
|
|
2323
|
+
assert.equal(retry.leaving, first.leaving);
|
|
2324
|
+
assert.equal(retry.leavingUntil, 3800);
|
|
2325
|
+
now = 2000;
|
|
2326
|
+
system.uncommitted(scene, retry, now);
|
|
2327
|
+
assert.equal(system.trip, null, 'ordinary retry exhausted');
|
|
2328
|
+
now = 3900;
|
|
2329
|
+
system.stepEnd(scene, { joinState: () => 'failed' }, now);
|
|
2330
|
+
assert.equal(system.trip.leaving, first.leaving);
|
|
2331
|
+
assert.equal(system.trip.leavingUntil, 3800, 'end retry cannot extend the toast');
|
|
2332
|
+
system.showLeaving(scene, system.trip, now);
|
|
2333
|
+
assert.equal(system.leavingToast, null);
|
|
2334
|
+
await flush();
|
|
2335
|
+
scene.multiplayer.target = { mode: 'named', key: 'another-visit' };
|
|
2336
|
+
system.settleEnd(scene);
|
|
2337
|
+
assert.equal(system.endLeaving, null);
|
|
2338
|
+
} finally { globalThis.performance = saved; HubState.clear(); }
|
|
2339
|
+
});
|
|
2340
|
+
|
|
2341
|
+
await test('v1.52: a slow trip keeps its cover line and creates no expired arrival toast; no-line trips keep the old cover arguments', async () => {
|
|
2342
|
+
try {
|
|
2343
|
+
HubState.clear();
|
|
2344
|
+
const { system, scene } = setup();
|
|
2345
|
+
const covers = [];
|
|
2346
|
+
system.chrome.setCover = (...args) => covers.push(args);
|
|
2347
|
+
system.startTrip(scene, { title: 'Town' });
|
|
2348
|
+
system.setTripCover(1, system.trip);
|
|
2349
|
+
assert.deepEqual(covers.at(-1), [1, 'Town']);
|
|
2350
|
+
const trip = system.trip;
|
|
2351
|
+
trip.leaving = 'The well is waiting';
|
|
2352
|
+
system.setTripCover(1, trip);
|
|
2353
|
+
assert.deepEqual(covers.at(-1), [1, 'Town', 'The well is waiting']);
|
|
2354
|
+
system.showLeaving(scene, trip, trip.leavingUntil + 1);
|
|
2355
|
+
assert.equal(system.leavingToast, null);
|
|
2356
|
+
trip.shut = 'full';
|
|
2357
|
+
system.setTripCover(1, trip);
|
|
2358
|
+
assert.deepEqual(covers.at(-1), [1, 'Town']);
|
|
2359
|
+
system.showLeaving(scene, trip, trip.startedAt + 1);
|
|
2360
|
+
assert.equal(system.leavingToast, null, 'a door that stayed shut has no arrival line');
|
|
2361
|
+
} finally { HubState.clear(); }
|
|
2362
|
+
});
|
|
2363
|
+
|
|
2364
|
+
await test('v1.52: hubLeaving is a bounded localhost fixture, ignored by hosted pages and classic cabinets', async () => {
|
|
2365
|
+
const saved = globalThis.location;
|
|
2366
|
+
try {
|
|
2367
|
+
HubState.clear();
|
|
2368
|
+
for (const hostname of ['localhost', '127.0.0.1', 'castle.xyz']) {
|
|
2369
|
+
globalThis.location = { hostname, search: '?hubLeaving=%20' + 'x'.repeat(140) + '%20' };
|
|
2370
|
+
const { system, scene } = setup();
|
|
2371
|
+
system.startTrip(scene, { title: 'Town' });
|
|
2372
|
+
assert.equal(system.trip.leaving, hostname === 'castle.xyz' ? null : 'x'.repeat(120));
|
|
2373
|
+
system.trip = null;
|
|
2374
|
+
system.startTrip(scene, { title: 'Cabinet', classic: true });
|
|
2375
|
+
assert.equal(system.trip.leaving, null);
|
|
2376
|
+
}
|
|
2377
|
+
} finally { globalThis.location = saved; HubState.clear(); }
|
|
2378
|
+
});
|
|
2379
|
+
|
|
2380
|
+
await test('yourGames v1.54: keyless sends nothing; offers obey party, solo, invitation, game and trip rules', async () => {
|
|
2381
|
+
try {
|
|
2382
|
+
const { system, scene } = setup();
|
|
2383
|
+
const seen = cueChrome(system);
|
|
2384
|
+
system.chrome.setCover = () => {};
|
|
2385
|
+
const sent = townNet(scene, new Map([['p2', 'bo']]), { p2: '102' });
|
|
2386
|
+
HubState.hub.place = { title: 'Town', result: null };
|
|
2387
|
+
HubState.hub.doors = [{ id: 'race', title: 'Foot Race' }, { id: 'solo', title: 'Sprint', solo: true }];
|
|
2388
|
+
HubState.hub.yours = { rows: [{ door: 'race', title: 'Foot Race', line: 'Best 10 s · today', hearted: true }], hearts: ['race'] };
|
|
2389
|
+
let heartReads = 0;
|
|
2390
|
+
globalThis.__tripHub.hearts = async () => { heartReads++; return { status: 'ok', hearts: ['race'] }; };
|
|
2391
|
+
HubState.deck.yourGames = false;
|
|
2392
|
+
const before = globalThis.__yoursUserReads ?? 0;
|
|
2393
|
+
system.drawChrome(scene, null, performance.now());
|
|
2394
|
+
await flush();
|
|
2395
|
+
assert.equal(system.yours, undefined);
|
|
2396
|
+
assert.equal(heartReads, 0);
|
|
2397
|
+
assert.equal(globalThis.__yoursUserReads ?? 0, before, 'keyless reads no account');
|
|
2398
|
+
assert.equal(seen.ask, null);
|
|
2399
|
+
HubState.deck.yourGames = true;
|
|
2400
|
+
HubState.deck.cues = true;
|
|
2401
|
+
system.drawChrome(scene, null, performance.now());
|
|
2402
|
+
await flush();
|
|
2403
|
+
system.drawChrome(scene, null, performance.now());
|
|
2404
|
+
assert.equal(heartReads, 1);
|
|
2405
|
+
assert.deepEqual([seen.ask.kind, seen.ask.text, seen.ask.line, seen.ask.yes], ['yours', '♥ Foot Race', 'Best 10 s · today', 'Go']);
|
|
2406
|
+
system.answer(scene, seen.ask, false);
|
|
2407
|
+
system.drawChrome(scene, null, performance.now());
|
|
2408
|
+
assert.equal(seen.ask, null, 'dismissed once');
|
|
2409
|
+
const back = (door) => {
|
|
2410
|
+
const at = performance.now();
|
|
2411
|
+
system.finishTrip(scene, { n: 1, startedAt: at, marks: { covered: at, arrived: at, firstFrame: at, revealed: at }, target: { arrive: { door, returning: true } } });
|
|
2412
|
+
};
|
|
2413
|
+
back('race');
|
|
2414
|
+
HubState.hub.party.members = ['p2'];
|
|
2415
|
+
system.drawChrome(scene, null, performance.now());
|
|
2416
|
+
assert.equal(seen.ask.yes, 'Go together');
|
|
2417
|
+
assert.equal(seen.ask.heart, true);
|
|
2418
|
+
system.answer(scene, seen.ask, true);
|
|
2419
|
+
assert.deepEqual(sent.splice(0), [{ k: 'hub-party', op: 'go', door: 'race' }]);
|
|
2420
|
+
scene.persistent.hubResult = { title: 'Sprint', score: 14, unit: 's' };
|
|
2421
|
+
back('solo');
|
|
2422
|
+
system.drawChrome(scene, null, performance.now());
|
|
2423
|
+
assert.deepEqual([seen.ask.door, seen.ask.yes, system.againAsk], ['solo', 'Go', null]);
|
|
2424
|
+
assert.equal(seen.ask.line, 'Last 14 s · today', 'return outside the top five still has a personal line');
|
|
2425
|
+
HubState.hub.party.invite = { from: 'p2', username: 'bo' };
|
|
2426
|
+
system.drawChrome(scene, null, performance.now());
|
|
2427
|
+
assert.equal(seen.ask.kind, 'invite');
|
|
2428
|
+
HubState.hub.party.invite = null;
|
|
2429
|
+
HubState.hub.party.proposal = { asked: false, door: 'race' };
|
|
2430
|
+
system.drawChrome(scene, null, performance.now());
|
|
2431
|
+
assert.equal(seen.ask, null, 'no offer over any proposal');
|
|
2432
|
+
HubState.hub.party.proposal = null;
|
|
2433
|
+
HubState.hub.place.result = {};
|
|
2434
|
+
system.drawChrome(scene, null, performance.now());
|
|
2435
|
+
assert.equal(seen.ask, null, 'never in a game');
|
|
2436
|
+
HubState.hub.place.result = null;
|
|
2437
|
+
system.trip = { phase: 'open' };
|
|
2438
|
+
system.drawChrome(scene, null, performance.now());
|
|
2439
|
+
assert.equal(seen.ask, null, 'never during a trip');
|
|
2440
|
+
assert.equal(heartReads, 1);
|
|
2441
|
+
} finally {
|
|
2442
|
+
HubState.deck.yourGames = false;
|
|
2443
|
+
HubState.hub.yours = null;
|
|
2444
|
+
delete globalThis.__tripHub.hearts;
|
|
2445
|
+
delete globalThis.__yoursUserReads;
|
|
2446
|
+
resetTown();
|
|
2447
|
+
}
|
|
2448
|
+
});
|
|
2449
|
+
|
|
2450
|
+
// v1.61: exercise the production lifecycle methods, including direct door
|
|
2451
|
+
// travel that starts without a hub-go message.
|
|
2452
|
+
for (const [name, leave] of [
|
|
2453
|
+
['door trip', (system, scene) => system.startTrip(scene, { scene: 'scenes/next.scene' })],
|
|
2454
|
+
['leaving the session', (system, scene) => {
|
|
2455
|
+
scene.multiplayer.switchSession = () => {};
|
|
2456
|
+
system.leaveSession(scene, scene.multiplayer);
|
|
2457
|
+
}],
|
|
2458
|
+
['same-scene load', (system, scene) => system.reset(scene)],
|
|
2459
|
+
['entering another scene', (system, scene) => system.enterScene(scene)],
|
|
2460
|
+
['disconnect', (system, scene) => {
|
|
2461
|
+
system.lastNet = { closed: () => true };
|
|
2462
|
+
scene.multiplayer.net = null;
|
|
2463
|
+
system.watchSession(scene, scene.multiplayer);
|
|
2464
|
+
}],
|
|
2465
|
+
['runtime disposal', (system) => { system.chrome = null; system.dispose(); }],
|
|
2466
|
+
]) {
|
|
2467
|
+
for (const deckOwns of [false, true]) {
|
|
2468
|
+
await test(`v1.61: ${name} clears only a hub-owned shot (deck owns: ${deckOwns})`, () => {
|
|
2469
|
+
HubState.clear();
|
|
2470
|
+
const { system, scene } = setup();
|
|
2471
|
+
scene.cameraControl = 'orbit';
|
|
2472
|
+
const pose = { look: { x: 1, y: 2, z: 3 }, distance: 8, pitch: 30, yaw: 45 };
|
|
2473
|
+
try {
|
|
2474
|
+
receiveShot(scene, pose);
|
|
2475
|
+
if (deckOwns) { scene.orbitShot = pose; }
|
|
2476
|
+
leave(system, scene);
|
|
2477
|
+
assert.equal(scene.orbitShot, deckOwns ? pose : undefined);
|
|
2478
|
+
assert.equal(Object.hasOwn(HubState.hub, 'shot'), false);
|
|
2479
|
+
} finally {
|
|
2480
|
+
clearShot();
|
|
2481
|
+
}
|
|
2482
|
+
});
|
|
2483
|
+
}
|
|
2484
|
+
}
|
|
2485
|
+
|
|
2486
|
+
// A connection the session let go and took back (a phone's app switch): the
|
|
2487
|
+
// real-time server sends a WORLD snapshot each time it gives a connection a
|
|
2488
|
+
// body, and the client's hub system greets again when a second one is drained.
|
|
2489
|
+
function fakeNet(selfId = 'p1') {
|
|
2490
|
+
const net = {
|
|
2491
|
+
sent: [],
|
|
2492
|
+
inbox: [],
|
|
2493
|
+
id: selfId,
|
|
2494
|
+
send(msg) {
|
|
2495
|
+
net.sent.push(msg);
|
|
2496
|
+
},
|
|
2497
|
+
selfId: () => net.id,
|
|
2498
|
+
drain() {
|
|
2499
|
+
const out = net.inbox;
|
|
2500
|
+
net.inbox = [];
|
|
2501
|
+
return out;
|
|
2502
|
+
},
|
|
2503
|
+
};
|
|
2504
|
+
return net;
|
|
2505
|
+
}
|
|
2506
|
+
|
|
2507
|
+
await test('every place: a connection the session took back on the same net says a fresh hello once; steady state sends none', async () => {
|
|
2508
|
+
for (const place of [{}, { decor: { grid: { x: 0, z: 0, w: 1, d: 1, cell: 1 } } }]) {
|
|
2509
|
+
const { system, scene } = setup();
|
|
2510
|
+
HubState.hub.place = place;
|
|
2511
|
+
scene.persistent.hubArriving = { door: 'race', party: 3, returning: true, near: '42' };
|
|
2512
|
+
scene.persistent.hubResult = { title: 'Race', outcome: 'win' };
|
|
2513
|
+
const net = fakeNet();
|
|
2514
|
+
const mp = { net, joined: false };
|
|
2515
|
+
const hellos = () => net.sent.filter((m) => m.k === 'hub-hello');
|
|
2516
|
+
system.sayHello(scene, mp);
|
|
2517
|
+
assert.equal(hellos().length, 1);
|
|
2518
|
+
assert.equal(hellos()[0].party, 3);
|
|
2519
|
+
// The join's own snapshot, then ordinary traffic: no hello again.
|
|
2520
|
+
net.inbox.push({ k: 'w' }, { k: 's' });
|
|
2521
|
+
net.drain();
|
|
2522
|
+
mp.joined = true;
|
|
2523
|
+
for (let i = 0; i < 20; i += 1) {
|
|
2524
|
+
net.inbox.push({ k: 's' }, { k: 'hub-hud' });
|
|
2525
|
+
net.drain();
|
|
2526
|
+
system.sayHello(scene, mp);
|
|
2527
|
+
}
|
|
2528
|
+
assert.equal(hellos().length, 1, 'steady state: no extra hello');
|
|
2529
|
+
// The drop: the session let the player go, the SDK resumed this net, and
|
|
2530
|
+
// the session gave it a body again (a WORLD, queued while frames stopped).
|
|
2531
|
+
const kept = { startNear: system.startNear, say: system.say, together: system.together };
|
|
2532
|
+
net.inbox.push({ k: 'w' });
|
|
2533
|
+
net.drain();
|
|
2534
|
+
system.sayHello(scene, mp);
|
|
2535
|
+
system.sayHello(scene, mp);
|
|
2536
|
+
assert.equal(hellos().length, 2, 'one fresh hello');
|
|
2537
|
+
const again = hellos()[1];
|
|
2538
|
+
assert.equal(again.resume, true);
|
|
2539
|
+
assert.equal(again.again, undefined, 'fresh: the place re-sends what it had sent');
|
|
2540
|
+
assert.equal(again.party, 1, 'from a party of one');
|
|
2541
|
+
assert.equal(again.carry, null, 'carrying nothing back twice');
|
|
2542
|
+
assert.equal(again.near, undefined);
|
|
2543
|
+
assert.equal(again.from, 'race');
|
|
2544
|
+
assert.equal(system.startNear, kept.startNear, 'session state kept');
|
|
2545
|
+
assert.equal(system.say, kept.say);
|
|
2546
|
+
// A second drop greets once more.
|
|
2547
|
+
net.inbox.push({ k: 'w' });
|
|
2548
|
+
net.drain();
|
|
2549
|
+
system.sayHello(scene, mp);
|
|
2550
|
+
assert.equal(hellos().length, 3);
|
|
2551
|
+
HubState.hub.place = null;
|
|
2552
|
+
delete scene.persistent.hubArriving;
|
|
2553
|
+
delete scene.persistent.hubResult;
|
|
2554
|
+
await flush();
|
|
2555
|
+
}
|
|
2556
|
+
});
|
|
2557
|
+
|
|
2558
|
+
await test('a resumed net under a new player id greets afresh; a new net still greets as before', async () => {
|
|
2559
|
+
const { system, scene } = setup();
|
|
2560
|
+
const net = fakeNet('p1');
|
|
2561
|
+
const mp = { net, joined: true };
|
|
2562
|
+
system.sayHello(scene, mp);
|
|
2563
|
+
net.id = 'p9';
|
|
2564
|
+
system.sayHello(scene, mp);
|
|
2565
|
+
const hellos = net.sent.filter((m) => m.k === 'hub-hello');
|
|
2566
|
+
assert.equal(hellos.length, 2);
|
|
2567
|
+
assert.equal(hellos[1].resume, true);
|
|
2568
|
+
system.sayHello(scene, mp);
|
|
2569
|
+
assert.equal(net.sent.filter((m) => m.k === 'hub-hello').length, 2, 'once');
|
|
2570
|
+
const other = fakeNet('p2');
|
|
2571
|
+
system.sayHello(scene, { net: other, joined: false });
|
|
2572
|
+
assert.equal(other.sent.length, 1);
|
|
2573
|
+
assert.equal(other.sent[0].resume, undefined, 'a new net is an ordinary hello');
|
|
2574
|
+
await flush();
|
|
2575
|
+
});
|
|
2576
|
+
|
|
2577
|
+
await test('a new player id on the same net clears the old session\'s private state before the new session\'s packets apply', async () => {
|
|
2578
|
+
// The private packets as the hook layer applies them (client/hookLayer.js).
|
|
2579
|
+
const apply = (msg) => {
|
|
2580
|
+
if (msg.k === 'hub-hud') HubState.hub.hudMe = msg.hud ?? null;
|
|
2581
|
+
if (msg.k === 'hub-tune') HubState.hub.tune = msg.tune;
|
|
2582
|
+
if (msg.k === 'hub-decor') HubState.hub.decor = { button: msg.button, spec: msg.spec, grid: msg.grid };
|
|
2583
|
+
if (msg.k === 'hub-leaving') HubState.hub.leaving = msg.text;
|
|
2584
|
+
if (msg.k === 'hub-ballot-card') BallotClient.gate(HubState.hub.place, net, msg.card);
|
|
2585
|
+
};
|
|
2586
|
+
const BallotClient = await import('../code/client/ballot.js');
|
|
2587
|
+
const { system, scene } = setup();
|
|
2588
|
+
system.scene = scene;
|
|
2589
|
+
const net = fakeNet('pA');
|
|
2590
|
+
const mp = { net, joined: true };
|
|
2591
|
+
scene.multiplayer = { ...scene.multiplayer, net };
|
|
2592
|
+
system.sayHello(scene, mp);
|
|
2593
|
+
// Session A sends this player its own HUD, tune, decor, leaving line,
|
|
2594
|
+
// labels, marks, a held spot, and a choice card.
|
|
2595
|
+
HubState.hub.place = { ballot: true };
|
|
2596
|
+
for (const msg of [
|
|
2597
|
+
{ k: 'hub-hud', hud: { title: 'A only' } },
|
|
2598
|
+
{ k: 'hub-tune', tune: { speed: 2 } },
|
|
2599
|
+
{ k: 'hub-decor', button: 'Decorate', spec: {}, grid: null },
|
|
2600
|
+
{ k: 'hub-leaving', text: 'A leaving' },
|
|
2601
|
+
{ k: 'hub-ballot-card', card: { v: 'a-1', mode: 'talk', faces: [] } },
|
|
2602
|
+
]) {
|
|
2603
|
+
apply(msg);
|
|
2604
|
+
}
|
|
2605
|
+
BallotClient.settle(HubState.hub.place);
|
|
2606
|
+
HubState.hub.labelsMe = { x: 'A label' };
|
|
2607
|
+
HubState.hub.marks = { x: 1 };
|
|
2608
|
+
HubState.hub.held.set?.('pA', true);
|
|
2609
|
+
HubState.hub.held.add?.('pA');
|
|
2610
|
+
assert.equal(HubState.hub.hudMe.title, 'A only');
|
|
2611
|
+
assert.ok(BallotClient.cardFor(net), 'the card is held under A');
|
|
2612
|
+
// The SDK re-acquires: same net, new player id; session B has no private
|
|
2613
|
+
// overrides, and its first packet is an ordinary one.
|
|
2614
|
+
net.id = 'pB';
|
|
2615
|
+
net.inbox.push({ k: 'hub-say-x' });
|
|
2616
|
+
const got = net.drain();
|
|
2617
|
+
assert.equal(got.length, 1, 'the packets still go to the caller');
|
|
2618
|
+
assert.equal(HubState.hub.hudMe, null, 'HUD cleared at the boundary');
|
|
2619
|
+
assert.equal(HubState.hub.tune, null, 'tune cleared');
|
|
2620
|
+
assert.equal(HubState.hub.decor, undefined, 'decor cleared');
|
|
2621
|
+
assert.equal(HubState.hub.leaving, null, 'leaving line cleared');
|
|
2622
|
+
assert.deepEqual(HubState.hub.labelsMe, {});
|
|
2623
|
+
assert.deepEqual(HubState.hub.marks, {});
|
|
2624
|
+
assert.equal(HubState.hub.held.size, 0);
|
|
2625
|
+
assert.equal(HubState.hub.place, null);
|
|
2626
|
+
assert.equal(BallotClient.cardFor(net), null, 'the card goes');
|
|
2627
|
+
assert.equal(system.startNear, null, 'a recovery starts beside nobody');
|
|
2628
|
+
// B's own packets then apply normally, and are not cleared again.
|
|
2629
|
+
apply({ k: 'hub-hud', hud: { title: 'B' } });
|
|
2630
|
+
apply({ k: 'hub-tune', tune: { speed: 0.5 } });
|
|
2631
|
+
system.sayHello(scene, mp);
|
|
2632
|
+
net.drain();
|
|
2633
|
+
system.sayHello(scene, mp);
|
|
2634
|
+
assert.equal(HubState.hub.hudMe.title, 'B');
|
|
2635
|
+
assert.equal(HubState.hub.tune.speed, 0.5);
|
|
2636
|
+
const hellos = net.sent.filter((m) => m.k === 'hub-hello');
|
|
2637
|
+
assert.equal(hellos.length, 2, 'one fresh hello for B');
|
|
2638
|
+
assert.equal(hellos[1].resume, true);
|
|
2639
|
+
// The id seen first by sayHello (before any drain) resets too, once.
|
|
2640
|
+
net.id = 'pC';
|
|
2641
|
+
HubState.hub.hudMe = { title: 'B stale' };
|
|
2642
|
+
system.sayHello(scene, mp);
|
|
2643
|
+
assert.equal(HubState.hub.hudMe, null);
|
|
2644
|
+
apply({ k: 'hub-hud', hud: { title: 'C' } });
|
|
2645
|
+
net.drain();
|
|
2646
|
+
assert.equal(HubState.hub.hudMe.title, 'C', 'not reset twice');
|
|
2647
|
+
assert.equal(net.sent.filter((m) => m.k === 'hub-hello').length, 3);
|
|
2648
|
+
HubState.clear();
|
|
2649
|
+
await flush();
|
|
2650
|
+
});
|
|
2651
|
+
|
|
2652
|
+
await test('a game (a place with result) keeps the old way: no client re-hello after a drop', async () => {
|
|
2653
|
+
const { system, scene } = setup();
|
|
2654
|
+
HubState.hub.place = { result: { score: null } };
|
|
2655
|
+
const net = fakeNet();
|
|
2656
|
+
const mp = { net, joined: true };
|
|
2657
|
+
system.sayHello(scene, mp);
|
|
2658
|
+
net.inbox.push({ k: 'w' });
|
|
2659
|
+
net.drain();
|
|
2660
|
+
system.sayHello(scene, mp);
|
|
2661
|
+
system.sayHello(scene, mp);
|
|
2662
|
+
assert.equal(net.sent.filter((m) => m.k === 'hub-hello').length, 1);
|
|
2663
|
+
HubState.hub.place = null;
|
|
2664
|
+
await flush();
|
|
2665
|
+
});
|
|
2666
|
+
|
|
2667
|
+
await test('a game back under a new player id says one fresh, ordinary hello (a party of one, nothing carried)', async () => {
|
|
2668
|
+
const { system, scene } = setup();
|
|
2669
|
+
system.scene = scene;
|
|
2670
|
+
HubState.hub.place = { result: { score: null } };
|
|
2671
|
+
scene.persistent.hubArriving = { door: 'dash', party: 3, returning: true, near: '42' };
|
|
2672
|
+
scene.persistent.hubResult = { title: 'Race', outcome: 'win' };
|
|
2673
|
+
const net = fakeNet('pA');
|
|
2674
|
+
const mp = { net, joined: true };
|
|
2675
|
+
system.sayHello(scene, mp);
|
|
2676
|
+
// A fresh session: the identity reset clears the place until its WORLD.
|
|
2677
|
+
net.id = 'pB';
|
|
2678
|
+
net.drain();
|
|
2679
|
+
assert.equal(HubState.hub.place, null);
|
|
2680
|
+
system.sayHello(scene, mp);
|
|
2681
|
+
system.sayHello(scene, mp);
|
|
2682
|
+
const hellos = net.sent.filter((m) => m.k === 'hub-hello');
|
|
2683
|
+
assert.equal(hellos.length, 2, 'one fresh hello');
|
|
2684
|
+
assert.equal(hellos[1].resume, undefined, 'not a resume');
|
|
2685
|
+
assert.equal(hellos[1].again, undefined, 'a fresh client');
|
|
2686
|
+
assert.equal(hellos[1].party, 1);
|
|
2687
|
+
assert.equal(hellos[1].carry, null);
|
|
2688
|
+
assert.equal(hellos[1].near, undefined);
|
|
2689
|
+
// The new session's WORLD names the game; a drop after it under the same id
|
|
2690
|
+
// keeps the old way.
|
|
2691
|
+
HubState.hub.place = { result: { score: null } };
|
|
2692
|
+
net.inbox.push({ k: 'w' });
|
|
2693
|
+
net.drain();
|
|
2694
|
+
system.sayHello(scene, mp);
|
|
2695
|
+
assert.equal(net.sent.filter((m) => m.k === 'hub-hello').length, 2);
|
|
2696
|
+
HubState.hub.place = null;
|
|
2697
|
+
delete scene.persistent.hubArriving;
|
|
2698
|
+
delete scene.persistent.hubResult;
|
|
2699
|
+
await flush();
|
|
2700
|
+
});
|
|
2701
|
+
|
|
2702
|
+
await test('packets queued under the old player id are dropped at the identity boundary; the new session\'s private packets before its WORLD apply', async () => {
|
|
2703
|
+
const Rehello = await import('../code/client/rehello.js');
|
|
2704
|
+
const BallotClient = await import('../code/client/ballot.js');
|
|
2705
|
+
const { system, scene } = setup();
|
|
2706
|
+
system.scene = scene;
|
|
2707
|
+
const net = fakeNet('pA');
|
|
2708
|
+
const mp = { net, joined: true };
|
|
2709
|
+
system.sayHello(scene, mp);
|
|
2710
|
+
// As the hook layer applies them (client/hookLayer.js).
|
|
2711
|
+
const apply = (msg) => {
|
|
2712
|
+
if (msg.k === 'hub-hud') HubState.hub.hudMe = msg.hud ?? null;
|
|
2713
|
+
if (msg.k === 'hub-tune') HubState.hub.tune = msg.tune;
|
|
2714
|
+
if (msg.k === 'hub-ballot-card') BallotClient.gate(HubState.hub.place, net, msg.card);
|
|
2715
|
+
};
|
|
2716
|
+
// Each message is tagged as it arrives (the hook layer's `arrive`).
|
|
2717
|
+
const arrive = (msg) => {
|
|
2718
|
+
Rehello.tag(msg, net);
|
|
2719
|
+
net.inbox.push(msg);
|
|
2720
|
+
};
|
|
2721
|
+
// Session A's private packets arrive while the page is hidden (no drain).
|
|
2722
|
+
arrive({ k: 'hub-hud', hud: { title: 'A' } });
|
|
2723
|
+
arrive({ k: 'hub-tune', tune: { speed: 2 } });
|
|
2724
|
+
arrive({ k: 'hub-ballot-card', card: { v: 'a-1', mode: 'talk', faces: [] } });
|
|
2725
|
+
// The SDK re-acquires under B; B's private HUD comes ahead of its WORLD.
|
|
2726
|
+
net.id = 'pB';
|
|
2727
|
+
arrive({ k: 'hub-hud', hud: { title: 'B' } });
|
|
2728
|
+
net.inbox.push({ k: 'w', hubPlace: {} });
|
|
2729
|
+
const got = net.drain();
|
|
2730
|
+
assert.deepEqual(got.map((m) => m.k), ['hub-hud', 'w'], 'A\'s packets dropped, B\'s kept in order');
|
|
2731
|
+
assert.equal(got[0].hud.title, 'B');
|
|
2732
|
+
for (const msg of got) apply(msg);
|
|
2733
|
+
assert.equal(HubState.hub.hudMe.title, 'B', 'B\'s HUD applied');
|
|
2734
|
+
assert.equal(HubState.hub.tune, null, 'A\'s tune not re-applied');
|
|
2735
|
+
assert.equal(BallotClient.cardFor(net), null, 'A\'s card not re-applied');
|
|
2736
|
+
// Untagged messages (arrived before a net, or snapshots) are kept.
|
|
2737
|
+
net.inbox.push({ k: 'hub-hud', hud: { title: 'untagged' } });
|
|
2738
|
+
assert.equal(net.drain().length, 1);
|
|
2739
|
+
HubState.clear();
|
|
2740
|
+
await flush();
|
|
2741
|
+
});
|
|
2742
|
+
|
|
1516
2743
|
console.warn = warn;
|
|
1517
2744
|
console.log = log;
|
|
1518
2745
|
console.log(`hub trips: ${n} tests passed`);
|