castle-web-cli 0.4.232 → 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/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 +329 -11
- 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 +309 -35
- 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/chrome.js +1144 -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 +339 -20
- package/kits/hub-game/code/client/hookLayer.js +299 -13
- 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 +109 -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 +516 -27
- package/kits/hub-game/code/client/toastBand.js +37 -0
- package/kits/hub-game/code/client/together.js +32 -0
- package/kits/hub-game/code/client/visibility.js +43 -0
- package/kits/hub-game/code/client/wear.js +461 -170
- 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 +9 -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/history.js +5 -0
- package/kits/hub-game/code/server/hub.js +1254 -50
- 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 +378 -7
- 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 +2 -2
- package/kits/hub-game/code/server/players.js +22 -0
- 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 +12 -0
- 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 +845 -95
- package/kits/hub-game/docs/content-pack.md +1 -1
- package/kits/hub-game/docs/contract.md +2244 -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 +662 -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-orbit.mjs +918 -0
- package/kits/hub-game/scripts/test-grab.mjs +7 -0
- package/kits/hub-game/scripts/test-hats.mjs +422 -168
- 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 +716 -2
- package/kits/hub-game/scripts/test-hud-clear.mjs +328 -4
- 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 +207 -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-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-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 +477 -2
- package/kits/hub-game/scripts/test-toast-band.mjs +61 -0
- package/kits/hub-game/scripts/test-try-on.mjs +22 -22
- 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 +253 -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 +326 -1
- package/kits/physics-3d/CLAUDE.md +1169 -30
- package/kits/physics-3d/behaviors/Player.jsx +629 -72
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/docs/pxmodel-format.md +8 -0
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +69 -13
- 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 +9 -5
- package/kits/physics-3d/engine3d/orbitinput.js +487 -9
- 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 +796 -69
- package/kits/physics-3d/main.jsx +5 -0
- package/kits/physics-3d/package.json +1 -1
- package/kits/physics-3d/scripts/look-baseline.mjs +155 -0
- package/kits/physics-3d/scripts/test-camera-orbit.mjs +2563 -80
- package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +1 -1
- 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 +8 -1
- package/kits/physics-3d/scripts/test-static-scenery.mjs +2171 -0
- package/kits/physics-3d/scripts/test-steady-hover.mjs +2 -0
- package/kits/physics-3d/scripts/test-view-range.mjs +260 -0
- package/kits/physics-3d/systems/physics3d.js +383 -6
- 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
|
@@ -0,0 +1,753 @@
|
|
|
1
|
+
// Avatars on the wire (contract §11 and §12, v1.51). A place's `hubAv` only
|
|
2
|
+
// ever names one of the first four avatars, so a client from before the
|
|
3
|
+
// twelve after them always has something to draw: a player who wears 4-15 is
|
|
4
|
+
// listed there as `avatar % 4`, and what they really wear is in `hubAv2`,
|
|
5
|
+
// which a v1.51 client prefers and an older one ignores. `hubAv2` is there
|
|
6
|
+
// only while someone wears one: a place where nobody does writes what it
|
|
7
|
+
// wrote before v1.51, byte for byte.
|
|
8
|
+
//
|
|
9
|
+
// The server is the kit's layer on a fake session and the client the kit's
|
|
10
|
+
// real hook layer, as test-try-on.mjs runs them. `story` is a visit in which
|
|
11
|
+
// everyone wears one of the first four; what the place writes in it is held
|
|
12
|
+
// to `BEFORE_V144`, the sha256 of what the kit wrote at the commit before
|
|
13
|
+
// v1.51 (25ce4d8b). `HUB_AV_BASELINE=<dir>` points at another copy of this
|
|
14
|
+
// kit (`git archive <commit> kits/hub-game/code | tar -x -C <dir>`, then the
|
|
15
|
+
// path to `kits/hub-game` in it): the story is run on that copy's server too,
|
|
16
|
+
// compared byte for byte, and its hash printed. `npm run check` runs this
|
|
17
|
+
// without one; it needs nothing installed.
|
|
18
|
+
|
|
19
|
+
import assert from 'node:assert/strict';
|
|
20
|
+
import { createHash } from 'node:crypto';
|
|
21
|
+
import { register } from 'node:module';
|
|
22
|
+
import { pathToFileURL } from 'node:url';
|
|
23
|
+
import path from 'node:path';
|
|
24
|
+
|
|
25
|
+
const sceneStub = 'export const readScene = () => globalThis.__hubTestActors ?? [];';
|
|
26
|
+
const renderer = new URL('../../multiplayer-3d/code/client/avatars.js', import.meta.url).href;
|
|
27
|
+
const avatarsStub = `
|
|
28
|
+
import * as Renderer from ${JSON.stringify(renderer)};
|
|
29
|
+
export * from ${JSON.stringify(renderer)};
|
|
30
|
+
export function dropMissing(avatars, scene, keep) {
|
|
31
|
+
(globalThis.__hubDropped ??= []).push([...keep.keys()].sort().join(","));
|
|
32
|
+
Renderer.dropMissing(avatars, scene, keep);
|
|
33
|
+
}
|
|
34
|
+
`;
|
|
35
|
+
const rendererStubs = {
|
|
36
|
+
'./nameTags.js': '',
|
|
37
|
+
'./poses.js': 'export function applyPose(transform, pose) { [transform.x, transform.y, transform.z] = pose; }',
|
|
38
|
+
'@imports/castle.physics-2d/engine/art.js': 'export const artReady = () => false;',
|
|
39
|
+
'@imports/castle.physics-2d/engine/avatarArt.js': 'export const avatarFacePath = () => null;',
|
|
40
|
+
'@imports/castle.physics-3d/engine3d/materials.js': 'export function makeShapeMesh() { throw new Error("unexpected head drawing"); }',
|
|
41
|
+
};
|
|
42
|
+
register(
|
|
43
|
+
`data:text/javascript,${encodeURIComponent(`
|
|
44
|
+
import { readFile } from 'node:fs/promises';
|
|
45
|
+
import { fileURLToPath } from 'node:url';
|
|
46
|
+
const stubs = {
|
|
47
|
+
'@imports/castle.physics-3d/engine3d/orbitlens.js': ${JSON.stringify(new URL('../../physics-3d/engine3d/orbitlens.js', import.meta.url).href)},
|
|
48
|
+
'@imports/castle.multiplayer-3d/code/server/sceneBodies.js': 'data:text/javascript,${encodeURIComponent(sceneStub)}',
|
|
49
|
+
'@imports/castle.multiplayer-3d/code/client/avatars.js': 'data:text/javascript,${encodeURIComponent(avatarsStub)}',
|
|
50
|
+
'castle-web-sdk': ${JSON.stringify(new URL('./fixtures/sdk-stub.mjs', import.meta.url).href)},
|
|
51
|
+
};
|
|
52
|
+
export async function resolve(specifier, context, next) {
|
|
53
|
+
const rendererStubs = ${JSON.stringify(rendererStubs)};
|
|
54
|
+
if (context.parentURL === ${JSON.stringify(renderer)} && specifier in rendererStubs) {
|
|
55
|
+
return { url: 'data:text/javascript,' + encodeURIComponent(rendererStubs[specifier]), shortCircuit: true };
|
|
56
|
+
}
|
|
57
|
+
if (stubs[specifier]) {
|
|
58
|
+
return { url: stubs[specifier], shortCircuit: true };
|
|
59
|
+
}
|
|
60
|
+
return next(specifier, context);
|
|
61
|
+
}
|
|
62
|
+
// The hook layer reads the deck's castle.json through the bundler.
|
|
63
|
+
export async function load(url, context, next) {
|
|
64
|
+
if (url.endsWith('/code/client/hookLayer.js')) {
|
|
65
|
+
const source = await readFile(fileURLToPath(url), 'utf8');
|
|
66
|
+
return { format: 'module', source: source.replaceAll('import.meta.glob(', '(() => ({}))('), shortCircuit: true };
|
|
67
|
+
}
|
|
68
|
+
return next(url, context);
|
|
69
|
+
}
|
|
70
|
+
`)}`,
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const at = (root, file) => pathToFileURL(path.join(root, file)).href;
|
|
74
|
+
const KIT = path.join(import.meta.dirname, '..');
|
|
75
|
+
const { layer } = await import(at(KIT, 'code/server/hub.js'));
|
|
76
|
+
const hookLayer = (await import(at(KIT, 'code/client/hookLayer.js'))).default;
|
|
77
|
+
const State = await import(at(KIT, 'code/client/state.js'));
|
|
78
|
+
const Avatar = await import(at(KIT, 'code/client/avatar.js'));
|
|
79
|
+
const Avatars = await import('@imports/castle.multiplayer-3d/code/client/avatars.js');
|
|
80
|
+
const baseline = process.env.HUB_AV_BASELINE ? (await import(at(path.resolve(process.env.HUB_AV_BASELINE), 'code/server/hub.js'))).layer : null;
|
|
81
|
+
|
|
82
|
+
// What the kit wrote in `story` at 25ce4d8b, the commit before v1.51.
|
|
83
|
+
const BEFORE_V144 = '2d09e59c8685d74fcb30d924f6176179be3260e946b15fda2a46a79a5dce5201';
|
|
84
|
+
|
|
85
|
+
globalThis.__hubTestActors = [{ id: 'spawn', components: { Player: {}, Transform: { x: 0, y: 1, z: 0 } } }];
|
|
86
|
+
const castleJson = { server: { maxPlayers: 8 }, hub: { contract: 1, title: 'Town' } };
|
|
87
|
+
const sceneExists = () => true;
|
|
88
|
+
const flush = () => new Promise((resolve) => setImmediate(resolve));
|
|
89
|
+
|
|
90
|
+
const ROSTER = [
|
|
91
|
+
{ playerId: 'p1', userId: '101', username: 'ada', isAnonymous: false },
|
|
92
|
+
{ playerId: 'p2', userId: '102', username: 'bo', isAnonymous: false },
|
|
93
|
+
{ playerId: 'p3', userId: '103', username: 'cy', isAnonymous: false },
|
|
94
|
+
{ playerId: 'p4', userId: 'anon-1', username: 'guest', isAnonymous: true },
|
|
95
|
+
];
|
|
96
|
+
|
|
97
|
+
// A place on a fake session, with everything it writes kept in `log` in the
|
|
98
|
+
// order it wrote it: snapshots, deltas and messages to one player. `ghost`
|
|
99
|
+
// is each account's avatar there (user id -> index), `hides(x, y)` the host's
|
|
100
|
+
// block answer; `platform: false` is the dev serve, where the hello stands.
|
|
101
|
+
function room(make, { hides = null, ghost = {}, ghostColors = {}, readWait = null, platform = true, avatarColors } = {}) {
|
|
102
|
+
const log = [];
|
|
103
|
+
const players = [];
|
|
104
|
+
const hub = {
|
|
105
|
+
place: 'main',
|
|
106
|
+
title: 'Town',
|
|
107
|
+
result: null,
|
|
108
|
+
arrival: () => null,
|
|
109
|
+
reportResult: async () => ({ recorded: true }),
|
|
110
|
+
updatePad: async () => ({ status: 'gathering', members: [] }),
|
|
111
|
+
async readResults(input) {
|
|
112
|
+
if (readWait) {
|
|
113
|
+
await readWait();
|
|
114
|
+
}
|
|
115
|
+
const out = {};
|
|
116
|
+
for (const id of input.userIds ?? []) {
|
|
117
|
+
out[id] = { avatar: ghost[id] ?? null, ...(Object.hasOwn(ghostColors, id) ? { avatarColor: ghostColors[id] } : {}), recent: [], records: [], wearable: null };
|
|
118
|
+
}
|
|
119
|
+
return { players: out, boards: {} };
|
|
120
|
+
},
|
|
121
|
+
wear: async (playerId, wearable) => ({ wearable }),
|
|
122
|
+
};
|
|
123
|
+
if (hides) {
|
|
124
|
+
hub.hiddenPair = hides;
|
|
125
|
+
}
|
|
126
|
+
const session = {
|
|
127
|
+
sessionId: 's-1',
|
|
128
|
+
place: null,
|
|
129
|
+
players,
|
|
130
|
+
hub: platform ? hub : null,
|
|
131
|
+
send: (playerId, data) => log.push(['send', playerId, JSON.stringify(data)]),
|
|
132
|
+
broadcast: (data) => log.push(['broadcast', JSON.stringify(data)]),
|
|
133
|
+
};
|
|
134
|
+
const manifest = avatarColors === undefined ? castleJson : { ...castleJson, hub: { ...castleJson.hub, avatarColors } };
|
|
135
|
+
const h = make(manifest, {}, {}, sceneExists);
|
|
136
|
+
h.sceneFor(session);
|
|
137
|
+
const world = { timeMs: 0, players: new Map(), bodies: new Map(), scenePath: 'scenes/main.scene' };
|
|
138
|
+
h.ready(world);
|
|
139
|
+
return {
|
|
140
|
+
log,
|
|
141
|
+
join() {
|
|
142
|
+
const snapshot = h.join();
|
|
143
|
+
log.push(['join', JSON.stringify(snapshot)]);
|
|
144
|
+
return snapshot;
|
|
145
|
+
},
|
|
146
|
+
delta() {
|
|
147
|
+
const delta = h.delta();
|
|
148
|
+
log.push(['delta', JSON.stringify(delta)]);
|
|
149
|
+
return delta;
|
|
150
|
+
},
|
|
151
|
+
// Two ticks with ghost's answer between them, then what everyone is sent.
|
|
152
|
+
async tick() {
|
|
153
|
+
world.timeMs += 50;
|
|
154
|
+
h.place(world);
|
|
155
|
+
await flush();
|
|
156
|
+
world.timeMs += 50;
|
|
157
|
+
h.place(world);
|
|
158
|
+
h.step(world);
|
|
159
|
+
return this.delta();
|
|
160
|
+
},
|
|
161
|
+
enter(playerId, avatar) {
|
|
162
|
+
world.players.set(playerId, { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
|
|
163
|
+
players.push({ ...ROSTER.find((p) => p.playerId === playerId) });
|
|
164
|
+
this.hello(playerId, avatar);
|
|
165
|
+
},
|
|
166
|
+
hello(playerId, avatar, extra = {}) {
|
|
167
|
+
h.message(session, { playerId }, { k: 'hub-hello', avatar, from: null, party: 1, ...extra });
|
|
168
|
+
},
|
|
169
|
+
exit(playerId) {
|
|
170
|
+
world.players.delete(playerId);
|
|
171
|
+
players.splice(players.findIndex((p) => p.playerId === playerId), 1);
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// The last message of a kind to one player, parsed, and every key a log named.
|
|
177
|
+
const sentTo = (log, playerId, k) => log.filter((e) => e[0] === 'send' && e[1] === playerId && JSON.parse(e[2]).k === k).map((e) => JSON.parse(e[2]));
|
|
178
|
+
// A delta with nothing to say is null.
|
|
179
|
+
const says = (delta, key) => Boolean(delta && key in delta);
|
|
180
|
+
const text = (log) => log.map((entry) => entry.join(' ')).join('\n');
|
|
181
|
+
const sha = (log) => createHash('sha256').update(text(log)).digest('hex');
|
|
182
|
+
|
|
183
|
+
// A visit in which nobody wears anything past the first four: people come and
|
|
184
|
+
// go, change avatars (their own picks, ghost's answers over them, a pick over
|
|
185
|
+
// ghost's), a snapshot for each joiner; then the same again with two of them
|
|
186
|
+
// hidden from each other. `beyond` (v1.51 only) has two helloes say an index
|
|
187
|
+
// no kit before v1.51 took, and ghost answer one: all were avatar 0 then.
|
|
188
|
+
async function story(make, { old = false } = {}) {
|
|
189
|
+
const logs = [];
|
|
190
|
+
for (const hides of [null, (x, y) => [x, y].sort().join() === 'p1,p2']) {
|
|
191
|
+
for (const platform of [true, false]) {
|
|
192
|
+
const r = room(make, { hides, platform, ghost: { 101: 3, 102: null, 103: 2 } });
|
|
193
|
+
r.join();
|
|
194
|
+
r.enter('p1', 1);
|
|
195
|
+
await r.tick();
|
|
196
|
+
r.join();
|
|
197
|
+
r.enter('p2', 0);
|
|
198
|
+
r.enter('p4', 2);
|
|
199
|
+
await r.tick();
|
|
200
|
+
r.join();
|
|
201
|
+
r.hello('p2', 3, { again: true });
|
|
202
|
+
await r.tick();
|
|
203
|
+
r.hello('p2', 3, { again: true });
|
|
204
|
+
r.hello('p1', 2, { again: true });
|
|
205
|
+
await r.tick();
|
|
206
|
+
r.enter('p3', 1);
|
|
207
|
+
await r.tick();
|
|
208
|
+
r.join();
|
|
209
|
+
r.hello('p4', 0, { again: true });
|
|
210
|
+
r.hello('p3', 3, { again: true });
|
|
211
|
+
await r.tick();
|
|
212
|
+
// Out of range, as every kit has refused it: avatar 0.
|
|
213
|
+
for (const bad of old ? [-1, 1.5, '2', null] : [-1, 1.5, '2', null, 16, 255]) {
|
|
214
|
+
r.hello('p4', bad, { again: true });
|
|
215
|
+
await r.tick();
|
|
216
|
+
}
|
|
217
|
+
r.exit('p2');
|
|
218
|
+
await r.tick();
|
|
219
|
+
r.join();
|
|
220
|
+
r.exit('p1');
|
|
221
|
+
r.hello('p3', 1, { again: true });
|
|
222
|
+
await r.tick();
|
|
223
|
+
await r.tick();
|
|
224
|
+
logs.push(...r.log);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return logs;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const info = console.log;
|
|
231
|
+
const warn = console.warn;
|
|
232
|
+
console.log = () => {};
|
|
233
|
+
console.warn = () => {};
|
|
234
|
+
let n = 0;
|
|
235
|
+
async function test(name, fn) {
|
|
236
|
+
await fn();
|
|
237
|
+
n += 1;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
await test('nobody past the first four: every byte the place writes is what it wrote before v1.51', async () => {
|
|
241
|
+
const now = await story(layer);
|
|
242
|
+
assert.ok(!text(now).includes('hubAvC'), 'no colours adds no snapshot, delta or message key');
|
|
243
|
+
assert.ok(!text(now).includes('hubAv2'), 'the key is absent from every snapshot, delta and message');
|
|
244
|
+
// The story says something: avatars, their changes, and per-player messages for the hidden pair.
|
|
245
|
+
assert.ok(now.filter((e) => e[0] === 'join').length >= 16 && now.some((e) => e[0] === 'send' && e[2].includes('"hub-av"')));
|
|
246
|
+
assert.ok(now.some((e) => e[0] === 'delta' && e[1] === '{"hubAv":{"p1":3,"p2":3,"p4":2}}'), "ghost's answer and a pick land");
|
|
247
|
+
assert.ok(now.some((e) => e[0] === 'send' && e[2] === '{"k":"hub-av","hubAv":{"p1":2,"p2":3}}'));
|
|
248
|
+
// The same story without the two helloes only v1.51 could tell apart from the rest.
|
|
249
|
+
const same = await story(layer, { old: true });
|
|
250
|
+
assert.deepEqual(text(await story(layer, { old: true })), text(same), 'the story is the same every run');
|
|
251
|
+
if (baseline) {
|
|
252
|
+
const before = await story(baseline, { old: true });
|
|
253
|
+
assert.equal(text(same), text(before), 'this kit and the baseline write the same bytes');
|
|
254
|
+
info(`hub-game avatar wire: the baseline writes ${Buffer.byteLength(text(before))} bytes, sha256 ${sha(before)}`);
|
|
255
|
+
}
|
|
256
|
+
assert.equal(sha(same), BEFORE_V144, 'the place writes other bytes than it did before v1.51');
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
async function colorlessStory(make) {
|
|
260
|
+
const logs = [];
|
|
261
|
+
for (const hides of [null, (x, y) => [x, y].sort().join() === 'p1,p2']) {
|
|
262
|
+
for (const platform of [false, true]) {
|
|
263
|
+
const r = room(make, { hides, platform, ghost: { 101: 15, 102: 9 } });
|
|
264
|
+
r.enter('p1', 15);
|
|
265
|
+
r.enter('p2', 9);
|
|
266
|
+
r.enter('p3', 1);
|
|
267
|
+
for (let avatar = 0; avatar < 16; avatar += 1) {
|
|
268
|
+
r.hello('p1', avatar, { again: true });
|
|
269
|
+
await r.tick();
|
|
270
|
+
r.join();
|
|
271
|
+
}
|
|
272
|
+
r.exit('p1');
|
|
273
|
+
await r.tick();
|
|
274
|
+
r.join();
|
|
275
|
+
r.exit('p2');
|
|
276
|
+
await r.tick();
|
|
277
|
+
r.join();
|
|
278
|
+
logs.push(...r.log);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return logs;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
await test('all sixteen avatars without colours keep the preceding snapshots and deltas byte-for-byte', async () => {
|
|
285
|
+
const now = await colorlessStory(layer);
|
|
286
|
+
assert.ok(!text(now).includes('hubAvC'));
|
|
287
|
+
assert.equal(sha(now), '50541156b37a2f5e6f0fb8d657c4be5e4a4738db31ec169c61dbba3e98d70c43');
|
|
288
|
+
if (baseline) {
|
|
289
|
+
const before = await colorlessStory(baseline);
|
|
290
|
+
assert.equal(text(now), text(before));
|
|
291
|
+
info(`hub-game colourless wire baseline: sha256 ${sha(before)}`);
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
await test('a player on 9: hubAv says 1 and hubAv2 says 9, in the snapshot and in the delta', async () => {
|
|
296
|
+
const r = room(layer, { platform: false });
|
|
297
|
+
r.enter('p1', 2);
|
|
298
|
+
r.enter('p2', 9);
|
|
299
|
+
r.enter('p3', 15);
|
|
300
|
+
r.enter('p4', 4);
|
|
301
|
+
const delta = await r.tick();
|
|
302
|
+
assert.deepEqual(delta.hubAv, { p1: 2, p2: 1, p3: 3, p4: 0 });
|
|
303
|
+
assert.deepEqual(delta.hubAv2, { p2: 9, p3: 15, p4: 4 });
|
|
304
|
+
const snapshot = r.join();
|
|
305
|
+
assert.deepEqual(snapshot.hubAv, { p1: 2, p2: 1, p3: 3, p4: 0 });
|
|
306
|
+
assert.deepEqual(snapshot.hubAv2, { p2: 9, p3: 15, p4: 4 });
|
|
307
|
+
// hubAv never names an avatar a client from before v1.51 cannot draw.
|
|
308
|
+
for (const entry of r.log) {
|
|
309
|
+
const av = JSON.parse(entry.at(-1))?.hubAv;
|
|
310
|
+
assert.ok(Object.values(av ?? {}).every((avatar) => Number.isInteger(avatar) && avatar >= 0 && avatar < 4), entry.join(' '));
|
|
311
|
+
}
|
|
312
|
+
// Nothing changes: nothing more is said.
|
|
313
|
+
const quiet = await r.tick();
|
|
314
|
+
assert.equal(says(quiet, 'hubAv') || says(quiet, 'hubAv2'), false);
|
|
315
|
+
// 9 -> 13: the stand-in is the same 1, and only hubAv2 says so.
|
|
316
|
+
r.hello('p2', 13, { again: true });
|
|
317
|
+
const moved = await r.tick();
|
|
318
|
+
assert.equal(says(moved, 'hubAv'), false);
|
|
319
|
+
assert.deepEqual(moved.hubAv2, { p2: 13, p3: 15, p4: 4 });
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
await test('ghost says 9 over a hello of 2: the same two blocks', async () => {
|
|
323
|
+
const r = room(layer, { ghost: { 101: 9 } });
|
|
324
|
+
r.enter('p1', 2);
|
|
325
|
+
const delta = await r.tick();
|
|
326
|
+
assert.deepEqual([delta.hubAv, delta.hubAv2], [{ p1: 1 }, { p1: 9 }]);
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
await test('back to one of the first four: hubAv2 loses the key, and the last one out sends it empty once, then never', async () => {
|
|
330
|
+
const r = room(layer, { platform: false });
|
|
331
|
+
r.enter('p1', 9);
|
|
332
|
+
r.enter('p2', 12);
|
|
333
|
+
assert.deepEqual((await r.tick()).hubAv2, { p1: 9, p2: 12 });
|
|
334
|
+
r.hello('p1', 2, { again: true });
|
|
335
|
+
const one = await r.tick();
|
|
336
|
+
assert.deepEqual([one.hubAv, one.hubAv2], [{ p1: 2, p2: 0 }, { p2: 12 }]);
|
|
337
|
+
assert.deepEqual(r.join().hubAv2, { p2: 12 });
|
|
338
|
+
// The last of them changes back: the delta carries the block, empty, so a
|
|
339
|
+
// client that had it hears that it is gone; a snapshot has no key at all.
|
|
340
|
+
r.hello('p2', 3, { again: true });
|
|
341
|
+
const none = await r.tick();
|
|
342
|
+
assert.deepEqual(none.hubAv, { p1: 2, p2: 3 });
|
|
343
|
+
assert.deepEqual(none.hubAv2, {});
|
|
344
|
+
assert.equal(JSON.stringify(none).includes('"hubAv2":{}'), true);
|
|
345
|
+
assert.equal('hubAv2' in r.join(), false);
|
|
346
|
+
for (let k = 0; k < 3; k += 1) {
|
|
347
|
+
assert.equal(says(await r.tick(), 'hubAv2'), false, 'said once');
|
|
348
|
+
}
|
|
349
|
+
// And a player who leaves takes theirs with them, the same way.
|
|
350
|
+
r.hello('p1', 7, { again: true });
|
|
351
|
+
assert.deepEqual((await r.tick()).hubAv2, { p1: 7 });
|
|
352
|
+
r.exit('p1');
|
|
353
|
+
const left = await r.tick();
|
|
354
|
+
assert.deepEqual([left.hubAv, left.hubAv2], [{ p2: 3 }, {}]);
|
|
355
|
+
assert.equal('hubAv2' in r.join(), false);
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
await test('a hidden pair: neither block names them to everyone, and each who may see them is told both alone', async () => {
|
|
359
|
+
const hides = (x, y) => [x, y].sort().join() === 'p1,p2';
|
|
360
|
+
const r = room(layer, { hides, platform: true, ghost: {} });
|
|
361
|
+
r.enter('p1', 9);
|
|
362
|
+
r.enter('p2', 2);
|
|
363
|
+
r.enter('p3', 6);
|
|
364
|
+
const delta = await r.tick();
|
|
365
|
+
// Everyone's blocks leave the pair out; p3 is in both.
|
|
366
|
+
assert.deepEqual([delta.hubAv, delta.hubAv2], [{ p3: 2 }, { p3: 6 }]);
|
|
367
|
+
assert.deepEqual([r.join().hubAv, r.join().hubAv2], [{ p3: 2 }, { p3: 6 }]);
|
|
368
|
+
// p3 may see both: the stand-ins, and the real one beside them.
|
|
369
|
+
assert.deepEqual(sentTo(r.log, 'p3', 'hub-av').at(-1), { k: 'hub-av', hubAv: { p1: 1, p2: 2 }, hubAv2: { p1: 9 } });
|
|
370
|
+
// Each of the pair is told of themself, never of the other.
|
|
371
|
+
assert.deepEqual(sentTo(r.log, 'p1', 'hub-av').at(-1), { k: 'hub-av', hubAv: { p1: 1 }, hubAv2: { p1: 9 } });
|
|
372
|
+
assert.deepEqual(sentTo(r.log, 'p2', 'hub-av').at(-1), { k: 'hub-av', hubAv: { p2: 2 } });
|
|
373
|
+
for (const viewer of ['p1', 'p2', 'p3']) {
|
|
374
|
+
for (const id of Object.keys(sentTo(r.log, viewer, 'hub-av').at(-1).hubAv)) {
|
|
375
|
+
assert.equal(id in delta.hubAv, false, 'per-viewer players are omitted from shared hubAv');
|
|
376
|
+
assert.equal(id in delta.hubAv2, false, 'and from shared hubAv2');
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
for (const entry of r.log.filter((e) => e[0] === 'send' && e[1] === 'p2')) {
|
|
380
|
+
assert.ok(!entry[2].includes('p1'), 'p2 is never told of p1');
|
|
381
|
+
}
|
|
382
|
+
// 9 -> 5: the stand-in is still 1; the message goes again because hubAv2 changed.
|
|
383
|
+
const before = sentTo(r.log, 'p3', 'hub-av').length;
|
|
384
|
+
r.hello('p1', 5, { again: true });
|
|
385
|
+
await r.tick();
|
|
386
|
+
assert.equal(sentTo(r.log, 'p3', 'hub-av').length, before + 1);
|
|
387
|
+
assert.deepEqual(sentTo(r.log, 'p3', 'hub-av').at(-1), { k: 'hub-av', hubAv: { p1: 1, p2: 2 }, hubAv2: { p1: 5 } });
|
|
388
|
+
// Back to 1: the same stand-in, and the message goes once more, now without the key.
|
|
389
|
+
r.hello('p1', 1, { again: true });
|
|
390
|
+
await r.tick();
|
|
391
|
+
assert.equal(sentTo(r.log, 'p3', 'hub-av').length, before + 2);
|
|
392
|
+
assert.deepEqual(sentTo(r.log, 'p3', 'hub-av').at(-1), { k: 'hub-av', hubAv: { p1: 1, p2: 2 } });
|
|
393
|
+
assert.deepEqual(sentTo(r.log, 'p1', 'hub-av').at(-1), { k: 'hub-av', hubAv: { p1: 1 } });
|
|
394
|
+
await r.tick();
|
|
395
|
+
assert.equal(sentTo(r.log, 'p3', 'hub-av').length, before + 2, 'and not again');
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
await test('hello colours are ignored without hub ops or opt-in, with identical wire bytes for absent and false', async () => {
|
|
399
|
+
const logs = [];
|
|
400
|
+
for (const avatarColors of [undefined, false]) {
|
|
401
|
+
const r = room(layer, { avatarColors, platform: false });
|
|
402
|
+
r.enter('p1', 9);
|
|
403
|
+
await r.tick();
|
|
404
|
+
r.hello('p1', 9, { again: true, color: 3 });
|
|
405
|
+
assert.equal(says(await r.tick(), 'hubAvC'), false);
|
|
406
|
+
assert.equal('hubAvC' in r.join(), false);
|
|
407
|
+
assert.ok(r.log.every((entry) => !entry.at(-1).includes('hubAvC')));
|
|
408
|
+
logs.push(r.log);
|
|
409
|
+
}
|
|
410
|
+
assert.deepEqual(logs[0], logs[1], 'stand-in wire is identical for absent and false');
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
await test('hub ops propagate re-hello colours live without opt-in and clear missing colours', async () => {
|
|
414
|
+
for (const avatarColors of [undefined, false]) {
|
|
415
|
+
const r = room(layer, { avatarColors, ghost: { 101: 9, 102: 2 } });
|
|
416
|
+
r.enter('p1', 9);
|
|
417
|
+
r.enter('p2', 2);
|
|
418
|
+
await r.tick();
|
|
419
|
+
assert.equal('hubAvC' in r.join(), false);
|
|
420
|
+
r.hello('p1', 9, { again: true, color: 3 });
|
|
421
|
+
assert.deepEqual((await r.tick()).hubAvC, { p1: 3 }, 'other players receive the colour immediately');
|
|
422
|
+
assert.deepEqual(r.join().hubAvC, { p1: 3 });
|
|
423
|
+
assert.equal(says(await r.tick(), 'hubAvC'), false);
|
|
424
|
+
r.hello('p1', 9, { again: true });
|
|
425
|
+
assert.deepEqual((await r.tick()).hubAvC, {}, 'omitting colour clears the live block');
|
|
426
|
+
assert.equal('hubAvC' in r.join(), false);
|
|
427
|
+
assert.equal(says(await r.tick(), 'hubAvC'), false);
|
|
428
|
+
}
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
await test('colours latch only while used and clear once; character changes clear missing colours', async () => {
|
|
432
|
+
const r = room(layer, { platform: false, avatarColors: true });
|
|
433
|
+
r.enter('p1', 9);
|
|
434
|
+
await r.tick();
|
|
435
|
+
assert.equal('hubAvC' in r.join(), false);
|
|
436
|
+
r.hello('p1', 9, { again: true, color: 2 });
|
|
437
|
+
assert.deepEqual((await r.tick()).hubAvC, { p1: 2 });
|
|
438
|
+
assert.deepEqual(r.join().hubAvC, { p1: 2 });
|
|
439
|
+
assert.equal(says(await r.tick(), 'hubAvC'), false);
|
|
440
|
+
r.hello('p1', 10, { again: true });
|
|
441
|
+
assert.deepEqual((await r.tick()).hubAvC, {});
|
|
442
|
+
assert.equal('hubAvC' in r.join(), false);
|
|
443
|
+
assert.equal(says(await r.tick(), 'hubAvC'), false);
|
|
444
|
+
for (const color of [-1, 16, 1.5, '2', null]) {
|
|
445
|
+
r.hello('p1', 10, { again: true, color });
|
|
446
|
+
assert.equal(says(await r.tick(), 'hubAvC'), false);
|
|
447
|
+
}
|
|
448
|
+
r.hello('p1', 10, { again: true, color: 15 });
|
|
449
|
+
assert.deepEqual((await r.tick()).hubAvC, { p1: 15 }, 'later kit colours survive wire validation');
|
|
450
|
+
r.exit('p1');
|
|
451
|
+
assert.deepEqual((await r.tick()).hubAvC, {});
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
await test('ghost colour is accepted regardless of opt-in and wins over hello; absent/invalid ghost colour is zero', async () => {
|
|
455
|
+
for (const avatarColors of [undefined, false, true]) {
|
|
456
|
+
for (const color of [undefined, -1, 16, 1.5, '2', 0, 3]) {
|
|
457
|
+
const r = room(layer, { ghost: { 101: 9 }, ghostColors: { 101: color }, avatarColors });
|
|
458
|
+
r.enter('p1', 2);
|
|
459
|
+
r.hello('p1', 2, { again: true, color: 5 });
|
|
460
|
+
const delta = await r.tick();
|
|
461
|
+
assert.deepEqual(delta.hubAv2, { p1: 9 });
|
|
462
|
+
assert.deepEqual(delta.hubAvC, color === 3 ? { p1: 3 } : undefined);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
await test('a late ghost answer cannot put a queued colour onto another character', async () => {
|
|
468
|
+
for (const avatar of [2, 9]) {
|
|
469
|
+
let release;
|
|
470
|
+
const waiting = new Promise((resolve) => { release = resolve; });
|
|
471
|
+
const r = room(layer, { ghost: { 101: avatar }, readWait: () => waiting, avatarColors: true });
|
|
472
|
+
r.enter('p1', 2);
|
|
473
|
+
await r.tick();
|
|
474
|
+
r.hello('p1', 2, { again: true, color: 4 });
|
|
475
|
+
assert.deepEqual((await r.tick()).hubAvC, { p1: 4 });
|
|
476
|
+
release();
|
|
477
|
+
await flush();
|
|
478
|
+
await r.tick();
|
|
479
|
+
assert.deepEqual(r.join().hubAvC, avatar === 2 ? { p1: 4 } : undefined);
|
|
480
|
+
assert.deepEqual(r.join().hubAv2, avatar === 9 ? { p1: 9 } : undefined);
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
await test('colours in blocked pairs use private whole blocks and clear on a colour-only change', async () => {
|
|
485
|
+
const r = room(layer, { hides: (x, y) => [x, y].sort().join() === 'p1,p2', ghost: { 101: 9, 102: 2, 103: 6 }, ghostColors: { 101: 3, 102: 4, 103: 2 }, avatarColors: true });
|
|
486
|
+
r.enter('p1', 9);
|
|
487
|
+
r.enter('p2', 2);
|
|
488
|
+
r.enter('p3', 6);
|
|
489
|
+
const delta = await r.tick();
|
|
490
|
+
assert.deepEqual(delta.hubAvC, { p3: 2 });
|
|
491
|
+
assert.deepEqual(r.join().hubAvC, { p3: 2 });
|
|
492
|
+
assert.deepEqual(sentTo(r.log, 'p1', 'hub-av').at(-1).hubAvC, { p1: 3 });
|
|
493
|
+
assert.deepEqual(sentTo(r.log, 'p2', 'hub-av').at(-1).hubAvC, { p2: 4 });
|
|
494
|
+
assert.deepEqual(sentTo(r.log, 'p3', 'hub-av').at(-1).hubAvC, { p1: 3, p2: 4 });
|
|
495
|
+
r.hello('p1', 9, { again: true, color: 1 });
|
|
496
|
+
await r.tick();
|
|
497
|
+
assert.deepEqual(sentTo(r.log, 'p3', 'hub-av').at(-1).hubAvC, { p1: 1, p2: 4 });
|
|
498
|
+
r.hello('p1', 9, { again: true });
|
|
499
|
+
await r.tick();
|
|
500
|
+
assert.equal('hubAvC' in sentTo(r.log, 'p1', 'hub-av').at(-1), false);
|
|
501
|
+
for (const entry of r.log.filter((e) => e[0] === 'send' && e[1] === 'p2')) {
|
|
502
|
+
assert.ok(!entry[2].includes('p1'));
|
|
503
|
+
}
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
// --- the client ---
|
|
507
|
+
|
|
508
|
+
// A client: the kit's hook layer fed a server's log as `viewer` gets it. A
|
|
509
|
+
// client from before v1.51 is the same log with what it never read left out.
|
|
510
|
+
function client(viewer, { old = false } = {}) {
|
|
511
|
+
State.clear();
|
|
512
|
+
const scene = { files: null };
|
|
513
|
+
const system = { net: { others: () => new Map(ROSTER.map((p) => [p.playerId, p.username])) }, avatars: Avatars.makeAvatars() };
|
|
514
|
+
let fed = 0;
|
|
515
|
+
return {
|
|
516
|
+
feed(log) {
|
|
517
|
+
for (const entry of log.slice(fed)) {
|
|
518
|
+
if (entry[0] === 'join' || entry[0] === 'delta') {
|
|
519
|
+
const msg = JSON.parse(entry[1]);
|
|
520
|
+
if (!msg) {
|
|
521
|
+
continue;
|
|
522
|
+
}
|
|
523
|
+
if (old) {
|
|
524
|
+
delete msg.hubAv2;
|
|
525
|
+
}
|
|
526
|
+
hookLayer.state(scene, msg, system);
|
|
527
|
+
} else if (entry[0] === 'send' && entry[1] === viewer) {
|
|
528
|
+
const msg = JSON.parse(entry[2]);
|
|
529
|
+
if (old) {
|
|
530
|
+
delete msg.hubAv2;
|
|
531
|
+
}
|
|
532
|
+
hookLayer.message(scene, msg);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
fed = log.length;
|
|
536
|
+
return Object.fromEntries(State.hub.avatars);
|
|
537
|
+
},
|
|
538
|
+
// What `hookLayer.avatar` draws for a player, as a blueprint path's avatar index.
|
|
539
|
+
draws(playerId, files) {
|
|
540
|
+
scene.files = files;
|
|
541
|
+
hookLayer.state(scene, {}, system);
|
|
542
|
+
const look = hookLayer.avatar(playerId, 'x');
|
|
543
|
+
return look ? Number(/avatar-(\d+)\.scene$/.exec(look.blueprint)[1]) : null;
|
|
544
|
+
},
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
const filesFor = (count) => Object.fromEntries(Array.from({ length: count }, (_, i) => [`imports/castle.hub-game/blueprints/avatar-${i}.scene`, '{}']));
|
|
549
|
+
|
|
550
|
+
await test('a v1.51 client draws what hubAv2 says; a client from before it draws the stand-in, never nobody', async () => {
|
|
551
|
+
const r = room(layer, { platform: false });
|
|
552
|
+
r.join();
|
|
553
|
+
r.enter('p1', 2);
|
|
554
|
+
r.enter('p2', 9);
|
|
555
|
+
await r.tick();
|
|
556
|
+
const now = client('p3');
|
|
557
|
+
assert.deepEqual(now.feed(r.log), { p1: 2, p2: 9 });
|
|
558
|
+
assert.equal(now.draws('p2', filesFor(16)), 9);
|
|
559
|
+
assert.equal(now.draws('p1', filesFor(16)), 2);
|
|
560
|
+
// A client from before v1.51 (what it reads of the same bytes, and the four
|
|
561
|
+
// blueprints it has): the stand-in, drawn.
|
|
562
|
+
const then = client('p3', { old: true });
|
|
563
|
+
assert.deepEqual(then.feed(r.log), { p1: 2, p2: 1 });
|
|
564
|
+
assert.equal(then.draws('p2', filesFor(4)), 1);
|
|
565
|
+
// 9 -> 13, the same stand-in: the v1.51 client still hears it and redraws that player alone.
|
|
566
|
+
const again = client('p3');
|
|
567
|
+
again.feed(r.log);
|
|
568
|
+
globalThis.__hubDropped = [];
|
|
569
|
+
r.hello('p2', 13, { again: true });
|
|
570
|
+
await r.tick();
|
|
571
|
+
assert.deepEqual(again.feed(r.log), { p1: 2, p2: 13 });
|
|
572
|
+
assert.deepEqual(globalThis.__hubDropped, ['p1,p3,p4'], 'p2 is dropped to respawn as 13');
|
|
573
|
+
// Back to 3: the block comes empty, and the client is back on hubAv.
|
|
574
|
+
globalThis.__hubDropped = [];
|
|
575
|
+
r.hello('p2', 3, { again: true });
|
|
576
|
+
const gone = await r.tick();
|
|
577
|
+
assert.deepEqual(gone.hubAv2, {});
|
|
578
|
+
assert.deepEqual(again.feed(r.log), { p1: 2, p2: 3 });
|
|
579
|
+
assert.equal(State.hub.avatars2All.size, 0);
|
|
580
|
+
assert.deepEqual(globalThis.__hubDropped, ['p1,p3,p4']);
|
|
581
|
+
// A late joiner's snapshot has no key: nobody is drawn from a block that is gone.
|
|
582
|
+
const late = client('p4');
|
|
583
|
+
r.join();
|
|
584
|
+
assert.deepEqual(late.feed(r.log.slice(-1)), { p1: 2, p2: 3 });
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
await test('a snapshot without hubAv2 clears what a client had; a hidden player the same by their own message', async () => {
|
|
588
|
+
// Another session's snapshot (a door trip keeps the page): the old block must not outlive it.
|
|
589
|
+
const c = client('p3');
|
|
590
|
+
hookLayer.state({ files: null }, { hubPlace: { id: 'main' }, hubAv: { p1: 1 }, hubAv2: { p1: 9 } }, null);
|
|
591
|
+
assert.deepEqual(Object.fromEntries(State.hub.avatars), { p1: 9 });
|
|
592
|
+
hookLayer.state({ files: null }, { hubPlace: { id: 'main' }, hubAv: { p1: 1 } }, null);
|
|
593
|
+
assert.deepEqual(Object.fromEntries(State.hub.avatars), { p1: 1 });
|
|
594
|
+
// A delta that says nothing of it leaves it alone.
|
|
595
|
+
hookLayer.state({ files: null }, { hubAv2: { p1: 9 } }, null);
|
|
596
|
+
hookLayer.state({ files: null }, { hud: null }, null);
|
|
597
|
+
assert.deepEqual(Object.fromEntries(State.hub.avatars), { p1: 9 });
|
|
598
|
+
// The pair's own message is whole each time.
|
|
599
|
+
const hides = (x, y) => [x, y].sort().join() === 'p1,p2';
|
|
600
|
+
const r = room(layer, { hides });
|
|
601
|
+
r.enter('p1', 9);
|
|
602
|
+
r.enter('p2', 2);
|
|
603
|
+
r.enter('p3', 6);
|
|
604
|
+
await r.tick();
|
|
605
|
+
const third = client('p3');
|
|
606
|
+
assert.deepEqual(third.feed(r.log), { p3: 6, p1: 9, p2: 2 });
|
|
607
|
+
assert.deepEqual(client('p2').feed(r.log), { p3: 6, p2: 2 });
|
|
608
|
+
assert.deepEqual(client('p3', { old: true }).feed(r.log), { p3: 2, p1: 1, p2: 2 });
|
|
609
|
+
r.hello('p1', 1, { again: true });
|
|
610
|
+
await r.tick();
|
|
611
|
+
const after = client('p3');
|
|
612
|
+
assert.deepEqual(after.feed(r.log), { p3: 6, p1: 1, p2: 2 });
|
|
613
|
+
assert.equal(State.hub.avatars2Me.size, 0);
|
|
614
|
+
void c;
|
|
615
|
+
});
|
|
616
|
+
|
|
617
|
+
await test('a fading player respawns only for a change involving a later avatar; 0 to 1 keeps the legacy fade', () => {
|
|
618
|
+
for (const [before, index, respawns] of [[0, 1, false], [9, 9, false], [9, 13, true], [1, 9, true], [9, 1, true]]) {
|
|
619
|
+
client('p3');
|
|
620
|
+
const actors = new Map();
|
|
621
|
+
const nodes = new Map();
|
|
622
|
+
let spawned = 0;
|
|
623
|
+
const scene = {
|
|
624
|
+
files: filesFor(16),
|
|
625
|
+
three: { nodes },
|
|
626
|
+
getActor: (id) => actors.get(id),
|
|
627
|
+
despawnActor(id) {
|
|
628
|
+
actors.delete(id);
|
|
629
|
+
nodes.delete(id);
|
|
630
|
+
},
|
|
631
|
+
spawnFromBlueprint(blueprint, options) {
|
|
632
|
+
const actor = { id: `avatar-${++spawned}`, blueprint, components: options.components };
|
|
633
|
+
actors.set(actor.id, actor);
|
|
634
|
+
nodes.set(actor.id, { node: { scale: { value: 1, setScalar(value) { this.value = value; } }, userData: {} } });
|
|
635
|
+
return actor;
|
|
636
|
+
},
|
|
637
|
+
};
|
|
638
|
+
const system = { net: { others: () => new Map([['p1', 'ada']]) }, avatars: Avatars.makeAvatars() };
|
|
639
|
+
const draw = () => Avatars.showPlayer(system.avatars, scene, 'p1', null, [0, 0, 0, 0], hookLayer.avatar('p1', 'ada'));
|
|
640
|
+
hookLayer.state(scene, { hubPlace: { id: 'main' }, hubAv: { p1: before % Avatar.DEFAULT_AVATARS }, ...(before >= Avatar.DEFAULT_AVATARS ? { hubAv2: { p1: before } } : {}) }, system);
|
|
641
|
+
const original = draw();
|
|
642
|
+
Avatars.retire(system.avatars, scene, 'p1');
|
|
643
|
+
hookLayer.state(scene, { out: ['p1'] }, system);
|
|
644
|
+
Avatars.animate(system.avatars, scene, 0.1);
|
|
645
|
+
const grown = system.avatars.leaving.get('p1').grown;
|
|
646
|
+
const node = nodes.get(original.id).node;
|
|
647
|
+
const scale = node.scale.value;
|
|
648
|
+
hookLayer.state(scene, {
|
|
649
|
+
...(before % Avatar.DEFAULT_AVATARS !== index % Avatar.DEFAULT_AVATARS ? { hubAv: { p1: index % Avatar.DEFAULT_AVATARS } } : {}),
|
|
650
|
+
...(before >= Avatar.DEFAULT_AVATARS || index >= Avatar.DEFAULT_AVATARS ? { hubAv2: index >= Avatar.DEFAULT_AVATARS ? { p1: index } : {} } : {}),
|
|
651
|
+
}, system);
|
|
652
|
+
Avatars.enter(system.avatars, 'p1');
|
|
653
|
+
hookLayer.state(scene, { in: ['p1'] }, system);
|
|
654
|
+
const returned = draw();
|
|
655
|
+
assert.equal(returned.blueprint, `imports/castle.hub-game/blueprints/avatar-${respawns ? index : before}.scene`);
|
|
656
|
+
if (!respawns) {
|
|
657
|
+
// bc1c178e: even a 0-3 change restores the original actor and fade.
|
|
658
|
+
assert.equal(returned, original, 'the original actor reverses the same fade');
|
|
659
|
+
assert.equal(system.avatars.entering.get('p1'), grown);
|
|
660
|
+
assert.equal(nodes.get(returned.id).node, node);
|
|
661
|
+
assert.equal(node.scale.value, scale);
|
|
662
|
+
assert.equal(system.avatars.retired.size, 0);
|
|
663
|
+
assert.equal(spawned, 1);
|
|
664
|
+
Avatars.animate(system.avatars, scene, 0.05);
|
|
665
|
+
const next = grown + 0.05 / 0.35;
|
|
666
|
+
assert.equal(system.avatars.entering.get('p1'), next);
|
|
667
|
+
assert.equal(node.scale.value, next * next * (3 - 2 * next));
|
|
668
|
+
} else {
|
|
669
|
+
assert.notEqual(returned.id, original.id, 'a changed avatar respawns');
|
|
670
|
+
assert.equal(actors.has(original.id), false);
|
|
671
|
+
assert.equal(system.avatars.retired.has(original.id), true);
|
|
672
|
+
assert.equal(system.avatars.entering.get('p1'), 0);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
});
|
|
676
|
+
|
|
677
|
+
await test('a fresh shared snapshot overrides stale hubAv2Me, but keeps a hidden player told before WORLD', () => {
|
|
678
|
+
const c = client('p3');
|
|
679
|
+
const scene = { files: filesFor(16) };
|
|
680
|
+
hookLayer.state(scene, { k: 'w', hubPlace: { id: 'main' }, hubAv: {} }, null);
|
|
681
|
+
hookLayer.message(scene, { k: 'hub-av', hubAv: { p1: 1 }, hubAv2: { p1: 9 } });
|
|
682
|
+
assert.equal(c.draws('p1', scene.files), 9);
|
|
683
|
+
// Automatic transport recovery: no State.clear and no empty hub-av resent.
|
|
684
|
+
hookLayer.state(scene, { k: 'w', hubPlace: { id: 'main' }, hubAv: { p1: 1 } }, null);
|
|
685
|
+
assert.equal(State.hub.avatars.get('p1'), 1);
|
|
686
|
+
assert.equal(c.draws('p1', scene.files), 1);
|
|
687
|
+
hookLayer.state(scene, { k: 'w', hubPlace: { id: 'main' }, hubAv: { p1: 1 }, hubAv2: { p1: 13 } }, null);
|
|
688
|
+
assert.equal(c.draws('p1', scene.files), 13, 'the shared real index also wins');
|
|
689
|
+
hookLayer.message(scene, { k: 'hub-av', hubAv: { p1: 1 }, hubAv2: { p1: 9 } });
|
|
690
|
+
hookLayer.state(scene, { k: 'w', hubPlace: { id: 'main' }, hubAv: { p3: 2 } }, null);
|
|
691
|
+
assert.equal(c.draws('p1', scene.files), 9, 'a pre-WORLD override survives the formerly shared block');
|
|
692
|
+
// A legitimate override before WORLD: shared blocks omit a hidden pair.
|
|
693
|
+
State.clear();
|
|
694
|
+
hookLayer.message(scene, { k: 'hub-av', hubAv: { p1: 1 }, hubAv2: { p1: 9 } });
|
|
695
|
+
hookLayer.state(scene, { k: 'w', hubPlace: { id: 'main' }, hubAv: { p3: 2 } }, null);
|
|
696
|
+
assert.equal(c.draws('p1', scene.files), 9);
|
|
697
|
+
hookLayer.state(scene, { k: 'w', hubPlace: { id: 'main' }, hubAv: { p3: 2 } }, null);
|
|
698
|
+
assert.equal(c.draws('p1', scene.files), 9, 'residual staleness for an omitted player is unchanged');
|
|
699
|
+
// Legacy hubAv staleness remains, including its draw in a 0-3 room.
|
|
700
|
+
State.clear();
|
|
701
|
+
hookLayer.message(scene, { k: 'hub-av', hubAv: { p1: 3 } });
|
|
702
|
+
hookLayer.state(scene, { k: 'w', hubPlace: { id: 'main' }, hubAv: { p1: 1 } }, null);
|
|
703
|
+
assert.equal(c.draws('p1', scene.files), 3);
|
|
704
|
+
});
|
|
705
|
+
|
|
706
|
+
await test('hubAv2 is only ever a better word for a player hubAv lists: nothing else in it is drawn', () => {
|
|
707
|
+
client('p3');
|
|
708
|
+
const scene = { files: null };
|
|
709
|
+
hookLayer.state(scene, { hubPlace: { id: 'main' }, hubAv: { p1: 1, p2: 2, p4: 0 }, hubAv2: { p1: 9, p2: '9', p4: -3, ghost: 5, p5: 9.5 } }, null);
|
|
710
|
+
assert.deepEqual(Object.fromEntries(State.hub.avatars), { p1: 9, p2: 2, p4: 0 });
|
|
711
|
+
// Not an object at all: as if it were not there.
|
|
712
|
+
for (const bad of [7, 'x', true, null]) {
|
|
713
|
+
hookLayer.state(scene, { hubPlace: { id: 'main' }, hubAv: { p1: 1 }, hubAv2: bad }, null);
|
|
714
|
+
assert.deepEqual(Object.fromEntries(State.hub.avatars), { p1: 1 }, String(bad));
|
|
715
|
+
}
|
|
716
|
+
// An avatar of a later kit (16 or more): the stand-in both blocks agree on.
|
|
717
|
+
hookLayer.state(scene, { hubPlace: { id: 'main' }, hubAv: { p1: 1 }, hubAv2: { p1: 21 } }, null);
|
|
718
|
+
assert.equal(State.hub.avatars.get('p1'), 21);
|
|
719
|
+
assert.equal(Avatar.known(21), 1);
|
|
720
|
+
scene.files = filesFor(16);
|
|
721
|
+
hookLayer.state(scene, {}, null);
|
|
722
|
+
assert.equal(hookLayer.avatar('p1', 'x').blueprint, 'imports/castle.hub-game/blueprints/avatar-1.scene');
|
|
723
|
+
});
|
|
724
|
+
|
|
725
|
+
await test('client colour-only changes redraw, whole snapshots clear, and shared colours override stale private ones', () => {
|
|
726
|
+
client('p3');
|
|
727
|
+
const scene = { files: null };
|
|
728
|
+
const system = { net: { others: () => new Map([['p1', 'ada'], ['p2', 'bo']]) }, avatars: Avatars.makeAvatars() };
|
|
729
|
+
hookLayer.state(scene, { hubPlace: { id: 'main' }, hubAv: { p1: 1, p2: 2 } }, system);
|
|
730
|
+
globalThis.__hubDropped = [];
|
|
731
|
+
hookLayer.state(scene, { hubAvC: { p1: 2, p2: '3', ghost: 1 } }, system);
|
|
732
|
+
assert.deepEqual(Object.fromEntries(State.hub.avatarColors), { p1: 2 });
|
|
733
|
+
assert.deepEqual(globalThis.__hubDropped, ['p2']);
|
|
734
|
+
hookLayer.message(scene, { k: 'hub-av', hubAv: { p1: 1 }, hubAvC: { p1: 4 } });
|
|
735
|
+
assert.equal(State.hub.avatarColors.get('p1'), 2, 'shared player wins');
|
|
736
|
+
hookLayer.state(scene, { k: 'w', hubPlace: { id: 'main' }, hubAv: { p1: 1, p2: 2 } }, system);
|
|
737
|
+
assert.equal(State.hub.avatarColors.size, 0);
|
|
738
|
+
hookLayer.state(scene, { hubAvC: { p1: 3 } }, system);
|
|
739
|
+
hookLayer.state(scene, { hud: null }, system);
|
|
740
|
+
assert.equal(State.hub.avatarColors.get('p1'), 3, 'unrelated delta keeps the block');
|
|
741
|
+
hookLayer.state(scene, { hubAvC: {} }, system);
|
|
742
|
+
assert.equal(State.hub.avatarColors.size, 0);
|
|
743
|
+
State.clear();
|
|
744
|
+
hookLayer.message(scene, { k: 'hub-av', hubAv: { p1: 1 }, hubAvC: { p1: 4 } });
|
|
745
|
+
hookLayer.state(scene, { k: 'w', hubPlace: { id: 'main' }, hubAv: { p2: 2 } }, system);
|
|
746
|
+
assert.equal(State.hub.avatarColors.get('p1'), 4, 'pre-WORLD private colour survives for an omitted player');
|
|
747
|
+
hookLayer.message(scene, { k: 'hub-av', hubAv: { p1: 1 } });
|
|
748
|
+
assert.equal(State.hub.avatarColors.size, 0, 'private whole block clears on omission');
|
|
749
|
+
});
|
|
750
|
+
|
|
751
|
+
console.log = info;
|
|
752
|
+
console.warn = warn;
|
|
753
|
+
console.log(`hub-game avatar wire: ${n} tests passed`);
|