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,1167 @@
|
|
|
1
|
+
// v1.71 private follower state, geometry, motion and reconnect cleanup.
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { setMaxListeners } from 'node:events';
|
|
4
|
+
import { register } from 'node:module';
|
|
5
|
+
import { readFileSync } from 'node:fs';
|
|
6
|
+
|
|
7
|
+
register(`data:text/javascript,${encodeURIComponent(`
|
|
8
|
+
import { readFile } from 'node:fs/promises';
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
10
|
+
export async function resolve(specifier, context, next) {
|
|
11
|
+
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 };
|
|
12
|
+
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 };
|
|
13
|
+
if (specifier === 'castle-web-sdk') return { url: 'data:text/javascript,export {};', shortCircuit: true };
|
|
14
|
+
if (specifier === '@imports/castle.multiplayer-3d/code/client/avatars.js') return { url: 'data:text/javascript,export const dropMissing = () => {};', shortCircuit: true };
|
|
15
|
+
if (specifier.startsWith('@imports/castle.physics-2d/engine/')) return { url: 'data:text/javascript,export const initialMedia = {}; export const playMedia = () => {}; export const stopMedia = () => {};', shortCircuit: true };
|
|
16
|
+
if (specifier === '../client/pack.js') return { url: 'data:text/javascript,export const cachedPacks = () => []; export const loadPack = () => {}; export const matchesOwn = () => false; export const resolveDeckDoor = () => {};', shortCircuit: true };
|
|
17
|
+
return next(specifier, context);
|
|
18
|
+
}
|
|
19
|
+
export async function load(url, context, next) {
|
|
20
|
+
if (url.endsWith('/code/client/hookLayer.js')) {
|
|
21
|
+
const source = await readFile(fileURLToPath(url), 'utf8');
|
|
22
|
+
return { format: 'module', source: source.replaceAll('import.meta.glob(', '(() => ({}))('), shortCircuit: true };
|
|
23
|
+
}
|
|
24
|
+
return next(url, context);
|
|
25
|
+
}
|
|
26
|
+
`)}`);
|
|
27
|
+
const State = await import('../code/client/state.js');
|
|
28
|
+
const hook = (await import('../code/client/hookLayer.js')).default;
|
|
29
|
+
const { installSystem } = await import('../code/systems/hub.js');
|
|
30
|
+
const { makeChrome } = await import('../code/client/chrome.js');
|
|
31
|
+
function fakeDom(view) {
|
|
32
|
+
const log = [];
|
|
33
|
+
let ids = 0;
|
|
34
|
+
const made = [];
|
|
35
|
+
function node(tag) {
|
|
36
|
+
const id = `${tag}#${(ids += 1)}`;
|
|
37
|
+
const styles = {};
|
|
38
|
+
let text = '';
|
|
39
|
+
const self = {
|
|
40
|
+
id,
|
|
41
|
+
tag,
|
|
42
|
+
children: [],
|
|
43
|
+
parent: null,
|
|
44
|
+
dataset: {},
|
|
45
|
+
attrs: {},
|
|
46
|
+
rect: null,
|
|
47
|
+
size: null,
|
|
48
|
+
style: new Proxy(styles, {
|
|
49
|
+
get: (target, key) => target[key] ?? '',
|
|
50
|
+
set(target, key, value) {
|
|
51
|
+
target[key] = String(value);
|
|
52
|
+
log.push(`${id} style.${String(key)}=${value}`);
|
|
53
|
+
return true;
|
|
54
|
+
},
|
|
55
|
+
}),
|
|
56
|
+
styles,
|
|
57
|
+
get textContent() {
|
|
58
|
+
return text;
|
|
59
|
+
},
|
|
60
|
+
set textContent(value) {
|
|
61
|
+
text = String(value);
|
|
62
|
+
log.push(`${id} text=${text}`);
|
|
63
|
+
},
|
|
64
|
+
appendChild(child) {
|
|
65
|
+
child.parent = self;
|
|
66
|
+
self.children.push(child);
|
|
67
|
+
log.push(`${id} +${child.id}`);
|
|
68
|
+
return child;
|
|
69
|
+
},
|
|
70
|
+
append(...kids) {
|
|
71
|
+
kids.forEach((kid) => self.appendChild(kid));
|
|
72
|
+
},
|
|
73
|
+
insertBefore(child, before) {
|
|
74
|
+
if (child.parent) {
|
|
75
|
+
child.parent.children = child.parent.children.filter((c) => c !== child);
|
|
76
|
+
}
|
|
77
|
+
child.parent = self;
|
|
78
|
+
const at = self.children.indexOf(before);
|
|
79
|
+
self.children.splice(at < 0 ? self.children.length : at, 0, child);
|
|
80
|
+
return child;
|
|
81
|
+
},
|
|
82
|
+
remove() {
|
|
83
|
+
if (self.parent) {
|
|
84
|
+
self.parent.children = self.parent.children.filter((c) => c !== self);
|
|
85
|
+
log.push(`${id} removed`);
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
replaceChildren(...kids) {
|
|
89
|
+
self.children = [];
|
|
90
|
+
log.push(`${id} emptied`);
|
|
91
|
+
kids.forEach((kid) => self.appendChild(kid));
|
|
92
|
+
},
|
|
93
|
+
handlers: {},
|
|
94
|
+
addEventListener(type, fn, options) {
|
|
95
|
+
self.handlers[type] = fn;
|
|
96
|
+
if (options?.signal) {
|
|
97
|
+
setMaxListeners(0, options.signal);
|
|
98
|
+
options.signal.addEventListener('abort', () => { delete self.handlers[type]; }, { once: true });
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
removeEventListener() {},
|
|
102
|
+
setAttribute(key, value) {
|
|
103
|
+
self.attrs[key] = String(value);
|
|
104
|
+
},
|
|
105
|
+
getAttribute: (key) => self.attrs[key] ?? null,
|
|
106
|
+
focus() { document.activeElement = self; },
|
|
107
|
+
blur() { if (document.activeElement === self) document.activeElement = null; },
|
|
108
|
+
// A stand-in layout: 7 px a character and 20 of padding, one 24 px line.
|
|
109
|
+
get offsetWidth() {
|
|
110
|
+
log.push(`${id} read`);
|
|
111
|
+
return (typeof self.size === 'function' ? self.size(self) : self.size)?.w ?? text.length * 7 + 20;
|
|
112
|
+
},
|
|
113
|
+
get offsetHeight() {
|
|
114
|
+
log.push(`${id} read`);
|
|
115
|
+
return (typeof self.size === 'function' ? self.size(self) : self.size)?.h ?? 24;
|
|
116
|
+
},
|
|
117
|
+
get offsetLeft() {
|
|
118
|
+
return parseFloat(styles.left) || 0;
|
|
119
|
+
},
|
|
120
|
+
get clientWidth() {
|
|
121
|
+
return self.client ?? self.offsetWidth;
|
|
122
|
+
},
|
|
123
|
+
get scrollWidth() {
|
|
124
|
+
return self.scroll ?? self.offsetWidth;
|
|
125
|
+
},
|
|
126
|
+
getBoundingClientRect() {
|
|
127
|
+
let r = self.rect ?? { left: 0, right: 0, top: 0, bottom: 0 };
|
|
128
|
+
if (styles.flexDirection === 'column-reverse') {
|
|
129
|
+
const height = self.children.length * 44 + (self.children.length - 1) * 6;
|
|
130
|
+
const bottom = styles.bottom.startsWith('max') ? 132 : parseFloat(styles.bottom);
|
|
131
|
+
r = { left: view.viewW - 162, right: view.viewW - 12, top: view.viewH - bottom - height, bottom: view.viewH - bottom };
|
|
132
|
+
}
|
|
133
|
+
return { ...r, width: r.right - r.left, height: r.bottom - r.top };
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
made.push(self);
|
|
137
|
+
return self;
|
|
138
|
+
}
|
|
139
|
+
const body = node('body');
|
|
140
|
+
globalThis.document = { body, createElement: node, activeElement: null };
|
|
141
|
+
globalThis.window = { innerWidth: view.viewW, innerHeight: view.viewH };
|
|
142
|
+
globalThis.innerWidth = view.viewW;
|
|
143
|
+
return { log, body, made };
|
|
144
|
+
}
|
|
145
|
+
const Companion = await import('../code/client/companion.js');
|
|
146
|
+
const THREE = await import('three');
|
|
147
|
+
const { fitOrbitLens } = await import('../../physics-3d/engine3d/orbitlens.js');
|
|
148
|
+
|
|
149
|
+
const spec = { look: 'lantern', say: '<b>Follow me</b>', at: 'goal' };
|
|
150
|
+
let passed = 0;
|
|
151
|
+
function test(name, fn) { fn(); passed += 1; console.log(`ok: ${name}`); }
|
|
152
|
+
const near = (a, b) => assert(Math.abs(a - b) < 1e-9, `${a} != ${b}`);
|
|
153
|
+
function rig(options = process.env.COMPANION_IDLE_TEST === '1' ? { idle: true } : undefined) {
|
|
154
|
+
const own = new THREE.Group(), other = new THREE.Group(), root = new THREE.Scene();
|
|
155
|
+
const local = { id: 'local', components: { Transform: { x: 2, y: 1, z: 3, rotationY: 0 } } };
|
|
156
|
+
const nodes = new Map([['local', { node: own }], ['other', { node: other }]]);
|
|
157
|
+
root.add(own, other);
|
|
158
|
+
const hub = { place: { companion: true }, companion: { c: spec, n: 1 }, glow: new Set(['p1', 'p2']) };
|
|
159
|
+
const scene = { three: { scene: root, nodes }, multiplayer: { net: { selfId: () => 'p1' }, avatars: { actors: new Map([['p2', 'other']]) } }, getActor: () => null };
|
|
160
|
+
const drawer = Companion.makeCompanion(options);
|
|
161
|
+
const frame = (now = 0, visible = true, busy = false) => drawer.frame(scene, local, hub, 0.05, now, visible, null, busy);
|
|
162
|
+
const labels = (now = 0) => drawer.labels({}, {}, (cam, x, y, z) => ({ x, y, z }), now);
|
|
163
|
+
return { scene, local, own, other, root, hub, drawer, frame, labels };
|
|
164
|
+
}
|
|
165
|
+
test('sanitise shares the server rules, reads once, and turns every invalid spec into null', () => {
|
|
166
|
+
assert.deepEqual(Companion.sanitise(spec), spec);
|
|
167
|
+
for (const value of [undefined, null, {}, [], { look: 'bad' }, { ...spec, extra: 1 }, { ...spec, [Symbol()]: 1 }, Object.create(spec), { ...spec, say: '' }, { ...spec, say: ' ' }, { ...spec, say: '😀'.repeat(81) }, { ...spec, at: '' }, { ...spec, at: 'x'.repeat(65) }, ...['\n', '\r', '\u2028', '\u2029', '\u061c', '\u200b', '\u200e', '\u202e', '\u2060', '\u2069', '\ufeff'].map((c) => ({ ...spec, say: `a${c}b` }))]) assert.equal(Companion.sanitise(value), null);
|
|
168
|
+
assert.equal(Companion.sanitise({ look: 'bird', say: '😀'.repeat(80), at: 'x'.repeat(64) }).say.length, 160);
|
|
169
|
+
let reads = 0;
|
|
170
|
+
assert.equal(Companion.sanitise({ get look() { reads++; return 'bird'; } }).look, 'bird'); assert.equal(reads, 1);
|
|
171
|
+
assert.equal(Companion.sanitise({ get look() { throw new Error('bad'); } }), null);
|
|
172
|
+
});
|
|
173
|
+
test('followTarget: facing-relative rest, feet height, point direction and half-Hz bob', () => {
|
|
174
|
+
const player = { x: 2, y: 1, z: 3, yaw: 0 };
|
|
175
|
+
assert.deepEqual(Companion.followTarget(player, null, 0), { x: 2.55, y: 1.75, z: 2.65 });
|
|
176
|
+
const right = Companion.followTarget({ ...player, yaw: Math.PI / 2 }, null, 0);
|
|
177
|
+
near(right.x, 1.65); near(right.z, 2.45);
|
|
178
|
+
const pointed = Companion.followTarget(player, { x: 5, z: 7 }, 0);
|
|
179
|
+
near(pointed.x, 2.54); near(pointed.z, 3.72); near(Math.hypot(pointed.x - 2, pointed.z - 3), 0.9);
|
|
180
|
+
near(Companion.followTarget(player, null, 0.5).y, 1.81);
|
|
181
|
+
near(Companion.followTarget(player, null, 1.5).y, 1.69);
|
|
182
|
+
near(Companion.followTarget(player, null, 2).y, 1.75);
|
|
183
|
+
assert.deepEqual(Companion.followTarget(player, { x: 2, z: 3 }, 0), Companion.followTarget(player, null, 0));
|
|
184
|
+
});
|
|
185
|
+
test('chat target follows camera forward at eye height, faces player, lifts above a panel and exits to follow', () => {
|
|
186
|
+
const player = { x: 2, y: 1, z: 3, yaw: 0 };
|
|
187
|
+
const camera = { forward: { x: 0, z: -1 }, position: { x: 2, y: 2, z: 8 } };
|
|
188
|
+
const target = Companion.chatTarget(player, camera, 0);
|
|
189
|
+
near(target.x, 2); near(target.z, 1.7); near(target.y, 1.85); near(target.yaw, 0);
|
|
190
|
+
const lifted = Companion.chatTarget(player, camera, 0, { left: 0, right: 360, top: 400, bottom: 668 }, { w: 360, h: 668 }, (at) => ({ x: 180, y: 450 - (at.y - 1.85) * 200 }));
|
|
191
|
+
near(lifted.y, 2.25);
|
|
192
|
+
const offscreen = Companion.chatTarget(player, camera, 0, null, { w: 360, h: 668 }, (at) => ({ x: 180, y: 700 - (at.y - 1.85) * 200 }));
|
|
193
|
+
near(offscreen.y, 2.25);
|
|
194
|
+
// Every lift covered (a far orbit): the highest on-screen candidate, never the last one tried.
|
|
195
|
+
const covered = Companion.chatTarget(player, camera, 0, { left: 0, right: 360, top: 400, bottom: 668 }, { w: 360, h: 668 }, (at) => ({ x: 180, y: 600 - (at.y - 1.85) * 20 }));
|
|
196
|
+
near(covered.y, 3.85);
|
|
197
|
+
const over = { ...camera, position: { x: 2, y: 2.8, z: 1.7 } };
|
|
198
|
+
const raisedSafe = Companion.chatTarget(player, over, 0, { left: 0, right: 360, top: 400, bottom: 668 }, { w: 360, h: 668 }, (at) => ({ x: 180, y: 450 - (at.y - 1.85) * 200 }));
|
|
199
|
+
assert(Math.hypot(raisedSafe.x - over.position.x, raisedSafe.y - over.position.y, raisedSafe.z - over.position.z) >= 0.9);
|
|
200
|
+
const rotated = Companion.chatTarget(player, { forward: { x: 1, z: 0 } }, 0);
|
|
201
|
+
near(rotated.x, 3.3); near(rotated.z, 3); near(rotated.yaw, -Math.PI / 2);
|
|
202
|
+
const closeCamera = { ...camera, position: { x: 2, y: 1.85, z: 1.7 } };
|
|
203
|
+
const safe = Companion.chatTarget(player, closeCamera, 0);
|
|
204
|
+
assert(Math.hypot(safe.x - closeCamera.position.x, safe.y - closeCamera.position.y, safe.z - closeCamera.position.z) >= 0.9);
|
|
205
|
+
assert(Math.hypot(safe.x - player.x, safe.z - player.z) >= 0.9);
|
|
206
|
+
assert.deepEqual(Companion.motionTarget(player, null, 0, false, null), Companion.followTarget(player, null, 0));
|
|
207
|
+
});
|
|
208
|
+
test('chat holds through 30 s and 3 min away, then smoothly follows when closed', () => {
|
|
209
|
+
for (const away of [30000, 180000]) {
|
|
210
|
+
const r = rig(); r.hub.place.companionChat = { name: 'Chirp' }; r.hub.companion.c = { look: 'bird' };
|
|
211
|
+
const chat = { camera: { forward: { x: 0, z: -1 } } };
|
|
212
|
+
const frame = (now, talking) => r.drawer.frame(r.scene, r.local, r.hub, 0.05, now, true, talking ? chat : null);
|
|
213
|
+
frame(0, true); frame(away, true);
|
|
214
|
+
const bird = r.root.children.find((n) => n.name === 'companion:bird');
|
|
215
|
+
near(bird.position.z, 1.7); near(bird.rotation.y, 0);
|
|
216
|
+
frame(away + 50, false); assert(bird.position.z > 1.7 && bird.position.z < 2.65);
|
|
217
|
+
frame(away * 2, false); assert(bird.position.z > 1.7);
|
|
218
|
+
r.drawer.dispose();
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
test('showTarget fills one third of portrait and landscape height and keeps the left screen spot through orbit', () => {
|
|
222
|
+
const player = { x: 0, y: 1, z: 0 };
|
|
223
|
+
const camera = new THREE.PerspectiveCamera(50, 412 / 870, 0.1, 100);
|
|
224
|
+
camera.position.set(0, 1, 6); camera.lookAt(0, 1, 0); camera.updateMatrixWorld(true);
|
|
225
|
+
const input = () => ({ position: camera.position, forward: camera.getWorldDirection(new THREE.Vector3()), fov: camera.fov, near: camera.near });
|
|
226
|
+
const project = (p) => new THREE.Vector3(p.x, p.y, p.z).project(camera);
|
|
227
|
+
for (const view of [{ w: 412, h: 870 }, { w: 870, h: 412 }]) {
|
|
228
|
+
camera.aspect = view.w / view.h; camera.updateProjectionMatrix();
|
|
229
|
+
for (const species of ['songbird', 'owl', 'parrot', 'hummingbird']) {
|
|
230
|
+
const bird = Companion.build('bird', { species });
|
|
231
|
+
const size = bird.userData.size;
|
|
232
|
+
assert(size > 0);
|
|
233
|
+
const target = Companion.showTarget(player, input(), view, size);
|
|
234
|
+
const top = project({ ...target, y: target.y + size / 2 }), bottom = project({ ...target, y: target.y - size / 2 });
|
|
235
|
+
const height = Math.abs(top.y - bottom.y) * view.h / 2;
|
|
236
|
+
assert(Math.abs(height / (view.h / 3) - 1) < 0.15);
|
|
237
|
+
const screen = project(target); near(screen.x, view.h > view.w ? -0.46 : -0.3); near(screen.y, view.h > view.w ? 0.2 : 0.1);
|
|
238
|
+
near(target.yaw, Math.atan2(camera.position.x - target.x, camera.position.z - target.z));
|
|
239
|
+
camera.position.set(6, 1, 0); camera.lookAt(0, 1, 0); camera.updateMatrixWorld(true);
|
|
240
|
+
const rotated = Companion.showTarget(player, input(), view, size);
|
|
241
|
+
near(project(rotated).x, screen.x); near(project(rotated).y, screen.y);
|
|
242
|
+
near(rotated.yaw, Math.atan2(camera.position.x - rotated.x, camera.position.z - rotated.z));
|
|
243
|
+
camera.position.set(0, 1, 6); camera.lookAt(0, 1, 0); camera.updateMatrixWorld(true);
|
|
244
|
+
bird.traverse((n) => { n.geometry?.dispose(); n.material?.dispose(); });
|
|
245
|
+
}
|
|
246
|
+
for (const size of [0.001, 100]) {
|
|
247
|
+
const target = Companion.showTarget(player, input(), view, size);
|
|
248
|
+
const offset = new THREE.Vector3(target.x, target.y, target.z).sub(camera.position);
|
|
249
|
+
assert(offset.length() >= camera.near + 0.3);
|
|
250
|
+
assert(offset.dot(input().forward) >= camera.near + 0.3);
|
|
251
|
+
assert(offset.length() <= camera.position.distanceTo(new THREE.Vector3(player.x, player.y, player.z)) - 0.4 + 1e-9);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
test('show follower flies close, stays full and camera-relative through orbit/zoom, and flies back when cleared', () => {
|
|
256
|
+
const r = rig(), player = r.local.components.Transform;
|
|
257
|
+
const cam = new THREE.PerspectiveCamera(50, 412 / 870, 0.1, 100);
|
|
258
|
+
r.scene.three.camera = cam;
|
|
259
|
+
const aim = () => { cam.lookAt(player.x, player.y, player.z); cam.updateMatrixWorld(true); };
|
|
260
|
+
cam.position.set(player.x, player.y + 1, player.z + 6); aim();
|
|
261
|
+
const camera = () => ({ position: cam.position, forward: cam.getWorldDirection(new THREE.Vector3()), fov: cam.fov, near: cam.near });
|
|
262
|
+
r.hub.companion = { c: { look: 'bird', dress: { wear: 'bow' } }, n: 2 };
|
|
263
|
+
r.frame();
|
|
264
|
+
const bird = r.root.children.find((n) => n.name === 'companion:bird');
|
|
265
|
+
const before = bird.position.clone();
|
|
266
|
+
r.scene.getActor = () => ({ components: { Transform: { x: 6, y: 0, z: 3 }, TownHats: {} } });
|
|
267
|
+
r.hub.companion = { c: { look: 'bird', dress: { wear: 'bow' }, pose: 'show', at: 'stall' }, n: 3, stamps: 1 };
|
|
268
|
+
r.frame(50);
|
|
269
|
+
assert(bird.position.distanceTo(before) < 2, 'approach starts with flight, allowing clearance in front of the player');
|
|
270
|
+
const target = () => Companion.showTarget(player, camera(), { w: 412, h: 870 }, bird.userData.size, bird.userData.radius, bird.userData.showVertices, 5);
|
|
271
|
+
for (let now = 100; now <= 5000; now += 50) r.frame(now);
|
|
272
|
+
assert(bird.position.distanceTo(new THREE.Vector3(target().x, target().y, target().z)) < 0.03);
|
|
273
|
+
near(bird.scale.x, bird.userData.normalScale);
|
|
274
|
+
assert.equal(bird.userData.worn.visible, true);
|
|
275
|
+
const glow = bird.children.find((node) => node.material?.blending === THREE.AdditiveBlending);
|
|
276
|
+
near(glow.material.opacity, 0.32 * 0.2);
|
|
277
|
+
assert(!bird.children.some((n) => n.name === 'companion:hat'));
|
|
278
|
+
bird.traverse((n) => { if (n.material && n.material.blending !== THREE.AdditiveBlending) near(n.material.opacity, 1); });
|
|
279
|
+
const spot = modelView(bird, cam);
|
|
280
|
+
for (let i = 1; i <= 30; i++) {
|
|
281
|
+
const angle = i * Math.PI / 60, radius = 6 - i * 0.1;
|
|
282
|
+
cam.position.set(player.x + radius * Math.sin(angle), player.y + 1 + i * 0.15, player.z + radius * Math.cos(angle));
|
|
283
|
+
player.rotationY += 3; aim(); r.frame(5000 + i * 50);
|
|
284
|
+
const screen = modelView(bird, cam);
|
|
285
|
+
assert(Math.abs(screen.x - spot.x) < 0.015 && Math.abs(screen.y - spot.y) < 0.015);
|
|
286
|
+
const offset = bird.position.clone().sub(cam.position);
|
|
287
|
+
assert(offset.dot(camera().forward) >= cam.near + 0.3 - 1e-9);
|
|
288
|
+
assert(offset.length() <= cam.position.distanceTo(new THREE.Vector3(player.x, player.y, player.z)) - 0.4);
|
|
289
|
+
assertShowAngle(bird, cam, (5000 + i * 50) / 1000);
|
|
290
|
+
}
|
|
291
|
+
const shown = bird.position.clone();
|
|
292
|
+
r.hub.companion = { c: { look: 'bird', dress: { wear: 'bow' } }, n: 4 };
|
|
293
|
+
r.frame(6550); assert(bird.position.distanceTo(shown) < 1);
|
|
294
|
+
assert(bird.position.distanceTo(shown) > 0);
|
|
295
|
+
for (let now = 6600; now <= 12000; now += 50) r.frame(now);
|
|
296
|
+
const follow = Companion.followTarget({ ...player, yaw: player.rotationY * Math.PI / 180 }, null, 12, true);
|
|
297
|
+
assert(bird.position.distanceTo(new THREE.Vector3(follow.x, follow.y, follow.z)) < 0.001);
|
|
298
|
+
near(bird.scale.x, bird.userData.normalScale * 0.7);
|
|
299
|
+
near(glow.material.opacity, 0.32 * 0.5);
|
|
300
|
+
r.drawer.dispose();
|
|
301
|
+
});
|
|
302
|
+
// Project actual transformed vertices, as the town's live stills do.
|
|
303
|
+
function modelView(bird, cam) {
|
|
304
|
+
let top = -Infinity, bottom = Infinity, left = Infinity, right = -Infinity, depth = Infinity;
|
|
305
|
+
const forward = cam.getWorldDirection(new THREE.Vector3());
|
|
306
|
+
bird.updateMatrixWorld(true);
|
|
307
|
+
bird.traverse((node) => {
|
|
308
|
+
const positions = node.geometry?.attributes.position;
|
|
309
|
+
if (!positions) { return; }
|
|
310
|
+
for (let i = 0; i < positions.count; i++) {
|
|
311
|
+
const vertex = new THREE.Vector3().fromBufferAttribute(positions, i).applyMatrix4(node.matrixWorld);
|
|
312
|
+
depth = Math.min(depth, vertex.clone().sub(cam.position).dot(forward));
|
|
313
|
+
const screen = vertex.project(cam);
|
|
314
|
+
if (node.material?.blending === THREE.AdditiveBlending) { continue; }
|
|
315
|
+
top = Math.max(top, screen.y); bottom = Math.min(bottom, screen.y);
|
|
316
|
+
left = Math.min(left, screen.x); right = Math.max(right, screen.x);
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
return { share: (top - bottom) / 2, depth, left: (left + 1) / 2, right: (right + 1) / 2, top: (1 - top) / 2, bottom: (1 - bottom) / 2, x: (left + right + 2) / 4, y: (2 - top - bottom) / 4 };
|
|
320
|
+
}
|
|
321
|
+
function assertShowAngle(bird, cam, seconds) {
|
|
322
|
+
const localCamera = new THREE.Vector3(0, 0, 1).applyQuaternion(cam.quaternion).applyQuaternion(bird.quaternion.clone().invert());
|
|
323
|
+
const yaw = Math.atan2(localCamera.x, localCamera.z) * 180 / Math.PI;
|
|
324
|
+
const elevation = Math.atan2(localCamera.y, Math.hypot(localCamera.x, localCamera.z)) * 180 / Math.PI;
|
|
325
|
+
assert(Math.abs(elevation - 30) < 1e-7, `camera elevation relative to paper: ${elevation}`);
|
|
326
|
+
assert(Math.abs(yaw - (8 + 2 * Math.sin(seconds * Math.PI / 2))) < 1e-7, `camera azimuth relative to paper: ${yaw}`);
|
|
327
|
+
}
|
|
328
|
+
function assertScreenUp(bird, cam) {
|
|
329
|
+
const up = new THREE.Vector3(0, 1, 0).applyQuaternion(bird.quaternion);
|
|
330
|
+
// Project at the bird's off-centre position; a view-plane dot product
|
|
331
|
+
// misses perspective roll. Aspect converts NDC deltas to screen pixels.
|
|
332
|
+
const origin = bird.position.clone().project(cam);
|
|
333
|
+
const tip = bird.position.clone().addScaledVector(up, 0.02).project(cam);
|
|
334
|
+
const roll = Math.abs(Math.atan2((tip.x - origin.x) * cam.aspect, tip.y - origin.y)) * 180 / Math.PI;
|
|
335
|
+
assert(roll <= 10, `${cam.aspect < 1 ? 'portrait' : 'landscape'} FOV ${cam.fov}: projected up axis roll ${roll} degrees`);
|
|
336
|
+
return roll;
|
|
337
|
+
}
|
|
338
|
+
test('every species stays screen upright through the show turn in portrait and landscape at FOV 50, 70 and 90', () => {
|
|
339
|
+
for (const view of [{ w: 412, h: 870 }, { w: 870, h: 412 }]) {
|
|
340
|
+
for (const fov of [50, 70, 90]) {
|
|
341
|
+
let maxRoll = 0;
|
|
342
|
+
for (const species of ['songbird', 'owl', 'parrot', 'hummingbird']) {
|
|
343
|
+
const r = rig(), player = r.local.components.Transform;
|
|
344
|
+
const cam = new THREE.PerspectiveCamera(fov, view.w / view.h, 0.1, 100);
|
|
345
|
+
cam.position.set(player.x, player.y + 4.5, player.z + 6); cam.lookAt(player.x, player.y, player.z); cam.updateMatrixWorld(true);
|
|
346
|
+
r.scene.three.camera = cam;
|
|
347
|
+
r.hub.companion = { c: { look: 'bird', dress: { species, wear: 'tophat' }, pose: 'show' }, n: 2 };
|
|
348
|
+
for (let now = 0; now <= 5000; now += 50) {
|
|
349
|
+
r.frame(now);
|
|
350
|
+
const bird = r.root.children.find((node) => node.name === 'companion:bird');
|
|
351
|
+
maxRoll = Math.max(maxRoll, assertScreenUp(bird, cam));
|
|
352
|
+
assertShowAngle(bird, cam, now / 1000);
|
|
353
|
+
if (now >= 700) {
|
|
354
|
+
const box = modelView(bird, cam), portrait = view.h > view.w;
|
|
355
|
+
assert(box.share <= 0.38, `${species}: fitted height at FOV ${fov}`);
|
|
356
|
+
assert(Math.abs(box.x - (portrait ? 0.27 : 0.35)) < 0.015 && Math.abs(box.y - (portrait ? 0.40 : 0.45)) < 0.015, `${species}: slot at FOV ${fov}`);
|
|
357
|
+
assert(box.left >= 0.04 && box.right <= 0.96 && box.top >= 0.04 && box.bottom <= 0.96, `${species}: inset at FOV ${fov}`);
|
|
358
|
+
if (portrait) {
|
|
359
|
+
const playerScreen = new THREE.Vector3(player.x, player.y, player.z).project(cam);
|
|
360
|
+
assert(box.right <= (playerScreen.x + 1) / 2 - 0.02, `${species}: player margin at FOV ${fov}`);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
r.drawer.dispose();
|
|
365
|
+
}
|
|
366
|
+
console.log(`show up ${view.w}x${view.h} FOV ${fov}: max projected roll ${maxRoll.toFixed(6)} degrees`);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
test('held hummingbird geometry clears near + 0.15 with a horizontal camera 0.801 m from the player', () => {
|
|
371
|
+
const r = rig(), player = r.local.components.Transform;
|
|
372
|
+
const cam = new THREE.PerspectiveCamera(50, 412 / 870, 0.1, 100);
|
|
373
|
+
cam.position.set(player.x, player.y, player.z + 0.801); cam.lookAt(player.x, player.y, player.z); cam.updateMatrixWorld(true);
|
|
374
|
+
r.scene.three.camera = cam;
|
|
375
|
+
r.hub.companion = { c: { look: 'bird', dress: { species: 'hummingbird' }, pose: 'show' }, n: 2 };
|
|
376
|
+
for (let now = 0; now <= 1600; now += 50) {
|
|
377
|
+
r.frame(now);
|
|
378
|
+
const bird = r.root.children.find((n) => n.name === 'companion:bird');
|
|
379
|
+
assert(modelView(bird, cam).depth >= cam.near + 0.15 - 1e-9, 'even approaching, the beak stays clear');
|
|
380
|
+
const offset = bird.position.clone().sub(cam.position);
|
|
381
|
+
assert(offset.dot(cam.getWorldDirection(new THREE.Vector3())) < 0.801, 'held origin stays on the camera side of the player');
|
|
382
|
+
}
|
|
383
|
+
r.drawer.dispose();
|
|
384
|
+
});
|
|
385
|
+
test('town camera shows actual geometry at one third height and completes show flight in 0.7 s at any distance', () => {
|
|
386
|
+
const engine = readFileSync(new URL('../../physics-3d/engine3d/world3d.js', import.meta.url), 'utf8');
|
|
387
|
+
const [, fov, nearPlane, far] = engine.match(/new THREE\.PerspectiveCamera\(([\d.]+), aspect, ([\d.]+), ([\d.]+)\)/);
|
|
388
|
+
for (const species of ['songbird', 'owl', 'parrot', 'hummingbird']) {
|
|
389
|
+
for (const [behind, wear, landscape] of [[6, undefined], [30, undefined], [6, 'tophat'], [6, 'tophat', true], [6, 'sunhat'], [6, 'stampcap'], [6, 'flowercrown'], [6, 'bow'], [6, 'scarf']]) {
|
|
390
|
+
const r = rig(), player = r.local.components.Transform;
|
|
391
|
+
const view = landscape ? { w: 870, h: 412 } : { w: 412, h: 870 };
|
|
392
|
+
const cam = new THREE.PerspectiveCamera(Number(fov), view.w / view.h, Number(nearPlane), Number(far));
|
|
393
|
+
cam.position.set(player.x, player.y + 4.5, player.z + behind); cam.lookAt(player.x, player.y, player.z); cam.updateMatrixWorld(true);
|
|
394
|
+
r.scene.three.camera = cam;
|
|
395
|
+
r.scene.cameraControl = 'orbit';
|
|
396
|
+
r.scene.data = { engine: { camera: { control: 'orbit', follow: 'rigid' } } };
|
|
397
|
+
// Use the actual renderer's lens hook in its real order, after systems.
|
|
398
|
+
const frame = (now) => { r.frame(now); fitOrbitLens(r.scene.three, r.scene); cam.updateMatrixWorld(true); };
|
|
399
|
+
const dress = { species, ...(wear ? { wear } : {}) };
|
|
400
|
+
r.hub.companion = { c: { look: 'bird', dress }, n: 2 }; frame(0);
|
|
401
|
+
r.hub.companion = { c: { look: 'bird', dress, pose: 'show' }, n: 3 };
|
|
402
|
+
for (let now = 50; now <= 700; now += 50) frame(now);
|
|
403
|
+
const bird = r.root.children.find((n) => n.name === 'companion:bird');
|
|
404
|
+
const input = { position: cam.position, forward: cam.getWorldDirection(new THREE.Vector3()), fov: cam.fov, near: cam.near };
|
|
405
|
+
const target = Companion.showTarget(player, input, view, bird.userData.size, bird.userData.radius, bird.userData.showVertices, 0.7);
|
|
406
|
+
assert(bird.position.distanceTo(new THREE.Vector3(target.x, target.y, target.z)) < 1e-9, 'flight completes by 0.7 s regardless of distance');
|
|
407
|
+
for (let now = 750; now <= 1600; now += 50) frame(now);
|
|
408
|
+
const { share, depth } = modelView(bird, cam);
|
|
409
|
+
assert(share >= 0.28 && share <= 0.38, `${species}: actual projected geometry share ${share}`);
|
|
410
|
+
assert(depth >= cam.near + 0.15);
|
|
411
|
+
const offset = bird.position.clone().sub(cam.position);
|
|
412
|
+
const playerOffset = new THREE.Vector3(player.x, player.y, player.z).sub(cam.position);
|
|
413
|
+
assert(offset.dot(input.forward) > 0 && offset.dot(input.forward) < playerOffset.dot(input.forward) - 0.4);
|
|
414
|
+
assert(offset.length() < playerOffset.length() - 0.4);
|
|
415
|
+
const box = modelView(bird, cam);
|
|
416
|
+
assert(Math.abs(box.x - (landscape ? 0.35 : 0.27)) < 0.015 && Math.abs(box.y - (landscape ? 0.45 : 0.40)) < 0.015, `${species}: centre ${box.x}, ${box.y}`);
|
|
417
|
+
assert(box.left >= 0.04 && box.right <= 0.96 && box.top >= 0.04 && box.bottom <= 0.96, `${species}: inset ${JSON.stringify(box)}`);
|
|
418
|
+
if (!landscape) {
|
|
419
|
+
const playerScreen = new THREE.Vector3(player.x, player.y, player.z).project(cam);
|
|
420
|
+
assert(box.right <= (playerScreen.x + 1) / 2 - 0.02, `${species}: fitted box clears the player centre`);
|
|
421
|
+
}
|
|
422
|
+
assertShowAngle(bird, cam, 1.6);
|
|
423
|
+
assertScreenUp(bird, cam);
|
|
424
|
+
if (wear === 'tophat') {
|
|
425
|
+
// Measure the item's real local box, independently of its stored rig dimensions.
|
|
426
|
+
const hat = bird.userData.worn;
|
|
427
|
+
const hatBox = new THREE.Box3();
|
|
428
|
+
hat.traverse((node) => {
|
|
429
|
+
const positions = node.geometry?.attributes.position;
|
|
430
|
+
if (!positions) return;
|
|
431
|
+
for (let i = 0; i < positions.count; i++) hatBox.expandByPoint(new THREE.Vector3().fromBufferAttribute(positions, i).applyMatrix4(node.matrix));
|
|
432
|
+
});
|
|
433
|
+
const hatSize = hatBox.getSize(new THREE.Vector3()).multiplyScalar(bird.userData.normalScale);
|
|
434
|
+
const body = bird.children.find((node) => node.geometry && node.material.blending !== THREE.AdditiveBlending);
|
|
435
|
+
const positions = body.geometry.attributes.position, bodyBox = new THREE.Box3();
|
|
436
|
+
// Songbird's first two triangles are its body; the third is its tail.
|
|
437
|
+
for (let i = 0; i < (species === 'songbird' ? 6 : positions.count); i++) bodyBox.expandByPoint(new THREE.Vector3().fromBufferAttribute(positions, i).applyMatrix4(body.matrix));
|
|
438
|
+
const bodyLength = bodyBox.getSize(new THREE.Vector3()).z * bird.userData.normalScale;
|
|
439
|
+
const head = bird.children.find((node) => node.geometry?.type === 'TetrahedronGeometry');
|
|
440
|
+
const headBox = head ? new THREE.Box3().setFromBufferAttribute(head.geometry.attributes.position) : bodyBox;
|
|
441
|
+
const headWidth = headBox.getSize(new THREE.Vector3()).x * bird.userData.normalScale;
|
|
442
|
+
assert(Math.abs(hatSize.y / bodyLength - 1 / 3) < 0.01);
|
|
443
|
+
assert(hatSize.x / headWidth <= 1.11);
|
|
444
|
+
assert(hat.parent === bird.userData.hatAnchor);
|
|
445
|
+
}
|
|
446
|
+
if (behind === 6 && !landscape && (!wear || wear === 'tophat')) { console.log(`town show ${species}${wear ? '+' + wear : ''}: ${(share * 100).toFixed(2)}% screen height at 1.6 s, FOV ${cam.fov}`); }
|
|
447
|
+
for (let now = 1650; now <= 5600; now += 50) {
|
|
448
|
+
frame(now);
|
|
449
|
+
const turnBox = modelView(bird, cam);
|
|
450
|
+
assert(turnBox.share >= 0.28 && turnBox.share <= 0.38, `${species}+${wear}: turn share ${turnBox.share}`);
|
|
451
|
+
assert(turnBox.left >= 0.04 && turnBox.right <= 0.96 && turnBox.top >= 0.04 && turnBox.bottom <= 0.96, `${species}: whole turn stays inside inset`);
|
|
452
|
+
assert(Math.abs(turnBox.x - (landscape ? 0.35 : 0.27)) < 0.015 && Math.abs(turnBox.y - (landscape ? 0.45 : 0.40)) < 0.015);
|
|
453
|
+
if (!landscape) {
|
|
454
|
+
const playerScreen = new THREE.Vector3(player.x, player.y, player.z).project(cam);
|
|
455
|
+
assert(turnBox.right <= (playerScreen.x + 1) / 2 - 0.02, `${species}: player margin throughout the turn`);
|
|
456
|
+
}
|
|
457
|
+
assertShowAngle(bird, cam, now / 1000);
|
|
458
|
+
assertScreenUp(bird, cam);
|
|
459
|
+
}
|
|
460
|
+
r.drawer.dispose();
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
test('show restores quiet tophat to full scale and opaque paper on its first approach frame, including the orbit lens first frame', () => {
|
|
465
|
+
for (const fov of [undefined, 90]) {
|
|
466
|
+
const r = rig(), player = r.local.components.Transform;
|
|
467
|
+
const cam = new THREE.PerspectiveCamera(50, 412 / 870, 0.1, 100);
|
|
468
|
+
cam.position.set(player.x, player.y + 4.5, player.z + 6); cam.lookAt(player.x, player.y, player.z); cam.updateMatrixWorld(true);
|
|
469
|
+
r.scene.three.camera = cam; r.scene.cameraControl = 'orbit';
|
|
470
|
+
r.scene.data = { engine: { camera: { control: 'orbit', follow: 'rigid', ...(fov ? { fov } : {}) } } };
|
|
471
|
+
r.hub.companion = { c: { look: 'bird', dress: { wear: 'tophat' } }, n: 2 };
|
|
472
|
+
for (let now = 0; now <= 3000; now += 50) r.frame(now);
|
|
473
|
+
const bird = r.root.children.find((n) => n.name === 'companion:bird');
|
|
474
|
+
near(bird.scale.x, bird.userData.normalScale * 0.7);
|
|
475
|
+
bird.traverse((node) => { if (node.material?.blending !== THREE.AdditiveBlending && node.material) near(node.material.opacity, 0.5); });
|
|
476
|
+
r.hub.companion = { c: { look: 'bird', dress: { wear: 'tophat' }, pose: 'show' }, n: 3 };
|
|
477
|
+
// Systems see the original 50-degree lens before render applies orbit FOV.
|
|
478
|
+
for (let now = 3050; now <= 4650; now += 50) {
|
|
479
|
+
r.frame(now); fitOrbitLens(r.scene.three, r.scene);
|
|
480
|
+
near(bird.scale.x, bird.userData.normalScale);
|
|
481
|
+
bird.traverse((node) => {
|
|
482
|
+
if (node.material && node.material.blending !== THREE.AdditiveBlending) {
|
|
483
|
+
near(node.material.opacity, 1); assert.equal(node.material.transparent, false); assert.equal(node.material.depthWrite, true);
|
|
484
|
+
} else if (node.material) {
|
|
485
|
+
assert(node.material.opacity <= 0.32 / 4);
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
assertShowAngle(bird, cam, now / 1000);
|
|
489
|
+
assert(modelView(bird, cam).depth >= cam.near + 0.15);
|
|
490
|
+
}
|
|
491
|
+
const { share } = modelView(bird, cam);
|
|
492
|
+
const minimum = Math.max(cam.near + 0.3, cam.near + 0.15 + bird.userData.radius);
|
|
493
|
+
const heldDepth = bird.position.clone().sub(cam.position).dot(cam.getWorldDirection(new THREE.Vector3()));
|
|
494
|
+
assert(share >= 0.28 || Math.abs(heldDepth - minimum) < 0.001, 'a wider FOV may shrink the fit only at the camera clearance limit');
|
|
495
|
+
r.drawer.dispose();
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
test('restStep waits 1.5 s below 0.2 m/s, resets on movement/target, and is pure', () => {
|
|
499
|
+
const player = { x: 1, y: 1, z: 2 };
|
|
500
|
+
const first = Companion.restStep(null, player, 0.5); assert.equal(first.resting, false);
|
|
501
|
+
const before = { ...first };
|
|
502
|
+
let motion = Companion.restStep(first, player, 0.5); assert.deepEqual(first, before);
|
|
503
|
+
motion = Companion.restStep(motion, player, 0.5); assert.equal(motion.resting, false);
|
|
504
|
+
motion = Companion.restStep(motion, player, 0.5); assert.equal(motion.resting, true);
|
|
505
|
+
assert.equal(Companion.restStep(motion, { ...player, x: 1.11 }, 0.5).still, 0);
|
|
506
|
+
assert.equal(Companion.restStep(motion, { ...player, y: 1.11 }, 0.5).resting, false);
|
|
507
|
+
assert.equal(Companion.restStep(motion, player, 0.5, true).still, 0);
|
|
508
|
+
assert.equal(Companion.restStep(motion, player, -1).still, 0);
|
|
509
|
+
let slow = first;
|
|
510
|
+
for (let i = 1; i <= 3; i++) slow = Companion.restStep(slow, { ...player, x: 1 + i * 0.05 }, 0.5);
|
|
511
|
+
assert.equal(slow.resting, true);
|
|
512
|
+
const shoulder = Companion.followTarget(player, null, 1, true);
|
|
513
|
+
assert.deepEqual(shoulder, { x: 1.28, y: 1.55, z: 2 });
|
|
514
|
+
assert.deepEqual(shoulder, Companion.followTarget(player, null, 2.5, true));
|
|
515
|
+
const turned = Companion.followTarget({ ...player, yaw: Math.PI / 2 }, null, 1, true);
|
|
516
|
+
near(turned.x, 1); near(turned.z, 1.72);
|
|
517
|
+
});
|
|
518
|
+
test('bird rests facing the player without flapping, then lifts off for motion or a target', () => {
|
|
519
|
+
const r = rig(); r.hub.companion.c = { look: 'bird' }; r.local.components.Transform.rotationY = 90;
|
|
520
|
+
for (let i = 0; i <= 60; i++) r.frame(i * 50);
|
|
521
|
+
const bird = r.root.children.find((n) => n.name === 'companion:bird');
|
|
522
|
+
near(bird.rotation.y, Math.PI / 2);
|
|
523
|
+
const wings = bird.children.filter((n) => n.userData.wing);
|
|
524
|
+
for (const wing of wings) near(wing.rotation.z, wing.userData.wing * -0.55);
|
|
525
|
+
r.frame(3250); for (const wing of wings) near(wing.rotation.z, wing.userData.wing * -0.55);
|
|
526
|
+
const at = r.local.components.Transform;
|
|
527
|
+
for (let i = 0; i < 100; i++) r.frame(3300 + i * 50);
|
|
528
|
+
near(bird.position.x, at.x); near(bird.position.y, at.y + 0.55); near(bird.position.z, at.z - 0.28);
|
|
529
|
+
at.x += 0.1; r.frame(8310); assert.notEqual(wings[0].rotation.z, wings[0].userData.wing * -0.55);
|
|
530
|
+
for (let i = 0; i <= 40; i++) r.frame(8400 + i * 50);
|
|
531
|
+
r.hub.companion.c = { look: 'bird', at: 'unknown' }; r.frame(10410);
|
|
532
|
+
assert.notEqual(wings[0].rotation.z, wings[0].userData.wing * -0.55);
|
|
533
|
+
r.drawer.dispose();
|
|
534
|
+
});
|
|
535
|
+
test('step: time-based exponential ease, six-metre snap and arrival placement', () => {
|
|
536
|
+
const a = { x: 0, y: 0, z: 0 }, b = { x: 5, y: 0, z: 0 };
|
|
537
|
+
near(Companion.step(a, b, 0.25).x, 5 * (1 - Math.exp(-1)));
|
|
538
|
+
near(Companion.step(Companion.step(a, b, 0.1), b, 0.15).x, Companion.step(a, b, 0.25).x);
|
|
539
|
+
assert.deepEqual(Companion.step(a, b, 0), a);
|
|
540
|
+
assert.deepEqual(Companion.step(a, b, -1), a);
|
|
541
|
+
assert.deepEqual(Companion.step(null, b, 0), b);
|
|
542
|
+
assert.deepEqual(Companion.step(a, { x: 6.01, y: 0, z: 0 }, 0.01), { x: 6.01, y: 0, z: 0 });
|
|
543
|
+
assert(Companion.step(a, { x: 6, y: 0, z: 0 }, 0.01).x < 6);
|
|
544
|
+
});
|
|
545
|
+
test('leadTarget uses a horizontal ten-metre leash, actor height, a six-second orbit and bob', () => {
|
|
546
|
+
const player = { x: 0, y: 100, z: 0 }, actor = { x: 10, y: 2, z: 0 };
|
|
547
|
+
const lead = Companion.leadTarget(player, actor, 0);
|
|
548
|
+
assert.deepEqual(lead, { x: 10.35, y: 3.1, z: 0 });
|
|
549
|
+
assert.equal(Companion.leadTarget(player, { ...actor, x: 10.01 }, 0), null);
|
|
550
|
+
assert.equal(Companion.leadTarget(player, null, 0), null);
|
|
551
|
+
const opposite = Companion.leadTarget(player, actor, 3);
|
|
552
|
+
near(opposite.x, 9.65); near(opposite.z, 0);
|
|
553
|
+
const lap = Companion.leadTarget(player, actor, 6);
|
|
554
|
+
near(lap.x, lead.x); near(lap.y, lead.y); near(lap.z, lead.z);
|
|
555
|
+
near(Companion.leadTarget(player, actor, 0.5).y, 3.16);
|
|
556
|
+
near(Companion.lookDownPitch(lead, lead), 35 * Math.PI / 180);
|
|
557
|
+
assert.equal(Companion.lookDownPitch(player, lead), 0);
|
|
558
|
+
});
|
|
559
|
+
test('lead and return flights ease across long routes but still snap six metres of drift', () => {
|
|
560
|
+
const start = { x: 0, y: 1, z: 0 }, goal = { x: 10, y: 1, z: 0 };
|
|
561
|
+
const next = Companion.step(start, goal, 0.05, start);
|
|
562
|
+
near(next.x, 10 * (1 - Math.exp(-0.1)));
|
|
563
|
+
assert(Companion.step(next, goal, 0.05, start).x < 2);
|
|
564
|
+
const back = Companion.step(goal, start, 0.05, goal);
|
|
565
|
+
assert(back.x > 9 && back.x < 10);
|
|
566
|
+
assert.deepEqual(Companion.step({ x: 5, y: 1, z: 6.01 }, goal, 0.05, start), goal);
|
|
567
|
+
});
|
|
568
|
+
test('lead phases reach the shared front spot, pause facing the player, ease the turn, then fly', () => {
|
|
569
|
+
const player = { x: 0, y: 1, z: 0, yaw: 0 }, pointAt = { x: 8, y: 0, z: 0 };
|
|
570
|
+
const framing = { camera: { forward: { x: 0, z: -1 } } };
|
|
571
|
+
const input = { id: 'door', player, pointAt, pos: { x: 0.55, y: 1.75, z: -0.35 }, now: 0, framing, dt: 0 };
|
|
572
|
+
let s = Companion.leadStep(null, input);
|
|
573
|
+
assert.equal(s.phase, 'front');
|
|
574
|
+
assert.deepEqual(s.front, Companion.frontTarget(player, framing.camera, 0, undefined, undefined, undefined, 1.5));
|
|
575
|
+
const frozen = structuredClone(s);
|
|
576
|
+
s = Companion.leadStep(s, { ...input, dt: s.duration });
|
|
577
|
+
assert.equal(s.phase, 'pause'); near(s.pos.z, -1.5); near(s.pos.y, 1.85); near(s.yaw, 0);
|
|
578
|
+
assert.equal(frozen.phase, 'front'); near(frozen.elapsed, 0);
|
|
579
|
+
const spot = s.pos;
|
|
580
|
+
s = Companion.leadStep(s, { ...input, dt: 0.59 });
|
|
581
|
+
assert.equal(s.phase, 'pause'); assert.deepEqual(s.pos, spot);
|
|
582
|
+
s = Companion.leadStep(s, { ...input, dt: 0.01 }); assert.equal(s.phase, 'turn');
|
|
583
|
+
s = Companion.leadStep(s, { ...input, dt: 0.2 });
|
|
584
|
+
near(s.yaw, Math.atan2(s.goal.x - s.front.x, s.goal.z - s.front.z) / 2);
|
|
585
|
+
s = Companion.leadStep(s, { ...input, dt: 0.2 }); assert.equal(s.phase, 'fly'); assert.deepEqual(s.pos, spot);
|
|
586
|
+
const start = s.pos;
|
|
587
|
+
s = Companion.leadStep(s, { ...input, dt: 0.1 });
|
|
588
|
+
near(Math.hypot(s.pos.x - start.x, s.pos.y - start.y, s.pos.z - start.z), 0.3);
|
|
589
|
+
const fallback = Companion.leadStep(null, { ...input, framing: null, player: { ...player, yaw: Math.PI / 2 } });
|
|
590
|
+
near(fallback.front.x, 1.5); near(fallback.front.z, 0);
|
|
591
|
+
});
|
|
592
|
+
test('lead legs take one second for 3 m and three for 9 m, cap at four, and never snap', () => {
|
|
593
|
+
const player = { x: 0, y: 1, z: 0 }, pointAt = { x: 9, y: 0, z: 0 };
|
|
594
|
+
const input = { id: 'door', player, pointAt, now: 0, dt: 0 };
|
|
595
|
+
for (const length of [3, 9, 30]) {
|
|
596
|
+
const front = { x: 0, y: 1, z: 0, yaw: 0 }, goal = { x: length, y: 1, z: 0 };
|
|
597
|
+
let s = { id: 'door', player, phase: 'turn', elapsed: 0, duration: 0.4, front, goal, pos: front, yaw: 0 };
|
|
598
|
+
s = Companion.leadStep(s, { ...input, dt: 0.4 });
|
|
599
|
+
near(s.duration, Math.min(length / 3, 4)); assert.equal(s.phase, 'fly');
|
|
600
|
+
const next = Companion.leadStep(s, { ...input, dt: 0.1 });
|
|
601
|
+
near(next.pos.x, length / s.duration * 0.1); assert(next.pos.x < length);
|
|
602
|
+
const split = Companion.leadStep(next, { ...input, dt: 0.2 });
|
|
603
|
+
const whole = Companion.leadStep(s, { ...input, dt: 0.3 });
|
|
604
|
+
near(split.pos.x, whole.pos.x);
|
|
605
|
+
const arrived = Companion.leadStep(s, { ...input, dt: s.duration });
|
|
606
|
+
assert.equal(arrived.phase, 'hover'); near(arrived.pos.x, length);
|
|
607
|
+
}
|
|
608
|
+
const farStart = Companion.leadStep(null, { ...input, pos: { x: -20, y: 1, z: 0 }, dt: 0.01 });
|
|
609
|
+
assert(farStart.pos.x < -19, 'the six-metre snap never runs even on the front leg');
|
|
610
|
+
let route = Companion.leadStep(null, input);
|
|
611
|
+
const total = route.duration + 1 + Math.hypot(route.goal.x - route.front.x, route.goal.y - route.front.y, route.goal.z - route.front.z) / 3;
|
|
612
|
+
const one = Companion.leadStep(route, { ...input, dt: total });
|
|
613
|
+
for (let i = 0; i < 100; i++) route = Companion.leadStep(route, { ...input, dt: total / 100 });
|
|
614
|
+
near(route.pos.x, one.pos.x); near(route.pos.z, one.pos.z);
|
|
615
|
+
});
|
|
616
|
+
test('every lead phase aborts on chat, walk-away, a lost target or an ended lead', () => {
|
|
617
|
+
const player = { x: 0, y: 1, z: 0 }, pointAt = { x: 8, y: 0, z: 0 };
|
|
618
|
+
const input = { id: 'door', player, pointAt, now: 0, dt: 0 };
|
|
619
|
+
let s = Companion.leadStep(null, input);
|
|
620
|
+
for (const phase of ['front', 'pause', 'turn', 'fly', 'hover']) {
|
|
621
|
+
const previous = { ...s, phase };
|
|
622
|
+
assert.equal(Companion.leadStep(previous, { ...input, chatting: true }), null);
|
|
623
|
+
assert.equal(Companion.leadStep(previous, { ...input, player: { ...player, x: 7 } }), null);
|
|
624
|
+
assert.equal(Companion.leadStep(previous, { ...input, pointAt: { ...pointAt, x: 10.01 } }), null);
|
|
625
|
+
assert.equal(Companion.leadStep(previous, { ...input, pointAt: null }), null);
|
|
626
|
+
assert.equal(Companion.leadStep(previous, { ...input, id: null }), null);
|
|
627
|
+
}
|
|
628
|
+
const switched = Companion.leadStep(s, { ...input, id: 'other' });
|
|
629
|
+
assert.equal(switched.phase, 'front'); assert.equal(switched.id, 'other');
|
|
630
|
+
});
|
|
631
|
+
test('hat uses the target component, wears for three seconds, falls/fades, and only repeats on a new visit', () => {
|
|
632
|
+
assert(Companion.isHatStall({ components: { TownHats: { district: 'sunny' } } }));
|
|
633
|
+
assert(!Companion.isHatStall({ id: 'TownHats', components: { TownHatMat: {} } }));
|
|
634
|
+
let s = Companion.hatStep(null, 'stall', 1000); assert.equal(s.phase, 'on');
|
|
635
|
+
const frozen = { ...s };
|
|
636
|
+
s = Companion.hatStep(s, 'stall', 3999); assert.equal(s.phase, 'on');
|
|
637
|
+
s = Companion.hatStep(s, null, 4000); assert.equal(s.phase, 'drop'); near(s.opacity, 1);
|
|
638
|
+
s = Companion.hatStep(s, 'stall', 4300); near(s.drop, 0.3); near(s.opacity, 0.5);
|
|
639
|
+
s = Companion.hatStep(s, 'stall', 4600); assert.equal(s.phase, 'done'); near(s.opacity, 0);
|
|
640
|
+
assert.equal(Companion.hatStep(s, 'stall', 9000).phase, 'done');
|
|
641
|
+
assert.equal(Companion.hatStep(s, null, 9000), null);
|
|
642
|
+
assert.equal(Companion.hatStep(null, 'stall', 9001).phase, 'on');
|
|
643
|
+
assert.deepEqual(frozen, { id: 'stall', since: 1000, phase: 'on', drop: 0, opacity: 1 });
|
|
644
|
+
});
|
|
645
|
+
test('stamp twirl is a pure one-second spin/hop/pulse, drops cooldown events, and does not queue them', () => {
|
|
646
|
+
let s = Companion.twirlStep(null, 0, 0); assert(!s.active);
|
|
647
|
+
s = Companion.twirlStep(s, 1, 1000); assert(s.active);
|
|
648
|
+
const frozen = { ...s };
|
|
649
|
+
s = Companion.twirlStep(s, 1, 1500); near(s.yaw, Math.PI); near(s.hop, 0.25); near(s.pulse, 1);
|
|
650
|
+
assert.equal(frozen.yaw, 0);
|
|
651
|
+
s = Companion.twirlStep(s, 1, 2000); assert(!s.active);
|
|
652
|
+
s = Companion.twirlStep(s, 2, 10_999); assert(!s.active);
|
|
653
|
+
s = Companion.twirlStep(s, 2, 11_000); assert(!s.active, 'suppressed cue stays consumed');
|
|
654
|
+
s = Companion.twirlStep(s, 3, 11_000); assert(s.active);
|
|
655
|
+
assert(Companion.ownStamp({ k: 'hub-cue', cue: 'stamp' }));
|
|
656
|
+
assert(!Companion.ownStamp({ k: 'hub-cue', cue: 'stamp', actor: 'other-player' }));
|
|
657
|
+
assert(!Companion.ownStamp({ k: 'hub-cue', cue: 'hat-on' }));
|
|
658
|
+
});
|
|
659
|
+
test('busy, twirl, and hat all keep the companion non-quiet without an at or line', () => {
|
|
660
|
+
assert(Companion.isQuiet({}));
|
|
661
|
+
for (const key of ['at', 'line', 'busy', 'talking', 'hat', 'twirl']) assert(!Companion.isQuiet({ [key]: true }), key);
|
|
662
|
+
});
|
|
663
|
+
test('quietStep is pure, exponentially eases size/opacity and restores both within half a second', () => {
|
|
664
|
+
const initial = { scale: 1, opacity: 1 };
|
|
665
|
+
const quiet = Companion.quietStep(initial, true, 0.15);
|
|
666
|
+
near(quiet.scale, 0.7 + 0.3 * Math.exp(-1)); near(quiet.opacity, 0.5 + 0.5 * Math.exp(-1));
|
|
667
|
+
assert.deepEqual(initial, { scale: 1, opacity: 1 });
|
|
668
|
+
assert.deepEqual(Companion.quietStep(initial, true, -1), initial);
|
|
669
|
+
assert.deepEqual(Companion.quietStep(initial, true, 1), { scale: 0.7, opacity: 0.5 });
|
|
670
|
+
assert.deepEqual(Companion.quietStep({ scale: 0.7, opacity: 0.5 }, false, 0.5), initial);
|
|
671
|
+
});
|
|
672
|
+
test('quiet shoulder, chat/tap busy state, timed line and target apply to every follower material', () => {
|
|
673
|
+
const r = rig(); r.hub.companion = { c: { look: 'bird' }, n: 2 };
|
|
674
|
+
for (let i = 0; i <= 60; i++) r.frame(i * 50);
|
|
675
|
+
const bird = r.root.children.find((n) => n.name === 'companion:bird');
|
|
676
|
+
near(bird.scale.x, 2.2 * 0.7);
|
|
677
|
+
for (const child of bird.children.filter((n) => n.material)) {
|
|
678
|
+
assert(child.material.transparent); assert.equal(child.material.depthWrite, false);
|
|
679
|
+
near(child.material.opacity, child.material.blending === THREE.AdditiveBlending ? 0.16 : 0.5);
|
|
680
|
+
}
|
|
681
|
+
for (let i = 1; i <= 10; i++) r.frame(3000 + i * 50, true, true);
|
|
682
|
+
near(bird.scale.x, 2.2);
|
|
683
|
+
for (const child of bird.children.filter((n) => n.material)) {
|
|
684
|
+
const glow = child.material.blending === THREE.AdditiveBlending;
|
|
685
|
+
near(child.material.opacity, glow ? 0.32 : 1);
|
|
686
|
+
assert.equal(child.material.transparent, glow); assert.equal(child.material.depthWrite, !glow);
|
|
687
|
+
}
|
|
688
|
+
for (let i = 1; i <= 20; i++) r.frame(3500 + i * 50);
|
|
689
|
+
r.hub.companion = { c: { look: 'bird', say: 'Look!' }, n: 3 };
|
|
690
|
+
for (let i = 1; i <= 10; i++) r.frame(4500 + i * 50);
|
|
691
|
+
near(bird.scale.x, 2.2);
|
|
692
|
+
for (let t = 5050; t <= 9500; t += 50) r.frame(t);
|
|
693
|
+
near(bird.scale.x, 2.2 * 0.7);
|
|
694
|
+
r.hub.companion = { c: { look: 'bird', at: 'unknown' }, n: 4 };
|
|
695
|
+
for (let i = 1; i <= 10; i++) r.frame(9500 + i * 50);
|
|
696
|
+
near(bird.scale.x, 2.2); r.drawer.dispose();
|
|
697
|
+
});
|
|
698
|
+
test('follower flies out and home without snapping, looks down in orbit, and recovers a player teleport', () => {
|
|
699
|
+
const r = rig(); r.hub.companion = { c: { look: 'bird' }, n: 2 }; r.frame();
|
|
700
|
+
const bird = r.root.children.find((n) => n.name === 'companion:bird');
|
|
701
|
+
const actor = { x: 11, y: 0, z: 3 };
|
|
702
|
+
r.scene.getActor = () => ({ components: { Transform: actor } });
|
|
703
|
+
r.hub.companion = { c: { look: 'bird', at: 'goal' }, n: 3 };
|
|
704
|
+
const before = bird.position.clone(); r.frame(50);
|
|
705
|
+
assert(bird.position.distanceTo(before) < 1); assert(bird.position.x < 4);
|
|
706
|
+
near(bird.rotation.y, Math.atan2(bird.position.x - before.x, bird.position.z - before.z));
|
|
707
|
+
for (let t = 100; t <= 6000; t += 50) r.frame(t);
|
|
708
|
+
assert(Math.abs(bird.rotation.x - 35 * Math.PI / 180) < 1e-3);
|
|
709
|
+
assert(bird.children.filter((n) => n.userData.wing).every((n) => n.rotation.z !== n.userData.wing * -0.55));
|
|
710
|
+
r.hub.companion = { c: { look: 'bird' }, n: 4 };
|
|
711
|
+
const over = bird.position.clone(); r.frame(6050);
|
|
712
|
+
assert(bird.position.distanceTo(over) < 1); assert(bird.position.x > 9);
|
|
713
|
+
for (let t = 6100; t <= 9000; t += 50) r.frame(t);
|
|
714
|
+
assert(bird.position.x < 3);
|
|
715
|
+
r.local.components.Transform.x += 100; r.frame(9050);
|
|
716
|
+
assert(bird.position.x > 100); r.drawer.dispose();
|
|
717
|
+
});
|
|
718
|
+
test('an initial lead flies from the player; crossing the leash returns to the distant pointing offset', () => {
|
|
719
|
+
const r = rig(); r.hub.companion = { c: { look: 'bird', at: 'goal' }, n: 2 };
|
|
720
|
+
const actor = { x: 11, y: 0, z: 3 };
|
|
721
|
+
r.scene.getActor = () => ({ components: { Transform: actor } }); r.frame();
|
|
722
|
+
const bird = r.root.children.find((n) => n.name === 'companion:bird');
|
|
723
|
+
assert(bird.position.x < 2.55 && bird.position.x > 2);
|
|
724
|
+
assert(bird.position.z > 2.65, 'first leg goes in front of the player, away from the goal');
|
|
725
|
+
for (let t = 50; t <= 3000; t += 50) r.frame(t);
|
|
726
|
+
actor.x = 13;
|
|
727
|
+
const over = bird.position.clone(); r.frame(3050);
|
|
728
|
+
assert(bird.position.distanceTo(over) < 1);
|
|
729
|
+
for (let t = 3100; t <= 9000; t += 50) r.frame(t);
|
|
730
|
+
assert(Math.abs(bird.position.x - 2.9) < 1e-8);
|
|
731
|
+
assert(Math.abs(bird.rotation.x) < 1e-8); r.drawer.dispose();
|
|
732
|
+
});
|
|
733
|
+
test('rendered hat attaches at the stall, stays non-quiet on return, drops in world space, fades and disposes', () => {
|
|
734
|
+
const r = rig(); r.hub.companion = { c: { look: 'bird', at: 'stall' }, n: 2 };
|
|
735
|
+
r.scene.getActor = () => ({ components: { Transform: { x: 3, y: 0, z: 3 }, TownHats: { district: 'sunny' } } });
|
|
736
|
+
let hat, started;
|
|
737
|
+
for (let now = 0; now <= 5000; now += 50) {
|
|
738
|
+
r.frame(now);
|
|
739
|
+
const bird = r.root.children.find((n) => n.name === 'companion:bird');
|
|
740
|
+
hat = bird.children.find((n) => n.name === 'companion:hat');
|
|
741
|
+
if (hat) { started = now; break; }
|
|
742
|
+
}
|
|
743
|
+
assert(hat); const bird = hat.parent; assert.equal(bird.name, 'companion:bird');
|
|
744
|
+
assert(Math.hypot(bird.position.x - 3, bird.position.z - 3) < 0.5);
|
|
745
|
+
near(bird.scale.x, 2.2);
|
|
746
|
+
let disposed = 0;
|
|
747
|
+
hat.traverse((n) => { n.geometry?.addEventListener('dispose', () => disposed++); n.material?.addEventListener('dispose', () => disposed++); });
|
|
748
|
+
r.hub.companion = { c: { look: 'bird' }, n: 3 };
|
|
749
|
+
for (let now = started + 50; now < started + 3000; now += 50) r.frame(now);
|
|
750
|
+
assert.equal(hat.parent, bird); near(bird.scale.x, 2.2);
|
|
751
|
+
r.frame(started + 3000); assert.equal(hat.parent, r.root);
|
|
752
|
+
const dropFrom = hat.position.clone();
|
|
753
|
+
r.frame(started + 3300); assert(hat.position.y < dropFrom.y);
|
|
754
|
+
for (const mesh of hat.children) near(mesh.material.opacity, 0.5);
|
|
755
|
+
r.frame(started + 3350, false); assert.equal(hat.visible, false, 'detached hat hides during a trip too');
|
|
756
|
+
r.frame(started + 3400); assert.equal(hat.visible, true);
|
|
757
|
+
r.frame(started + 3600); assert.equal(hat.parent, null); assert.equal(disposed, 4);
|
|
758
|
+
r.drawer.dispose();
|
|
759
|
+
});
|
|
760
|
+
test('private stamp hook triggers only this follower, ignores public cues and keyless worlds, and works when muted', () => {
|
|
761
|
+
State.clear(); State.hub.place = { companion: true };
|
|
762
|
+
hook.message({}, { k: 'hub-companion', c: { look: 'bird' }, n: 1 });
|
|
763
|
+
const r = rig(), other = rig(); r.hub.companion = State.hub.companion;
|
|
764
|
+
other.hub.companion = { c: { look: 'bird' }, n: 1 };
|
|
765
|
+
for (let now = 0; now <= 3000; now += 50) { r.frame(now); other.frame(now); }
|
|
766
|
+
const bird = r.root.children.find((n) => n.name === 'companion:bird');
|
|
767
|
+
const remote = other.root.children.find((n) => n.name === 'companion:bird');
|
|
768
|
+
State.hub.soundGate = () => false;
|
|
769
|
+
hook.message({}, { k: 'hub-cue', cue: 'stamp', actor: 'other-player', radius: 12 });
|
|
770
|
+
assert(!Object.hasOwn(State.hub.companion, 'stamps'));
|
|
771
|
+
hook.message({}, { k: 'hub-cue', cue: 'stamp' });
|
|
772
|
+
assert.equal(State.hub.companion.stamps, 1);
|
|
773
|
+
r.frame(3100); other.frame(3100); near(bird.scale.x, 2.2); near(remote.scale.x, 2.2 * 0.7);
|
|
774
|
+
for (const mesh of bird.children.filter((n) => n.material)) near(mesh.material.opacity, mesh.material.blending === THREE.AdditiveBlending ? 0.32 : 1);
|
|
775
|
+
r.frame(3600); near(bird.rotation.y, Math.PI);
|
|
776
|
+
const glow = bird.children.find((n) => n.material.blending === THREE.AdditiveBlending);
|
|
777
|
+
assert(glow.scale.x > 1); assert(glow.material.opacity > 0.32);
|
|
778
|
+
r.frame(4100); near(bird.rotation.y, 0); near(glow.scale.x, 1);
|
|
779
|
+
hook.message({}, { k: 'hub-companion', c: { look: 'bird' }, n: 2 });
|
|
780
|
+
assert.equal(State.hub.companion.stamps, 1, 'ordinary spec updates retain the private event history');
|
|
781
|
+
r.hub.companion = State.hub.companion;
|
|
782
|
+
hook.message({}, { k: 'hub-cue', cue: 'stamp' }); r.frame(4200); assert(bird.scale.x < 2.2);
|
|
783
|
+
hook.state({}, { hubPlace: { id: 'plain' } });
|
|
784
|
+
const before = Object.keys(State.hub);
|
|
785
|
+
hook.message({}, { k: 'hub-cue', cue: 'stamp' });
|
|
786
|
+
assert.deepEqual(Object.keys(State.hub), before); assert(!Object.hasOwn(State.hub, 'companion'));
|
|
787
|
+
r.drawer.dispose(); other.drawer.dispose(); delete State.hub.soundGate; State.clear();
|
|
788
|
+
});
|
|
789
|
+
test('walk-away within the target leash aborts once, and any chat returns home before a fresh route', () => {
|
|
790
|
+
const r = rig(); r.hub.place.companionChat = { name: 'Chirp' }; r.hub.companion = { c: { look: 'bird', at: 'door' }, n: 2 };
|
|
791
|
+
r.scene.getActor = () => ({ components: { Transform: { x: 10, y: 0, z: 3 } } });
|
|
792
|
+
for (let now = 0; now <= 2000; now += 50) r.frame(now);
|
|
793
|
+
const bird = r.root.children.find((n) => n.name === 'companion:bird');
|
|
794
|
+
const chat = { camera: { forward: { x: 0, z: -1 } } };
|
|
795
|
+
r.drawer.frame(r.scene, r.local, r.hub, 0.05, 2050, true, chat);
|
|
796
|
+
for (let now = 2100; now <= 4000; now += 50) r.drawer.frame(r.scene, r.local, r.hub, 0.05, now, true, chat);
|
|
797
|
+
assert(Math.abs(bird.position.z - 1.7) < 0.05); assert(Math.abs(bird.rotation.y) < 0.01);
|
|
798
|
+
r.frame(4050); const chatSpot = bird.position.clone(); assert(chatSpot.z < 2, 'new lead starts at the shared front spot');
|
|
799
|
+
for (let now = 4100; now <= 7600; now += 50) { r.local.components.Transform.x += 0.1; r.frame(now); }
|
|
800
|
+
const player = r.local.components.Transform;
|
|
801
|
+
for (let now = 7650; now <= 10_000; now += 50) r.frame(now);
|
|
802
|
+
assert(Math.hypot(bird.position.x - player.x, bird.position.z - player.z) < 1, 'walk-away does not restart the same lead every other frame');
|
|
803
|
+
r.drawer.dispose();
|
|
804
|
+
});
|
|
805
|
+
test('sayMs counts code points and caps long lines', () => {
|
|
806
|
+
assert.equal(Companion.sayMs('Hi'), 3610);
|
|
807
|
+
assert.equal(Companion.sayMs('😀'), 3555);
|
|
808
|
+
assert.equal(Companion.sayMs('x'.repeat(80)), 7900);
|
|
809
|
+
assert.equal(Companion.sayMs('x'.repeat(200)), 9000);
|
|
810
|
+
});
|
|
811
|
+
test('private messages before WORLD, public Set, absent-key cleanup and clear', () => {
|
|
812
|
+
State.clear();
|
|
813
|
+
assert(!Object.hasOwn(State.hub, 'companion')); assert(!Object.hasOwn(State.hub, 'glow'));
|
|
814
|
+
hook.message({}, { k: 'hub-companion', c: spec, n: 1 }); assert.deepEqual(State.hub.companion, { c: spec, n: 1 });
|
|
815
|
+
hook.state({}, { hubPlace: { id: 'main', companion: true }, hubGlow: ['p2'] });
|
|
816
|
+
assert.deepEqual(State.hub.companion, { c: spec, n: 1 }); assert.deepEqual(State.hub.glow, new Set(['p2']));
|
|
817
|
+
hook.state({}, { hubGlow: [] }); assert.deepEqual(State.hub.glow, new Set());
|
|
818
|
+
hook.message({}, { k: 'hub-companion', c: { look: 'bad' }, n: 2 }); assert.deepEqual(State.hub.companion, { c: null, n: 2 });
|
|
819
|
+
hook.state({}, { hubPlace: { id: 'plain' }, hubGlow: ['p2'] });
|
|
820
|
+
hook.message({}, { k: 'hub-companion', c: spec, n: 3 });
|
|
821
|
+
assert(!Object.hasOwn(State.hub, 'companion')); assert(!Object.hasOwn(State.hub, 'glow'));
|
|
822
|
+
hook.state({}, { hubPlace: { id: 'main', companion: true }, hubGlow: ['p2'] });
|
|
823
|
+
hook.state({}, { hubPlace: { id: 'main', companion: true } }); assert(!Object.hasOwn(State.hub, 'glow'));
|
|
824
|
+
hook.message({}, { k: 'hub-companion', c: spec, n: 4 }); State.clear();
|
|
825
|
+
assert(!Object.hasOwn(State.hub, 'companion')); assert(!Object.hasOwn(State.hub, 'glow'));
|
|
826
|
+
});
|
|
827
|
+
test('lantern and bird: under 40 triangles, unlit, no textures/lights/shadows; disposal', () => {
|
|
828
|
+
for (const look of ['lantern', 'bird']) {
|
|
829
|
+
const r = rig(); r.hub.companion.c = { ...spec, look }; r.frame();
|
|
830
|
+
const follower = r.root.children.find((n) => n.name === `companion:${look}`);
|
|
831
|
+
assert(follower); assert.equal(follower.parent, r.root); assert(!r.own.children.length);
|
|
832
|
+
let triangles = 0, disposed = 0, resources = 0;
|
|
833
|
+
follower.traverse((node) => {
|
|
834
|
+
assert(!node.isLight);
|
|
835
|
+
if (node.isMesh) {
|
|
836
|
+
assert(node.material.isMeshBasicMaterial); assert.equal(node.material.map, null);
|
|
837
|
+
assert.equal(node.castShadow, false); assert.equal(node.receiveShadow, false);
|
|
838
|
+
triangles += (node.geometry.index?.count ?? node.geometry.attributes.position.count) / 3;
|
|
839
|
+
for (const resource of [node.geometry, node.material]) { resources++; resource.addEventListener('dispose', () => disposed++); }
|
|
840
|
+
if (node.material.blending === THREE.AdditiveBlending) assert.equal(node.material.depthWrite, false);
|
|
841
|
+
}
|
|
842
|
+
});
|
|
843
|
+
assert(triangles < 40); if (look === 'bird') { assert.equal(triangles, 16); near(follower.scale.x, 2.2); assert(follower.children.some((n) => n.material?.color.getHexString() === 'f2a65a')); }
|
|
844
|
+
r.drawer.dispose(); assert.equal(disposed, resources); assert.equal(r.root.children.length, 2); assert.equal(r.other.children.length, 0);
|
|
845
|
+
}
|
|
846
|
+
});
|
|
847
|
+
test('v1.78 species rig, wearable/tint and dress rebuild disposal', () => {
|
|
848
|
+
for (const species of ['songbird', 'owl', 'parrot', 'hummingbird']) {
|
|
849
|
+
const r = rig(); r.hub.companion.c = { look: 'bird', dress: { species, wear: 'bow', tint: 'mint' } }; r.frame();
|
|
850
|
+
const bird = r.root.children.find((n) => n.name === 'companion:bird');
|
|
851
|
+
const wings = bird.children.filter((n) => n.userData.wing);
|
|
852
|
+
assert.equal(wings.length, 2);
|
|
853
|
+
assert.deepEqual(new Set(wings.map((n) => n.userData.wing)), new Set([-1, 1]));
|
|
854
|
+
assert(bird.userData.hatAnchor); assert(bird.userData.worn); assert.equal(bird.userData.normalScale, 2.2);
|
|
855
|
+
let resources = 0, disposed = 0;
|
|
856
|
+
bird.traverse((n) => { for (const resource of [n.geometry, n.material].filter(Boolean)) { resources++; resource.addEventListener('dispose', () => disposed++); } });
|
|
857
|
+
r.hub.companion = { c: { look: 'bird', dress: { species, wear: 'scarf' } }, n: 2 }; r.frame(50);
|
|
858
|
+
assert.equal(disposed, resources); assert.equal(bird.parent, null);
|
|
859
|
+
r.drawer.dispose();
|
|
860
|
+
const base = Companion.build('bird', { species });
|
|
861
|
+
let triangles = 0;
|
|
862
|
+
base.traverse((n) => { if (n.geometry) { triangles += (n.geometry.index?.count ?? n.geometry.attributes.position.count) / 3; } });
|
|
863
|
+
assert(triangles <= 40, `${species}: ${triangles}`);
|
|
864
|
+
console.log(`species ${species}: ${triangles} triangles`);
|
|
865
|
+
base.traverse((n) => { n.geometry?.dispose(); n.material?.dispose(); });
|
|
866
|
+
}
|
|
867
|
+
assert.equal(Companion.sanitise({ look: 'bird', dress: { wear: 'bad' } }), null);
|
|
868
|
+
for (const wear of ['tophat', 'sunhat', 'bow', 'scarf', 'stampcap', 'flowercrown']) {
|
|
869
|
+
const r = rig(); r.hub.companion.c = { look: 'bird', dress: { wear } }; r.frame();
|
|
870
|
+
assert(r.root.children.find((n) => n.name === 'companion:bird').userData.worn);
|
|
871
|
+
r.drawer.dispose();
|
|
872
|
+
}
|
|
873
|
+
});
|
|
874
|
+
test('v1.78 every species and accessory joins quiet opacity and hides during hat try-on', () => {
|
|
875
|
+
for (const species of ['songbird', 'owl', 'parrot', 'hummingbird']) {
|
|
876
|
+
const r = rig(), dress = { species, wear: 'flowercrown', tint: 'midnight' };
|
|
877
|
+
r.hub.companion = { c: { look: 'bird', dress }, n: 2 };
|
|
878
|
+
for (let now = 0; now <= 3000; now += 50) r.frame(now);
|
|
879
|
+
const bird = r.root.children.find((n) => n.name === 'companion:bird');
|
|
880
|
+
near(bird.scale.x, 2.2 * 0.7);
|
|
881
|
+
bird.traverse((n) => { if (n.material) { near(n.material.opacity, n.material.blending === THREE.AdditiveBlending ? 0.16 : 0.5); } });
|
|
882
|
+
const glow = bird.children.find((n) => n.material?.blending === THREE.AdditiveBlending);
|
|
883
|
+
assert.equal(glow.material.color.getHexString(), 'ffd27a', 'tint leaves the glow warm');
|
|
884
|
+
assert(bird.children.some((n) => n.material?.color.getHexString() === '39436b'), 'main paper is tinted');
|
|
885
|
+
r.hub.companion = { c: { look: 'bird', dress, at: 'stall' }, n: 3 };
|
|
886
|
+
r.scene.getActor = () => ({ components: { Transform: { x: 3, y: 0, z: 3 }, TownHats: { district: 'sunny' } } });
|
|
887
|
+
let started;
|
|
888
|
+
for (let now = 3050; now <= 9000; now += 50) {
|
|
889
|
+
r.frame(now);
|
|
890
|
+
if (bird.children.some((n) => n.name === 'companion:hat')) { started = now; break; }
|
|
891
|
+
}
|
|
892
|
+
assert(started); assert.equal(bird.userData.worn.visible, false);
|
|
893
|
+
r.hub.companion = { c: { look: 'bird', dress }, n: 4 };
|
|
894
|
+
for (let now = started + 50; now <= started + 3650; now += 50) r.frame(now);
|
|
895
|
+
assert.equal(bird.userData.worn.visible, true);
|
|
896
|
+
r.drawer.dispose();
|
|
897
|
+
}
|
|
898
|
+
});
|
|
899
|
+
test('show immediately hides an existing try-on hat and restores the worn item for every species', () => {
|
|
900
|
+
for (const species of ['songbird', 'owl', 'parrot', 'hummingbird']) {
|
|
901
|
+
const r = rig(), dress = { species, wear: 'tophat' };
|
|
902
|
+
const cam = new THREE.PerspectiveCamera(50, 412 / 870, 0.1, 100);
|
|
903
|
+
cam.position.set(2, 2, 9); cam.lookAt(2, 1, 3); cam.updateMatrixWorld(true);
|
|
904
|
+
r.scene.three.camera = cam;
|
|
905
|
+
r.scene.getActor = () => ({ components: { Transform: { x: 3, y: 0, z: 3 }, TownHats: {} } });
|
|
906
|
+
r.hub.companion = { c: { look: 'bird', dress, at: 'stall' }, n: 2 };
|
|
907
|
+
let hat, bird, started;
|
|
908
|
+
for (let now = 0; now <= 5000; now += 50) {
|
|
909
|
+
r.frame(now); bird = r.root.children.find((n) => n.name === 'companion:bird');
|
|
910
|
+
hat = bird.children.find((n) => n.name === 'companion:hat');
|
|
911
|
+
if (hat) { started = now; break; }
|
|
912
|
+
}
|
|
913
|
+
assert(hat); assert.equal(bird.userData.worn.visible, false);
|
|
914
|
+
r.hub.companion = { c: { look: 'bird', dress, at: 'stall', pose: 'show' }, n: 3 };
|
|
915
|
+
r.frame(started + 50);
|
|
916
|
+
assert.equal(hat.parent, null); assert.equal(bird.userData.worn.visible, true);
|
|
917
|
+
near(bird.scale.x, bird.userData.normalScale);
|
|
918
|
+
r.drawer.dispose();
|
|
919
|
+
}
|
|
920
|
+
});
|
|
921
|
+
test('owner-only timed bubble uses existing textContent chrome, repeats on new words or a fresh attach, not on a new target', () => {
|
|
922
|
+
const r = rig(); r.frame();
|
|
923
|
+
const labels = r.labels(); assert.equal(labels.length, 1); assert.equal(labels[0].text, spec.say);
|
|
924
|
+
const dom = fakeDom({ viewW: 360, viewH: 780 }), chrome = makeChrome({ avatarCount: 4, onBack() {}, onAvatar() {} });
|
|
925
|
+
chrome.setLabels(labels);
|
|
926
|
+
const bubble = dom.made.find((node) => node.textContent === spec.say);
|
|
927
|
+
assert(bubble); assert.equal(bubble.tag, 'div'); assert(!Object.hasOwn(bubble.attrs, 'tabindex'));
|
|
928
|
+
for (let n = bubble; n; n = n.parent) assert.notEqual(n.style.pointerEvents, 'auto');
|
|
929
|
+
r.hub.companion = { c: { ...spec }, n: 1 }; r.frame(1000);
|
|
930
|
+
assert.equal(r.labels(Companion.sayMs(spec.say)).length, 0);
|
|
931
|
+
// A new target alone does not say the expired line again; new words do,
|
|
932
|
+
// and so does a follower attached afresh (a reconnect).
|
|
933
|
+
r.hub.companion = { c: { ...spec, at: 'pad' }, n: 2 }; r.frame(8000); assert.equal(r.labels(8000).length, 0);
|
|
934
|
+
r.hub.companion = { c: { ...spec, say: 'This way!' }, n: 3 }; r.frame(8050); assert.equal(r.labels(8050)[0].text, 'This way!');
|
|
935
|
+
delete r.hub.companion; r.frame(8060);
|
|
936
|
+
r.hub.companion = { c: { ...spec, say: 'This way!' }, n: 3 }; r.frame(20000); assert.equal(r.labels(20000).length, 1);
|
|
937
|
+
r.hub.companion = { c: { look: 'bird' }, n: 4 }; r.frame(20100); assert.deepEqual(r.labels(20100), []);
|
|
938
|
+
chrome.dispose(); r.drawer.clear();
|
|
939
|
+
});
|
|
940
|
+
test('the current line is said again once after a dropped connection or a hidden page, and not by ordinary frames', () => {
|
|
941
|
+
const r = rig(); let state = 'connected';
|
|
942
|
+
r.scene.multiplayer.net.status = () => ({ state });
|
|
943
|
+
r.frame(0); const ms = Companion.sayMs(spec.say);
|
|
944
|
+
for (let t = 1000; t <= 30000; t += 1000) r.frame(t);
|
|
945
|
+
assert.equal(r.labels(30000).length, 0);
|
|
946
|
+
// 30 s away under the same id: the place re-sends the same version.
|
|
947
|
+
state = 'reconnecting'; r.frame(30050); assert.equal(r.labels(30050).length, 0);
|
|
948
|
+
state = 'connected'; r.frame(30100); assert.equal(r.labels(30100)[0].text, spec.say);
|
|
949
|
+
r.frame(30150); r.hub.companion = { c: { ...spec }, n: 9 }; r.frame(30200);
|
|
950
|
+
assert.equal(r.labels(30100 + ms - 1).length, 1); assert.equal(r.labels(30100 + ms).length, 0);
|
|
951
|
+
// A hidden page whose socket never dropped: frames stop, then return.
|
|
952
|
+
r.frame(30100 + ms); r.frame(30100 + ms + Companion.AWAY_MS - 1); assert.equal(r.labels(30100 + ms + Companion.AWAY_MS - 1).length, 0);
|
|
953
|
+
const back = 30100 + ms + 2 * Companion.AWAY_MS - 1; r.frame(back); assert.equal(r.labels(back)[0].text, spec.say);
|
|
954
|
+
// No line to say: nothing is shown on return.
|
|
955
|
+
r.hub.companion = { c: { look: 'bird' }, n: 10 }; r.frame(back + 50); r.frame(back + 50 + Companion.AWAY_MS); assert.deepEqual(r.labels(back + 50 + Companion.AWAY_MS), []);
|
|
956
|
+
r.drawer.clear();
|
|
957
|
+
});
|
|
958
|
+
test('glows skip self, follow/rebuild avatar nodes, hide on trips; absent local hides follower', () => {
|
|
959
|
+
const r = rig(); r.frame();
|
|
960
|
+
assert.equal(r.own.children.length, 0); assert.equal(r.other.children.length, 1);
|
|
961
|
+
const old = r.other.children[0]; let disposed = 0; old.geometry.addEventListener('dispose', () => disposed++);
|
|
962
|
+
r.frame(50, false); assert.equal(old.visible, false); assert.deepEqual(r.labels(50), []);
|
|
963
|
+
r.frame(100); assert.equal(old.visible, true);
|
|
964
|
+
const replacement = new THREE.Group(); r.scene.three.nodes.set('other', { node: replacement }); r.frame(150);
|
|
965
|
+
assert.equal(disposed, 1); assert.equal(r.other.children.length, 0); assert.equal(replacement.children.length, 1);
|
|
966
|
+
r.scene.three.nodes.delete('local'); r.frame(200); assert.deepEqual(r.labels(200), []);
|
|
967
|
+
assert.equal(r.root.children.find((n) => n.name.startsWith('companion:')).visible, false);
|
|
968
|
+
r.hub.glow.clear(); r.frame(250); assert.equal(replacement.children.length, 0);
|
|
969
|
+
r.drawer.clear();
|
|
970
|
+
});
|
|
971
|
+
test('unknown point is ignored, known point faces the bird; clearing disposes both looks', () => {
|
|
972
|
+
const r = rig(); r.hub.companion.c = { ...spec, look: 'bird' }; r.frame();
|
|
973
|
+
const bird = r.root.children.find((n) => n.name === 'companion:bird');
|
|
974
|
+
near(bird.position.x, 2.55); near(bird.position.y, 1.75); near(bird.position.z, 2.65);
|
|
975
|
+
r.scene.getActor = () => ({ components: { Transform: { x: 2, z: 14 } } }); r.frame(50);
|
|
976
|
+
near(bird.rotation.y, Math.atan2(2 - bird.position.x, 14 - bird.position.z));
|
|
977
|
+
const wing = bird.children.find((n) => n.userData.wing); assert.notEqual(wing.rotation.z, 0);
|
|
978
|
+
r.hub.companion = { c: null, n: 2 }; r.frame(100); assert(!bird.parent);
|
|
979
|
+
r.drawer.clear();
|
|
980
|
+
});
|
|
981
|
+
test('rehello drops stale private follower; avatar hello keeps it; new identity clears all', () => {
|
|
982
|
+
let system; installSystem({ registerSystem(value) { system = value; } });
|
|
983
|
+
State.clear(); State.hub.place = { companion: true }; State.hub.companion = { c: spec, n: 1 }; State.hub.glow = new Set(['p1']);
|
|
984
|
+
const scene = { persistent: {} }, sent = []; let playerId = 'p1';
|
|
985
|
+
const net = { selfId: () => playerId, send: (msg) => sent.push(msg), drain: () => [] }, mp = { net };
|
|
986
|
+
system.sendHello(scene, mp, net, 0, { again: true }); assert.deepEqual(State.hub.companion, { c: spec, n: 1 });
|
|
987
|
+
system.sendHello(scene, mp, net, 0, { resume: true }); assert(!Object.hasOwn(State.hub, 'companion')); assert.equal(sent.at(-1).resume, true);
|
|
988
|
+
hook.message({}, { k: 'hub-companion', c: spec, n: 1 });
|
|
989
|
+
playerId = 'p2'; net.drain(); assert(!Object.hasOwn(State.hub, 'companion')); assert(!Object.hasOwn(State.hub, 'glow'));
|
|
990
|
+
});
|
|
991
|
+
test('same-id rehello asks the open talk panel to reattach after sending hello', () => {
|
|
992
|
+
let system; installSystem({ registerSystem(value) { system = value; } });
|
|
993
|
+
State.clear(); State.hub.place = { companion: true, companionChat: { name: 'Chirp' } };
|
|
994
|
+
const scene = { persistent: {} }, calls = []; let queue = [];
|
|
995
|
+
const net = { selfId: () => 'p1', send: (msg) => calls.push(msg), drain() { const result = queue; queue = []; return result; } };
|
|
996
|
+
const mp = { net, joined: true };
|
|
997
|
+
system.talk = { resume: () => calls.push('reattach') };
|
|
998
|
+
system.sendHello(scene, mp, net, 0, { again: true }); calls.length = 0;
|
|
999
|
+
queue.push({ k: 'w' }); net.drain();
|
|
1000
|
+
system.sayHello(scene, mp);
|
|
1001
|
+
assert.equal(calls[0].k, 'hub-hello'); assert.equal(calls[0].resume, true); assert.equal(calls[1], 'reattach');
|
|
1002
|
+
calls.length = 0; system.sayHello(scene, mp);
|
|
1003
|
+
assert(!calls.includes('reattach'), 'ordinary frames do not reattach');
|
|
1004
|
+
State.clear();
|
|
1005
|
+
});
|
|
1006
|
+
test('system keyless frame creates nothing; opt-in creates drawer and removal disposes it', () => {
|
|
1007
|
+
State.clear(); fakeDom({ viewW: 360, viewH: 780 });
|
|
1008
|
+
let system; installSystem({ registerSystem(value) { system = value; } });
|
|
1009
|
+
const calls = [];
|
|
1010
|
+
system.chrome = new Proxy({ peopleOpen: () => false, chatFocused: () => false }, { get(target, name) { return target[name] ?? ((...args) => calls.push([name, ...args])); } });
|
|
1011
|
+
system.talk = { frame() {}, talking: () => false, typing: () => false, talkingWith: () => null };
|
|
1012
|
+
system.idle = { frame() {}, draw() {}, labels: () => [] };
|
|
1013
|
+
system.grab = { frame() {} }; system.sound = { frame() {} }; system.sayHooked = true;
|
|
1014
|
+
system.together.frame = () => {};
|
|
1015
|
+
for (const method of ['keepResident', 'wearAvatar', 'applyTune', 'watchSession', 'sayHello', 'followPlace', 'holdFall', 'turnSpinners', 'applySpawns', 'applyTints', 'registerInterest', 'applyVisibility', 'applyWear', 'adoptLate', 'runCommands', 'askFriends', 'stepEnd', 'faceArrival', 'measure']) system[method] = () => {};
|
|
1016
|
+
system.sceneKey = 'main';
|
|
1017
|
+
const scene = { sceneKey: 'main', currentScenePath: 'scenes/main.scene', multiplayer: { net: { selfId: () => 'p1' } }, actorWith: () => null, persistent: { hubTickets: [], hubAvatar: 0 }, getActors: () => [] };
|
|
1018
|
+
hook.state({}, { hubPlace: { id: 'main' } }); system.afterBehaviors(scene, 0.05);
|
|
1019
|
+
assert(!Object.hasOwn(system, 'companion')); assert(!Object.hasOwn(State.hub, 'companion')); assert(!Object.hasOwn(State.hub, 'glow'));
|
|
1020
|
+
hook.state({}, { hubPlace: { id: 'main', companion: true } }); system.afterBehaviors(scene, 0.05);
|
|
1021
|
+
assert(system.companion);
|
|
1022
|
+
const busy = []; system.companion.frame = (...args) => busy.push(args[7]);
|
|
1023
|
+
system.talk.talkingWith = () => 'companion:p1'; system.afterBehaviors(scene, 0.05); assert.equal(busy.at(-1), true);
|
|
1024
|
+
system.talk.talkingWith = () => 'rowan'; system.afterBehaviors(scene, 0.05); assert.equal(busy.at(-1), false);
|
|
1025
|
+
system.companionTappedUntil = performance.now() + 3000; system.afterBehaviors(scene, 0.05); assert.equal(busy.at(-1), true);
|
|
1026
|
+
system.companionTappedUntil = -Infinity; system.afterBehaviors(scene, 0.05); assert.equal(busy.at(-1), false);
|
|
1027
|
+
hook.state({}, { hubPlace: { id: 'main' } }); system.afterBehaviors(scene, 0.05); assert(!Object.hasOwn(system, 'companion'));
|
|
1028
|
+
assert(!Object.hasOwn(system, 'companionTappedUntil'));
|
|
1029
|
+
});
|
|
1030
|
+
const { makeTalk } = await import('../code/client/talk.js');
|
|
1031
|
+
test('companion has no wide prompt; real NPC wins; tap entry and existing panel stay id-agnostic', () => {
|
|
1032
|
+
State.clear(); State.hub.place = { companion: true, companionChat: { name: 'Chirp' } }; State.hub.companion = { c: { look: 'bird' }, n: 1 };
|
|
1033
|
+
const sent = [], prompts = [], titles = [], lines = []; let handlers;
|
|
1034
|
+
const chrome = { onTalk(value) { handlers = value; }, talkPrompt(...args) { prompts.push(args); }, openTalk(name) { titles.push(name); }, closeTalk() {}, talkWaiting() {}, talkLine(...args) { lines.push(args); }, talkAsks() {}, talkFocused: () => false };
|
|
1035
|
+
const talk = makeTalk(chrome), local = { components: { Transform: { x: 0, y: 1, z: 0 } } };
|
|
1036
|
+
const net = { selfId: () => 'p1', send: (msg) => sent.push(msg) }, mp = { net };
|
|
1037
|
+
let actors = [];
|
|
1038
|
+
const scene = { multiplayer: mp, actorWith: () => local, getActors: () => actors };
|
|
1039
|
+
talk.frame(scene, mp, true); assert.deepEqual(prompts.at(-1), [null, false]); talk.openCompanion(scene); assert.deepEqual(sent.at(-1), { k: 'hub-npc-open', npc: 'companion:p1' });
|
|
1040
|
+
State.hub.npcEvents.push({ k: 'hub-npc', npc: 'companion:p1', open: true, name: 'Chirp', mind: false, opening: { text: 'Hi!' } });
|
|
1041
|
+
talk.frame(scene, mp, true); assert.equal(talk.talkingToCompanion(), true); assert.deepEqual(titles, ['Chirp']); assert.deepEqual(lines[0], ['them', 'Hi!']);
|
|
1042
|
+
State.hub.npcEvents.push({ k: 'hub-npc-line', npc: 'companion:p1', text: 'Try the garden', why: 'authored' }); talk.frame(scene, mp, true); assert.equal(lines.at(-1)[1], 'Try the garden'); handlers.end();
|
|
1043
|
+
actors = [{ id: 'rowan', components: { HubNpc: { name: 'Rowan', character: 'greeter' }, Transform: { x: 1, y: 1, z: 0 } } }];
|
|
1044
|
+
talk.frame(scene, mp, true); assert.deepEqual(prompts.at(-1), ['Rowan', true]); handlers.open(); assert.equal(sent.at(-1).npc, 'rowan');
|
|
1045
|
+
talk.reset(); talk.frame(scene, mp, true); talk.openCompanion(scene); assert.equal(sent.at(-1).npc, 'companion:p1');
|
|
1046
|
+
talk.reset(); State.hub.companion.c = null; actors = []; talk.frame(scene, mp, true); assert.equal(prompts.at(-1)[0], null);
|
|
1047
|
+
State.hub.companion.c = { look: 'bird' }; delete State.hub.place.companionChat; talk.frame(scene, mp, true); assert.equal(prompts.at(-1)[0], null);
|
|
1048
|
+
const count = sent.length; talk.openCompanion(scene); assert.equal(sent.length, count); State.clear();
|
|
1049
|
+
});
|
|
1050
|
+
test('tap hit area is local, 44 px, accessible, gated by panel, and removed with no screen', () => {
|
|
1051
|
+
fakeDom({ viewW: 360, viewH: 780 });
|
|
1052
|
+
const chrome = makeChrome({ avatarCount: 4, onBack() {}, onAvatar() {} });
|
|
1053
|
+
assert(!Object.hasOwn(chrome, 'companionTalkButton')); let opened = 0;
|
|
1054
|
+
chrome.setCompanionTalk({ x: 170, y: 300 }, 'Chirp', () => opened++);
|
|
1055
|
+
const hit = chrome.companionTalkButton;
|
|
1056
|
+
assert.equal(hit.style.width, '44px'); assert.equal(hit.style.height, '44px'); assert.equal(hit.style.left, '170px'); assert.equal(hit.attrs['aria-label'], 'Chat with Chirp');
|
|
1057
|
+
chrome.setCompanionTalk({ x: 170, y: 300 }, 'Chirp', () => { opened += 2; });
|
|
1058
|
+
let stopped = false; hit.handlers.pointerdown({ stopPropagation() { stopped = true; } }); assert(stopped); assert.equal(opened, 2);
|
|
1059
|
+
chrome.openTalk('Chirp'); chrome.setCompanionTalk({ x: 170, y: 300 }, 'Chirp', () => opened++); assert(!Object.hasOwn(chrome, 'companionTalkButton')); assert(!hit.parent.children.includes(hit));
|
|
1060
|
+
chrome.closeTalk(); chrome.setCompanionTalk({ x: 170, y: 300 }, 'Chirp', () => opened++); chrome.setCompanionTalk(null); assert(!Object.hasOwn(chrome, 'companionTalkButton'));
|
|
1061
|
+
chrome.dispose();
|
|
1062
|
+
});
|
|
1063
|
+
test('badge is lazy, in the dock, and hides for every open panel at phone and tablet sizes', () => {
|
|
1064
|
+
for (const [viewW, viewH] of [[360, 668], [412, 915], [820, 1180]]) {
|
|
1065
|
+
const dom = fakeDom({ viewW, viewH });
|
|
1066
|
+
const chrome = makeChrome({ avatarCount: 4, onBack() {}, onAvatar() {} });
|
|
1067
|
+
assert(!chrome.companionBadge);
|
|
1068
|
+
chrome.setCompanionBadge(false); assert(!chrome.companionBadge);
|
|
1069
|
+
let opened = 0;
|
|
1070
|
+
chrome.setCompanionBadge(true, 'Chirp', () => opened++);
|
|
1071
|
+
const badge = chrome.companionBadge;
|
|
1072
|
+
assert.equal(badge.style.width, '44px'); assert.equal(badge.style.height, '44px');
|
|
1073
|
+
assert.equal(badge.attrs['aria-label'], 'Chat with Chirp');
|
|
1074
|
+
assert(badge.parent.children.some((n) => n.textContent === 'Doors'));
|
|
1075
|
+
assert.equal(badge.parent.style.flexWrap, 'wrap-reverse');
|
|
1076
|
+
assert.equal(badge.parent.style.maxWidth, 'calc(100vw - 130px)');
|
|
1077
|
+
badge.handlers.pointerdown({ stopPropagation() {} }); assert.equal(opened, 1);
|
|
1078
|
+
chrome.openTalk('Chirp'); assert.equal(badge.style.display, 'none');
|
|
1079
|
+
chrome.closeTalk(); assert.equal(badge.style.display, 'block');
|
|
1080
|
+
const character = dom.made.find((n) => n.textContent === 'Character');
|
|
1081
|
+
character.handlers.pointerdown({ stopPropagation() {} }); assert.equal(badge.style.display, 'none');
|
|
1082
|
+
character.handlers.pointerdown({ stopPropagation() {} }); assert.equal(badge.style.display, 'block');
|
|
1083
|
+
for (const name of ['Doors', 'People', 'Quick chat', 'Emote']) {
|
|
1084
|
+
const control = dom.made.find((n) => n.textContent === name || n.attrs['aria-label'] === name || (name === 'People' && n.parent === badge.parent && n !== badge && n.textContent !== 'Doors'));
|
|
1085
|
+
control.handlers.pointerdown({ stopPropagation() {}, preventDefault() {} }); assert.equal(badge.style.display, 'none', name);
|
|
1086
|
+
control.handlers.pointerdown({ stopPropagation() {}, preventDefault() {} }); assert.equal(badge.style.display, 'block', name);
|
|
1087
|
+
}
|
|
1088
|
+
chrome.setCompanionBadge(false); assert(!chrome.companionBadge);
|
|
1089
|
+
chrome.dispose();
|
|
1090
|
+
}
|
|
1091
|
+
});
|
|
1092
|
+
// Exercise the actual mind path: inspect gate, empty audience, private status
|
|
1093
|
+
// polling, and the same panel with an id that has no scene actor.
|
|
1094
|
+
{
|
|
1095
|
+
State.clear(); State.hub.place = { companion: true, companionChat: { name: 'Chirp' } }; State.hub.companion = { c: { look: 'bird' }, n: 1 };
|
|
1096
|
+
const requests = [], reads = [], lines = [], sent = []; let handlers, finish;
|
|
1097
|
+
const replied = new Promise((resolve) => { finish = resolve; });
|
|
1098
|
+
const chrome = { onTalk(value) { handlers = value; }, talkPrompt() {}, openTalk() {}, closeTalk() {}, talkWaiting() {}, talkLine(who, text) { lines.push([who, text]); if (text === 'private:mind:p1') finish(); }, talkAsks() {}, talkTyping() {}, talkFocused: () => false };
|
|
1099
|
+
const net = { selfId: () => 'p1', send(msg) { sent.push(msg); }, characters: { async requestCharacterTurn(request) { requests.push(request); }, async readCharacters(request) { reads.push(request); return request.query.type === 'inspect' ? {} : { status: 'completed', response: 'private:mind:p1' }; } } };
|
|
1100
|
+
const mp = { net }, scene = { multiplayer: mp, actorWith: () => ({ components: { Transform: { x: 0, y: 1, z: 0 } } }), getActors: () => [] };
|
|
1101
|
+
const talk = makeTalk(chrome); talk.frame(scene, mp, true); await Promise.resolve();
|
|
1102
|
+
assert.equal(reads[0].query.type, 'inspect', 'companion presence registers before the first badge tap');
|
|
1103
|
+
talk.openCompanion(scene); State.hub.npcEvents.push({ k: 'hub-npc', npc: 'companion:p1', open: true, name: 'Chirp', character: 'companion', mind: true }); talk.frame(scene, mp, true);
|
|
1104
|
+
handlers.send('private:input:p1'); await replied;
|
|
1105
|
+
assert.equal(requests.length, 1); assert.equal(requests[0].characterId, 'companion'); assert.equal(requests[0].input, 'private:input:p1');
|
|
1106
|
+
assert.deepEqual(requests[0].audience, { disclosure: 'participants', playerIds: [], characterIds: [] });
|
|
1107
|
+
assert.equal(reads.at(-1).query.type, 'status'); assert.equal(reads.at(-1).query.operationId, requests[0].operationId);
|
|
1108
|
+
assert.deepEqual(lines, [['me', 'private:input:p1'], ['them', 'private:mind:p1']]); assert.deepEqual(sent, [{ k: 'hub-npc-open', npc: 'companion:p1' }]);
|
|
1109
|
+
talk.reset(); State.clear(); passed++; console.log('ok: virtual mind uses existing private status polling and panel with no listener or world message');
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
|
|
1113
|
+
test('opted-in idle ticks accumulate time and wake immediately for changed inputs', () => {
|
|
1114
|
+
const idle = Companion.makeIdleTick();
|
|
1115
|
+
assert.equal(idle.take([1, 'pose'], 0.05), 0.05);
|
|
1116
|
+
idle.ready = true;
|
|
1117
|
+
assert.equal(idle.take([1, 'pose'], 0.05), null);
|
|
1118
|
+
assert.equal(idle.take([1, 'pose'], 0.05), null);
|
|
1119
|
+
assert.equal(idle.take([1, 'pose'], 0.05), null);
|
|
1120
|
+
near(idle.take([1, 'pose'], 0.05), 0.2);
|
|
1121
|
+
assert.equal(idle.take([2, 'pose'], 0.05), 0.05);
|
|
1122
|
+
assert.equal(idle.take([2, 'show'], 0.05), 0.05);
|
|
1123
|
+
});
|
|
1124
|
+
test('opted-in settled companion stops transform writes, wakes for movement and speech', () => {
|
|
1125
|
+
const r = rig({ idle: true });
|
|
1126
|
+
r.hub.companion.c = { look: 'bird' };
|
|
1127
|
+
for (let i = 0; i < 400; i++) r.frame(i * 50);
|
|
1128
|
+
const bird = r.root.children.find(n => n.name === 'companion:bird');
|
|
1129
|
+
let changes = 0, turns = 0, paints = 0;
|
|
1130
|
+
const onChange = bird.rotation._onChangeCallback;
|
|
1131
|
+
bird.rotation._onChangeCallback = () => { turns++; onChange(); };
|
|
1132
|
+
const traverse = bird.traverse.bind(bird);
|
|
1133
|
+
bird.traverse = (...args) => { paints++; return traverse(...args); };
|
|
1134
|
+
const set = bird.position.set.bind(bird.position);
|
|
1135
|
+
bird.position.set = (...args) => { changes++; return set(...args); };
|
|
1136
|
+
for (let i = 400; i < 440; i++) r.frame(i * 50);
|
|
1137
|
+
assert.equal(changes, 0);
|
|
1138
|
+
assert.equal(turns, 0, 'idle does not dirty the quaternion');
|
|
1139
|
+
assert.equal(paints, 0, 'idle does not traverse all the materials');
|
|
1140
|
+
r.local.components.Transform.x += 1;
|
|
1141
|
+
r.frame(22000);
|
|
1142
|
+
assert(changes > 0, 'movement wakes on the first frame');
|
|
1143
|
+
r.hub.companion = { c: { look: 'bird', say: 'Hello again' }, n: 2 };
|
|
1144
|
+
r.frame(22050);
|
|
1145
|
+
assert.equal(r.labels(22050)[0].text, 'Hello again');
|
|
1146
|
+
});
|
|
1147
|
+
|
|
1148
|
+
|
|
1149
|
+
|
|
1150
|
+
test('opted-in waiting guide ticks at 5 Hz and wakes for a moving destination', () => {
|
|
1151
|
+
const r = rig({ idle: true });
|
|
1152
|
+
const destination = { x: 4, y: 1, z: 5 };
|
|
1153
|
+
r.scene.getActor = () => ({ components: { Transform: destination } });
|
|
1154
|
+
r.hub.companion.c = { look: 'bird', at: 'goal' };
|
|
1155
|
+
for (let i = 0; i < 400; i++) r.frame(i * 50);
|
|
1156
|
+
const bird = r.root.children.find(n => n.name === 'companion:bird');
|
|
1157
|
+
let writes = 0;
|
|
1158
|
+
const set = bird.position.set.bind(bird.position);
|
|
1159
|
+
bird.position.set = (...args) => { writes++; return set(...args); };
|
|
1160
|
+
for (let i = 400; i < 440; i++) r.frame(i * 50);
|
|
1161
|
+
assert(writes > 0 && writes <= 10, `${writes} hover writes over 2 s`);
|
|
1162
|
+
const before = writes;
|
|
1163
|
+
destination.x += 2;
|
|
1164
|
+
r.frame(22000);
|
|
1165
|
+
assert(writes > before, 'destination movement wakes on the first frame');
|
|
1166
|
+
});
|
|
1167
|
+
console.log(`${passed} companion client tests passed`);
|