castle-web-cli 0.4.232 → 0.4.234
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/api.d.ts +11 -0
- package/dist/api.js +43 -0
- package/dist/bundle.d.ts +64 -0
- package/dist/bundle.js +558 -2
- package/dist/castle-host/host.d.ts +18 -2
- package/dist/castle-host/host.js +844 -39
- package/dist/castleJson.d.ts +23 -2
- package/dist/castleJson.js +46 -2
- package/dist/check.d.ts +3 -1
- package/dist/check.js +20 -3
- package/dist/chunkLoader.d.ts +3 -0
- package/dist/chunkLoader.js +111 -0
- package/dist/devParty.d.ts +26 -0
- package/dist/devParty.js +231 -0
- package/dist/devSaveStorage.js +4 -0
- package/dist/devSessionStorage.js +50 -2
- package/dist/devSocial.d.ts +24 -0
- package/dist/devSocial.js +70 -0
- package/dist/ide.d.ts +2 -0
- package/dist/ide.js +119 -15
- 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 +11 -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 +25 -1
- package/dist/save-deck.js +178 -9
- package/dist/serve.js +32 -11
- package/dist/shell/assets/{index-D2tWM896.js → index-DulbYIJm.js} +97 -97
- 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/dist/vitePlugins.d.ts +2 -1
- package/dist/vitePlugins.js +13 -0
- package/kits/base/castle.json +1 -1
- package/kits/base/package-lock.json +1 -1
- package/kits/base/sdk/README.md +339 -5
- package/kits/base/sdk/avatar.d.ts +6 -2
- package/kits/base/sdk/avatar.js +12 -4
- package/kits/base/sdk/castle.d.ts +7 -3
- package/kits/base/sdk/castle.js +2 -0
- package/kits/base/sdk/commands.d.ts +176 -1
- package/kits/base/sdk/commands.js +3 -0
- package/kits/base/sdk/display.d.ts +3 -0
- package/kits/base/sdk/display.js +9 -3
- package/kits/base/sdk/hub.d.ts +37 -6
- package/kits/base/sdk/hub.js +63 -4
- package/kits/base/sdk/multiplayer.d.ts +7 -1
- package/kits/base/sdk/multiplayer.js +148 -32
- package/kits/base/sdk/multiplayerProtocol.d.ts +2 -0
- package/kits/base/sdk/party.d.ts +23 -0
- package/kits/base/sdk/party.js +91 -0
- package/kits/base/sdk/reconnectBudget.d.ts +23 -0
- package/kits/base/sdk/reconnectBudget.js +96 -0
- package/kits/base/sdk/save.d.ts +38 -1
- package/kits/base/sdk/save.js +81 -7
- package/kits/base/sdk/server/hub.d.ts +117 -0
- package/kits/base/sdk/server/hub.js +119 -2
- package/kits/base/sdk/server/platformHandle.d.ts +43 -1
- package/kits/base/sdk/server/storage.d.ts +17 -0
- package/kits/base/sdk/server/storage.js +65 -3
- package/kits/base/sdk/server/wrapper.d.ts +43 -6
- package/kits/base/sdk/server/wrapper.js +93 -9
- package/kits/base/sdk/social.d.ts +9 -0
- package/kits/base/sdk/social.js +5 -0
- package/kits/hub-game/CLAUDE.md +451 -13
- package/kits/hub-game/README.md +63 -0
- 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/castle.json +5 -5
- package/kits/hub-game/code/client/act.js +312 -0
- package/kits/hub-game/code/client/actionLayout.js +147 -0
- package/kits/hub-game/code/client/actionOverflow.js +556 -0
- package/kits/hub-game/code/client/actorBudget.js +47 -0
- package/kits/hub-game/code/client/arrivalCamera.js +50 -0
- package/kits/hub-game/code/client/askSlot.js +117 -0
- package/kits/hub-game/code/client/attention.js +11 -2
- package/kits/hub-game/code/client/avatar.js +311 -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 +253 -0
- package/kits/hub-game/code/client/backVisibility.js +13 -0
- package/kits/hub-game/code/client/ballot.js +472 -0
- package/kits/hub-game/code/client/build.js +38 -0
- package/kits/hub-game/code/client/chat.js +41 -5
- package/kits/hub-game/code/client/chatModeration.js +5 -0
- package/kits/hub-game/code/client/chrome.js +2144 -160
- 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/crowdNames.js +241 -0
- package/kits/hub-game/code/client/decor.js +515 -0
- package/kits/hub-game/code/client/defaultEnvironment.js +194 -0
- package/kits/hub-game/code/client/doorErrors.js +39 -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/fall.js +18 -0
- package/kits/hub-game/code/client/farAvatars.js +233 -0
- package/kits/hub-game/code/client/firstJoin.js +9 -2
- package/kits/hub-game/code/client/fpsTelemetry.js +50 -0
- package/kits/hub-game/code/client/frameBatch.js +5 -0
- package/kits/hub-game/code/client/grab.js +368 -29
- package/kits/hub-game/code/client/hookLayer.js +385 -20
- package/kits/hub-game/code/client/hudCopy.js +51 -0
- package/kits/hub-game/code/client/hudRate.js +20 -0
- package/kits/hub-game/code/client/idle.js +177 -24
- package/kits/hub-game/code/client/interestCap.js +81 -0
- package/kits/hub-game/code/client/invites.js +231 -0
- package/kits/hub-game/code/client/joinError.js +9 -0
- package/kits/hub-game/code/client/keys.js +36 -0
- package/kits/hub-game/code/client/labelsNear.js +234 -0
- package/kits/hub-game/code/client/landscapeLayout.js +17 -0
- package/kits/hub-game/code/client/layoutCache.js +264 -0
- package/kits/hub-game/code/client/loadTelemetry.js +20 -0
- package/kits/hub-game/code/client/loadingCover.js +148 -0
- package/kits/hub-game/code/client/loadingEntry.js +8 -0
- package/kits/hub-game/code/client/menuIcons.js +34 -0
- package/kits/hub-game/code/client/menuRows.js +43 -0
- package/kits/hub-game/code/client/modelReady.js +7 -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/padCueArrival.js +23 -0
- package/kits/hub-game/code/client/padCues.js +112 -0
- package/kits/hub-game/code/client/padOccupancy.js +88 -0
- package/kits/hub-game/code/client/padReadability.js +26 -0
- package/kits/hub-game/code/client/padRings.js +69 -0
- package/kits/hub-game/code/client/pushVisit.js +14 -0
- package/kits/hub-game/code/client/quality.js +205 -0
- package/kits/hub-game/code/client/qualityEntry.js +55 -0
- package/kits/hub-game/code/client/rehello.js +167 -0
- package/kits/hub-game/code/client/safeLayout.js +338 -0
- package/kits/hub-game/code/client/safeStyle.js +42 -0
- package/kits/hub-game/code/client/say.js +12 -3
- package/kits/hub-game/code/client/shot.js +146 -0
- package/kits/hub-game/code/client/shotFit.js +56 -0
- package/kits/hub-game/code/client/signIn.js +28 -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 +162 -1
- package/kits/hub-game/code/client/stuck.js +259 -0
- package/kits/hub-game/code/client/talk.js +714 -59
- package/kits/hub-game/code/client/tiers.js +543 -52
- package/kits/hub-game/code/client/toastBand.js +37 -0
- package/kits/hub-game/code/client/together.js +39 -2
- package/kits/hub-game/code/client/visibility.js +43 -0
- package/kits/hub-game/code/client/weakestLookBake.js +92 -0
- package/kits/hub-game/code/client/weakestTier.js +295 -0
- package/kits/hub-game/code/client/wear.js +461 -170
- package/kits/hub-game/code/client/worldLabels.js +241 -0
- package/kits/hub-game/code/client/yours.js +200 -0
- package/kits/hub-game/code/companionSpec.js +45 -0
- package/kits/hub-game/code/npcDisplayText.js +55 -0
- package/kits/hub-game/code/privateText.js +7 -0
- package/kits/hub-game/code/server/act.js +124 -0
- package/kits/hub-game/code/server/actions.js +138 -0
- package/kits/hub-game/code/server/actors.js +11 -2
- package/kits/hub-game/code/server/analytics.js +83 -0
- package/kits/hub-game/code/server/anonymousEntry.js +49 -0
- package/kits/hub-game/code/server/arrivalPose.js +36 -0
- 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 +107 -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/doorAnalytics.js +52 -0
- package/kits/hub-game/code/server/earned.js +478 -0
- package/kits/hub-game/code/server/frameBatch.js +183 -0
- package/kits/hub-game/code/server/friendBests.js +166 -0
- package/kits/hub-game/code/server/friendsAmong.js +272 -0
- package/kits/hub-game/code/server/history.js +7 -0
- package/kits/hub-game/code/server/hub.js +2510 -95
- package/kits/hub-game/code/server/idle.js +60 -12
- package/kits/hub-game/code/server/index.js +28 -6
- package/kits/hub-game/code/server/invites.js +19 -0
- package/kits/hub-game/code/server/labels.js +36 -2
- package/kits/hub-game/code/server/loadAbandon.js +106 -0
- package/kits/hub-game/code/server/manifest.js +586 -7
- package/kits/hub-game/code/server/menu.js +161 -0
- package/kits/hub-game/code/server/npcs.js +1025 -113
- package/kits/hub-game/code/server/observe.js +408 -0
- package/kits/hub-game/code/server/padOccupancy.js +85 -0
- package/kits/hub-game/code/server/party.js +2 -2
- package/kits/hub-game/code/server/players.js +30 -0
- package/kits/hub-game/code/server/resumePose.js +152 -0
- package/kits/hub-game/code/server/say.js +1 -1
- package/kits/hub-game/code/server/shot.js +110 -0
- package/kits/hub-game/code/server/standing.js +123 -0
- package/kits/hub-game/code/server/storageLimit.js +187 -0
- package/kits/hub-game/code/server/vis.js +175 -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/act.js +35 -0
- package/kits/hub-game/code/shared/cues.js +9 -0
- package/kits/hub-game/code/shared/danceIdle.js +28 -0
- package/kits/hub-game/code/shared/decor.js +41 -0
- package/kits/hub-game/code/shared/loadStages.js +12 -0
- package/kits/hub-game/code/shared/quality.js +74 -0
- package/kits/hub-game/code/shared/say.js +2 -0
- package/kits/hub-game/code/shared/shot.js +53 -0
- package/kits/hub-game/code/shared/spin.js +57 -0
- package/kits/hub-game/code/systems/hub.js +1753 -202
- package/kits/hub-game/docs/analytics.md +279 -0
- package/kits/hub-game/docs/content-pack.md +1 -1
- package/kits/hub-game/docs/contract.md +3475 -77
- package/kits/hub-game/docs/home-pieces.md +71 -0
- package/kits/hub-game/docs/observed-progress.md +252 -0
- package/kits/hub-game/main.jsx +2 -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 +10 -1
- package/kits/hub-game/package.json +6 -2
- package/kits/hub-game/play/player.js +142 -0
- package/kits/hub-game/play/registry.js +47 -0
- package/kits/hub-game/play.jsx +37 -0
- package/kits/hub-game/scripts/check.mjs +117 -16
- package/kits/hub-game/scripts/companion-follower-wire.json +1 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +132 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless.json +293 -0
- package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +26 -0
- package/kits/hub-game/scripts/fixtures/fake-dom.mjs +123 -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/pose-storage-fixture.mjs +46 -0
- package/kits/hub-game/scripts/soundscape-wave-analysis.mjs +125 -0
- package/kits/hub-game/scripts/test-act-client.mjs +186 -0
- package/kits/hub-game/scripts/test-act.mjs +171 -0
- package/kits/hub-game/scripts/test-action-layout.mjs +80 -0
- package/kits/hub-game/scripts/test-action-observers.mjs +46 -0
- package/kits/hub-game/scripts/test-actions-client.mjs +853 -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 +38 -23
- package/kits/hub-game/scripts/test-analytics.mjs +76 -0
- package/kits/hub-game/scripts/test-anonymous-entry.mjs +28 -0
- package/kits/hub-game/scripts/test-arrival-pose-server.mjs +196 -0
- package/kits/hub-game/scripts/test-arrival-pose.mjs +24 -0
- package/kits/hub-game/scripts/test-ask-client.mjs +358 -0
- package/kits/hub-game/scripts/test-ask-slot.mjs +85 -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 +792 -0
- package/kits/hub-game/scripts/test-avatar.mjs +584 -7
- package/kits/hub-game/scripts/test-back-visibility.mjs +82 -0
- package/kits/hub-game/scripts/test-ballot.mjs +1008 -0
- package/kits/hub-game/scripts/test-ban-join.mjs +121 -13
- package/kits/hub-game/scripts/test-build.mjs +49 -0
- package/kits/hub-game/scripts/test-cells.mjs +71 -0
- package/kits/hub-game/scripts/test-chat.mjs +863 -0
- package/kits/hub-game/scripts/test-classic.mjs +2 -0
- package/kits/hub-game/scripts/test-companion-chat.mjs +216 -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-control-layout-dom.mjs +120 -0
- package/kits/hub-game/scripts/test-crowd-names.mjs +205 -0
- package/kits/hub-game/scripts/test-decor-client.mjs +344 -0
- package/kits/hub-game/scripts/test-decor.mjs +464 -0
- package/kits/hub-game/scripts/test-default-environment-root.mjs +95 -0
- package/kits/hub-game/scripts/test-default-environment.mjs +267 -0
- package/kits/hub-game/scripts/test-door-analytics.mjs +58 -0
- package/kits/hub-game/scripts/test-door-jump.mjs +100 -0
- package/kits/hub-game/scripts/test-earned-client.mjs +459 -0
- package/kits/hub-game/scripts/test-earned.mjs +1224 -0
- package/kits/hub-game/scripts/test-emote-bubble.mjs +110 -0
- package/kits/hub-game/scripts/test-far-avatars.mjs +340 -0
- package/kits/hub-game/scripts/test-fps-telemetry.mjs +112 -0
- package/kits/hub-game/scripts/test-frame-batch.mjs +252 -0
- package/kits/hub-game/scripts/test-fresh-friends.mjs +118 -0
- package/kits/hub-game/scripts/test-friend-bests.mjs +435 -0
- package/kits/hub-game/scripts/test-grab-orbit.mjs +961 -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-high-only.mjs +170 -0
- package/kits/hub-game/scripts/test-hub-leaving.mjs +203 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +758 -2
- package/kits/hub-game/scripts/test-hub-trip.mjs +1594 -12
- package/kits/hub-game/scripts/test-hud-clear.mjs +484 -57
- package/kits/hub-game/scripts/test-hud-defects-dom.mjs +100 -0
- package/kits/hub-game/scripts/test-hud-rate.mjs +224 -0
- package/kits/hub-game/scripts/test-hud-safe-visibility-dom.mjs +83 -0
- package/kits/hub-game/scripts/test-idle.mjs +427 -1
- package/kits/hub-game/scripts/test-interest-cap.mjs +36 -0
- package/kits/hub-game/scripts/test-interest-cells.mjs +513 -0
- package/kits/hub-game/scripts/test-interest-client.mjs +118 -0
- package/kits/hub-game/scripts/test-interest.mjs +15 -0
- package/kits/hub-game/scripts/test-invites-client.mjs +430 -0
- package/kits/hub-game/scripts/test-invites.mjs +109 -0
- package/kits/hub-game/scripts/test-keys.mjs +46 -1
- package/kits/hub-game/scripts/test-labels.mjs +664 -0
- package/kits/hub-game/scripts/test-landscape-layout.mjs +194 -0
- package/kits/hub-game/scripts/test-list-scroll-dom.mjs +49 -0
- package/kits/hub-game/scripts/test-load-abandon.mjs +246 -0
- package/kits/hub-game/scripts/test-loading-cover.mjs +162 -0
- package/kits/hub-game/scripts/test-manifest.mjs +472 -0
- package/kits/hub-game/scripts/test-menu-client.mjs +585 -0
- package/kits/hub-game/scripts/test-menu.mjs +319 -0
- package/kits/hub-game/scripts/test-npcs.mjs +2528 -13
- package/kits/hub-game/scripts/test-object-entry.mjs +76 -0
- package/kits/hub-game/scripts/test-observed.mjs +745 -0
- package/kits/hub-game/scripts/test-pack.mjs +7 -0
- package/kits/hub-game/scripts/test-pad-cues.mjs +304 -0
- package/kits/hub-game/scripts/test-pad-occupancy.mjs +177 -0
- package/kits/hub-game/scripts/test-picker.mjs +541 -0
- package/kits/hub-game/scripts/test-placement-cache.mjs +690 -0
- package/kits/hub-game/scripts/test-progress-reset.mjs +559 -0
- package/kits/hub-game/scripts/test-push-visit.mjs +26 -0
- package/kits/hub-game/scripts/test-quality.mjs +385 -0
- package/kits/hub-game/scripts/test-rehello.mjs +1733 -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-resume-action-order.mjs +598 -0
- package/kits/hub-game/scripts/test-resume-held.mjs +239 -0
- package/kits/hub-game/scripts/test-resume-pose.mjs +142 -0
- package/kits/hub-game/scripts/test-safe-events-dom.mjs +116 -0
- package/kits/hub-game/scripts/test-safe-layout.mjs +330 -0
- package/kits/hub-game/scripts/test-say.mjs +1 -1
- package/kits/hub-game/scripts/test-shot.mjs +901 -0
- package/kits/hub-game/scripts/test-signin-client.mjs +45 -0
- package/kits/hub-game/scripts/test-soundscape.mjs +5437 -0
- package/kits/hub-game/scripts/test-spin.mjs +314 -0
- package/kits/hub-game/scripts/test-standing.mjs +449 -0
- package/kits/hub-game/scripts/test-storage-limit.mjs +333 -0
- package/kits/hub-game/scripts/test-stuck.mjs +1904 -0
- package/kits/hub-game/scripts/test-talk-overlay-dom.mjs +130 -0
- package/kits/hub-game/scripts/test-tier-cells.mjs +706 -0
- package/kits/hub-game/scripts/test-tiers-render.mjs +412 -0
- package/kits/hub-game/scripts/test-tiers.mjs +476 -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 +770 -0
- package/kits/hub-game/scripts/test-visibility.mjs +134 -0
- package/kits/hub-game/scripts/test-weakest-tier.mjs +924 -0
- package/kits/hub-game/scripts/test-world-labels.mjs +367 -0
- package/kits/hub-game/scripts/test-yours-chrome.mjs +210 -0
- package/kits/hub-game/scripts/test-yours.mjs +403 -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/joinFailure.js +27 -0
- package/kits/multiplayer-3d/code/client/nameTags.js +59 -4
- package/kits/multiplayer-3d/code/client/resumeGate.js +139 -0
- 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 +443 -34
- package/kits/multiplayer-3d/package-lock.json +8 -1
- package/kits/multiplayer-3d/package.json +3 -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-join-watchdog.mjs +436 -0
- package/kits/multiplayer-3d/scripts/test-own-name-tag.mjs +247 -0
- package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +624 -0
- package/kits/physics-2d/CLAUDE.md +19 -1
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/frozenActors.js +233 -0
- package/kits/physics-2d/engine/scene.js +337 -3
- 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/eslint.config.js +1 -1
- package/kits/physics-2d/play/behaviors/AnalogStick.js +198 -0
- package/kits/physics-2d/play/behaviors/Camera.js +40 -0
- package/kits/physics-2d/play/behaviors/Collider.js +122 -0
- package/kits/physics-2d/play/behaviors/Draggable.js +115 -0
- package/kits/physics-2d/play/behaviors/Goal.js +46 -0
- package/kits/physics-2d/play/behaviors/Joints.js +126 -0
- package/kits/physics-2d/play/behaviors/Layout.js +71 -0
- package/kits/physics-2d/play/behaviors/RigidBody.js +57 -0
- package/kits/physics-2d/play/behaviors/Slingshot.js +142 -0
- package/kits/physics-2d/play/behaviors/SoundPlayer.js +263 -0
- package/kits/physics-2d/play/behaviors/Sprite.js +406 -0
- package/kits/physics-2d/play/behaviors/Style.js +209 -0
- package/kits/physics-2d/play/behaviors/Text.js +85 -0
- package/kits/physics-2d/play/behaviors/Video.js +93 -0
- package/kits/physics-2d/scripts/test-skip-unchanged.mjs +326 -1
- package/kits/physics-3d/CLAUDE.md +42 -529
- package/kits/physics-3d/behaviors/Body.jsx +3 -0
- package/kits/physics-3d/behaviors/Model.jsx +3 -0
- package/kits/physics-3d/behaviors/Player.jsx +661 -87
- package/kits/physics-3d/behaviors/Shape.jsx +3 -0
- package/kits/physics-3d/behaviors/Solid.jsx +3 -0
- package/kits/physics-3d/behaviors/Transform.jsx +3 -0
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/docs/engine-camera.md +542 -0
- package/kits/physics-3d/docs/engine-frame-cap.md +136 -0
- package/kits/physics-3d/docs/engine-load.md +149 -0
- package/kits/physics-3d/docs/engine-look.md +114 -0
- package/kits/physics-3d/docs/engine-shadows.md +372 -0
- package/kits/physics-3d/docs/engine-skip-work.md +187 -0
- package/kits/physics-3d/docs/engine-sky.md +198 -0
- package/kits/physics-3d/docs/engine-static-actors.md +226 -0
- package/kits/physics-3d/docs/engine-view.md +37 -0
- package/kits/physics-3d/docs/pxmodel-format.md +9 -1
- package/kits/physics-3d/engine3d/PlayOnly3D.jsx +5 -1
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +19 -277
- package/kits/physics-3d/engine3d/actornode.js +87 -0
- package/kits/physics-3d/engine3d/animationBudget.js +23 -0
- package/kits/physics-3d/engine3d/branches.js +3 -13
- package/kits/physics-3d/engine3d/cage.js +2 -7
- package/kits/physics-3d/engine3d/cageops.js +2 -17
- package/kits/physics-3d/engine3d/dataBehaviors.js +12 -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 +99 -0
- package/kits/physics-3d/engine3d/frozenphysics.js +140 -0
- package/kits/physics-3d/engine3d/frozenstatics.js +273 -0
- package/kits/physics-3d/engine3d/gait.js +126 -0
- package/kits/physics-3d/engine3d/initialModelFiles.js +18 -0
- package/kits/physics-3d/engine3d/kithooks.js +47 -0
- package/kits/physics-3d/engine3d/look.js +514 -48
- package/kits/physics-3d/engine3d/lookbake.js +208 -0
- package/kits/physics-3d/engine3d/materialpresets.js +2 -0
- package/kits/physics-3d/engine3d/modelFiles.js +3 -17
- package/kits/physics-3d/engine3d/modelMath.js +49 -0
- package/kits/physics-3d/engine3d/modelready.js +16 -0
- package/kits/physics-3d/engine3d/motion.js +39 -10
- package/kits/physics-3d/engine3d/nearshadows.js +106 -21
- package/kits/physics-3d/engine3d/optimize.js +9 -5
- package/kits/physics-3d/engine3d/orbitinput.js +522 -10
- package/kits/physics-3d/engine3d/orbitlens.js +48 -0
- package/kits/physics-3d/engine3d/ownmodel.js +213 -0
- package/kits/physics-3d/engine3d/partgeometry.js +1 -16
- package/kits/physics-3d/engine3d/paths.js +1 -9
- package/kits/physics-3d/engine3d/playTimings.js +50 -0
- package/kits/physics-3d/engine3d/playerRun.js +372 -0
- package/kits/physics-3d/engine3d/pxmodel.js +42 -11
- package/kits/physics-3d/engine3d/rapier.js +27 -0
- package/kits/physics-3d/engine3d/scatter.js +1 -11
- package/kits/physics-3d/engine3d/shadowfade.js +890 -0
- package/kits/physics-3d/engine3d/sky.js +547 -0
- package/kits/physics-3d/engine3d/skylife.js +306 -0
- package/kits/physics-3d/engine3d/squarefirst.js +177 -0
- package/kits/physics-3d/engine3d/stillshadows.js +399 -0
- package/kits/physics-3d/engine3d/sweep.js +1 -25
- 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 +1253 -76
- package/kits/physics-3d/eslint.config.js +2 -1
- package/kits/physics-3d/main.jsx +10 -2
- package/kits/physics-3d/package-lock.json +7 -0
- package/kits/physics-3d/package.json +5 -1
- package/kits/physics-3d/play/behaviors/Body.js +31 -0
- package/kits/physics-3d/play/behaviors/Door.js +37 -0
- package/kits/physics-3d/play/behaviors/Lookable.js +16 -0
- package/kits/physics-3d/play/behaviors/Model.js +23 -0
- package/kits/physics-3d/play/behaviors/Pickup.js +46 -0
- package/kits/physics-3d/play/behaviors/Player.js +1204 -0
- package/kits/physics-3d/play/behaviors/Shape.js +47 -0
- package/kits/physics-3d/play/behaviors/Solid.js +16 -0
- package/kits/physics-3d/play/behaviors/Transform.js +29 -0
- package/kits/physics-3d/pnpm-lock.yaml +8 -0
- package/kits/physics-3d/scripts/bench-shadow-fade.mjs +37 -0
- package/kits/physics-3d/scripts/build-rapier-gz.mjs +56 -0
- package/kits/physics-3d/scripts/frozen-statics-fixture.mjs +141 -0
- package/kits/physics-3d/scripts/look-baseline.mjs +155 -0
- package/kits/physics-3d/scripts/test-camera-follow.mjs +5 -1
- package/kits/physics-3d/scripts/test-camera-orbit.mjs +2613 -82
- package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +2 -2
- package/kits/physics-3d/scripts/test-empty-gait-hints.mjs +89 -0
- package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +438 -0
- package/kits/physics-3d/scripts/test-frame-cap.mjs +452 -0
- package/kits/physics-3d/scripts/test-frozen-nested.mjs +49 -0
- package/kits/physics-3d/scripts/test-frozen-statics-legacy-physics2d.mjs +123 -0
- package/kits/physics-3d/scripts/test-frozen-statics.mjs +434 -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 +5 -2
- package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +2001 -0
- package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +582 -0
- package/kits/physics-3d/scripts/test-orbit-shot.mjs +657 -0
- package/kits/physics-3d/scripts/test-orbit-view.mjs +230 -0
- package/kits/physics-3d/scripts/test-rapier-gz.mjs +106 -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-square-first.mjs +921 -0
- package/kits/physics-3d/scripts/test-static-actors.mjs +10 -1
- package/kits/physics-3d/scripts/test-static-physics.mjs +4 -1
- package/kits/physics-3d/scripts/test-static-scenery.mjs +2174 -0
- package/kits/physics-3d/scripts/test-steady-hover.mjs +7 -2
- package/kits/physics-3d/scripts/test-still-shadows.mjs +477 -0
- package/kits/physics-3d/scripts/test-view-range.mjs +260 -0
- package/kits/physics-3d/systems/physics3d.js +419 -9
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/client/connection.js +33 -10
- package/kits/real-time/code/client/gameHooks.js +2 -0
- package/kits/real-time/code/client/joinOverlay.js +9 -4
- package/kits/real-time/code/server/gameHooks.js +7 -0
- package/kits/real-time/code/server/session.js +102 -22
- package/kits/real-time/package-lock.json +1 -1
- package/package.json +2 -2
- package/dist/shell/assets/index-Cf61cNfT.css +0 -1
|
@@ -0,0 +1,1008 @@
|
|
|
1
|
+
// The choice card (contract v1.68, `hub.ballot`): the manifest's fixed lines,
|
|
2
|
+
// the server's card checks, per-viewer views, blocks, the tap checks and
|
|
3
|
+
// limits and the `ballot` hook; a place without the key is exactly what it
|
|
4
|
+
// was; and the client words the card from ids. `npm run check` runs it; it
|
|
5
|
+
// needs nothing installed.
|
|
6
|
+
|
|
7
|
+
import assert from 'node:assert/strict';
|
|
8
|
+
import { register } from 'node:module';
|
|
9
|
+
|
|
10
|
+
const sceneStub = 'export const readScene = () => globalThis.__hubTestActors ?? [];';
|
|
11
|
+
const avatarsStub = 'export function dropMissing() {}';
|
|
12
|
+
register(
|
|
13
|
+
`data:text/javascript,${encodeURIComponent(`
|
|
14
|
+
import { readFile } from 'node:fs/promises';
|
|
15
|
+
import { fileURLToPath } from 'node:url';
|
|
16
|
+
const stubs = {
|
|
17
|
+
'@imports/castle.multiplayer-3d/code/server/sceneBodies.js': 'data:text/javascript,${encodeURIComponent(sceneStub)}',
|
|
18
|
+
'@imports/castle.multiplayer-3d/code/client/avatars.js': 'data:text/javascript,${encodeURIComponent(avatarsStub)}',
|
|
19
|
+
'castle-web-sdk': ${JSON.stringify(new URL('./fixtures/sdk-stub.mjs', import.meta.url).href)},
|
|
20
|
+
};
|
|
21
|
+
export async function resolve(specifier, context, next) {
|
|
22
|
+
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 };
|
|
23
|
+
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 };
|
|
24
|
+
if (stubs[specifier]) {
|
|
25
|
+
return { url: stubs[specifier], shortCircuit: true };
|
|
26
|
+
}
|
|
27
|
+
return next(specifier, context);
|
|
28
|
+
}
|
|
29
|
+
// The hook layer reads the deck's castle.json through the bundler.
|
|
30
|
+
export async function load(url, context, next) {
|
|
31
|
+
if (url.endsWith('/code/client/hookLayer.js')) {
|
|
32
|
+
const source = await readFile(fileURLToPath(url), 'utf8');
|
|
33
|
+
return { format: 'module', source: source.replaceAll('import.meta.glob(', '(() => ({}))('), shortCircuit: true };
|
|
34
|
+
}
|
|
35
|
+
return next(url, context);
|
|
36
|
+
}
|
|
37
|
+
`)}`,
|
|
38
|
+
);
|
|
39
|
+
const { layer } = await import('../code/server/hub.js');
|
|
40
|
+
const { readManifest, publicPlace } = await import('../code/server/manifest.js');
|
|
41
|
+
const Ballot = await import('../code/server/ballot.js');
|
|
42
|
+
const Client = await import('../code/client/ballot.js');
|
|
43
|
+
const hookLayer = (await import('../code/client/hookLayer.js')).default;
|
|
44
|
+
const State = await import('../code/client/state.js');
|
|
45
|
+
|
|
46
|
+
globalThis.__hubTestActors = [{ id: 'spawn', components: { Player: {}, Transform: { x: 0, y: 1, z: 0 } } }];
|
|
47
|
+
const LINES = [
|
|
48
|
+
{ id: 'boat', text: 'I saw them by the boat', about: 'face' },
|
|
49
|
+
{ id: 'sus', text: 'Acting strange', about: 'face' },
|
|
50
|
+
{ id: 'not-me', text: 'Not me!', about: 'self' },
|
|
51
|
+
];
|
|
52
|
+
const deck = (ballot, extra = {}) => ({
|
|
53
|
+
server: { maxPlayers: 8 },
|
|
54
|
+
hub: { contract: 1, title: 'Sneaks', result: { outcomes: ['win', 'lose'] }, ...(ballot === undefined || ballot === 'absent' ? {} : { ballot }), ...extra },
|
|
55
|
+
});
|
|
56
|
+
const scenes = () => true;
|
|
57
|
+
const errorsOf = (ballot) => readManifest(deck(ballot), scenes).errors;
|
|
58
|
+
let n = 0;
|
|
59
|
+
|
|
60
|
+
// --- the manifest ---------------------------------------------------------
|
|
61
|
+
{
|
|
62
|
+
const { manifest } = readManifest(deck({ lines: LINES }), scenes);
|
|
63
|
+
assert.deepEqual(manifest.places.main.ballot, { lines: LINES });
|
|
64
|
+
assert.deepEqual(publicPlace('main', manifest.places.main).ballot, { lines: LINES });
|
|
65
|
+
assert.deepEqual(readManifest(deck(true), scenes).manifest.places.main.ballot, { lines: [] });
|
|
66
|
+
assert.deepEqual(readManifest(deck({}), scenes).manifest.places.main.ballot, { lines: [] });
|
|
67
|
+
for (const off of [undefined, false]) {
|
|
68
|
+
const place = readManifest(deck(off), scenes).manifest.places.main;
|
|
69
|
+
assert.ok(!('ballot' in place));
|
|
70
|
+
assert.ok(!('ballot' in publicPlace('main', place)));
|
|
71
|
+
}
|
|
72
|
+
// Text is trimmed; a place of its own may declare it too.
|
|
73
|
+
assert.equal(readManifest(deck({ lines: [{ id: 'a', text: ' Hi ', about: 'self' }] }), scenes).manifest.places.main.ballot.lines[0].text, 'Hi');
|
|
74
|
+
const places = readManifest(deck(undefined, { places: { meet: { title: 'Meeting', scene: 'scenes/meet.scene', ballot: { lines: [LINES[2]] } } } }), scenes).manifest.places;
|
|
75
|
+
assert.deepEqual(places.meet.ballot, { lines: [LINES[2]] });
|
|
76
|
+
assert.ok(!('ballot' in places.main));
|
|
77
|
+
n += 1;
|
|
78
|
+
}
|
|
79
|
+
{
|
|
80
|
+
const line = (over) => ({ lines: [{ id: 'a', text: 'Hi', about: 'self', ...over }] });
|
|
81
|
+
assert.match(errorsOf('yes').join(), /ballot must be true, false or an object/);
|
|
82
|
+
assert.match(errorsOf({ lines: LINES, extra: 1 }).join(), /ballot\.extra is not part/);
|
|
83
|
+
assert.match(errorsOf(line({ id: 'Boat' })).join(), /\.id must be/);
|
|
84
|
+
assert.match(errorsOf(line({ id: 'a'.repeat(25) })).join(), /\.id must be/);
|
|
85
|
+
assert.match(errorsOf(line({ text: '' })).join(), /\.text must be 1-40/);
|
|
86
|
+
assert.match(errorsOf(line({ text: 'x'.repeat(41) })).join(), /\.text must be 1-40/);
|
|
87
|
+
assert.match(errorsOf(line({ text: 'two\nlines' })).join(), /\.text must be 1-40/);
|
|
88
|
+
assert.match(errorsOf(line({ about: 'them' })).join(), /\.about must be/);
|
|
89
|
+
assert.match(errorsOf(line({ about: undefined })).join(), /\.about must be/);
|
|
90
|
+
assert.match(errorsOf(line({ said: 'x' })).join(), /lines\[0\]\.said is not part/);
|
|
91
|
+
assert.match(errorsOf({ lines: [LINES[0], { ...LINES[1], id: 'boat' }] }).join(), /listed twice/);
|
|
92
|
+
assert.match(errorsOf({ lines: Array.from({ length: 33 }, (_, i) => ({ id: `l${i}`, text: 'x', about: 'self' })) }).join(), /at most 32/);
|
|
93
|
+
assert.deepEqual(errorsOf({ lines: Array.from({ length: 32 }, (_, i) => ({ id: `l${i}`, text: 'x', about: 'self' })) }), []);
|
|
94
|
+
assert.match(errorsOf({ lines: 'boat' }).join(), /at most 32/);
|
|
95
|
+
n += 1;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// --- the server -------------------------------------------------------------
|
|
99
|
+
const ROSTER = ['p1', 'p2', 'p3', 'p4'].map((playerId, i) => ({ playerId, userId: String(101 + i), username: ['amy', 'bo', 'cy', 'di'][i] }));
|
|
100
|
+
function boot({ ballot = { lines: LINES }, hiddenPair = null, hooks = {}, extra = {} } = {}) {
|
|
101
|
+
const calls = [];
|
|
102
|
+
const heard = [];
|
|
103
|
+
const deckHooks = {
|
|
104
|
+
ballot: (hub, playerId, tap) => calls.push([playerId, tap]),
|
|
105
|
+
message: (hub, player, data) => heard.push([player.playerId, data]),
|
|
106
|
+
...hooks,
|
|
107
|
+
};
|
|
108
|
+
const h = layer(deck(ballot, extra), deckHooks, {}, scenes);
|
|
109
|
+
const sent = [];
|
|
110
|
+
const session = {
|
|
111
|
+
sessionId: 'dev:test',
|
|
112
|
+
players: ROSTER,
|
|
113
|
+
send: (playerId, msg) => sent.push([playerId, JSON.parse(JSON.stringify(msg))]),
|
|
114
|
+
broadcast: (msg) => sent.push(['*', JSON.parse(JSON.stringify(msg))]),
|
|
115
|
+
...(hiddenPair
|
|
116
|
+
? { hub: { place: 'main', arrival: () => null, readResults: async () => ({ players: {}, boards: {} }), updatePad: async () => ({}), reportResult: async () => ({}), hiddenPair } }
|
|
117
|
+
: {}),
|
|
118
|
+
};
|
|
119
|
+
h.sceneFor(session);
|
|
120
|
+
const players = new Map(ROSTER.map(({ playerId }) => [playerId, { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } }]));
|
|
121
|
+
const world = { timeMs: 0, players, bodies: new Map(), scenePath: 'scenes/main.scene' };
|
|
122
|
+
h.ready(world);
|
|
123
|
+
ROSTER.forEach(({ playerId }, i) => h.message(session, { playerId }, { k: 'hub-hello', avatar: i + 3 }));
|
|
124
|
+
const realNow = Date.now;
|
|
125
|
+
Date.now = () => realNow() + 5000;
|
|
126
|
+
h.place(world, []);
|
|
127
|
+
Date.now = realNow;
|
|
128
|
+
const hub = captured.ctx;
|
|
129
|
+
sent.length = 0;
|
|
130
|
+
const tick = () => {
|
|
131
|
+
world.timeMs += 50;
|
|
132
|
+
h.step(world, []);
|
|
133
|
+
};
|
|
134
|
+
return { h, hub, session, world, sent, calls, heard, tick };
|
|
135
|
+
}
|
|
136
|
+
// The deck's `hub` is the context its hooks are handed: caught from `ready`.
|
|
137
|
+
const captured = {};
|
|
138
|
+
const b2calls = [];
|
|
139
|
+
// A tap as the client makes it: on the card last delivered to that player,
|
|
140
|
+
// carrying its version (rule A), unless the test names a `v` itself.
|
|
141
|
+
const deliveredTo = (b, playerId) => b.sent.filter(([to, msg]) => to === playerId && msg.k === 'hub-ballot-card').at(-1)?.[1].card ?? null;
|
|
142
|
+
const tapAs = (b, playerId, data) =>
|
|
143
|
+
b.h.message(b.session, { playerId }, { k: 'hub-ballot', ...(Object.hasOwn(data, 'v') ? {} : { v: deliveredTo(b, playerId)?.v }), ...data });
|
|
144
|
+
const cards = (b) => b.sent.filter(([, msg]) => msg.k === 'hub-ballot-card');
|
|
145
|
+
const warns = [];
|
|
146
|
+
const realWarn = console.warn;
|
|
147
|
+
console.warn = (...args) => warns.push(args.join(' '));
|
|
148
|
+
const realLog = console.log;
|
|
149
|
+
console.log = () => {};
|
|
150
|
+
|
|
151
|
+
function withCtx(options = {}) {
|
|
152
|
+
const hooks = { ready: (hub) => { captured.ctx = hub; }, ...(options.hooks ?? {}) };
|
|
153
|
+
return boot({ ...options, hooks });
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const FACES = [{ playerId: 'p1' }, { playerId: 'p2', note: 'on the bench' }, { playerId: 'p3', off: true, note: 'out' }, { playerId: 'p4', mark: '#FF0000' }];
|
|
157
|
+
|
|
158
|
+
// A card for everyone: each player is sent their own view once, with the
|
|
159
|
+
// kit's names and avatars; nothing more until it changes.
|
|
160
|
+
{
|
|
161
|
+
const b = withCtx();
|
|
162
|
+
assert.equal(b.hub.ballot(null, { title: 'Meeting', text: 'Who was it?', until: 30_000, faces: FACES, options: [{ id: 'skip', text: 'Skip' }] }), true);
|
|
163
|
+
b.tick();
|
|
164
|
+
const got = cards(b);
|
|
165
|
+
assert.deepEqual(got.map(([to]) => to), ['p1', 'p2', 'p3', 'p4']);
|
|
166
|
+
const { v: firstV, ...card } = got[0][1].card;
|
|
167
|
+
// The version is an opaque string: this server's epoch and a counter.
|
|
168
|
+
assert.match(firstV, /^[0-9a-z]+-1$/);
|
|
169
|
+
assert.deepEqual(card, {
|
|
170
|
+
mode: 'talk',
|
|
171
|
+
title: 'Meeting',
|
|
172
|
+
text: 'Who was it?',
|
|
173
|
+
until: 30_000,
|
|
174
|
+
faces: [{ id: 'p1' }, { id: 'p2', note: 'on the bench' }, { id: 'p3', note: 'out', off: true }, { id: 'p4', mark: '#ff0000' }],
|
|
175
|
+
options: [{ id: 'skip', text: 'Skip' }],
|
|
176
|
+
lines: ['boat', 'sus', 'not-me'],
|
|
177
|
+
feed: [],
|
|
178
|
+
who: { p1: { name: 'amy', avatar: 3 }, p2: { name: 'bo', avatar: 4 }, p3: { name: 'cy', avatar: 5 }, p4: { name: 'di', avatar: 6 } },
|
|
179
|
+
});
|
|
180
|
+
b.sent.length = 0;
|
|
181
|
+
b.tick();
|
|
182
|
+
assert.equal(cards(b).length, 0);
|
|
183
|
+
// Per-player replaces shared for that player; clearing it shows shared again.
|
|
184
|
+
assert.equal(b.hub.ballot(['p2', 'nobody'], { mode: 'vote', faces: FACES, picked: { face: 'p1' } }), true);
|
|
185
|
+
b.tick();
|
|
186
|
+
assert.deepEqual(cards(b).map(([to, msg]) => [to, msg.card.mode, msg.card.picked]), [['p2', 'vote', { face: 'p1' }]]);
|
|
187
|
+
b.sent.length = 0;
|
|
188
|
+
b.hub.ballot(['p2'], null);
|
|
189
|
+
b.tick();
|
|
190
|
+
assert.deepEqual(cards(b).map(([to, msg]) => [to, msg.card.mode]), [['p2', 'talk']]);
|
|
191
|
+
// Clearing for everyone clears every card, a player's own included.
|
|
192
|
+
b.hub.ballot(['p3'], { mode: 'reveal', faces: FACES });
|
|
193
|
+
b.tick();
|
|
194
|
+
b.sent.length = 0;
|
|
195
|
+
b.hub.ballot(null, null);
|
|
196
|
+
b.tick();
|
|
197
|
+
assert.deepEqual(cards(b).map(([to, msg]) => [to, msg.card]), [['p1', null], ['p2', null], ['p3', null], ['p4', null]]);
|
|
198
|
+
// A client that joins afresh is sent its card again; a second hello (an avatar change) is not.
|
|
199
|
+
b.hub.ballot(null, { faces: FACES });
|
|
200
|
+
b.tick();
|
|
201
|
+
b.sent.length = 0;
|
|
202
|
+
b.h.message(b.session, { playerId: 'p1' }, { k: 'hub-hello', avatar: 3, again: true });
|
|
203
|
+
b.tick();
|
|
204
|
+
assert.equal(cards(b).length, 0);
|
|
205
|
+
b.h.message(b.session, { playerId: 'p1' }, { k: 'hub-hello', avatar: 3 });
|
|
206
|
+
b.tick();
|
|
207
|
+
assert.deepEqual(cards(b).map(([to]) => to), ['p1']);
|
|
208
|
+
n += 1;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// A bad card warns once and changes nothing; so does a place without the key.
|
|
212
|
+
{
|
|
213
|
+
const b = withCtx();
|
|
214
|
+
const bad = [
|
|
215
|
+
'card',
|
|
216
|
+
{ mode: 'shout' },
|
|
217
|
+
{ title: 'x'.repeat(41) },
|
|
218
|
+
{ text: 'x'.repeat(121) },
|
|
219
|
+
{ until: Infinity },
|
|
220
|
+
{ faces: [{ playerId: 'p1' }, { playerId: 'p1' }] },
|
|
221
|
+
{ faces: [{ playerId: 'p1', note: 'x'.repeat(25) }] },
|
|
222
|
+
{ faces: [{ playerId: 'p1', votes: -1 }] },
|
|
223
|
+
{ faces: [{ playerId: 'p1', mark: 'red' }] },
|
|
224
|
+
{ faces: [{ playerId: 'p1', name: 'evil' }] },
|
|
225
|
+
{ faces: Array.from({ length: 25 }, (_, i) => ({ playerId: `x${i}` })) },
|
|
226
|
+
{ options: [{ id: 'skip', text: 'x'.repeat(33) }] },
|
|
227
|
+
{ options: [{ id: 'Skip', text: 'Skip' }] },
|
|
228
|
+
{ lines: ['nope'] },
|
|
229
|
+
{ feed: [{ from: 'p1', line: 'boat' }] },
|
|
230
|
+
{ feed: [{ from: 'p1', to: 'p2', line: 'not-me' }] },
|
|
231
|
+
{ feed: Array.from({ length: 7 }, () => ({ from: 'p1', line: 'not-me' })) },
|
|
232
|
+
{ picked: { face: 'p9' }, faces: FACES },
|
|
233
|
+
{ words: 'hello' },
|
|
234
|
+
];
|
|
235
|
+
for (const spec of bad) {
|
|
236
|
+
assert.equal(b.hub.ballot(null, spec), false, JSON.stringify(spec));
|
|
237
|
+
}
|
|
238
|
+
assert.equal(b.hub.ballot('p1', { faces: FACES }), false);
|
|
239
|
+
b.tick();
|
|
240
|
+
assert.equal(cards(b).length, 0);
|
|
241
|
+
const before = warns.length;
|
|
242
|
+
b.hub.ballot(null, { mode: 'shout' });
|
|
243
|
+
assert.equal(warns.length, before);
|
|
244
|
+
n += 1;
|
|
245
|
+
}
|
|
246
|
+
{
|
|
247
|
+
const b = withCtx({ ballot: 'absent' });
|
|
248
|
+
// A deck that declares no card anywhere has no `hub.ballot` at all.
|
|
249
|
+
assert.equal('ballot' in b.hub, false);
|
|
250
|
+
// Keys absent: no card is ever sent, the snapshot's place has no ballot,
|
|
251
|
+
// and a `hub-ballot` message is the deck's own, as it always was.
|
|
252
|
+
b.tick();
|
|
253
|
+
assert.equal(b.sent.length, 0);
|
|
254
|
+
assert.ok(!('ballot' in b.h.join({ playerId: 'p1' }).hubPlace));
|
|
255
|
+
tapAs(b, 'p1', { v: 3, face: 'p2', line: 'boat' });
|
|
256
|
+
assert.deepEqual(b.heard, [['p1', { k: 'hub-ballot', v: 3, face: 'p2', line: 'boat' }]]);
|
|
257
|
+
assert.equal(b.calls.length, 0);
|
|
258
|
+
n += 1;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// A deck with a card in another place: `hub.ballot` here refuses, once.
|
|
262
|
+
{
|
|
263
|
+
warns.length = 0;
|
|
264
|
+
const b = withCtx({ ballot: 'absent', extra: { places: { meet: { title: 'Meeting', scene: 'scenes/meet.scene', ballot: true } } } });
|
|
265
|
+
assert.equal(b.hub.ballot(null, { faces: FACES }), false);
|
|
266
|
+
assert.equal(b.hub.ballot(null, { faces: FACES }), false);
|
|
267
|
+
assert.equal(warns.filter((w) => w.includes('hub.ballot')).length, 1);
|
|
268
|
+
b.tick();
|
|
269
|
+
assert.equal(cards(b).length, 0);
|
|
270
|
+
n += 1;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// Taps: ids only, checked against the card this player was sent.
|
|
274
|
+
{
|
|
275
|
+
const b = withCtx();
|
|
276
|
+
b.hub.ballot(null, { faces: FACES, options: [{ id: 'skip', text: 'Skip' }], lines: ['boat', 'not-me'] });
|
|
277
|
+
// Nothing before the card has been sent.
|
|
278
|
+
tapAs(b, 'p1', { line: 'not-me' });
|
|
279
|
+
assert.equal(b.calls.length, 0);
|
|
280
|
+
b.tick();
|
|
281
|
+
const refused = [
|
|
282
|
+
{ face: 'p2', line: 'not-me' }, // a line about oneself takes no face
|
|
283
|
+
{ line: 'boat' }, // a line about a face needs one
|
|
284
|
+
{ face: 'p3', line: 'boat' }, // an off face
|
|
285
|
+
{ face: 'p9', line: 'boat' }, // not on the card
|
|
286
|
+
{ face: 'p2', line: 'sus' }, // not offered now
|
|
287
|
+
{ face: 'p2', line: 'boat', text: 'free words' }, // nothing typed is carried
|
|
288
|
+
{ line: 'not-me', option: 'skip' },
|
|
289
|
+
{ option: 'nope' },
|
|
290
|
+
{ face: 'p2' }, // talk: a face alone says nothing
|
|
291
|
+
{ face: 7, line: 'boat' },
|
|
292
|
+
];
|
|
293
|
+
for (const data of refused) {
|
|
294
|
+
tapAs(b, 'p1', data);
|
|
295
|
+
}
|
|
296
|
+
assert.deepEqual(b.calls, []);
|
|
297
|
+
assert.deepEqual(b.heard, []);
|
|
298
|
+
tapAs(b, 'p1', { face: 'p2', line: 'boat' });
|
|
299
|
+
tapAs(b, 'p2', { line: 'not-me' });
|
|
300
|
+
tapAs(b, 'p3', { option: 'skip' });
|
|
301
|
+
assert.deepEqual(b.calls, [
|
|
302
|
+
['p1', { face: 'p2', line: 'boat', option: null, mode: 'talk' }],
|
|
303
|
+
['p2', { face: null, line: 'not-me', option: null, mode: 'talk' }],
|
|
304
|
+
['p3', { face: null, line: null, option: 'skip', mode: 'talk' }],
|
|
305
|
+
]);
|
|
306
|
+
// A burst of three, then one every 1.5 s.
|
|
307
|
+
b.calls.length = 0;
|
|
308
|
+
for (let i = 0; i < 5; i += 1) {
|
|
309
|
+
tapAs(b, 'p4', { line: 'not-me' });
|
|
310
|
+
}
|
|
311
|
+
assert.equal(b.calls.length, 3);
|
|
312
|
+
const realNow = Date.now;
|
|
313
|
+
Date.now = () => realNow() + 1600;
|
|
314
|
+
tapAs(b, 'p4', { line: 'not-me' });
|
|
315
|
+
tapAs(b, 'p4', { line: 'not-me' });
|
|
316
|
+
Date.now = realNow;
|
|
317
|
+
assert.equal(b.calls.length, 4);
|
|
318
|
+
n += 1;
|
|
319
|
+
}
|
|
320
|
+
{
|
|
321
|
+
const b = withCtx();
|
|
322
|
+
b.hub.ballot(null, { mode: 'vote', faces: FACES, options: [{ id: 'skip', text: 'Skip' }] });
|
|
323
|
+
b.hub.ballot(['p4'], { mode: 'vote', faces: FACES, picked: { option: 'skip' }, options: [{ id: 'skip', text: 'Skip' }] });
|
|
324
|
+
b.tick();
|
|
325
|
+
for (const data of [{ face: 'p2', line: 'boat' }, { line: 'not-me' }, {}, { face: 'p3' }, { face: 'p2', option: 'skip' }]) {
|
|
326
|
+
tapAs(b, 'p1', data);
|
|
327
|
+
}
|
|
328
|
+
tapAs(b, 'p4', { face: 'p2' }); // locked in already
|
|
329
|
+
assert.deepEqual(b.calls, []);
|
|
330
|
+
tapAs(b, 'p1', { face: 'p2' });
|
|
331
|
+
tapAs(b, 'p2', { option: 'skip' });
|
|
332
|
+
assert.deepEqual(b.calls, [
|
|
333
|
+
['p1', { face: 'p2', line: null, option: null, mode: 'vote' }],
|
|
334
|
+
['p2', { face: null, line: null, option: 'skip', mode: 'vote' }],
|
|
335
|
+
]);
|
|
336
|
+
b.hub.ballot(null, { mode: 'reveal', faces: FACES.map((f, i) => ({ ...f, votes: i })) });
|
|
337
|
+
b.hub.ballot(['p4'], null);
|
|
338
|
+
b.tick();
|
|
339
|
+
tapAs(b, 'p1', { face: 'p2' });
|
|
340
|
+
assert.equal(b.calls.length, 2);
|
|
341
|
+
n += 1;
|
|
342
|
+
}
|
|
343
|
+
// A hook that throws is the deck's problem, not the session's.
|
|
344
|
+
{
|
|
345
|
+
const b = withCtx({ hooks: { ballot: () => { throw new Error('boom'); } } });
|
|
346
|
+
b.hub.ballot(null, { faces: FACES });
|
|
347
|
+
b.tick();
|
|
348
|
+
assert.doesNotThrow(() => tapAs(b, 'p1', { line: 'not-me' }));
|
|
349
|
+
n += 1;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// Blocks: a player hidden from the viewer is not on their card, no feed row
|
|
353
|
+
// names them, and their name is out of the deck's words.
|
|
354
|
+
{
|
|
355
|
+
const b = withCtx({ hiddenPair: (x, y) => [x, y].sort().join() === 'p1,p2' });
|
|
356
|
+
b.hub.ballot(null, { title: 'bo is out', faces: FACES, feed: [{ from: 'p2', to: 'p4', line: 'boat' }, { from: 'p4', line: 'not-me' }, { from: 'p3', to: 'p2', line: 'boat' }] });
|
|
357
|
+
b.tick();
|
|
358
|
+
const view = (to) => cards(b).find(([id]) => id === to)[1].card;
|
|
359
|
+
assert.deepEqual(view('p1').faces.map((f) => f.id), ['p1', 'p3', 'p4']);
|
|
360
|
+
assert.deepEqual(view('p1').feed, [{ from: 'p4', line: 'not-me' }]);
|
|
361
|
+
assert.equal(view('p1').title, 'someone is out');
|
|
362
|
+
assert.ok(!('p2' in view('p1').who));
|
|
363
|
+
assert.deepEqual(view('p3').faces.map((f) => f.id), ['p1', 'p2', 'p3', 'p4']);
|
|
364
|
+
assert.equal(view('p3').feed.length, 3);
|
|
365
|
+
// And a tap about them is refused: they are not on that card.
|
|
366
|
+
tapAs(b, 'p1', { face: 'p2', line: 'boat' });
|
|
367
|
+
assert.equal(b.calls.length, 0);
|
|
368
|
+
n += 1;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// A player who leaves takes their own card with them, and is no face on
|
|
372
|
+
// anyone else's.
|
|
373
|
+
{
|
|
374
|
+
const b = withCtx();
|
|
375
|
+
b.hub.ballot(null, { title: 'Shared', faces: FACES });
|
|
376
|
+
b.hub.ballot(['p2'], { title: 'Mine', faces: FACES });
|
|
377
|
+
b.tick();
|
|
378
|
+
b.world.players.delete('p2');
|
|
379
|
+
b.session.players = ROSTER.filter((p) => p.playerId !== 'p2');
|
|
380
|
+
b.h.place(b.world, []);
|
|
381
|
+
b.sent.length = 0;
|
|
382
|
+
b.hub.ballot(null, { title: 'Shared', faces: FACES, options: [{ id: 'skip', text: 'Skip' }] });
|
|
383
|
+
b.tick();
|
|
384
|
+
assert.deepEqual(cards(b).at(-1)[1].card.faces.map((f) => f.id), ['p1', 'p3', 'p4']);
|
|
385
|
+
b.world.players.set('p2', { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
|
|
386
|
+
b.session.players = ROSTER;
|
|
387
|
+
b.h.message(b.session, { playerId: 'p2' }, { k: 'hub-hello', avatar: 4 });
|
|
388
|
+
b.sent.length = 0;
|
|
389
|
+
b.tick();
|
|
390
|
+
assert.deepEqual(cards(b).filter(([to]) => to === 'p2').map(([, msg]) => msg.card.title), ['Shared']);
|
|
391
|
+
n += 1;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// --- review fixes ----------------------------------------------------------
|
|
395
|
+
|
|
396
|
+
// A lock the hook sets holds at once: replayed votes in the same tick are
|
|
397
|
+
// refused before the next send.
|
|
398
|
+
{
|
|
399
|
+
const vote = { mode: 'vote', faces: FACES };
|
|
400
|
+
const b = withCtx({
|
|
401
|
+
hooks: {
|
|
402
|
+
ballot: (hub, playerId, tap) => {
|
|
403
|
+
b2calls.push([playerId, tap]);
|
|
404
|
+
hub.ballot([playerId], { ...vote, picked: { face: tap.face } });
|
|
405
|
+
},
|
|
406
|
+
},
|
|
407
|
+
});
|
|
408
|
+
b.hub.ballot(null, vote);
|
|
409
|
+
b.tick();
|
|
410
|
+
for (let i = 0; i < 3; i += 1) {
|
|
411
|
+
tapAs(b, 'p1', { face: 'p2' });
|
|
412
|
+
}
|
|
413
|
+
assert.equal(b2calls.length, 1);
|
|
414
|
+
// And a card the hook took down a moment ago takes no taps either.
|
|
415
|
+
b.hub.ballot(null, null);
|
|
416
|
+
tapAs(b, 'p3', { face: 'p2' });
|
|
417
|
+
assert.equal(b2calls.length, 1);
|
|
418
|
+
n += 1;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// Connections that never said hello leave nothing behind.
|
|
422
|
+
{
|
|
423
|
+
const players = new Map([['p1', {}]]);
|
|
424
|
+
const h = { place: { ballot: { lines: LINES } }, sim: { players, timeMs: 0 }, players: new Map(), session: { send() {} } };
|
|
425
|
+
const deps = { blockedPairs: () => null, namesOf: () => [], usernameOf: (id) => id, avatarOf: () => null };
|
|
426
|
+
for (let i = 0; i < 20; i += 1) {
|
|
427
|
+
players.set(`g${i}`, {});
|
|
428
|
+
}
|
|
429
|
+
assert.equal(Ballot.ballot(h, null, { faces: [{ playerId: 'p1' }] }), true);
|
|
430
|
+
assert.equal(Ballot.ballot(h, ['g0', 'g1'], { faces: [{ playerId: 'p1' }] }), true);
|
|
431
|
+
Ballot.send(h, deps);
|
|
432
|
+
assert.equal(h.ballotState.views.size, 21);
|
|
433
|
+
for (let i = 0; i < 20; i += 1) {
|
|
434
|
+
players.delete(`g${i}`);
|
|
435
|
+
}
|
|
436
|
+
Ballot.send(h, deps);
|
|
437
|
+
for (const map of ['me', 'sent', 'views', 'rate']) {
|
|
438
|
+
assert.deepEqual([...h.ballotState[map].keys()].filter((id) => id !== 'p1'), [], map);
|
|
439
|
+
}
|
|
440
|
+
n += 1;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// A lock on a face the viewer cannot see (blocked, or gone) stays a lock,
|
|
444
|
+
// and names nobody.
|
|
445
|
+
{
|
|
446
|
+
const vote = { mode: 'vote', faces: FACES, picked: { face: 'p2' } };
|
|
447
|
+
const b = withCtx({ hiddenPair: (x, y) => [x, y].sort().join() === 'p1,p2' });
|
|
448
|
+
b.hub.ballot(['p1', 'p3'], vote);
|
|
449
|
+
b.tick();
|
|
450
|
+
const view = (to) => cards(b).filter(([id]) => id === to).at(-1)[1].card;
|
|
451
|
+
assert.deepEqual(view('p1').picked, {});
|
|
452
|
+
assert.deepEqual(view('p3').picked, { face: 'p2' });
|
|
453
|
+
assert.ok(!JSON.stringify(view('p1')).includes('p2'));
|
|
454
|
+
tapAs(b, 'p1', { face: 'p4' });
|
|
455
|
+
assert.equal(b.calls.length, 0);
|
|
456
|
+
assert.deepEqual(Client.voteLabel(view('p1'), { face: null, option: null, pending: null }, 'p1', 0), { text: 'Locked in ✓', enabled: false });
|
|
457
|
+
// Gone: p2 leaves, p3's lock stays.
|
|
458
|
+
b.world.players.delete('p2');
|
|
459
|
+
b.session.players = ROSTER.filter((p) => p.playerId !== 'p2');
|
|
460
|
+
b.h.place(b.world, []);
|
|
461
|
+
b.tick();
|
|
462
|
+
assert.deepEqual(view('p3').picked, {});
|
|
463
|
+
tapAs(b, 'p3', { face: 'p4' });
|
|
464
|
+
assert.equal(b.calls.length, 0);
|
|
465
|
+
n += 1;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
// (c) One gate on the client. A card that comes ahead of the WORLD snapshot
|
|
469
|
+
// (the server's first tick sends it before WORLD) is held, pending, with its
|
|
470
|
+
// connection; WORLD keeps it for a place with `ballot` or drops it for one
|
|
471
|
+
// without. In a place known to be keyless a card is dropped before anything
|
|
472
|
+
// is made (a legacy or custom `hub-ballot-card`). A card of another
|
|
473
|
+
// connection is let go.
|
|
474
|
+
{
|
|
475
|
+
const netA = { id: 'a' };
|
|
476
|
+
const netB = { id: 'b' };
|
|
477
|
+
const card = { v: 'e1-1', mode: 'talk', faces: [], options: [], lines: [], feed: [], who: {} };
|
|
478
|
+
const ballotPlace = { id: 'main', title: 'Meet', ballot: { lines: LINES } };
|
|
479
|
+
const keyless = { id: 'main', title: 'Town' };
|
|
480
|
+
const msg = (c) => ({ k: 'hub-ballot-card', card: c });
|
|
481
|
+
State.clear();
|
|
482
|
+
assert.equal(Client.held, null);
|
|
483
|
+
// Unknown place: one card held, pending, not drawn yet.
|
|
484
|
+
hookLayer.message({ multiplayer: { net: netA } }, msg({ ...card, v: 'e1-0' }));
|
|
485
|
+
hookLayer.message({ multiplayer: { net: netA } }, msg(card));
|
|
486
|
+
assert.equal(Client.held.pending, true);
|
|
487
|
+
assert.equal(Client.cardFor(netA), null);
|
|
488
|
+
hookLayer.state({}, { t: 1, hubPlace: ballotPlace }, null);
|
|
489
|
+
assert.equal(Client.cardFor(netA), card);
|
|
490
|
+
// Another connection's card is let go.
|
|
491
|
+
assert.equal(Client.cardFor(netB), null);
|
|
492
|
+
assert.equal(Client.held, null);
|
|
493
|
+
// Pending, then the place turns out keyless: dropped.
|
|
494
|
+
State.clear();
|
|
495
|
+
hookLayer.message({ multiplayer: { net: netA } }, msg(card));
|
|
496
|
+
hookLayer.state({}, { t: 1, hubPlace: keyless }, null);
|
|
497
|
+
assert.equal(Client.held, null);
|
|
498
|
+
// Known keyless place: dropped at the gate, nothing held (round 3 #3).
|
|
499
|
+
hookLayer.message({ multiplayer: { net: netA } }, msg(card));
|
|
500
|
+
assert.equal(Client.held, null);
|
|
501
|
+
assert.equal('ballot' in State.hub, false);
|
|
502
|
+
// Known ballot place: held at once; a malformed card or null is no card.
|
|
503
|
+
State.hub.place = ballotPlace;
|
|
504
|
+
hookLayer.message({ multiplayer: { net: netA } }, msg(card));
|
|
505
|
+
assert.equal(Client.cardFor(netA), card);
|
|
506
|
+
hookLayer.message({ multiplayer: { net: netA } }, msg({ mode: 'talk' }));
|
|
507
|
+
assert.equal(Client.cardFor(netA), null);
|
|
508
|
+
hookLayer.message({ multiplayer: { net: netA } }, msg(null));
|
|
509
|
+
assert.equal(Client.cardFor(netA), null);
|
|
510
|
+
// A tap carries the card's version.
|
|
511
|
+
assert.deepEqual(Client.tapMessage(card, { line: 'not-me' }), { v: 'e1-1', line: 'not-me' });
|
|
512
|
+
State.clear();
|
|
513
|
+
Client.cardFor(netB);
|
|
514
|
+
n += 1;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
// Rule B, by source: every ballot touchpoint in the hosts. On the client
|
|
518
|
+
// everything is behind the one gate (`held`, set only by `gate`); on the
|
|
519
|
+
// server behind `h.place.ballot`, `h.ballotState` or `manifest.ballot`.
|
|
520
|
+
{
|
|
521
|
+
const fs = await import('node:fs');
|
|
522
|
+
const lines = (path) => fs.readFileSync(new URL(path, import.meta.url), 'utf8').split('\n').map((l) => l.trim()).filter((l) => !l.startsWith('//') && /ballot|carded|cardFor/i.test(l));
|
|
523
|
+
assert.deepEqual(lines('../code/systems/hub.js'), [
|
|
524
|
+
"import { cardFor, forget as forgetBallot, held as ballotHeld, makeBallot } from '../client/ballot.js';",
|
|
525
|
+
'const card = ballotHeld ? cardFor(mp.net ?? null) : null;',
|
|
526
|
+
'if (ballotHeld) {',
|
|
527
|
+
'this.ballot ??= makeBallot({',
|
|
528
|
+
"send: (ids) => this.scene?.multiplayer?.net?.send({ k: 'hub-ballot', ...ids }),",
|
|
529
|
+
'this.carded = card !== null && !this.trip;',
|
|
530
|
+
'} else if (this.ballot) {',
|
|
531
|
+
'this.ballot.dispose();',
|
|
532
|
+
'this.ballot = null;',
|
|
533
|
+
'this.carded = false;',
|
|
534
|
+
'this.idle.frame(scene, mp, local, !this.trip && this.pendingEnd === null && !this.talk.talking() && !decorating && !this.carded && !this.actionInput, this.sceneKey);',
|
|
535
|
+
'this.act.frame(scene, mp, local, !this.trip && this.pendingEnd === null && !this.talk.talking() && !decorating && !this.actionInput && !this.askInput && !this.menuInput && !this.carded);',
|
|
536
|
+
'}, !this.signIn.pending() && !this.trip && this.pendingEnd === null && !this.talk.talking() && !decorating && !this.carded && !this.askInput && !this.menuInput,',
|
|
537
|
+
'if (this.ballot) {',
|
|
538
|
+
'const box = this.carded ? this.chrome.hudClearBox?.() : null;',
|
|
539
|
+
'this.ballot.frame(this.carded ? cardFor(mp.net ?? null) : null, Hub.hub.place?.ballot?.lines ?? [], mp.net?.selfId?.() ?? null, Hub.simNow(), box ? box.bottom : 0);',
|
|
540
|
+
"this.chrome.safeSurface?.('ballot', this.ballot?.surface?.());",
|
|
541
|
+
// A new player id on the same net drops a held card (only one held).
|
|
542
|
+
'if (ballotHeld) {',
|
|
543
|
+
'forgetBallot();',
|
|
544
|
+
'const eligible = !this.trip && place && !place.result && this.pendingEnd === null && !this.talk?.talking?.() && !this.carded &&',
|
|
545
|
+
'const free = idle && place !== null && this.pendingEnd === null && !this.talk.talking() && !this.carded;',
|
|
546
|
+
'place?.id, this.trip?.phase, this.pendingEnd !== null, this.carded, this.decor?.opened() === true,',
|
|
547
|
+
'if (panels) {chrome.setFeed?.(idle && place !== null && !this.carded ? this.say.feed() : []);}',
|
|
548
|
+
'const canTalk = cam && idle && this.pendingEnd === null && !this.talk.talking() && this.decor?.opened() !== true && !this.carded;',
|
|
549
|
+
'const pickerFree = idle && place !== null && !this.talk.talking() && !this.carded;',
|
|
550
|
+
'scene.data?.engine?.hubInviteRail !== true || Hub.hub.place !== place || Boolean(place.result) || this.talk.talking() || this.carded ||',
|
|
551
|
+
// Optional pad readability only reads the card state to hide its caption.
|
|
552
|
+
'this.carded || this.decor?.opened() === true);',
|
|
553
|
+
'if (this.ballot) {',
|
|
554
|
+
'this.ballot.dispose();',
|
|
555
|
+
'this.ballot = null;',
|
|
556
|
+
]);
|
|
557
|
+
assert.deepEqual(lines('../code/client/hookLayer.js'), [
|
|
558
|
+
"import * as Ballot from './ballot.js';",
|
|
559
|
+
"case 'hub-ballot-card':",
|
|
560
|
+
'Ballot.gate(hub.place, scene?.multiplayer?.net ?? null, msg.card);',
|
|
561
|
+
'if (msg.hubPlace && Ballot.held) {',
|
|
562
|
+
'Ballot.settle(msg.hubPlace);',
|
|
563
|
+
]);
|
|
564
|
+
assert.deepEqual(lines('../code/server/hub.js'), [
|
|
565
|
+
"import * as Ballot from './ballot.js';",
|
|
566
|
+
"if (h.place?.ballot && data?.k === 'hub-ballot') {",
|
|
567
|
+
'Ballot.message(h, player, data, h.place.ballot.lines);',
|
|
568
|
+
'if (h.ballotState) {',
|
|
569
|
+
'Ballot.send(h, ballotDeps(h));',
|
|
570
|
+
'if (manifest.ballot) {',
|
|
571
|
+
'h.ctx.ballot = (playerIds, spec) => Ballot.ballot(h, playerIds, spec);',
|
|
572
|
+
'const ballotStale = back || h.ballotState?.sent.get(player.playerId) === STALE;',
|
|
573
|
+
'if (h.ballotState) {',
|
|
574
|
+
'Ballot.joinedAfresh(h, player.playerId);',
|
|
575
|
+
'if (ballotStale && h.ballotState) {',
|
|
576
|
+
'h.ballotState.sent.set(player.playerId, STALE);',
|
|
577
|
+
'if (h.ballotState) {',
|
|
578
|
+
'Ballot.forget(h, playerId);',
|
|
579
|
+
'function ballotDeps(h) {',
|
|
580
|
+
]);
|
|
581
|
+
assert.deepEqual(lines('../code/client/state.js'), []);
|
|
582
|
+
// A keyless manifest carries no ballot anywhere.
|
|
583
|
+
const { manifest } = readManifest(deck('absent'), scenes);
|
|
584
|
+
assert.ok(!('ballot' in manifest) && !('ballot' in manifest.places.main));
|
|
585
|
+
assert.equal(readManifest(deck('absent', { places: { meet: { title: 'M', scene: 'scenes/meet.scene', ballot: true } } }), scenes).manifest.ballot, true);
|
|
586
|
+
n += 1;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
// Rule A: an id the player was never delivered is refused, even when the
|
|
590
|
+
// current card offers it; one taken off the current card is refused too.
|
|
591
|
+
{
|
|
592
|
+
const b = withCtx();
|
|
593
|
+
b.hub.ballot(null, { faces: FACES, options: [{ id: 'old', text: 'Old' }] });
|
|
594
|
+
b.tick();
|
|
595
|
+
b.hub.ballot(null, { faces: FACES, options: [{ id: 'new', text: 'New' }] });
|
|
596
|
+
tapAs(b, 'p1', { option: 'new' });
|
|
597
|
+
tapAs(b, 'p1', { option: 'old' });
|
|
598
|
+
assert.equal(b.calls.length, 0);
|
|
599
|
+
b.tick();
|
|
600
|
+
tapAs(b, 'p1', { option: 'new' });
|
|
601
|
+
assert.deepEqual(b.calls.map(([, tap]) => tap.option), ['new']);
|
|
602
|
+
// A mode change waits for delivery too: a vote on a talk card is refused.
|
|
603
|
+
b.hub.ballot(null, { mode: 'vote', faces: FACES });
|
|
604
|
+
b.tick();
|
|
605
|
+
b.hub.ballot(null, { mode: 'talk', faces: FACES });
|
|
606
|
+
tapAs(b, 'p2', { face: 'p4' });
|
|
607
|
+
tapAs(b, 'p2', { line: 'not-me' });
|
|
608
|
+
assert.equal(b.calls.length, 1);
|
|
609
|
+
b.tick();
|
|
610
|
+
tapAs(b, 'p2', { line: 'not-me' });
|
|
611
|
+
assert.equal(b.calls.length, 2);
|
|
612
|
+
n += 1;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
// (b) The card's version. Each `hub.ballot` call is a new, higher version;
|
|
616
|
+
// a tap is taken only when its `v` is both the version delivered and the
|
|
617
|
+
// current one. An option in both cards of an undelivered talk -> vote change
|
|
618
|
+
// is refused (round 3 #2), and so is a replay on an older version.
|
|
619
|
+
{
|
|
620
|
+
const b = withCtx();
|
|
621
|
+
b.hub.ballot(null, { faces: FACES, options: [{ id: 'skip', text: 'Skip' }] });
|
|
622
|
+
b.tick();
|
|
623
|
+
const v1 = deliveredTo(b, 'p1').v;
|
|
624
|
+
b.hub.ballot(null, { mode: 'vote', faces: FACES, options: [{ id: 'skip', text: 'Skip' }] });
|
|
625
|
+
tapAs(b, 'p1', { option: 'skip' });
|
|
626
|
+
assert.equal(b.calls.length, 0);
|
|
627
|
+
b.tick();
|
|
628
|
+
const v2 = deliveredTo(b, 'p1').v;
|
|
629
|
+
assert.notEqual(v2, v1);
|
|
630
|
+
tapAs(b, 'p1', { v: v1, option: 'skip' });
|
|
631
|
+
tapAs(b, 'p1', { v: `${v2}0`, option: 'skip' });
|
|
632
|
+
tapAs(b, 'p1', { v: undefined, option: 'skip' });
|
|
633
|
+
tapAs(b, 'p1', { v: Number(v2.split('-')[1]), option: 'skip' });
|
|
634
|
+
assert.equal(b.calls.length, 0);
|
|
635
|
+
tapAs(b, 'p1', { option: 'skip' });
|
|
636
|
+
assert.deepEqual(b.calls, [['p1', { face: null, line: null, option: 'skip', mode: 'vote' }]]);
|
|
637
|
+
// A player's own card with other taps is a new version of theirs alone;
|
|
638
|
+
// the same card again keeps it.
|
|
639
|
+
b.hub.ballot(['p2'], { mode: 'vote', faces: FACES });
|
|
640
|
+
b.hub.ballot(['p2'], { mode: 'vote', faces: FACES });
|
|
641
|
+
b.tick();
|
|
642
|
+
const v4 = deliveredTo(b, 'p2').v;
|
|
643
|
+
assert.ok(![v1, v2].includes(v4));
|
|
644
|
+
assert.equal(deliveredTo(b, 'p3').v, v2);
|
|
645
|
+
// A player's own card cleared: they are back on the shared card, and a
|
|
646
|
+
// tap on the cleared one is refused.
|
|
647
|
+
b.hub.ballot(['p2'], null);
|
|
648
|
+
tapAs(b, 'p2', { v: v4, face: 'p4' });
|
|
649
|
+
assert.equal(b.calls.length, 1);
|
|
650
|
+
n += 1;
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
// A card's version moves only when what can be tapped on it changes: a
|
|
654
|
+
// refresh of the feed, title, text, until, notes, votes, marks or option
|
|
655
|
+
// words keeps it (a tap made as another line lands is still taken), and a
|
|
656
|
+
// change of mode, faces offered or `off`, lines, option ids or `picked`
|
|
657
|
+
// moves it. A player's own card that differs from the shared one only in its
|
|
658
|
+
// feed keeps the shared card's version.
|
|
659
|
+
{
|
|
660
|
+
const b = withCtx();
|
|
661
|
+
const base = { title: 'Meeting', faces: FACES, lines: ['boat', 'not-me'], options: [{ id: 'skip', text: 'Skip' }] };
|
|
662
|
+
b.hub.ballot(null, base);
|
|
663
|
+
b.tick();
|
|
664
|
+
const v = deliveredTo(b, 'p1').v;
|
|
665
|
+
const vOf = (spec, to = null) => {
|
|
666
|
+
b.hub.ballot(to, spec);
|
|
667
|
+
b.tick();
|
|
668
|
+
return deliveredTo(b, to ? to[0] : 'p1').v;
|
|
669
|
+
};
|
|
670
|
+
// Feed-only refresh: the delivered card is still the current one, so a tap
|
|
671
|
+
// made on it before the new feed arrives is taken.
|
|
672
|
+
b.hub.ballot(null, { ...base, feed: [{ from: 'p2', line: 'not-me' }] });
|
|
673
|
+
tapAs(b, 'p1', { line: 'not-me' });
|
|
674
|
+
assert.equal(b.calls.length, 1);
|
|
675
|
+
b.tick();
|
|
676
|
+
assert.equal(deliveredTo(b, 'p1').v, v);
|
|
677
|
+
assert.deepEqual(deliveredTo(b, 'p1').feed, [{ from: 'p2', line: 'not-me' }]);
|
|
678
|
+
for (const words of [
|
|
679
|
+
{ title: 'Meeting!' },
|
|
680
|
+
{ text: 'Who?' },
|
|
681
|
+
{ until: 9000 },
|
|
682
|
+
{ faces: FACES.map((f) => ({ ...f, note: 'here', votes: 2, mark: '#123456' })) },
|
|
683
|
+
{ options: [{ id: 'skip', text: 'Pass' }] },
|
|
684
|
+
]) {
|
|
685
|
+
assert.equal(vOf({ ...base, ...words }), v, JSON.stringify(words));
|
|
686
|
+
}
|
|
687
|
+
// What can be tapped: each moves it, and back again moves it once more.
|
|
688
|
+
let last = v;
|
|
689
|
+
for (const taps of [
|
|
690
|
+
{ mode: 'vote' },
|
|
691
|
+
{ faces: FACES.slice(0, 3) },
|
|
692
|
+
{ faces: FACES.map((f) => ({ ...f, off: false })) },
|
|
693
|
+
{ lines: ['boat'] },
|
|
694
|
+
{ options: [{ id: 'skip', text: 'Skip' }, { id: 'wait', text: 'Wait' }] },
|
|
695
|
+
{ mode: 'vote', picked: { face: 'p2' } },
|
|
696
|
+
]) {
|
|
697
|
+
const moved = vOf({ ...base, ...taps });
|
|
698
|
+
assert.notEqual(moved, last, JSON.stringify(taps));
|
|
699
|
+
last = vOf(base);
|
|
700
|
+
assert.ok(![moved, v].includes(last));
|
|
701
|
+
}
|
|
702
|
+
// A player's own card differing only in feed keeps the shared version, and
|
|
703
|
+
// a tap on it is taken before and after it is delivered.
|
|
704
|
+
const shared = deliveredTo(b, 'p3').v;
|
|
705
|
+
b.calls.length = 0;
|
|
706
|
+
b.hub.ballot(['p3'], { ...base, feed: [{ from: 'p1', line: 'not-me' }] });
|
|
707
|
+
tapAs(b, 'p3', { line: 'not-me' });
|
|
708
|
+
b.tick();
|
|
709
|
+
assert.equal(deliveredTo(b, 'p3').v, shared);
|
|
710
|
+
assert.equal(deliveredTo(b, 'p3').feed.length, 1);
|
|
711
|
+
tapAs(b, 'p3', { line: 'not-me' });
|
|
712
|
+
assert.equal(b.calls.length, 2);
|
|
713
|
+
// ...and one that changes its taps does not.
|
|
714
|
+
b.hub.ballot(['p3'], { ...base, lines: ['boat'] });
|
|
715
|
+
tapAs(b, 'p3', { line: 'not-me' });
|
|
716
|
+
assert.equal(b.calls.length, 2);
|
|
717
|
+
// The client keeps a selection through a refresh of the same version and
|
|
718
|
+
// starts afresh (nothing selected or pending) on a new one.
|
|
719
|
+
const card = { v: 'e1-5', mode: 'vote', faces: [{ id: 'p1' }, { id: 'p2' }], options: [], lines: [], feed: [], who: {} };
|
|
720
|
+
let sel = Client.keepSel(card, { face: null, option: null, pending: null, mode: null, v: null });
|
|
721
|
+
({ sel } = Client.tap(card, LINES, sel, { face: 'p2' }));
|
|
722
|
+
sel = Client.tap(card, LINES, sel, { vote: true }, 100).sel;
|
|
723
|
+
assert.equal(Client.keepSel({ ...card, title: 'x' }, sel).pending, 100);
|
|
724
|
+
assert.deepEqual(Client.keepSel({ ...card, v: 'e1-6' }, sel), { face: null, option: null, pending: null, mode: 'vote', v: 'e1-6' });
|
|
725
|
+
n += 1;
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
// Round 4 #1: versions belong to one server. A replacement server for the
|
|
729
|
+
// same layer restarts its counter, but under its own epoch, so a tap made on
|
|
730
|
+
// the old server's card is never taken as one on the new server's.
|
|
731
|
+
{
|
|
732
|
+
const a = withCtx();
|
|
733
|
+
a.hub.ballot(null, { faces: FACES, options: [{ id: 'skip', text: 'Skip' }] });
|
|
734
|
+
a.tick();
|
|
735
|
+
const old = deliveredTo(a, 'p1').v;
|
|
736
|
+
const b = withCtx();
|
|
737
|
+
b.hub.ballot(null, { mode: 'vote', faces: FACES, options: [{ id: 'skip', text: 'Skip' }] });
|
|
738
|
+
b.tick();
|
|
739
|
+
const fresh = deliveredTo(b, 'p1').v;
|
|
740
|
+
assert.equal(old.split('-')[1], fresh.split('-')[1]);
|
|
741
|
+
assert.notEqual(old, fresh);
|
|
742
|
+
tapAs(b, 'p1', { v: old, option: 'skip' });
|
|
743
|
+
assert.equal(b.calls.length, 0);
|
|
744
|
+
tapAs(b, 'p1', { v: fresh, option: 'skip' });
|
|
745
|
+
assert.equal(b.calls.length, 1);
|
|
746
|
+
n += 1;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
// Round 4 #2: every WORLD snapshot rechecks a held card, pending or not: a
|
|
750
|
+
// recovery that keeps the connection but lands in a keyless place lets go of
|
|
751
|
+
// an established card.
|
|
752
|
+
{
|
|
753
|
+
const net = { id: 'n' };
|
|
754
|
+
const card = { v: 'e1-1', mode: 'talk', faces: [], options: [], lines: [], feed: [], who: {} };
|
|
755
|
+
State.clear();
|
|
756
|
+
State.hub.place = { id: 'main', title: 'Meet', ballot: { lines: LINES } };
|
|
757
|
+
hookLayer.message({ multiplayer: { net } }, { k: 'hub-ballot-card', card });
|
|
758
|
+
assert.equal(Client.cardFor(net), card);
|
|
759
|
+
assert.equal(Client.held.pending, false);
|
|
760
|
+
// The same place again keeps it.
|
|
761
|
+
hookLayer.state({}, { t: 2, hubPlace: State.hub.place }, null);
|
|
762
|
+
assert.equal(Client.cardFor(net), card);
|
|
763
|
+
hookLayer.state({}, { t: 3, hubPlace: { id: 'main', title: 'Town' } }, null);
|
|
764
|
+
assert.equal(Client.held, null);
|
|
765
|
+
assert.equal(Client.cardFor(net), null);
|
|
766
|
+
State.clear();
|
|
767
|
+
n += 1;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
// Round 4 #3: the hub system reads the gate again after `cardFor` (which
|
|
771
|
+
// lets go of another connection's card) and makes or draws nothing unless it
|
|
772
|
+
// still holds one: no make -> frame(null) -> dispose on a keyless visit.
|
|
773
|
+
{
|
|
774
|
+
const fs = await import('node:fs');
|
|
775
|
+
const src = fs.readFileSync(new URL('../code/systems/hub.js', import.meta.url), 'utf8');
|
|
776
|
+
const at = (text) => {
|
|
777
|
+
const i = src.indexOf(text);
|
|
778
|
+
assert.ok(i >= 0, text);
|
|
779
|
+
return i;
|
|
780
|
+
};
|
|
781
|
+
const lookup = at('const card = ballotHeld ? cardFor(mp.net ?? null) : null;');
|
|
782
|
+
const gate = src.indexOf('if (ballotHeld) {', lookup);
|
|
783
|
+
const make = at('this.ballot ??= makeBallot({');
|
|
784
|
+
assert.ok(lookup < gate && gate < make && src.lastIndexOf('if (ballotHeld)', make) === gate);
|
|
785
|
+
// And cardFor itself lets go, so `held` reads null right after.
|
|
786
|
+
Client.gate({ id: 'main', title: 'Meet', ballot: { lines: LINES } }, { id: 'old' }, { v: 'e1-1', mode: 'talk', faces: [], options: [], lines: [], feed: [], who: {} });
|
|
787
|
+
assert.equal(Client.cardFor({ id: 'new' }), null);
|
|
788
|
+
assert.equal(Client.held, null);
|
|
789
|
+
n += 1;
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
// (a) The card is a pure function of who is connected now. While a blocked
|
|
793
|
+
// player is here, the viewer has no face, row or name of theirs. Once they
|
|
794
|
+
// leave, every viewer loses their feed rows alike, nothing is remembered, and
|
|
795
|
+
// a departed name in the deck's own words is no longer redacted (the HUD's
|
|
796
|
+
// and labels' limit too). A viewer who reconnects with the same id (round 3
|
|
797
|
+
// #1) is shown exactly what everyone else is.
|
|
798
|
+
{
|
|
799
|
+
const lines = [...LINES, { id: 'bo-did', text: 'bo did it', about: 'self' }];
|
|
800
|
+
const b = withCtx({ ballot: { lines }, hiddenPair: (x, y) => [x, y].sort().join() === 'p1,p2' && b.session.players.some((p) => p.playerId === 'p2') });
|
|
801
|
+
const spec = { title: 'bo is out', faces: FACES, feed: [{ from: 'p3', line: 'bo-did' }, { from: 'p2', line: 'not-me' }, { from: 'p4', to: 'p2', line: 'boat' }] };
|
|
802
|
+
b.hub.ballot(null, spec);
|
|
803
|
+
b.tick();
|
|
804
|
+
const view = (to) => cards(b).filter(([id]) => id === to).at(-1)[1].card;
|
|
805
|
+
assert.equal(view('p1').title, 'someone is out');
|
|
806
|
+
assert.deepEqual(view('p1').feed, [{ from: 'p3', line: 'bo-did' }]);
|
|
807
|
+
assert.deepEqual(Client.feedWords(view('p1'), lines, 'p1'), ['cy: someone did it']);
|
|
808
|
+
assert.equal(view('p3').feed.length, 3);
|
|
809
|
+
// bo leaves: their rows go for everyone, from the next send on.
|
|
810
|
+
b.world.players.delete('p2');
|
|
811
|
+
b.session.players = ROSTER.filter((p) => p.playerId !== 'p2');
|
|
812
|
+
b.h.place(b.world, []);
|
|
813
|
+
b.tick();
|
|
814
|
+
for (const id of ['p1', 'p3', 'p4']) {
|
|
815
|
+
assert.deepEqual(view(id).feed, [{ from: 'p3', line: 'bo-did' }], id);
|
|
816
|
+
assert.ok(!('p2' in view(id).who), id);
|
|
817
|
+
}
|
|
818
|
+
assert.equal(view('p1').title, 'bo is out');
|
|
819
|
+
assert.ok(!('words' in view('p1')));
|
|
820
|
+
// p1 reconnects with the same id: the same card as everyone else.
|
|
821
|
+
b.world.players.delete('p1');
|
|
822
|
+
b.session.players = ROSTER.filter((p) => p.playerId !== 'p2' && p.playerId !== 'p1');
|
|
823
|
+
b.h.place(b.world, []);
|
|
824
|
+
b.tick();
|
|
825
|
+
b.world.players.set('p1', { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
|
|
826
|
+
b.session.players = ROSTER.filter((p) => p.playerId !== 'p2');
|
|
827
|
+
b.h.message(b.session, { playerId: 'p1' }, { k: 'hub-hello', avatar: 3 });
|
|
828
|
+
b.sent.length = 0;
|
|
829
|
+
b.tick();
|
|
830
|
+
const { v: v1, ...again } = view('p1');
|
|
831
|
+
const { v: v3, ...other } = view('p3');
|
|
832
|
+
assert.equal(v1, v3);
|
|
833
|
+
assert.deepEqual(again, other);
|
|
834
|
+
assert.deepEqual(again.feed, [{ from: 'p3', line: 'bo-did' }]);
|
|
835
|
+
n += 1;
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
// Ids are looked up as own properties only, client and server.
|
|
839
|
+
{
|
|
840
|
+
const lines = [{ id: 'constructor', text: 'Not me!', about: 'self' }];
|
|
841
|
+
const card = JSON.parse(JSON.stringify({ mode: 'talk', faces: [], options: [], lines: ['constructor'], feed: [{ from: 'toString', line: 'constructor' }], who: {}, words: {} }));
|
|
842
|
+
assert.equal(Client.textOf(card, lines[0]), 'Not me!');
|
|
843
|
+
assert.equal(Client.nameOf(card, 'toString', 'p1'), 'someone');
|
|
844
|
+
assert.deepEqual(Client.feedWords(card, lines, 'p1'), ['someone: Not me!']);
|
|
845
|
+
const view = Ballot.viewFor(
|
|
846
|
+
{ mode: 'talk', faces: [{ playerId: '__proto__' }, { playerId: 'constructor' }], options: [], lines: [], feed: [] },
|
|
847
|
+
'p1',
|
|
848
|
+
{ usernameOf: (id) => `name-${id}`, avatarOf: () => 1, hidden: null, names: [], lines: [] },
|
|
849
|
+
);
|
|
850
|
+
const wire = JSON.parse(JSON.stringify(view));
|
|
851
|
+
assert.deepEqual(wire.faces.map((f) => f.id), ['__proto__', 'constructor']);
|
|
852
|
+
assert.equal(Client.nameOf(wire, '__proto__', 'p1'), 'name-__proto__');
|
|
853
|
+
assert.equal(Client.nameOf(wire, 'constructor', 'p1'), 'name-constructor');
|
|
854
|
+
assert.equal(Object.getPrototypeOf(wire), Object.prototype);
|
|
855
|
+
n += 1;
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
// A blocked player's name is out of every word the card shows: the
|
|
859
|
+
// manifest's lines too, in the chips and in the feed.
|
|
860
|
+
{
|
|
861
|
+
const lines = [...LINES, { id: 'bo-did', text: 'bo did it', about: 'self' }];
|
|
862
|
+
const b = withCtx({ ballot: { lines }, hiddenPair: (x, y) => [x, y].sort().join() === 'p1,p2' });
|
|
863
|
+
b.hub.ballot(null, { faces: FACES, feed: [{ from: 'p3', line: 'bo-did' }, { from: 'p2', line: 'not-me' }] });
|
|
864
|
+
b.tick();
|
|
865
|
+
const view = (to) => cards(b).find(([id]) => id === to)[1].card;
|
|
866
|
+
assert.deepEqual(view('p1').words, { 'bo-did': 'someone did it' });
|
|
867
|
+
assert.deepEqual(view('p1').feed, [{ from: 'p3', line: 'bo-did' }]);
|
|
868
|
+
assert.deepEqual(Client.feedWords(view('p1'), lines, 'p1'), ['cy: someone did it']);
|
|
869
|
+
assert.equal(Client.textOf(view('p1'), lines[3]), 'someone did it');
|
|
870
|
+
assert.ok(!('words' in view('p3')));
|
|
871
|
+
assert.deepEqual(Client.feedWords(view('p3'), lines, 'p3'), ['You: bo did it', 'bo: Not me!']);
|
|
872
|
+
n += 1;
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
// Clearing a player's own card is rule A too: back on the shared card they
|
|
876
|
+
// keep their version when it allows the same taps as the card they had, and
|
|
877
|
+
// get a new one otherwise (a follower copy of the shared card, its own `v`).
|
|
878
|
+
{
|
|
879
|
+
const talk = { faces: FACES };
|
|
880
|
+
const vote = { mode: 'vote', faces: FACES };
|
|
881
|
+
const b = withCtx();
|
|
882
|
+
const vOf = (playerId) => deliveredTo(b, playerId)?.v;
|
|
883
|
+
// (a) A different card in between: a tap still on the shared card's
|
|
884
|
+
// version from before it is refused; one on the new version is taken.
|
|
885
|
+
b.hub.ballot(null, talk);
|
|
886
|
+
b.tick();
|
|
887
|
+
const sharedV = vOf('p1');
|
|
888
|
+
b.hub.ballot(['p1'], vote);
|
|
889
|
+
b.tick();
|
|
890
|
+
const privateV = vOf('p1');
|
|
891
|
+
assert.notEqual(privateV, sharedV);
|
|
892
|
+
b.hub.ballot(['p1'], null);
|
|
893
|
+
b.tick();
|
|
894
|
+
const back = deliveredTo(b, 'p1');
|
|
895
|
+
assert.equal(back.mode, 'talk');
|
|
896
|
+
assert.ok(![sharedV, privateV].includes(back.v));
|
|
897
|
+
assert.ok(!('of' in back) && !('key' in back));
|
|
898
|
+
tapAs(b, 'p1', { v: sharedV, line: 'not-me' });
|
|
899
|
+
assert.equal(b.calls.length, 0);
|
|
900
|
+
tapAs(b, 'p1', { line: 'not-me' });
|
|
901
|
+
assert.deepEqual(b.calls.map(([who]) => who), ['p1']);
|
|
902
|
+
// (b) The same taps on both: a tap in flight on the player's own version
|
|
903
|
+
// is taken, before the next send and after it.
|
|
904
|
+
b.hub.ballot(['p2'], vote);
|
|
905
|
+
b.tick();
|
|
906
|
+
const ownV = vOf('p2');
|
|
907
|
+
b.hub.ballot(null, { ...vote, title: 'Vote now' });
|
|
908
|
+
b.tick();
|
|
909
|
+
assert.notEqual(vOf('p4'), ownV);
|
|
910
|
+
assert.equal(vOf('p2'), ownV);
|
|
911
|
+
b.hub.ballot(['p2'], null);
|
|
912
|
+
tapAs(b, 'p2', { v: ownV, face: 'p1' });
|
|
913
|
+
assert.deepEqual(b.calls.map(([who]) => who), ['p1', 'p2']);
|
|
914
|
+
b.tick();
|
|
915
|
+
assert.equal(deliveredTo(b, 'p2').title, 'Vote now');
|
|
916
|
+
assert.equal(vOf('p2'), ownV);
|
|
917
|
+
// (c) A follower keeps its version while the shared card it follows is
|
|
918
|
+
// replaced by one allowing the same taps, and takes the shared card's new
|
|
919
|
+
// version when it is not; clearing for everyone clears followers too.
|
|
920
|
+
b.hub.ballot(null, talk);
|
|
921
|
+
b.tick();
|
|
922
|
+
b.hub.ballot(['p3'], vote);
|
|
923
|
+
b.tick();
|
|
924
|
+
b.hub.ballot(['p3'], null);
|
|
925
|
+
b.tick();
|
|
926
|
+
const followV = vOf('p3');
|
|
927
|
+
assert.notEqual(followV, vOf('p4'));
|
|
928
|
+
b.hub.ballot(null, { ...talk, title: 'Still talking' });
|
|
929
|
+
b.tick();
|
|
930
|
+
assert.equal(deliveredTo(b, 'p3').title, 'Still talking');
|
|
931
|
+
assert.equal(vOf('p3'), followV);
|
|
932
|
+
b.hub.ballot(null, vote);
|
|
933
|
+
b.tick();
|
|
934
|
+
assert.equal(deliveredTo(b, 'p3').mode, 'vote');
|
|
935
|
+
assert.equal(vOf('p3'), vOf('p4'));
|
|
936
|
+
assert.notEqual(vOf('p3'), followV);
|
|
937
|
+
b.hub.ballot(['p3'], talk);
|
|
938
|
+
b.hub.ballot(['p3'], null);
|
|
939
|
+
b.tick();
|
|
940
|
+
const againV = vOf('p3');
|
|
941
|
+
assert.notEqual(againV, vOf('p4'));
|
|
942
|
+
b.hub.ballot(null, null);
|
|
943
|
+
b.tick();
|
|
944
|
+
assert.equal(deliveredTo(b, 'p3'), null);
|
|
945
|
+
b.hub.ballot(null, vote);
|
|
946
|
+
b.tick();
|
|
947
|
+
assert.equal(vOf('p3'), vOf('p4'));
|
|
948
|
+
assert.notEqual(vOf('p3'), againV);
|
|
949
|
+
// Every follower copy follows the shared card of now.
|
|
950
|
+
const h = { place: { ballot: { lines: LINES } }, sim: { players: new Map([['p1', {}], ['p2', {}]]) } };
|
|
951
|
+
Ballot.ballot(h, null, talk);
|
|
952
|
+
Ballot.ballot(h, ['p1', 'p2'], vote);
|
|
953
|
+
Ballot.ballot(h, ['p1', 'p2'], null);
|
|
954
|
+
Ballot.ballot(h, null, { ...talk, title: 'Again' });
|
|
955
|
+
assert.deepEqual([...h.ballotState.me.values()].map((card) => card.of === h.ballotState.shared), [true, true]);
|
|
956
|
+
n += 1;
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
// --- the client's words -------------------------------------------------------
|
|
960
|
+
{
|
|
961
|
+
const card = {
|
|
962
|
+
mode: 'talk',
|
|
963
|
+
faces: [{ id: 'p1' }, { id: 'p2' }, { id: 'p3', off: true }],
|
|
964
|
+
options: [{ id: 'skip', text: 'Skip' }],
|
|
965
|
+
lines: ['boat', 'not-me'],
|
|
966
|
+
feed: [{ from: 'p2', to: 'p1', line: 'boat' }, { from: 'p2', line: 'not-me' }, { from: 'p1', to: 'p9', line: 'boat' }, { from: 'p2', line: 'gone' }],
|
|
967
|
+
who: { p1: { name: 'amy', avatar: 0 }, p2: { name: 'bo', avatar: 1 } },
|
|
968
|
+
};
|
|
969
|
+
assert.deepEqual(Client.feedWords(card, LINES, 'p3'), ['bo → amy: I saw them by the boat', 'bo: Not me!', 'amy → someone: I saw them by the boat']);
|
|
970
|
+
assert.deepEqual(Client.feedWords(card, LINES, 'p1'), ['bo → You: I saw them by the boat', 'bo: Not me!', 'You → someone: I saw them by the boat']);
|
|
971
|
+
// Talk: a face, then a line about it; a line about oneself at once.
|
|
972
|
+
let sel = Client.keepSel(card, { face: null, option: null, pending: null, mode: null });
|
|
973
|
+
assert.equal(Client.hintOf(card, LINES, sel, 'p1'), 'Tap a face, then what to say');
|
|
974
|
+
assert.equal(Client.tap(card, LINES, sel, { line: 'boat' }).send, null);
|
|
975
|
+
assert.equal(Client.tap(card, LINES, sel, { face: 'p3' }).sel.face, null);
|
|
976
|
+
({ sel } = Client.tap(card, LINES, sel, { face: 'p2' }));
|
|
977
|
+
assert.equal(Client.hintOf(card, LINES, sel, 'p1'), 'About bo:');
|
|
978
|
+
const said = Client.tap(card, LINES, sel, { line: 'boat' });
|
|
979
|
+
assert.deepEqual(said.send, { face: 'p2', line: 'boat' });
|
|
980
|
+
assert.equal(said.sel.face, null);
|
|
981
|
+
assert.deepEqual(Client.tap(card, LINES, sel, { line: 'not-me' }).send, { line: 'not-me' });
|
|
982
|
+
assert.deepEqual(Client.tap(card, LINES, sel, { option: 'skip' }).send, { option: 'skip' });
|
|
983
|
+
assert.equal(Client.tap(card, LINES, sel, { line: 'sus' }).send, null);
|
|
984
|
+
// Vote: pick, then Vote; locked once the server says so.
|
|
985
|
+
const vote = { ...card, mode: 'vote' };
|
|
986
|
+
sel = Client.keepSel(vote, sel);
|
|
987
|
+
assert.equal(sel.face, null);
|
|
988
|
+
assert.deepEqual(Client.voteLabel(vote, sel, 'p1', 0), { text: 'Vote', enabled: false });
|
|
989
|
+
({ sel } = Client.tap(vote, LINES, sel, { face: 'p1' }));
|
|
990
|
+
assert.deepEqual(Client.voteLabel(vote, sel, 'p1', 0), { text: 'Vote for You', enabled: true });
|
|
991
|
+
({ sel } = Client.tap(vote, LINES, sel, { option: 'skip' }));
|
|
992
|
+
assert.deepEqual(Client.voteLabel(vote, sel, 'p1', 0), { text: 'Vote: Skip', enabled: true });
|
|
993
|
+
const sent = Client.tap(vote, LINES, sel, { vote: true }, 1000);
|
|
994
|
+
assert.deepEqual(sent.send, { option: 'skip' });
|
|
995
|
+
assert.equal(Client.tap(vote, LINES, sent.sel, { vote: true }, 1500).send, null);
|
|
996
|
+
assert.deepEqual(Client.voteLabel(vote, sent.sel, 'p1', 1500), { text: 'Sending…', enabled: false });
|
|
997
|
+
const locked = { ...vote, picked: { face: 'p2' } };
|
|
998
|
+
assert.deepEqual(Client.voteLabel(locked, Client.keepSel(locked, sent.sel), 'p1', 1500), { text: 'Locked in: bo ✓', enabled: false });
|
|
999
|
+
assert.equal(Client.tap(locked, LINES, sel, { face: 'p1' }).send, null);
|
|
1000
|
+
assert.equal(Client.tap({ ...card, mode: 'reveal' }, LINES, sel, { face: 'p1' }).send, null);
|
|
1001
|
+
assert.equal(Client.clock(83.2), '1:24');
|
|
1002
|
+
assert.equal(Client.clock(-3), '0:00');
|
|
1003
|
+
n += 1;
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
console.warn = realWarn;
|
|
1007
|
+
console.log = realLog;
|
|
1008
|
+
console.log(`test-ballot: ${n} groups passed`);
|