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,1194 @@
|
|
|
1
|
+
// Earned items (contract §11, v1.53), the server half: a game's declaration
|
|
2
|
+
// (`hub.unlocks`), `hub.unlock`, `hub.wearEarned`, `hub.unlocksOf` and
|
|
3
|
+
// `hub.earned` against a stub host (code/server/earned.js, hub.js); the
|
|
4
|
+
// arrival read's `earned`; `hubEarned` and `hub-earned` latched and filtered
|
|
5
|
+
// for hidden pairs as `hubWear` and `hub-wear` are; the dev serve's and a
|
|
6
|
+
// guest's session-only unlock; and a place where nobody shows one writing
|
|
7
|
+
// exactly what it wrote before.
|
|
8
|
+
//
|
|
9
|
+
// The server is the kit's layer on a fake session, as test-try-on runs it, and
|
|
10
|
+
// the client the kit's real hook layer. One scripted session, `story`, is run
|
|
11
|
+
// with and without its `hub.unlock` calls and compared as text.
|
|
12
|
+
//
|
|
13
|
+
// `HUB_EARNED_BASELINE=<dir>` points at another copy of this kit (say
|
|
14
|
+
// `git archive <commit> kits/hub-game/code | tar -x -C <dir>` and the path to
|
|
15
|
+
// `kits/hub-game` in it): the story without unlocks is then run on that copy
|
|
16
|
+
// too, and compared byte for byte. `npm run check` runs this without one.
|
|
17
|
+
|
|
18
|
+
import assert from 'node:assert/strict';
|
|
19
|
+
import { register } from 'node:module';
|
|
20
|
+
import { pathToFileURL } from 'node:url';
|
|
21
|
+
import path from 'node:path';
|
|
22
|
+
import fs from 'node:fs';
|
|
23
|
+
import os from 'node:os';
|
|
24
|
+
|
|
25
|
+
const sceneStub = 'export const readScene = () => globalThis.__hubTestActors ?? [];';
|
|
26
|
+
const avatarsStub = 'export function dropMissing() {}';
|
|
27
|
+
register(
|
|
28
|
+
`data:text/javascript,${encodeURIComponent(`
|
|
29
|
+
import { readFile } from 'node:fs/promises';
|
|
30
|
+
import { fileURLToPath } from 'node:url';
|
|
31
|
+
const stubs = {
|
|
32
|
+
'@imports/castle.multiplayer-3d/code/server/sceneBodies.js': 'data:text/javascript,${encodeURIComponent(sceneStub)}',
|
|
33
|
+
'@imports/castle.multiplayer-3d/code/client/avatars.js': 'data:text/javascript,${encodeURIComponent(avatarsStub)}',
|
|
34
|
+
'castle-web-sdk': ${JSON.stringify(new URL('./fixtures/sdk-stub.mjs', import.meta.url).href)},
|
|
35
|
+
};
|
|
36
|
+
export async function resolve(specifier, context, next) {
|
|
37
|
+
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 };
|
|
38
|
+
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 };
|
|
39
|
+
if (specifier.startsWith('@imports/castle.physics-2d/engine/')) {
|
|
40
|
+
return { url: 'data:text/javascript,export const initialMedia = {}; export const playMedia = () => {}; export const stopMedia = () => {};', shortCircuit: true };
|
|
41
|
+
}
|
|
42
|
+
if (specifier === '../client/pack.js') {
|
|
43
|
+
return { url: 'data:text/javascript,export const loadPack = () => {}; export const cachedPacks = () => []; export const matchesOwn = () => false; export const resolveDeckDoor = () => {};', shortCircuit: true };
|
|
44
|
+
}
|
|
45
|
+
if (stubs[specifier]) {
|
|
46
|
+
return { url: stubs[specifier], shortCircuit: true };
|
|
47
|
+
}
|
|
48
|
+
return next(specifier, context);
|
|
49
|
+
}
|
|
50
|
+
export async function load(url, context, next) {
|
|
51
|
+
if (url.endsWith('/code/client/hookLayer.js')) {
|
|
52
|
+
const source = await readFile(fileURLToPath(url), 'utf8');
|
|
53
|
+
return { format: 'module', source: source.replaceAll('import.meta.glob(', '(() => ({}))('), shortCircuit: true };
|
|
54
|
+
}
|
|
55
|
+
return next(url, context);
|
|
56
|
+
}
|
|
57
|
+
`)}`,
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
async function kit(root) {
|
|
61
|
+
const at = (file) => pathToFileURL(path.join(root, file)).href;
|
|
62
|
+
return {
|
|
63
|
+
layer: (await import(at('code/server/hub.js'))).layer,
|
|
64
|
+
hookLayer: (await import(at('code/client/hookLayer.js'))).default,
|
|
65
|
+
State: await import(at('code/client/state.js')),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const here = await kit(path.join(import.meta.dirname, '..'));
|
|
70
|
+
const baseline = process.env.HUB_EARNED_BASELINE ? await kit(path.resolve(process.env.HUB_EARNED_BASELINE)) : null;
|
|
71
|
+
const Earned = await import('../code/server/earned.js');
|
|
72
|
+
const { readManifest } = await import('../code/server/manifest.js');
|
|
73
|
+
|
|
74
|
+
globalThis.__hubTestActors = [{ id: 'spawn', components: { Player: {}, Transform: { x: 0, y: 1, z: 0 } } }];
|
|
75
|
+
const UNLOCKS = [
|
|
76
|
+
{ id: 'cove-3-wins', class: 'badge', shape: 'badge-round', name: 'Cove Ace', deed: 'win 3 races in Cove', color: '#3aa0d8' },
|
|
77
|
+
{ id: 'night-lamp', class: 'held', shape: 'held-lantern', name: 'Night Lamp', deed: 'finish a night run', color: '#FFAA00' },
|
|
78
|
+
];
|
|
79
|
+
const plainJson = { deckId: 'cove-deck', server: { maxPlayers: 8 }, hub: { contract: 1, title: 'Cove', result: {} } };
|
|
80
|
+
const declaringJson = { ...plainJson, hub: { ...plainJson.hub, unlocks: UNLOCKS } };
|
|
81
|
+
const HOME_UNLOCKS = [
|
|
82
|
+
{ id: 'farm-planter', class: 'furniture', piece: 'planter', name: 'Crate Planter', deed: 'buy at the stand for 300 coins', color: '#8a5a2b' },
|
|
83
|
+
{ id: 'farm-yard', class: 'deed', piece: 'yard', name: 'Yard Deed', deed: 'buy at the stand for 800 coins', color: '#5aa04a' },
|
|
84
|
+
];
|
|
85
|
+
const homeJson = { ...declaringJson, hub: { ...declaringJson.hub, unlocks: [...UNLOCKS, ...HOME_UNLOCKS] } };
|
|
86
|
+
const PET_UNLOCK = { id: 'adopt-cat', class: 'pet', piece: 'pet-cat', name: 'Cat', deed: 'adopt a cat', color: '#8a5a2b' };
|
|
87
|
+
const petJson = { ...homeJson, hub: { ...homeJson.hub, unlocks: [...homeJson.hub.unlocks, PET_UNLOCK] } };
|
|
88
|
+
const pet = { deckId: 'cove-deck', ...PET_UNLOCK };
|
|
89
|
+
const planter = { deckId: 'cove-deck', ...HOME_UNLOCKS[0] };
|
|
90
|
+
const yard = { deckId: 'cove-deck', ...HOME_UNLOCKS[1] };
|
|
91
|
+
const flush = () => new Promise((resolve) => setImmediate(resolve));
|
|
92
|
+
|
|
93
|
+
const ROSTER = [
|
|
94
|
+
{ playerId: 'p1', userId: '101', username: 'ada', isAnonymous: false },
|
|
95
|
+
{ playerId: 'p2', userId: '102', username: 'bo', isAnonymous: false },
|
|
96
|
+
{ playerId: 'p3', userId: 'anon-1', username: 'guest', isAnonymous: true },
|
|
97
|
+
];
|
|
98
|
+
const halo = { kind: 'halo', color: '#ffd700', rarity: 4 };
|
|
99
|
+
const ace = { deckId: 'cove-deck', ...UNLOCKS[0] };
|
|
100
|
+
const lamp = { deckId: 'cove-deck', ...UNLOCKS[1], color: '#ffaa00' };
|
|
101
|
+
const drawn = (item) => ({ class: item.class, shape: item.shape, color: item.color, name: item.name });
|
|
102
|
+
const fail = (code) => Object.assign(new Error(code), { code });
|
|
103
|
+
|
|
104
|
+
// A place on a fake session; everything it writes is kept in `log` in order.
|
|
105
|
+
// `platform: false` is the dev serve (no hub ops at all); `ops` replaces the
|
|
106
|
+
// host's earned-item methods; `saved` is ghost's arrival read per user id.
|
|
107
|
+
function room(layer, { json = declaringJson, hides = null, saved = {}, ops = {}, platform = true, sessionId = 's-1', trace = null } = {}) {
|
|
108
|
+
const record = (...entry) => trace?.push(JSON.stringify(entry));
|
|
109
|
+
const log = [];
|
|
110
|
+
const calls = [];
|
|
111
|
+
const players = ROSTER.map((p) => ({ ...p }));
|
|
112
|
+
const reads = [];
|
|
113
|
+
const hub = {
|
|
114
|
+
place: 'main',
|
|
115
|
+
title: 'Cove',
|
|
116
|
+
result: null,
|
|
117
|
+
arrival: () => null,
|
|
118
|
+
async reportResult() {
|
|
119
|
+
return { recorded: true };
|
|
120
|
+
},
|
|
121
|
+
async updatePad() {
|
|
122
|
+
return { status: 'gathering', members: [] };
|
|
123
|
+
},
|
|
124
|
+
readResults(input) {
|
|
125
|
+
calls.push(['read', input]);
|
|
126
|
+
log.push(['ghost-read', JSON.stringify(input)]);
|
|
127
|
+
const out = {};
|
|
128
|
+
for (const id of input.userIds ?? []) {
|
|
129
|
+
out[id] = { avatar: 1, recent: [], records: [], wearable: saved[id]?.wearable ?? null, ...(saved[id]?.earned ? { earned: saved[id].earned } : {}) };
|
|
130
|
+
}
|
|
131
|
+
const answer = { players: out, boards: {} };
|
|
132
|
+
if (ops.slowRead && input.userIds) {
|
|
133
|
+
return new Promise((resolve) => reads.push(() => resolve(answer)));
|
|
134
|
+
}
|
|
135
|
+
return Promise.resolve(answer);
|
|
136
|
+
},
|
|
137
|
+
async wear(playerId, wearable) {
|
|
138
|
+
calls.push(['wear', playerId, wearable]);
|
|
139
|
+
return { wearable };
|
|
140
|
+
},
|
|
141
|
+
async unlock(playerId, itemId) {
|
|
142
|
+
calls.push(['unlock', playerId, itemId]);
|
|
143
|
+
log.push(['ghost-unlock', playerId, itemId]);
|
|
144
|
+
if (ops.unlock) {
|
|
145
|
+
return ops.unlock(playerId, itemId);
|
|
146
|
+
}
|
|
147
|
+
const item = UNLOCKS.find((u) => u.id === itemId);
|
|
148
|
+
if (!item) {
|
|
149
|
+
throw fail('CAULDRON_HUB_UNLOCK_NOT_DECLARED');
|
|
150
|
+
}
|
|
151
|
+
return { unlocked: true, isNew: true, earned: { deckId: 'cove-deck', ...item } };
|
|
152
|
+
},
|
|
153
|
+
async wearEarned(playerId, earned) {
|
|
154
|
+
calls.push(['wearEarned', playerId, earned]);
|
|
155
|
+
if (ops.wearEarned) {
|
|
156
|
+
return ops.wearEarned(playerId, earned);
|
|
157
|
+
}
|
|
158
|
+
return { earned: earned ? { ...UNLOCKS.find((u) => u.id === earned.id), deckId: earned.deckId } : null };
|
|
159
|
+
},
|
|
160
|
+
async readUnlocks(userIds) {
|
|
161
|
+
calls.push(['readUnlocks', userIds]);
|
|
162
|
+
if (ops.readUnlocks) {
|
|
163
|
+
return ops.readUnlocks(userIds);
|
|
164
|
+
}
|
|
165
|
+
return { players: Object.fromEntries(userIds.map((id) => [id, { owned: [ace, { bad: true }] }])) };
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
for (const [name, value] of Object.entries(ops)) {
|
|
169
|
+
if (value === null) {
|
|
170
|
+
delete hub[name];
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (hides) {
|
|
174
|
+
hub.hiddenPair = hides;
|
|
175
|
+
}
|
|
176
|
+
// Install recording before layer construction/ready, including arrival reads.
|
|
177
|
+
if (trace) {
|
|
178
|
+
for (const method of ['readResults', 'unlock', 'readUnlocks', 'wearEarned']) {
|
|
179
|
+
const call = hub[method];
|
|
180
|
+
if (typeof call !== 'function') continue;
|
|
181
|
+
hub[method] = async (...args) => {
|
|
182
|
+
record('host', method, ...args);
|
|
183
|
+
const answer = await call(...args);
|
|
184
|
+
record('host-answer', method, answer);
|
|
185
|
+
return answer;
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const session = {
|
|
190
|
+
sessionId,
|
|
191
|
+
place: null,
|
|
192
|
+
players,
|
|
193
|
+
hub: platform ? hub : null,
|
|
194
|
+
send: (playerId, data) => {
|
|
195
|
+
record('send', playerId, data);
|
|
196
|
+
log.push(['send', playerId, JSON.stringify(data)]);
|
|
197
|
+
},
|
|
198
|
+
broadcast: (data) => {
|
|
199
|
+
record('broadcast', data);
|
|
200
|
+
log.push(['broadcast', JSON.stringify(data)]);
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
let ctx = null;
|
|
204
|
+
const deck = {
|
|
205
|
+
ready: (h) => (ctx = h),
|
|
206
|
+
arrive: (h, group) => log.push(['arrive', JSON.stringify(group)]),
|
|
207
|
+
leave: (h, playerId) => log.push(['leave', playerId]),
|
|
208
|
+
step: () => log.push(['step']),
|
|
209
|
+
};
|
|
210
|
+
const h = layer(json, deck, {}, () => true);
|
|
211
|
+
h.sceneFor(session);
|
|
212
|
+
const world = { timeMs: 0, players: new Map(), bodies: new Map(), scenePath: 'scenes/main.scene' };
|
|
213
|
+
h.ready(world);
|
|
214
|
+
return {
|
|
215
|
+
h,
|
|
216
|
+
log,
|
|
217
|
+
calls,
|
|
218
|
+
world,
|
|
219
|
+
reads,
|
|
220
|
+
session,
|
|
221
|
+
hub: () => ctx,
|
|
222
|
+
join(playerId = null) {
|
|
223
|
+
const snapshot = h.join();
|
|
224
|
+
record('join', playerId, snapshot);
|
|
225
|
+
log.push(['join', JSON.stringify(snapshot)]);
|
|
226
|
+
return snapshot;
|
|
227
|
+
},
|
|
228
|
+
delta() {
|
|
229
|
+
const delta = h.delta();
|
|
230
|
+
record('delta', delta);
|
|
231
|
+
log.push(['delta', JSON.stringify(delta)]);
|
|
232
|
+
return delta;
|
|
233
|
+
},
|
|
234
|
+
async tick(ms = 50) {
|
|
235
|
+
world.timeMs += ms;
|
|
236
|
+
h.place(world);
|
|
237
|
+
await flush();
|
|
238
|
+
world.timeMs += ms;
|
|
239
|
+
h.place(world);
|
|
240
|
+
h.step(world);
|
|
241
|
+
},
|
|
242
|
+
enter(playerId) {
|
|
243
|
+
world.players.set(playerId, { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
|
|
244
|
+
if (!players.some((p) => p.playerId === playerId)) {
|
|
245
|
+
players.push({ ...ROSTER.find((p) => p.playerId === playerId) });
|
|
246
|
+
}
|
|
247
|
+
h.message(session, { playerId }, { k: 'hub-hello', avatar: 1, from: null, party: 1 });
|
|
248
|
+
},
|
|
249
|
+
// A client joining afresh with the same player id (a reload).
|
|
250
|
+
rehello(playerId) {
|
|
251
|
+
h.message(session, { playerId }, { k: 'hub-hello', avatar: 1, from: null, party: 1 });
|
|
252
|
+
},
|
|
253
|
+
exit(playerId) {
|
|
254
|
+
world.players.delete(playerId);
|
|
255
|
+
const at = players.findIndex((p) => p.playerId === playerId);
|
|
256
|
+
if (at >= 0) {
|
|
257
|
+
players.splice(at, 1);
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// One visit. `unlocks` false leaves every earned-item call out.
|
|
264
|
+
async function story(layer, { unlocks, hides = null, json = declaringJson }) {
|
|
265
|
+
const r = room(layer, { hides, json, saved: { 101: { wearable: halo } } });
|
|
266
|
+
r.join();
|
|
267
|
+
r.delta();
|
|
268
|
+
r.enter('p1');
|
|
269
|
+
r.enter('p2');
|
|
270
|
+
await r.tick();
|
|
271
|
+
r.join();
|
|
272
|
+
r.delta();
|
|
273
|
+
if (unlocks) {
|
|
274
|
+
await r.hub().unlock('p2', 'cove-3-wins');
|
|
275
|
+
}
|
|
276
|
+
r.hub().wear('p2', { kind: 'aura', color: '#00ff00', rarity: 2 });
|
|
277
|
+
r.hub().mark('p1', { text: 'RED', color: '#d1453b' });
|
|
278
|
+
await r.tick();
|
|
279
|
+
r.delta();
|
|
280
|
+
r.enter('p3');
|
|
281
|
+
await r.tick();
|
|
282
|
+
r.join();
|
|
283
|
+
r.delta();
|
|
284
|
+
if (unlocks) {
|
|
285
|
+
await r.hub().unlock('p3', 'night-lamp');
|
|
286
|
+
await r.hub().wearEarned('p1', { deckId: 'cove-deck', id: 'night-lamp' });
|
|
287
|
+
}
|
|
288
|
+
await r.tick();
|
|
289
|
+
r.delta();
|
|
290
|
+
r.exit('p2');
|
|
291
|
+
await r.tick();
|
|
292
|
+
r.join();
|
|
293
|
+
r.delta();
|
|
294
|
+
await r.h.shutdown();
|
|
295
|
+
r.delta();
|
|
296
|
+
r.join();
|
|
297
|
+
return r;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// What a client that knows nothing of earned items is left with.
|
|
301
|
+
function withoutEarned(log) {
|
|
302
|
+
const out = [];
|
|
303
|
+
for (const entry of log) {
|
|
304
|
+
if (entry[0] === 'ghost-unlock' || (entry[0] === 'send' && JSON.parse(entry[2]).k === 'hub-earned')) {
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
if (entry[0] === 'join' || entry[0] === 'delta') {
|
|
308
|
+
const value = JSON.parse(entry[1]);
|
|
309
|
+
if (value && 'hubEarned' in value) {
|
|
310
|
+
delete value.hubEarned;
|
|
311
|
+
out.push([entry[0], JSON.stringify(entry[0] === 'delta' && Object.keys(value).length === 0 ? null : value)]);
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
out.push(entry);
|
|
316
|
+
}
|
|
317
|
+
return out;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const text = (log) => log.map((entry) => entry.join(' ')).join('\n');
|
|
321
|
+
|
|
322
|
+
const info = console.log;
|
|
323
|
+
const warned = [];
|
|
324
|
+
console.warn = (line) => warned.push(String(line));
|
|
325
|
+
console.log = () => {};
|
|
326
|
+
let n = 0;
|
|
327
|
+
async function test(name, fn) {
|
|
328
|
+
await fn();
|
|
329
|
+
n += 1;
|
|
330
|
+
info(`ok: ${name}`);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
await test('the declaration: at most 8, ids and shapes as ghost takes them, no rarity; the manifest carries it only when declared', async () => {
|
|
334
|
+
const ok = readManifest(declaringJson);
|
|
335
|
+
assert.deepEqual(ok.errors, []);
|
|
336
|
+
assert.deepEqual(ok.manifest.unlocks.map((u) => u.id), ['cove-3-wins', 'night-lamp']);
|
|
337
|
+
assert.equal(ok.manifest.unlocks[1].color, '#ffaa00');
|
|
338
|
+
assert.equal('unlocks' in readManifest(plainJson).manifest, false, 'a deck without it reads as before');
|
|
339
|
+
const bad = (unlocks) => readManifest({ ...plainJson, hub: { ...plainJson.hub, unlocks } }).errors;
|
|
340
|
+
assert.match(bad(Array.from({ length: 9 }, (_, i) => ({ ...UNLOCKS[0], id: `a${i}` })))[0], /at most 8/);
|
|
341
|
+
assert.match(bad([{ ...UNLOCKS[0], rarity: 3 }])[0], /rarity/);
|
|
342
|
+
assert.match(bad([{ ...UNLOCKS[0], id: 'Cove' }])[0], /\.id/);
|
|
343
|
+
assert.match(bad([{ ...UNLOCKS[0], class: 'hat' }])[0], /\.class/);
|
|
344
|
+
assert.match(bad([{ ...UNLOCKS[0], shape: 'x'.repeat(25) }])[0], /\.shape/);
|
|
345
|
+
assert.match(bad([{ ...UNLOCKS[0], name: '' }])[0], /\.name/);
|
|
346
|
+
assert.match(bad([{ ...UNLOCKS[0], name: 'x'.repeat(25) }])[0], /\.name/);
|
|
347
|
+
assert.match(bad([{ ...UNLOCKS[0], deed: 'x'.repeat(81) }])[0], /\.deed/);
|
|
348
|
+
assert.match(bad([{ ...UNLOCKS[0], color: 'blue' }])[0], /\.color/);
|
|
349
|
+
assert.match(bad([UNLOCKS[0], UNLOCKS[0]])[0], /twice/);
|
|
350
|
+
assert.match(bad({})[0], /must be a list/);
|
|
351
|
+
// Name and deed trimmed before their lengths, as ghost does.
|
|
352
|
+
const padded = readManifest({ ...plainJson, hub: { ...plainJson.hub, unlocks: [{ ...UNLOCKS[0], name: ` ${'x'.repeat(24)} `, deed: ' win 3 races in Cove\n' }] } });
|
|
353
|
+
assert.deepEqual(padded.errors, []);
|
|
354
|
+
assert.equal(padded.manifest.unlocks[0].name, 'x'.repeat(24));
|
|
355
|
+
assert.equal(padded.manifest.unlocks[0].deed, 'win 3 races in Cove');
|
|
356
|
+
assert.match(bad([{ ...UNLOCKS[0], name: ' ' }])[0], /\.name/);
|
|
357
|
+
assert.match(bad([{ ...UNLOCKS[0], deed: ' \t ' }])[0], /\.deed/);
|
|
358
|
+
// A deck that would be refused runs none of its game, as for any manifest error.
|
|
359
|
+
assert.equal(readManifest({ ...plainJson, hub: { ...plainJson.hub, unlocks: [{}] } }).manifest, null);
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
await test('hub.unlock goes to the host for a signed-in player; the answer is kept and drawn; hub.wearing is untouched', async () => {
|
|
363
|
+
const r = room(here.layer, { saved: { 101: { wearable: halo } } });
|
|
364
|
+
r.enter('p1');
|
|
365
|
+
await r.tick();
|
|
366
|
+
r.delta();
|
|
367
|
+
const answer = await r.hub().unlock('p1', 'cove-3-wins');
|
|
368
|
+
assert.deepEqual(answer, { isNew: true, earned: ace, saved: true });
|
|
369
|
+
assert.deepEqual(r.calls.filter((c) => c[0] === 'unlock'), [['unlock', 'p1', 'cove-3-wins']]);
|
|
370
|
+
assert.deepEqual(r.hub().earned('p1'), ace);
|
|
371
|
+
assert.deepEqual(r.hub().wearing('p1'), halo, 'the Look slot is what it was');
|
|
372
|
+
// A copy: changing it changes nothing kept.
|
|
373
|
+
r.hub().earned('p1').color = '#000000';
|
|
374
|
+
assert.equal(r.hub().earned('p1').color, '#3aa0d8');
|
|
375
|
+
assert.deepEqual(r.delta(), { hubEarned: { p1: drawn(ace) } });
|
|
376
|
+
assert.equal(r.delta(), null, 'latched: sent only on change');
|
|
377
|
+
assert.deepEqual(r.join().hubEarned, { p1: drawn(ace) });
|
|
378
|
+
// An answer that shows nothing new (another is shown) keeps what is shown.
|
|
379
|
+
const s = room(here.layer, { ops: { unlock: async () => ({ unlocked: true, isNew: false, earned: null }) } });
|
|
380
|
+
s.enter('p1');
|
|
381
|
+
await s.tick();
|
|
382
|
+
assert.deepEqual(await s.hub().unlock('p1', 'night-lamp'), { isNew: false, earned: null, saved: true });
|
|
383
|
+
assert.equal(s.hub().earned('p1'), null);
|
|
384
|
+
assert.equal('hubEarned' in s.join(), false);
|
|
385
|
+
assert.equal(s.hub().earned('nobody'), null);
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
await test('refusals resolve null, are logged once per code, and change nothing', async () => {
|
|
389
|
+
warned.length = 0;
|
|
390
|
+
const r = room(here.layer, { ops: { unlock: async () => { throw fail('CAULDRON_HUB_UNLOCK_RATE_LIMITED'); }, wearEarned: async () => { throw fail('CAULDRON_HUB_EARNED_NOT_A_ROOT'); } } });
|
|
391
|
+
r.enter('p1');
|
|
392
|
+
await r.tick();
|
|
393
|
+
r.delta();
|
|
394
|
+
assert.equal(await r.hub().unlock('p1', 'cove-3-wins'), null);
|
|
395
|
+
assert.equal(await r.hub().unlock('p1', 'cove-3-wins'), null);
|
|
396
|
+
assert.equal(await r.hub().wearEarned('p1', { deckId: 'cove-deck', id: 'cove-3-wins' }), null);
|
|
397
|
+
assert.equal(await r.hub().wearEarned('p1', null), null);
|
|
398
|
+
assert.equal(warned.filter((w) => w.includes('unlock refused (CAULDRON_HUB_UNLOCK_RATE_LIMITED)')).length, 1);
|
|
399
|
+
assert.equal(warned.filter((w) => w.includes('wearEarned refused (CAULDRON_HUB_EARNED_NOT_A_ROOT)')).length, 1);
|
|
400
|
+
assert.equal(r.hub().earned('p1'), null);
|
|
401
|
+
assert.equal(r.delta(), null);
|
|
402
|
+
// Arguments the kit refuses never reach the host.
|
|
403
|
+
const before = r.calls.length;
|
|
404
|
+
assert.equal(await r.hub().unlock('p1', 'Not An Id'), null);
|
|
405
|
+
assert.equal(await r.hub().unlock('p1', 7), null);
|
|
406
|
+
assert.equal(await r.hub().unlock('ghost', 'cove-3-wins'), null);
|
|
407
|
+
assert.equal(await r.hub().wearEarned('p1', { id: 'cove-3-wins' }), null);
|
|
408
|
+
assert.equal(await r.hub().wearEarned('p1', 'cove-3-wins'), null);
|
|
409
|
+
assert.equal(r.calls.length, before);
|
|
410
|
+
assert.ok(warned.some((w) => w.includes('hub.unlock: an item id')));
|
|
411
|
+
assert.ok(warned.some((w) => w.includes('"ghost" is not a player here')));
|
|
412
|
+
assert.ok(warned.some((w) => w.includes('a choice is { deckId, id } or null')));
|
|
413
|
+
// A read the host refuses is null too.
|
|
414
|
+
const q = room(here.layer, { ops: { readUnlocks: async () => { throw fail('CAULDRON_HUB_INVALID_ARGUMENT'); } } });
|
|
415
|
+
assert.equal(await q.hub().unlocksOf(['101']), null);
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
await test('hub.wearEarned is the town choosing: the answer is what is shown, null clears it', async () => {
|
|
419
|
+
const r = room(here.layer);
|
|
420
|
+
r.enter('p1');
|
|
421
|
+
await r.tick();
|
|
422
|
+
r.delta();
|
|
423
|
+
assert.deepEqual(await r.hub().wearEarned('p1', { deckId: 'cove-deck', id: 'night-lamp' }), { earned: lamp, saved: true });
|
|
424
|
+
assert.deepEqual(r.calls.at(-1), ['wearEarned', 'p1', { deckId: 'cove-deck', id: 'night-lamp' }]);
|
|
425
|
+
assert.deepEqual(r.delta(), { hubEarned: { p1: drawn(lamp) } });
|
|
426
|
+
assert.deepEqual(await r.hub().wearEarned('p1', null), { earned: null, saved: true });
|
|
427
|
+
assert.deepEqual(r.delta(), { hubEarned: {} }, '`{}` once when the last goes');
|
|
428
|
+
assert.equal(r.delta(), null);
|
|
429
|
+
assert.equal('hubEarned' in r.join(), false);
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
await test('hub.unlocksOf is the host read, cleaned; null where the host has none', async () => {
|
|
433
|
+
const r = room(here.layer);
|
|
434
|
+
assert.deepEqual(await r.hub().unlocksOf(['101', 5]), { players: { 101: { owned: [ace] } } });
|
|
435
|
+
assert.deepEqual(r.calls.at(-1), ['readUnlocks', ['101']]);
|
|
436
|
+
// Always a promise, of null where the host has no such read.
|
|
437
|
+
const none = room(here.layer, { platform: false }).hub().unlocksOf(['101']);
|
|
438
|
+
assert.ok(none instanceof Promise);
|
|
439
|
+
assert.equal(await none, null);
|
|
440
|
+
assert.equal(await room(here.layer, { ops: { readUnlocks: null } }).hub().unlocksOf(['101']), null);
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
await test("the arrival read's earned is kept; one without it changes nothing", async () => {
|
|
444
|
+
const r = room(here.layer, { saved: { 101: { earned: lamp }, 102: {} } });
|
|
445
|
+
r.enter('p1');
|
|
446
|
+
r.enter('p2');
|
|
447
|
+
await r.tick();
|
|
448
|
+
assert.deepEqual(r.hub().earned('p1'), lamp);
|
|
449
|
+
assert.equal(r.hub().earned('p2'), null);
|
|
450
|
+
assert.deepEqual(r.delta().hubEarned, { p1: drawn(lamp) });
|
|
451
|
+
// Something that is not an earned item is not kept.
|
|
452
|
+
const s = room(here.layer, { saved: { 101: { earned: { ...lamp, class: 'hat' } } } });
|
|
453
|
+
s.enter('p1');
|
|
454
|
+
await s.tick();
|
|
455
|
+
assert.equal(s.hub().earned('p1'), null);
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
await test('the race rule: an unlock or choice made after a read began wins over that read', async () => {
|
|
459
|
+
for (const act of [
|
|
460
|
+
(r) => r.hub().unlock('p1', 'cove-3-wins'),
|
|
461
|
+
(r) => r.hub().wearEarned('p1', { deckId: 'cove-deck', id: 'cove-3-wins' }),
|
|
462
|
+
]) {
|
|
463
|
+
const r = room(here.layer, { saved: { 101: { earned: lamp } }, ops: { slowRead: true } });
|
|
464
|
+
r.enter('p1');
|
|
465
|
+
r.world.timeMs += 50;
|
|
466
|
+
r.h.place(r.world);
|
|
467
|
+
assert.equal(r.reads.length, 1, 'the arrival read is in flight');
|
|
468
|
+
await act(r);
|
|
469
|
+
assert.deepEqual(r.hub().earned('p1'), ace);
|
|
470
|
+
r.reads[0]();
|
|
471
|
+
await flush();
|
|
472
|
+
assert.deepEqual(r.hub().earned('p1'), ace, 'the older read did not undo it');
|
|
473
|
+
}
|
|
474
|
+
// A refused unlock or choice applies nothing: the arrival's item lands.
|
|
475
|
+
for (const act of [
|
|
476
|
+
(r) => r.hub().unlock('p1', 'cove-3-wins'),
|
|
477
|
+
(r) => r.hub().wearEarned('p1', { deckId: 'cove-deck', id: 'cove-3-wins' }),
|
|
478
|
+
(r) => r.hub().wearEarned('p1', null),
|
|
479
|
+
]) {
|
|
480
|
+
const r = room(here.layer, {
|
|
481
|
+
saved: { 101: { earned: lamp } },
|
|
482
|
+
ops: {
|
|
483
|
+
slowRead: true,
|
|
484
|
+
unlock: async () => { throw fail('CAULDRON_HUB_UNLOCK_RATE_LIMITED'); },
|
|
485
|
+
wearEarned: async () => { throw fail('CAULDRON_HUB_EARNED_NOT_A_ROOT'); },
|
|
486
|
+
},
|
|
487
|
+
});
|
|
488
|
+
r.enter('p1');
|
|
489
|
+
r.world.timeMs += 50;
|
|
490
|
+
r.h.place(r.world);
|
|
491
|
+
assert.equal(await act(r), null);
|
|
492
|
+
r.reads[0]();
|
|
493
|
+
await flush();
|
|
494
|
+
assert.deepEqual(r.hub().earned('p1'), lamp, 'a refusal did not drop the arrival read');
|
|
495
|
+
}
|
|
496
|
+
// Without anything since, the read is kept.
|
|
497
|
+
const r = room(here.layer, { saved: { 101: { earned: lamp } }, ops: { slowRead: true } });
|
|
498
|
+
r.enter('p1');
|
|
499
|
+
r.world.timeMs += 50;
|
|
500
|
+
r.h.place(r.world);
|
|
501
|
+
r.reads[0]();
|
|
502
|
+
await flush();
|
|
503
|
+
assert.deepEqual(r.hub().earned('p1'), lamp);
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
await test('a hidden pair: out of the shared map, sent alone to who may see it, as hub-wear is', async () => {
|
|
507
|
+
const hides = (a, b) => (a === 'p1' && b === 'p2') || (a === 'p2' && b === 'p1');
|
|
508
|
+
const r = room(here.layer, { hides });
|
|
509
|
+
for (const id of ['p1', 'p2', 'p3']) {
|
|
510
|
+
r.enter(id);
|
|
511
|
+
}
|
|
512
|
+
await r.tick();
|
|
513
|
+
r.delta();
|
|
514
|
+
r.log.length = 0;
|
|
515
|
+
await r.hub().unlock('p1', 'cove-3-wins');
|
|
516
|
+
await r.hub().unlock('p3', 'cove-3-wins');
|
|
517
|
+
await r.tick();
|
|
518
|
+
const delta = r.delta();
|
|
519
|
+
assert.deepEqual(delta.hubEarned, { p3: drawn(ace) }, 'p1 is in a hidden pair');
|
|
520
|
+
const alone = r.log.filter((e) => e[0] === 'send' && JSON.parse(e[2]).k === 'hub-earned');
|
|
521
|
+
assert.deepEqual(
|
|
522
|
+
alone.map((e) => [e[1], JSON.parse(e[2]).hubEarned]),
|
|
523
|
+
[
|
|
524
|
+
['p1', { p1: drawn(ace) }],
|
|
525
|
+
['p3', { p1: drawn(ace) }],
|
|
526
|
+
],
|
|
527
|
+
'p1 sees their own and p3 sees p1; p2 is never told',
|
|
528
|
+
);
|
|
529
|
+
// Sent only on change.
|
|
530
|
+
r.log.length = 0;
|
|
531
|
+
await r.tick();
|
|
532
|
+
assert.equal(r.log.filter((e) => e[0] === 'send' && JSON.parse(e[2]).k === 'hub-earned').length, 0);
|
|
533
|
+
// Cleared: the empty map goes once.
|
|
534
|
+
await r.hub().wearEarned('p1', null);
|
|
535
|
+
await r.tick();
|
|
536
|
+
assert.deepEqual(
|
|
537
|
+
r.log.filter((e) => e[0] === 'send' && JSON.parse(e[2]).k === 'hub-earned').map((e) => [e[1], JSON.parse(e[2]).hubEarned]),
|
|
538
|
+
[
|
|
539
|
+
['p1', {}],
|
|
540
|
+
['p3', {}],
|
|
541
|
+
],
|
|
542
|
+
);
|
|
543
|
+
// A reload with the same player id is told again: p1 their own, alone.
|
|
544
|
+
await r.hub().unlock('p1', 'cove-3-wins');
|
|
545
|
+
await r.tick();
|
|
546
|
+
r.log.length = 0;
|
|
547
|
+
await r.tick();
|
|
548
|
+
assert.equal(r.log.filter((e) => e[0] === 'send' && JSON.parse(e[2]).k === 'hub-earned').length, 0);
|
|
549
|
+
r.rehello('p1');
|
|
550
|
+
r.rehello('p2');
|
|
551
|
+
await r.tick();
|
|
552
|
+
assert.deepEqual(
|
|
553
|
+
r.log.filter((e) => e[0] === 'send' && JSON.parse(e[2]).k === 'hub-earned').map((e) => [e[1], JSON.parse(e[2]).hubEarned]),
|
|
554
|
+
[
|
|
555
|
+
['p1', { p1: drawn(ace) }],
|
|
556
|
+
['p2', {}],
|
|
557
|
+
],
|
|
558
|
+
'the reloaded clients are sent what they may see, empty or not',
|
|
559
|
+
);
|
|
560
|
+
// An avatar change (`again`) is not a fresh join.
|
|
561
|
+
r.log.length = 0;
|
|
562
|
+
r.h.message(r.session, { playerId: 'p1' }, { k: 'hub-hello', avatar: 2, from: null, party: 1, again: true });
|
|
563
|
+
await r.tick();
|
|
564
|
+
assert.equal(r.log.filter((e) => e[0] === 'send' && JSON.parse(e[2]).k === 'hub-earned').length, 0);
|
|
565
|
+
});
|
|
566
|
+
|
|
567
|
+
await test('the dev serve and a guest: session-only, from the declaration, never sent to ghost', async () => {
|
|
568
|
+
warned.length = 0;
|
|
569
|
+
const r = room(here.layer, { platform: false });
|
|
570
|
+
r.enter('p1');
|
|
571
|
+
await r.tick();
|
|
572
|
+
r.delta();
|
|
573
|
+
assert.deepEqual(await r.hub().unlock('p1', 'cove-3-wins'), { isNew: true, earned: ace, saved: false });
|
|
574
|
+
assert.deepEqual(r.delta(), { hubEarned: { p1: drawn(ace) } });
|
|
575
|
+
// Again: not new. A second item is owned but the first stays shown.
|
|
576
|
+
assert.deepEqual(await r.hub().unlock('p1', 'cove-3-wins'), { isNew: false, earned: ace, saved: false });
|
|
577
|
+
assert.deepEqual(await r.hub().unlock('p1', 'night-lamp'), { isNew: true, earned: ace, saved: false });
|
|
578
|
+
// The town's choice among what is owned here.
|
|
579
|
+
assert.deepEqual(await r.hub().wearEarned('p1', { deckId: 'cove-deck', id: 'night-lamp' }), { earned: lamp, saved: false });
|
|
580
|
+
assert.equal(await r.hub().wearEarned('p1', { deckId: 'other-deck', id: 'night-lamp' }), null);
|
|
581
|
+
assert.deepEqual(await r.hub().wearEarned('p1', null), { earned: null, saved: false });
|
|
582
|
+
// Undeclared: refused, logged once.
|
|
583
|
+
assert.equal(await r.hub().unlock('p1', 'not-declared'), null);
|
|
584
|
+
assert.equal(await r.hub().unlock('p1', 'not-declared'), null);
|
|
585
|
+
assert.equal(warned.filter((w) => w.includes('"not-declared" is not declared')).length, 1);
|
|
586
|
+
// A deck that declares none can give none.
|
|
587
|
+
const plain = room(here.layer, { platform: false, json: plainJson });
|
|
588
|
+
plain.enter('p1');
|
|
589
|
+
assert.equal(await plain.hub().unlock('p1', 'cove-3-wins'), null);
|
|
590
|
+
// A deck with no id yet is 'local'.
|
|
591
|
+
const unsaved = room(here.layer, { platform: false, json: { ...declaringJson, deckId: undefined } });
|
|
592
|
+
unsaved.enter('p1');
|
|
593
|
+
assert.equal((await unsaved.hub().unlock('p1', 'cove-3-wins')).earned.deckId, 'local');
|
|
594
|
+
// A guest on production: the same, and the host is never asked.
|
|
595
|
+
const g = room(here.layer);
|
|
596
|
+
g.enter('p3');
|
|
597
|
+
await g.tick();
|
|
598
|
+
assert.deepEqual(await g.hub().unlock('p3', 'night-lamp'), { isNew: true, earned: lamp, saved: false });
|
|
599
|
+
assert.equal(g.calls.filter((c) => c[0] === 'unlock' || c[0] === 'wearEarned').length, 0);
|
|
600
|
+
// A host whose runtime cannot keep unlocks, or has no such method, is the same.
|
|
601
|
+
for (const ops of [{ unlock: async () => { throw fail('CAULDRON_HUB_UNAVAILABLE'); } }, { unlock: null, wearEarned: null }]) {
|
|
602
|
+
const u = room(here.layer, { ops });
|
|
603
|
+
u.enter('p1');
|
|
604
|
+
await u.tick();
|
|
605
|
+
assert.deepEqual(await u.hub().unlock('p1', 'cove-3-wins'), { isNew: true, earned: ace, saved: false });
|
|
606
|
+
// The host that only lacks unlocks still saves the choice.
|
|
607
|
+
assert.deepEqual(await u.hub().wearEarned('p1', null), { earned: null, saved: ops.wearEarned !== null });
|
|
608
|
+
}
|
|
609
|
+
// Leaving forgets it all: back again, nothing is owned or shown.
|
|
610
|
+
r.exit('p1');
|
|
611
|
+
await r.tick();
|
|
612
|
+
r.enter('p1');
|
|
613
|
+
assert.equal(r.hub().earned('p1'), null);
|
|
614
|
+
assert.equal(await r.hub().wearEarned('p1', { deckId: 'cove-deck', id: 'night-lamp' }), null);
|
|
615
|
+
});
|
|
616
|
+
|
|
617
|
+
await test('given before a hello: kept, shown once they say hello, gone with them if they never do', async () => {
|
|
618
|
+
const r = room(here.layer);
|
|
619
|
+
r.world.players.set('p1', { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
|
|
620
|
+
assert.deepEqual(await r.hub().unlock('p1', 'cove-3-wins'), { isNew: true, earned: ace, saved: true });
|
|
621
|
+
assert.equal('hubEarned' in r.join(), false);
|
|
622
|
+
assert.equal(r.delta()?.hubEarned, undefined);
|
|
623
|
+
r.enter('p1');
|
|
624
|
+
assert.deepEqual(r.join().hubEarned, { p1: drawn(ace) });
|
|
625
|
+
const s = room(here.layer);
|
|
626
|
+
s.world.players.set('p2', { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
|
|
627
|
+
await s.hub().unlock('p2', 'cove-3-wins');
|
|
628
|
+
s.exit('p2');
|
|
629
|
+
await s.tick();
|
|
630
|
+
// Pruned: the same player id coming back (a fresh session) shows nothing.
|
|
631
|
+
s.enter('p2');
|
|
632
|
+
assert.equal(s.hub().earned('p2'), null);
|
|
633
|
+
assert.equal('hubEarned' in s.join(), false);
|
|
634
|
+
});
|
|
635
|
+
|
|
636
|
+
await test('delayed unlock receipts cannot undo a newer shown choice or clear', async () => {
|
|
637
|
+
for (const itemId of [planter.id, UNLOCKS[0].id]) {
|
|
638
|
+
for (const choice of [{ deckId: lamp.deckId, id: lamp.id }, null]) {
|
|
639
|
+
let finish;
|
|
640
|
+
const r = room(here.layer, { json: homeJson, saved: { 101: { earned: ace } }, ops: {
|
|
641
|
+
unlock: () => new Promise((resolve) => { finish = resolve; }),
|
|
642
|
+
} });
|
|
643
|
+
r.enter('p1');
|
|
644
|
+
await r.tick();
|
|
645
|
+
r.delta();
|
|
646
|
+
assert.deepEqual(r.hub().earned('p1'), ace);
|
|
647
|
+
const grant = r.hub().unlock('p1', itemId);
|
|
648
|
+
await r.hub().wearEarned('p1', choice);
|
|
649
|
+
const shown = choice ? lamp : null;
|
|
650
|
+
assert.deepEqual(r.hub().earned('p1'), shown);
|
|
651
|
+
assert.deepEqual(r.delta(), { hubEarned: shown ? { p1: drawn(shown) } : {} });
|
|
652
|
+
r.log.length = 0;
|
|
653
|
+
finish({ isNew: true, earned: ace });
|
|
654
|
+
// The receipt still reports Ghost's answer; only application is guarded.
|
|
655
|
+
assert.deepEqual(await grant, { isNew: true, earned: ace, saved: true });
|
|
656
|
+
assert.deepEqual(r.hub().earned('p1'), shown);
|
|
657
|
+
assert.equal(r.delta(), null, 'the delayed receipt sends no reversion');
|
|
658
|
+
assert.deepEqual(r.join().hubEarned, shown ? { p1: drawn(shown) } : undefined);
|
|
659
|
+
const notices = r.log.filter((e) => e[0] === 'send' && JSON.parse(e[2]).k === 'hub-home-unlock');
|
|
660
|
+
assert.equal(notices.length, itemId === planter.id ? 1 : 0, 'home ownership and announcement still apply');
|
|
661
|
+
if (itemId === planter.id) {
|
|
662
|
+
const before = r.calls.length;
|
|
663
|
+
assert.equal(await r.hub().wearEarned('p1', { deckId: planter.deckId, id: planter.id }), null);
|
|
664
|
+
assert.equal(r.calls.length, before);
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
// A refused later choice changes no revision: the unlock may still apply.
|
|
669
|
+
let finish;
|
|
670
|
+
const r = room(here.layer, { ops: {
|
|
671
|
+
unlock: () => new Promise((resolve) => { finish = resolve; }),
|
|
672
|
+
wearEarned: async () => { throw fail('CAULDRON_HUB_EARNED_NOT_A_ROOT'); },
|
|
673
|
+
} });
|
|
674
|
+
r.enter('p1');
|
|
675
|
+
await r.tick();
|
|
676
|
+
const grant = r.hub().unlock('p1', ace.id);
|
|
677
|
+
assert.equal(await r.hub().wearEarned('p1', null), null);
|
|
678
|
+
finish({ isNew: true, earned: ace });
|
|
679
|
+
await grant;
|
|
680
|
+
assert.deepEqual(r.hub().earned('p1'), ace);
|
|
681
|
+
});
|
|
682
|
+
|
|
683
|
+
await test('home grants before hello are pruned after departure without starting the earned wire', async () => {
|
|
684
|
+
for (const config of [
|
|
685
|
+
{ platform: false, playerId: 'p1' },
|
|
686
|
+
{ playerId: 'p3' },
|
|
687
|
+
{ playerId: 'p1', ops: { unlock: async () => { throw fail('CAULDRON_HUB_UNAVAILABLE'); } } },
|
|
688
|
+
]) {
|
|
689
|
+
const { playerId } = config;
|
|
690
|
+
const r = room(here.layer, { json: homeJson, ...config });
|
|
691
|
+
const body = () => ({ at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
|
|
692
|
+
r.world.players.set(playerId, body());
|
|
693
|
+
const first = await r.hub().unlock(playerId, planter.id);
|
|
694
|
+
assert.deepEqual(first, { isNew: true, earned: null, saved: false });
|
|
695
|
+
assert.equal((await r.hub().unlock(playerId, planter.id)).isNew, false);
|
|
696
|
+
assert.equal('hubEarned' in r.join(), false);
|
|
697
|
+
r.delta();
|
|
698
|
+
r.exit(playerId);
|
|
699
|
+
await r.tick();
|
|
700
|
+
r.join();
|
|
701
|
+
r.delta();
|
|
702
|
+
// A new body with the same id, still before hello, gets fresh ownership.
|
|
703
|
+
r.world.players.set(playerId, body());
|
|
704
|
+
assert.equal((await r.hub().unlock(playerId, planter.id)).isNew, true);
|
|
705
|
+
r.rehello(playerId);
|
|
706
|
+
await r.tick();
|
|
707
|
+
r.join();
|
|
708
|
+
r.delta();
|
|
709
|
+
assert.ok(!text(r.log).includes('hubEarned') && !text(r.log).includes('hub-earned'));
|
|
710
|
+
}
|
|
711
|
+
const h = { ...Earned.newEarnedState(), players: new Map(), sim: { players: new Map() } };
|
|
712
|
+
h.homeOwned.set('departed', new Set(['home']));
|
|
713
|
+
h.sessionOwned.set('departed', new Set([planter.id]));
|
|
714
|
+
assert.equal(Earned.used(h), false, 'home ownership never enables the wire gate');
|
|
715
|
+
assert.equal(Earned.needsPrune(h), true);
|
|
716
|
+
Earned.prune(h);
|
|
717
|
+
assert.equal(h.homeOwned.size, 0);
|
|
718
|
+
assert.equal(h.sessionOwned.size, 0);
|
|
719
|
+
assert.equal(Earned.needsPrune(h), false);
|
|
720
|
+
});
|
|
721
|
+
|
|
722
|
+
await test('SDK and base-kit types keep receipt/arrival shape required and home items in owned only', async () => {
|
|
723
|
+
const ts = await import('typescript');
|
|
724
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'hub-home-types-'));
|
|
725
|
+
try {
|
|
726
|
+
const files = [];
|
|
727
|
+
for (const [name, relative] of [
|
|
728
|
+
['source', '../../../sdk/src/server/hub.ts'],
|
|
729
|
+
['mirror', '../../base/sdk/server/hub.d.ts'],
|
|
730
|
+
['dist', '../../../sdk/dist/server/hub.d.ts'],
|
|
731
|
+
['public-mirror', '../../base/sdk/server/wrapper.d.ts'],
|
|
732
|
+
]) {
|
|
733
|
+
const file = path.join(dir, `${name}.ts`);
|
|
734
|
+
files.push(file);
|
|
735
|
+
fs.writeFileSync(file, `
|
|
736
|
+
import type * as Hub from ${JSON.stringify(path.resolve(import.meta.dirname, relative))};
|
|
737
|
+
declare const unlock: Hub.MultiplayerHubUnlockReceipt;
|
|
738
|
+
declare const wear: Hub.MultiplayerHubWearEarnedReceipt;
|
|
739
|
+
declare const arrival: Hub.MultiplayerHubPlayerResults;
|
|
740
|
+
const unlockShape: string = unlock.earned!.shape;
|
|
741
|
+
const wearShape: string = wear.earned!.shape;
|
|
742
|
+
const arrivalShape: string = arrival.earned!.shape;
|
|
743
|
+
const wearableClass: Hub.MultiplayerHubEarnedClass = 'held';
|
|
744
|
+
const homeClasses: Hub.MultiplayerHubHomeClass[] = ['furniture', 'deed', 'pet'];
|
|
745
|
+
const homeClass: Hub.MultiplayerHubHomeClass = 'pet';
|
|
746
|
+
const home: Hub.MultiplayerHubHomeItem = {
|
|
747
|
+
deckId: 'nestlings', id: 'adopt-cat', class: homeClass, piece: 'pet-cat',
|
|
748
|
+
name: 'Cat', deed: 'adopt a cat', color: '#8a5a2b',
|
|
749
|
+
};
|
|
750
|
+
const owned: Hub.MultiplayerHubUnlocksRead = { players: { '101': { owned: [home, unlock.earned!] } } };
|
|
751
|
+
const item = owned.players['101'].owned[0];
|
|
752
|
+
if (item.class === 'furniture' || item.class === 'deed' || item.class === 'pet') {
|
|
753
|
+
const piece: string = item.piece;
|
|
754
|
+
}
|
|
755
|
+
// @ts-expect-error A home class is not an earned-slot class.
|
|
756
|
+
const badClass: Hub.MultiplayerHubEarnedClass = 'pet';
|
|
757
|
+
// @ts-expect-error A home item cannot be a receipt's shown item.
|
|
758
|
+
const badReceipt: Hub.MultiplayerHubUnlockReceipt = { unlocked: true, isNew: true, earned: home };
|
|
759
|
+
// @ts-expect-error A home item cannot be a wearable choice receipt.
|
|
760
|
+
const badWear: Hub.MultiplayerHubWearEarnedReceipt = { earned: home };
|
|
761
|
+
// @ts-expect-error A home item cannot be an arrival's shown item.
|
|
762
|
+
const badArrival: Hub.MultiplayerHubPlayerResults = { recent: [], records: [], avatar: null, earned: home };
|
|
763
|
+
// @ts-expect-error Wearable items have no piece field.
|
|
764
|
+
const badPiece = unlock.earned!.piece;
|
|
765
|
+
`);
|
|
766
|
+
}
|
|
767
|
+
const program = ts.createProgram(files, {
|
|
768
|
+
strict: true, noEmit: true, skipLibCheck: true, types: [],
|
|
769
|
+
target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.ESNext,
|
|
770
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler, allowImportingTsExtensions: true,
|
|
771
|
+
});
|
|
772
|
+
const diagnostics = ts.getPreEmitDiagnostics(program);
|
|
773
|
+
assert.equal(diagnostics.length, 0, ts.formatDiagnostics(diagnostics, {
|
|
774
|
+
getCanonicalFileName: (file) => file, getCurrentDirectory: () => dir, getNewLine: () => '\n',
|
|
775
|
+
}));
|
|
776
|
+
} finally {
|
|
777
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
778
|
+
}
|
|
779
|
+
});
|
|
780
|
+
|
|
781
|
+
await test('home declarations: separate 8 wearable, 6 furniture/deed and 16 pet caps, exact fields and unique ids', async () => {
|
|
782
|
+
const json = (unlocks) => ({ ...plainJson, hub: { ...plainJson.hub, unlocks } });
|
|
783
|
+
const homes = Array.from({ length: 6 }, (_, i) => ({ ...HOME_UNLOCKS[i % 2], id: `home-${i}` }));
|
|
784
|
+
const wearables = Array.from({ length: 8 }, (_, i) => ({ ...UNLOCKS[0], id: `badge-${i}` }));
|
|
785
|
+
assert.deepEqual(readManifest(json([...wearables, ...homes])).errors, []);
|
|
786
|
+
assert.equal(readManifest(json([...wearables, ...homes])).manifest.unlocks.length, 14);
|
|
787
|
+
assert.equal(Earned.MAX_PET_UNLOCKS, 16);
|
|
788
|
+
assert.deepEqual(Earned.HOME_CLASSES, ['furniture', 'deed', 'pet']);
|
|
789
|
+
const pets = Array.from({ length: 16 }, (_, i) => ({ ...PET_UNLOCK, id: `pet-${i}` }));
|
|
790
|
+
const furniture = homes.map((item) => ({ ...item, class: 'furniture' }));
|
|
791
|
+
assert.deepEqual(readManifest(json([...pets, ...furniture, ...wearables])).errors, []);
|
|
792
|
+
assert.equal(readManifest(json([...pets, ...furniture, ...wearables])).manifest.unlocks.length, 30);
|
|
793
|
+
assert.ok(readManifest(json([...pets, { ...PET_UNLOCK, id: 'pet-16' }])).errors.includes('hub.unlocks may declare at most 16 pet items.'));
|
|
794
|
+
assert.match(readManifest(json([...pets, ...furniture, { ...HOME_UNLOCKS[0], id: 'home-6' }])).errors.join(), /at most 6 home/);
|
|
795
|
+
assert.match(readManifest(json([...pets, ...wearables, { ...UNLOCKS[0], id: 'badge-8' }])).errors.join(), /at most 8/);
|
|
796
|
+
for (const piece of ['planter', 'pet-', 'pet-1cat', 'pet-Cat', `pet-${'a'.repeat(21)}`, undefined]) {
|
|
797
|
+
assert.equal(Earned.readUnlock({ ...PET_UNLOCK, piece }), '.piece of a pet must match pet-[a-z][a-z0-9-]{0,19}');
|
|
798
|
+
}
|
|
799
|
+
assert.equal(Earned.readUnlock({ ...PET_UNLOCK, piece: `pet-${'a'.repeat(20)}` }).piece.length, 24);
|
|
800
|
+
assert.equal(Earned.readUnlock({ ...PET_UNLOCK, piece: 'pet-walk-1' }), ".piece pet-walk-* is the house pet's stage, not a species");
|
|
801
|
+
for (const id of [HOME_UNLOCKS[0].id, UNLOCKS[0].id]) {
|
|
802
|
+
assert.match(readManifest(json([...HOME_UNLOCKS, ...UNLOCKS, { ...PET_UNLOCK, id }])).errors.join(), /twice/);
|
|
803
|
+
}
|
|
804
|
+
// Existing home pieces, including the house's stages and collar, keep working.
|
|
805
|
+
for (const cls of ['furniture', 'deed']) {
|
|
806
|
+
for (const piece of ['pet-cat', 'pet-walk-1', 'pet-walk-2', 'pet-walk-3', 'pet-collar']) {
|
|
807
|
+
assert.equal(Earned.readUnlock({ ...HOME_UNLOCKS[0], class: cls, piece }).piece, piece);
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
assert.match(readManifest(json([...homes, { ...HOME_UNLOCKS[0], id: 'home-6' }])).errors.join(), /at most 6 home/);
|
|
811
|
+
assert.match(readManifest(json([...wearables, { ...UNLOCKS[0], id: 'badge-8' }, ...homes])).errors.join(), /at most 8/);
|
|
812
|
+
for (const [item, error] of [
|
|
813
|
+
[{ ...HOME_UNLOCKS[0], shape: 'badge-round' }, /\.shape/],
|
|
814
|
+
[{ ...UNLOCKS[0], piece: 'planter' }, /\.piece/],
|
|
815
|
+
[{ ...HOME_UNLOCKS[0], piece: 'Planter' }, /\.piece/],
|
|
816
|
+
[{ ...HOME_UNLOCKS[0], piece: 'x'.repeat(25) }, /\.piece/],
|
|
817
|
+
[{ ...HOME_UNLOCKS[0], piece: undefined }, /\.piece/],
|
|
818
|
+
[{ ...HOME_UNLOCKS[0], id: UNLOCKS[0].id }, /twice/],
|
|
819
|
+
]) {
|
|
820
|
+
assert.match(readManifest(json([UNLOCKS[0], item])).errors.join(), error);
|
|
821
|
+
}
|
|
822
|
+
assert.deepEqual(readManifest(json([{ ...HOME_UNLOCKS[0], piece: 'future-piece' }])).errors, []);
|
|
823
|
+
});
|
|
824
|
+
|
|
825
|
+
await test('publish check reads the home catalogue; an unlisted piece warns without failing', async () => {
|
|
826
|
+
const { default: check } = await import('./check.mjs');
|
|
827
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'hub-home-check-'));
|
|
828
|
+
try {
|
|
829
|
+
fs.mkdirSync(path.join(dir, 'scenes'));
|
|
830
|
+
fs.writeFileSync(path.join(dir, 'scenes/main.scene'), JSON.stringify({ actors: globalThis.__hubTestActors }));
|
|
831
|
+
const fixture = {
|
|
832
|
+
...homeJson,
|
|
833
|
+
hub: { ...homeJson.hub, unlocks: [
|
|
834
|
+
...Array.from({ length: 8 }, (_, i) => ({ ...UNLOCKS[0], id: `badge-${i}` })),
|
|
835
|
+
...Array.from({ length: 6 }, (_, i) => ({ ...HOME_UNLOCKS[i % 2], id: `home-${i}` })),
|
|
836
|
+
] },
|
|
837
|
+
server: { ...homeJson.server, main: 'code/server/index.js' },
|
|
838
|
+
};
|
|
839
|
+
fs.writeFileSync(path.join(dir, 'castle.json'), JSON.stringify(fixture));
|
|
840
|
+
assert.deepEqual(await check({ deckDir: dir, self: true }), { errors: [], warnings: [] });
|
|
841
|
+
fixture.hub = { ...fixture.hub, unlocks: [{ ...PET_UNLOCK, piece: 'pet-dog' }] };
|
|
842
|
+
fs.writeFileSync(path.join(dir, 'castle.json'), JSON.stringify(fixture));
|
|
843
|
+
assert.deepEqual(await check({ deckDir: dir, self: true }), { errors: [], warnings: [] });
|
|
844
|
+
fixture.hub = { ...fixture.hub, unlocks: [{ ...HOME_UNLOCKS[0], piece: 'future-piece' }, PET_UNLOCK] };
|
|
845
|
+
fs.writeFileSync(path.join(dir, 'castle.json'), JSON.stringify(fixture));
|
|
846
|
+
const answer = await check({ deckDir: dir, self: true });
|
|
847
|
+
assert.deepEqual(answer.errors, []);
|
|
848
|
+
assert.equal(answer.warnings.length, 2);
|
|
849
|
+
assert.match(answer.warnings[0], /piece "future-piece".*home-pieces\.md/);
|
|
850
|
+
assert.match(answer.warnings[1], /piece "pet-cat".*home-pieces\.md/);
|
|
851
|
+
} finally {
|
|
852
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
853
|
+
}
|
|
854
|
+
});
|
|
855
|
+
|
|
856
|
+
await test('home unlocks: host, guest, dev serve and unavailable fallback keep ownership without an earned wire', async () => {
|
|
857
|
+
for (const config of [
|
|
858
|
+
{ platform: false },
|
|
859
|
+
{ ops: { unlock: async () => { throw fail('CAULDRON_HUB_UNAVAILABLE'); } } },
|
|
860
|
+
{ ops: { unlock: null } },
|
|
861
|
+
// Ghost answers with what the player shows: a badge, never the home item.
|
|
862
|
+
{ hostSaves: true, ops: { unlock: async (_p, id) => ({ isNew: true, earned: UNLOCKS.some((u) => u.id === id) ? { deckId: ace.deckId, ...UNLOCKS.find((u) => u.id === id) } : null }) } },
|
|
863
|
+
]) {
|
|
864
|
+
for (const [playerId, firstItem] of ['p1', 'p3'].flatMap((id) => [planter, pet].map((item) => [id, item]))) {
|
|
865
|
+
const r = room(here.layer, { json: petJson, ...config });
|
|
866
|
+
r.enter(playerId);
|
|
867
|
+
await r.tick();
|
|
868
|
+
r.delta();
|
|
869
|
+
r.log.length = 0;
|
|
870
|
+
const answer = await r.hub().unlock(playerId, firstItem.id);
|
|
871
|
+
assert.equal(answer.earned, null, 'the receipt says what the player shows, never a home item');
|
|
872
|
+
assert.equal(answer.isNew, true);
|
|
873
|
+
assert.equal(answer.saved, playerId !== 'p3' && config.hostSaves === true);
|
|
874
|
+
assert.equal(r.hub().earned(playerId), null);
|
|
875
|
+
assert.equal('hubEarned' in r.join(), false);
|
|
876
|
+
assert.equal(r.delta(), null);
|
|
877
|
+
await r.tick();
|
|
878
|
+
assert.equal(r.log.some((e) => e[0] === 'send' && JSON.parse(e[2]).k === 'hub-earned'), false);
|
|
879
|
+
const notifications = r.log.filter((e) => e[0] === 'send' && JSON.parse(e[2]).k === 'hub-home-unlock');
|
|
880
|
+
assert.deepEqual(notifications, [['send', playerId, '{"k":"hub-home-unlock"}']]);
|
|
881
|
+
here.State.clear();
|
|
882
|
+
here.hookLayer.message({}, JSON.parse(notifications[0][2]));
|
|
883
|
+
assert.deepEqual(here.State.hub.commands, [{ k: 'hub-home-unlock' }]);
|
|
884
|
+
assert.equal(here.State.hub.earned.size, 0);
|
|
885
|
+
const { installSystem } = await import('../code/systems/hub.js');
|
|
886
|
+
let system;
|
|
887
|
+
installSystem({ registerSystem: (value) => { system = value; } });
|
|
888
|
+
system.runCommands({}, 1000);
|
|
889
|
+
assert.deepEqual(system.toast, { text: 'Sent to your house', until: 5000 });
|
|
890
|
+
// Another home item leaves an existing badge alone.
|
|
891
|
+
await r.hub().unlock(playerId, UNLOCKS[0].id);
|
|
892
|
+
assert.deepEqual(r.hub().earned(playerId), ace);
|
|
893
|
+
const before = r.hub().earned(playerId);
|
|
894
|
+
r.delta();
|
|
895
|
+
await r.hub().unlock(playerId, yard.id);
|
|
896
|
+
await r.hub().unlock(playerId, pet.id);
|
|
897
|
+
assert.deepEqual(r.hub().earned(playerId), before);
|
|
898
|
+
assert.equal(r.delta(), null);
|
|
899
|
+
warned.length = 0;
|
|
900
|
+
const calls = r.calls.length;
|
|
901
|
+
for (const item of [firstItem, firstItem, yard, pet]) {
|
|
902
|
+
assert.equal(await r.hub().wearEarned(playerId, { deckId: item.deckId, id: item.id }), null);
|
|
903
|
+
}
|
|
904
|
+
assert.equal(r.calls.length, calls, 'home wear is refused before the host');
|
|
905
|
+
assert.equal(warned.filter((w) => w.includes('CAULDRON_HUB_EARNED_NOT_WEARABLE')).length, 1);
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
for (const firstItem of [planter, pet]) {
|
|
909
|
+
const r = room(here.layer, { json: petJson, platform: false });
|
|
910
|
+
r.enter('p1');
|
|
911
|
+
await r.tick();
|
|
912
|
+
r.log.length = 0;
|
|
913
|
+
await r.hub().unlock('p1', firstItem.id);
|
|
914
|
+
assert.equal((await r.hub().unlock('p1', firstItem.id)).isNew, false);
|
|
915
|
+
assert.equal(r.log.filter((e) => e[0] === 'send' && JSON.parse(e[2]).k === 'hub-home-unlock').length, 1);
|
|
916
|
+
r.exit('p1');
|
|
917
|
+
await r.tick();
|
|
918
|
+
r.enter('p1');
|
|
919
|
+
assert.equal((await r.hub().unlock('p1', firstItem.id)).isNew, true, 'local ownership ends with the visit');
|
|
920
|
+
}
|
|
921
|
+
});
|
|
922
|
+
|
|
923
|
+
await test('owned reads include home class and piece, and known cross-deck home choices never call the host', async () => {
|
|
924
|
+
const crossDeck = { ...planter, deckId: 'farm-deck' };
|
|
925
|
+
const r = room(here.layer, { ops: { readUnlocks: async () => ({ players: { 101: { owned: [ace, crossDeck, yard, pet, { ...pet, deckId: 'nestlings-deck' }] } } }) } });
|
|
926
|
+
r.enter('p1');
|
|
927
|
+
await r.tick();
|
|
928
|
+
assert.deepEqual(await r.hub().unlocksOf(['101']), { players: { 101: { owned: [ace, crossDeck, yard, pet, { ...pet, deckId: 'nestlings-deck' }] } } });
|
|
929
|
+
warned.length = 0;
|
|
930
|
+
const calls = r.calls.length;
|
|
931
|
+
assert.equal(await r.hub().wearEarned('p1', { deckId: crossDeck.deckId, id: crossDeck.id }), null);
|
|
932
|
+
assert.equal(await r.hub().wearEarned('p1', { deckId: crossDeck.deckId, id: crossDeck.id }), null);
|
|
933
|
+
for (const item of [pet, { ...pet, deckId: 'nestlings-deck' }]) {
|
|
934
|
+
assert.equal(await r.hub().wearEarned('p1', { deckId: item.deckId, id: item.id }), null);
|
|
935
|
+
}
|
|
936
|
+
assert.equal(r.calls.length, calls);
|
|
937
|
+
assert.equal(warned.filter((w) => w.includes('CAULDRON_HUB_EARNED_NOT_WEARABLE')).length, 1);
|
|
938
|
+
// The arrival read and an invalid host choice cannot put a home item on an avatar.
|
|
939
|
+
for (const home of [planter, pet]) {
|
|
940
|
+
const s = room(here.layer, { saved: { 101: { earned: home } }, ops: { wearEarned: async () => ({ earned: home }) } });
|
|
941
|
+
s.enter('p1');
|
|
942
|
+
await s.tick();
|
|
943
|
+
assert.equal(s.hub().earned('p1'), null);
|
|
944
|
+
assert.equal(await s.hub().wearEarned('p1', { deckId: 'unknown', id: 'unknown' }), null);
|
|
945
|
+
assert.equal('hubEarned' in s.join(), false);
|
|
946
|
+
}
|
|
947
|
+
// A home unlock does not supersede an arrival's shown wearable.
|
|
948
|
+
const pending = room(here.layer, { json: homeJson, saved: { 101: { earned: lamp } }, ops: {
|
|
949
|
+
slowRead: true,
|
|
950
|
+
unlock: async () => ({ isNew: true, earned: planter }),
|
|
951
|
+
} });
|
|
952
|
+
pending.enter('p1');
|
|
953
|
+
pending.world.timeMs += 50;
|
|
954
|
+
pending.h.place(pending.world);
|
|
955
|
+
await pending.hub().unlock('p1', planter.id);
|
|
956
|
+
assert.equal(pending.hub().earned('p1'), null);
|
|
957
|
+
pending.reads[0]();
|
|
958
|
+
await flush();
|
|
959
|
+
assert.deepEqual(pending.hub().earned('p1'), lamp);
|
|
960
|
+
});
|
|
961
|
+
|
|
962
|
+
await test('the home-unlock command says Sent to your house through the existing toast', async () => {
|
|
963
|
+
const { installSystem } = await import('../code/systems/hub.js');
|
|
964
|
+
let system;
|
|
965
|
+
installSystem({ registerSystem: (value) => { system = value; } });
|
|
966
|
+
here.State.clear();
|
|
967
|
+
here.hookLayer.message({}, { k: 'hub-home-unlock' });
|
|
968
|
+
system.runCommands({}, 1000);
|
|
969
|
+
assert.deepEqual(system.toast, { text: 'Sent to your house', until: 5000 });
|
|
970
|
+
assert.equal(here.State.hub.commands.length, 0);
|
|
971
|
+
assert.equal(here.State.hub.earned.size, 0);
|
|
972
|
+
});
|
|
973
|
+
|
|
974
|
+
await test('v1.77: a boat deed first unlock says Sent to your boat at the Harbour; furniture keeps the house bytes; a repeat sends nothing', async () => {
|
|
975
|
+
const BOAT_UNLOCK = { id: 'boat-sloop-deed', class: 'deed', piece: 'boat-sloop', name: 'Sloop', deed: 'buy at the boatyard for 900 coins', color: '#3a6ea5' };
|
|
976
|
+
const boatJson = { ...homeJson, hub: { ...homeJson.hub, unlocks: [...homeJson.hub.unlocks, BOAT_UNLOCK] } };
|
|
977
|
+
const { installSystem } = await import('../code/systems/hub.js');
|
|
978
|
+
for (const config of [
|
|
979
|
+
{ platform: false },
|
|
980
|
+
{ hostSaves: true, ops: { unlock: async () => ({ isNew: true, earned: null }) } },
|
|
981
|
+
]) {
|
|
982
|
+
for (const [itemId, bytes, text] of [
|
|
983
|
+
[BOAT_UNLOCK.id, '{"k":"hub-home-unlock","to":"boat"}', 'Sent to your boat at the Harbour'],
|
|
984
|
+
[planter.id, '{"k":"hub-home-unlock"}', 'Sent to your house'],
|
|
985
|
+
]) {
|
|
986
|
+
const r = room(here.layer, { json: boatJson, ...config });
|
|
987
|
+
r.enter('p1');
|
|
988
|
+
await r.tick();
|
|
989
|
+
r.delta();
|
|
990
|
+
r.log.length = 0;
|
|
991
|
+
await r.hub().unlock('p1', itemId);
|
|
992
|
+
const notices = r.log.filter((e) => e[0] === 'send' && JSON.parse(e[2]).k === 'hub-home-unlock');
|
|
993
|
+
assert.deepEqual(notices, [['send', 'p1', bytes]]);
|
|
994
|
+
here.State.clear();
|
|
995
|
+
here.hookLayer.message({}, JSON.parse(notices[0][2]));
|
|
996
|
+
let system;
|
|
997
|
+
installSystem({ registerSystem: (value) => { system = value; } });
|
|
998
|
+
system.runCommands({}, 1000);
|
|
999
|
+
assert.deepEqual(system.toast, { text, until: 5000 });
|
|
1000
|
+
assert.equal(here.State.hub.commands.length, 0);
|
|
1001
|
+
// A repeat unlock is not new and sends nothing.
|
|
1002
|
+
if (config.platform === false) {
|
|
1003
|
+
r.log.length = 0;
|
|
1004
|
+
assert.equal((await r.hub().unlock('p1', itemId)).isNew, false);
|
|
1005
|
+
assert.equal(r.log.filter((e) => e[0] === 'send' && JSON.parse(e[2]).k === 'hub-home-unlock').length, 0);
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
// The host answers a repeat as not new: nothing is sent.
|
|
1010
|
+
const r = room(here.layer, { json: boatJson, hostSaves: true, ops: { unlock: async () => ({ isNew: false, earned: null }) } });
|
|
1011
|
+
r.enter('p1');
|
|
1012
|
+
await r.tick();
|
|
1013
|
+
r.log.length = 0;
|
|
1014
|
+
await r.hub().unlock('p1', BOAT_UNLOCK.id);
|
|
1015
|
+
assert.equal(r.log.filter((e) => e[0] === 'send' && JSON.parse(e[2]).k === 'hub-home-unlock').length, 0);
|
|
1016
|
+
});
|
|
1017
|
+
|
|
1018
|
+
await test('the town wardrobe filters furniture and deeds out of the owned read', async () => {
|
|
1019
|
+
const { makeWardrobe } = await import('../../../experiments/hub-town/code/server/wardrobe.js');
|
|
1020
|
+
const { default: catalogue } = await import('../../../experiments/hub-town/code/server/wardrobe.data.js');
|
|
1021
|
+
const [deckId, shelf] = Object.entries(catalogue)[0];
|
|
1022
|
+
const item = shelf.items[0];
|
|
1023
|
+
const stall = { id: 'stall', t: { x: 0, y: 1, z: 0 }, props: {} };
|
|
1024
|
+
const mat = { ...stall, id: 'mat', props: { deckId, id: item.id } };
|
|
1025
|
+
const lit = { ...mat, id: 'lit', props: { ...mat.props, lit: true } };
|
|
1026
|
+
const shown = [];
|
|
1027
|
+
const hub = {
|
|
1028
|
+
now: 0,
|
|
1029
|
+
actorsWith: (name) => ({ TownWardrobe: [stall], TownWardrobeMat: [mat], TownWardrobeItem: [lit] }[name] ?? []),
|
|
1030
|
+
players: () => [{ playerId: 'p1', userId: '101', at: stall.t }],
|
|
1031
|
+
hide(_id, _to) {},
|
|
1032
|
+
show(id, _to) { shown.push(id); },
|
|
1033
|
+
label() {},
|
|
1034
|
+
unlocksOf: async () => ({ players: { 101: { owned: [{ ...planter, deckId, id: item.id }, { ...yard, deckId, id: item.id }] } } }),
|
|
1035
|
+
wearEarned: () => { throw new Error('home item offered to wear'); },
|
|
1036
|
+
};
|
|
1037
|
+
const wardrobe = makeWardrobe();
|
|
1038
|
+
wardrobe.ready(hub);
|
|
1039
|
+
wardrobe.step(hub);
|
|
1040
|
+
await flush();
|
|
1041
|
+
hub.now = 10000;
|
|
1042
|
+
wardrobe.step(hub);
|
|
1043
|
+
await flush();
|
|
1044
|
+
assert.deepEqual(shown, []);
|
|
1045
|
+
});
|
|
1046
|
+
|
|
1047
|
+
// Furniture and badge only, on a keyless host session: freeze initialization
|
|
1048
|
+
// and the entire visit's wire, including each client's join and the host read.
|
|
1049
|
+
async function homeWearableTrace() {
|
|
1050
|
+
const trace = [];
|
|
1051
|
+
const r = room(here.layer, {
|
|
1052
|
+
trace,
|
|
1053
|
+
json: { ...plainJson, hub: { ...plainJson.hub, unlocks: [HOME_UNLOCKS[0], UNLOCKS[0]] } },
|
|
1054
|
+
ops: {
|
|
1055
|
+
unlock: async (_playerId, id) => ({ isNew: true, earned: id === ace.id ? ace : null }),
|
|
1056
|
+
readUnlocks: async () => ({ players: { 101: { owned: [planter, ace] } } }),
|
|
1057
|
+
},
|
|
1058
|
+
});
|
|
1059
|
+
r.join('p1');
|
|
1060
|
+
r.delta();
|
|
1061
|
+
r.enter('p1');
|
|
1062
|
+
await r.tick();
|
|
1063
|
+
r.delta();
|
|
1064
|
+
r.join('p2');
|
|
1065
|
+
r.enter('p2');
|
|
1066
|
+
await r.tick();
|
|
1067
|
+
r.delta();
|
|
1068
|
+
await r.hub().unlock('p1', planter.id);
|
|
1069
|
+
r.delta();
|
|
1070
|
+
await r.hub().unlocksOf(['101']);
|
|
1071
|
+
await r.hub().wearEarned('p1', { deckId: planter.deckId, id: planter.id });
|
|
1072
|
+
await r.hub().unlock('p1', ace.id);
|
|
1073
|
+
r.delta();
|
|
1074
|
+
await r.hub().wearEarned('p1', { deckId: ace.deckId, id: ace.id });
|
|
1075
|
+
r.delta();
|
|
1076
|
+
r.join('p1'); // A reload also receives a snapshot with the shown badge.
|
|
1077
|
+
await r.hub().wearEarned('p1', null);
|
|
1078
|
+
r.delta();
|
|
1079
|
+
return `[${trace.join(',')}]`;
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
await test('no pets: furniture and badge wire and host calls match the pre-pet trace byte for byte', async () => {
|
|
1083
|
+
// Captured from the full pre-change kit code at 741d74c18^ in scratch.
|
|
1084
|
+
// This literal is always checked, including without HUB_EARNED_BASELINE.
|
|
1085
|
+
const expected = [
|
|
1086
|
+
'[["join","p1",{"hubPlace":{"contract":1,"id":"main","title":"Cove","scene":"scenes/main.scene","controller":"walk","maxDurationSec":600,"result":{"score":null},"fallY":null},"hubAv":{},"hud":null,"hidden":[],"held":[],"labels":{},"tints":{},"marks":{},"hubDoors":[],"spawned":{},"spawnTemplates":{}}]',
|
|
1087
|
+
',["delta",{"hubAv":{},"hud":null,"hidden":[],"held":[],"labels":{},"tints":{},"marks":{},"hubDoors":[],"spawnTemplates":{},"spawned":{}}]',
|
|
1088
|
+
',["host","readResults",{"userIds":["101"]}]',
|
|
1089
|
+
',["host-answer","readResults",{"players":{"101":{"avatar":1,"recent":[],"records":[],"wearable":null}},"boards":{}}]',
|
|
1090
|
+
',["send","p1",{"k":"hub-arrived","facing":0}]',
|
|
1091
|
+
',["delta",{"hubAv":{"p1":1}}]',
|
|
1092
|
+
',["join","p2",{"hubPlace":{"contract":1,"id":"main","title":"Cove","scene":"scenes/main.scene","controller":"walk","maxDurationSec":600,"result":{"score":null},"fallY":null},"hubAv":{"p1":1},"hud":null,"hidden":[],"held":[],"labels":{},"tints":{},"marks":{},"hubDoors":[],"spawned":{},"spawnTemplates":{}}]',
|
|
1093
|
+
',["host","readResults",{"userIds":["102"]}]',
|
|
1094
|
+
',["host-answer","readResults",{"players":{"102":{"avatar":1,"recent":[],"records":[],"wearable":null}},"boards":{}}]',
|
|
1095
|
+
',["send","p2",{"k":"hub-arrived","facing":0}]',
|
|
1096
|
+
',["delta",{"hubAv":{"p1":1,"p2":1}}]',
|
|
1097
|
+
',["host","unlock","p1","farm-planter"]',
|
|
1098
|
+
',["host-answer","unlock",{"isNew":true,"earned":null}]',
|
|
1099
|
+
',["send","p1",{"k":"hub-home-unlock"}]',
|
|
1100
|
+
',["delta",null]',
|
|
1101
|
+
',["host","readUnlocks",["101"]]',
|
|
1102
|
+
',["host-answer","readUnlocks",{"players":{"101":{"owned":[{"deckId":"cove-deck","id":"farm-planter","class":"furniture","piece":"planter","name":"Crate Planter","deed":"buy at the stand for 300 coins","color":"#8a5a2b"},{"deckId":"cove-deck","id":"cove-3-wins","class":"badge","shape":"badge-round","name":"Cove Ace","deed":"win 3 races in Cove","color":"#3aa0d8"}]}}}]',
|
|
1103
|
+
',["host","unlock","p1","cove-3-wins"]',
|
|
1104
|
+
',["host-answer","unlock",{"isNew":true,"earned":{"deckId":"cove-deck","id":"cove-3-wins","class":"badge","shape":"badge-round","name":"Cove Ace","deed":"win 3 races in Cove","color":"#3aa0d8"}}]',
|
|
1105
|
+
',["delta",{"hubEarned":{"p1":{"class":"badge","shape":"badge-round","color":"#3aa0d8","name":"Cove Ace"}}}]',
|
|
1106
|
+
',["host","wearEarned","p1",{"deckId":"cove-deck","id":"cove-3-wins"}]',
|
|
1107
|
+
',["host-answer","wearEarned",{"earned":{"id":"cove-3-wins","class":"badge","shape":"badge-round","name":"Cove Ace","deed":"win 3 races in Cove","color":"#3aa0d8","deckId":"cove-deck"}}]',
|
|
1108
|
+
',["delta",null]',
|
|
1109
|
+
',["join","p1",{"hubPlace":{"contract":1,"id":"main","title":"Cove","scene":"scenes/main.scene","controller":"walk","maxDurationSec":600,"result":{"score":null},"fallY":null},"hubAv":{"p1":1,"p2":1},"hubEarned":{"p1":{"class":"badge","shape":"badge-round","color":"#3aa0d8","name":"Cove Ace"}},"hud":null,"hidden":[],"held":[],"labels":{},"tints":{},"marks":{},"hubDoors":[],"spawned":{},"spawnTemplates":{}}]',
|
|
1110
|
+
',["host","wearEarned","p1",null]',
|
|
1111
|
+
',["host-answer","wearEarned",{"earned":null}]',
|
|
1112
|
+
',["delta",{"hubEarned":{}}]',
|
|
1113
|
+
']',
|
|
1114
|
+
].join('');
|
|
1115
|
+
assert.equal(await homeWearableTrace(), expected);
|
|
1116
|
+
});
|
|
1117
|
+
|
|
1118
|
+
const never = await story(here.layer, { unlocks: false });
|
|
1119
|
+
const used = await story(here.layer, { unlocks: true });
|
|
1120
|
+
|
|
1121
|
+
await test('keys absent: a place where nobody shows an earned item names none, in any snapshot, delta or message', async () => {
|
|
1122
|
+
assert.ok(!text(never.log).includes('hubEarned') && !text(never.log).includes('hub-earned'));
|
|
1123
|
+
// A deck that declares unlocks and one that does not write the same.
|
|
1124
|
+
const plain = await story(here.layer, { unlocks: false, json: plainJson });
|
|
1125
|
+
assert.equal(text(plain.log), text(never.log));
|
|
1126
|
+
const homeDeclared = await story(here.layer, { unlocks: false, json: homeJson });
|
|
1127
|
+
assert.equal(text(homeDeclared.log), text(never.log), 'home declarations without ownership change no bytes');
|
|
1128
|
+
assert.ok(text(never.log).length > 2000);
|
|
1129
|
+
// With a hidden pair in the place too.
|
|
1130
|
+
const hides = (a, b) => (a === 'p1' && b === 'p3') || (a === 'p3' && b === 'p1');
|
|
1131
|
+
const hiddenNever = await story(here.layer, { unlocks: false, hides });
|
|
1132
|
+
const hiddenPlain = await story(here.layer, { unlocks: false, hides, json: plainJson });
|
|
1133
|
+
assert.ok(!text(hiddenNever.log).includes('hubEarned') && !text(hiddenNever.log).includes('hub-earned'));
|
|
1134
|
+
assert.ok(text(hiddenNever.log).includes('hub-wear'), 'the story does send things alone');
|
|
1135
|
+
assert.equal(text(hiddenPlain.log), text(hiddenNever.log));
|
|
1136
|
+
const hiddenUsed = await story(here.layer, { unlocks: true, hides });
|
|
1137
|
+
assert.ok(text(hiddenUsed.log).includes('hub-earned'));
|
|
1138
|
+
assert.equal(text(withoutEarned(hiddenUsed.log)), text(hiddenNever.log));
|
|
1139
|
+
});
|
|
1140
|
+
|
|
1141
|
+
await test('used: everything else the place writes is what it writes when nobody has one, in the same order', async () => {
|
|
1142
|
+
assert.ok(text(used.log).includes('hubEarned'));
|
|
1143
|
+
assert.equal(text(withoutEarned(used.log)), text(never.log));
|
|
1144
|
+
});
|
|
1145
|
+
|
|
1146
|
+
await test('the client: the hook layer reads hubEarned and hub-earned, and a place without them leaves it empty', async () => {
|
|
1147
|
+
const feed = (log, viewer) => {
|
|
1148
|
+
here.State.clear();
|
|
1149
|
+
const scene = { files: null };
|
|
1150
|
+
for (const entry of log) {
|
|
1151
|
+
if (entry[0] === 'join' || entry[0] === 'delta') {
|
|
1152
|
+
const msg = JSON.parse(entry[1]);
|
|
1153
|
+
if (msg) {
|
|
1154
|
+
here.hookLayer.state(scene, msg, null);
|
|
1155
|
+
}
|
|
1156
|
+
} else if (entry[0] === 'send' && entry[1] === viewer) {
|
|
1157
|
+
here.hookLayer.message(scene, JSON.parse(entry[2]));
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
return Object.fromEntries(here.State.hub.earned);
|
|
1161
|
+
};
|
|
1162
|
+
assert.deepEqual(feed(never.log, 'p1'), {});
|
|
1163
|
+
// Halfway through the used story, before the place ends.
|
|
1164
|
+
const cut = used.log.findIndex((e) => e[0] === 'leave');
|
|
1165
|
+
assert.deepEqual(feed(used.log.slice(0, cut), 'p1'), { p1: drawn(lamp), p2: drawn(ace), p3: drawn(lamp) });
|
|
1166
|
+
here.hookLayer.message({}, { k: 'hub-earned', hubEarned: { p9: drawn(ace) } });
|
|
1167
|
+
assert.deepEqual(here.State.hub.earned.get('p9'), drawn(ace));
|
|
1168
|
+
here.State.clear();
|
|
1169
|
+
assert.equal(here.State.hub.earned.size + here.State.hub.earnedAll.size + here.State.hub.earnedMe.size, 0);
|
|
1170
|
+
});
|
|
1171
|
+
|
|
1172
|
+
if (baseline) {
|
|
1173
|
+
await test('keys absent, against the baseline kit: byte for byte the same story', async () => {
|
|
1174
|
+
const before = await story(baseline.layer, { unlocks: false, json: plainJson });
|
|
1175
|
+
const now = await story(here.layer, { unlocks: false, json: plainJson });
|
|
1176
|
+
assert.equal(text(now.log), text(before.log));
|
|
1177
|
+
for (const json of [declaringJson, plainJson]) {
|
|
1178
|
+
for (const unlocks of [false, true]) {
|
|
1179
|
+
const old = await story(baseline.layer, { unlocks, json });
|
|
1180
|
+
const current = await story(here.layer, { unlocks, json });
|
|
1181
|
+
assert.equal(text(current.log), text(old.log), 'wearable-only and keyless visits match the pre-home kit byte for byte');
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
const hides = (a, b) => (a === 'p1' && b === 'p3') || (a === 'p3' && b === 'p1');
|
|
1185
|
+
const hiddenBefore = await story(baseline.layer, { unlocks: false, json: plainJson, hides });
|
|
1186
|
+
const hiddenNow = await story(here.layer, { unlocks: false, json: plainJson, hides });
|
|
1187
|
+
assert.equal(text(hiddenNow.log), text(hiddenBefore.log));
|
|
1188
|
+
info(`baseline with a hidden pair: ${Buffer.byteLength(text(hiddenBefore.log))} bytes identical`);
|
|
1189
|
+
info(`baseline: ${Buffer.byteLength(text(before.log))} bytes identical`);
|
|
1190
|
+
});
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
console.log = info;
|
|
1194
|
+
console.log(`test-earned: ${n} passed`);
|