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,1904 @@
|
|
|
1
|
+
// "Stuck?" (contract v1.33, a deck's `hub.stuck`): the rule that tells a player
|
|
2
|
+
// who walks and gets nowhere from one who walks (`code/client/stuck.js`), the
|
|
3
|
+
// chip and the Doors row the chrome draws for it (over a small stand-in for
|
|
4
|
+
// the DOM), the hub system's use of both, and the place server's answer to a
|
|
5
|
+
// tap (`hub-unstick` in `code/server/hub.js`: the arrival, in a town, once in
|
|
6
|
+
// 5 s). Each half is also run with the key absent: nothing is made, drawn,
|
|
7
|
+
// sent or answered. `npm run check` runs this; it needs nothing installed.
|
|
8
|
+
|
|
9
|
+
import assert from 'node:assert/strict';
|
|
10
|
+
import fs from 'node:fs';
|
|
11
|
+
import { register } from 'node:module';
|
|
12
|
+
import {
|
|
13
|
+
STUCK_AFTER_MS,
|
|
14
|
+
STUCK_EVERY_MS,
|
|
15
|
+
STUCK_FRAME_MAX_MS,
|
|
16
|
+
STUCK_HITCH_MS,
|
|
17
|
+
STUCK_KEEP_MS,
|
|
18
|
+
STUCK_MOVE_M,
|
|
19
|
+
STUCK_PAUSE_MS,
|
|
20
|
+
STUCK_RELEASE_MS,
|
|
21
|
+
STUCK_WINDOW_MS,
|
|
22
|
+
chipShift,
|
|
23
|
+
makeStuck,
|
|
24
|
+
stuckDone,
|
|
25
|
+
stuckFrame,
|
|
26
|
+
stuckSpan,
|
|
27
|
+
stuckText,
|
|
28
|
+
stuckWhere,
|
|
29
|
+
walkInput,
|
|
30
|
+
} from '../code/client/stuck.js';
|
|
31
|
+
|
|
32
|
+
let n = 0;
|
|
33
|
+
function test(name, fn) {
|
|
34
|
+
try {
|
|
35
|
+
fn();
|
|
36
|
+
} catch (err) {
|
|
37
|
+
console.error(`not ok: ${name}`);
|
|
38
|
+
throw err;
|
|
39
|
+
}
|
|
40
|
+
n += 1;
|
|
41
|
+
}
|
|
42
|
+
// The same for a test that waits (for promises a hook left behind to settle).
|
|
43
|
+
async function testAsync(name, fn) {
|
|
44
|
+
try {
|
|
45
|
+
await fn();
|
|
46
|
+
} catch (err) {
|
|
47
|
+
console.error(`not ok: ${name}`);
|
|
48
|
+
throw err;
|
|
49
|
+
}
|
|
50
|
+
n += 1;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// --- the rule ---------------------------------------------------------------
|
|
54
|
+
|
|
55
|
+
const FRAME = 16;
|
|
56
|
+
// Runs frames from `from` up to `to` ms, `every` apart; `at(t)` is the body,
|
|
57
|
+
// `walking(t)` the input.
|
|
58
|
+
function run(s, from, to, at, walking, key = 'town', every = FRAME) {
|
|
59
|
+
let shown = false;
|
|
60
|
+
const seen = [];
|
|
61
|
+
for (let t = from; t <= to; t += every) {
|
|
62
|
+
const p = at(t);
|
|
63
|
+
shown = stuckFrame(s, { key, x: p.x, z: p.z, walking: walking(t) }, t);
|
|
64
|
+
seen.push(shown);
|
|
65
|
+
}
|
|
66
|
+
return { shown, ever: seen.includes(true), seen };
|
|
67
|
+
}
|
|
68
|
+
// When the chip first shows, or null: frames `every` apart for `limit` ms.
|
|
69
|
+
function firstShown(at, walking, every = FRAME, limit = 60000) {
|
|
70
|
+
const s = makeStuck();
|
|
71
|
+
for (let t = 0; t <= limit; t += every) {
|
|
72
|
+
const p = at(t);
|
|
73
|
+
if (stuckFrame(s, { key: 'town', x: p.x, z: p.z, walking: walking(t) }, t)) {
|
|
74
|
+
return t;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
const still = () => ({ x: 4, z: -2 });
|
|
80
|
+
const yes = () => true;
|
|
81
|
+
const no = () => false;
|
|
82
|
+
// The frame rates a device may draw at: 60, 30, 15, 12, 10, 5 and 4 a second.
|
|
83
|
+
const RATES = [16, 33, 66, 83, 100, 200, 250];
|
|
84
|
+
// A body walked at the Player's 6 m/s by the player loop: 33 ms of walking a frame at most.
|
|
85
|
+
const STEP_M = (every) => 6 * Math.min(every, 33) / 1000;
|
|
86
|
+
|
|
87
|
+
test('standing still, with no input, never shows it', () => {
|
|
88
|
+
assert.equal(run(makeStuck(), 0, 30000, still, no).ever, false);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('walking into a wall shows it after 3 s of input, not before', () => {
|
|
92
|
+
const s = makeStuck();
|
|
93
|
+
assert.equal(run(s, 0, STUCK_AFTER_MS - FRAME, still, yes).ever, false);
|
|
94
|
+
assert.equal(run(s, STUCK_AFTER_MS, STUCK_AFTER_MS + 1000, still, yes).shown, true);
|
|
95
|
+
// A shuffle along the wall is still nowhere.
|
|
96
|
+
const t0 = STUCK_AFTER_MS + 1000;
|
|
97
|
+
assert.equal(run(s, t0, t0 + 5000, (t) => ({ x: 4 + 0.3 * Math.sin(t / 90), z: -2 }), yes).seen.every(Boolean), true);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('walking in bursts shows it: the breaks are not counted, and do not start it over', () => {
|
|
101
|
+
// The playtest: 1 s pushing into the wall, 0.5 s let go, again and again.
|
|
102
|
+
const burst = (on, off) => (t) => t % (on + off) < on;
|
|
103
|
+
const at = firstShown(still, burst(1000, 500));
|
|
104
|
+
assert.ok(at !== null && at >= 4000 && at <= 4700, `3 s of input in 1 s bursts is 4 to 4.5 s in, give or take a frame a burst: ${at}`);
|
|
105
|
+
// Half a second on, half off: 6 s. Shorter taps the same.
|
|
106
|
+
const half = firstShown(still, burst(500, 500));
|
|
107
|
+
assert.ok(half >= 5300 && half <= 6400, `${half}`);
|
|
108
|
+
const taps = firstShown(still, burst(200, 200));
|
|
109
|
+
assert.ok(taps >= 5300 && taps <= 7200, `${taps}`);
|
|
110
|
+
// Once up it stays up through the breaks.
|
|
111
|
+
const s = makeStuck();
|
|
112
|
+
run(s, 0, 6000, still, burst(1000, 500));
|
|
113
|
+
assert.equal(run(s, 6016, 20000, still, burst(1000, 500)).seen.every(Boolean), true);
|
|
114
|
+
// Less than 3 s of input in any 8: not trying to get anywhere. Never.
|
|
115
|
+
assert.equal(firstShown(still, burst(300, 700)), null, '2.4 s in 8');
|
|
116
|
+
assert.equal(firstShown(still, burst(1000, 3000)), null, '2 s in 8');
|
|
117
|
+
assert.ok(firstShown(still, burst(1000, 1500)) !== null, '3 s inside 6');
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test('"nowhere" is the box round where the body was, corner to corner, under 1 m', () => {
|
|
121
|
+
assert.equal(STUCK_MOVE_M, 1);
|
|
122
|
+
assert.equal(STUCK_WINDOW_MS, 8000);
|
|
123
|
+
// Just under a metre across, along a wall: stuck. Just over: not.
|
|
124
|
+
const along = (m) => (t) => ({ x: 4 + (m / 2) * Math.sin(t / 300), z: -2 });
|
|
125
|
+
assert.ok(firstShown(along(0.9), yes) !== null);
|
|
126
|
+
assert.equal(firstShown(along(1.1), yes), null);
|
|
127
|
+
// It is the corner-to-corner of the box, not the longest side: 0.8 by 0.8 is 1.13.
|
|
128
|
+
const boxed = (m) => (t) => ({ x: 4 + (m / 2) * Math.sin(t / 300), z: -2 + (m / 2) * Math.cos(t / 470) });
|
|
129
|
+
assert.equal(firstShown(boxed(0.8), yes), null);
|
|
130
|
+
assert.ok(firstShown(boxed(0.6), yes) !== null, '0.6 by 0.6 is 0.85');
|
|
131
|
+
// `stuckSpan` says it: null until the window holds 3 s of input.
|
|
132
|
+
const s = makeStuck();
|
|
133
|
+
run(s, 0, 2000, along(0.9), yes);
|
|
134
|
+
assert.equal(stuckSpan(s), null);
|
|
135
|
+
run(s, 2016, 6000, along(0.9), yes);
|
|
136
|
+
assert.ok(stuckSpan(s) > 0.85 && stuckSpan(s) <= 0.9, `${stuckSpan(s)}`);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test('a free walker is never offered it, at 4 to 60 frames a second', () => {
|
|
140
|
+
// The player loop's clamp, which is why: the body moves 33 ms of walking a frame at most
|
|
141
|
+
// (a scene without `engine.maxFps`; the town sets none).
|
|
142
|
+
const loop = fs.readFileSync(new URL('../../physics-3d/engine3d/framecap.js', import.meta.url), 'utf8');
|
|
143
|
+
assert.match(loop, /export const MAX_DT = 0\.033;/);
|
|
144
|
+
assert.match(loop, /const dt = Math\.min\(maxFps > 0 \? MAX_CAPPED_DT : MAX_DT, \(now - clock\.previousTime\) \/ 1000\);/);
|
|
145
|
+
const player = fs.readFileSync(new URL('../../physics-3d/behaviors/Player.jsx', import.meta.url), 'utf8');
|
|
146
|
+
assert.match(player, /static defaultProps = \{ speed: 6,/);
|
|
147
|
+
for (const every of RATES) {
|
|
148
|
+
// Straight on for a minute.
|
|
149
|
+
assert.equal(firstShown((t) => ({ x: (t / every) * STEP_M(every), z: 0 }), yes, every), null, `${every} ms frames, straight`);
|
|
150
|
+
// And in bursts, walking on each time.
|
|
151
|
+
let x = 0;
|
|
152
|
+
assert.equal(firstShown((t) => ({ x: t % 1500 < 1000 ? (x += STEP_M(every)) : x, z: 0 }), (t) => t % 1500 < 1000, every), null, `${every} ms frames, bursts`);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test('pacing back and forth across 3 m is not stuck; across 0.9 m it is', () => {
|
|
157
|
+
// Back and forth along x between 0 and `across`, at the loop's step a frame.
|
|
158
|
+
const pace = (across, every) => {
|
|
159
|
+
let x = 0;
|
|
160
|
+
let dir = 1;
|
|
161
|
+
return () => {
|
|
162
|
+
x += dir * STEP_M(every);
|
|
163
|
+
if (x >= across || x <= 0) {
|
|
164
|
+
dir = -dir;
|
|
165
|
+
x = Math.max(0, Math.min(across, x));
|
|
166
|
+
}
|
|
167
|
+
return { x, z: 0 };
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
for (const every of RATES) {
|
|
171
|
+
assert.equal(firstShown(pace(3, every), yes, every), null, `3 m at ${every} ms frames`);
|
|
172
|
+
assert.ok(firstShown(pace(0.9, every), yes, every) !== null, `0.9 m at ${every} ms frames`);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test('circling a 1.5 m prop is not stuck', () => {
|
|
177
|
+
// Round a prop 1.5 m across with the body's own 0.45 m beyond it: a circle 2.4 m across.
|
|
178
|
+
const radius = 0.75 + 0.45;
|
|
179
|
+
for (const every of RATES) {
|
|
180
|
+
let angle = 0;
|
|
181
|
+
const circle = () => {
|
|
182
|
+
angle += STEP_M(every) / radius;
|
|
183
|
+
return { x: 10 + radius * Math.cos(angle), z: 10 + radius * Math.sin(angle) };
|
|
184
|
+
};
|
|
185
|
+
assert.equal(firstShown(circle, yes, every), null, `${every} ms frames`);
|
|
186
|
+
}
|
|
187
|
+
// Pushing at the prop from one side, sliding a little round it and back: stuck.
|
|
188
|
+
assert.ok(firstShown((t) => ({ x: 10 + radius * Math.cos(0.3 * Math.sin(t / 400)), z: 10 + radius * Math.sin(0.3 * Math.sin(t / 400)) }), yes) !== null);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test('getting somewhere hides it, and a wall met after a walk is counted from the wall', () => {
|
|
192
|
+
const s = makeStuck();
|
|
193
|
+
run(s, 0, 4000, still, yes);
|
|
194
|
+
assert.equal(s.shown, true);
|
|
195
|
+
// Walking off at 6 m/s: gone within the first metre.
|
|
196
|
+
let x = 4;
|
|
197
|
+
const off = run(s, 4016, 4016 + 500, () => ({ x: (x += 6 * 0.016), z: -2 }), yes);
|
|
198
|
+
assert.equal(off.shown, false);
|
|
199
|
+
assert.ok(off.seen.indexOf(false) <= 12, `gone after ${off.seen.indexOf(false)} frames`);
|
|
200
|
+
// On for 4 s more, then into another wall: 3 s of input at the wall, not 8.
|
|
201
|
+
run(s, 4532, 8532, () => ({ x: (x += 6 * 0.016), z: -2 }), yes);
|
|
202
|
+
const wall = { x, z: -2 };
|
|
203
|
+
const hit = 8548;
|
|
204
|
+
assert.equal(run(s, hit, hit + STUCK_AFTER_MS - 200, () => wall, yes).ever, false);
|
|
205
|
+
assert.equal(run(s, hit + STUCK_AFTER_MS - 184, hit + STUCK_AFTER_MS + 200, () => wall, yes).shown, true);
|
|
206
|
+
// Moved without walking (pushed, carried, put somewhere): gone as well.
|
|
207
|
+
assert.equal(stuckFrame(s, { key: 'town', x: x + 9, z: 9, walking: false }, hit + STUCK_AFTER_MS + 216), false);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
test('letting go hides it 3 s after the last input: long enough to tap it', () => {
|
|
211
|
+
const s = makeStuck();
|
|
212
|
+
run(s, 0, 4000, still, yes);
|
|
213
|
+
// The thumb comes off the stick: the chip is still there to be tapped.
|
|
214
|
+
assert.equal(run(s, 4016, 4000 + STUCK_RELEASE_MS - FRAME, still, no).seen.every(Boolean), true);
|
|
215
|
+
assert.equal(run(s, 4000 + STUCK_RELEASE_MS, 4000 + STUCK_RELEASE_MS + 100, still, no).shown, false);
|
|
216
|
+
// Standing there, it stays down.
|
|
217
|
+
assert.equal(run(s, 7200, 30000, still, no).ever, false);
|
|
218
|
+
// Pushed on again after a long rest: 3 s of input once more.
|
|
219
|
+
assert.equal(run(s, 30016, 30016 + STUCK_AFTER_MS - 100, still, yes).ever, false);
|
|
220
|
+
assert.equal(run(s, 30016 + STUCK_AFTER_MS - 84, 30016 + STUCK_AFTER_MS + 200, still, yes).shown, true);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
test('a change of place starts over', () => {
|
|
224
|
+
const s = makeStuck();
|
|
225
|
+
run(s, 0, 4000, still, yes);
|
|
226
|
+
assert.equal(s.shown, true);
|
|
227
|
+
assert.equal(stuckFrame(s, { key: 'race', x: 4, z: -2, walking: true }, 4016), false);
|
|
228
|
+
assert.equal(run(s, 4032, 4016 + STUCK_AFTER_MS - FRAME, still, yes, 'race').ever, false);
|
|
229
|
+
assert.equal(run(s, 4016 + STUCK_AFTER_MS, 4016 + STUCK_AFTER_MS + 100, still, yes, 'race').shown, true);
|
|
230
|
+
// No body to read (between places): nothing, and over again after.
|
|
231
|
+
assert.equal(stuckFrame(s, { key: 'race', x: undefined, z: undefined, walking: true }, 9000), false);
|
|
232
|
+
assert.equal(stuckFrame(s, { key: 'race', x: 4, z: -2, walking: true }, 9016), false);
|
|
233
|
+
assert.equal(s.frames.length, 1);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
test('a pause is not walking time: one frame, 10 s of nothing, then a frame does not show it', () => {
|
|
237
|
+
const s = makeStuck();
|
|
238
|
+
const f = (t, x = 4) => stuckFrame(s, { key: 'town', x, z: -2, walking: true }, t);
|
|
239
|
+
assert.equal(f(0), false);
|
|
240
|
+
// The tab was hidden, or the page stalled: the next frame is 10 s on, 0.1 m away.
|
|
241
|
+
assert.equal(f(10000, 4.1), false);
|
|
242
|
+
// And a whole 3 s of frames is still needed from there.
|
|
243
|
+
assert.equal(run(s, 10016, 10000 + STUCK_AFTER_MS - FRAME, () => ({ x: 4.1, z: -2 }), yes).ever, false);
|
|
244
|
+
assert.equal(run(s, 10000 + STUCK_AFTER_MS, 10000 + STUCK_AFTER_MS + 100, () => ({ x: 4.1, z: -2 }), yes).shown, true);
|
|
245
|
+
// A pause takes a chip that was up with it: nothing is known of what happened in it.
|
|
246
|
+
assert.equal(f(30000, 4.1), false);
|
|
247
|
+
// The clock going backwards is a pause too.
|
|
248
|
+
run(s, 30016, 34000, () => ({ x: 4.1, z: -2 }), yes);
|
|
249
|
+
assert.equal(s.shown, true);
|
|
250
|
+
assert.equal(f(1000, 4.1), false);
|
|
251
|
+
// Exactly at the pause bound it is a pause; just under, a hitch that keeps the count.
|
|
252
|
+
const edge = makeStuck();
|
|
253
|
+
run(edge, 0, 1000, still, yes);
|
|
254
|
+
stuckFrame(edge, { key: 'town', x: 4, z: -2, walking: true }, edge.last + STUCK_PAUSE_MS - 1);
|
|
255
|
+
assert.ok(edge.frames.length > 2, 'just under: nothing forgotten');
|
|
256
|
+
stuckFrame(edge, { key: 'town', x: 4, z: -2, walking: true }, edge.last + STUCK_PAUSE_MS);
|
|
257
|
+
assert.equal(edge.frames.length, 1, 'at the bound: over again');
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
test('a slow phone waits the same 3 s: a frame counts for its own length, up to 100 ms', () => {
|
|
261
|
+
assert.equal(STUCK_FRAME_MAX_MS, 100);
|
|
262
|
+
assert.equal(STUCK_HITCH_MS, 250);
|
|
263
|
+
const shownAt = (every, limit = 60000) => firstShown(still, yes, every, limit);
|
|
264
|
+
// 60, 15, 12 and 10 frames a second: 3 s of wall time, to within a frame.
|
|
265
|
+
for (const every of [16, 66, 83, 100]) {
|
|
266
|
+
const at = shownAt(every);
|
|
267
|
+
assert.ok(at >= STUCK_AFTER_MS && at < STUCK_AFTER_MS + every, `${every} ms frames: shown at ${at}`);
|
|
268
|
+
}
|
|
269
|
+
// 5 frames a second (200 ms, under the hitch bound): each counts 100 ms, so 6 s.
|
|
270
|
+
assert.equal(shownAt(200), 2 * STUCK_AFTER_MS);
|
|
271
|
+
// 4 a second, exactly at the hitch bound: a frame still counts (for 100 ms), 3 s of
|
|
272
|
+
// input is 7.5 s of frames, inside the 8 s looked back over.
|
|
273
|
+
assert.equal(shownAt(STUCK_HITCH_MS), (STUCK_AFTER_MS / STUCK_FRAME_MAX_MS) * STUCK_HITCH_MS);
|
|
274
|
+
// Past it a frame counts for nothing: a page that only hitches never shows it.
|
|
275
|
+
assert.equal(shownAt(STUCK_HITCH_MS + 1), null);
|
|
276
|
+
assert.equal(shownAt(500, 120000), null);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
test('a hitch neither accuses nor forgets: it adds nothing and the count goes on', () => {
|
|
280
|
+
const s = makeStuck();
|
|
281
|
+
// 2 s seen, a 600 ms hitch, then 1 s more: 3 s seen, 3.6 s of wall time.
|
|
282
|
+
assert.equal(run(s, 0, 2000, still, yes).ever, false);
|
|
283
|
+
assert.equal(stuckFrame(s, { key: 'town', x: 4, z: -2, walking: true }, 2600), false);
|
|
284
|
+
assert.equal(s.frames.reduce((sum, frame) => sum + frame.walked, 0), 2000, 'the hitch counted for nothing, and nothing was lost');
|
|
285
|
+
assert.equal(run(s, 2616, 2600 + 1000 - FRAME, still, yes).ever, false);
|
|
286
|
+
assert.equal(run(s, 2600 + 1000, 2600 + 1100, still, yes).shown, true);
|
|
287
|
+
// A hitch with the chip up leaves it up; a pause takes it down.
|
|
288
|
+
assert.equal(stuckFrame(s, { key: 'town', x: 4, z: -2, walking: true }, 4400), true);
|
|
289
|
+
assert.equal(stuckFrame(s, { key: 'town', x: 4, z: -2, walking: true }, 4400 + STUCK_PAUSE_MS), false);
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
test('a page hidden mid-count starts over', () => {
|
|
293
|
+
const s = makeStuck();
|
|
294
|
+
run(s, 0, 2000, still, yes);
|
|
295
|
+
assert.equal(stuckFrame(s, { key: 'town', x: 4, z: -2, walking: true, hidden: true }, 2016), false);
|
|
296
|
+
assert.equal(s.frames.length, 0);
|
|
297
|
+
// Shown again at once (no pause between the frames): the 2 s before do not count.
|
|
298
|
+
assert.equal(run(s, 2032, 2032 + STUCK_AFTER_MS - 2 * FRAME, still, yes).ever, false);
|
|
299
|
+
assert.equal(run(s, 2032 + STUCK_AFTER_MS, 2032 + STUCK_AFTER_MS + 100, still, yes).shown, true);
|
|
300
|
+
// Hidden with the chip up: gone, and frames drawn while hidden count for nothing.
|
|
301
|
+
for (let t = 6000; t < 12000; t += FRAME) {
|
|
302
|
+
assert.equal(stuckFrame(s, { key: 'town', x: 4, z: -2, walking: true, hidden: true }, t), false);
|
|
303
|
+
}
|
|
304
|
+
assert.equal(run(s, 12000, 12000 + STUCK_AFTER_MS - 2 * FRAME, still, yes).ever, false);
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
test('the work of a frame is bounded however fast the device draws', () => {
|
|
308
|
+
// 1000 frames a second for 12 s: never more frames kept than the bound.
|
|
309
|
+
const s = makeStuck();
|
|
310
|
+
for (let t = 0; t <= 12000; t += 1) {
|
|
311
|
+
stuckFrame(s, { key: 'town', x: 4, z: -2, walking: t % 3000 < 2000 }, t);
|
|
312
|
+
assert.ok(s.frames.length <= 4096, `${s.frames.length} frames at ${t}`);
|
|
313
|
+
}
|
|
314
|
+
assert.ok(Math.abs(s.walked - s.frames.reduce((sum, frame) => sum + frame.walked, 0)) < 1e-6, 'the running sum is the frames\' own');
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
// The rule written out the slow way, frame by frame, with nothing kept but
|
|
318
|
+
// every frame ever drawn: what the window holds is the frames no older than
|
|
319
|
+
// 8 s, each by its own time.
|
|
320
|
+
function reference() {
|
|
321
|
+
let all = [];
|
|
322
|
+
let shown = false;
|
|
323
|
+
let last = null;
|
|
324
|
+
let walkedAt = null;
|
|
325
|
+
return ({ x, z, walking, hidden = false }, now) => {
|
|
326
|
+
let dt = last === null ? 0 : now - last;
|
|
327
|
+
// A hidden page, a clock that went backwards, a second with no frame: over again.
|
|
328
|
+
if (hidden || dt < 0 || dt >= STUCK_PAUSE_MS) {
|
|
329
|
+
all = [];
|
|
330
|
+
shown = false;
|
|
331
|
+
walkedAt = null;
|
|
332
|
+
last = null;
|
|
333
|
+
dt = 0;
|
|
334
|
+
if (hidden) {
|
|
335
|
+
return { shown: false, held: 0 };
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
last = now;
|
|
339
|
+
all.push({ at: now, walked: walking && dt <= STUCK_HITCH_MS ? Math.min(dt, STUCK_FRAME_MAX_MS) : 0, x, z });
|
|
340
|
+
if (walking) {
|
|
341
|
+
walkedAt = now;
|
|
342
|
+
}
|
|
343
|
+
const inWindow = all.filter((f) => f.at > now - STUCK_WINDOW_MS);
|
|
344
|
+
const need = shown ? STUCK_KEEP_MS : STUCK_AFTER_MS;
|
|
345
|
+
let sum = 0;
|
|
346
|
+
let span = null;
|
|
347
|
+
const box = { x0: Infinity, x1: -Infinity, z0: Infinity, z1: -Infinity };
|
|
348
|
+
for (let i = inWindow.length - 1; i >= 0 && span === null; i -= 1) {
|
|
349
|
+
const f = inWindow[i];
|
|
350
|
+
sum += f.walked;
|
|
351
|
+
box.x0 = Math.min(box.x0, f.x);
|
|
352
|
+
box.x1 = Math.max(box.x1, f.x);
|
|
353
|
+
box.z0 = Math.min(box.z0, f.z);
|
|
354
|
+
box.z1 = Math.max(box.z1, f.z);
|
|
355
|
+
if (sum >= need) {
|
|
356
|
+
span = Math.hypot(box.x1 - box.x0, box.z1 - box.z0);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
shown = span !== null && span < STUCK_MOVE_M && walkedAt !== null && now - walkedAt < STUCK_RELEASE_MS;
|
|
360
|
+
return { shown, held: inWindow.reduce((total, f) => total + f.walked, 0) };
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
test('right at the threshold the chip does not flicker: 375 ms of every second, 5 ms frames', () => {
|
|
365
|
+
// The reviewed case: exactly 3,000 ms of input in every 8 s once the window is full.
|
|
366
|
+
const s = makeStuck();
|
|
367
|
+
const ref = reference();
|
|
368
|
+
let flips = 0;
|
|
369
|
+
let was = false;
|
|
370
|
+
let firstAt = null;
|
|
371
|
+
for (let t = 0; t <= 40000; t += 5) {
|
|
372
|
+
const walking = t % 1000 < 375;
|
|
373
|
+
const shown = stuckFrame(s, { key: 'town', x: 4, z: -2, walking }, t);
|
|
374
|
+
const want = ref({ x: 4, z: -2, walking }, t);
|
|
375
|
+
assert.equal(shown, want.shown, `at ${t}`);
|
|
376
|
+
assert.ok(Math.abs(s.walked - want.held) < 1e-6, `the window holds ${want.held} at ${t}, kept ${s.walked}`);
|
|
377
|
+
if (t >= 8000) {
|
|
378
|
+
assert.equal(want.held, 3000, 'exactly 3 s in every full window');
|
|
379
|
+
}
|
|
380
|
+
if (shown !== was) {
|
|
381
|
+
flips += 1;
|
|
382
|
+
firstAt ??= t;
|
|
383
|
+
was = shown;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
assert.equal(flips, 1, 'up once, and it stays');
|
|
387
|
+
assert.ok(firstAt >= 7370 && firstAt <= 8000, `up as the window first holds 3 s: ${firstAt}`);
|
|
388
|
+
assert.equal(was, true);
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
test('a frame leaves the window by its own time, and the chip stays until the window holds under 2.5 s', () => {
|
|
392
|
+
assert.equal(STUCK_KEEP_MS, 2500);
|
|
393
|
+
// 3.1 s of input in one go, then none: 3 s after the last input it goes (the release rule).
|
|
394
|
+
const s = makeStuck();
|
|
395
|
+
run(s, 0, 3100, still, yes, 'town', 5);
|
|
396
|
+
assert.equal(s.shown, true);
|
|
397
|
+
assert.equal(s.walked, 3100);
|
|
398
|
+
// Just short of the threshold in every window: 370 of every 1000 ms is 2,960 in 8 s. Never.
|
|
399
|
+
assert.equal(firstShown(still, (t) => t % 1000 < 370, 5, 40000), null);
|
|
400
|
+
// Shown, then the player eases off to 320 of every 1000 (2,560 in 8 s, over 2.5 s): it stays.
|
|
401
|
+
const eased = makeStuck();
|
|
402
|
+
run(eased, 0, 10000, still, (t) => t % 1000 < 400, 'town', 5);
|
|
403
|
+
assert.equal(eased.shown, true);
|
|
404
|
+
assert.equal(run(eased, 10005, 40000, still, (t) => t % 1000 < 320, 'town', 5).seen.every(Boolean), true);
|
|
405
|
+
// To 300 of every 1000 (2,400 in 8 s): it goes, once, and stays gone.
|
|
406
|
+
const off = run(eased, 40005, 70000, still, (t) => t % 1000 < 300, 'town', 5).seen;
|
|
407
|
+
assert.equal(off.at(-1), false);
|
|
408
|
+
assert.equal(off.filter((v, i) => i > 0 && v !== off[i - 1]).length, 1);
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
test('for any pattern of bursts, frame rate and wandering the chip is exactly what the frames in the window say', () => {
|
|
412
|
+
// A small seeded generator, so a failure names its case.
|
|
413
|
+
const rng = (seed) => () => {
|
|
414
|
+
seed = (seed * 1664525 + 1013904223) >>> 0;
|
|
415
|
+
return seed / 4294967296;
|
|
416
|
+
};
|
|
417
|
+
for (let seed = 1; seed <= 60; seed += 1) {
|
|
418
|
+
const r = rng(seed);
|
|
419
|
+
const every = [4, 5, 8, 16, 33, 50, 83, 100, 200, 250, 300][Math.floor(r() * 11)];
|
|
420
|
+
const jitter = r() < 0.5;
|
|
421
|
+
const on = 100 + Math.floor(r() * 1500);
|
|
422
|
+
const off = Math.floor(r() * 1500);
|
|
423
|
+
// Where the body goes: nowhere, a shuffle under or over a metre, or walking on.
|
|
424
|
+
const kind = Math.floor(r() * 4);
|
|
425
|
+
const reach = [0, 0.3 + r() * 0.6, 1.05 + r() * 2, 0][kind];
|
|
426
|
+
const s = makeStuck();
|
|
427
|
+
const ref = reference();
|
|
428
|
+
let t = 0;
|
|
429
|
+
let x = 0;
|
|
430
|
+
let flips = 0;
|
|
431
|
+
let was = false;
|
|
432
|
+
while (t <= 30000) {
|
|
433
|
+
const walking = t % (on + off) < on;
|
|
434
|
+
if (kind === 3 && walking) {
|
|
435
|
+
x += 0.02;
|
|
436
|
+
}
|
|
437
|
+
const at = { x: kind === 3 ? x : (reach / 2) * Math.sin(t / 700), z: kind === 2 ? (reach / 3) * Math.cos(t / 900) : 0 };
|
|
438
|
+
const shown = stuckFrame(s, { key: 'town', x: at.x, z: at.z, walking }, t);
|
|
439
|
+
const want = ref({ ...at, walking }, t);
|
|
440
|
+
assert.equal(shown, want.shown, `seed ${seed} (${every} ms frames, ${on} on / ${off} off, kind ${kind}) at ${t}`);
|
|
441
|
+
assert.ok(Math.abs(s.walked - want.held) < 1e-6, `seed ${seed} at ${t}: the window holds ${want.held}, kept ${s.walked}`);
|
|
442
|
+
flips += shown !== was ? 1 : 0;
|
|
443
|
+
was = shown;
|
|
444
|
+
// Now and then a frame comes late, short of a pause.
|
|
445
|
+
t += jitter && r() < 0.05 ? every + Math.floor(r() * 600) : every;
|
|
446
|
+
}
|
|
447
|
+
if (kind === 3 || kind === 2) {
|
|
448
|
+
assert.equal(flips, 0, `seed ${seed}: a body that gets somewhere is never offered it`);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
test('the clock going backwards starts over at zero: the frame that resets counts for nothing', () => {
|
|
454
|
+
// The reviewed case: at 4,000 ms the clock is back at 0; 3 s of walking on the
|
|
455
|
+
// spot from there is 3 s, not 2 (the reset frame took 1 s away, and the chip waited 7 s).
|
|
456
|
+
const s = makeStuck();
|
|
457
|
+
run(s, 0, 4000, still, yes);
|
|
458
|
+
assert.equal(s.shown, true);
|
|
459
|
+
assert.equal(stuckFrame(s, { key: 'town', x: 4, z: -2, walking: true }, 0), false);
|
|
460
|
+
assert.equal(s.walked, 0, 'back at 0: nothing, and nothing taken away');
|
|
461
|
+
assert.deepEqual(s.frames.map((f) => f.walked), [0]);
|
|
462
|
+
assert.equal(run(s, 16, STUCK_AFTER_MS - FRAME, still, yes).ever, false);
|
|
463
|
+
assert.equal(run(s, STUCK_AFTER_MS, STUCK_AFTER_MS + 2 * FRAME, still, yes).shown, true);
|
|
464
|
+
assert.equal(s.walked >= STUCK_AFTER_MS && s.walked <= STUCK_AFTER_MS + 2 * FRAME, true, `${s.walked}`);
|
|
465
|
+
// The same after a pause, a hidden page and a change of place: the first frame is 0.
|
|
466
|
+
for (const next of [
|
|
467
|
+
{ now: 20000, frame: { key: 'town', x: 4, z: -2, walking: true } },
|
|
468
|
+
{ now: STUCK_AFTER_MS + 100, frame: { key: 'race', x: 4, z: -2, walking: true } },
|
|
469
|
+
]) {
|
|
470
|
+
const again = makeStuck();
|
|
471
|
+
run(again, 0, STUCK_AFTER_MS + 50, still, yes);
|
|
472
|
+
stuckFrame(again, next.frame, next.now);
|
|
473
|
+
assert.equal(again.walked, 0);
|
|
474
|
+
assert.deepEqual(again.frames.map((f) => f.walked), [0]);
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
test('whatever the clock and the page do, the running total is never negative and is the sum of the frames in the window', () => {
|
|
479
|
+
const rng = (seed) => () => {
|
|
480
|
+
seed = (seed * 1664525 + 1013904223) >>> 0;
|
|
481
|
+
return seed / 4294967296;
|
|
482
|
+
};
|
|
483
|
+
let jumps = 0;
|
|
484
|
+
let gaps = 0;
|
|
485
|
+
let hiddens = 0;
|
|
486
|
+
for (let seed = 101; seed <= 180; seed += 1) {
|
|
487
|
+
const r = rng(seed);
|
|
488
|
+
const every = [4, 5, 8, 16, 33, 50, 83, 100, 200, 250][Math.floor(r() * 10)];
|
|
489
|
+
const on = 100 + Math.floor(r() * 1500);
|
|
490
|
+
const off = Math.floor(r() * 1200);
|
|
491
|
+
const reach = [0, 0.4, 1.5][Math.floor(r() * 3)];
|
|
492
|
+
const s = makeStuck();
|
|
493
|
+
const ref = reference();
|
|
494
|
+
let t = 5000 + Math.floor(r() * 5000);
|
|
495
|
+
let hiddenFor = 0;
|
|
496
|
+
for (let frame = 0; frame < 4000; frame += 1) {
|
|
497
|
+
const walking = (frame * every) % (on + off) < on;
|
|
498
|
+
const hidden = hiddenFor > 0;
|
|
499
|
+
hiddenFor -= 1;
|
|
500
|
+
const at = { x: (reach / 2) * Math.sin(frame / 40), z: 0 };
|
|
501
|
+
const shown = stuckFrame(s, { key: 'town', x: at.x, z: at.z, walking, hidden }, t);
|
|
502
|
+
const want = ref({ ...at, walking, hidden }, t);
|
|
503
|
+
const where = `seed ${seed}, frame ${frame} at ${t}`;
|
|
504
|
+
assert.equal(shown, want.shown, where);
|
|
505
|
+
assert.ok(s.walked >= 0, `${where}: the total is ${s.walked}`);
|
|
506
|
+
assert.ok(s.frames.every((f) => f.walked >= 0 && f.walked <= STUCK_FRAME_MAX_MS), where);
|
|
507
|
+
const sum = s.frames.reduce((total, f) => total + f.walked, 0);
|
|
508
|
+
assert.ok(Math.abs(s.walked - sum) < 1e-6, `${where}: total ${s.walked}, frames ${sum}`);
|
|
509
|
+
assert.ok(Math.abs(s.walked - want.held) < 1e-6, `${where}: the window holds ${want.held}, kept ${s.walked}`);
|
|
510
|
+
// What comes next: a frame; now and then the clock jumps back, a second
|
|
511
|
+
// or more goes by with no frame, a frame comes late, or the page is hidden a while.
|
|
512
|
+
const roll = r();
|
|
513
|
+
if (roll < 0.004) {
|
|
514
|
+
t -= 1 + Math.floor(r() * 6000);
|
|
515
|
+
jumps += 1;
|
|
516
|
+
} else if (roll < 0.008) {
|
|
517
|
+
t += STUCK_PAUSE_MS + Math.floor(r() * 3000);
|
|
518
|
+
gaps += 1;
|
|
519
|
+
} else if (roll < 0.012) {
|
|
520
|
+
hiddenFor = 1 + Math.floor(r() * 30);
|
|
521
|
+
hiddens += 1;
|
|
522
|
+
t += every;
|
|
523
|
+
} else if (roll < 0.03) {
|
|
524
|
+
t += every + Math.floor(r() * 700);
|
|
525
|
+
} else {
|
|
526
|
+
t += every;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
assert.ok(jumps > 300 && gaps > 300 && hiddens > 300, `each was tried many times: ${jumps} back, ${gaps} gaps, ${hiddens} hidden`);
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
test("walk input is the Player behavior's own rule, under both cameras", () => {
|
|
534
|
+
const keys = (...codes) => new Set(codes);
|
|
535
|
+
const stick = (x, y) => ({ active: true, x, y });
|
|
536
|
+
for (const orbit of [true, false]) {
|
|
537
|
+
assert.equal(walkInput(keys('KeyW'), null, orbit), true);
|
|
538
|
+
assert.equal(walkInput(keys('ArrowDown'), null, orbit), true);
|
|
539
|
+
assert.equal(walkInput(keys(), null, orbit), false);
|
|
540
|
+
assert.equal(walkInput(undefined, undefined, orbit), false);
|
|
541
|
+
assert.equal(walkInput(keys('Space'), null, orbit), false, 'a jump is not a walk');
|
|
542
|
+
assert.equal(walkInput(keys('ArrowLeft'), null, orbit), false, 'turning');
|
|
543
|
+
assert.equal(walkInput(keys('KeyW', 'KeyS'), null, orbit), false, 'both ways is neither');
|
|
544
|
+
assert.equal(walkInput(keys(), stick(0, -0.8), orbit), true);
|
|
545
|
+
assert.equal(walkInput(keys(), stick(0.05, 0.05), orbit), false, 'the dead zone');
|
|
546
|
+
assert.equal(walkInput(keys(), stick(0.1, 0.1), orbit), false, 'the dead zone is of its length: 0.141');
|
|
547
|
+
assert.equal(walkInput(keys(), { active: false, x: 0, y: -1 }, orbit), false);
|
|
548
|
+
// The dead zone is the stick's LENGTH; past it any push up or down walks.
|
|
549
|
+
assert.equal(walkInput(keys(), stick(0.9, 0.1), orbit), true, 'mostly sideways, a little back: the body walks');
|
|
550
|
+
assert.equal(walkInput(keys(), stick(0.9, -0.01), orbit), true);
|
|
551
|
+
assert.equal(walkInput(keys(), stick(0.12, 0.1), orbit), true, 'length 0.156');
|
|
552
|
+
// A walk key with a turn key still walks.
|
|
553
|
+
assert.equal(walkInput(keys('KeyW', 'ArrowLeft'), null, orbit), true);
|
|
554
|
+
assert.equal(walkInput(keys('KeyW', 'KeyA'), null, orbit), true);
|
|
555
|
+
// W and S together ask for nothing, so the stick is read.
|
|
556
|
+
assert.equal(walkInput(keys('KeyW', 'KeyS'), stick(0, -1), orbit), true);
|
|
557
|
+
}
|
|
558
|
+
// The drive camera (`readDrive`): a stick straight sideways and A/D only turn,
|
|
559
|
+
// and the stick is not read while the keys ask for a turn.
|
|
560
|
+
assert.equal(walkInput(keys(), stick(0.9, 0), false), false);
|
|
561
|
+
assert.equal(walkInput(keys('KeyA'), null, false), false);
|
|
562
|
+
assert.equal(walkInput(keys('KeyA'), stick(0, -1), false), false);
|
|
563
|
+
assert.equal(walkInput(keys('ArrowRight'), stick(0, -1), false), false);
|
|
564
|
+
assert.equal(walkInput(keys('KeyA', 'KeyD'), stick(0, -1), false), true, 'the two turns cancel: the stick is read');
|
|
565
|
+
assert.equal(walkInput(keys('ArrowLeft', 'KeyD'), stick(0, -1), false), true);
|
|
566
|
+
// The orbit camera (`driveOrbiting`): A/D and a sideways stick walk; left and
|
|
567
|
+
// right swing the camera and do not stop the stick being read.
|
|
568
|
+
assert.equal(walkInput(keys(), stick(0.9, 0), true), true);
|
|
569
|
+
assert.equal(walkInput(keys('KeyA'), null, true), true);
|
|
570
|
+
assert.equal(walkInput(keys('KeyA', 'KeyD'), null, true), false);
|
|
571
|
+
assert.equal(walkInput(keys('ArrowRight'), stick(0, -1), true), true);
|
|
572
|
+
assert.equal(walkInput(keys('ArrowRight'), stick(0.9, 0), true), true);
|
|
573
|
+
// The source this mirrors still reads as it did.
|
|
574
|
+
const player = fs.readFileSync(new URL('../../physics-3d/behaviors/Player.jsx', import.meta.url), 'utf8');
|
|
575
|
+
assert.match(player, /if \(forward === 0 && turn === 0 && stick\?\.active && Math\.hypot\(stick\.x, stick\.y\) >= 0\.15\) \{\n {4}forward = -stick\.y;/);
|
|
576
|
+
assert.match(player, /drive\.forward !== 0/);
|
|
577
|
+
assert.match(player, /if \(ahead === 0 && aside === 0 && stick\?\.active && Math\.hypot\(stick\.x, stick\.y\) >= 0\.15\) \{\n {4}ahead = -stick\.y;\n {4}aside = stick\.x;/);
|
|
578
|
+
assert.match(player, /let ahead = held\(keys, \['KeyW', 'ArrowUp'\], \['KeyS', 'ArrowDown'\]\);/);
|
|
579
|
+
// With no held shot (the case `walkInput` mirrors) only A/D walk sideways and
|
|
580
|
+
// the arrows swing the camera. A held shot's arrows strafe instead (36d66bfe).
|
|
581
|
+
assert.match(player, /let aside = shot \? [^:\n]+ : held\(keys, \['KeyD'\], \['KeyA'\]\);/);
|
|
582
|
+
assert.match(player, /if \(!shot\) per\.camAngle \+= held\(keys, \['ArrowRight'\], \['ArrowLeft'\]\)/);
|
|
583
|
+
});
|
|
584
|
+
|
|
585
|
+
test('the words say where the tap goes', () => {
|
|
586
|
+
assert.equal(stuckText('the square'), 'Stuck? Tap to go to the square');
|
|
587
|
+
assert.equal(stuckText(null), 'Stuck? Tap to go back to the start');
|
|
588
|
+
assert.equal(stuckWhere('the square'), 'Back to the square');
|
|
589
|
+
assert.equal(stuckWhere(null), 'Back to the start');
|
|
590
|
+
// v1.39, a spot the place picks: its own name for it, or words that name nowhere.
|
|
591
|
+
assert.equal(stuckText('the street', true), 'Stuck? Tap to go to the street');
|
|
592
|
+
assert.equal(stuckText(null, true), 'Stuck? Tap to get unstuck');
|
|
593
|
+
assert.equal(stuckWhere(null, true), 'Get unstuck');
|
|
594
|
+
assert.equal(stuckDone('the street', true), 'Back to the street');
|
|
595
|
+
assert.equal(stuckDone(null, true), "You're unstuck");
|
|
596
|
+
assert.equal(stuckDone('the square', false), 'Back to the square');
|
|
597
|
+
assert.equal(stuckDone(null, false), 'Back to the start');
|
|
598
|
+
});
|
|
599
|
+
|
|
600
|
+
// --- where the chip may sit ---------------------------------------------------
|
|
601
|
+
|
|
602
|
+
const PORTRAIT = { w: 412, h: 870 };
|
|
603
|
+
const LANDSCAPE = { w: 800, h: 360 };
|
|
604
|
+
// The chip where the chrome hangs it in a view: centred, its bottom 202 px up.
|
|
605
|
+
const hung = (view, w = 234, h = 34) => ({ left: view.w / 2 - w / 2, right: view.w / 2 + w / 2, top: view.h - 202 - h, bottom: view.h - 202 });
|
|
606
|
+
const mid = (view, w, top, h) => ({ left: view.w / 2 - w / 2, right: view.w / 2 + w / 2, top, bottom: top + h });
|
|
607
|
+
const clear = (a, b, gap = 6) => a.right <= b.left || a.left >= b.right || a.bottom + gap <= b.top || a.top >= b.bottom + gap;
|
|
608
|
+
|
|
609
|
+
test('portrait 412x870: the chip stays where it hangs, clear of the errands, a question and the buttons', () => {
|
|
610
|
+
const box = hung(PORTRAIT);
|
|
611
|
+
assert.deepEqual(box, { left: 89, right: 323, top: 634, bottom: 668 }, 'as it measured on the page');
|
|
612
|
+
const errands = mid(PORTRAIT, 246, 12, 90);
|
|
613
|
+
const wrapped = mid(PORTRAIT, 320, 92, 62);
|
|
614
|
+
const others = [
|
|
615
|
+
{ left: 10, right: 89, top: 823, bottom: 860 }, // Doors
|
|
616
|
+
{ left: 289, right: 402, top: 823, bottom: 860 }, // Character
|
|
617
|
+
{ left: 340, right: 392, top: 672, bottom: 724 }, // emote
|
|
618
|
+
{ left: 340, right: 392, top: 612, bottom: 664 }, // quick chat
|
|
619
|
+
mid(PORTRAIT, 180, 870 - 160 - 30, 30), // the invite button
|
|
620
|
+
mid(PORTRAIT, 90, 870 - 112 - 40, 40), // Sit
|
|
621
|
+
mid(PORTRAIT, 200, 870 - 64 - 36, 36), // a toast
|
|
622
|
+
];
|
|
623
|
+
assert.equal(chipShift(box, [errands, wrapped], others, PORTRAIT.h), 0);
|
|
624
|
+
for (const other of [errands, wrapped, ...others]) {
|
|
625
|
+
assert.equal(clear(box, other), true);
|
|
626
|
+
}
|
|
627
|
+
});
|
|
628
|
+
|
|
629
|
+
test('landscape 800x360: the chip hangs over a question, and is moved to just under it', () => {
|
|
630
|
+
const box = hung(LANDSCAPE);
|
|
631
|
+
assert.deepEqual(box, { left: 283, right: 517, top: 124, bottom: 158 });
|
|
632
|
+
const hud = mid(LANDSCAPE, 400, 12, 48);
|
|
633
|
+
// No question: clear of the HUD as it hangs.
|
|
634
|
+
assert.equal(chipShift(box, [hud], [], LANDSCAPE.h), 0);
|
|
635
|
+
// A party question wrapped to two lines, from 92 to 154: the reviewer's case.
|
|
636
|
+
const wrapped = mid(LANDSCAPE, 320, 92, 62);
|
|
637
|
+
assert.equal(clear(box, wrapped), false, 'where it hangs is over the question');
|
|
638
|
+
let down = chipShift(box, [hud, wrapped], [], LANDSCAPE.h);
|
|
639
|
+
assert.equal(down, 154 + 6 - 124);
|
|
640
|
+
assert.equal(box.top + down, 160, 'just under it');
|
|
641
|
+
// "Play <door> again?" on one line, from 92 to 138.
|
|
642
|
+
const again = mid(LANDSCAPE, 320, 92, 46);
|
|
643
|
+
down = chipShift(box, [hud, again], [mid(LANDSCAPE, 90, 360 - 112 - 40, 40)], LANDSCAPE.h);
|
|
644
|
+
assert.equal(box.top + down, 144);
|
|
645
|
+
assert.equal(box.bottom + down + 6 <= 208, true, 'and clear over Sit');
|
|
646
|
+
// The order they are given in does not matter.
|
|
647
|
+
assert.equal(chipShift(box, [again, hud], [], LANDSCAPE.h), down);
|
|
648
|
+
});
|
|
649
|
+
|
|
650
|
+
test('no room: under the question it would lie over another control, so it is not drawn', () => {
|
|
651
|
+
const box = hung(LANDSCAPE);
|
|
652
|
+
const hud = mid(LANDSCAPE, 400, 12, 48);
|
|
653
|
+
const wrapped = mid(LANDSCAPE, 320, 92, 62);
|
|
654
|
+
const invite = mid(LANDSCAPE, 180, 360 - 160 - 30, 30);
|
|
655
|
+
assert.equal(chipShift(box, [hud, wrapped], [invite], LANDSCAPE.h), null);
|
|
656
|
+
// The invite button alone is under where it hangs: clear.
|
|
657
|
+
assert.equal(chipShift(box, [hud], [invite], LANDSCAPE.h), 0);
|
|
658
|
+
// A HUD so tall it reaches the question's place and past it: under it, if that fits.
|
|
659
|
+
const tall = mid(LANDSCAPE, 400, 12, 160);
|
|
660
|
+
assert.equal(box.top + chipShift(box, [tall], [], LANDSCAPE.h), 178);
|
|
661
|
+
assert.equal(chipShift(box, [tall], [mid(LANDSCAPE, 200, 360 - 64 - 36, 36)], LANDSCAPE.h), 178 - 124, 'the toast is at 260: clear');
|
|
662
|
+
assert.equal(chipShift(box, [tall], [mid(LANDSCAPE, 90, 360 - 112 - 40, 40)], LANDSCAPE.h), null, 'Sit is at 208: not clear');
|
|
663
|
+
});
|
|
664
|
+
|
|
665
|
+
test('shorter views: under the HUD and the question while it fits whole in the view, else not drawn', () => {
|
|
666
|
+
// 800x250: it hangs at 14, inside the HUD.
|
|
667
|
+
const view = { w: 800, h: 250 };
|
|
668
|
+
const box = hung(view);
|
|
669
|
+
assert.equal(box.top, 14);
|
|
670
|
+
const hud = mid(view, 400, 12, 48);
|
|
671
|
+
assert.equal(box.top + chipShift(box, [hud], [], view.h), 66);
|
|
672
|
+
const again = mid(view, 320, 92, 46);
|
|
673
|
+
assert.equal(box.top + chipShift(box, [hud, again], [], view.h), 144);
|
|
674
|
+
assert.equal(chipShift(box, [hud, again], [mid(view, 200, 250 - 64 - 36, 36)], view.h), null, 'a toast is there');
|
|
675
|
+
// 800x180: under both would run off the bottom.
|
|
676
|
+
const tiny = { w: 800, h: 180 };
|
|
677
|
+
assert.equal(chipShift(hung(tiny), [mid(tiny, 400, 12, 48), mid(tiny, 320, 92, 46)], [], tiny.h), null);
|
|
678
|
+
// It hangs off the top of the view, with nothing up: brought into it.
|
|
679
|
+
assert.equal(hung(tiny).top, -56);
|
|
680
|
+
assert.equal(hung(tiny).top + chipShift(hung(tiny), [], [], tiny.h), 6);
|
|
681
|
+
// Something beside it, not over or under it, is not in its way.
|
|
682
|
+
assert.equal(chipShift(hung(LANDSCAPE), [{ left: 0, right: 200, top: 100, bottom: 300 }], [{ left: 600, right: 800, top: 100, bottom: 300 }], LANDSCAPE.h), 0);
|
|
683
|
+
});
|
|
684
|
+
|
|
685
|
+
// --- the chrome, over a stand-in DOM ----------------------------------------
|
|
686
|
+
|
|
687
|
+
// A stand-in layout, enough for where the chip goes: a node's box on screen is
|
|
688
|
+
// its `rect` (set by a test, as the browser would lay the chrome's CSS out),
|
|
689
|
+
// nothing while it is not displayed; the chip hangs where its own CSS puts it
|
|
690
|
+
// (centred, its bottom 202 px up), 234 x 34 as it measured on a 412 px phone.
|
|
691
|
+
const CHIP = { w: 234, h: 34, up: 202 };
|
|
692
|
+
function fakeDom(view = PORTRAIT) {
|
|
693
|
+
const made = [];
|
|
694
|
+
function node(tag) {
|
|
695
|
+
const listeners = {};
|
|
696
|
+
const self = {
|
|
697
|
+
tag,
|
|
698
|
+
children: [],
|
|
699
|
+
parent: null,
|
|
700
|
+
dataset: {},
|
|
701
|
+
attrs: {},
|
|
702
|
+
style: {},
|
|
703
|
+
textContent: '',
|
|
704
|
+
appendChild(child) {
|
|
705
|
+
child.parent = self;
|
|
706
|
+
self.children.push(child);
|
|
707
|
+
return child;
|
|
708
|
+
},
|
|
709
|
+
insertBefore(child, before) {
|
|
710
|
+
if (child.parent) {
|
|
711
|
+
child.parent.children = child.parent.children.filter((c) => c !== child);
|
|
712
|
+
}
|
|
713
|
+
child.parent = self;
|
|
714
|
+
const at = self.children.indexOf(before);
|
|
715
|
+
self.children.splice(at < 0 ? self.children.length : at, 0, child);
|
|
716
|
+
return child;
|
|
717
|
+
},
|
|
718
|
+
remove() {
|
|
719
|
+
if (self.parent) {
|
|
720
|
+
self.parent.children = self.parent.children.filter((c) => c !== self);
|
|
721
|
+
}
|
|
722
|
+
},
|
|
723
|
+
replaceChildren() {
|
|
724
|
+
self.children = [];
|
|
725
|
+
},
|
|
726
|
+
addEventListener: (type, fn) => (listeners[type] = fn),
|
|
727
|
+
removeEventListener() {},
|
|
728
|
+
setAttribute: (key, value) => (self.attrs[key] = String(value)),
|
|
729
|
+
press: () => listeners.pointerdown({ stopPropagation() {}, preventDefault() {} }),
|
|
730
|
+
focus() {},
|
|
731
|
+
blur() {},
|
|
732
|
+
rect: null,
|
|
733
|
+
// For what the chrome hangs from a point (a label, a pointer, a cabinet's
|
|
734
|
+
// card, the ribbon): its size, its box then following `left`/`top`.
|
|
735
|
+
size: null,
|
|
736
|
+
getBoundingClientRect() {
|
|
737
|
+
let r = self.style.display === 'none' ? null : self.rect;
|
|
738
|
+
if (self.style.display !== 'none' && self.dataset.hub === 'toast') {
|
|
739
|
+
const w = self.size?.w ?? 200;
|
|
740
|
+
const h = self.size?.h ?? 36;
|
|
741
|
+
const top = self.style.bottom ? view.h - Number.parseFloat(self.style.bottom) - h : Number.parseFloat(self.style.top) || 12;
|
|
742
|
+
r = { left: (view.w - w) / 2, right: (view.w + w) / 2, top, bottom: top + h };
|
|
743
|
+
}
|
|
744
|
+
if (self.style.display !== 'none' && self.dataset.hub === 'stuck') {
|
|
745
|
+
const down = Number(/translate\(-50%, (-?[\d.]+)px\)/.exec(self.style.transform)?.[1] ?? 0);
|
|
746
|
+
const top = self.offsetTop + down;
|
|
747
|
+
r = { left: (view.w - CHIP.w) / 2, right: (view.w + CHIP.w) / 2, top, bottom: top + CHIP.h };
|
|
748
|
+
}
|
|
749
|
+
if (!r && self.style.display !== 'none' && self.size && self.style.left) {
|
|
750
|
+
const x = parseFloat(self.style.left);
|
|
751
|
+
const y = parseFloat(self.style.top);
|
|
752
|
+
const top = String(self.style.transform).includes('-50%, -50%') ? y - self.size.h / 2 : y - self.size.h;
|
|
753
|
+
r = { left: x - self.size.w / 2, right: x + self.size.w / 2, top, bottom: top + self.size.h };
|
|
754
|
+
}
|
|
755
|
+
return r ? { ...r, width: r.right - r.left, height: r.bottom - r.top } : { left: 0, right: 0, top: 0, bottom: 0, width: 0, height: 0 };
|
|
756
|
+
},
|
|
757
|
+
get offsetWidth() {
|
|
758
|
+
return self.dataset.hub === 'stuck' ? CHIP.w : (self.size?.w ?? (self.dataset.hub === 'toast' ? 200 : 100));
|
|
759
|
+
},
|
|
760
|
+
get offsetHeight() {
|
|
761
|
+
return self.dataset.hub === 'stuck' ? CHIP.h : (self.size?.h ?? (self.dataset.hub === 'toast' ? 36 : 40));
|
|
762
|
+
},
|
|
763
|
+
get offsetLeft() {
|
|
764
|
+
return self.dataset.hub === 'stuck' ? view.w / 2 : 0;
|
|
765
|
+
},
|
|
766
|
+
get offsetTop() {
|
|
767
|
+
return self.dataset.hub === 'stuck' ? view.h - CHIP.up - CHIP.h : 0;
|
|
768
|
+
},
|
|
769
|
+
};
|
|
770
|
+
made.push(self);
|
|
771
|
+
return self;
|
|
772
|
+
}
|
|
773
|
+
const body = node('body');
|
|
774
|
+
globalThis.document = { body, createElement: node, activeElement: null };
|
|
775
|
+
const events = {};
|
|
776
|
+
globalThis.window = { innerWidth: view.w, innerHeight: view.h, addEventListener: (type, fn) => (events[type] = fn), removeEventListener: (type) => delete events[type] };
|
|
777
|
+
return { made, events };
|
|
778
|
+
}
|
|
779
|
+
const { makeChrome } = await import('../code/client/chrome.js');
|
|
780
|
+
// The chrome's own nodes, found by the CSS it gives them, and laid out as the
|
|
781
|
+
// browser lays that CSS out: the HUD from 12 px down the middle, a question
|
|
782
|
+
// from 92 px (`h` tall: 46 one line, 62 wrapped to two on a 320 px card), and
|
|
783
|
+
// the bottom-centre buttons by how far up they hang.
|
|
784
|
+
function rig(view = PORTRAIT) {
|
|
785
|
+
const dom = fakeDom(view);
|
|
786
|
+
const chrome = makeChrome({ onBack() {}, onAvatar() {}, avatarCount: 4 });
|
|
787
|
+
const by = (test) => dom.made.find((c) => test(c.style));
|
|
788
|
+
const nodes = {
|
|
789
|
+
hud: by((st) => st.textShadow?.includes('rgba(0,0,0,0.95)')),
|
|
790
|
+
ask: by((st) => st.width === 'min(86vw, 320px)'),
|
|
791
|
+
near: by((st) => String(st.bottom).startsWith('max(160px')),
|
|
792
|
+
sit: by((st) => String(st.bottom).startsWith('max(112px')),
|
|
793
|
+
toast: dom.made.find((c) => c.dataset.hub === 'toast'),
|
|
794
|
+
};
|
|
795
|
+
const mid = view.w / 2;
|
|
796
|
+
const centred = (w, top, h) => ({ left: mid - w / 2, right: mid + w / 2, top, bottom: top + h });
|
|
797
|
+
const lay = {
|
|
798
|
+
hud: (h, w = Math.min((view.w > view.h ? 0.42 : 0.7) * view.w, view.w > view.h ? 420 : 400)) => (nodes.hud.rect = centred(w, 12, h)),
|
|
799
|
+
ask: (h) => (nodes.ask.rect = centred(Math.min(0.86 * view.w, 320), 92, h)),
|
|
800
|
+
near: () => (nodes.near.rect = centred(180, view.h - 160 - 30, 30)),
|
|
801
|
+
sit: () => (nodes.sit.rect = centred(90, view.h - 112 - 40, 40)),
|
|
802
|
+
toast: () => {
|
|
803
|
+
nodes.toast.size = { w: 200, h: 36 };
|
|
804
|
+
nodes.toast.rect = centred(200, 12, 36);
|
|
805
|
+
},
|
|
806
|
+
};
|
|
807
|
+
const chip = () => {
|
|
808
|
+
const node = dom.made.find((c) => c.dataset.hub === 'stuck');
|
|
809
|
+
if (!node || node.style.display !== 'block') {
|
|
810
|
+
return null;
|
|
811
|
+
}
|
|
812
|
+
const down = Number(/translate\(-50%, (-?[\d.]+)px\)/.exec(node.style.transform)?.[1] ?? 0);
|
|
813
|
+
const top = view.h - CHIP.up - CHIP.h + down;
|
|
814
|
+
return { left: mid - CHIP.w / 2, right: mid + CHIP.w / 2, top, bottom: top + CHIP.h };
|
|
815
|
+
};
|
|
816
|
+
const prompt = () => chrome.stuckPrompt('Stuck? Tap to go to the square', () => {});
|
|
817
|
+
return { ...dom, chrome, nodes, lay, chip, prompt };
|
|
818
|
+
}
|
|
819
|
+
const texts = (node) => [node.textContent, ...node.children.flatMap(texts)].filter(Boolean);
|
|
820
|
+
const DOORS = [{ id: 'race', title: 'Foot Race' }, { id: 'gems', title: 'Gem Rush', solo: true }];
|
|
821
|
+
|
|
822
|
+
test('the chrome of a deck without the key: no chip, no row, nothing made for either', () => {
|
|
823
|
+
const plain = rig();
|
|
824
|
+
plain.chrome.setDoors(DOORS, 'Go');
|
|
825
|
+
const made = plain.made.length;
|
|
826
|
+
const list = plain.made.find((c) => c.children.length === DOORS.length && texts(c).includes('Foot Race'));
|
|
827
|
+
assert.deepEqual(texts(list), ['Foot Race', 'Go', 'Gem Rush', 'solo', 'Go']);
|
|
828
|
+
// Hiding a chip that was never shown builds none.
|
|
829
|
+
plain.chrome.stuckPrompt(null);
|
|
830
|
+
plain.chrome.setDoors(DOORS, 'Go', null);
|
|
831
|
+
assert.equal(plain.made.length, made);
|
|
832
|
+
assert.equal(plain.made.some((c) => c.dataset.hub === 'stuck' || c.dataset.hub === 'stuck-row'), false);
|
|
833
|
+
});
|
|
834
|
+
|
|
835
|
+
test('the chip: built when first shown, its words, a tap, hidden again', () => {
|
|
836
|
+
const r = rig();
|
|
837
|
+
let taps = 0;
|
|
838
|
+
r.chrome.stuckPrompt('Stuck? Tap to go to the square', () => (taps += 1));
|
|
839
|
+
const chip = r.made.find((c) => c.dataset.hub === 'stuck');
|
|
840
|
+
assert.equal(chip.tag, 'button');
|
|
841
|
+
assert.equal(chip.textContent, 'Stuck? Tap to go to the square');
|
|
842
|
+
assert.equal(chip.style.display, 'block');
|
|
843
|
+
assert.equal(chip.style.background, 'rgba(20,16,12,0.8)', 'the dark pill of the other buttons');
|
|
844
|
+
chip.press();
|
|
845
|
+
assert.equal(taps, 1);
|
|
846
|
+
r.chrome.stuckPrompt(null);
|
|
847
|
+
assert.equal(chip.style.display, 'none');
|
|
848
|
+
r.chrome.stuckPrompt('Stuck? Tap to go back to the start', () => (taps += 10));
|
|
849
|
+
assert.equal(r.made.filter((c) => c.dataset.hub === 'stuck').length, 1, 'one chip, reused');
|
|
850
|
+
assert.equal(chip.textContent, 'Stuck? Tap to go back to the start');
|
|
851
|
+
chip.press();
|
|
852
|
+
assert.equal(taps, 11);
|
|
853
|
+
});
|
|
854
|
+
|
|
855
|
+
test('the chip is never over an open list', () => {
|
|
856
|
+
const r = rig();
|
|
857
|
+
r.chrome.setDoors(DOORS, 'Go');
|
|
858
|
+
const doorsButton = r.made.find((c) => c.tag === 'button' && c.textContent === 'Doors');
|
|
859
|
+
doorsButton.press();
|
|
860
|
+
r.chrome.stuckPrompt('Stuck? Tap to go to the square', () => {});
|
|
861
|
+
const chip = r.made.find((c) => c.dataset.hub === 'stuck');
|
|
862
|
+
assert.equal(chip.style.display, 'none');
|
|
863
|
+
doorsButton.press();
|
|
864
|
+
r.chrome.stuckPrompt('Stuck? Tap to go to the square', () => {});
|
|
865
|
+
assert.equal(chip.style.display, 'block');
|
|
866
|
+
});
|
|
867
|
+
|
|
868
|
+
test('the chrome places the chip by what it shows: portrait, where it hangs', () => {
|
|
869
|
+
const r = rig(PORTRAIT);
|
|
870
|
+
r.chrome.setHud({ title: 'Today', text: 'errands' }, null);
|
|
871
|
+
r.lay.hud(90, 246);
|
|
872
|
+
r.chrome.setAsk({ key: 'q', text: 'bo wants to go to Foot Race with the party. Come along?', yes: 'Go', no: 'Not now' });
|
|
873
|
+
r.lay.ask(62);
|
|
874
|
+
r.chrome.nearPrompt('+ Party · amy', () => {});
|
|
875
|
+
r.lay.near();
|
|
876
|
+
r.prompt();
|
|
877
|
+
assert.deepEqual(r.chip(), { left: 89, right: 323, top: 634, bottom: 668 });
|
|
878
|
+
assert.equal(r.made.find((c) => c.dataset.hub === 'stuck').style.transform, 'translateX(-50%)');
|
|
879
|
+
});
|
|
880
|
+
|
|
881
|
+
test('the chrome places the chip by what it shows: landscape 800x360', () => {
|
|
882
|
+
const r = rig(LANDSCAPE);
|
|
883
|
+
r.chrome.setHud({ title: 'Today', text: 'errands' }, null);
|
|
884
|
+
const hud = r.lay.hud(48);
|
|
885
|
+
r.prompt();
|
|
886
|
+
assert.equal(r.chip().top, 124, 'nothing in its way: where it hangs');
|
|
887
|
+
// A wrapped party question comes up: under it.
|
|
888
|
+
r.chrome.setAsk({ key: 'q', text: 'bo wants to go to Foot Race with the party. Come along?', yes: 'Go', no: 'Not now' });
|
|
889
|
+
const question = r.lay.ask(62);
|
|
890
|
+
r.prompt();
|
|
891
|
+
assert.equal(r.chip().top, 160);
|
|
892
|
+
assert.equal(clear(r.chip(), question) && clear(r.chip(), hud), true);
|
|
893
|
+
// The play-again offer (the same card, one line).
|
|
894
|
+
r.chrome.setAsk({ key: 'again:race:1', text: 'Play Foot Race again?', yes: 'Play again', no: 'Not now' });
|
|
895
|
+
const again = r.lay.ask(46);
|
|
896
|
+
r.prompt();
|
|
897
|
+
assert.equal(r.chip().top, 144);
|
|
898
|
+
assert.equal(clear(r.chip(), again), true);
|
|
899
|
+
// Standing by someone as well: the invite button is where the chip would go. Not drawn.
|
|
900
|
+
r.chrome.nearPrompt('+ Party · amy', () => {});
|
|
901
|
+
r.lay.near();
|
|
902
|
+
r.prompt();
|
|
903
|
+
assert.equal(r.chip(), null);
|
|
904
|
+
// The question answered: back where it hangs, over the invite button.
|
|
905
|
+
r.chrome.setAsk(null);
|
|
906
|
+
r.prompt();
|
|
907
|
+
assert.equal(r.chip().top, 124);
|
|
908
|
+
assert.equal(r.made.find((c) => c.dataset.hub === 'stuck').style.transform, 'translateX(-50%)');
|
|
909
|
+
// A HUD that is not shown is not in its way, whatever box it last had.
|
|
910
|
+
r.lay.hud(200);
|
|
911
|
+
r.prompt();
|
|
912
|
+
assert.equal(r.chip().top, 218, 'under a HUD that comes down to 212');
|
|
913
|
+
r.chrome.setHud(null, null);
|
|
914
|
+
r.prompt();
|
|
915
|
+
assert.equal(r.chip().top, 124);
|
|
916
|
+
});
|
|
917
|
+
|
|
918
|
+
// What a clear HUD's flush moves (`hud.clear`, v1.26): each is put at y 96 on
|
|
919
|
+
// an 800x360 view, where it clears the chip (124 to 158) -- and under a HUD
|
|
920
|
+
// that comes down to 95 the flush then moves it to 101, over the chip. The
|
|
921
|
+
// chip is placed after the flush, as the hub system does it, and yields.
|
|
922
|
+
const MOVED = {
|
|
923
|
+
"a cabinet's card": {
|
|
924
|
+
size: { w: 120, h: 28 },
|
|
925
|
+
put: (r, x, y) => r.chrome.setCabinet({ id: 'door-arcade', rev: 1, card: { title: 'Arcade', top: [{ username: 'ada', score: 310 }] }, x, y, opacity: 1 }, () => null),
|
|
926
|
+
node: (r) => r.made.find((c) => c.dataset.hub === 'cabinet'),
|
|
927
|
+
},
|
|
928
|
+
'the ribbon': {
|
|
929
|
+
size: { w: 150, h: 26 },
|
|
930
|
+
put: (r, x, y) => r.chrome.setRibbon({ x, y }, '🏅 12.3 s'),
|
|
931
|
+
node: (r) => r.made.find((c) => String(c.style.background).startsWith('linear-gradient(#f2c94c')),
|
|
932
|
+
},
|
|
933
|
+
'a pointer': {
|
|
934
|
+
size: { w: 60, h: 20 },
|
|
935
|
+
put: (r, x, y) => r.chrome.setPointers([{ id: 'amy', x, y, text: 'amy', angle: null }]),
|
|
936
|
+
node: (r) => r.made.find((c) => c.style.background === 'rgba(233,196,143,0.92)' && c.tag === 'div' && c.style.boxShadow === '0 1px 4px rgba(0,0,0,0.4)'),
|
|
937
|
+
},
|
|
938
|
+
'a label': {
|
|
939
|
+
size: { w: 100, h: 24 },
|
|
940
|
+
put: (r, x, y) => r.chrome.setLabels([{ id: 'plate', x, y, text: 'Start here' }]),
|
|
941
|
+
node: (r) => r.made.find((c) => c.textContent === 'Start here'),
|
|
942
|
+
},
|
|
943
|
+
};
|
|
944
|
+
// One frame as the hub system draws it: the HUD, the thing, the flush, then the chip.
|
|
945
|
+
function frameWith(what, { clearHud, x = 400, y = 96 }) {
|
|
946
|
+
const r = rig(LANDSCAPE);
|
|
947
|
+
r.lay.hud(83);
|
|
948
|
+
const frame = () => {
|
|
949
|
+
r.chrome.setHudClear(clearHud);
|
|
950
|
+
r.chrome.setHud({ title: 'Lantern Run', big: '12.3', text: 'find the lantern' }, null);
|
|
951
|
+
what.put(r, x, y);
|
|
952
|
+
const node = what.node(r);
|
|
953
|
+
node.size = what.size;
|
|
954
|
+
if (clearHud) {
|
|
955
|
+
r.chrome.flushHudClear();
|
|
956
|
+
}
|
|
957
|
+
r.prompt();
|
|
958
|
+
return node.getBoundingClientRect();
|
|
959
|
+
};
|
|
960
|
+
// Twice: the first frame builds the node before the test can size it.
|
|
961
|
+
frame();
|
|
962
|
+
return { r, box: frame() };
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
// A card or the ribbon is something a player taps or reads: the chip yields.
|
|
966
|
+
// A label, speech or a pointer is hung on the world: it passes under the chip
|
|
967
|
+
// as under every other button, so one drifting across never takes it down.
|
|
968
|
+
const YIELDS_TO = ["a cabinet's card", 'the ribbon'];
|
|
969
|
+
// Whether the chip is drawn over `node`: later among the root's children.
|
|
970
|
+
function chipOver(r, node) {
|
|
971
|
+
const root = r.made.find((c) => c.dataset.hub === 'stuck').parent;
|
|
972
|
+
const layer = (n) => (n.parent === root ? n : layer(n.parent));
|
|
973
|
+
return root.children.indexOf(r.made.find((c) => c.dataset.hub === 'stuck')) > root.children.indexOf(layer(node));
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
for (const [name, what] of Object.entries(MOVED)) {
|
|
977
|
+
const yields = YIELDS_TO.includes(name);
|
|
978
|
+
test(`a clear HUD moves ${name} under itself and over where the chip hangs: ${yields ? 'the chip yields' : 'it passes under the chip'}`, () => {
|
|
979
|
+
const { r, box } = frameWith(what, { clearHud: true });
|
|
980
|
+
assert.equal(box.top, 101, 'the flush moved it from 96 to just under the HUD (95 + 6)');
|
|
981
|
+
assert.equal(box.bottom, 101 + what.size.h);
|
|
982
|
+
assert.equal(box.bottom + 6 > 124, true, "which is over the chip's spot");
|
|
983
|
+
if (yields) {
|
|
984
|
+
assert.equal(r.chip(), null, 'measured after the flush: not drawn');
|
|
985
|
+
} else {
|
|
986
|
+
assert.equal(r.chip().top, 124, 'the chip stays where it hangs');
|
|
987
|
+
assert.equal(chipOver(r, what.node(r)), true, 'and is drawn over it');
|
|
988
|
+
}
|
|
989
|
+
// Beside the chip, it is not in its way, moved or not.
|
|
990
|
+
const beside = frameWith(what, { clearHud: true, x: 205 });
|
|
991
|
+
assert.equal(beside.box.top, 101);
|
|
992
|
+
assert.equal(beside.r.chip().top, 124);
|
|
993
|
+
});
|
|
994
|
+
test(`without a clear HUD ${name} stays where it was put, and the chip where it hangs`, () => {
|
|
995
|
+
const { r, box } = frameWith(what, { clearHud: false });
|
|
996
|
+
assert.equal(box.bottom, 96);
|
|
997
|
+
assert.equal(r.chip().top, 124);
|
|
998
|
+
// Put right over the chip's spot.
|
|
999
|
+
const over = frameWith(what, { clearHud: false, y: 150 });
|
|
1000
|
+
if (yields) {
|
|
1001
|
+
assert.equal(over.r.chip(), null, 'the chip yields there too');
|
|
1002
|
+
} else {
|
|
1003
|
+
assert.equal(over.r.chip().top, 124, 'it does not hide the chip');
|
|
1004
|
+
assert.equal(chipOver(over.r, what.node(over.r)), true);
|
|
1005
|
+
// Drifting across, frame after frame: the chip never goes.
|
|
1006
|
+
for (let x = 200; x <= 600; x += 20) {
|
|
1007
|
+
what.put(over.r, x, 150);
|
|
1008
|
+
over.r.prompt();
|
|
1009
|
+
assert.equal(over.r.chip().top, 124);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
});
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
test('the hub system places the chip last: after every setter and after the flush', () => {
|
|
1016
|
+
const src = fs.readFileSync(new URL('../code/systems/hub.js', import.meta.url), 'utf8');
|
|
1017
|
+
const from = src.indexOf('\n drawChrome(scene, local, now) {');
|
|
1018
|
+
const body = src.slice(from, src.indexOf('\n }\n', from));
|
|
1019
|
+
const offer = body.indexOf('this.offerUnstick(');
|
|
1020
|
+
assert.ok(offer > body.lastIndexOf('chrome.flushHudClear'), 'after the flush');
|
|
1021
|
+
assert.equal(/chrome\.\w+\??\.?\(/.test(body.slice(offer)), false, 'and no chrome call after it');
|
|
1022
|
+
// Without the key the frame ends as it did: the flush is its last call.
|
|
1023
|
+
assert.match(body, /\n {4}if \(this\.hudClear\) \{\n {6}chrome\.flushHudClear\?\.\(\);\n {4}\}\n(?: {4}\/\/.*\n)* {4}if \(Hub\.deck\.stuck\) \{\n {6}this\.offerUnstick\(scene, local, town, now\);\n {4}\}(?:\n(?: {4}\/\/.*\n)* {4}if \(padCuesEnabled\(scene\.data\?\.engine\) \|\| this\.padReadability\) \{\n {6}this\.drawPadReadability\(scene, local\);\n {4}\})?$/);
|
|
1024
|
+
});
|
|
1025
|
+
|
|
1026
|
+
test('no room for the chip: the Doors row is still there', () => {
|
|
1027
|
+
const r = rig({ w: 800, h: 180 });
|
|
1028
|
+
r.chrome.setHud({ title: 'Today', text: 'errands' }, null);
|
|
1029
|
+
r.lay.hud(48);
|
|
1030
|
+
r.chrome.setAsk({ key: 'again:race:1', text: 'Play Foot Race again?', yes: 'Play again', no: 'Not now' });
|
|
1031
|
+
r.lay.ask(46);
|
|
1032
|
+
r.chrome.setDoors(DOORS, 'Go', { where: 'Back to the square', onPick() {} });
|
|
1033
|
+
r.prompt();
|
|
1034
|
+
assert.equal(r.chip(), null);
|
|
1035
|
+
assert.equal(r.made.find((c) => c.dataset.hub === 'stuck').style.display, 'none');
|
|
1036
|
+
assert.equal(r.made.some((c) => c.dataset.hub === 'stuck-row'), true);
|
|
1037
|
+
});
|
|
1038
|
+
|
|
1039
|
+
test('the Doors list: a "Stuck?" row over the doors, and its press', () => {
|
|
1040
|
+
const r = rig();
|
|
1041
|
+
let picks = 0;
|
|
1042
|
+
r.chrome.setDoors(DOORS, 'Go', { where: 'Back to the square', onPick: () => (picks += 1) });
|
|
1043
|
+
const row = r.made.find((c) => c.dataset.hub === 'stuck-row');
|
|
1044
|
+
const list = row.parent;
|
|
1045
|
+
const scrollList = list.parent;
|
|
1046
|
+
assert.equal(list.children[0], row, 'first in the list');
|
|
1047
|
+
assert.deepEqual(texts(list), ['Stuck?', 'Back to the square', 'Go', 'Foot Race', 'Go', 'Gem Rush', 'solo', 'Go']);
|
|
1048
|
+
row.children.find((c) => c.tag === 'button').press();
|
|
1049
|
+
assert.equal(picks, 1);
|
|
1050
|
+
assert.equal(scrollList.style.display, 'none', 'the list closes, as for a door');
|
|
1051
|
+
// The same list again is not rebuilt; without the row it is, as it always was.
|
|
1052
|
+
const made = r.made.length;
|
|
1053
|
+
r.chrome.setDoors(DOORS, 'Go', { where: 'Back to the square', onPick: () => (picks += 1) });
|
|
1054
|
+
assert.equal(r.made.length, made);
|
|
1055
|
+
r.chrome.setDoors(DOORS, 'Go');
|
|
1056
|
+
assert.deepEqual(texts(list), ['Foot Race', 'Go', 'Gem Rush', 'solo', 'Go']);
|
|
1057
|
+
});
|
|
1058
|
+
|
|
1059
|
+
// --- the hub system ---------------------------------------------------------
|
|
1060
|
+
|
|
1061
|
+
const sdkStub = 'export const Hub = undefined;';
|
|
1062
|
+
const packStub = 'export const loadPack = () => Promise.reject(new Error("no")); export const cachedPacks = () => []; export const matchesOwn = () => false; export const resolveDeckDoor = () => Promise.reject(new Error("no"));';
|
|
1063
|
+
const mediaStub = 'export const initialMedia = {}; export const playMedia = () => {}; export const stopMedia = () => {};';
|
|
1064
|
+
const sceneStub = 'export const readScene = () => globalThis.__hubTestActors ?? [];';
|
|
1065
|
+
// stuck.js as the hub system sees it: the real one, with `makeStuck` counted.
|
|
1066
|
+
const stuckSpy = `
|
|
1067
|
+
export * from ${JSON.stringify(new URL('../code/client/stuck.js', import.meta.url).href)};
|
|
1068
|
+
import { makeStuck as real } from ${JSON.stringify(new URL('../code/client/stuck.js', import.meta.url).href)};
|
|
1069
|
+
export function makeStuck() {
|
|
1070
|
+
globalThis.__stuckMade = (globalThis.__stuckMade ?? 0) + 1;
|
|
1071
|
+
return real();
|
|
1072
|
+
}`;
|
|
1073
|
+
const url = (src) => 'data:text/javascript,' + encodeURIComponent(src);
|
|
1074
|
+
register(
|
|
1075
|
+
url(`
|
|
1076
|
+
export async function resolve(specifier, context, next) {
|
|
1077
|
+
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 };
|
|
1078
|
+
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 };
|
|
1079
|
+
if (specifier === 'castle-web-sdk') return { url: ${JSON.stringify(url(sdkStub))}, shortCircuit: true };
|
|
1080
|
+
if (specifier.startsWith('@imports/castle.physics-2d/engine/')) return { url: ${JSON.stringify(url(mediaStub))}, shortCircuit: true };
|
|
1081
|
+
if (specifier === '@imports/castle.multiplayer-3d/code/server/sceneBodies.js') return { url: ${JSON.stringify(url(sceneStub))}, shortCircuit: true };
|
|
1082
|
+
if (specifier === '../client/pack.js') return { url: ${JSON.stringify(url(packStub))}, shortCircuit: true };
|
|
1083
|
+
if (specifier === '../client/stuck.js' && context.parentURL?.endsWith('/code/systems/hub.js')) return { url: ${JSON.stringify(url(stuckSpy))}, shortCircuit: true };
|
|
1084
|
+
return next(specifier, context);
|
|
1085
|
+
}`),
|
|
1086
|
+
);
|
|
1087
|
+
const { installSystem } = await import('../code/systems/hub.js');
|
|
1088
|
+
const State = await import('../code/client/state.js');
|
|
1089
|
+
|
|
1090
|
+
{
|
|
1091
|
+
let system;
|
|
1092
|
+
installSystem({ registerSystem: (s) => (system = s) });
|
|
1093
|
+
const prompts = [];
|
|
1094
|
+
system.chrome = { stuckPrompt: (text, handler) => prompts.push([text, handler]) };
|
|
1095
|
+
system.sceneKey = 'scenes/main.scene';
|
|
1096
|
+
const sent = [];
|
|
1097
|
+
const scene = {
|
|
1098
|
+
keys: new Set(['KeyW']),
|
|
1099
|
+
moveInput: null,
|
|
1100
|
+
cameraControl: 'orbit',
|
|
1101
|
+
multiplayer: { net: { selfId: () => 'me', send: (msg) => sent.push(msg) } },
|
|
1102
|
+
};
|
|
1103
|
+
system.scene = scene;
|
|
1104
|
+
const local = { components: { Transform: { x: 4, y: 1, z: -2 } } };
|
|
1105
|
+
const realNow = performance.now.bind(performance);
|
|
1106
|
+
let clock = 100000;
|
|
1107
|
+
performance.now = () => clock;
|
|
1108
|
+
const frames = (ms, town = true) => {
|
|
1109
|
+
for (const end = clock + ms; clock < end; clock += FRAME) {
|
|
1110
|
+
system.offerUnstick(scene, local, town, clock);
|
|
1111
|
+
}
|
|
1112
|
+
};
|
|
1113
|
+
|
|
1114
|
+
test('hub.stuck absent: nothing made, drawn or sent', () => {
|
|
1115
|
+
assert.equal(State.deck.stuck, false, 'off unless castle.json says so');
|
|
1116
|
+
assert.equal(State.hub.stuck, null);
|
|
1117
|
+
// A tap that could not have happened still sends nothing.
|
|
1118
|
+
State.hub.place = { id: 'main', result: null };
|
|
1119
|
+
system.unstick(scene);
|
|
1120
|
+
assert.deepEqual(sent, []);
|
|
1121
|
+
assert.equal(system.stuck, undefined);
|
|
1122
|
+
assert.equal(globalThis.__stuckMade, undefined);
|
|
1123
|
+
assert.deepEqual(prompts, []);
|
|
1124
|
+
});
|
|
1125
|
+
|
|
1126
|
+
test('hub.js reaches it only behind the opt-in', () => {
|
|
1127
|
+
const src = fs.readFileSync(new URL('../code/systems/hub.js', import.meta.url), 'utf8');
|
|
1128
|
+
assert.equal(src.match(/makeStuck\(/g)?.length, 1);
|
|
1129
|
+
assert.equal(src.match(/this\.offerUnstick\(/g)?.length, 1);
|
|
1130
|
+
assert.match(src, /\n {4}if \(Hub\.deck\.stuck\) \{\n {6}this\.offerUnstick\(scene, local, town, now\);\n {4}\}/);
|
|
1131
|
+
assert.match(src, /const stuckRow = Hub\.deck\.stuck && town && Hub\.hub\.stuck \? /);
|
|
1132
|
+
assert.match(src, /\n {2}unstick\(scene\) \{[^}]*?if \(!Hub\.deck\.stuck \|\| /);
|
|
1133
|
+
assert.equal(src.match(/hub-unstick/g)?.length, 3, 'the tap, the ask (v1.39), one comment');
|
|
1134
|
+
assert.match(src, /\n {4}if \(offer\.hook\) \{\n[^}]*hub-unstick', ask: true/, 'the ask only in a place with the hook');
|
|
1135
|
+
// Outside its two methods and the Doors row, the system never names it.
|
|
1136
|
+
const from = src.indexOf(' offerUnstick(scene, local, town, now) {');
|
|
1137
|
+
const to = src.indexOf('\n }\n', src.indexOf(' unstick(scene) {'));
|
|
1138
|
+
const rest = src.slice(0, from) + src.slice(to);
|
|
1139
|
+
assert.equal(rest.match(/this\.stuck\b|this\.stuckShown\b|this\.unstuckAt\b|stuckFrame|walkInput|stuckText|stuckDone|stuckTo\b|\.unstuck\b/g)?.length, 4, 'only the import line');
|
|
1140
|
+
// The hook layer reads the place's word only in a deck that asks.
|
|
1141
|
+
const hooks = fs.readFileSync(new URL('../code/client/hookLayer.js', import.meta.url), 'utf8');
|
|
1142
|
+
assert.equal(hooks.match(/hubStuck/g)?.length, 4);
|
|
1143
|
+
assert.match(hooks, /if \(deck\.stuck && msg\.stuck && typeof msg\.stuck === 'object'\)/);
|
|
1144
|
+
assert.match(hooks, /case 'hub-unstick-to':\n[^\n]*\n {8}if \(deck\.stuck\) \{/);
|
|
1145
|
+
assert.match(hooks, /if \(deck\.stuck && msg\.hubPlace\) \{\n[^}]*hubStuck/);
|
|
1146
|
+
});
|
|
1147
|
+
|
|
1148
|
+
test('hub.stuck true, in a town that takes it: offered after 3 s into a wall', () => {
|
|
1149
|
+
State.deck.stuck = true;
|
|
1150
|
+
State.hub.stuck = { to: 'the square' };
|
|
1151
|
+
frames(STUCK_AFTER_MS - 2 * FRAME);
|
|
1152
|
+
assert.equal(globalThis.__stuckMade, 1);
|
|
1153
|
+
assert.equal(prompts.some(([text]) => text), false, 'not yet');
|
|
1154
|
+
frames(4 * FRAME);
|
|
1155
|
+
assert.equal(prompts.at(-1)[0], 'Stuck? Tap to go to the square');
|
|
1156
|
+
});
|
|
1157
|
+
|
|
1158
|
+
test('a tap asks the place once, and not again for 5 s', () => {
|
|
1159
|
+
prompts.at(-1)[1]();
|
|
1160
|
+
assert.deepEqual(sent, [{ k: 'hub-unstick' }]);
|
|
1161
|
+
assert.equal(system.toast.text, 'Back to the square');
|
|
1162
|
+
frames(FRAME);
|
|
1163
|
+
assert.equal(prompts.at(-1)[0], null, 'the chip goes with the tap');
|
|
1164
|
+
clock += STUCK_EVERY_MS - 1000;
|
|
1165
|
+
system.unstick(scene);
|
|
1166
|
+
assert.equal(sent.length, 1);
|
|
1167
|
+
clock += 1000;
|
|
1168
|
+
system.unstick(scene);
|
|
1169
|
+
assert.equal(sent.length, 2);
|
|
1170
|
+
});
|
|
1171
|
+
|
|
1172
|
+
test('not offered where the place does not take it, in a game, or to a held player', () => {
|
|
1173
|
+
clock += 60000;
|
|
1174
|
+
prompts.length = 0;
|
|
1175
|
+
// A game behind a door of this deck: the server sent no `hubStuck`.
|
|
1176
|
+
State.hub.stuck = null;
|
|
1177
|
+
frames(STUCK_AFTER_MS + 1000);
|
|
1178
|
+
assert.equal(prompts.some(([text]) => text), false);
|
|
1179
|
+
system.unstick(scene);
|
|
1180
|
+
assert.equal(sent.length, 2);
|
|
1181
|
+
// Not a town this frame (a trip, an NPC's panel, an ending).
|
|
1182
|
+
State.hub.stuck = { to: null };
|
|
1183
|
+
frames(STUCK_AFTER_MS + 1000, false);
|
|
1184
|
+
assert.equal(prompts.some(([text]) => text), false);
|
|
1185
|
+
// Held by the place.
|
|
1186
|
+
State.hub.held.add('me');
|
|
1187
|
+
frames(STUCK_AFTER_MS + 1000);
|
|
1188
|
+
assert.equal(prompts.some(([text]) => text), false);
|
|
1189
|
+
State.hub.held.clear();
|
|
1190
|
+
// A hidden page: frames drawn there count for nothing.
|
|
1191
|
+
globalThis.document.visibilityState = 'hidden';
|
|
1192
|
+
frames(STUCK_AFTER_MS + 1000);
|
|
1193
|
+
assert.equal(prompts.some(([text]) => text), false);
|
|
1194
|
+
globalThis.document.visibilityState = 'visible';
|
|
1195
|
+
frames(STUCK_AFTER_MS - 2 * FRAME);
|
|
1196
|
+
assert.equal(prompts.some(([text]) => text), false, 'and the count starts when it is seen again');
|
|
1197
|
+
frames(1000);
|
|
1198
|
+
assert.equal(prompts.at(-1)[0], 'Stuck? Tap to go back to the start', 'a place with no name for its arrival');
|
|
1199
|
+
});
|
|
1200
|
+
|
|
1201
|
+
test('a place with no `unstick` hook is never asked what a tap would do', () => {
|
|
1202
|
+
assert.equal(sent.some((msg) => msg.ask), false);
|
|
1203
|
+
});
|
|
1204
|
+
|
|
1205
|
+
test('v1.39, a place that picks the spot: asked as the chip comes up, and its word is the chip\'s', () => {
|
|
1206
|
+
clock += 60000;
|
|
1207
|
+
prompts.length = 0;
|
|
1208
|
+
sent.length = 0;
|
|
1209
|
+
State.hub.stuck = { to: 'the square', hook: true };
|
|
1210
|
+
frames(STUCK_AFTER_MS + 200);
|
|
1211
|
+
assert.deepEqual(sent, [{ k: 'hub-unstick', ask: true }], 'asked once, as it came up');
|
|
1212
|
+
assert.equal(prompts.at(-1)[0], 'Stuck? Tap to get unstuck', 'until the place answers, words that name nowhere');
|
|
1213
|
+
// It names the spot.
|
|
1214
|
+
State.hub.stuckTo = { spot: true, to: 'the street' };
|
|
1215
|
+
frames(FRAME);
|
|
1216
|
+
assert.equal(prompts.at(-1)[0], 'Stuck? Tap to go to the street');
|
|
1217
|
+
// A spot with no name.
|
|
1218
|
+
State.hub.stuckTo = { spot: true, to: null };
|
|
1219
|
+
frames(FRAME);
|
|
1220
|
+
assert.equal(prompts.at(-1)[0], 'Stuck? Tap to get unstuck');
|
|
1221
|
+
// The hook had nothing for this player: the arrival, in the arrival's words.
|
|
1222
|
+
State.hub.stuckTo = { spot: false, to: 'the square' };
|
|
1223
|
+
frames(FRAME);
|
|
1224
|
+
assert.equal(prompts.at(-1)[0], 'Stuck? Tap to go to the square');
|
|
1225
|
+
State.hub.stuckTo = { spot: false, to: null };
|
|
1226
|
+
frames(FRAME);
|
|
1227
|
+
assert.equal(prompts.at(-1)[0], 'Stuck? Tap to go back to the start');
|
|
1228
|
+
// Still up, it is not asked again; gone and back, it is, and the old answer is not kept.
|
|
1229
|
+
frames(2000);
|
|
1230
|
+
assert.equal(sent.length, 1);
|
|
1231
|
+
scene.keys.clear();
|
|
1232
|
+
frames(4000);
|
|
1233
|
+
assert.equal(prompts.at(-1)[0], null);
|
|
1234
|
+
scene.keys.add('KeyW');
|
|
1235
|
+
frames(200);
|
|
1236
|
+
assert.equal(sent.length, 2);
|
|
1237
|
+
assert.equal(prompts.at(-1)[0], 'Stuck? Tap to get unstuck');
|
|
1238
|
+
});
|
|
1239
|
+
|
|
1240
|
+
test('v1.39, a place that picks the spot: the tap is the same message, and the place says where it put them', () => {
|
|
1241
|
+
system.toast = { text: '', until: 0 };
|
|
1242
|
+
prompts.at(-1)[1]();
|
|
1243
|
+
assert.deepEqual(sent.at(-1), { k: 'hub-unstick' });
|
|
1244
|
+
assert.equal(system.toast.text, '', 'nothing is said before the place has');
|
|
1245
|
+
State.hub.unstuck = { spot: true, to: 'the street' };
|
|
1246
|
+
frames(FRAME);
|
|
1247
|
+
assert.equal(system.toast.text, 'Back to the street');
|
|
1248
|
+
assert.equal(State.hub.unstuck, null, 'said once');
|
|
1249
|
+
State.hub.unstuck = { spot: true, to: null };
|
|
1250
|
+
frames(FRAME);
|
|
1251
|
+
assert.equal(system.toast.text, "You're unstuck");
|
|
1252
|
+
State.hub.unstuck = { spot: false, to: 'the square' };
|
|
1253
|
+
frames(FRAME);
|
|
1254
|
+
assert.equal(system.toast.text, 'Back to the square');
|
|
1255
|
+
});
|
|
1256
|
+
|
|
1257
|
+
performance.now = realNow;
|
|
1258
|
+
State.deck.stuck = false;
|
|
1259
|
+
State.hub.stuckTo = { spot: true, to: 'x' };
|
|
1260
|
+
State.hub.unstuck = { spot: true, to: 'x' };
|
|
1261
|
+
State.clear();
|
|
1262
|
+
assert.equal(State.hub.stuck, null, 'forgotten on a session switch');
|
|
1263
|
+
assert.equal(State.hub.stuckTo, null);
|
|
1264
|
+
assert.equal(State.hub.unstuck, null);
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
// --- the place server -------------------------------------------------------
|
|
1268
|
+
|
|
1269
|
+
const { layer } = await import('../code/server/hub.js');
|
|
1270
|
+
const { readManifest } = await import('../code/server/manifest.js');
|
|
1271
|
+
|
|
1272
|
+
globalThis.__hubTestActors = [
|
|
1273
|
+
{ id: 'spawn', components: { Player: {}, Transform: { x: 0, y: 1, z: 0 } } },
|
|
1274
|
+
{ id: 'gate', components: { Transform: { x: 6, y: 1, z: -9, rotationY: 90 } } },
|
|
1275
|
+
{ id: 'door-race', components: { HubDoor: { id: 'race', to: 'race' }, Transform: { x: -28, y: 1.4, z: 0, rotationY: 90 } } },
|
|
1276
|
+
];
|
|
1277
|
+
const deckJson = (hub = {}) => ({
|
|
1278
|
+
server: { maxPlayers: 8 },
|
|
1279
|
+
hub: {
|
|
1280
|
+
contract: 1,
|
|
1281
|
+
title: 'Town',
|
|
1282
|
+
arrival: { actor: 'gate', spread: 1.5, face: 'actor' },
|
|
1283
|
+
places: {
|
|
1284
|
+
race: {
|
|
1285
|
+
title: 'Foot Race',
|
|
1286
|
+
scene: 'scenes/race.scene',
|
|
1287
|
+
result: { outcomes: ['win', 'lose'], score: { unit: 'ms', better: 'lower', min: 0, max: 600000 } },
|
|
1288
|
+
},
|
|
1289
|
+
},
|
|
1290
|
+
...hub,
|
|
1291
|
+
},
|
|
1292
|
+
});
|
|
1293
|
+
const sceneExists = (scene) => ['scenes/main.scene', 'scenes/race.scene'].includes(scene);
|
|
1294
|
+
const PLAYERS = [{ playerId: 'p1', userId: '101', username: 'ada' }, { playerId: 'p2', userId: '102', username: 'bo' }];
|
|
1295
|
+
const FAR = { x: 40, y: 1, z: 40 };
|
|
1296
|
+
const realDateNow = Date.now;
|
|
1297
|
+
let skew = 0;
|
|
1298
|
+
Date.now = () => realDateNow() + skew;
|
|
1299
|
+
|
|
1300
|
+
function boot({ hub = {}, sessionId = 'dev:test', hooks = {} } = {}) {
|
|
1301
|
+
let ctx = null;
|
|
1302
|
+
const heard = [];
|
|
1303
|
+
const h = layer(deckJson(hub), { ...hooks, ready: (c) => (ctx = c), message: (c, player, data) => heard.push(data) }, {}, sceneExists);
|
|
1304
|
+
const sent = [];
|
|
1305
|
+
const session = { sessionId, players: PLAYERS, send: (playerId, msg) => sent.push([playerId, msg]), broadcast() {} };
|
|
1306
|
+
h.sceneFor(session);
|
|
1307
|
+
const players = new Map();
|
|
1308
|
+
for (const { playerId } of PLAYERS) {
|
|
1309
|
+
players.set(playerId, { at: { ...FAR }, facing: 0, body: { setTranslation() {} } });
|
|
1310
|
+
}
|
|
1311
|
+
const world = { timeMs: 0, players, bodies: new Map(), scenePath: 'scenes/main.scene' };
|
|
1312
|
+
h.ready(world);
|
|
1313
|
+
for (const { playerId } of PLAYERS) {
|
|
1314
|
+
h.message(session, { playerId }, { k: 'hub-hello', avatar: 0 });
|
|
1315
|
+
}
|
|
1316
|
+
// Everyone arrives once the group wait has passed; then they walk off.
|
|
1317
|
+
skew += 5000;
|
|
1318
|
+
h.place(world, []);
|
|
1319
|
+
// (and the moment an arrival is kept where it was put, v1.40, is over)
|
|
1320
|
+
skew += 700;
|
|
1321
|
+
h.place(world, []);
|
|
1322
|
+
for (const body of players.values()) {
|
|
1323
|
+
body.at = { ...FAR };
|
|
1324
|
+
body.clamped = false;
|
|
1325
|
+
}
|
|
1326
|
+
sent.length = 0;
|
|
1327
|
+
const b = { h, session, world, sent, heard, ctx: () => ctx };
|
|
1328
|
+
b.unstick = (playerId) => h.message(session, { playerId }, { k: 'hub-unstick' });
|
|
1329
|
+
b.at = (playerId) => world.players.get(playerId).at;
|
|
1330
|
+
return b;
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
test('the manifest: the deck\'s, true or false, and carried only when true', () => {
|
|
1334
|
+
assert.deepEqual(readManifest(deckJson({ stuck: true }), sceneExists).errors, []);
|
|
1335
|
+
assert.deepEqual(readManifest(deckJson({ stuck: false }), sceneExists).errors, []);
|
|
1336
|
+
assert.match(readManifest(deckJson({ stuck: 'yes' }), sceneExists).errors.join(), /hub\.stuck must be true or false/);
|
|
1337
|
+
const inPlace = deckJson();
|
|
1338
|
+
inPlace.hub.places.race.stuck = true;
|
|
1339
|
+
assert.match(readManifest(inPlace, sceneExists).errors.join('\n'), /hub\.places\.race\.stuck is not part/);
|
|
1340
|
+
assert.equal(readManifest(deckJson({ stuck: true }), sceneExists).manifest.stuck, true);
|
|
1341
|
+
const without = readManifest(deckJson(), sceneExists).manifest;
|
|
1342
|
+
assert.deepEqual(readManifest(deckJson({ stuck: false }), sceneExists).manifest, without);
|
|
1343
|
+
assert.deepEqual(Object.keys(without), ['contract', 'cues', 'places'], 'the manifest of a deck without it is the one it was');
|
|
1344
|
+
});
|
|
1345
|
+
|
|
1346
|
+
test('a deck without the key: no `hubStuck`, the same Doors list, and the message is not the kit\'s', () => {
|
|
1347
|
+
for (const hub of [{}, { stuck: false }]) {
|
|
1348
|
+
const b = boot({ hub });
|
|
1349
|
+
const withKey = boot({ hub: { stuck: true } });
|
|
1350
|
+
const join = b.h.join();
|
|
1351
|
+
assert.equal('hubStuck' in join, false);
|
|
1352
|
+
const { hubStuck, ...rest } = withKey.h.join();
|
|
1353
|
+
assert.deepEqual(hubStuck, { to: null });
|
|
1354
|
+
assert.deepEqual(join, rest, 'the snapshot is otherwise the same');
|
|
1355
|
+
assert.deepEqual(join.hubDoors, [{ id: 'race', title: 'Foot Race' }]);
|
|
1356
|
+
b.unstick('p1');
|
|
1357
|
+
assert.deepEqual(b.at('p1'), FAR, 'nobody is moved');
|
|
1358
|
+
assert.deepEqual(b.sent, []);
|
|
1359
|
+
assert.deepEqual(b.heard, [{ k: 'hub-unstick' }], "it goes to the place's own hook, as any message the kit does not know");
|
|
1360
|
+
assert.equal(b.h.join().hubStuck, undefined);
|
|
1361
|
+
}
|
|
1362
|
+
});
|
|
1363
|
+
|
|
1364
|
+
test('with the key, in a town: put at the arrival, facing as an arrival does, and told', () => {
|
|
1365
|
+
const b = boot({ hub: { stuck: true } });
|
|
1366
|
+
b.unstick('p1');
|
|
1367
|
+
assert.deepEqual(b.at('p1'), { x: 6, y: 0.76, z: -9 }, 'the arrival actor, as the fall rule places one player');
|
|
1368
|
+
const body = b.world.players.get('p1');
|
|
1369
|
+
assert.ok(Math.abs(body.facing - Math.PI / 2) < 1e-9, 'the arrival actor\'s facing');
|
|
1370
|
+
assert.equal(body.clamped, true, 'reaches the client as a clamp');
|
|
1371
|
+
assert.deepEqual(b.sent, [['p1', { k: 'hub-jumped', facing: body.facing }]]);
|
|
1372
|
+
assert.deepEqual(b.heard, [], "never the place's own message");
|
|
1373
|
+
assert.deepEqual(b.at('p2'), FAR, 'only the player who asked');
|
|
1374
|
+
// The same spot the fall rule uses: a deck with `fallY`, a player below it.
|
|
1375
|
+
const fall = boot({ hub: { stuck: true, fallY: -5 } });
|
|
1376
|
+
fall.world.players.get('p2').at = { x: 40, y: -9, z: 40 };
|
|
1377
|
+
fall.world.timeMs += 50;
|
|
1378
|
+
fall.h.place(fall.world, []);
|
|
1379
|
+
assert.deepEqual(fall.at('p2'), b.at('p1'));
|
|
1380
|
+
});
|
|
1381
|
+
|
|
1382
|
+
test('refused when asked again within 5 s, taken after', () => {
|
|
1383
|
+
const b = boot({ hub: { stuck: true } });
|
|
1384
|
+
b.unstick('p1');
|
|
1385
|
+
b.world.players.get('p1').at = { ...FAR };
|
|
1386
|
+
skew += 4900;
|
|
1387
|
+
b.unstick('p1');
|
|
1388
|
+
assert.deepEqual(b.at('p1'), FAR);
|
|
1389
|
+
assert.equal(b.sent.length, 1);
|
|
1390
|
+
// Another player's own count.
|
|
1391
|
+
b.unstick('p2');
|
|
1392
|
+
assert.deepEqual(b.at('p2'), { x: 6, y: 0.76, z: -9 });
|
|
1393
|
+
skew += 200;
|
|
1394
|
+
b.unstick('p1');
|
|
1395
|
+
assert.deepEqual(b.at('p1'), { x: 6, y: 0.76, z: -9 });
|
|
1396
|
+
assert.equal(b.sent.length, 3);
|
|
1397
|
+
// It counts as a jump: no door jump within a second of it, and none of it
|
|
1398
|
+
// within a second of a door jump.
|
|
1399
|
+
b.world.players.get('p1').at = { ...FAR };
|
|
1400
|
+
b.h.message(b.session, { playerId: 'p1' }, { k: 'hub-door-jump', door: 'race' });
|
|
1401
|
+
assert.deepEqual(b.at('p1'), FAR);
|
|
1402
|
+
skew += 6000;
|
|
1403
|
+
b.h.message(b.session, { playerId: 'p1' }, { k: 'hub-door-jump', door: 'race' });
|
|
1404
|
+
const atDoor = { ...b.at('p1') };
|
|
1405
|
+
assert.notDeepEqual(atDoor, FAR);
|
|
1406
|
+
b.unstick('p1');
|
|
1407
|
+
assert.deepEqual(b.at('p1'), atDoor);
|
|
1408
|
+
});
|
|
1409
|
+
|
|
1410
|
+
test('refused in a game place, whatever the deck says', () => {
|
|
1411
|
+
const b = boot({ hub: { stuck: true }, sessionId: 'dev:hub.race.abc123' });
|
|
1412
|
+
assert.equal('hubStuck' in b.h.join(), false, 'the client is never told it may ask');
|
|
1413
|
+
b.unstick('p1');
|
|
1414
|
+
assert.deepEqual(b.at('p1'), FAR);
|
|
1415
|
+
assert.deepEqual(b.sent, []);
|
|
1416
|
+
// The main place itself a game.
|
|
1417
|
+
const game = boot({ hub: { stuck: true, result: { outcomes: ['win', 'lose'] } } });
|
|
1418
|
+
assert.equal('hubStuck' in game.h.join(), false);
|
|
1419
|
+
game.unstick('p1');
|
|
1420
|
+
assert.deepEqual(game.at('p1'), FAR);
|
|
1421
|
+
});
|
|
1422
|
+
|
|
1423
|
+
test('refused for a held player, one who has not arrived, one who has ended, one not here', () => {
|
|
1424
|
+
const b = boot({ hub: { stuck: true } });
|
|
1425
|
+
b.ctx().hold('p1', { x: 3, y: 1, z: 3 });
|
|
1426
|
+
b.unstick('p1');
|
|
1427
|
+
assert.deepEqual(b.at('p1'), { x: 3, y: 1, z: 3 });
|
|
1428
|
+
b.ctx().release('p1');
|
|
1429
|
+
// Refused, not counted: free again, the first ask is taken.
|
|
1430
|
+
b.unstick('p1');
|
|
1431
|
+
assert.deepEqual(b.at('p1'), { x: 6, y: 0.76, z: -9 });
|
|
1432
|
+
b.ctx().end(['p2']);
|
|
1433
|
+
b.sent.length = 0;
|
|
1434
|
+
b.unstick('p2');
|
|
1435
|
+
assert.deepEqual(b.at('p2'), FAR);
|
|
1436
|
+
b.h.message(b.session, { playerId: 'ghost' }, { k: 'hub-unstick' });
|
|
1437
|
+
b.h.message(b.session, undefined, { k: 'hub-unstick' });
|
|
1438
|
+
assert.deepEqual(b.sent, []);
|
|
1439
|
+
// Said hello and not yet placed.
|
|
1440
|
+
const early = layer(deckJson({ stuck: true }), {}, {}, sceneExists);
|
|
1441
|
+
const session = { sessionId: 'dev:test', players: PLAYERS, send() {}, broadcast() {} };
|
|
1442
|
+
early.sceneFor(session);
|
|
1443
|
+
const players = new Map([['p1', { at: { ...FAR }, facing: 0, body: { setTranslation() {} } }]]);
|
|
1444
|
+
early.ready({ timeMs: 0, players, bodies: new Map(), scenePath: 'scenes/main.scene' });
|
|
1445
|
+
early.message(session, { playerId: 'p1' }, { k: 'hub-hello', avatar: 0 });
|
|
1446
|
+
early.message(session, { playerId: 'p1' }, { k: 'hub-unstick' });
|
|
1447
|
+
assert.deepEqual(players.get('p1').at, FAR);
|
|
1448
|
+
});
|
|
1449
|
+
|
|
1450
|
+
test("the arrival's name is the place's own word for the spot, or none", () => {
|
|
1451
|
+
const named = (where) => boot({ hub: { stuck: true }, hooks: { where } }).h.join().hubStuck;
|
|
1452
|
+
let asked = null;
|
|
1453
|
+
assert.deepEqual(named((hub, at) => ((asked = at), 'in the square')), { to: 'the square' });
|
|
1454
|
+
assert.deepEqual(asked, { x: 6, y: 1, z: -9 }, 'asked about the arrival');
|
|
1455
|
+
assert.deepEqual(named(() => 'on Race Row'), { to: 'Race Row' });
|
|
1456
|
+
assert.deepEqual(named(() => 'at the Arcade'), { to: 'the Arcade' });
|
|
1457
|
+
assert.deepEqual(named(() => null), { to: null });
|
|
1458
|
+
assert.deepEqual(named(() => 'somewhere'), { to: null }, 'words of another shape are not guessed at');
|
|
1459
|
+
assert.deepEqual(named(() => 'in '), { to: null });
|
|
1460
|
+
assert.deepEqual(named(() => {
|
|
1461
|
+
throw new Error('no');
|
|
1462
|
+
}), { to: null });
|
|
1463
|
+
assert.deepEqual(boot({ hub: { stuck: true } }).h.join().hubStuck, { to: null }, 'a place with no `where` hook');
|
|
1464
|
+
});
|
|
1465
|
+
|
|
1466
|
+
// --- v1.39: the place's own spot (the `unstick` hook) -------------------------
|
|
1467
|
+
|
|
1468
|
+
// v1.48: fresh actor data proves flat-ground standing height, without a world query.
|
|
1469
|
+
const ARRIVAL = { x: 6, y: 0.76, z: -9 };
|
|
1470
|
+
// A place whose hook answers `answer(playerId, from)`, and what it was asked.
|
|
1471
|
+
function hooked(answer, extra = {}) {
|
|
1472
|
+
const asked = [];
|
|
1473
|
+
const b = boot({
|
|
1474
|
+
hub: { stuck: true, ...extra.hub },
|
|
1475
|
+
sessionId: extra.sessionId,
|
|
1476
|
+
hooks: {
|
|
1477
|
+
unstick: (hub, playerId, from) => {
|
|
1478
|
+
asked.push([typeof hub?.hold, playerId, from]);
|
|
1479
|
+
return answer(playerId, from);
|
|
1480
|
+
},
|
|
1481
|
+
},
|
|
1482
|
+
});
|
|
1483
|
+
b.asked = asked;
|
|
1484
|
+
b.ask = (playerId) => b.h.message(b.session, { playerId }, { k: 'hub-unstick', ask: true });
|
|
1485
|
+
return b;
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
test('the hook returns a spot: the player is put there, facing as it says, and told where', () => {
|
|
1489
|
+
const b = hooked(() => ({ x: 12, z: -3, facing: 90, to: 'the street' }));
|
|
1490
|
+
assert.deepEqual(b.h.join().hubStuck, { to: null, hook: true }, 'the snapshot says the place picks, and still names its arrival');
|
|
1491
|
+
b.unstick('p1');
|
|
1492
|
+
assert.deepEqual(b.asked, [['function', 'p1', FAR]], 'asked with the place\'s context, the player and where their body is');
|
|
1493
|
+
assert.deepEqual(b.at('p1'), { x: 12, y: 0.76, z: -3 });
|
|
1494
|
+
const body = b.world.players.get('p1');
|
|
1495
|
+
assert.ok(Math.abs(body.facing - Math.PI / 2) < 1e-9, 'degrees, as `hub.hold` takes them');
|
|
1496
|
+
assert.equal(body.clamped, true);
|
|
1497
|
+
assert.deepEqual(b.sent, [['p1', { k: 'hub-jumped', facing: body.facing, stuck: { spot: true, to: 'the street' } }]]);
|
|
1498
|
+
assert.deepEqual(b.at('p2'), FAR, 'only the player who asked');
|
|
1499
|
+
// Its own height, no facing (the body keeps its own), no name.
|
|
1500
|
+
const bare = hooked(() => ({ x: -4, y: 3.5, z: 7 }));
|
|
1501
|
+
bare.world.players.get('p1').facing = 1.25;
|
|
1502
|
+
bare.unstick('p1');
|
|
1503
|
+
assert.deepEqual(bare.at('p1'), { x: -4, y: 3.5, z: 7 });
|
|
1504
|
+
assert.equal(bare.world.players.get('p1').facing, 1.25);
|
|
1505
|
+
assert.deepEqual(bare.sent, [['p1', { k: 'hub-jumped', facing: 1.25, stuck: { spot: true, to: null } }]]);
|
|
1506
|
+
// A name is a short string: anything else is no name, and a long one is cut.
|
|
1507
|
+
for (const [to, said] of [[42, null], [' ', null], [{ a: 1 }, null], ['x'.repeat(60), 'x'.repeat(40)], [' the street ', 'the street']]) {
|
|
1508
|
+
const named = hooked(() => ({ x: 1, z: 1, to }));
|
|
1509
|
+
named.unstick('p1');
|
|
1510
|
+
assert.deepEqual(named.at('p1'), { x: 1, y: 0.76, z: 1 });
|
|
1511
|
+
assert.equal(named.sent[0][1].stuck.to, said);
|
|
1512
|
+
}
|
|
1513
|
+
});
|
|
1514
|
+
|
|
1515
|
+
test('the hook returns null, or nothing: the arrival, as without it', () => {
|
|
1516
|
+
for (const nothing of [null, undefined]) {
|
|
1517
|
+
const b = hooked(() => nothing);
|
|
1518
|
+
b.unstick('p1');
|
|
1519
|
+
assert.deepEqual(b.at('p1'), ARRIVAL);
|
|
1520
|
+
const body = b.world.players.get('p1');
|
|
1521
|
+
assert.ok(Math.abs(body.facing - Math.PI / 2) < 1e-9, 'facing as an arrival does');
|
|
1522
|
+
assert.deepEqual(b.sent, [['p1', { k: 'hub-jumped', facing: body.facing, stuck: { spot: false, to: null } }]]);
|
|
1523
|
+
assert.equal(b.asked.length, 1);
|
|
1524
|
+
}
|
|
1525
|
+
// With a `where` hook the arrival has its name.
|
|
1526
|
+
const b = boot({ hub: { stuck: true }, hooks: { unstick: () => null, where: () => 'in the square' } });
|
|
1527
|
+
b.unstick('p1');
|
|
1528
|
+
assert.deepEqual(b.sent[0][1].stuck, { spot: false, to: 'the square' });
|
|
1529
|
+
});
|
|
1530
|
+
|
|
1531
|
+
test('the hook returns garbage, or throws: the arrival', () => {
|
|
1532
|
+
const garbage = [
|
|
1533
|
+
'the street', 42, true, [], {}, { x: 1 }, { z: 1 }, { x: NaN, z: 1 }, { x: 1, z: Infinity }, { x: '1', z: 1 },
|
|
1534
|
+
{ x: 201, z: 0 }, { x: 0, z: -201 }, { x: 1, z: 1, y: -31 }, { x: 1, z: 1, y: 81 }, { x: 1, z: 1, y: 'up' },
|
|
1535
|
+
{ x: 1, z: 1, facing: 'north' }, { x: 1, z: 1, facing: NaN },
|
|
1536
|
+
];
|
|
1537
|
+
for (const answer of garbage) {
|
|
1538
|
+
const b = hooked(() => answer);
|
|
1539
|
+
b.unstick('p1');
|
|
1540
|
+
assert.deepEqual(b.at('p1'), ARRIVAL, JSON.stringify(answer));
|
|
1541
|
+
assert.deepEqual(b.sent[0][1].stuck, { spot: false, to: null });
|
|
1542
|
+
}
|
|
1543
|
+
// The edge of the world box is inside it.
|
|
1544
|
+
const edge = hooked(() => ({ x: 200, y: 80, z: -200 }));
|
|
1545
|
+
edge.unstick('p1');
|
|
1546
|
+
assert.deepEqual(edge.at('p1'), { x: 200, y: 80, z: -200 });
|
|
1547
|
+
const thrower = hooked(() => {
|
|
1548
|
+
throw new Error('no route');
|
|
1549
|
+
});
|
|
1550
|
+
thrower.unstick('p1');
|
|
1551
|
+
assert.deepEqual(thrower.at('p1'), ARRIVAL);
|
|
1552
|
+
assert.equal(thrower.sent.length, 1);
|
|
1553
|
+
});
|
|
1554
|
+
|
|
1555
|
+
// Nothing the place returns or throws can stop a tap from landing somewhere
|
|
1556
|
+
// valid and answering. Each of these is a hook that misbehaves in its own way.
|
|
1557
|
+
const HOSTILE = {
|
|
1558
|
+
'an object whose `then` is async and throws': () => ({
|
|
1559
|
+
async then() {
|
|
1560
|
+
throw new Error('failed');
|
|
1561
|
+
},
|
|
1562
|
+
}),
|
|
1563
|
+
'an object whose `then` is async and resolves to a spot': () => ({
|
|
1564
|
+
x: 12,
|
|
1565
|
+
z: -3,
|
|
1566
|
+
async then() {
|
|
1567
|
+
return { x: 12, z: -3 };
|
|
1568
|
+
},
|
|
1569
|
+
}),
|
|
1570
|
+
'a native promise already rejected': () => Promise.reject(new Error('rejected')),
|
|
1571
|
+
'a native promise whose own `then` was replaced by one that throws': () => {
|
|
1572
|
+
const p = Promise.reject(new Error('rejected'));
|
|
1573
|
+
p.then = () => {
|
|
1574
|
+
throw new Error('own then');
|
|
1575
|
+
};
|
|
1576
|
+
return p;
|
|
1577
|
+
},
|
|
1578
|
+
'a proxy whose `then` getter throws': () => new Proxy({ x: 12, z: -3 }, {
|
|
1579
|
+
get(target, key) {
|
|
1580
|
+
if (key === 'then') {
|
|
1581
|
+
throw new Error('then getter');
|
|
1582
|
+
}
|
|
1583
|
+
return target[key];
|
|
1584
|
+
},
|
|
1585
|
+
}),
|
|
1586
|
+
'a function with a `then`': () => Object.assign(() => {}, { x: 12, z: -3, async then() { throw new Error('fn then'); } }),
|
|
1587
|
+
'a promise that rejects (an async hook that throws)': async () => {
|
|
1588
|
+
throw new Error('no route');
|
|
1589
|
+
},
|
|
1590
|
+
'a promise that resolves to a spot': async () => ({ x: 12, z: -3 }),
|
|
1591
|
+
'a rejected promise made by hand': () => Promise.reject(new Error('no')),
|
|
1592
|
+
'a thenable that throws from then': () => ({
|
|
1593
|
+
x: 12,
|
|
1594
|
+
z: -3,
|
|
1595
|
+
then() {
|
|
1596
|
+
throw new Error('then');
|
|
1597
|
+
},
|
|
1598
|
+
}),
|
|
1599
|
+
'a `then` getter that throws': () => ({
|
|
1600
|
+
x: 12,
|
|
1601
|
+
z: -3,
|
|
1602
|
+
get then() {
|
|
1603
|
+
throw new Error('then getter');
|
|
1604
|
+
},
|
|
1605
|
+
}),
|
|
1606
|
+
'an `x` getter that throws': () => ({
|
|
1607
|
+
get x() {
|
|
1608
|
+
throw new Error('x');
|
|
1609
|
+
},
|
|
1610
|
+
z: -3,
|
|
1611
|
+
}),
|
|
1612
|
+
'a `to` getter that throws': () => ({
|
|
1613
|
+
x: 12,
|
|
1614
|
+
z: -3,
|
|
1615
|
+
get to() {
|
|
1616
|
+
throw new Error('to');
|
|
1617
|
+
},
|
|
1618
|
+
}),
|
|
1619
|
+
'a `facing` getter that throws': () => ({
|
|
1620
|
+
x: 12,
|
|
1621
|
+
z: -3,
|
|
1622
|
+
get facing() {
|
|
1623
|
+
throw new Error('facing');
|
|
1624
|
+
},
|
|
1625
|
+
}),
|
|
1626
|
+
'a proxy that throws on every read': () => new Proxy({}, {
|
|
1627
|
+
get() {
|
|
1628
|
+
throw new Error('proxy');
|
|
1629
|
+
},
|
|
1630
|
+
}),
|
|
1631
|
+
'a throw of something that cannot be printed': () => {
|
|
1632
|
+
throw { get message() { throw new Error('message'); } };
|
|
1633
|
+
},
|
|
1634
|
+
'a throw of null': () => {
|
|
1635
|
+
throw null;
|
|
1636
|
+
},
|
|
1637
|
+
};
|
|
1638
|
+
|
|
1639
|
+
for (const [name, hook] of Object.entries(HOSTILE)) {
|
|
1640
|
+
await testAsync(`a hostile hook -- ${name}: the tap still lands at the arrival and is answered, and the ask is answered`, async () => {
|
|
1641
|
+
const unhandled = [];
|
|
1642
|
+
const onUnhandled = (reason) => unhandled.push(reason);
|
|
1643
|
+
process.on('unhandledRejection', onUnhandled);
|
|
1644
|
+
try {
|
|
1645
|
+
const b = hooked(hook);
|
|
1646
|
+
// The ask: answered, nobody moved.
|
|
1647
|
+
b.ask('p1');
|
|
1648
|
+
assert.deepEqual(b.sent, [['p1', { k: 'hub-unstick-to', spot: false, to: null }]]);
|
|
1649
|
+
assert.deepEqual(b.at('p1'), FAR);
|
|
1650
|
+
// The tap: at the arrival, answered, the limit spent with it and not before.
|
|
1651
|
+
b.sent.length = 0;
|
|
1652
|
+
b.unstick('p1');
|
|
1653
|
+
assert.deepEqual(b.at('p1'), ARRIVAL);
|
|
1654
|
+
const body = b.world.players.get('p1');
|
|
1655
|
+
assert.deepEqual(b.sent, [['p1', { k: 'hub-jumped', facing: body.facing, stuck: { spot: false, to: null } }]]);
|
|
1656
|
+
// The snapshot too.
|
|
1657
|
+
assert.deepEqual(b.h.join().hubStuck, { to: null, hook: true });
|
|
1658
|
+
// Nothing left unhandled once the promises have settled: two turns of the loop.
|
|
1659
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
1660
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
1661
|
+
assert.deepEqual(unhandled, []);
|
|
1662
|
+
} finally {
|
|
1663
|
+
process.off('unhandledRejection', onUnhandled);
|
|
1664
|
+
}
|
|
1665
|
+
});
|
|
1666
|
+
}
|
|
1667
|
+
|
|
1668
|
+
test('a tap never spends its limit without moving the player and answering', () => {
|
|
1669
|
+
// A hook hostile on the first ask only: the first tap lands at the arrival and
|
|
1670
|
+
// is answered; the limit then holds as for any tap.
|
|
1671
|
+
let calls = 0;
|
|
1672
|
+
const b = hooked(() => {
|
|
1673
|
+
calls += 1;
|
|
1674
|
+
if (calls === 1) {
|
|
1675
|
+
return { get x() { throw new Error('x'); } };
|
|
1676
|
+
}
|
|
1677
|
+
return { x: 12, z: -3 };
|
|
1678
|
+
});
|
|
1679
|
+
b.unstick('p1');
|
|
1680
|
+
assert.deepEqual(b.at('p1'), ARRIVAL);
|
|
1681
|
+
assert.equal(b.sent.length, 1);
|
|
1682
|
+
b.world.players.get('p1').at = { ...FAR };
|
|
1683
|
+
b.unstick('p1');
|
|
1684
|
+
assert.deepEqual(b.at('p1'), FAR, 'within 5 s: refused, as after any tap that landed');
|
|
1685
|
+
assert.equal(calls, 1);
|
|
1686
|
+
skew += 6000;
|
|
1687
|
+
b.unstick('p1');
|
|
1688
|
+
assert.deepEqual(b.at('p1'), { x: 12, y: 0.76, z: -3 });
|
|
1689
|
+
assert.equal(b.sent.length, 2);
|
|
1690
|
+
});
|
|
1691
|
+
|
|
1692
|
+
await testAsync('a hostile `where` hook stops neither the tap nor the snapshot', async () => {
|
|
1693
|
+
const unhandled = [];
|
|
1694
|
+
const onUnhandled = (reason) => unhandled.push(reason);
|
|
1695
|
+
process.on('unhandledRejection', onUnhandled);
|
|
1696
|
+
try {
|
|
1697
|
+
for (const where of [
|
|
1698
|
+
async () => {
|
|
1699
|
+
throw new Error('where');
|
|
1700
|
+
},
|
|
1701
|
+
() => ({
|
|
1702
|
+
async then() {
|
|
1703
|
+
throw new Error('failed');
|
|
1704
|
+
},
|
|
1705
|
+
}),
|
|
1706
|
+
() => new Proxy({}, {
|
|
1707
|
+
get() {
|
|
1708
|
+
throw new Error('then getter');
|
|
1709
|
+
},
|
|
1710
|
+
}),
|
|
1711
|
+
() => {
|
|
1712
|
+
throw { get message() { throw new Error('message'); } };
|
|
1713
|
+
},
|
|
1714
|
+
() => ({ trim() { throw new Error('trim'); } }),
|
|
1715
|
+
]) {
|
|
1716
|
+
const b = boot({ hub: { stuck: true }, hooks: { where, unstick: () => null } });
|
|
1717
|
+
assert.deepEqual(b.h.join().hubStuck, { to: null, hook: true });
|
|
1718
|
+
b.unstick('p1');
|
|
1719
|
+
assert.deepEqual(b.at('p1'), ARRIVAL);
|
|
1720
|
+
assert.deepEqual(b.sent.at(-1)[1].stuck, { spot: false, to: null });
|
|
1721
|
+
}
|
|
1722
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
1723
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
1724
|
+
assert.deepEqual(unhandled, []);
|
|
1725
|
+
} finally {
|
|
1726
|
+
process.off('unhandledRejection', onUnhandled);
|
|
1727
|
+
}
|
|
1728
|
+
});
|
|
1729
|
+
|
|
1730
|
+
test('with the hook the limits are the ones they were: 5 s, a jump, holds, a town only', () => {
|
|
1731
|
+
const b = hooked(() => ({ x: 12, z: -3 }));
|
|
1732
|
+
b.unstick('p1');
|
|
1733
|
+
b.world.players.get('p1').at = { ...FAR };
|
|
1734
|
+
skew += 4900;
|
|
1735
|
+
b.unstick('p1');
|
|
1736
|
+
assert.deepEqual(b.at('p1'), FAR, 'again within 5 s: refused');
|
|
1737
|
+
assert.equal(b.asked.length, 1, 'and the place is not even asked');
|
|
1738
|
+
skew += 200;
|
|
1739
|
+
b.unstick('p1');
|
|
1740
|
+
assert.deepEqual(b.at('p1'), { x: 12, y: 0.76, z: -3 });
|
|
1741
|
+
// Within a second of a door jump.
|
|
1742
|
+
skew += 6000;
|
|
1743
|
+
b.h.message(b.session, { playerId: 'p1' }, { k: 'hub-door-jump', door: 'race' });
|
|
1744
|
+
const atDoor = { ...b.at('p1') };
|
|
1745
|
+
b.unstick('p1');
|
|
1746
|
+
assert.deepEqual(b.at('p1'), atDoor);
|
|
1747
|
+
// Held: refused, and not counted.
|
|
1748
|
+
b.ctx().hold('p2', { x: 3, y: 1, z: 3 });
|
|
1749
|
+
b.unstick('p2');
|
|
1750
|
+
assert.deepEqual(b.at('p2'), { x: 3, y: 1, z: 3 });
|
|
1751
|
+
b.ctx().release('p2');
|
|
1752
|
+
b.unstick('p2');
|
|
1753
|
+
assert.deepEqual(b.at('p2'), { x: 12, y: 0.76, z: -3 });
|
|
1754
|
+
// Ended, or not here.
|
|
1755
|
+
skew += 6000;
|
|
1756
|
+
b.ctx().end(['p2']);
|
|
1757
|
+
const asked = b.asked.length;
|
|
1758
|
+
b.unstick('p2');
|
|
1759
|
+
b.h.message(b.session, { playerId: 'ghost' }, { k: 'hub-unstick' });
|
|
1760
|
+
assert.equal(b.asked.length, asked);
|
|
1761
|
+
// A game place: no hook is asked, nobody moves, the snapshot says nothing.
|
|
1762
|
+
const game = hooked(() => ({ x: 12, z: -3 }), { sessionId: 'dev:hub.race.abc123' });
|
|
1763
|
+
assert.equal('hubStuck' in game.h.join(), false);
|
|
1764
|
+
game.unstick('p1');
|
|
1765
|
+
game.ask('p1');
|
|
1766
|
+
assert.deepEqual(game.at('p1'), FAR);
|
|
1767
|
+
assert.deepEqual(game.asked, []);
|
|
1768
|
+
assert.deepEqual(game.sent, []);
|
|
1769
|
+
const main = hooked(() => ({ x: 12, z: -3 }), { hub: { result: { outcomes: ['win', 'lose'] } } });
|
|
1770
|
+
main.unstick('p1');
|
|
1771
|
+
main.ask('p1');
|
|
1772
|
+
assert.deepEqual(main.at('p1'), FAR);
|
|
1773
|
+
assert.deepEqual(main.asked, []);
|
|
1774
|
+
});
|
|
1775
|
+
|
|
1776
|
+
test('what a tap would do, asked before it: answered, nobody moved, once a second', () => {
|
|
1777
|
+
let n = 0;
|
|
1778
|
+
const b = hooked(() => ((n += 1) % 2 ? { x: 12, z: -3, to: 'the street' } : null));
|
|
1779
|
+
b.ask('p1');
|
|
1780
|
+
assert.deepEqual(b.sent, [['p1', { k: 'hub-unstick-to', spot: true, to: 'the street' }]]);
|
|
1781
|
+
assert.deepEqual(b.at('p1'), FAR, 'nobody is moved by the asking');
|
|
1782
|
+
assert.equal(b.world.players.get('p1').clamped, false);
|
|
1783
|
+
assert.deepEqual(b.asked, [['function', 'p1', FAR]]);
|
|
1784
|
+
b.ask('p1');
|
|
1785
|
+
assert.equal(b.sent.length, 1, 'again within a second: not answered');
|
|
1786
|
+
skew += 1100;
|
|
1787
|
+
b.ask('p1');
|
|
1788
|
+
assert.deepEqual(b.sent[1], ['p1', { k: 'hub-unstick-to', spot: false, to: null }], 'nothing for them: the arrival, by its name');
|
|
1789
|
+
// The asking is not the tap's limit: the tap is taken at once.
|
|
1790
|
+
b.unstick('p1');
|
|
1791
|
+
assert.deepEqual(b.at('p1'), { x: 12, y: 0.76, z: -3 });
|
|
1792
|
+
// A held player, one not here: not answered.
|
|
1793
|
+
b.ctx().hold('p2', { x: 3, y: 1, z: 3 });
|
|
1794
|
+
b.ask('p2');
|
|
1795
|
+
b.h.message(b.session, { playerId: 'ghost' }, { k: 'hub-unstick', ask: true });
|
|
1796
|
+
assert.equal(b.sent.filter(([, msg]) => msg.k === 'hub-unstick-to').length, 2);
|
|
1797
|
+
});
|
|
1798
|
+
|
|
1799
|
+
test('a place with no hook: the snapshot, the answer and the tap are v1.33\'s', () => {
|
|
1800
|
+
const b = boot({ hub: { stuck: true } });
|
|
1801
|
+
assert.deepEqual(b.h.join().hubStuck, { to: null }, 'no `hook`');
|
|
1802
|
+
b.h.message(b.session, { playerId: 'p1' }, { k: 'hub-unstick', ask: true });
|
|
1803
|
+
assert.deepEqual(b.sent, [], 'asked what a tap would do: nothing to say, and nobody moved');
|
|
1804
|
+
assert.deepEqual(b.at('p1'), FAR);
|
|
1805
|
+
assert.deepEqual(b.heard, [], "nor is it the place's own message");
|
|
1806
|
+
b.unstick('p1');
|
|
1807
|
+
assert.deepEqual(b.at('p1'), ARRIVAL);
|
|
1808
|
+
assert.deepEqual(b.sent, [['p1', { k: 'hub-jumped', facing: b.world.players.get('p1').facing }]], 'no `stuck` in the reply');
|
|
1809
|
+
// And a deck without the key: `ask` or not, the message is the place's own.
|
|
1810
|
+
const plain = boot({ hooks: { unstick: () => ({ x: 12, z: -3 }) } });
|
|
1811
|
+
plain.h.message(plain.session, { playerId: 'p1' }, { k: 'hub-unstick', ask: true });
|
|
1812
|
+
plain.unstick('p1');
|
|
1813
|
+
assert.deepEqual(plain.at('p1'), FAR);
|
|
1814
|
+
assert.deepEqual(plain.sent, []);
|
|
1815
|
+
assert.deepEqual(plain.heard, [{ k: 'hub-unstick', ask: true }, { k: 'hub-unstick' }]);
|
|
1816
|
+
assert.equal('hubStuck' in plain.h.join(), false);
|
|
1817
|
+
});
|
|
1818
|
+
|
|
1819
|
+
test('toast bands: a phone clears Talk and follows questions; a desktop clears Talk and an asked-for chip', () => {
|
|
1820
|
+
const previous = globalThis.matchMedia;
|
|
1821
|
+
const changes = new Set();
|
|
1822
|
+
const media = { matches: false, addEventListener: (type, fn) => changes.add(fn), removeEventListener: (type, fn) => changes.delete(fn) };
|
|
1823
|
+
globalThis.matchMedia = () => media;
|
|
1824
|
+
try {
|
|
1825
|
+
const r = rig(PORTRAIT);
|
|
1826
|
+
const talk = r.made.find((c) => c.tag === 'button' && String(c.style.bottom).startsWith('max(64px'));
|
|
1827
|
+
talk.rect = mid(PORTRAIT, 200, PORTRAIT.h - 64 - 40, 40);
|
|
1828
|
+
r.chrome.talkPrompt('Sam');
|
|
1829
|
+
r.chrome.setHud({ title: 'Today', text: 'errands' }, null);
|
|
1830
|
+
r.lay.hud(90);
|
|
1831
|
+
r.chrome.setToast('Sam joined your party');
|
|
1832
|
+
let box = r.nodes.toast.getBoundingClientRect();
|
|
1833
|
+
assert.equal(box.top, 108);
|
|
1834
|
+
assert.ok(clear(box, talk.rect));
|
|
1835
|
+
assert.notEqual(r.nodes.toast.style.pointerEvents, 'auto');
|
|
1836
|
+
r.chrome.setAsk({ key: 'q', text: 'Come along?', yes: 'Go', no: 'Not now' });
|
|
1837
|
+
r.lay.ask(62);
|
|
1838
|
+
r.chrome.setToast('Sam joined your party');
|
|
1839
|
+
assert.equal(r.nodes.toast.getBoundingClientRect().top, 160, 'a question appearing while the toast stays up moves it on the next frame');
|
|
1840
|
+
media.matches = true;
|
|
1841
|
+
changes.forEach((fn) => fn());
|
|
1842
|
+
r.chrome.setToast('Sam joined your party');
|
|
1843
|
+
box = r.nodes.toast.getBoundingClientRect();
|
|
1844
|
+
assert.equal(r.nodes.toast.style.top, '');
|
|
1845
|
+
assert.equal(box.bottom, talk.rect.top - 6);
|
|
1846
|
+
window.innerHeight += 40;
|
|
1847
|
+
r.chrome.setToast('Sam joined your party');
|
|
1848
|
+
assert.equal(Number.parseFloat(r.nodes.toast.style.bottom), window.innerHeight - talk.rect.top + 6, 'the next frame remeasures an active toast after a resize');
|
|
1849
|
+
window.innerHeight -= 40;
|
|
1850
|
+
r.chrome.setToast('Sam joined your party');
|
|
1851
|
+
for (let frame = 0; frame < 4; frame += 1) {
|
|
1852
|
+
r.chrome.setToast('Sam joined your party');
|
|
1853
|
+
r.prompt();
|
|
1854
|
+
box = r.nodes.toast.getBoundingClientRect();
|
|
1855
|
+
assert.ok(r.chip(), 'the chip stays visible on every frame');
|
|
1856
|
+
assert.ok(clear(box, r.chip()) && clear(box, talk.rect), 'the toast is clear of the chip and of Talk');
|
|
1857
|
+
assert.equal(box.bottom, talk.rect.top - 6, 'and stays in the one place, frame after frame');
|
|
1858
|
+
}
|
|
1859
|
+
// A chip that cannot be drawn (something else is where it hangs) is
|
|
1860
|
+
// still left its spot: the toast does not move as the chip is tried and
|
|
1861
|
+
// hidden, frame after frame.
|
|
1862
|
+
r.nodes.sit.style.display = 'block';
|
|
1863
|
+
r.nodes.sit.rect = r.chip();
|
|
1864
|
+
r.nodes.near.style.display = 'block';
|
|
1865
|
+
r.nodes.near.rect = { ...talk.rect, top: r.chip().bottom, bottom: talk.rect.top };
|
|
1866
|
+
const places = new Set();
|
|
1867
|
+
for (let frame = 0; frame < 4; frame += 1) {
|
|
1868
|
+
r.chrome.setToast('Sam joined your party');
|
|
1869
|
+
places.add(r.nodes.toast.style.bottom);
|
|
1870
|
+
r.prompt();
|
|
1871
|
+
places.add(r.nodes.toast.style.bottom);
|
|
1872
|
+
assert.equal(r.chip(), null, 'the chip yields to the control in its spot');
|
|
1873
|
+
}
|
|
1874
|
+
assert.equal(places.size, 1, `one place through every frame: ${[...places]}`);
|
|
1875
|
+
assert.ok(r.nodes.toast.getBoundingClientRect().bottom <= r.nodes.sit.rect.top - 6);
|
|
1876
|
+
r.nodes.sit.style.display = 'none';
|
|
1877
|
+
r.nodes.near.style.display = 'none';
|
|
1878
|
+
// A chip moved down on a short phone can return to its hanging spot
|
|
1879
|
+
// when desktop mode comes in. Reserve that spot before it returns.
|
|
1880
|
+
media.matches = false;
|
|
1881
|
+
r.chrome.setToast('');
|
|
1882
|
+
r.chrome.setAsk(null);
|
|
1883
|
+
r.lay.hud(660);
|
|
1884
|
+
r.prompt();
|
|
1885
|
+
assert.ok(r.chip().top > PORTRAIT.h - CHIP.up - CHIP.h);
|
|
1886
|
+
media.matches = true;
|
|
1887
|
+
r.chrome.setHud(null, null);
|
|
1888
|
+
r.chrome.setToast('Sam joined your party');
|
|
1889
|
+
r.prompt();
|
|
1890
|
+
assert.equal(r.chip().top, PORTRAIT.h - CHIP.up - CHIP.h);
|
|
1891
|
+
assert.ok(clear(r.nodes.toast.getBoundingClientRect(), r.chip()));
|
|
1892
|
+
r.chrome.dispose();
|
|
1893
|
+
assert.equal(changes.size, 0, 'media listener is removed');
|
|
1894
|
+
} finally {
|
|
1895
|
+
if (previous === undefined) {
|
|
1896
|
+
delete globalThis.matchMedia;
|
|
1897
|
+
} else {
|
|
1898
|
+
globalThis.matchMedia = previous;
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
});
|
|
1902
|
+
|
|
1903
|
+
Date.now = realDateNow;
|
|
1904
|
+
console.log(`test-stuck: ${n} passed`);
|