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,1151 @@
|
|
|
1
|
+
// The soundscape (a deck with `hub.soundscape`): the sounds the kit makes
|
|
2
|
+
// itself, synthesised in WebAudio, never from a file and never speech:
|
|
3
|
+
//
|
|
4
|
+
// babble an NPC's line becomes made-up syllables with round-6 glottal pulses
|
|
5
|
+
// and four formants, in that NPC's own voice
|
|
6
|
+
// steps footsteps under the player and under the players and NPCs near
|
|
7
|
+
// them, a jump and a landing
|
|
8
|
+
// ambience optional zone beds, nearby spots and quiet generative music
|
|
9
|
+
// ui optional door transitions, private activity timers and chip taps
|
|
10
|
+
// cues chosen place cues and existing emote, seat and talk state edges
|
|
11
|
+
//
|
|
12
|
+
// with one control in the chrome (a speaker button: mute, volume) that also
|
|
13
|
+
// scales the place's own `hub.sound` files (`sound.js`).
|
|
14
|
+
//
|
|
15
|
+
// The hub system (`systems/hub.js`) makes one only in a deck that asks. A deck
|
|
16
|
+
// without the key never runs a line of this: no context, no listener, no
|
|
17
|
+
// storage read, no node.
|
|
18
|
+
//
|
|
19
|
+
// Everything plays into one master gain through a bus of its own (`voice`,
|
|
20
|
+
// `steps`, opt-in `ambience` and `ui`). `frame` sounds once per
|
|
21
|
+
// frame, `completeFrame` settles after the transport drain. Boolean steps
|
|
22
|
+
// use street everywhere; only an object reads the ground map.
|
|
23
|
+
//
|
|
24
|
+
// Rules that hold for every sound here:
|
|
25
|
+
// - nothing sounds before the player's first gesture, and nothing waits for
|
|
26
|
+
// it: a sound that cannot play now is dropped, never queued;
|
|
27
|
+
// - a line that arrived while nothing could sound is never said late;
|
|
28
|
+
// - who sounds is chosen before anything is built (the nearest two voices,
|
|
29
|
+
// the nearest four other steps), so a crowd costs no more than its cap;
|
|
30
|
+
// - no number that is not finite reaches the audio graph, and nothing here
|
|
31
|
+
// can throw into the hub's frame;
|
|
32
|
+
// - nothing sounds while the page is hidden, while the player is on a trip
|
|
33
|
+
// through a door, or while the control is muted, except the short tail of
|
|
34
|
+
// a departure whoosh started before the trip; hiding or muting cuts it;
|
|
35
|
+
// - no timers: everything is scheduled on the context's clock, and a node
|
|
36
|
+
// made for one sound is stopped and disconnected when it ends.
|
|
37
|
+
|
|
38
|
+
import * as Shared from '@imports/castle.physics-2d/engine/audioContext';
|
|
39
|
+
import { hub } from './state.js';
|
|
40
|
+
import { makeSoundscapeMap, sanitiseSoundscape } from './soundscapeMap.js';
|
|
41
|
+
import { makeAmbience, BEDS } from './soundscapeAmbience.js';
|
|
42
|
+
import { makeUi } from './soundscapeUi.js';
|
|
43
|
+
import { makeBusker } from './soundscapeBusker.js';
|
|
44
|
+
import { makeActions, distanceGain } from './soundscapeActions.js';
|
|
45
|
+
import { simlish, VOICE_TYPES } from './soundscapeVoice.js';
|
|
46
|
+
export { BABBLE_MAX_S, BABBLE_MAX_SYLLABLES, babblePlan, VOICE_TYPES } from './soundscapeVoice.js';
|
|
47
|
+
|
|
48
|
+
export const SETTINGS_KEY = 'castle.hub.soundscape.v1';
|
|
49
|
+
export const DEFAULT_VOLUME = 0.7;
|
|
50
|
+
// The control's 100% at the master gain, and each bus under it. Set by
|
|
51
|
+
// measuring what comes out (rendered offline in Chromium, at 100%): a step
|
|
52
|
+
// peaks at 0.09 to 0.17 of full scale by its surface, a landing near 0.25, a
|
|
53
|
+
// line near 0.3, and two voices, a landing and four other steps at the same
|
|
54
|
+
// instant near 0.6. A limiter behind the master holds what sums.
|
|
55
|
+
// The ambience bus was raised 8 dB from 0.5 on the owner's ear: footsteps
|
|
56
|
+
// were too loud against the beds, so a bed sits about 8 dB under a footstep.
|
|
57
|
+
export const MASTER = 0.9;
|
|
58
|
+
const BUS = { voice: 1, steps: 1.6, ambience: 0.5 * 10 ** (8 / 20), ui: 0.5 };
|
|
59
|
+
|
|
60
|
+
// --- babble ------------------------------------------------------------------
|
|
61
|
+
|
|
62
|
+
// NPC voices sounding at once (the nearest win), and how far a public line
|
|
63
|
+
// carries (`gainAt`'s straight line, as the place's own sounds fall off).
|
|
64
|
+
export const VOICES_MAX = 2;
|
|
65
|
+
export const BABBLE_RADIUS_M = 12;
|
|
66
|
+
// The panel owns its NPC's voice while open and for this long after closing
|
|
67
|
+
// or saying a line. Labels may be truncated, so no text is compared across sources.
|
|
68
|
+
const PANEL_VOICE_MS = 10000;
|
|
69
|
+
// Matches the old babble's loudness: rendered offline in Chromium through the
|
|
70
|
+
// whole chain (four NPCs x three lines, volume 0.7), the old line's median
|
|
71
|
+
// active RMS was -25.64 dBFS and this voice's -18.70 at 0.55, so 0.55 is
|
|
72
|
+
// scaled by 10^(-6.94/20).
|
|
73
|
+
export const BABBLE_LEVEL = 0.55 * 10 ** (-6.94 / 20);
|
|
74
|
+
|
|
75
|
+
// FNV-1a, 32 bits: the same string is the same number on every client.
|
|
76
|
+
export function hashOf(text) {
|
|
77
|
+
let h = 0x811c9dc5;
|
|
78
|
+
const s = String(text);
|
|
79
|
+
for (let i = 0; i < s.length; i += 1) {
|
|
80
|
+
h ^= s.charCodeAt(i);
|
|
81
|
+
h = Math.imul(h, 0x01000193);
|
|
82
|
+
}
|
|
83
|
+
return h >>> 0;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// A small seeded generator (mulberry32): numbers in [0, 1).
|
|
87
|
+
function seeded(seed) {
|
|
88
|
+
let a = seed >>> 0;
|
|
89
|
+
return () => {
|
|
90
|
+
a = (a + 0x6d2b79f5) >>> 0;
|
|
91
|
+
let t = a;
|
|
92
|
+
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
93
|
+
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
|
94
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
|
|
99
|
+
|
|
100
|
+
// Whole-word role defaults, in fixed precedence: gruff, gentle, lively.
|
|
101
|
+
// HubNpc role is the place's key; character is its characterBundle id.
|
|
102
|
+
export const VOICE_KEYWORDS = {
|
|
103
|
+
gruff: ['harbourmaster', 'harbour master', 'innkeeper', 'inn', 'fisher', 'captain', 'smith', 'guard', 'elder', 'grandpa', 'old'],
|
|
104
|
+
gentle: ['nursery', 'clinic', 'nurse', 'nana', 'granny', 'gardener', 'healer', 'vet', 'teacher', 'carer'],
|
|
105
|
+
lively: ['kid', 'child', 'barker', 'crier', 'hawker', 'postie', 'courier', 'runner', 'coach', 'announcer', 'busker'],
|
|
106
|
+
};
|
|
107
|
+
const rolePatterns = Object.entries(VOICE_KEYWORDS).map(([type, words]) =>
|
|
108
|
+
[type, new RegExp(`(?:^|[^\\p{L}\\p{N}_])(?:${words.join('|')})(?=$|[^\\p{L}\\p{N}_])`, 'u')]);
|
|
109
|
+
|
|
110
|
+
// Every NPC keeps its hash-derived words, pitch, mouth and rate variation.
|
|
111
|
+
// Legacy rate 4..10 maps linearly to 2.5..6; timbre remains ignored.
|
|
112
|
+
export function voiceOf(id, name = '', over = null, role = '', character = '') {
|
|
113
|
+
const seed = hashOf(`${id}|${name}`);
|
|
114
|
+
const next = seeded(seed);
|
|
115
|
+
const u = next();
|
|
116
|
+
next(); // Keep the old style draw so rate variation uses the same draw.
|
|
117
|
+
const words = `${role} ${character} ${name}`.toLowerCase();
|
|
118
|
+
const type = typeof over?.type === 'string' && Object.hasOwn(VOICE_TYPES, over.type)
|
|
119
|
+
? over.type : rolePatterns.find(([, pattern]) => pattern.test(words))?.[0] ?? 'townsfolk';
|
|
120
|
+
const voice = {
|
|
121
|
+
...VOICE_TYPES[type], seed, type,
|
|
122
|
+
pitch: 240 * 2 ** (u * 0.9 - 0.4),
|
|
123
|
+
mouth: 1 + u * 0.16,
|
|
124
|
+
rate: VOICE_TYPES[type].rate * (0.9 + next() * 0.2),
|
|
125
|
+
};
|
|
126
|
+
if (over && typeof over === 'object') {
|
|
127
|
+
if (typeof over.pitch === 'number' && Number.isFinite(over.pitch)) {
|
|
128
|
+
voice.pitch = clamp(over.pitch, 80, 500);
|
|
129
|
+
voice.mouth = 1 + clamp((Math.log2(voice.pitch / 240) + 0.4) / 0.9, 0, 1) * 0.16;
|
|
130
|
+
}
|
|
131
|
+
if (typeof over.rate === 'number' && Number.isFinite(over.rate)) {
|
|
132
|
+
voice.rate = 2.5 + (clamp(over.rate, 4, 10) - 4) * 3.5 / 6;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return voice;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// How loud a public line is `d` metres from the NPC who says it.
|
|
139
|
+
export function babbleGain(d) {
|
|
140
|
+
return Math.max(0, 1 - d / BABBLE_RADIUS_M);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// A line without the name the kit writes ahead of it over the NPC ("Rowan:
|
|
144
|
+
// Hello"), as the panel has it; its first words tell two copies of it apart.
|
|
145
|
+
function wordsOf(text, name) {
|
|
146
|
+
const line = String(text ?? '');
|
|
147
|
+
const head = name ? `${name}: ` : '';
|
|
148
|
+
return (head && line.startsWith(head) ? line.slice(head.length) : line).trim();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// --- steps -------------------------------------------------------------------
|
|
152
|
+
|
|
153
|
+
export const STRIDE_M = 0.65;
|
|
154
|
+
// A move this long in one frame is not a step: the player was put somewhere.
|
|
155
|
+
export const TELEPORT_M = 1.5;
|
|
156
|
+
export const OTHERS_GAIN = 0.5;
|
|
157
|
+
export const OTHERS_RADIUS_M = 10;
|
|
158
|
+
export const OTHER_STEPS_MAX = 4;
|
|
159
|
+
// A body slower than this is standing (a pose that drifts takes no steps).
|
|
160
|
+
const STILL_MPS = 0.4;
|
|
161
|
+
// A frame this long is a pause; what happened in it is not walked.
|
|
162
|
+
const PAUSE_S = 0.5;
|
|
163
|
+
// With no word on the ground (another player, an NPC): rising or falling this
|
|
164
|
+
// fast is in the air, and slower than SETTLED_MPS after a fall is landed.
|
|
165
|
+
const AIR_MPS = 3.5;
|
|
166
|
+
const SETTLED_MPS = 0.8;
|
|
167
|
+
// In the air this long with no fall seen: taken as back on the ground, quietly.
|
|
168
|
+
const AIR_LIMIT_S = 0.9;
|
|
169
|
+
// Shorter than this off the ground is a step's edge, not a landing.
|
|
170
|
+
const AIR_MIN_S = 0.12;
|
|
171
|
+
|
|
172
|
+
export const STEP = 1;
|
|
173
|
+
export const JUMP = 2;
|
|
174
|
+
export const LAND = 3;
|
|
175
|
+
|
|
176
|
+
// What a foot sounds like on each ground: a burst of noise through a filter
|
|
177
|
+
// (`type`, `f` Hz, `q`, `dur` seconds, `gain`) and a low thump under it.
|
|
178
|
+
// Grass is soft (low-passed at 2.5 kHz) and grass and wood are levelled so every
|
|
179
|
+
// surface's step sounds about as loud (K-weighted 50 ms step level within ~1 dB,
|
|
180
|
+
// measured offline in Chromium at volume 0.7).
|
|
181
|
+
export const SURFACES = {
|
|
182
|
+
grass: { lowCut: 180, type: 'lowpass', f: 2500, q: 0.6, dur: 0.11, gain: 0.17, thump: 68, thumpGain: 0.0785 },
|
|
183
|
+
street: { lowCut: 200, type: 'bandpass', f: 1100, q: 1.1, dur: 0.06, gain: 0.3, thump: 92, thumpGain: 0.12 },
|
|
184
|
+
wood: { lowCut: 220, type: 'bandpass', f: 520, q: 2.8, dur: 0.075, gain: 0.268, thump: 138, thumpGain: 0.142 },
|
|
185
|
+
stone: { lowCut: 200, type: 'bandpass', f: 1900, q: 2.4, dur: 0.045, gain: 0.44, thump: 108, thumpGain: 0.084 },
|
|
186
|
+
sand: { lowCut: 150, type: 'lowpass', f: 900, q: 0.5, dur: 0.14, gain: 0.4, thump: 60, thumpGain: 0.036 },
|
|
187
|
+
cobble: { lowCut: 210, type: 'bandpass', f: 1550, q: 3.2, dur: 0.055, gain: 0.36, thump: 122, thumpGain: 0.108 },
|
|
188
|
+
};
|
|
189
|
+
export const DEFAULT_SURFACE = 'street';
|
|
190
|
+
|
|
191
|
+
// The original ground, for boolean steps. Object steps use the scene map.
|
|
192
|
+
export function surfaceAt() {
|
|
193
|
+
return DEFAULT_SURFACE;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// How far a body goes between two footfalls at `speed` m/s: STRIDE_M at a walk
|
|
197
|
+
// (an NPC's 2.6 m/s is four steps a second), longer as it runs, so the
|
|
198
|
+
// Player's 6 m/s is still about four a second and not nine.
|
|
199
|
+
export function strideAt(speed) {
|
|
200
|
+
return STRIDE_M + clamp((speed - 2.6) * 0.25, 0, 0.85);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export function makeStepper() {
|
|
204
|
+
return { has: false, x: 0, y: 0, z: 0, walked: 0, foot: 0, air: false, airFor: 0, fell: false, fall: 0, seen: 0 };
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// One frame of one body. `x`, `y`, `z` where it is, `dt` seconds since its
|
|
208
|
+
// last frame, `grounded` whether it stands on something (null where nobody
|
|
209
|
+
// says: then how fast it rises or falls decides), `vy` its vertical speed
|
|
210
|
+
// (null: taken from the two frames). Returns 0, STEP (`s.foot` is which
|
|
211
|
+
// foot), JUMP (it left the ground going up, where `grounded` is known) or
|
|
212
|
+
// LAND (`s.fall` is how fast it came down, m/s).
|
|
213
|
+
export function stepFrame(s, x, y, z, dt, grounded = null, vy = null) {
|
|
214
|
+
if (!s.has || !(dt > 0) || !Number.isFinite(x + y + z)) {
|
|
215
|
+
s.has = Number.isFinite(x + y + z);
|
|
216
|
+
s.x = x;
|
|
217
|
+
s.y = y;
|
|
218
|
+
s.z = z;
|
|
219
|
+
return 0;
|
|
220
|
+
}
|
|
221
|
+
const moved = Math.hypot(x - s.x, z - s.z);
|
|
222
|
+
const rise = y - s.y;
|
|
223
|
+
s.x = x;
|
|
224
|
+
s.y = y;
|
|
225
|
+
s.z = z;
|
|
226
|
+
if (moved > TELEPORT_M || Math.abs(rise) > 2 * TELEPORT_M || dt > PAUSE_S) {
|
|
227
|
+
s.walked = 0;
|
|
228
|
+
s.air = false;
|
|
229
|
+
s.airFor = 0;
|
|
230
|
+
return 0;
|
|
231
|
+
}
|
|
232
|
+
const v = vy ?? rise / dt;
|
|
233
|
+
let onGround = grounded;
|
|
234
|
+
if (onGround === null) {
|
|
235
|
+
if (!s.air) {
|
|
236
|
+
onGround = Math.abs(v) < AIR_MPS;
|
|
237
|
+
} else {
|
|
238
|
+
onGround = (s.fell && Math.abs(v) < SETTLED_MPS) || s.airFor > AIR_LIMIT_S;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (!onGround) {
|
|
242
|
+
const left = !s.air;
|
|
243
|
+
if (left) {
|
|
244
|
+
s.air = true;
|
|
245
|
+
s.airFor = 0;
|
|
246
|
+
s.fell = false;
|
|
247
|
+
s.fall = 0;
|
|
248
|
+
}
|
|
249
|
+
s.airFor += dt;
|
|
250
|
+
if (v < -1) {
|
|
251
|
+
s.fell = true;
|
|
252
|
+
s.fall = Math.max(s.fall, -v);
|
|
253
|
+
}
|
|
254
|
+
return left && grounded === false && v > 2 ? JUMP : 0;
|
|
255
|
+
}
|
|
256
|
+
if (s.air) {
|
|
257
|
+
s.air = false;
|
|
258
|
+
s.walked = 0;
|
|
259
|
+
return s.fell && s.airFor >= AIR_MIN_S ? LAND : 0;
|
|
260
|
+
}
|
|
261
|
+
const speed = moved / dt;
|
|
262
|
+
if (speed < STILL_MPS) {
|
|
263
|
+
return 0;
|
|
264
|
+
}
|
|
265
|
+
s.walked += moved;
|
|
266
|
+
const stride = strideAt(speed);
|
|
267
|
+
if (s.walked < stride) {
|
|
268
|
+
return 0;
|
|
269
|
+
}
|
|
270
|
+
s.walked -= stride;
|
|
271
|
+
if (s.walked >= stride) {
|
|
272
|
+
s.walked = 0;
|
|
273
|
+
}
|
|
274
|
+
s.foot ^= 1;
|
|
275
|
+
return STEP;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// --- the control's memory ----------------------------------------------------
|
|
279
|
+
|
|
280
|
+
function pageStorage() {
|
|
281
|
+
try {
|
|
282
|
+
return globalThis.localStorage ?? null;
|
|
283
|
+
} catch {
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export function readSettings(storage) {
|
|
289
|
+
const out = { volume: DEFAULT_VOLUME, muted: false };
|
|
290
|
+
try {
|
|
291
|
+
const kept = JSON.parse(storage?.getItem(SETTINGS_KEY) ?? 'null');
|
|
292
|
+
if (kept && typeof kept === 'object') {
|
|
293
|
+
if (typeof kept.volume === 'number' && Number.isFinite(kept.volume)) {
|
|
294
|
+
out.volume = clamp(kept.volume, 0, 1);
|
|
295
|
+
}
|
|
296
|
+
out.muted = kept.muted === true;
|
|
297
|
+
}
|
|
298
|
+
} catch {
|
|
299
|
+
// No storage, or not ours: the defaults.
|
|
300
|
+
}
|
|
301
|
+
return out;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function writeSettings(storage, settings) {
|
|
305
|
+
try {
|
|
306
|
+
storage?.setItem(SETTINGS_KEY, JSON.stringify({ volume: settings.volume, muted: settings.muted }));
|
|
307
|
+
} catch {
|
|
308
|
+
// A page without storage keeps the setting for this visit.
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// --- the sounds --------------------------------------------------------------
|
|
313
|
+
|
|
314
|
+
// One second and a half of white noise per context, made once.
|
|
315
|
+
const noises = new WeakMap();
|
|
316
|
+
function noiseOf(ctx) {
|
|
317
|
+
let buffer = noises.get(ctx);
|
|
318
|
+
if (!buffer) {
|
|
319
|
+
const n = Math.floor(ctx.sampleRate * 1.5);
|
|
320
|
+
buffer = ctx.createBuffer(1, n, ctx.sampleRate);
|
|
321
|
+
const data = buffer.getChannelData(0);
|
|
322
|
+
const next = seeded(0x5eed);
|
|
323
|
+
for (let i = 0; i < n; i += 1) {
|
|
324
|
+
data[i] = next() * 2 - 1;
|
|
325
|
+
}
|
|
326
|
+
noises.set(ctx, buffer);
|
|
327
|
+
}
|
|
328
|
+
return buffer;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const RAY_FROM = { x: 0, y: 0, z: 0 };
|
|
332
|
+
const RAY_DOWN = { x: 0, y: -1, z: 0 };
|
|
333
|
+
|
|
334
|
+
// Whether the player's own body stands on something, as the Player behavior
|
|
335
|
+
// decides it (physics-3d `behaviors/Player.jsx` `applyHover`: a ray down from
|
|
336
|
+
// the middle of the capsule), or null where the physics cannot say.
|
|
337
|
+
function groundedOf(scene, local) {
|
|
338
|
+
const phys = scene.physics3d;
|
|
339
|
+
const t = local.components.Transform;
|
|
340
|
+
if (typeof phys?.castRay !== 'function') {
|
|
341
|
+
return null;
|
|
342
|
+
}
|
|
343
|
+
try {
|
|
344
|
+
const height = local.components.Shape?.height ?? 1.4;
|
|
345
|
+
RAY_FROM.x = t.x;
|
|
346
|
+
RAY_FROM.y = t.y;
|
|
347
|
+
RAY_FROM.z = t.z;
|
|
348
|
+
const hit = phys.castRay(RAY_FROM, RAY_DOWN, height, local);
|
|
349
|
+
return Boolean(hit && hit.distance < height / 2 + 0.4);
|
|
350
|
+
} catch {
|
|
351
|
+
return null;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
const finite = (...values) => values.every((value) => typeof value === 'number' && Number.isFinite(value));
|
|
356
|
+
|
|
357
|
+
// Fallback activation belongs to the page, surviving disposal and scene rebuilds.
|
|
358
|
+
const gesturedPages = new WeakSet();
|
|
359
|
+
|
|
360
|
+
// `options` is the deck's `hub.soundscape` as the hook layer read it
|
|
361
|
+
// (`{ babble, steps, zones?, ambience?, ui?, cues? }`). `audio` is the shared context, `win`
|
|
362
|
+
// where the player's first gesture is heard, `onHide` is called as the page
|
|
363
|
+
// is hidden (the hub system quiets the place's own sound files there, which
|
|
364
|
+
// no frame would get to).
|
|
365
|
+
export function makeSoundscape(options, { audio = Shared, storage = pageStorage(), doc = globalThis.document ?? null, win = globalThis.window ?? null, nav = globalThis.navigator ?? null, random = Math.random, onHide = () => {}, isOn = null, loudestLoop = () => 0, cueVoices, createOfflineContext } = {}) {
|
|
366
|
+
options = sanitiseSoundscape(options, BEDS, SURFACES);
|
|
367
|
+
const want = { babble: options?.babble !== false, steps: options?.steps !== false };
|
|
368
|
+
const map = options?.ambience || typeof options?.steps === 'object' ? makeSoundscapeMap(options, SURFACES) : null;
|
|
369
|
+
const ambience = options?.ambience ? makeAmbience(options.ambience, { noise: noiseOf, seeded, hash: hashOf, loudestLoop, random, win, createOfflineContext, canBake: () => live() && ctx?.state === 'running' && Number.isFinite(ctx.currentTime) }) : null;
|
|
370
|
+
let mapScene = null;
|
|
371
|
+
const settings = readSettings(storage);
|
|
372
|
+
// The context once it has been asked for, and what hangs off it.
|
|
373
|
+
let ctx = null;
|
|
374
|
+
let out = null;
|
|
375
|
+
let resumeAt = -Infinity;
|
|
376
|
+
let disposed = false;
|
|
377
|
+
// Whether the player has touched the page: the browser's word where it
|
|
378
|
+
// gives one, else the first tap or key heard here.
|
|
379
|
+
const page = win ?? doc ?? globalThis;
|
|
380
|
+
// Lines being voiced: { npc, d, osc, gain, loud, nodes }.
|
|
381
|
+
const lines = [];
|
|
382
|
+
// npc actor id -> { text, frame }: the speech label last seen over it.
|
|
383
|
+
const seen = new Map();
|
|
384
|
+
// NPC -> when the panel's ownership of its voice expires after a line/close.
|
|
385
|
+
const panelUntil = new Map();
|
|
386
|
+
let panelNpc = null;
|
|
387
|
+
// This frame's new lines and others' steps, before any is built.
|
|
388
|
+
const linesWanted = [];
|
|
389
|
+
const stepsWanted = [];
|
|
390
|
+
// actor id -> stepper, the bodies near enough to hear; and the local one.
|
|
391
|
+
const steppers = new Map();
|
|
392
|
+
const mine = makeStepper();
|
|
393
|
+
// Other bodies' steps sounding: { until, d, shot }.
|
|
394
|
+
const otherSteps = [];
|
|
395
|
+
// Every one-shot not yet ended, to stop on the way out.
|
|
396
|
+
const shots = new Set();
|
|
397
|
+
// The scene's NPC actor ids, looked for again every 120 frames.
|
|
398
|
+
let npcIds = [];
|
|
399
|
+
let npcScene = null;
|
|
400
|
+
let npcAt = 0;
|
|
401
|
+
let frameNo = 0;
|
|
402
|
+
let lastAt = null;
|
|
403
|
+
/*
|
|
404
|
+
* RULE 1 (lateness): transport messages are buffered until a frame drains
|
|
405
|
+
* them. Set `settling` when hidden (visibilitychange), on a door trip,
|
|
406
|
+
* muted or at volume 0. Keep it set until TWO consecutive live frames have
|
|
407
|
+
* completed. While not live or settling, drop EVERYTHING processed for
|
|
408
|
+
* good and mark it seen: panel lines, speech labels, hub-sound one-shots
|
|
409
|
+
* (soundGate returns false), and footsteps. Count completed engine frames,
|
|
410
|
+
* after all systems, so drain order within a frame cannot change the rule.
|
|
411
|
+
* The first gesture does NOT set settling: before it, drop because the
|
|
412
|
+
* page is not activated; after it, play immediately if otherwise live.
|
|
413
|
+
* UI exceptions: a departure already started may finish into a trip;
|
|
414
|
+
* hiding or muting cuts it. Arrival alone waits for settling, for 3 s at
|
|
415
|
+
* most, and never waits for a gesture or through another interruption.
|
|
416
|
+
* RULE 2 (one voice per NPC line): the panel owns the voice of NPC X while
|
|
417
|
+
* open and for 10 s after closing or its last panel line. Voice NO private
|
|
418
|
+
* or public speech label on X in that window. Always voice panel lines
|
|
419
|
+
* (including repeats), subject to rule 1. Other NPCs' labels sound once by
|
|
420
|
+
* their existing per-label seen identity. Never compare panel/label text.
|
|
421
|
+
* INVARIANT C (activation is the page's, not the instance's): after a user
|
|
422
|
+
* gesture on this page, every later soundscape instance is activated.
|
|
423
|
+
*/
|
|
424
|
+
let frameOn = true;
|
|
425
|
+
let settling = 0;
|
|
426
|
+
let warned = false;
|
|
427
|
+
|
|
428
|
+
const level = () => (settings.muted ? 0 : settings.volume * MASTER);
|
|
429
|
+
const hidden = () => doc?.hidden === true;
|
|
430
|
+
const activated = () => gesturedPages.has(page) || nav?.userActivation?.hasBeenActive === true;
|
|
431
|
+
// The hub supplies its current trip state; stand-alone frame callers keep
|
|
432
|
+
// their explicit `on` until their next frame.
|
|
433
|
+
const blocked = () => (isOn ? isOn() : frameOn) !== true || hidden() || settings.muted || settings.volume <= 0;
|
|
434
|
+
const live = () => {
|
|
435
|
+
const off = blocked();
|
|
436
|
+
if (off) {
|
|
437
|
+
settling = 2;
|
|
438
|
+
}
|
|
439
|
+
return !disposed && !off && activated() && settling === 0;
|
|
440
|
+
};
|
|
441
|
+
// How loud the place's own sound files play: null before the player's first
|
|
442
|
+
// gesture (`sound.js` then starts nothing), 0 hidden or muted.
|
|
443
|
+
const filesLevel = () => (!activated() ? null : hidden() || settings.muted ? 0 : settings.volume);
|
|
444
|
+
|
|
445
|
+
// Nothing here may stop the hub's frame: what throws is dropped, and said once.
|
|
446
|
+
function failed(err) {
|
|
447
|
+
if (!warned) {
|
|
448
|
+
warned = true;
|
|
449
|
+
console.warn(`[hub] soundscape: ${err?.message ?? err}`);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
function build(context) {
|
|
454
|
+
const master = context.createGain();
|
|
455
|
+
master.gain.value = level();
|
|
456
|
+
const limiter = context.createDynamicsCompressor();
|
|
457
|
+
limiter.threshold.value = -10;
|
|
458
|
+
limiter.knee.value = 6;
|
|
459
|
+
limiter.ratio.value = 12;
|
|
460
|
+
limiter.attack.value = 0.003;
|
|
461
|
+
limiter.release.value = 0.15;
|
|
462
|
+
master.connect(limiter);
|
|
463
|
+
limiter.connect(context.destination);
|
|
464
|
+
const graph = { master, limiter };
|
|
465
|
+
for (const [name, gain] of Object.entries(BUS)) {
|
|
466
|
+
const bus = context.createGain();
|
|
467
|
+
bus.gain.value = gain;
|
|
468
|
+
bus.connect(master);
|
|
469
|
+
graph[name] = bus;
|
|
470
|
+
}
|
|
471
|
+
return graph;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// The context, running, or null: then whatever asked is dropped. Made the
|
|
475
|
+
// first time something would sound after the player has touched the page.
|
|
476
|
+
function ready(now) {
|
|
477
|
+
if (disposed || settings.muted || settings.volume <= 0 || hidden() || !activated()) {
|
|
478
|
+
return null;
|
|
479
|
+
}
|
|
480
|
+
if (!ctx) {
|
|
481
|
+
ctx = audio.getAudioContext?.() ?? null;
|
|
482
|
+
if (!ctx) {
|
|
483
|
+
return null;
|
|
484
|
+
}
|
|
485
|
+
audio.bindAudioResume?.();
|
|
486
|
+
out = build(ctx);
|
|
487
|
+
}
|
|
488
|
+
if (ctx.state !== 'running' || !Number.isFinite(ctx.currentTime)) {
|
|
489
|
+
if (now - resumeAt > 1000) {
|
|
490
|
+
resumeAt = now;
|
|
491
|
+
audio.resumeAudioContext?.();
|
|
492
|
+
}
|
|
493
|
+
return null;
|
|
494
|
+
}
|
|
495
|
+
return ctx;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
function release(nodes) {
|
|
499
|
+
for (const node of nodes) {
|
|
500
|
+
try {
|
|
501
|
+
node.disconnect();
|
|
502
|
+
} catch {
|
|
503
|
+
// Already out.
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
const ui = options.ui === true || options.cues === true ? makeUi({ ready, context: () => ctx, bus: () => out.ui, noise: noiseOf, live, canArrive: () => !disposed && !blocked() && activated(), failed }) : null;
|
|
509
|
+
const busker = options.cues === true ? makeBusker({ ready, context: () => ctx, bus: () => out.ui, failed, distanceGain }) : null;
|
|
510
|
+
const actions = options.cues === true ? makeActions(ui, cueVoices, busker) : null;
|
|
511
|
+
|
|
512
|
+
// --- babble ---
|
|
513
|
+
|
|
514
|
+
// A line stopped: a 20 ms fade and all three sources stopped within 30 ms,
|
|
515
|
+
// with every node released by the ending callback.
|
|
516
|
+
function cut(line) {
|
|
517
|
+
const at = lines.indexOf(line);
|
|
518
|
+
if (at >= 0) {
|
|
519
|
+
lines.splice(at, 1);
|
|
520
|
+
}
|
|
521
|
+
line.voice.stop(ctx.currentTime);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
function trackPanel(npc, now) {
|
|
525
|
+
if (panelNpc && panelNpc !== npc) {
|
|
526
|
+
panelUntil.set(panelNpc, now + PANEL_VOICE_MS);
|
|
527
|
+
}
|
|
528
|
+
panelNpc = npc;
|
|
529
|
+
for (const [id, until] of panelUntil) {
|
|
530
|
+
if (until <= now) {
|
|
531
|
+
panelUntil.delete(id);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
// Builds and schedules one line: `words` in `npc`'s voice at `d` metres (0:
|
|
537
|
+
// said to this player in the panel). Whether it may sound, and whose place
|
|
538
|
+
// it takes, is decided before this is called. Returns whether it started.
|
|
539
|
+
function startLine(context, props, npc, name, words, d) {
|
|
540
|
+
const loud = babbleGain(d);
|
|
541
|
+
const t0 = context.currentTime + 0.03;
|
|
542
|
+
if (!(loud > 0) || !finite(loud, t0)) { return false; }
|
|
543
|
+
let gain;
|
|
544
|
+
try {
|
|
545
|
+
gain = context.createGain();
|
|
546
|
+
gain.gain.value = loud;
|
|
547
|
+
gain.connect(out.voice);
|
|
548
|
+
const line = { npc, d, gain, loud, voice: null };
|
|
549
|
+
line.voice = simlish(context, gain, words, t0, { ...voiceOf(npc, name, props.voice, props.role, props.character), level: BABBLE_LEVEL }, () => {
|
|
550
|
+
release([gain]);
|
|
551
|
+
const at = lines.indexOf(line);
|
|
552
|
+
if (at >= 0) { lines.splice(at, 1); }
|
|
553
|
+
});
|
|
554
|
+
if (!line.voice) { release([gain]); return false; }
|
|
555
|
+
lines.push(line);
|
|
556
|
+
return true;
|
|
557
|
+
} catch (err) {
|
|
558
|
+
if (gain) { release([gain]); }
|
|
559
|
+
failed(err);
|
|
560
|
+
return false;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
// Makes room for a line at `d` metres from `npc`, or says there is none: a
|
|
565
|
+
// new line from the same NPC cuts its old one, and with VOICES_MAX sounding
|
|
566
|
+
// the farthest gives way to a nearer one only.
|
|
567
|
+
function roomFor(npc, d) {
|
|
568
|
+
for (let i = lines.length - 1; i >= 0; i -= 1) {
|
|
569
|
+
if (lines[i].npc === npc) {
|
|
570
|
+
cut(lines[i]);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
if (lines.length < VOICES_MAX) {
|
|
574
|
+
return true;
|
|
575
|
+
}
|
|
576
|
+
let far = lines[0];
|
|
577
|
+
for (const line of lines) {
|
|
578
|
+
if (line.d > far.d) {
|
|
579
|
+
far = line;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
if (!(far.d > d)) {
|
|
583
|
+
return false;
|
|
584
|
+
}
|
|
585
|
+
cut(far);
|
|
586
|
+
return true;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
// This frame's new public lines: the nearest VOICES_MAX are looked at, and
|
|
590
|
+
// only one that has a place is built -- forty NPCs speaking in one frame
|
|
591
|
+
// cost two voices, not forty made and thirty-eight thrown away.
|
|
592
|
+
function voiceWanted(scene, now) {
|
|
593
|
+
const context = ready(now);
|
|
594
|
+
if (context) {
|
|
595
|
+
linesWanted.sort((a, b) => a.d - b.d);
|
|
596
|
+
for (let i = 0; i < linesWanted.length && i < VOICES_MAX; i += 1) {
|
|
597
|
+
const w = linesWanted[i];
|
|
598
|
+
if (roomFor(w.id, w.d)) {
|
|
599
|
+
startLine(context, w.props, w.id, w.name, w.words, w.d);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
linesWanted.length = 0;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// How far `at` is from `me`, or Infinity where either is nowhere a number.
|
|
607
|
+
function apart(me, at) {
|
|
608
|
+
const d = me && at ? Math.hypot(at.x - me.x, at.y - me.y, at.z - me.z) : Infinity;
|
|
609
|
+
return Number.isFinite(d) ? d : Infinity;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
// The speech labels over NPCs (`hub.labels`, with this player's own over
|
|
613
|
+
// them): one that is new is voiced, by how far its NPC stands. The NPC this
|
|
614
|
+
// player is talking with says its lines in the panel (`say`), not here.
|
|
615
|
+
// `fresh`: whether a new label may be voiced; one that appeared while
|
|
616
|
+
// nothing could sound (before the first gesture, on a trip, hidden, muted)
|
|
617
|
+
// is taken as seen and never said late.
|
|
618
|
+
function hear(scene, me, talkingWith, fresh, now) {
|
|
619
|
+
const own = hub.labelsMe;
|
|
620
|
+
for (let pass = 0; pass < 2; pass += 1) {
|
|
621
|
+
const labels = pass === 0 ? own : hub.labels;
|
|
622
|
+
for (const id in labels) {
|
|
623
|
+
if (pass === 1 && id in own) {
|
|
624
|
+
continue;
|
|
625
|
+
}
|
|
626
|
+
const label = labels[id];
|
|
627
|
+
if (label?.style !== 'speech' || typeof label.text !== 'string') {
|
|
628
|
+
continue;
|
|
629
|
+
}
|
|
630
|
+
const actor = scene.getActor(id);
|
|
631
|
+
const props = actor?.components?.HubNpc;
|
|
632
|
+
if (!props) {
|
|
633
|
+
continue;
|
|
634
|
+
}
|
|
635
|
+
const was = seen.get(id);
|
|
636
|
+
if (was && was.text === label.text) {
|
|
637
|
+
was.frame = frameNo;
|
|
638
|
+
continue;
|
|
639
|
+
}
|
|
640
|
+
seen.set(id, { text: label.text, frame: frameNo });
|
|
641
|
+
if (!fresh || id === talkingWith || now < (panelUntil.get(id) ?? -Infinity)) {
|
|
642
|
+
continue;
|
|
643
|
+
}
|
|
644
|
+
const name = typeof props.name === 'string' ? props.name : '';
|
|
645
|
+
const words = wordsOf(label.text, name);
|
|
646
|
+
const d = Math.max(apart(me, actor.components.Transform), 0.001);
|
|
647
|
+
if (!(babbleGain(d) > 0)) {
|
|
648
|
+
continue;
|
|
649
|
+
}
|
|
650
|
+
linesWanted.push({ id, props, name, words, d });
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
for (const [id, was] of seen) {
|
|
654
|
+
if (was.frame !== frameNo) {
|
|
655
|
+
seen.delete(id);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
if (linesWanted.length) {
|
|
659
|
+
voiceWanted(scene, now);
|
|
660
|
+
}
|
|
661
|
+
// A public line follows the listener: louder as they walk up to it.
|
|
662
|
+
for (const line of lines) {
|
|
663
|
+
if (line.d === 0) {
|
|
664
|
+
continue;
|
|
665
|
+
}
|
|
666
|
+
const d = Math.max(apart(me, scene.getActor(line.npc)?.components.Transform), 0.001);
|
|
667
|
+
const loud = babbleGain(d);
|
|
668
|
+
line.d = d;
|
|
669
|
+
if (finite(loud) && Math.abs(loud - line.loud) > 0.03) {
|
|
670
|
+
line.loud = loud;
|
|
671
|
+
line.gain.gain.setTargetAtTime(loud, ctx.currentTime, 0.05);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
// --- steps ---
|
|
677
|
+
|
|
678
|
+
function stopShot(shot) {
|
|
679
|
+
shots.delete(shot);
|
|
680
|
+
try {
|
|
681
|
+
shot.src.stop();
|
|
682
|
+
shot.low?.stop();
|
|
683
|
+
} catch {
|
|
684
|
+
// Not started, or over.
|
|
685
|
+
}
|
|
686
|
+
release(shot.nodes);
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
// A burst of the shared noise through `type` at `f`, and a thump under it,
|
|
690
|
+
// into the steps bus at `gain`; returns the one-shot, or null where a
|
|
691
|
+
// number it was given is not one (nothing is made then).
|
|
692
|
+
function burst(context, type, f, q, dur, gain, thump, thumpGain, sweepTo = 0, lowCut = 0) {
|
|
693
|
+
const t = context.currentTime;
|
|
694
|
+
if (!finite(t, f, q, dur, gain, thump, thumpGain, sweepTo, lowCut) || !(f > 0) || !(dur > 0) || !(gain > 0) || sweepTo < 0 || (thumpGain > 0 && !(thump > 0))) {
|
|
695
|
+
return null;
|
|
696
|
+
}
|
|
697
|
+
const nodes = [];
|
|
698
|
+
const made = (node) => {
|
|
699
|
+
nodes.push(node);
|
|
700
|
+
return node;
|
|
701
|
+
};
|
|
702
|
+
try {
|
|
703
|
+
const src = made(context.createBufferSource());
|
|
704
|
+
src.buffer = noiseOf(context);
|
|
705
|
+
const filter = made(context.createBiquadFilter());
|
|
706
|
+
filter.type = type;
|
|
707
|
+
filter.frequency.setValueAtTime(f, t);
|
|
708
|
+
if (sweepTo) {
|
|
709
|
+
filter.frequency.exponentialRampToValueAtTime(sweepTo, t + dur);
|
|
710
|
+
}
|
|
711
|
+
filter.Q.value = q;
|
|
712
|
+
const env = made(context.createGain());
|
|
713
|
+
env.gain.setValueAtTime(0, t);
|
|
714
|
+
env.gain.linearRampToValueAtTime(gain, t + (sweepTo ? dur * 0.4 : 0.004));
|
|
715
|
+
env.gain.exponentialRampToValueAtTime(0.0008, t + dur);
|
|
716
|
+
src.connect(filter);
|
|
717
|
+
if (lowCut >= 150) {
|
|
718
|
+
const cut = made(context.createBiquadFilter());
|
|
719
|
+
cut.type = 'highpass';
|
|
720
|
+
cut.frequency.value = lowCut;
|
|
721
|
+
cut.Q.value = 0.7;
|
|
722
|
+
filter.connect(cut);
|
|
723
|
+
cut.connect(env);
|
|
724
|
+
} else {
|
|
725
|
+
filter.connect(env);
|
|
726
|
+
}
|
|
727
|
+
env.connect(out.steps);
|
|
728
|
+
let low = null;
|
|
729
|
+
if (thumpGain > 0) {
|
|
730
|
+
low = made(context.createOscillator());
|
|
731
|
+
low.type = 'sine';
|
|
732
|
+
low.frequency.setValueAtTime(thump, t);
|
|
733
|
+
low.frequency.exponentialRampToValueAtTime(thump * 0.55, t + 0.045);
|
|
734
|
+
const lowEnv = made(context.createGain());
|
|
735
|
+
lowEnv.gain.setValueAtTime(0, t);
|
|
736
|
+
lowEnv.gain.linearRampToValueAtTime(thumpGain, t + 0.005);
|
|
737
|
+
lowEnv.gain.exponentialRampToValueAtTime(0.0008, t + 0.055);
|
|
738
|
+
low.connect(lowEnv);
|
|
739
|
+
lowEnv.connect(out.steps);
|
|
740
|
+
low.start(t);
|
|
741
|
+
low.stop(t + 0.065);
|
|
742
|
+
}
|
|
743
|
+
const shot = { nodes, src, low };
|
|
744
|
+
shots.add(shot);
|
|
745
|
+
src.onended = () => {
|
|
746
|
+
shots.delete(shot);
|
|
747
|
+
release(nodes);
|
|
748
|
+
};
|
|
749
|
+
// The noise from anywhere in the buffer, so no two steps are one sample.
|
|
750
|
+
src.start(t, clamp(random(), 0, 1) * 1.2 || 0, Math.max(dur, 0.1) + 0.02);
|
|
751
|
+
return shot;
|
|
752
|
+
} catch (err) {
|
|
753
|
+
release(nodes);
|
|
754
|
+
failed(err);
|
|
755
|
+
return null;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
// A footfall on `surface` at `gain` (1 the player's own); `heavy` a landing
|
|
760
|
+
// (how hard, 0-1), or -1 for a plain step.
|
|
761
|
+
function footfall(context, surface, foot, gain, heavy = -1) {
|
|
762
|
+
const s = Object.hasOwn(SURFACES, surface) ? SURFACES[surface] : SURFACES[DEFAULT_SURFACE];
|
|
763
|
+
const tone = (foot ? 1 : 0.92) * (0.94 + random() * 0.12);
|
|
764
|
+
const loud = gain * (0.88 + random() * 0.24);
|
|
765
|
+
if (heavy < 0) {
|
|
766
|
+
// Another body's step is the burst alone.
|
|
767
|
+
return burst(context, s.type, s.f * tone, s.q, s.dur, s.gain * loud, s.thump * tone, gain >= 1 ? s.thumpGain * loud : 0, 0, s.lowCut);
|
|
768
|
+
}
|
|
769
|
+
const hard = 1 + heavy * 0.6;
|
|
770
|
+
return burst(context, s.type, s.f * 0.8, s.q, s.dur * 1.5, s.gain * gain * hard, s.thump * 0.85, Math.min(0.3, (s.thumpGain + 0.072) * gain * hard), 0, s.lowCut);
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
// The player's own step, jump or landing.
|
|
774
|
+
function playOwn(event, s, x, z, now) {
|
|
775
|
+
const context = ready(now);
|
|
776
|
+
if (!context) {
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
if (event === JUMP) {
|
|
780
|
+
// A small whoosh upward, and no thump.
|
|
781
|
+
burst(context, 'bandpass', 500, 1.4, 0.13, 0.22, 0, 0, 1900);
|
|
782
|
+
} else if (event === LAND) {
|
|
783
|
+
footfall(context, map ? map.ownSurface(x, z) : surfaceAt(x, z), s.foot, 1, finite(s.fall) ? clamp((s.fall - 4) / 10, 0, 1) : 0);
|
|
784
|
+
} else {
|
|
785
|
+
footfall(context, map ? map.ownSurface(x, z) : surfaceAt(x, z), s.foot, 1);
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
// This frame's steps of other bodies, nearest first: OTHER_STEPS_MAX sound
|
|
790
|
+
// at once, a nearer one takes the place of the farthest still sounding
|
|
791
|
+
// (which is stopped, not faded under it), and nothing is built for a step
|
|
792
|
+
// that has no place -- forty walkers in step cost four bursts.
|
|
793
|
+
function playWanted(now) {
|
|
794
|
+
const context = ready(now);
|
|
795
|
+
if (context) {
|
|
796
|
+
const t = context.currentTime;
|
|
797
|
+
for (let i = otherSteps.length - 1; i >= 0; i -= 1) {
|
|
798
|
+
if (otherSteps[i].until <= t || !shots.has(otherSteps[i].shot)) {
|
|
799
|
+
otherSteps.splice(i, 1);
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
stepsWanted.sort((a, b) => a.d - b.d);
|
|
803
|
+
for (const w of stepsWanted) {
|
|
804
|
+
const gain = OTHERS_GAIN * (1 - w.d / OTHERS_RADIUS_M);
|
|
805
|
+
if (!(gain > 0)) {
|
|
806
|
+
break;
|
|
807
|
+
}
|
|
808
|
+
if (otherSteps.length >= OTHER_STEPS_MAX) {
|
|
809
|
+
let far = 0;
|
|
810
|
+
for (let i = 1; i < otherSteps.length; i += 1) {
|
|
811
|
+
if (otherSteps[i].d > otherSteps[far].d) {
|
|
812
|
+
far = i;
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
if (!(otherSteps[far].d > w.d)) {
|
|
816
|
+
break;
|
|
817
|
+
}
|
|
818
|
+
stopShot(otherSteps.splice(far, 1)[0].shot);
|
|
819
|
+
}
|
|
820
|
+
const surface = map ? map.surfaceAt(w.x, w.z, steppers.get(w.id)?.zone) : surfaceAt(w.x, w.z);
|
|
821
|
+
const shot = w.event === LAND ? footfall(context, surface, w.foot, gain, 0) : footfall(context, surface, w.foot, gain);
|
|
822
|
+
if (shot) {
|
|
823
|
+
otherSteps.push({ until: t + 0.12, d: w.d, shot });
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
stepsWanted.length = 0;
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
function walkOther(scene, id, me, dt, live) {
|
|
831
|
+
const t = scene.getActor(id)?.components.Transform;
|
|
832
|
+
// A hidden actor waits far under the ground.
|
|
833
|
+
if (!t || t.y < -100 || hub.hidden.has(id)) {
|
|
834
|
+
return;
|
|
835
|
+
}
|
|
836
|
+
const d = apart(me, t);
|
|
837
|
+
if (!(d <= OTHERS_RADIUS_M + 2)) {
|
|
838
|
+
return;
|
|
839
|
+
}
|
|
840
|
+
let s = steppers.get(id);
|
|
841
|
+
if (!s) {
|
|
842
|
+
s = makeStepper();
|
|
843
|
+
steppers.set(id, s);
|
|
844
|
+
}
|
|
845
|
+
s.seen = frameNo;
|
|
846
|
+
if (map) {
|
|
847
|
+
s.zone = map.zoneAt(t.x, t.z, s.zone);
|
|
848
|
+
}
|
|
849
|
+
const event = stepFrame(s, t.x, t.y, t.z, dt);
|
|
850
|
+
if (event && live && d < OTHERS_RADIUS_M) {
|
|
851
|
+
stepsWanted.push({ id, event, foot: s.foot, x: t.x, z: t.z, d: Math.max(d, 0.001) });
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
function walk(scene, mp, local, dt, live, now) {
|
|
856
|
+
const me = local?.components.Transform ?? null;
|
|
857
|
+
if (!me) {
|
|
858
|
+
mine.has = false;
|
|
859
|
+
return;
|
|
860
|
+
}
|
|
861
|
+
if (hub.hidden.has(local.id)) {
|
|
862
|
+
mine.has = false;
|
|
863
|
+
} else {
|
|
864
|
+
const grounded = groundedOf(scene, local);
|
|
865
|
+
let vy = null;
|
|
866
|
+
try {
|
|
867
|
+
vy = grounded === null ? null : (scene.physics3d.getVelocity?.(local)?.y ?? null);
|
|
868
|
+
} catch {
|
|
869
|
+
vy = null;
|
|
870
|
+
}
|
|
871
|
+
const event = stepFrame(mine, me.x, me.y, me.z, dt, grounded, finite(vy) ? vy : null);
|
|
872
|
+
if (event && live) {
|
|
873
|
+
playOwn(event, mine, me.x, me.z, now);
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
const actors = mp?.avatars?.actors;
|
|
877
|
+
if (actors) {
|
|
878
|
+
for (const actorId of actors.values()) {
|
|
879
|
+
walkOther(scene, actorId, me, dt, live);
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
if (scene !== npcScene || frameNo - npcAt > 120) {
|
|
883
|
+
npcScene = scene;
|
|
884
|
+
npcAt = frameNo;
|
|
885
|
+
npcIds = [];
|
|
886
|
+
for (const actor of scene.getActors?.() ?? []) {
|
|
887
|
+
if (actor.components?.HubNpc) {
|
|
888
|
+
npcIds.push(actor.id);
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
for (let i = 0; i < npcIds.length; i += 1) {
|
|
893
|
+
walkOther(scene, npcIds[i], me, dt, live);
|
|
894
|
+
}
|
|
895
|
+
if (stepsWanted.length) {
|
|
896
|
+
playWanted(now);
|
|
897
|
+
}
|
|
898
|
+
if (frameNo % 64 === 0) {
|
|
899
|
+
for (const [id, s] of steppers) {
|
|
900
|
+
if (s.seen < frameNo - 64) {
|
|
901
|
+
steppers.delete(id);
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
// --- all of it ---
|
|
908
|
+
|
|
909
|
+
function quiet(departing = false) {
|
|
910
|
+
ambience?.quiet();
|
|
911
|
+
if (busker) { busker.quiet(); }
|
|
912
|
+
ui?.quiet(departing && !hidden() && !settings.muted && settings.volume > 0 && activated());
|
|
913
|
+
if (actions && hub.cueEvents) {
|
|
914
|
+
hub.cueEvents.length = 0;
|
|
915
|
+
}
|
|
916
|
+
for (const line of [...lines]) {
|
|
917
|
+
cut(line);
|
|
918
|
+
}
|
|
919
|
+
for (const shot of [...shots]) {
|
|
920
|
+
stopShot(shot);
|
|
921
|
+
}
|
|
922
|
+
otherSteps.length = 0;
|
|
923
|
+
linesWanted.length = 0;
|
|
924
|
+
stepsWanted.length = 0;
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
function apply() {
|
|
928
|
+
try {
|
|
929
|
+
if (out) {
|
|
930
|
+
const t = ctx.currentTime;
|
|
931
|
+
out.master.gain.cancelScheduledValues(t);
|
|
932
|
+
out.master.gain.setTargetAtTime(hidden() ? 0 : level(), t, 0.02);
|
|
933
|
+
}
|
|
934
|
+
if (settings.muted || settings.volume <= 0) {
|
|
935
|
+
settling = 2;
|
|
936
|
+
quiet();
|
|
937
|
+
}
|
|
938
|
+
} catch (err) {
|
|
939
|
+
failed(err);
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
const onVisibility = () => {
|
|
944
|
+
try {
|
|
945
|
+
if (hidden()) {
|
|
946
|
+
settling = 2;
|
|
947
|
+
quiet();
|
|
948
|
+
onHide();
|
|
949
|
+
}
|
|
950
|
+
} catch (err) {
|
|
951
|
+
failed(err);
|
|
952
|
+
}
|
|
953
|
+
apply();
|
|
954
|
+
};
|
|
955
|
+
doc?.addEventListener?.('visibilitychange', onVisibility);
|
|
956
|
+
// The first tap or key, for a browser that does not say whether there was one.
|
|
957
|
+
const onGesture = () => {
|
|
958
|
+
gesturedPages.add(page);
|
|
959
|
+
win?.removeEventListener?.('pointerdown', onGesture, true);
|
|
960
|
+
win?.removeEventListener?.('keydown', onGesture, true);
|
|
961
|
+
};
|
|
962
|
+
if (!nav?.userActivation && !gesturedPages.has(page)) {
|
|
963
|
+
win?.addEventListener?.('pointerdown', onGesture, true);
|
|
964
|
+
win?.addEventListener?.('keydown', onGesture, true);
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
function run(scene, mp, local, on, talkingWith, now) {
|
|
968
|
+
frameNo += 1;
|
|
969
|
+
const dt = lastAt === null ? 0 : (now - lastAt) / 1000;
|
|
970
|
+
lastAt = now;
|
|
971
|
+
frameOn = on === true;
|
|
972
|
+
const liveNow = live();
|
|
973
|
+
trackPanel(talkingWith, now);
|
|
974
|
+
if (busker) { busker.frame(scene, local, now, liveNow); }
|
|
975
|
+
if (!liveNow) {
|
|
976
|
+
if (ui) {
|
|
977
|
+
quiet((isOn ? isOn() : frameOn) === false);
|
|
978
|
+
} else {
|
|
979
|
+
quiet();
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
if (ui) {
|
|
983
|
+
ui.frame(now, liveNow);
|
|
984
|
+
}
|
|
985
|
+
if (map) {
|
|
986
|
+
if (mapScene !== scene) {
|
|
987
|
+
ambience?.quiet();
|
|
988
|
+
mapScene = scene;
|
|
989
|
+
}
|
|
990
|
+
map.read(scene);
|
|
991
|
+
const me = local?.components.Transform;
|
|
992
|
+
if (me) {
|
|
993
|
+
map.update(me.x, me.z);
|
|
994
|
+
if (ambience && liveNow && !hub.hidden.has(local.id) && Number.isFinite(me.x) && Number.isFinite(me.y) && Number.isFinite(me.z)) {
|
|
995
|
+
const context = ready(now);
|
|
996
|
+
if (context) {
|
|
997
|
+
ambience.frame(context, out.ambience, map.bed(), map.spotAt(me.x, me.z));
|
|
998
|
+
}
|
|
999
|
+
} else {
|
|
1000
|
+
ambience?.quiet();
|
|
1001
|
+
}
|
|
1002
|
+
} else {
|
|
1003
|
+
ambience?.quiet();
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
if (want.babble) {
|
|
1007
|
+
hear(scene, local?.components.Transform ?? null, talkingWith, liveNow, now);
|
|
1008
|
+
}
|
|
1009
|
+
if (want.steps) {
|
|
1010
|
+
walk(scene, mp, local, finite(dt) ? dt : 0, liveNow, now);
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
return {
|
|
1015
|
+
// Also gates file one-shots when the transport drains, including settling.
|
|
1016
|
+
live,
|
|
1017
|
+
// Only the new ui sub-key makes callbacks. Arrival alone waits for
|
|
1018
|
+
// settling; an ordinary chip, departure or activity cue never waits.
|
|
1019
|
+
...(options.ui === true ? {
|
|
1020
|
+
cue(name, now) {
|
|
1021
|
+
try {
|
|
1022
|
+
return ui.cue(name, now);
|
|
1023
|
+
} catch (err) {
|
|
1024
|
+
failed(err);
|
|
1025
|
+
return false;
|
|
1026
|
+
}
|
|
1027
|
+
},
|
|
1028
|
+
uiArrival(now) {
|
|
1029
|
+
try {
|
|
1030
|
+
ui.arrive(now);
|
|
1031
|
+
} catch (err) {
|
|
1032
|
+
failed(err);
|
|
1033
|
+
}
|
|
1034
|
+
},
|
|
1035
|
+
} : {}),
|
|
1036
|
+
// Registered after every other engine system. The recovery frame stays
|
|
1037
|
+
// silent through a drain after `frame`, and those late labels/poses are
|
|
1038
|
+
// marked seen before counting this live frame as completed.
|
|
1039
|
+
completeFrame(scene, mp, local, on, talkingWith, now) {
|
|
1040
|
+
try {
|
|
1041
|
+
frameOn = on === true;
|
|
1042
|
+
trackPanel(talkingWith, now);
|
|
1043
|
+
const liveNow = live();
|
|
1044
|
+
if (ui) {
|
|
1045
|
+
ui.frame(now, liveNow, hub.place && !hub.place.result ? hub.hudMe : null, options.ui === true);
|
|
1046
|
+
}
|
|
1047
|
+
if (actions) {
|
|
1048
|
+
actions.frame(scene, mp, local, talkingWith, now, liveNow);
|
|
1049
|
+
busker.frame(scene, local, now, liveNow); // This frame's sends start now.
|
|
1050
|
+
}
|
|
1051
|
+
if (want.babble) {
|
|
1052
|
+
hear(scene, local?.components.Transform ?? null, talkingWith, liveNow, now);
|
|
1053
|
+
}
|
|
1054
|
+
if (!liveNow && want.steps) {
|
|
1055
|
+
walk(scene, mp, local, 0, false, now);
|
|
1056
|
+
}
|
|
1057
|
+
if (!disposed && !blocked() && activated()) {
|
|
1058
|
+
settling = Math.max(0, settling - 1);
|
|
1059
|
+
}
|
|
1060
|
+
} catch (err) {
|
|
1061
|
+
failed(err);
|
|
1062
|
+
}
|
|
1063
|
+
},
|
|
1064
|
+
// One frame. `on`: whether the place may sound now (not during a trip, as
|
|
1065
|
+
// `sound.js`); `talkingWith` the NPC whose words are in the open panel.
|
|
1066
|
+
// Returns how loud the place's own sound files play, 0 to 1, or null
|
|
1067
|
+
// before the player's first gesture: `sound.js` starts nothing then.
|
|
1068
|
+
// Never throws: a sound that cannot be made is dropped.
|
|
1069
|
+
frame(scene, mp, local, on, talkingWith, now) {
|
|
1070
|
+
try {
|
|
1071
|
+
run(scene, mp, local, on, talkingWith, now);
|
|
1072
|
+
} catch (err) {
|
|
1073
|
+
failed(err);
|
|
1074
|
+
linesWanted.length = 0;
|
|
1075
|
+
stepsWanted.length = 0;
|
|
1076
|
+
}
|
|
1077
|
+
return filesLevel();
|
|
1078
|
+
},
|
|
1079
|
+
// A line the NPC this player is talking with said in the panel: theirs
|
|
1080
|
+
// alone, at full voice. One that comes while nothing may sound (hidden,
|
|
1081
|
+
// a trip, before a gesture, or settling) is dropped, not kept.
|
|
1082
|
+
say(scene, npc, text, now) {
|
|
1083
|
+
try {
|
|
1084
|
+
if (!want.babble || !npc || typeof text !== 'string' || disposed) {
|
|
1085
|
+
return;
|
|
1086
|
+
}
|
|
1087
|
+
const props = scene?.getActor?.(npc)?.components?.HubNpc;
|
|
1088
|
+
if (!props) {
|
|
1089
|
+
return;
|
|
1090
|
+
}
|
|
1091
|
+
panelUntil.set(npc, now + PANEL_VOICE_MS);
|
|
1092
|
+
if (!live()) {
|
|
1093
|
+
return;
|
|
1094
|
+
}
|
|
1095
|
+
const name = typeof props.name === 'string' ? props.name : '';
|
|
1096
|
+
const words = wordsOf(text, name);
|
|
1097
|
+
const context = ready(now);
|
|
1098
|
+
if (context && roomFor(npc, 0)) {
|
|
1099
|
+
startLine(context, props, npc, name, words, 0);
|
|
1100
|
+
}
|
|
1101
|
+
} catch (err) {
|
|
1102
|
+
failed(err);
|
|
1103
|
+
}
|
|
1104
|
+
},
|
|
1105
|
+
settings: () => settings,
|
|
1106
|
+
setVolume(volume) {
|
|
1107
|
+
const v = Number(volume);
|
|
1108
|
+
settings.volume = Number.isNaN(v) ? 0 : clamp(v, 0, 1);
|
|
1109
|
+
writeSettings(storage, settings);
|
|
1110
|
+
apply();
|
|
1111
|
+
},
|
|
1112
|
+
setMuted(muted) {
|
|
1113
|
+
settings.muted = muted === true;
|
|
1114
|
+
writeSettings(storage, settings);
|
|
1115
|
+
apply();
|
|
1116
|
+
},
|
|
1117
|
+
// What is sounding, for the tests and a phone's readout.
|
|
1118
|
+
counts: () => ({ lines: lines.length, shots: shots.size, others: otherSteps.length, steppers: steppers.size, panels: panelUntil.size }),
|
|
1119
|
+
// Optional ground and bed readout; the original counts keep their shape.
|
|
1120
|
+
ambienceCounts: () => ambience?.counts() ?? { beds: 0, spot: 0, nodes: 0 },
|
|
1121
|
+
uiCounts: () => ui?.counts() ?? { voices: 0, nodes: 0, arrival: false },
|
|
1122
|
+
...(busker ? { buskerCounts: () => busker.counts() } : {}),
|
|
1123
|
+
zone: () => map?.zone() ?? null,
|
|
1124
|
+
surfaceAt: (x, z) => map ? map.ownSurface(x, z) : surfaceAt(x, z),
|
|
1125
|
+
dispose() {
|
|
1126
|
+
if (disposed) {
|
|
1127
|
+
return;
|
|
1128
|
+
}
|
|
1129
|
+
doc?.removeEventListener?.('visibilitychange', onVisibility);
|
|
1130
|
+
win?.removeEventListener?.('pointerdown', onGesture, true);
|
|
1131
|
+
win?.removeEventListener?.('keydown', onGesture, true);
|
|
1132
|
+
try {
|
|
1133
|
+
if (ctx) {
|
|
1134
|
+
quiet();
|
|
1135
|
+
release(Object.values(out));
|
|
1136
|
+
}
|
|
1137
|
+
ui?.dispose();
|
|
1138
|
+
if (busker) { busker.dispose(); }
|
|
1139
|
+
} catch (err) {
|
|
1140
|
+
failed(err);
|
|
1141
|
+
}
|
|
1142
|
+
disposed = true;
|
|
1143
|
+
out = null;
|
|
1144
|
+
ctx = null;
|
|
1145
|
+
seen.clear();
|
|
1146
|
+
panelUntil.clear();
|
|
1147
|
+
panelNpc = null;
|
|
1148
|
+
steppers.clear();
|
|
1149
|
+
},
|
|
1150
|
+
};
|
|
1151
|
+
}
|