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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { HUD_COPY_STYLE, firstPromptSentence, promptShift, warnHudCopy } from './hudCopy.js';
|
|
1
2
|
// The hub's own chrome: DOM drawn by the place, never by a game's content, so a
|
|
2
3
|
// game cannot hide or fake it (contract: "Hub-owned UI"). The door cover, the
|
|
3
4
|
// Back control, the declared HUD, actor labels and speech, the result ribbon,
|
|
@@ -7,17 +8,37 @@
|
|
|
7
8
|
// reports), the pointers to friends out of sight,
|
|
8
9
|
// the Grab / Throw button (a place with `grab`, v1.3), the emote picker and
|
|
9
10
|
// the Sit / Stand button (a place with `idle`, v1.6), an arcade cabinet's
|
|
10
|
-
// board card (v1.7),
|
|
11
|
+
// board card (v1.7), the "Stuck?" chip and Doors row (a deck with `hub.stuck`,
|
|
12
|
+
// v1.33), the sound control (a deck with `hub.soundscape`), and the frame-rate
|
|
13
|
+
// readout behind `?hubstats`. In a place
|
|
11
14
|
// that asks (`hud.clear`, v1.26) the HUD is kept short and what is drawn over
|
|
12
15
|
// the world is kept out from under it (`hudClear.js`).
|
|
13
16
|
|
|
17
|
+
import * as Colors from './avatarColors.js';
|
|
18
|
+
import { AVATAR_FACES } from './avatarFaces.js';
|
|
14
19
|
import { cardMode, makeCardView, tapCard } from './cabinets.js';
|
|
15
20
|
import { boxAt, fitPx, hudLayout, pushBelow } from './hudClear.js';
|
|
16
|
-
import {
|
|
21
|
+
import { chipShift } from './stuck.js';
|
|
22
|
+
import { toastBand } from './toastBand.js';
|
|
23
|
+
import { emoteBubbleShift, placeEmoteBubble } from './emoteBubble.js';
|
|
24
|
+
import { makeActionOverflow } from './actionOverflow.js';
|
|
25
|
+
import { actionLayout } from './actionLayout.js';
|
|
26
|
+
import { guardScrollKeys, takeKeys } from './keys.js';
|
|
27
|
+
import { validPrivateText } from '../privateText.js';
|
|
28
|
+
import { menuIcon } from './menuIcons.js';
|
|
29
|
+
import { drawMenuRows } from './menuRows.js';
|
|
30
|
+
import { landscapeViewport, watchViewport } from './landscapeLayout.js';
|
|
31
|
+
import { loadingCover } from './loadingCover.js';
|
|
32
|
+
|
|
33
|
+
import { makeSafeLayout } from './safeLayout.js';
|
|
34
|
+
import { makeWorldLayout } from './worldLabels.js';
|
|
35
|
+
import { makeLayoutCache, placementCache } from './layoutCache.js';
|
|
36
|
+
|
|
37
|
+
export { landscapeViewport } from './landscapeLayout.js';
|
|
17
38
|
|
|
18
39
|
const Z = 2147480000;
|
|
19
40
|
|
|
20
|
-
function
|
|
41
|
+
function createElement(tag, style, parent = document.body) {
|
|
21
42
|
const node = document.createElement(tag);
|
|
22
43
|
Object.assign(node.style, style);
|
|
23
44
|
parent.appendChild(node);
|
|
@@ -29,21 +50,61 @@ function el(tag, style, parent = document.body) {
|
|
|
29
50
|
// pale sky as it does over a dark street.
|
|
30
51
|
const BARE_TEXT_SHADOW = '0 0 2px rgba(0,0,0,0.95), 0 0 2px rgba(0,0,0,0.95), 0 1px 4px rgba(0,0,0,0.75), 0 0 10px rgba(0,0,0,0.45)';
|
|
31
52
|
|
|
32
|
-
|
|
53
|
+
// The character picker's grid: four cells across, each a tap target this wide
|
|
54
|
+
// (and 62 px tall).
|
|
55
|
+
const PICKER_COLUMNS = 4;
|
|
56
|
+
const PICKER_CELL_PX = 64;
|
|
57
|
+
|
|
58
|
+
// The talk panel's log counts as at its end within this many pixels of it.
|
|
59
|
+
const TALK_END_PX = 8;
|
|
60
|
+
|
|
61
|
+
export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount, onPerson = () => {}, onJumpDoor = () => {}, onReport = () => {}, onAsk = () => {}, onHeart = () => {}, onLeaveParty = () => {}, onReportChat = () => {}, onBlockChat = () => {}, onChip, safeInsets = false, worldLabelsDefault = false }) {
|
|
62
|
+
const geometry = makeLayoutCache();
|
|
63
|
+
const placeActions = placementCache();
|
|
64
|
+
const positionLayers = new WeakSet();
|
|
65
|
+
function el(tag, style, parent = document.body) {
|
|
66
|
+
const node = createElement(tag, style, parent);
|
|
67
|
+
if (style.position === 'absolute' || style.position === 'fixed') {
|
|
68
|
+
geometry.register(node, { positioned: positionLayers.has(parent) || style.transform === 'translate(-50%, -100%)' });
|
|
69
|
+
}
|
|
70
|
+
const remove = node.remove.bind(node);
|
|
71
|
+
node.remove = () => {geometry.unregister(node); remove();};
|
|
72
|
+
const replace = node.replaceChildren?.bind(node);
|
|
73
|
+
if (replace) {node.replaceChildren = (...children) => {
|
|
74
|
+
for (const child of node.children) {geometry.unregister(child);}
|
|
75
|
+
replace(...children);
|
|
76
|
+
};}
|
|
77
|
+
return node;
|
|
78
|
+
}
|
|
79
|
+
let canvasSource = null;
|
|
80
|
+
let safeLayout = null;
|
|
81
|
+
let worldLayout = null;
|
|
82
|
+
let worldViewport = null;
|
|
83
|
+
let worldAvatar = null;
|
|
84
|
+
// The avatar box snapped outward to 16 px, so a walking player does not
|
|
85
|
+
// re-solve or shuffle the action rail every frame.
|
|
86
|
+
let avatarReserve = null;
|
|
87
|
+
const worldObstacles = () => worldAvatar ? [worldAvatar] : [];
|
|
88
|
+
const worldView = () => ({ ...(safeLayout?.view() ?? { w: geometry.view().w, h: geometry.view().h }), ...(worldViewport ? { world: worldViewport } : {}) });
|
|
89
|
+
const edge = (side, px) => safeInsets ? `max(${px}px, env(safe-area-inset-${side}))` : `${px}px`;
|
|
33
90
|
const unguardKeys = guardScrollKeys();
|
|
91
|
+
takeKeys();
|
|
34
92
|
// A desktop stage (a mouse, room to spare): NPC lines are narrower and the
|
|
35
93
|
// talk panel sits in the bottom-left corner, clear of the avatar. Phones
|
|
36
94
|
// and narrow stages keep the layout they were tuned on.
|
|
37
95
|
const desktopQuery = globalThis.matchMedia?.('(pointer: fine) and (min-width: 700px)') ?? null;
|
|
38
96
|
const desktop = () => desktopQuery?.matches === true;
|
|
39
97
|
const root = el('div', { position: 'fixed', inset: '0', pointerEvents: 'none', zIndex: String(Z), font: '600 15px/1.3 system-ui, sans-serif', color: '#fff' });
|
|
98
|
+
if (loadingCover) { root.setAttribute('data-hub-loading-chrome', ''); }
|
|
40
99
|
|
|
41
100
|
// The door cover: a dark warm field the door animation fades to, with the
|
|
42
101
|
// destination named in it. It sits over everything while a scene swaps.
|
|
43
102
|
const cover = el('div', { position: 'absolute', inset: '0', opacity: '0', background: 'radial-gradient(ellipse at center, #2a1d14 0%, #0b0806 70%)', display: 'flex', alignItems: 'center', justifyContent: 'center', transition: 'none' }, root);
|
|
44
103
|
const coverText = el('div', { opacity: '0.85', letterSpacing: '0.12em', textTransform: 'uppercase', fontSize: '14px', color: '#e9c48f' }, cover);
|
|
45
104
|
|
|
46
|
-
|
|
105
|
+
let coverLine = null;
|
|
106
|
+
|
|
107
|
+
const back = el('button', { position: 'absolute', top: 'max(12px, env(safe-area-inset-top))', left: edge('left', 12), pointerEvents: 'auto', padding: '9px 16px 9px 12px', borderRadius: '22px', border: '1px solid rgba(255,255,255,0.35)', background: 'rgba(20,16,12,0.72)', color: '#fff', font: 'inherit', display: 'none', cursor: 'pointer' }, root);
|
|
47
108
|
back.textContent = '‹ Town';
|
|
48
109
|
back.addEventListener('pointerdown', (event) => {
|
|
49
110
|
event.stopPropagation();
|
|
@@ -51,11 +112,32 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
51
112
|
});
|
|
52
113
|
|
|
53
114
|
const hud = el('div', { position: 'absolute', top: 'max(12px, env(safe-area-inset-top))', left: '50%', transform: 'translateX(-50%)', textAlign: 'center', textShadow: BARE_TEXT_SHADOW, display: 'none', maxWidth: '70vw' }, root);
|
|
54
|
-
const hudTitle = el('div', { fontSize: '13px',
|
|
55
|
-
const hudBig = el('div', { fontSize: '56px', fontWeight: '800', lineHeight: '1.05' }, hud);
|
|
56
|
-
const hudText = el('div', { fontSize: '14px', fontWeight: '500' },
|
|
115
|
+
const hudTitle = el('div', { ...HUD_COPY_STYLE, fontSize: '13px', maxHeight: '41.8px', letterSpacing: '0.06em', textTransform: 'uppercase' }, hud);
|
|
116
|
+
const hudBig = el('div', { background: HUD_COPY_STYLE.background, borderRadius: '14px', padding: '0 8px', boxSizing: 'border-box', width: 'max-content', maxWidth: '100%', margin: '4px auto 0', overflowWrap: 'anywhere', fontSize: '56px', fontWeight: '800', lineHeight: '1.05' }, hud);
|
|
117
|
+
const hudText = el('div', { ...HUD_COPY_STYLE, position: 'absolute', left: 'max(16px, env(safe-area-inset-left))', right: 'max(16px, env(safe-area-inset-right))', bottom: 'max(54px, calc(env(safe-area-inset-bottom) + 48px))', fontSize: '14px', overflow: 'visible', maxWidth: 'min(60vw, 560px, calc(100vw - max(16px, env(safe-area-inset-left)) - max(16px, env(safe-area-inset-right))))', fontWeight: '500', textAlign: 'center', display: 'none', zIndex: '2' }, root);
|
|
118
|
+
hudText.dataset.hub = 'hud-prompt';
|
|
119
|
+
geometry.register(hudBig, { fit: true });
|
|
120
|
+
let hudPromptAsked = false;
|
|
121
|
+
|
|
122
|
+
hudTitle.dataset.hubCopy = 'subtitle';
|
|
123
|
+
hudText.dataset.hubCopy = 'instruction';
|
|
57
124
|
|
|
58
125
|
const labels = el('div', { position: 'absolute', inset: '0' }, root);
|
|
126
|
+
positionLayers.add(labels);
|
|
127
|
+
// v1.43 `measureLabel`: nothing until a deck that keeps its labels apart asks.
|
|
128
|
+
const labelMeasures = new Map();
|
|
129
|
+
const usedLabelMeasures = new Set();
|
|
130
|
+
// Pointers to friends out of sight (a town) and to a place's goals: a small
|
|
131
|
+
// chip over one far off, or at the screen's edge with an arrow when it is
|
|
132
|
+
// off screen. v1.34: made here, with the labels, so every panel, card and
|
|
133
|
+
// button made after them is drawn over a pointer (they were made after the
|
|
134
|
+
// talk panel, and a goal's arrow sat on the words of the NPC being read).
|
|
135
|
+
// v1.38: and put UNDER the labels, so an NPC's speech bubble is read over a
|
|
136
|
+
// chip (a goal's chip over an NPC cut through the words it was saying).
|
|
137
|
+
const pointers = el('div', { position: 'absolute', inset: '0' }, root);
|
|
138
|
+
positionLayers.add(pointers);
|
|
139
|
+
root.insertBefore(pointers, labels);
|
|
140
|
+
const pointerNodes = new Map();
|
|
59
141
|
const labelNodes = new Map();
|
|
60
142
|
|
|
61
143
|
// An arcade cabinet's card (v1.7). By the cabinet it is a chip: the best
|
|
@@ -154,43 +236,207 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
154
236
|
|
|
155
237
|
const ribbon = el('div', { position: 'absolute', display: 'none', transform: 'translate(-50%, -100%)', padding: '4px 10px', borderRadius: '6px', background: 'linear-gradient(#f2c94c, #d69e2e)', color: '#3b2600', fontSize: '13px', fontWeight: '800', whiteSpace: 'nowrap', boxShadow: '0 2px 6px rgba(0,0,0,0.4)' }, root);
|
|
156
238
|
|
|
157
|
-
const toast = el('div', { position: 'absolute',
|
|
239
|
+
const toast = el('div', { position: 'absolute', top: 'max(12px, env(safe-area-inset-top))', left: '50%', transform: 'translateX(-50%)', width: 'max-content', maxWidth: 'calc(100vw - 24px)', boxSizing: 'border-box', textAlign: 'center', padding: '8px 14px', borderRadius: '8px', background: 'rgba(20,16,12,0.8)', fontSize: '14px', display: 'none' }, root);
|
|
240
|
+
toast.dataset.hub = 'toast';
|
|
241
|
+
// Where a phone's toast starts, read in pixels: the safe area's inset has
|
|
242
|
+
// no other way to be measured.
|
|
243
|
+
const toastStart = el('div', { position: 'absolute', top: 'max(12px, env(safe-area-inset-top))', left: '0', width: '0', height: '0', visibility: 'hidden' }, root);
|
|
244
|
+
const actionBottom = el('div', { position: 'absolute', bottom: 'max(132px, calc(env(safe-area-inset-bottom) + 122px))', left: '0', width: '0', height: '0', visibility: 'hidden' }, root);
|
|
245
|
+
let toastWrap = null;
|
|
246
|
+
let toastChoiceBlocked = false;
|
|
247
|
+
function syncToastVisibility() {
|
|
248
|
+
const visibility = toastChoiceBlocked || pickerOpen ? 'hidden' : '';
|
|
249
|
+
if (toast.style.visibility !== visibility) {toast.style.visibility = visibility;}
|
|
250
|
+
}
|
|
158
251
|
|
|
159
252
|
// The avatar picker: one button, "Character", that opens the kit's
|
|
160
|
-
// characters under their own heading
|
|
161
|
-
|
|
253
|
+
// characters under their own heading: a grid, four across, each cell the
|
|
254
|
+
// character's face and name (`avatarFaces.js`, written with the models) and
|
|
255
|
+
// the one worn ringed in gold. The card never stands taller than the screen
|
|
256
|
+
// has room for over the button, and scrolls inside itself where it would
|
|
257
|
+
// (`fitPicker`). A cell is picked
|
|
258
|
+
// on `click`, not on the press, so a finger that scrolls the card picks
|
|
259
|
+
// nothing.
|
|
260
|
+
const overPicker = [];
|
|
261
|
+
const shutRound = [];
|
|
262
|
+
const picker = el('div', { position: 'absolute', right: edge('right', 10), bottom: 'max(10px, env(safe-area-inset-bottom))', display: 'none', flexDirection: 'column', alignItems: 'flex-end', gap: '6px', pointerEvents: 'auto' }, root);
|
|
162
263
|
picker.addEventListener('pointerdown', (event) => event.stopPropagation());
|
|
163
|
-
const pickerCard = el('div', { display: 'none', flexDirection: 'column', gap: '6px', padding: '8px', borderRadius: '12px', background: 'rgba(20,16,12,0.88)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)' }, picker);
|
|
164
|
-
|
|
165
|
-
|
|
264
|
+
const pickerCard = el('div', { display: 'none', flexDirection: 'column', gap: '6px', padding: '8px', borderRadius: '12px', background: 'rgba(20,16,12,0.88)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)', boxSizing: 'border-box', maxWidth: 'calc(100vw - 20px)', overflowY: 'auto', overscrollBehavior: 'contain', touchAction: 'pan-y' }, picker);
|
|
265
|
+
// What is left over the button and its margins; `dvh` where the browser has
|
|
266
|
+
// it (a phone's toolbars), `vh` where it does not.
|
|
267
|
+
for (const unit of ['vh', 'dvh']) {
|
|
268
|
+
pickerCard.style.maxHeight = `calc(100${unit} - 76px - env(safe-area-inset-top) - env(safe-area-inset-bottom))`;
|
|
269
|
+
}
|
|
270
|
+
const pickerHeading = el('div', { fontSize: '12px', opacity: '0.8' }, pickerCard);
|
|
271
|
+
pickerHeading.textContent = 'Your character';
|
|
272
|
+
const pickerRow = el('div', { display: 'grid', gridTemplateColumns: `repeat(${PICKER_COLUMNS}, ${PICKER_CELL_PX}px)`, gap: '6px' }, pickerCard);
|
|
166
273
|
const pickerButtons = [];
|
|
167
274
|
let pickerOpen = false;
|
|
275
|
+
let pickerSelected = null;
|
|
276
|
+
let inviteRow = null, invitePick = null;
|
|
277
|
+
const pickerHandle = el('div', { width: '32px', height: '4px', borderRadius: '2px', background: 'rgba(255,255,255,0.5)', margin: '2px auto 6px', pointerEvents: 'none' }, pickerCard);
|
|
278
|
+
pickerHandle.dataset.hub = 'picker-handle';
|
|
279
|
+
pickerCard.insertBefore(pickerHandle, pickerHeading);
|
|
280
|
+
const pickerClose = el('button', { minHeight: '44px', padding: '8px 12px', borderRadius: '12px', border: '1px solid rgba(255,255,255,0.4)', background: 'rgba(20,16,12,0.7)', color: '#fff', font: 'inherit', cursor: 'pointer', display: 'none' }, pickerCard);
|
|
281
|
+
pickerClose.type = 'button'; pickerClose.textContent = 'Close'; pickerClose.setAttribute('aria-label', 'Close character sheet');
|
|
282
|
+
pickerCard.insertBefore(pickerClose, pickerHeading);
|
|
283
|
+
let companionLock = null, companionLockVisibility = null;
|
|
284
|
+
function restoreCompanionLock() {
|
|
285
|
+
if (companionLock && companionLockVisibility !== null) {companionLock.style.visibility = companionLockVisibility;}
|
|
286
|
+
companionLockVisibility = null;
|
|
287
|
+
}
|
|
288
|
+
let pickerFitKey = '';
|
|
289
|
+
// The card is a sheet fitted to the viewport: over the right-side lane above
|
|
290
|
+
// the button, or, on a phone on its side with no room there for the whole
|
|
291
|
+
// sheet, one strip of whole tiles along the bottom with its own Close. Open,
|
|
292
|
+
// it covers the rail, so the rail's buttons are out of sight until it shuts.
|
|
293
|
+
function fitPicker(force = false) {
|
|
294
|
+
const { w, h } = geometry.view();
|
|
295
|
+
const key = `${landscape}:${pickerOpen}:${lockLift}:${pickerCard.children.length}:${inviteRow?.style.display}:${colorRow?.style.display}:${w}:${h}`;
|
|
296
|
+
if (!force && key === pickerFitKey) {return;}
|
|
297
|
+
pickerFitKey = key;
|
|
298
|
+
// Measured once per change of what decides it: a landscape sheet that
|
|
299
|
+
// would scroll in the lane cuts its last row, so it becomes the strip.
|
|
300
|
+
const compact = landscape && (h < 300 || pickerOpen && (layPicker(false), pickerCard.scrollHeight > pickerCard.clientHeight + 1));
|
|
301
|
+
layPicker(compact);
|
|
302
|
+
}
|
|
303
|
+
function layPicker(compact) {
|
|
304
|
+
Object.assign(pickerCard.style, {
|
|
305
|
+
position: 'fixed', right: compact ? 'auto' : '10px', left: compact ? '50%' : '', transform: compact ? 'translateX(-50%)' : '', bottom: compact ? 'max(12px, env(safe-area-inset-bottom))' : `max(${64 + lockLift}px, calc(env(safe-area-inset-bottom) + ${64 + lockLift}px))`, flexShrink: '0',
|
|
306
|
+
});
|
|
307
|
+
for (const unit of ['vh', 'dvh']) {pickerCard.style.maxHeight = `calc(100${unit} - ${compact ? 24 : 80 + lockLift}px - env(safe-area-inset-top) - env(safe-area-inset-bottom))`;}
|
|
308
|
+
const tiles = Math.max(1, Math.floor((geometry.view().w - 26) / (PICKER_CELL_PX + 6)));
|
|
309
|
+
const stripWidth = tiles * (PICKER_CELL_PX + 6) - 6;
|
|
310
|
+
Object.assign(pickerCard.style, { width: compact ? `${stripWidth + 8}px` : '', padding: compact ? '4px' : '8px 8px 24px', gap: compact ? '2px' : '6px', overflowY: compact ? 'hidden' : 'auto', gridTemplateColumns: compact ? '1fr auto' : '', touchAction: compact ? 'pan-x' : 'pan-y' });
|
|
311
|
+
pickerCard.style.display = pickerOpen ? compact ? 'grid' : 'flex' : 'none';
|
|
312
|
+
for (const child of pickerCard.children) {
|
|
313
|
+
child.style.flexShrink = '0';
|
|
314
|
+
// Close keeps the right-hand column with or without Invite beside it.
|
|
315
|
+
child.style.gridColumn = !compact ? '' : child === pickerClose ? '2' : child === inviteRow ? '1' : '1 / -1';
|
|
316
|
+
}
|
|
317
|
+
pickerHandle.style.display = compact ? 'none' : 'block';
|
|
318
|
+
pickerClose.style.display = compact ? '' : 'none';
|
|
319
|
+
pickerHeading.style.display = compact ? 'none' : '';
|
|
320
|
+
Object.assign(pickerRow.style, { gridTemplateColumns: compact ? 'none' : `repeat(${PICKER_COLUMNS}, ${PICKER_CELL_PX}px)`, gridAutoFlow: compact ? 'column' : '', gridAutoColumns: compact ? `${PICKER_CELL_PX}px` : '', width: compact ? `${stripWidth}px` : '', overflowX: compact ? 'auto' : '', overflowY: compact ? 'hidden' : '', scrollSnapType: compact ? 'x mandatory' : '', scrollbarWidth: compact ? 'none' : '', touchAction: compact ? 'pan-x' : '' });
|
|
321
|
+
for (const button of pickerButtons) {
|
|
322
|
+
Object.assign(button.style, { scrollSnapAlign: compact ? 'start' : '', scrollSnapStop: compact ? 'always' : '', touchAction: compact ? 'pan-x' : 'pan-y' });
|
|
323
|
+
}
|
|
324
|
+
pickerToggle.style.visibility = compact && pickerOpen ? 'hidden' : '';
|
|
325
|
+
dock.style.visibility = compact && pickerOpen ? 'hidden' : '';
|
|
326
|
+
if (compact && pickerOpen && companionLock) {
|
|
327
|
+
if (companionLockVisibility === null) {companionLockVisibility = companionLock.style.visibility ?? '';}
|
|
328
|
+
companionLock.style.visibility = 'hidden';
|
|
329
|
+
} else {restoreCompanionLock();}
|
|
330
|
+
for (const node of railNodes) {
|
|
331
|
+
if (node !== picker && !overPicker.includes(node)) {node.style.visibility = pickerOpen ? 'hidden' : '';}
|
|
332
|
+
}
|
|
333
|
+
syncToastVisibility();
|
|
334
|
+
}
|
|
168
335
|
const setPickerOpen = (open) => {
|
|
169
336
|
pickerOpen = open;
|
|
170
|
-
|
|
337
|
+
picker.style.zIndex = open ? '4' : '';
|
|
338
|
+
showCompanionBadge();
|
|
339
|
+
if (open) {
|
|
340
|
+
pickerRow.style.gridTemplateColumns = `repeat(${PICKER_COLUMNS}, ${PICKER_CELL_PX}px)`;
|
|
341
|
+
}
|
|
342
|
+
// Open, the card lies under the round buttons up the right edge and the
|
|
343
|
+
// talk button along the bottom, which would take its taps; they are out
|
|
344
|
+
// of sight until it shuts, and what a round one had open shuts with it.
|
|
345
|
+
for (const button of overPicker) {
|
|
346
|
+
button.style.visibility = open ? 'hidden' : '';
|
|
347
|
+
}
|
|
348
|
+
if (open) {
|
|
349
|
+
for (const shut of shutRound) {
|
|
350
|
+
shut();
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
fitPicker();
|
|
171
354
|
};
|
|
355
|
+
pickerClose.addEventListener('click', (event) => {event.stopPropagation(); setPickerOpen(false);});
|
|
172
356
|
for (let i = 0; i < avatarCount; i += 1) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
button.
|
|
176
|
-
|
|
357
|
+
// A character this kit has no face for is a number, as all of them were.
|
|
358
|
+
const [name, face] = AVATAR_FACES[i] ?? [`Character ${i + 1}`, null];
|
|
359
|
+
const button = el('button', { width: `${PICKER_CELL_PX}px`, minHeight: '62px', boxSizing: 'border-box', padding: '4px 0 3px', borderRadius: '12px', border: '2px solid rgba(255,255,255,0.4)', background: 'rgba(20,16,12,0.7)', color: '#fff', font: '600 11px/1.2 system-ui, sans-serif', cursor: 'pointer', display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: '2px', touchAction: 'pan-y', overflow: 'hidden' }, pickerRow);
|
|
360
|
+
if (face) {
|
|
361
|
+
el('div', { width: '36px', height: '36px', flex: 'none', pointerEvents: 'none' }, button).innerHTML = `<svg viewBox="0 0 24 24" width="36" height="36" stroke="#241a2e" stroke-width="1.3" stroke-linejoin="round" stroke-linecap="round" aria-hidden="true">${face}</svg>`;
|
|
362
|
+
}
|
|
363
|
+
el('div', { maxWidth: '100%', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', pointerEvents: 'none', fontSize: face ? '11px' : '13px' }, button).textContent = face ? name : String(i + 1);
|
|
364
|
+
button.setAttribute('aria-label', face ? `Character: ${name}` : name);
|
|
365
|
+
button.setAttribute('aria-pressed', 'false');
|
|
366
|
+
button.addEventListener('click', (event) => {
|
|
177
367
|
event.stopPropagation();
|
|
178
368
|
setPickerOpen(false);
|
|
179
369
|
onAvatar(i);
|
|
180
370
|
});
|
|
181
371
|
pickerButtons.push(button);
|
|
182
372
|
}
|
|
373
|
+
let colorRow = null;
|
|
374
|
+
let colorKey = null;
|
|
375
|
+
const colorButtons = [];
|
|
376
|
+
function showColors(selected, { available = false, style = 'toon', color = 0, files = null, model = null } = {}) {
|
|
377
|
+
const palette = Colors.AVATAR_COLORS[selected];
|
|
378
|
+
if (!available || style !== 'toon' || !palette) {
|
|
379
|
+
if (colorRow) {
|
|
380
|
+
colorRow.style.display = 'none';
|
|
381
|
+
}
|
|
382
|
+
colorKey = null;
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
const wornColor = Colors.known(selected, color);
|
|
386
|
+
const key = `${selected}:${wornColor}`;
|
|
387
|
+
if (colorKey === key) {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
// Dot zero is read from the model's named main part, never a face colour.
|
|
391
|
+
let original;
|
|
392
|
+
try {
|
|
393
|
+
const data = JSON.parse(files?.[model]);
|
|
394
|
+
original = data.parts?.find((part) => palette.main.includes(part.id))?.color;
|
|
395
|
+
} catch {
|
|
396
|
+
// A pack still loading has no original colour to show yet.
|
|
397
|
+
}
|
|
398
|
+
if (!original) {
|
|
399
|
+
if (colorRow) {
|
|
400
|
+
colorRow.style.display = 'none';
|
|
401
|
+
}
|
|
402
|
+
colorKey = null;
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
if (!colorRow) {
|
|
406
|
+
colorRow = document.createElement('div');
|
|
407
|
+
Object.assign(colorRow.style, { display: 'flex', gap: '4px', justifyContent: 'center' });
|
|
408
|
+
pickerCard.insertBefore(colorRow, pickerRow.nextSibling ?? [...pickerCard.children][[...pickerCard.children].indexOf(pickerRow) + 1] ?? null);
|
|
409
|
+
for (let c = 0; c < Colors.COLORS; c += 1) {
|
|
410
|
+
const button = el('button', { width: '44px', height: '44px', boxSizing: 'border-box', flex: 'none', padding: '6px', borderRadius: '50%', border: '2px solid transparent', cursor: 'pointer', touchAction: 'pan-y' }, colorRow);
|
|
411
|
+
button.setAttribute('aria-label', `Colour: ${c + 1}`);
|
|
412
|
+
button.addEventListener('click', (event) => {
|
|
413
|
+
event.stopPropagation();
|
|
414
|
+
onColor(c);
|
|
415
|
+
});
|
|
416
|
+
colorButtons.push(button);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
colorRow.style.display = 'flex';
|
|
420
|
+
colorButtons.forEach((button, c) => {
|
|
421
|
+
button.style.background = c === 0 ? original : palette.colors[c - 1][0];
|
|
422
|
+
button.style.borderColor = c === wornColor ? '#f2c94c' : 'rgba(255,255,255,0.4)';
|
|
423
|
+
button.setAttribute('aria-pressed', String(c === wornColor));
|
|
424
|
+
});
|
|
425
|
+
colorKey = key;
|
|
426
|
+
}
|
|
183
427
|
const pickerToggle = el('button', { padding: '8px 14px', borderRadius: '18px', border: '1px solid rgba(255,255,255,0.4)', background: 'rgba(20,16,12,0.72)', color: '#fff', font: 'inherit', cursor: 'pointer' }, picker);
|
|
184
428
|
pickerToggle.textContent = 'Character';
|
|
185
429
|
// Graphics: Auto / Low / High, under the characters, in a deck that has
|
|
186
430
|
// device tiers (`tiers.js`). Built on the first `setGraphics`, so a deck
|
|
187
431
|
// without them draws the card as it always was.
|
|
188
432
|
let graphics = null;
|
|
189
|
-
function buildGraphics() {
|
|
433
|
+
function buildGraphics(weakest = false) {
|
|
190
434
|
const row = el('div', { display: 'flex', alignItems: 'center', gap: '6px', marginTop: '2px' }, pickerCard);
|
|
191
435
|
el('div', { fontSize: '12px', opacity: '0.8', flex: '1' }, row).textContent = 'Graphics';
|
|
192
436
|
const buttons = new Map();
|
|
193
|
-
|
|
437
|
+
const modes = [['auto', 'Auto'], ['low', 'Low'], ['high', 'High']];
|
|
438
|
+
if (weakest) { modes.splice(2, 0, ['weakest', 'Weakest']); }
|
|
439
|
+
for (const [mode, text] of modes) {
|
|
194
440
|
const button = el('button', { padding: '4px 9px', borderRadius: '12px', border: '1px solid rgba(255,255,255,0.4)', background: 'rgba(20,16,12,0.7)', color: '#fff', font: '600 12px system-ui, sans-serif', cursor: 'pointer' }, row);
|
|
195
441
|
button.textContent = text;
|
|
196
442
|
button.setAttribute('aria-label', `Graphics: ${text}`);
|
|
@@ -211,6 +457,7 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
211
457
|
// conversation is open. Keys typed here are the panel's, not the game's.
|
|
212
458
|
let talkHandlers = { open() {}, send() {}, end() {} };
|
|
213
459
|
const talkButton = el('button', { position: 'absolute', bottom: 'max(64px, calc(env(safe-area-inset-bottom) + 54px))', left: '50%', transform: 'translateX(-50%)', pointerEvents: 'auto', padding: '10px 18px', borderRadius: '22px', border: '1px solid rgba(255,255,255,0.45)', background: 'rgba(20,16,12,0.8)', color: '#fff', font: 'inherit', display: 'none', cursor: 'pointer' }, root);
|
|
460
|
+
overPicker.push(talkButton);
|
|
214
461
|
talkButton.addEventListener('pointerdown', (event) => {
|
|
215
462
|
event.stopPropagation();
|
|
216
463
|
talkHandlers.open();
|
|
@@ -225,14 +472,75 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
225
472
|
talkHandlers.end();
|
|
226
473
|
});
|
|
227
474
|
const panelLog = el('div', { maxHeight: '28vh', overflowY: 'auto', display: 'flex', flexDirection: 'column', gap: '4px', fontSize: '14px', fontWeight: '500' }, panel);
|
|
475
|
+
geometry.register(panelLog, { scroll: true });
|
|
476
|
+
// v1.46: the mind is answering; reduced motion keeps a plain ellipsis.
|
|
477
|
+
const typingStyle = el('style', {}, root);
|
|
478
|
+
typingStyle.textContent = `
|
|
479
|
+
@keyframes hub-npc-dot { 0%, 80%, 100% { opacity: .35; } 40% { opacity: 1; } }
|
|
480
|
+
.hub-npc-typing span { animation: hub-npc-dot 1.2s infinite; }
|
|
481
|
+
.hub-npc-typing span:nth-child(2) { animation-delay: .2s; }
|
|
482
|
+
.hub-npc-typing span:nth-child(3) { animation-delay: .4s; }
|
|
483
|
+
@media (prefers-reduced-motion: reduce) {
|
|
484
|
+
.hub-npc-typing span { animation: none; display: none; }
|
|
485
|
+
.hub-npc-typing::after { content: '…'; }
|
|
486
|
+
}
|
|
487
|
+
`;
|
|
488
|
+
let panelTyping = null;
|
|
489
|
+
let panelMind = false;
|
|
490
|
+
let panelOpening = null;
|
|
491
|
+
// An under-13 speaker's line under the opening of a mind they cannot type
|
|
492
|
+
// to, made only while there is one, like the questions.
|
|
493
|
+
let panelHint = null;
|
|
494
|
+
const dropHint = () => {
|
|
495
|
+
panelHint?.remove();
|
|
496
|
+
panelHint = null;
|
|
497
|
+
};
|
|
498
|
+
const dropTyping = () => {
|
|
499
|
+
panelTyping?.remove();
|
|
500
|
+
panelTyping = null;
|
|
501
|
+
};
|
|
502
|
+
// The questions are made only while there are some to offer.
|
|
503
|
+
let panelAsks = null;
|
|
504
|
+
let panelChildAsks = false;
|
|
505
|
+
let asksHandler = null;
|
|
506
|
+
// The row is taken out again, not hidden: the panel of a conversation with
|
|
507
|
+
// no questions has the nodes it always had.
|
|
508
|
+
const dropAsks = () => {
|
|
509
|
+
panelAsks?.remove();
|
|
510
|
+
panelAsks = null;
|
|
511
|
+
panelChildAsks = false;
|
|
512
|
+
asksHandler = null;
|
|
513
|
+
syncTalkSurfaces();
|
|
514
|
+
};
|
|
228
515
|
// Not a <form>: castle.xyz plays a deck in a frame sandboxed without
|
|
229
516
|
// `allow-forms`, where a form's submission (Enter, or a submit button) is
|
|
230
517
|
// blocked before its submit event fires, so nothing would ever be said.
|
|
231
518
|
const panelForm = el('div', { display: 'flex', gap: '6px', margin: '0' }, panel);
|
|
519
|
+
// Chat words, not an account: no autofill or saved suggestions (Chrome
|
|
520
|
+
// offered emails on a bare field).
|
|
521
|
+
const chatField = (input, name) => {
|
|
522
|
+
input.type = 'text';
|
|
523
|
+
input.name = name;
|
|
524
|
+
input.autocomplete = 'off';
|
|
525
|
+
input.inputMode = 'text';
|
|
526
|
+
input.setAttribute('autocapitalize', 'sentences');
|
|
527
|
+
input.spellcheck = true;
|
|
528
|
+
};
|
|
232
529
|
const panelInput = el('input', { flex: '1', minWidth: '0', padding: '8px 10px', borderRadius: '8px', border: '1px solid rgba(255,255,255,0.3)', background: 'rgba(255,255,255,0.1)', color: '#fff', font: '500 15px system-ui, sans-serif' }, panelForm);
|
|
530
|
+
chatField(panelInput, 'say');
|
|
233
531
|
panelInput.maxLength = 280;
|
|
234
532
|
panelInput.placeholder = 'Say something…';
|
|
235
533
|
panelInput.enterKeyHint = 'send';
|
|
534
|
+
const setTalkTyping = (allowed) => {
|
|
535
|
+
const wasHidden = panelForm.style.display === 'none';
|
|
536
|
+
panelForm.style.display = allowed ? 'flex' : 'none';
|
|
537
|
+
if (!allowed) {
|
|
538
|
+
panelInput.blur();
|
|
539
|
+
if (!panelChildAsks) {dropAsks();}
|
|
540
|
+
} else if (wasHidden && globalThis.matchMedia?.('(pointer: fine)').matches && !(globalThis.navigator?.maxTouchPoints > 0)) {
|
|
541
|
+
panelInput.focus({ preventScroll: true });
|
|
542
|
+
}
|
|
543
|
+
};
|
|
236
544
|
const panelSend = el('button', { padding: '8px 14px', borderRadius: '8px', border: 'none', background: '#e9c48f', color: '#2b2118', font: '700 14px system-ui, sans-serif', cursor: 'pointer' }, panelForm);
|
|
237
545
|
panelSend.type = 'button';
|
|
238
546
|
panelSend.textContent = 'Say';
|
|
@@ -264,12 +572,50 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
264
572
|
submitTalk();
|
|
265
573
|
});
|
|
266
574
|
let talkOpen = false;
|
|
575
|
+
let followedLine = null, followedScroll = 0, followedSnapshot = null;
|
|
576
|
+
function followTalkLine() {
|
|
577
|
+
// A player who scrolled back keeps that position when chips arrive.
|
|
578
|
+
if (!followedLine?.isConnected) {return;}
|
|
579
|
+
const scroll = geometry.scroll(panelLog);
|
|
580
|
+
// An in-frame write stores the requested top; a later snapshot has the
|
|
581
|
+
// browser's clamped position. This frame's snapshot predates that write.
|
|
582
|
+
const expected = followedSnapshot ? Math.max(0, Math.min(followedScroll, scroll.height - scroll.client)) : followedScroll;
|
|
583
|
+
if (scroll !== followedSnapshot && Math.abs(scroll.top - expected) > 1) {return;}
|
|
584
|
+
const top = geometry.offsets(followedLine).top - geometry.offsets(panelLog).top;
|
|
585
|
+
panelLog.scrollTop = top;
|
|
586
|
+
followedScroll = geometry.active() ? top : panelLog.scrollTop;
|
|
587
|
+
followedSnapshot = geometry.active() ? scroll : null;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
function syncHudPrompt() {
|
|
591
|
+
const display = hudPromptAsked && !doorsOpen && !(talkOpen && panelAsks) ? 'block' : 'none';
|
|
592
|
+
hudText.style.display = display;
|
|
593
|
+
}
|
|
594
|
+
function syncTalkSurfaces() {
|
|
595
|
+
syncTalkCaption();
|
|
596
|
+
syncHudPrompt();
|
|
597
|
+
placeToast();
|
|
598
|
+
}
|
|
267
599
|
const layoutPanel = () => {
|
|
600
|
+
const landscape = landscapeViewport();
|
|
268
601
|
const wide = desktop();
|
|
269
|
-
Object.assign(panel.style,
|
|
270
|
-
? { left: '
|
|
602
|
+
Object.assign(panel.style, landscape
|
|
603
|
+
? { left: '50%', transform: 'translateX(-50%)', width: geometry.view().w < 740 ? 'min(70vw, 420px)' : 'min(56vw, max(220px, calc(100vw - 344px)), 560px)', maxHeight: 'calc(100dvh - 88px - env(safe-area-inset-top) - env(safe-area-inset-bottom))', boxSizing: 'border-box', overflow: 'hidden' }
|
|
604
|
+
: wide
|
|
605
|
+
? { left: edge('left', 10), transform: 'none', width: '340px' }
|
|
271
606
|
: { left: '50%', transform: 'translateX(-50%)', width: 'min(92vw, 420px)' });
|
|
272
|
-
|
|
607
|
+
if (!landscape) {
|
|
608
|
+
panel.style.maxHeight = '';
|
|
609
|
+
panel.style.boxSizing = '';
|
|
610
|
+
panel.style.overflow = '';
|
|
611
|
+
}
|
|
612
|
+
panelLog.style.maxHeight = landscape ? 'none' : wide ? 'min(28vh, 220px)' : '28vh';
|
|
613
|
+
panelLog.style.minHeight = landscape ? '0' : '';
|
|
614
|
+
panelLog.style.flex = landscape ? '1 1 auto' : '';
|
|
615
|
+
if (panelAsks) {
|
|
616
|
+
panelAsks.style.display = landscape ? 'grid' : 'flex';
|
|
617
|
+
panelAsks.style.gridTemplateColumns = landscape ? 'repeat(2, minmax(0, 1fr))' : '';
|
|
618
|
+
}
|
|
273
619
|
};
|
|
274
620
|
layoutPanel();
|
|
275
621
|
desktopQuery?.addEventListener?.('change', layoutPanel);
|
|
@@ -277,7 +623,7 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
277
623
|
// Grab / Throw (v1.3): a big thumb button bottom right, above the avatar
|
|
278
624
|
// picker, shown while there is something to grab or something held.
|
|
279
625
|
let grabHandler = () => {};
|
|
280
|
-
const grabButton = el('button', { position: 'absolute', right: '
|
|
626
|
+
const grabButton = el('button', { position: 'absolute', right: edge('right', 14), bottom: 'max(60px, calc(env(safe-area-inset-bottom) + 50px))', width: '76px', height: '76px', borderRadius: '38px', pointerEvents: 'auto', border: '2px solid rgba(255,255,255,0.55)', background: 'rgba(20,16,12,0.78)', color: '#fff', font: '800 16px system-ui, sans-serif', display: 'none', cursor: 'pointer', touchAction: 'manipulation', userSelect: 'none' }, root);
|
|
281
627
|
grabButton.addEventListener('pointerdown', (event) => {
|
|
282
628
|
event.stopPropagation();
|
|
283
629
|
event.preventDefault();
|
|
@@ -289,17 +635,20 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
289
635
|
let emoteHandler = () => {};
|
|
290
636
|
let sitHandler = () => {};
|
|
291
637
|
const emoteBottom = 'max(146px, calc(env(safe-area-inset-bottom) + 136px))';
|
|
292
|
-
const emoteButton = el('button', { position: 'absolute', right: '
|
|
638
|
+
const emoteButton = el('button', { position: 'absolute', right: edge('right', 20), bottom: emoteBottom, width: '52px', height: '52px', borderRadius: '26px', pointerEvents: 'auto', border: '2px solid rgba(255,255,255,0.5)', background: 'rgba(20,16,12,0.78)', color: '#fff', font: '24px system-ui, sans-serif', display: 'none', cursor: 'pointer', touchAction: 'manipulation', userSelect: 'none', padding: '0' }, root);
|
|
639
|
+
overPicker.push(emoteButton);
|
|
293
640
|
emoteButton.textContent = '☺';
|
|
294
641
|
emoteButton.setAttribute('aria-label', 'Emote');
|
|
295
|
-
const emoteRow = el('div', { position: 'absolute', right: '
|
|
642
|
+
const emoteRow = el('div', { position: 'absolute', right: edge('right', 80), bottom: emoteBottom, display: 'none', gap: '6px', pointerEvents: 'auto', padding: '4px', borderRadius: '28px', background: 'rgba(20,16,12,0.78)' }, root);
|
|
296
643
|
emoteRow.addEventListener('pointerdown', (event) => event.stopPropagation());
|
|
297
644
|
let emotesOpen = false;
|
|
298
645
|
let emotesKey = '';
|
|
299
646
|
const setEmotesOpen = (open) => {
|
|
300
647
|
emotesOpen = open;
|
|
648
|
+
showCompanionBadge();
|
|
301
649
|
emoteRow.style.display = open ? 'flex' : 'none';
|
|
302
650
|
};
|
|
651
|
+
shutRound.push(() => setEmotesOpen(false));
|
|
303
652
|
emoteButton.addEventListener('pointerdown', (event) => {
|
|
304
653
|
event.stopPropagation();
|
|
305
654
|
event.preventDefault();
|
|
@@ -309,10 +658,11 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
309
658
|
// button opens a small card, a row of emoji over the place's phrases; and
|
|
310
659
|
// the feed of what was just said, small, above the dock.
|
|
311
660
|
let sayHandler = () => {};
|
|
312
|
-
const sayButton = el('button', { position: 'absolute', right: '
|
|
661
|
+
const sayButton = el('button', { position: 'absolute', right: edge('right', 20), bottom: 'max(206px, calc(env(safe-area-inset-bottom) + 196px))', width: '52px', height: '52px', borderRadius: '26px', pointerEvents: 'auto', border: '2px solid rgba(255,255,255,0.5)', background: 'rgba(20,16,12,0.78)', color: '#fff', font: '22px system-ui, sans-serif', display: 'none', cursor: 'pointer', touchAction: 'manipulation', userSelect: 'none', padding: '0' }, root);
|
|
662
|
+
overPicker.push(sayButton);
|
|
313
663
|
sayButton.textContent = '💬';
|
|
314
664
|
sayButton.setAttribute('aria-label', 'Quick chat');
|
|
315
|
-
const sayCard = el('div', { position: 'absolute', right: '
|
|
665
|
+
const sayCard = el('div', { position: 'absolute', right: edge('right', 80), bottom: 'max(146px, calc(env(safe-area-inset-bottom) + 136px))', width: 'min(70vw, 236px)', display: 'none', flexDirection: 'column', gap: '6px', pointerEvents: 'auto', padding: '8px', borderRadius: '14px', background: 'rgba(20,16,12,0.88)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)' }, root);
|
|
316
666
|
sayCard.addEventListener('pointerdown', (event) => event.stopPropagation());
|
|
317
667
|
let sayOpen = false;
|
|
318
668
|
let sayKey = '';
|
|
@@ -320,16 +670,19 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
320
670
|
let sayNote = null;
|
|
321
671
|
const setSayOpen = (open) => {
|
|
322
672
|
sayOpen = open;
|
|
673
|
+
showCompanionBadge();
|
|
323
674
|
sayCard.style.display = open ? 'flex' : 'none';
|
|
324
675
|
};
|
|
676
|
+
shutRound.push(() => setSayOpen(false));
|
|
325
677
|
sayButton.addEventListener('pointerdown', (event) => {
|
|
326
678
|
event.stopPropagation();
|
|
327
679
|
event.preventDefault();
|
|
328
680
|
setSayOpen(!sayOpen);
|
|
329
681
|
setEmotesOpen(false);
|
|
330
682
|
});
|
|
331
|
-
const feed = el('div', { position: 'absolute', left: '
|
|
683
|
+
const feed = el('div', { position: 'absolute', left: edge('left', 10), bottom: 'max(70px, calc(env(safe-area-inset-bottom) + 60px))', maxWidth: '62vw', display: 'flex', flexDirection: 'column', gap: '2px', font: '500 12px/1.3 system-ui, sans-serif', textShadow: BARE_TEXT_SHADOW, opacity: '0.92' }, root);
|
|
332
684
|
let feedKey = '';
|
|
685
|
+
let chatModeration = false;
|
|
333
686
|
const sitButton = el('button', { position: 'absolute', bottom: 'max(112px, calc(env(safe-area-inset-bottom) + 102px))', left: '50%', transform: 'translateX(-50%)', pointerEvents: 'auto', padding: '10px 22px', borderRadius: '22px', border: '1px solid rgba(255,255,255,0.45)', background: 'rgba(20,16,12,0.8)', color: '#fff', font: 'inherit', display: 'none', cursor: 'pointer', touchAction: 'manipulation' }, root);
|
|
334
687
|
sitButton.addEventListener('pointerdown', (event) => {
|
|
335
688
|
event.stopPropagation();
|
|
@@ -339,49 +692,78 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
339
692
|
|
|
340
693
|
// Bottom left: the town's Doors, then People, side by side -- or People
|
|
341
694
|
// above Doors where a narrow screen leaves no room beside the avatar picker.
|
|
342
|
-
const dock = el('div', { position: 'absolute', left: '
|
|
695
|
+
const dock = el('div', { position: 'absolute', left: edge('left', 10), bottom: 'max(10px, env(safe-area-inset-bottom))', display: 'flex', flexWrap: 'wrap-reverse', alignItems: 'flex-start', gap: '6px', maxWidth: 'calc(100vw - 130px)' }, root);
|
|
343
696
|
// A list opens just above the dock, however tall the dock is.
|
|
344
697
|
const aboveDock = (list) => {
|
|
345
|
-
|
|
698
|
+
if (landscapeViewport()) {
|
|
699
|
+
list.style.bottom = '';
|
|
700
|
+
const top = `max(68px, env(safe-area-inset-top) + 56px) + ${geometry.size(dock).h + 6}px`;
|
|
701
|
+
list.style.top = `calc(${top})`;
|
|
702
|
+
list.style.maxHeight = `calc(100dvh - (${top}) - max(12px, env(safe-area-inset-bottom)))`;
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
705
|
+
list.style.top = '';
|
|
706
|
+
const bottom = `max(10px, env(safe-area-inset-bottom)) + ${geometry.size(dock).h + 6}px`;
|
|
707
|
+
list.style.bottom = `calc(${bottom})`;
|
|
708
|
+
list.style.maxHeight = `min(40vh, calc(100dvh - (${bottom}) - max(68px, env(safe-area-inset-top) + 56px)))`;
|
|
346
709
|
};
|
|
347
710
|
const doorsButton = el('button', { pointerEvents: 'auto', padding: '8px 14px', borderRadius: '18px', border: '1px solid rgba(255,255,255,0.4)', background: 'rgba(20,16,12,0.72)', color: '#fff', font: 'inherit', display: 'none', cursor: 'pointer' }, dock);
|
|
711
|
+
geometry.register(doorsButton);
|
|
348
712
|
doorsButton.textContent = 'Doors';
|
|
349
713
|
// The town's doors: the list opens above the dock, one list at a time, and
|
|
350
714
|
// Go puts the player in front of that door.
|
|
351
|
-
const doorsList = el('div', { position: 'absolute', left: '
|
|
715
|
+
const doorsList = el('div', { position: 'absolute', left: edge('left', 10), bottom: 'max(56px, calc(env(safe-area-inset-bottom) + 46px))', width: 'min(80vw, 260px)', maxHeight: '40vh', overflowY: 'auto', touchAction: 'pan-y', boxSizing: 'border-box', pointerEvents: 'auto', display: 'none', flexDirection: 'column', padding: '8px', borderRadius: '12px', background: 'rgba(20,16,12,0.88)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)' }, root);
|
|
716
|
+
const doorsBody = el('div', { display: 'flex', flexDirection: 'column', gap: '6px', flexShrink: '0', paddingBottom: '8px' }, doorsList);
|
|
352
717
|
doorsList.addEventListener('pointerdown', (event) => event.stopPropagation());
|
|
353
718
|
let doorsOpen = false;
|
|
354
719
|
let doorsKey = '';
|
|
720
|
+
// The "Stuck?" row's press (v1.33); never called in a deck without it.
|
|
721
|
+
let stuckRowPick = () => {};
|
|
355
722
|
function closeDoors() {
|
|
356
723
|
doorsOpen = false;
|
|
724
|
+
showCompanionBadge();
|
|
357
725
|
doorsList.style.display = 'none';
|
|
726
|
+
syncHudPrompt();
|
|
358
727
|
}
|
|
359
728
|
doorsButton.addEventListener('pointerdown', (event) => {
|
|
360
729
|
event.stopPropagation();
|
|
361
730
|
doorsOpen = !doorsOpen;
|
|
731
|
+
showCompanionBadge();
|
|
362
732
|
aboveDock(doorsList);
|
|
363
733
|
doorsList.style.display = doorsOpen ? 'flex' : 'none';
|
|
734
|
+
syncHudPrompt();
|
|
364
735
|
closePeople();
|
|
365
736
|
});
|
|
366
737
|
|
|
367
738
|
// The other players here, each with Report behind a confirm. Hub chrome
|
|
368
739
|
// only: a game's content cannot draw, hide or press it.
|
|
369
740
|
const peopleButton = el('button', { pointerEvents: 'auto', padding: '8px 14px', borderRadius: '18px', border: '1px solid rgba(255,255,255,0.4)', background: 'rgba(20,16,12,0.72)', color: '#fff', font: 'inherit', display: 'none', cursor: 'pointer' }, dock);
|
|
370
|
-
|
|
741
|
+
geometry.register(peopleButton);
|
|
742
|
+
const peopleList = el('div', { position: 'absolute', left: edge('left', 10), bottom: 'max(56px, calc(env(safe-area-inset-bottom) + 46px))', width: 'min(80vw, 260px)', maxHeight: '40vh', overflowY: 'auto', touchAction: 'pan-y', boxSizing: 'border-box', pointerEvents: 'auto', display: 'none', flexDirection: 'column', padding: '8px', borderRadius: '12px', background: 'rgba(20,16,12,0.88)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)' }, root);
|
|
743
|
+
const peopleBody = el('div', { display: 'flex', flexDirection: 'column', gap: '6px', flexShrink: '0', paddingBottom: '8px' }, peopleList);
|
|
371
744
|
peopleList.addEventListener('pointerdown', (event) => event.stopPropagation());
|
|
372
745
|
let peopleOpen = false;
|
|
373
746
|
let peopleKey = '';
|
|
374
747
|
function closePeople() {
|
|
375
748
|
peopleOpen = false;
|
|
749
|
+
showCompanionBadge();
|
|
376
750
|
peopleList.style.display = 'none';
|
|
377
751
|
}
|
|
378
752
|
peopleButton.addEventListener('pointerdown', (event) => {
|
|
379
753
|
event.stopPropagation();
|
|
380
754
|
peopleOpen = !peopleOpen;
|
|
755
|
+
showCompanionBadge();
|
|
381
756
|
aboveDock(peopleList);
|
|
382
757
|
peopleList.style.display = peopleOpen ? 'flex' : 'none';
|
|
383
758
|
closeDoors();
|
|
384
759
|
});
|
|
760
|
+
let companionBadge = null;
|
|
761
|
+
function showCompanionBadge() {
|
|
762
|
+
if (companionBadge) {companionBadge.style.display = talkOpen || pickerOpen || peopleOpen || doorsOpen || sayOpen || emotesOpen ? 'none' : 'block';}
|
|
763
|
+
}
|
|
764
|
+
let lockLift = 0;
|
|
765
|
+
const cornerBottoms = new Map([picker, grabButton, emoteButton, emoteRow, sayButton, sayCard].map((node) => [node, node.style.bottom]));
|
|
766
|
+
|
|
385
767
|
const smallButton = (parent, text, primary) => {
|
|
386
768
|
const button = el('button', { padding: '5px 12px', borderRadius: '12px', border: primary ? 'none' : '1px solid rgba(255,255,255,0.35)', background: primary ? '#e9c48f' : 'transparent', color: primary ? '#2b2118' : '#fff', font: '700 13px system-ui, sans-serif', cursor: 'pointer' }, parent);
|
|
387
769
|
button.textContent = text;
|
|
@@ -393,7 +775,7 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
393
775
|
// first: the question, then Report / Cancel. Returns the node its `where`
|
|
394
776
|
// words live in, so they change without the row being rebuilt.
|
|
395
777
|
function personRow(person) {
|
|
396
|
-
const box = el('div', { display: 'flex', flexDirection: 'column', gap: '4px' },
|
|
778
|
+
const box = el('div', { display: 'flex', flexDirection: 'column', gap: '4px' }, peopleBody);
|
|
397
779
|
let whereNode = null;
|
|
398
780
|
let more = false;
|
|
399
781
|
const act = (parent, action, primary) => {
|
|
@@ -458,17 +840,50 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
458
840
|
}
|
|
459
841
|
const peopleRows = new Map();
|
|
460
842
|
|
|
461
|
-
// Pointers to friends out of sight (a town): a small chip over a friend far
|
|
462
|
-
// off, or at the screen's edge with an arrow when they are off screen.
|
|
463
|
-
const pointers = el('div', { position: 'absolute', inset: '0' }, root);
|
|
464
|
-
const pointerNodes = new Map();
|
|
465
|
-
|
|
466
843
|
// A question put to the player (v1.10): an invitation to a party, a door
|
|
467
844
|
// their party wants to go through. One at a time, under the HUD.
|
|
468
845
|
const askCard = el('div', { position: 'absolute', top: 'max(92px, calc(env(safe-area-inset-top) + 80px))', left: '50%', transform: 'translateX(-50%)', width: 'min(86vw, 320px)', boxSizing: 'border-box', pointerEvents: 'auto', display: 'none', alignItems: 'center', gap: '8px', padding: '8px 10px', borderRadius: '12px', background: 'rgba(20,16,12,0.9)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)', fontSize: '14px' }, root);
|
|
469
846
|
askCard.addEventListener('pointerdown', (event) => event.stopPropagation());
|
|
847
|
+
// A suspended page can foreground before its first engine frame. Hide the
|
|
848
|
+
// old DOM at the lifecycle boundary so an overdue card cannot flash while
|
|
849
|
+
// that frame ages its existing lease. Keep its key and payload: a short
|
|
850
|
+
// absence may show the same still-live occurrence again on the next frame.
|
|
851
|
+
const askLifecycle = new AbortController();
|
|
852
|
+
let askAway = document.visibilityState === 'hidden' || document.hidden === true;
|
|
853
|
+
const hideAsk = () => {
|
|
854
|
+
askAway = true;
|
|
855
|
+
askCard.style.display = 'none';
|
|
856
|
+
};
|
|
857
|
+
const resumeAskFrames = () => { askAway = false; };
|
|
858
|
+
const askHidden = () => askAway || document.visibilityState === 'hidden' || document.hidden === true;
|
|
859
|
+
document.addEventListener?.('visibilitychange', () => {
|
|
860
|
+
if (document.visibilityState === 'hidden' || document.hidden === true) {
|
|
861
|
+
hideAsk();
|
|
862
|
+
} else {
|
|
863
|
+
resumeAskFrames();
|
|
864
|
+
}
|
|
865
|
+
}, { signal: askLifecycle.signal });
|
|
866
|
+
globalThis.window?.addEventListener?.('pagehide', hideAsk, { signal: askLifecycle.signal });
|
|
867
|
+
globalThis.window?.addEventListener?.('pageshow', resumeAskFrames, { signal: askLifecycle.signal });
|
|
470
868
|
let askKey = '';
|
|
471
869
|
let askNow = null;
|
|
870
|
+
// `fromAsk`: the button is on the ask card, so the tap carries the card it
|
|
871
|
+
// was drawn for (`onHeart(door, ask)`) for the lease to validate. A Doors
|
|
872
|
+
// list heart is `onHeart(door)`.
|
|
873
|
+
function heartButton(parent, door, hearted, fromAsk = false) {
|
|
874
|
+
const button = smallButton(parent, hearted ? '♥' : '♡', false);
|
|
875
|
+
button.style.flex = 'none';
|
|
876
|
+
button.setAttribute('aria-label', hearted ? 'Remove heart' : 'Heart this game');
|
|
877
|
+
button.setAttribute('aria-pressed', String(hearted));
|
|
878
|
+
button.addEventListener('pointerdown', (event) => {
|
|
879
|
+
event.stopPropagation();
|
|
880
|
+
if (fromAsk) {
|
|
881
|
+
onHeart(door, askNow);
|
|
882
|
+
} else {
|
|
883
|
+
onHeart(door);
|
|
884
|
+
}
|
|
885
|
+
});
|
|
886
|
+
}
|
|
472
887
|
// Standing by someone who is not in the player's party: invite them.
|
|
473
888
|
let nearHandler = () => {};
|
|
474
889
|
const nearButton = el('button', { position: 'absolute', bottom: 'max(160px, calc(env(safe-area-inset-bottom) + 150px))', left: '50%', transform: 'translateX(-50%)', pointerEvents: 'auto', padding: '6px 14px', borderRadius: '16px', border: '1px solid rgba(255,255,255,0.4)', background: 'rgba(20,16,12,0.78)', color: '#fff', font: '600 13px system-ui, sans-serif', display: 'none', cursor: 'pointer', touchAction: 'manipulation', maxWidth: '80vw', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, root);
|
|
@@ -478,7 +893,147 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
478
893
|
nearHandler();
|
|
479
894
|
});
|
|
480
895
|
|
|
481
|
-
|
|
896
|
+
// "Stuck?" (v1.33, `stuck.js`): a chip at the bottom centre, over the invite
|
|
897
|
+
// button's row, between the dock on the left and the round buttons on the
|
|
898
|
+
// right (never wider than leaves them clear: its words wrap). That is where
|
|
899
|
+
// it hangs; where it is drawn is `placeStuckChip`'s. Built on the first
|
|
900
|
+
// `stuckPrompt` with words, so a deck without `hub.stuck` has no node of it.
|
|
901
|
+
let stuckChip = null;
|
|
902
|
+
let stuckHandler = () => {};
|
|
903
|
+
let stuckShift = 'translateX(-50%)';
|
|
904
|
+
// Where the chip hangs while it is asked for (null otherwise): the room a
|
|
905
|
+
// toast leaves it, whether or not it could be drawn this frame.
|
|
906
|
+
let stuckSpot = null;
|
|
907
|
+
const shownRect = (node) => {
|
|
908
|
+
if (!node || node.style.display === 'none') {
|
|
909
|
+
return null;
|
|
910
|
+
}
|
|
911
|
+
const r = geometry.rect(node);
|
|
912
|
+
return r.width > 0 && r.height > 0 ? { left: r.left, right: r.right, top: r.top, bottom: r.bottom } : null;
|
|
913
|
+
};
|
|
914
|
+
// Measured only while a toast is up, on every setToast (said each frame, so
|
|
915
|
+
// a resize or a turned stage is met by the next one) and again after the
|
|
916
|
+
// chip is asked for. Everything a player taps is in its way, wherever it
|
|
917
|
+
// hangs (`toastBand`); the chip by the spot it is asked for at
|
|
918
|
+
// (`stuckSpot`), drawn this frame or not, so the two never chase each
|
|
919
|
+
// other's last box. The boxes are read before either inset is written,
|
|
920
|
+
// and a phone's toast starts under the safe area (`toastStart`).
|
|
921
|
+
function placeToast() {
|
|
922
|
+
if (toast.style.display === 'none') {
|
|
923
|
+
return;
|
|
924
|
+
}
|
|
925
|
+
// A landscape viewport keeps transient words in the top-centre band even
|
|
926
|
+
// with a mouse attached; this is the same visual lane on phones/tablets.
|
|
927
|
+
const wide = desktop() && !landscapeViewport();
|
|
928
|
+
const width = geometry.size(toast).w;
|
|
929
|
+
const height = geometry.size(toast).h;
|
|
930
|
+
const rects = [hud, hudText, ribbon, askCard, back, sound?.button, sound?.card, stats, talkButton, sitButton, nearButton, panel, dock, doorsList, peopleList, picker, grabButton, emoteButton, emoteRow, sayButton, sayCard].map(shownRect).filter(Boolean);
|
|
931
|
+
if (stuckSpot) {
|
|
932
|
+
rects.push(stuckSpot);
|
|
933
|
+
}
|
|
934
|
+
const band = toastBand({ desktop: wide, viewW: geometry.view().w, viewH: geometry.view().h, width, height, rects, start: Math.max(12, geometry.offsets(toastStart).top || 0) });
|
|
935
|
+
// With no free band toastBand clamps into the viewport. Choices win
|
|
936
|
+
// over transient feedback even when that fallback cannot fit above them.
|
|
937
|
+
const choices = talkOpen ? shownRect(panelAsks) : null;
|
|
938
|
+
const top = wide ? geometry.view().h - band.bottom - height : band.top;
|
|
939
|
+
const left = (geometry.view().w - width) / 2;
|
|
940
|
+
const blocked = choices && left < choices.right && left + width > choices.left && top < choices.bottom && top + height > choices.top;
|
|
941
|
+
toastChoiceBlocked = Boolean(blocked);
|
|
942
|
+
syncToastVisibility();
|
|
943
|
+
const nextTop = wide ? '' : `${band.top}px`;
|
|
944
|
+
const nextBottom = wide ? `${band.bottom}px` : '';
|
|
945
|
+
if (toast.style.top !== nextTop) {
|
|
946
|
+
toast.style.top = nextTop;
|
|
947
|
+
}
|
|
948
|
+
if (toast.style.bottom !== nextBottom) {
|
|
949
|
+
toast.style.bottom = nextBottom;
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
// The chip is kept out from under the HUD and a question the way a clear
|
|
953
|
+
// HUD keeps labels out from under itself (`hudClear.js`): moved to just
|
|
954
|
+
// under them, never off the view -- in any place, not only one that asks
|
|
955
|
+
// for `hud.clear`, since on a short view (a phone on its side) where it
|
|
956
|
+
// hangs is where they are. Where that leaves it over another control, or
|
|
957
|
+
// no room at all, it is not drawn (`chipShift`): the Doors row is still
|
|
958
|
+
// there. The toast reserves room for an asked-for chip on desktop; the
|
|
959
|
+
// chip otherwise yields to what a player taps or reads as a card. A
|
|
960
|
+
// cabinet's card and the ribbon are read where a clear HUD's flush left them, so this runs after
|
|
961
|
+
// `flushHudClear` in a frame. What is hung on the world -- labels, speech,
|
|
962
|
+
// pointers -- is not in its way: it passes under the chip as under every
|
|
963
|
+
// other button (their layers are made before it, so it is drawn over them),
|
|
964
|
+
// and a bubble drifting across never takes the chip down. Everything is
|
|
965
|
+
// read first, then the one style is written. Only while the chip is asked
|
|
966
|
+
// for; false when it cannot be drawn.
|
|
967
|
+
function placeStuckChip() {
|
|
968
|
+
const w = geometry.size(stuckChip).w;
|
|
969
|
+
const h = geometry.size(stuckChip).h;
|
|
970
|
+
const left = geometry.offsets(stuckChip).left - w / 2;
|
|
971
|
+
const top = geometry.offsets(stuckChip).top;
|
|
972
|
+
const above = [hud, askCard].map(shownRect).filter(Boolean);
|
|
973
|
+
const others = [hudText, back, toast, picker, talkButton, grabButton, emoteButton, emoteRow, sayButton, sayCard, feed, sitButton, dock, nearButton, stats, cabinet, ribbon, sound?.button, sound?.card].map(shownRect).filter(Boolean);
|
|
974
|
+
const down = chipShift({ left, right: left + w, top, bottom: top + h }, above, others, geometry.view().h);
|
|
975
|
+
if (down === null) {
|
|
976
|
+
return false;
|
|
977
|
+
}
|
|
978
|
+
const shift = down > 0 ? `translate(-50%, ${down}px)` : 'translateX(-50%)';
|
|
979
|
+
if (shift !== stuckShift) {
|
|
980
|
+
stuckShift = shift;
|
|
981
|
+
stuckChip.style.transform = shift;
|
|
982
|
+
}
|
|
983
|
+
return true;
|
|
984
|
+
}
|
|
985
|
+
function buildStuckChip() {
|
|
986
|
+
const chip = el('button', { position: 'absolute', bottom: 'max(202px, calc(env(safe-area-inset-bottom) + 192px))', left: '50%', transform: 'translateX(-50%)', pointerEvents: 'auto', padding: '9px 12px', borderRadius: '18px', border: '1px solid rgba(255,255,255,0.45)', background: 'rgba(20,16,12,0.8)', color: '#fff', font: '600 12px system-ui, sans-serif', display: 'none', cursor: 'pointer', touchAction: 'manipulation', boxSizing: 'border-box', width: 'max-content', maxWidth: 'calc(100vw - 170px)', textAlign: 'center' }, root);
|
|
987
|
+
chip.dataset.hub = 'stuck';
|
|
988
|
+
chip.addEventListener('pointerdown', (event) => {
|
|
989
|
+
event.stopPropagation();
|
|
990
|
+
event.preventDefault();
|
|
991
|
+
stuckHandler();
|
|
992
|
+
});
|
|
993
|
+
return chip;
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
// The sound control (a deck with `hub.soundscape`, `soundscape.js`): a small
|
|
997
|
+
// speaker button below the native camera corner, clear of the HUD and of
|
|
998
|
+
// the column of round buttons at the bottom right; a tap opens a card under
|
|
999
|
+
// it with Mute and a volume slider. Built on the first `soundControl`, so a
|
|
1000
|
+
// deck without the key has no node of it.
|
|
1001
|
+
let sound = null;
|
|
1002
|
+
const soundTop = 'max(64px, calc(env(safe-area-inset-top) + 64px))';
|
|
1003
|
+
function buildSound() {
|
|
1004
|
+
const top = soundTop;
|
|
1005
|
+
const button = el('button', { position: 'absolute', top, right: edge('right', 12), width: '40px', height: '40px', borderRadius: '20px', pointerEvents: 'auto', border: '1px solid rgba(255,255,255,0.4)', background: 'rgba(20,16,12,0.72)', color: '#fff', font: '18px system-ui, sans-serif', display: 'none', cursor: 'pointer', touchAction: 'manipulation', userSelect: 'none', padding: '0' }, root);
|
|
1006
|
+
button.dataset.hub = 'sound';
|
|
1007
|
+
const card = el('div', { position: 'absolute', top: `calc(${top} + 46px)`, right: edge('right', 12), width: 'min(70vw, 208px)', boxSizing: 'border-box', display: 'none', alignItems: 'center', gap: '8px', pointerEvents: 'auto', padding: '8px 10px', borderRadius: '12px', background: 'rgba(20,16,12,0.88)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)' }, root);
|
|
1008
|
+
card.dataset.hub = 'sound-card';
|
|
1009
|
+
card.addEventListener('pointerdown', (event) => event.stopPropagation());
|
|
1010
|
+
const mute = el('button', { flex: 'none', padding: '5px 10px', borderRadius: '12px', border: '1px solid rgba(255,255,255,0.35)', background: 'transparent', color: '#fff', font: '700 13px system-ui, sans-serif', cursor: 'pointer', touchAction: 'manipulation' }, card);
|
|
1011
|
+
const slider = el('input', { flex: '1', minWidth: '0', height: '28px', margin: '0', accentColor: '#e9c48f', cursor: 'pointer' }, card);
|
|
1012
|
+
slider.type = 'range';
|
|
1013
|
+
slider.min = '0';
|
|
1014
|
+
slider.max = '100';
|
|
1015
|
+
slider.step = '1';
|
|
1016
|
+
slider.setAttribute('aria-label', 'Volume');
|
|
1017
|
+
const made = { button, card, mute, slider, open: false, key: '', handlers: { onVolume() {}, onMuted() {} }, muted: false };
|
|
1018
|
+
button.addEventListener('pointerdown', (event) => {
|
|
1019
|
+
event.stopPropagation();
|
|
1020
|
+
event.preventDefault();
|
|
1021
|
+
made.open = !made.open;
|
|
1022
|
+
card.style.display = made.open ? 'flex' : 'none';
|
|
1023
|
+
layoutLandscapeRail();
|
|
1024
|
+
});
|
|
1025
|
+
mute.addEventListener('pointerdown', (event) => {
|
|
1026
|
+
event.stopPropagation();
|
|
1027
|
+
event.preventDefault();
|
|
1028
|
+
made.handlers.onMuted(!made.muted);
|
|
1029
|
+
});
|
|
1030
|
+
slider.addEventListener('input', () => made.handlers.onVolume(Number(slider.value) / 100));
|
|
1031
|
+
// The arrow keys are the avatar's again once the slider is let go.
|
|
1032
|
+
slider.addEventListener('change', () => slider.blur?.());
|
|
1033
|
+
return made;
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
const stats = el('div', { position: 'absolute', right: edge('right', 8), top: 'max(8px, env(safe-area-inset-top))', font: '11px/1.3 ui-monospace, monospace', opacity: '0.7', textAlign: 'right', whiteSpace: 'pre' }, root);
|
|
482
1037
|
|
|
483
1038
|
// A clear HUD (v1.26, `hudClear.js`), in a place whose manifest asks for it
|
|
484
1039
|
// (`setHudClear`). Everything below runs only then, or once as the option
|
|
@@ -487,64 +1042,51 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
487
1042
|
let hudClear = false;
|
|
488
1043
|
let hudClearDrawn = false;
|
|
489
1044
|
let hudClearKey = '';
|
|
490
|
-
let hudClearRect = null;
|
|
491
|
-
const hudClearSizes = new WeakMap();
|
|
492
1045
|
// The place before asked and this one does not: the styles of old, put
|
|
493
1046
|
// back the moment the option goes, whether or not a HUD is drawn after.
|
|
494
1047
|
function restoreHudClear() {
|
|
495
1048
|
hudBig.style.fontSize = '56px';
|
|
496
|
-
for (const key of ['whiteSpace', 'overflow', 'textOverflow'
|
|
1049
|
+
for (const key of ['whiteSpace', 'overflow', 'textOverflow']) {
|
|
497
1050
|
hudBig.style[key] = '';
|
|
498
1051
|
}
|
|
499
|
-
|
|
500
|
-
hudText.style[key] = '';
|
|
501
|
-
}
|
|
1052
|
+
hudBig.style.maxWidth = '100%';
|
|
502
1053
|
hud.style.maxHeight = '';
|
|
503
1054
|
hud.style.overflow = '';
|
|
504
1055
|
hudClearDrawn = false;
|
|
505
1056
|
hudClearKey = '';
|
|
506
|
-
hudClearRect = null;
|
|
507
1057
|
hudClearPending.clear();
|
|
508
1058
|
}
|
|
509
1059
|
function layoutHudClear(big, text) {
|
|
510
1060
|
hudClearDrawn = true;
|
|
511
1061
|
const backShown = back.style.display !== 'none';
|
|
512
|
-
const
|
|
513
|
-
|
|
514
|
-
return;
|
|
515
|
-
}
|
|
516
|
-
hudClearKey = key;
|
|
1062
|
+
const backBox = geometry.rect(back);
|
|
1063
|
+
const key = [hudTitle.textContent, big, text, geometry.view().w, geometry.view().h, backShown ? back.textContent : '', backBox.left, backBox.right].join('\u0001');
|
|
517
1064
|
const layout = hudLayout({
|
|
518
1065
|
big,
|
|
519
1066
|
text,
|
|
520
|
-
viewW:
|
|
521
|
-
viewH:
|
|
1067
|
+
viewW: geometry.view().w,
|
|
1068
|
+
viewH: geometry.view().h,
|
|
522
1069
|
// The big line's row is the Back button's: it keeps out of its way.
|
|
523
|
-
reserve: backShown ? back.
|
|
1070
|
+
reserve: backShown ? geometry.offsets(back).left + geometry.size(back).w + 8 : 0,
|
|
524
1071
|
});
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
hudText.style.webkitBoxOrient = layout.textLines === null ? '' : 'vertical';
|
|
536
|
-
hud.style.maxHeight = layout.maxHeight === null ? '' : `${layout.maxHeight}px`;
|
|
537
|
-
hud.style.overflow = layout.maxHeight === null ? '' : 'hidden';
|
|
1072
|
+
if (key !== hudClearKey) {
|
|
1073
|
+
hudClearKey = key;
|
|
1074
|
+
hudBig.style.fontSize = `${layout.bigPx}px`;
|
|
1075
|
+
hudBig.style.whiteSpace = layout.bigOneLine ? 'nowrap' : '';
|
|
1076
|
+
hudBig.style.overflow = layout.bigOneLine ? 'hidden' : '';
|
|
1077
|
+
hudBig.style.textOverflow = layout.bigOneLine ? 'ellipsis' : '';
|
|
1078
|
+
hudBig.style.maxWidth = layout.bigMaxWidth === null ? '100%' : `${layout.bigMaxWidth}px`;
|
|
1079
|
+
hud.style.maxHeight = layout.maxHeight === null ? '' : `${layout.maxHeight}px`;
|
|
1080
|
+
hud.style.overflow = layout.maxHeight === null ? '' : 'hidden';
|
|
1081
|
+
}
|
|
538
1082
|
if (layout.bigOneLine) {
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
1083
|
+
const fit = geometry.fit(hudBig);
|
|
1084
|
+
if (!geometry.active() || (fit.text === String(big) && fit.fontSize === hudBig.style.fontSize)) {
|
|
1085
|
+
const base = Number.parseFloat(fit.fontSize) || layout.bigPx;
|
|
1086
|
+
const px = fitPx(base, fit.client, fit.scroll);
|
|
1087
|
+
if (px < base) {hudBig.style.fontSize = `${px}px`;}
|
|
543
1088
|
}
|
|
544
1089
|
}
|
|
545
|
-
// The box as it is drawn now; it changes only with what the key holds.
|
|
546
|
-
const r = hud.getBoundingClientRect();
|
|
547
|
-
hudClearRect = r.width > 0 && r.height > 0 ? { left: r.left, right: r.right, top: r.top, bottom: r.bottom } : null;
|
|
548
1090
|
}
|
|
549
1091
|
// What a frame's setters ask to be kept clear of the HUD, by group
|
|
550
1092
|
// ("labels", "pointers", "cabinet", "ribbon"): each entry is [node, x, y,
|
|
@@ -573,32 +1115,27 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
573
1115
|
if (!hudClearPending.size) {
|
|
574
1116
|
return;
|
|
575
1117
|
}
|
|
576
|
-
const groups = [...hudClearPending.
|
|
1118
|
+
const groups = [...hudClearPending.entries()];
|
|
577
1119
|
hudClearPending.clear();
|
|
578
|
-
const rect = hudClear && hud.style.display !== 'none' ?
|
|
579
|
-
|
|
1120
|
+
const rect = hudClear && hud.style.display !== 'none' ? shownRect(hud) : null;
|
|
1121
|
+
const prompt = shownRect(hudText);
|
|
1122
|
+
if (!rect && !prompt) {
|
|
580
1123
|
return;
|
|
581
1124
|
}
|
|
582
1125
|
const moves = [];
|
|
583
|
-
for (const entries of groups) {
|
|
584
|
-
for (const [node, x, y, anchor
|
|
1126
|
+
for (const [group, entries] of groups) {
|
|
1127
|
+
for (const [node, x, y, anchor] of entries) {
|
|
585
1128
|
// One since hidden or taken away is left alone.
|
|
586
1129
|
if (!node || node.style.display === 'none' || !Number.isFinite(x) || !Number.isFinite(y)) {
|
|
587
1130
|
continue;
|
|
588
1131
|
}
|
|
589
|
-
//
|
|
590
|
-
//
|
|
591
|
-
|
|
592
|
-
const
|
|
593
|
-
const
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
box = { key, w: node.offsetWidth, h: node.offsetHeight };
|
|
597
|
-
hudClearSizes.set(node, box);
|
|
598
|
-
}
|
|
599
|
-
const down = pushBelow(boxAt(x, y, box.w, box.h, anchor), rect, undefined, window.innerHeight);
|
|
600
|
-
if (down > 0) {
|
|
601
|
-
moves.push([node, y + down]);
|
|
1132
|
+
// Unchanged labels use their snapshot size; changed copy or wrapping
|
|
1133
|
+
// is refreshed once before this batch writes clearance positions.
|
|
1134
|
+
const box = geometry.size(node);
|
|
1135
|
+
const down = pushBelow(boxAt(x, y, box.w, box.h, anchor), rect, undefined, geometry.view().h);
|
|
1136
|
+
const up = group === 'labels' || group === 'pointers' ? promptShift(boxAt(x, y + down, box.w, box.h, anchor), prompt) : 0;
|
|
1137
|
+
if (down + up !== 0) {
|
|
1138
|
+
moves.push([node, y + down + up]);
|
|
602
1139
|
}
|
|
603
1140
|
}
|
|
604
1141
|
}
|
|
@@ -607,8 +1144,569 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
607
1144
|
}
|
|
608
1145
|
}
|
|
609
1146
|
|
|
610
|
-
|
|
611
|
-
|
|
1147
|
+
// v1.74: made only when an opted-in place offers chips.
|
|
1148
|
+
let actionChips = null, actionKey = '', actionHandler = null, actionListeners = null;
|
|
1149
|
+
let actionIdentity = 0;
|
|
1150
|
+
let actionOverflow = null, actionOverflowOpen = null, actionOverflowObstacles = null;
|
|
1151
|
+
const actionSize = (node) => {
|
|
1152
|
+
const box = geometry.rect(node), size = geometry.size(node);
|
|
1153
|
+
return { w: box.width || size.w, h: box.height || size.h };
|
|
1154
|
+
};
|
|
1155
|
+
let overflowSources = new Set();
|
|
1156
|
+
function syncOverflowSources() {
|
|
1157
|
+
const nodes = new Set(actionOverflow?.surfaces?.() ?? []);
|
|
1158
|
+
for (const node of overflowSources) {if (!nodes.has(node)) {geometry.unregister(node);}}
|
|
1159
|
+
for (const node of nodes) {if (!overflowSources.has(node)) {geometry.register(node);}}
|
|
1160
|
+
overflowSources = nodes;
|
|
1161
|
+
}
|
|
1162
|
+
function clearLegacyActions() {
|
|
1163
|
+
actionListeners?.abort();
|
|
1164
|
+
actionChips?.remove();
|
|
1165
|
+
actionChips = actionListeners = actionHandler = null;
|
|
1166
|
+
actionKey = '';
|
|
1167
|
+
}
|
|
1168
|
+
function clearActions() {
|
|
1169
|
+
clearLegacyActions();
|
|
1170
|
+
actionOverflow?.dispose();
|
|
1171
|
+
actionOverflow = null;
|
|
1172
|
+
syncOverflowSources();
|
|
1173
|
+
actionOverflowOpen = actionOverflowObstacles = null;
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
// A turned phone reserves its lower-left half for the engine's drag stick.
|
|
1177
|
+
// Hub actions form one compact rail on the right; town navigation moves to
|
|
1178
|
+
// the upper-left, below the native 64 x 56 exit exclusion and the kit Back
|
|
1179
|
+
// button. Portrait values below are the original values byte-for-byte.
|
|
1180
|
+
let landscape = landscapeViewport();
|
|
1181
|
+
let textAsk = null;
|
|
1182
|
+
let placeMenu = null;
|
|
1183
|
+
// The nodes a row sheet covers (`coverControls`).
|
|
1184
|
+
const menuCovered = new Set();
|
|
1185
|
+
const railNodes = [picker, grabButton, emoteButton, sayButton, sitButton, talkButton, nearButton];
|
|
1186
|
+
const railHeight = (node) => Number.parseFloat(node.style.height) || geometry.size(node).h;
|
|
1187
|
+
function layoutLandscapeRail() {
|
|
1188
|
+
if (safeInsets) {return;}
|
|
1189
|
+
if (!landscape) {
|
|
1190
|
+
return;
|
|
1191
|
+
}
|
|
1192
|
+
const baseBottom = 10 + lockLift;
|
|
1193
|
+
let bottom = baseBottom;
|
|
1194
|
+
let right = 12;
|
|
1195
|
+
let columnWidth = 0;
|
|
1196
|
+
const placed = new Map();
|
|
1197
|
+
const ceiling = Math.max(
|
|
1198
|
+
safeInsets ? 108 + (safeLayout?.view().insets.top ?? 0) : Math.max(64, Math.min(geometry.view().h - 44, 76)),
|
|
1199
|
+
shownRect(sound?.button)?.bottom + 6 || 0,
|
|
1200
|
+
shownRect(sound?.card)?.bottom + 6 || 0,
|
|
1201
|
+
);
|
|
1202
|
+
for (const node of railNodes) {
|
|
1203
|
+
if (node.style.display === 'none' || node.style.visibility === 'hidden') {
|
|
1204
|
+
continue;
|
|
1205
|
+
}
|
|
1206
|
+
const height = railHeight(node);
|
|
1207
|
+
if (bottom > baseBottom && geometry.view().h - bottom - height < ceiling) {
|
|
1208
|
+
right += columnWidth + 6;
|
|
1209
|
+
bottom = baseBottom;
|
|
1210
|
+
columnWidth = 0;
|
|
1211
|
+
}
|
|
1212
|
+
node.style.right = safeInsets ? `calc(max(12px, env(safe-area-inset-right)) + ${right - 12}px)` : `${right}px`;
|
|
1213
|
+
node.style.bottom = `max(${bottom}px, calc(env(safe-area-inset-bottom) + ${Math.max(0, bottom - 10)}px))`;
|
|
1214
|
+
const width = geometry.size(node).w;
|
|
1215
|
+
placed.set(node, { right, bottom, width });
|
|
1216
|
+
columnWidth = Math.max(columnWidth, width);
|
|
1217
|
+
bottom += height + 6;
|
|
1218
|
+
}
|
|
1219
|
+
// Open pickers sit immediately left of the button that owns them, even
|
|
1220
|
+
// when the dense rail wrapped that button into its second column.
|
|
1221
|
+
for (const [card, button] of [[emoteRow, emoteButton], [sayCard, sayButton]]) {
|
|
1222
|
+
const at = placed.get(button);
|
|
1223
|
+
if (!at) {continue;}
|
|
1224
|
+
// Clear the whole action lane even when this card belongs to a narrower
|
|
1225
|
+
// round button beside a 160px text action.
|
|
1226
|
+
card.style.right = safeInsets ? `calc(max(12px, env(safe-area-inset-right)) + ${Math.max(184, at.right + at.width + 6) - 12}px)` : `${Math.max(184, at.right + at.width + 6)}px`;
|
|
1227
|
+
card.style.bottom = button.style.bottom;
|
|
1228
|
+
card.style.maxHeight = `calc(100dvh - ${at.bottom + 12}px - env(safe-area-inset-top) - env(safe-area-inset-bottom))`;
|
|
1229
|
+
card.style.overflowY = 'auto';
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
function layoutOpenOverlays() {
|
|
1233
|
+
const width = 'min(56vw, max(220px, calc(100vw - 344px)), 560px)';
|
|
1234
|
+
if (placeMenu?.sheet) {
|
|
1235
|
+
placeMenu.sheet.style.width = placeMenu.rows ? 'min(calc(100% - 24px), 720px)' : landscape ? width : 'min(100%, 720px)';
|
|
1236
|
+
}
|
|
1237
|
+
if (textAsk?.card) {
|
|
1238
|
+
textAsk.card.style.width = landscape ? width : 'min(90vw, 320px)';
|
|
1239
|
+
textAsk.card.style.maxHeight = landscape ? 'calc(100dvh - 88px - env(safe-area-inset-top) - env(safe-area-inset-bottom))' : '';
|
|
1240
|
+
textAsk.card.style.overflowY = landscape ? 'auto' : '';
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
function applyViewportLayout(force = false) {
|
|
1244
|
+
const next = landscapeViewport();
|
|
1245
|
+
if (!force && next === landscape) {
|
|
1246
|
+
for (const list of [doorsList, peopleList]) {aboveDock(list);}
|
|
1247
|
+
if (next) {layoutLandscapeRail();}
|
|
1248
|
+
return;
|
|
1249
|
+
}
|
|
1250
|
+
landscape = next;
|
|
1251
|
+
back.style.left = edge('left', landscape ? 76 : 12);
|
|
1252
|
+
hud.style.maxWidth = landscape ? 'min(42vw, 420px)' : '70vw';
|
|
1253
|
+
toast.style.maxWidth = landscape ? 'min(42vw, 420px)' : 'calc(100vw - 24px)';
|
|
1254
|
+
Object.assign(dock.style, landscape
|
|
1255
|
+
? { top: 'max(68px, calc(env(safe-area-inset-top) + 56px))', bottom: '', maxWidth: 'min(24vw, 160px)' }
|
|
1256
|
+
: { top: '', bottom: 'max(10px, env(safe-area-inset-bottom))', maxWidth: 'calc(100vw - 130px)' });
|
|
1257
|
+
for (const list of [doorsList, peopleList]) {aboveDock(list);}
|
|
1258
|
+
const centred = landscape
|
|
1259
|
+
? { left: 'auto', right: edge('right', 12), transform: 'none', maxWidth: 'min(38vw, 160px)' }
|
|
1260
|
+
: { left: '50%', right: '', transform: 'translateX(-50%)', maxWidth: '' };
|
|
1261
|
+
Object.assign(talkButton.style, centred);
|
|
1262
|
+
Object.assign(sitButton.style, centred);
|
|
1263
|
+
Object.assign(nearButton.style, landscape ? centred : { ...centred, maxWidth: '80vw' });
|
|
1264
|
+
Object.assign(grabButton.style, landscape
|
|
1265
|
+
? { right: edge('right', 14), width: '56px', height: '56px', borderRadius: '28px' }
|
|
1266
|
+
: { right: edge('right', 14), width: '76px', height: '76px', borderRadius: '38px' });
|
|
1267
|
+
for (const node of [emoteButton, sayButton]) {
|
|
1268
|
+
Object.assign(node.style, landscape
|
|
1269
|
+
? { right: edge('right', 18), width: '44px', height: '44px', borderRadius: '22px' }
|
|
1270
|
+
: { right: edge('right', 20), width: '52px', height: '52px', borderRadius: '26px' });
|
|
1271
|
+
}
|
|
1272
|
+
Object.assign(emoteRow.style, landscape
|
|
1273
|
+
? { right: edge('right', 68), maxWidth: 'calc(100vw - 156px)', overflowX: 'auto' }
|
|
1274
|
+
: { right: edge('right', 80), maxWidth: '', maxHeight: '', overflowX: '', overflowY: '' });
|
|
1275
|
+
Object.assign(sayCard.style, landscape
|
|
1276
|
+
? { right: edge('right', 68), maxHeight: 'calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom))', overflowY: 'auto' }
|
|
1277
|
+
: { right: edge('right', 80), maxHeight: '', overflowY: '' });
|
|
1278
|
+
if (!landscape) {
|
|
1279
|
+
picker.style.right = edge('right', 10);
|
|
1280
|
+
picker.style.bottom = lockLift ? `calc(${cornerBottoms.get(picker)} + ${lockLift}px)` : cornerBottoms.get(picker);
|
|
1281
|
+
grabButton.style.bottom = lockLift ? `calc(${cornerBottoms.get(grabButton)} + ${lockLift}px)` : cornerBottoms.get(grabButton);
|
|
1282
|
+
emoteButton.style.bottom = lockLift ? `calc(${cornerBottoms.get(emoteButton)} + ${lockLift}px)` : cornerBottoms.get(emoteButton);
|
|
1283
|
+
emoteRow.style.bottom = lockLift ? `calc(${cornerBottoms.get(emoteRow)} + ${lockLift}px)` : cornerBottoms.get(emoteRow);
|
|
1284
|
+
sayButton.style.bottom = lockLift ? `calc(${cornerBottoms.get(sayButton)} + ${lockLift}px)` : cornerBottoms.get(sayButton);
|
|
1285
|
+
sayCard.style.bottom = lockLift ? `calc(${cornerBottoms.get(sayCard)} + ${lockLift}px)` : cornerBottoms.get(sayCard);
|
|
1286
|
+
sitButton.style.bottom = 'max(112px, calc(env(safe-area-inset-bottom) + 102px))';
|
|
1287
|
+
talkButton.style.bottom = 'max(64px, calc(env(safe-area-inset-bottom) + 54px))';
|
|
1288
|
+
nearButton.style.bottom = 'max(160px, calc(env(safe-area-inset-bottom) + 150px))';
|
|
1289
|
+
}
|
|
1290
|
+
layoutPanel();
|
|
1291
|
+
layoutLandscapeRail();
|
|
1292
|
+
layoutOpenOverlays();
|
|
1293
|
+
placeToast();
|
|
1294
|
+
}
|
|
1295
|
+
const viewportChanged = () => {applyViewportLayout(); fitPicker(true);};
|
|
1296
|
+
const unwatchViewport = watchViewport(viewportChanged);
|
|
1297
|
+
// Avoid extra portrait writes: existing portrait snapshots remain a proof
|
|
1298
|
+
// of the untouched baseline, while an initially-landscape view is laid out.
|
|
1299
|
+
if (landscape) {
|
|
1300
|
+
applyViewportLayout(true);
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
// v1.75: only allocated for an opted-in prompt. The field is the only
|
|
1304
|
+
// DOM node that ever holds an answer, and it is wiped on every close.
|
|
1305
|
+
function closeTextAsk() {
|
|
1306
|
+
if (!textAsk?.card) {
|
|
1307
|
+
return;
|
|
1308
|
+
}
|
|
1309
|
+
textAsk.listeners.abort();
|
|
1310
|
+
textAsk.input.value = '';
|
|
1311
|
+
textAsk.input.blur();
|
|
1312
|
+
textAsk.shield.remove();
|
|
1313
|
+
textAsk.card = textAsk.shield = textAsk.input = textAsk.listeners = null;
|
|
1314
|
+
textAsk.onOpen?.(false);
|
|
1315
|
+
textAsk.onOpen = textAsk.cancel = null;
|
|
1316
|
+
}
|
|
1317
|
+
function clearTextAsk() {
|
|
1318
|
+
closeTextAsk();
|
|
1319
|
+
textAsk = null;
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
// v1.79: only an opted-in offer creates this bottom sheet or its CSS.
|
|
1323
|
+
function closeMenu() {
|
|
1324
|
+
if (!placeMenu?.sheet) {return;}
|
|
1325
|
+
placeMenu.listeners.abort();
|
|
1326
|
+
for (const timer of placeMenu.timers) { clearTimeout(timer); }
|
|
1327
|
+
placeMenu.sheet.remove();
|
|
1328
|
+
placeMenu.css.remove();
|
|
1329
|
+
placeMenu.restoreHud?.();
|
|
1330
|
+
uncoverControls();
|
|
1331
|
+
placeMenu.sheet = placeMenu.css = placeMenu.listeners = null;
|
|
1332
|
+
placeMenu.onOpen?.(false);
|
|
1333
|
+
placeMenu.onOpen = placeMenu.cancel = null;
|
|
1334
|
+
}
|
|
1335
|
+
function clearMenu() {
|
|
1336
|
+
closeMenu();
|
|
1337
|
+
placeMenu = null;
|
|
1338
|
+
}
|
|
1339
|
+
// A row sheet without `face` reaches to 24px under the top of the view, so
|
|
1340
|
+
// the controls drawn under it (Doors and People, the direction chips, the
|
|
1341
|
+
// character, chat, emoji and sound buttons, Shift lock, action chips and
|
|
1342
|
+
// rails) are hidden while it is open. The mask is a marker attribute and
|
|
1343
|
+
// one `!important` rule in the sheet's own style element: it never reads
|
|
1344
|
+
// or writes a control's style.visibility, so the visibility the kit gives a
|
|
1345
|
+
// control under the sheet is the one it has once the sheet closes. Asked
|
|
1346
|
+
// again every frame, so a control made while the sheet is open is covered
|
|
1347
|
+
// too.
|
|
1348
|
+
const MENU_COVERED_RULE = '[data-hub-menu-covered] { visibility: hidden !important; }';
|
|
1349
|
+
function menuCoveredNodes() {
|
|
1350
|
+
return [
|
|
1351
|
+
dock, doorsList, peopleList, pointers, picker, sayButton, sayCard, emoteButton, emoteRow,
|
|
1352
|
+
sound?.button, sound?.card, grabButton, talkButton, sitButton, nearButton, stuckChip,
|
|
1353
|
+
actionChips, actRail, padContext?.node, companionLock,
|
|
1354
|
+
...[...root.children].filter((node) => node.dataset?.hub === 'action-rail'),
|
|
1355
|
+
...[...extraSurfaces.values()].filter((item) => item.kind === 'control').map((item) => item.node),
|
|
1356
|
+
].filter((node) => node?.dataset);
|
|
1357
|
+
}
|
|
1358
|
+
function coverControls() {
|
|
1359
|
+
if (!placeMenu?.covers) {return;}
|
|
1360
|
+
for (const node of menuCoveredNodes()) {
|
|
1361
|
+
if (menuCovered.has(node) && node.dataset.hubMenuCovered !== undefined) {continue;}
|
|
1362
|
+
node.dataset.hubMenuCovered = '';
|
|
1363
|
+
menuCovered.add(node);
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
function uncoverControls() {
|
|
1367
|
+
if (!menuCovered.size) {return;}
|
|
1368
|
+
for (const node of menuCovered) {delete node.dataset.hubMenuCovered;}
|
|
1369
|
+
menuCovered.clear();
|
|
1370
|
+
}
|
|
1371
|
+
function setMenu(offer, handler, onOpen) {
|
|
1372
|
+
if (!offer) { closeMenu(); return; }
|
|
1373
|
+
if (placeMenu && offer.n <= placeMenu.n) {return;}
|
|
1374
|
+
closeMenu();
|
|
1375
|
+
placeMenu = { n: offer.n };
|
|
1376
|
+
const spec = offer.spec;
|
|
1377
|
+
if (!spec) {return;}
|
|
1378
|
+
const rows = spec.presentation === 'rows';
|
|
1379
|
+
placeMenu.rows = rows;
|
|
1380
|
+
if (rows) {
|
|
1381
|
+
const visibility = hud.style.visibility, promptVisibility = hudText.style.visibility;
|
|
1382
|
+
hud.style.visibility = hudText.style.visibility = 'hidden';
|
|
1383
|
+
placeMenu.restoreHud = () => { hud.style.visibility = visibility; hudText.style.visibility = promptVisibility; };
|
|
1384
|
+
}
|
|
1385
|
+
placeMenu.covers = rows && !Object.hasOwn(spec, 'face');
|
|
1386
|
+
if (Object.hasOwn(spec, 'face')) {placeMenu.face = spec.face;}
|
|
1387
|
+
const height = Object.hasOwn(spec, 'face') ? 40 : 55;
|
|
1388
|
+
const listeners = new AbortController(), signal = listeners.signal, timers = new Set();
|
|
1389
|
+
// The same column, padding, corners and shadow as the Doors/chat panels.
|
|
1390
|
+
// Token fallbacks use their existing palette when no tokens are installed.
|
|
1391
|
+
const sheet = el('div', { position: 'absolute', left: '50%', bottom: '0', transform: 'translateX(-50%)', width: 'min(100%, 720px)', maxHeight: rows && !Object.hasOwn(spec, 'face') ? 'calc(100vh - 24px)' : `${height}vh`, boxSizing: 'border-box', overflow: 'hidden', pointerEvents: 'auto', display: 'flex', flexDirection: 'column', gap: '6px', padding: '12px', paddingBottom: 'max(12px, env(safe-area-inset-bottom))', borderRadius: '12px 12px 0 0', background: 'var(--castle-surface-3, rgba(20,16,12,0.88))', color: 'var(--castle-text-primary, #fff)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)', zIndex: '9' }, root);
|
|
1392
|
+
sheet.className = 'hub-menu-sheet';
|
|
1393
|
+
sheet.dataset.hub = 'menu';
|
|
1394
|
+
sheet.setAttribute('role', 'dialog');
|
|
1395
|
+
sheet.setAttribute('aria-label', spec.title);
|
|
1396
|
+
const css = el('style', {}, sheet);
|
|
1397
|
+
css.textContent = `
|
|
1398
|
+
.hub-menu-tile { color: inherit; font: inherit; border: 1px solid var(--castle-border-2, rgba(255,255,255,.4)); background: var(--castle-surface-4, rgba(255,255,255,.1)); border-radius: 8px; }
|
|
1399
|
+
.hub-menu-tile:not(:disabled) { cursor: pointer; }
|
|
1400
|
+
.hub-menu-tile:not(:disabled):active, .hub-menu-tile.is-pressed { background: var(--castle-surface-5, rgba(255,255,255,.18)); transform: scale(.96); }
|
|
1401
|
+
@media (hover: hover) { .hub-menu-tile:not(:disabled):hover { border-color: var(--castle-text-primary, #fff); } }
|
|
1402
|
+
@media (prefers-reduced-motion: reduce) { .hub-menu-tile:not(:disabled):active, .hub-menu-tile.is-pressed { transform: none; } }
|
|
1403
|
+
@media (max-width: 600px) { .hub-menu-grid { grid-template-columns: repeat(4, minmax(64px, 1fr)) !important; } }
|
|
1404
|
+
@media (max-width: 340px) { .hub-menu-grid { grid-template-columns: repeat(3, minmax(64px, 1fr)) !important; } }
|
|
1405
|
+
@supports (height: 1dvh) { .hub-menu-sheet { max-height: ${rows && !Object.hasOwn(spec, 'face') ? 'calc(100dvh - 24px)' : `${height}dvh`} !important; } }
|
|
1406
|
+
` + (placeMenu.covers ? ` ${MENU_COVERED_RULE}\n ` : '');
|
|
1407
|
+
for (const type of ['pointerdown', 'pointermove', 'pointerup', 'mousedown', 'wheel', 'contextmenu', 'keydown', 'keyup']) {
|
|
1408
|
+
sheet.addEventListener(type, (event) => event.stopPropagation(), { signal });
|
|
1409
|
+
}
|
|
1410
|
+
const cancel = () => {
|
|
1411
|
+
if (!placeMenu?.sheet) {return;}
|
|
1412
|
+
closeMenu();
|
|
1413
|
+
handler('close', offer.n);
|
|
1414
|
+
};
|
|
1415
|
+
globalThis.addEventListener?.('keydown', (event) => {
|
|
1416
|
+
if (event.key === 'Escape' || event.key === 'BrowserBack') {
|
|
1417
|
+
event.preventDefault(); event.stopImmediatePropagation(); cancel();
|
|
1418
|
+
}
|
|
1419
|
+
}, { capture: true, signal });
|
|
1420
|
+
const row = el('div', { display: 'flex', alignItems: 'center', gap: '8px', flexShrink: '0' }, sheet);
|
|
1421
|
+
el('div', { flex: '1', overflowWrap: 'anywhere' }, row).textContent = spec.title;
|
|
1422
|
+
const close = smallButton(row, '×', false);
|
|
1423
|
+
close.type = 'button';
|
|
1424
|
+
Object.assign(close.style, { minWidth: '44px', minHeight: '44px', touchAction: 'manipulation' });
|
|
1425
|
+
close.setAttribute('aria-label', 'Close');
|
|
1426
|
+
close.addEventListener('pointerdown', (event) => event.preventDefault(), { signal });
|
|
1427
|
+
close.addEventListener('click', () => { close.blur(); cancel(); }, { signal });
|
|
1428
|
+
if (spec.note) {el('div', { fontSize: '13px', color: 'var(--castle-text-secondary, #fff)', overflowWrap: 'anywhere', flexShrink: '0' }, sheet).textContent = spec.note;}
|
|
1429
|
+
const scroll = el('div', { overflowY: 'auto', minHeight: '0', overscrollBehavior: 'contain', touchAction: 'pan-y' }, sheet);
|
|
1430
|
+
if (rows) {
|
|
1431
|
+
Object.assign(scroll.style, { flex: '1 1 auto', scrollbarGutter: 'stable' });
|
|
1432
|
+
drawMenuRows({ el, sheet, scroll, spec, signal, pick: (id) => { if (placeMenu?.sheet) { handler(id, offer.n); } } });
|
|
1433
|
+
}
|
|
1434
|
+
if (!rows) {
|
|
1435
|
+
for (const section of spec.sections) {
|
|
1436
|
+
el('div', { fontSize: '13px', margin: '8px 0', color: 'var(--castle-text-secondary, #fff)' }, scroll).textContent = section.title;
|
|
1437
|
+
const grid = el('div', { display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(64px, 1fr))', gap: '8px' }, scroll);
|
|
1438
|
+
grid.className = 'hub-menu-grid';
|
|
1439
|
+
for (const item of section.items) {
|
|
1440
|
+
const tile = el('button', { position: 'relative', aspectRatio: '1', minWidth: '64px', minHeight: '64px', padding: '6px', overflow: 'hidden', display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: '4px', touchAction: 'manipulation', overflowWrap: 'anywhere' }, grid);
|
|
1441
|
+
tile.className = 'hub-menu-tile'; tile.type = 'button'; tile.disabled = spec.readOnly === true;
|
|
1442
|
+
tile.dataset.id = item.id;
|
|
1443
|
+
tile.setAttribute('aria-label', item.label);
|
|
1444
|
+
tile.setAttribute('aria-pressed', item.on === true ? 'true' : 'false');
|
|
1445
|
+
if (item.on) {
|
|
1446
|
+
tile.style.outline = '2px solid var(--castle-text-primary, #fff)';
|
|
1447
|
+
tile.style.outlineOffset = '-3px';
|
|
1448
|
+
el('span', { position: 'absolute', top: '2px', right: '4px', fontSize: '12px' }, tile).textContent = '✓';
|
|
1449
|
+
}
|
|
1450
|
+
const swatch = el('span', { width: '28px', height: '28px', flexShrink: '0', borderRadius: item.icon ? '0' : '6px', background: item.color ?? 'var(--castle-text-primary, #fff)' }, tile);
|
|
1451
|
+
if (item.icon) {
|
|
1452
|
+
swatch.style.maskImage = swatch.style.webkitMaskImage = menuIcon(item.icon);
|
|
1453
|
+
swatch.style.maskSize = swatch.style.webkitMaskSize = 'contain';
|
|
1454
|
+
swatch.style.maskRepeat = swatch.style.webkitMaskRepeat = 'no-repeat';
|
|
1455
|
+
}
|
|
1456
|
+
swatch.setAttribute('aria-hidden', 'true');
|
|
1457
|
+
el('span', { fontSize: '12px', lineHeight: '1.15', maxHeight: '2.3em', overflow: 'hidden' }, tile).textContent = item.label;
|
|
1458
|
+
if (!tile.disabled) {
|
|
1459
|
+
tile.addEventListener('pointerdown', (event) => event.preventDefault(), { signal });
|
|
1460
|
+
tile.addEventListener('click', () => {
|
|
1461
|
+
if (!placeMenu?.sheet) {return;}
|
|
1462
|
+
tile.blur();
|
|
1463
|
+
tile.className = 'hub-menu-tile is-pressed';
|
|
1464
|
+
const timer = setTimeout(() => { tile.className = 'hub-menu-tile'; timers.delete(timer); }, 120);
|
|
1465
|
+
timers.add(timer);
|
|
1466
|
+
handler(item.id, offer.n);
|
|
1467
|
+
}, { signal });
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
Object.assign(placeMenu, { sheet, css, listeners, timers, onOpen, cancel });
|
|
1473
|
+
coverControls();
|
|
1474
|
+
layoutOpenOverlays();
|
|
1475
|
+
onOpen?.(true);
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1478
|
+
let actMode = false, actRail = null;
|
|
1479
|
+
let debugLayout = null;
|
|
1480
|
+
const extraSurfaces = new Map();
|
|
1481
|
+
let talkCaption = null;
|
|
1482
|
+
let padContext = null;
|
|
1483
|
+
const placePadContext = placementCache();
|
|
1484
|
+
function syncTalkCaption() {
|
|
1485
|
+
const node = extraSurfaces.get('engine-look')?.node;
|
|
1486
|
+
if (talkCaption && (!talkOpen || talkCaption.node !== node)) {
|
|
1487
|
+
talkCaption.node.style.visibility = talkCaption.visibility;
|
|
1488
|
+
talkCaption = null;
|
|
1489
|
+
}
|
|
1490
|
+
if (talkOpen && node && !talkCaption) {
|
|
1491
|
+
talkCaption = { node, visibility: node.style.visibility };
|
|
1492
|
+
node.style.visibility = 'hidden';
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
// This same registry feeds safe placement, More/Actions obstacles, and its
|
|
1496
|
+
// observer membership. No independent additive external-node watch list.
|
|
1497
|
+
function externalEntries() {
|
|
1498
|
+
for (const [id, item] of extraSurfaces) {
|
|
1499
|
+
if (item.node.isConnected === false) {geometry.unregister(item.node); extraSurfaces.delete(id);}
|
|
1500
|
+
}
|
|
1501
|
+
return [...extraSurfaces];
|
|
1502
|
+
}
|
|
1503
|
+
function syncActionSurfaces() {
|
|
1504
|
+
if (safeInsets) {safeLayout?.schedule(); return;}
|
|
1505
|
+
if (actionOverflow && actionOverflowObstacles) {actionOverflow.reconcileWatch(actionOverflowObstacles());}
|
|
1506
|
+
}
|
|
1507
|
+
const api = {
|
|
1508
|
+
beginLayoutFrame(canvas) {
|
|
1509
|
+
if (canvasSource !== canvas) {
|
|
1510
|
+
geometry.unregister(canvasSource); canvasSource = canvas; geometry.register(canvas);
|
|
1511
|
+
}
|
|
1512
|
+
geometry.beginFrame();
|
|
1513
|
+
if (stuckSpot && stuckChip) {
|
|
1514
|
+
const { w, h } = geometry.size(stuckChip), { left, top } = geometry.offsets(stuckChip);
|
|
1515
|
+
stuckSpot = { left: left - w / 2, right: left + w / 2, top, bottom: top + h };
|
|
1516
|
+
}
|
|
1517
|
+
const rect = canvas?.getBoundingClientRect ? geometry.rect(canvas) : null;
|
|
1518
|
+
if (worldViewport) {worldViewport = rect?.width > 0 && rect.height > 0 ? rect : null;}
|
|
1519
|
+
return rect;
|
|
1520
|
+
},
|
|
1521
|
+
endLayoutFrame() {
|
|
1522
|
+
// Setters late in the frame may have queued HUD clearance; place it by
|
|
1523
|
+
// this frame's snapshot before the snapshot ends.
|
|
1524
|
+
flushHudClear();
|
|
1525
|
+
if (placeMenu?.sheet) {coverControls();}
|
|
1526
|
+
geometry.endFrame();
|
|
1527
|
+
for (const [key, node] of labelMeasures) {
|
|
1528
|
+
if (!usedLabelMeasures.has(key)) {node.remove(); labelMeasures.delete(key);}
|
|
1529
|
+
}
|
|
1530
|
+
usedLabelMeasures.clear();
|
|
1531
|
+
},
|
|
1532
|
+
layoutGeometry: () => geometry,
|
|
1533
|
+
...(safeInsets ? {
|
|
1534
|
+
layout: () => safeLayout.report(),
|
|
1535
|
+
beginSafeInsets: () => safeLayout.begin(),
|
|
1536
|
+
flushSafeInsets: () => safeLayout.flush(),
|
|
1537
|
+
frameSafeInsets: () => safeLayout.frame(),
|
|
1538
|
+
} : {}),
|
|
1539
|
+
// Surface ownership is independent of safe-inset control placement. Door
|
|
1540
|
+
// text still yields to external cards when that optional placement is off.
|
|
1541
|
+
safeSurface(id, node, kind = 'card', placement = null) {
|
|
1542
|
+
const previous = extraSurfaces.get(id);
|
|
1543
|
+
if (previous?.node === node && previous?.kind === kind && previous?.placement === placement) {return;}
|
|
1544
|
+
if (previous?.node && previous.node !== node) {geometry.unregister(previous.node);}
|
|
1545
|
+
geometry.register(node, { positioned: placement?.transient === true });
|
|
1546
|
+
if (node) {extraSurfaces.set(id, { node, kind, placement });} else {extraSurfaces.delete(id);}
|
|
1547
|
+
syncTalkCaption();
|
|
1548
|
+
safeLayout?.watch(node);
|
|
1549
|
+
safeLayout?.schedule();
|
|
1550
|
+
syncActionSurfaces();
|
|
1551
|
+
},
|
|
1552
|
+
interactionRoot: () => root,
|
|
1553
|
+
interactionRail(pair, act, jump) {
|
|
1554
|
+
if (actRail) {railNodes.splice(railNodes.indexOf(actRail), 1);}
|
|
1555
|
+
actRail = pair;
|
|
1556
|
+
if (pair) {railNodes.splice(1, 0, pair);}
|
|
1557
|
+
api.safeSurface?.('act-pair', pair, 'control', pair ? {
|
|
1558
|
+
stack: 2,
|
|
1559
|
+
reportNodes: () => [{ id: 'act', node: act, kind: 'control' }, { id: 'jump', node: jump, kind: 'control' }],
|
|
1560
|
+
} : null);
|
|
1561
|
+
layoutLandscapeRail();
|
|
1562
|
+
},
|
|
1563
|
+
layoutInteractionRail() {
|
|
1564
|
+
if (!actRail) {return;}
|
|
1565
|
+
if (landscape) {layoutLandscapeRail();}
|
|
1566
|
+
else {Object.assign(actRail.style, { left: '', right: edge('right', 14), top: '', bottom: 'max(60px, calc(env(safe-area-inset-bottom) + 50px))' });}
|
|
1567
|
+
},
|
|
1568
|
+
setActMode: value => {
|
|
1569
|
+
actMode = value;
|
|
1570
|
+
if (value) {for (const node of [sitButton, grabButton, talkButton]) {node.style.display = 'none';}}
|
|
1571
|
+
},
|
|
1572
|
+
interactionObstacles: () => [back, hud, toast, askCard, sound?.button, sound?.card, picker, pickerCard, panel, emoteButton, emoteRow, sayButton, sayCard, feed, dock, doorsList, peopleList, nearButton, stuckChip, cabinet, ribbon].filter(node => node && node.style.display !== 'none' && node.style.visibility !== 'hidden'),
|
|
1573
|
+
setWorldLabelFocus(on) {
|
|
1574
|
+
if (worldLabelsDefault === on && worldLayout) {return;}
|
|
1575
|
+
worldLayout?.begin();
|
|
1576
|
+
worldLabelsDefault = on;
|
|
1577
|
+
// The root town retains its explicit near selection; its selected text
|
|
1578
|
+
// still needs the same final HUD/control/avatar clearance as doors.
|
|
1579
|
+
worldLayout = makeWorldLayout(surfaces, worldView, worldObstacles, geometry);
|
|
1580
|
+
},
|
|
1581
|
+
// An avatar crossing the camera's near plane has no reliable screen box
|
|
1582
|
+
// (and may be hidden by the renderer's first-person view).
|
|
1583
|
+
setWorldAvatar: (box) => {
|
|
1584
|
+
worldAvatar = box && [box.left, box.right, box.top, box.bottom].every(Number.isFinite) ? box : null;
|
|
1585
|
+
const snapped = worldAvatar && { left: Math.floor(worldAvatar.left / 16) * 16, right: Math.ceil(worldAvatar.right / 16) * 16,
|
|
1586
|
+
top: Math.floor(worldAvatar.top / 16) * 16, bottom: Math.ceil(worldAvatar.bottom / 16) * 16 };
|
|
1587
|
+
const same = snapped && avatarReserve ? ['left', 'right', 'top', 'bottom'].every((key) => snapped[key] === avatarReserve[key]) : snapped === avatarReserve;
|
|
1588
|
+
if (!same) {avatarReserve = snapped; if (safeInsets) {actionOverflow?.invalidate();}}
|
|
1589
|
+
},
|
|
1590
|
+
worldAvatar: () => worldAvatar,
|
|
1591
|
+
setWorldViewport: (area) => {worldViewport = area;},
|
|
1592
|
+
beginWorldLabels: () => worldLayout?.begin(),
|
|
1593
|
+
flushWorldLabels: () => worldLayout?.flush(),
|
|
1594
|
+
setMenu, clearMenu,
|
|
1595
|
+
cancelMenu: () => placeMenu?.cancel?.(),
|
|
1596
|
+
menuOpen: () => !!placeMenu?.sheet,
|
|
1597
|
+
menuFace: () => placeMenu?.sheet ? placeMenu.face : undefined,
|
|
1598
|
+
setTextAsk(spec, handler, onOpen) {
|
|
1599
|
+
if (!spec) {
|
|
1600
|
+
closeTextAsk();
|
|
1601
|
+
return;
|
|
1602
|
+
}
|
|
1603
|
+
if (textAsk && spec.n <= textAsk.n) {
|
|
1604
|
+
return;
|
|
1605
|
+
}
|
|
1606
|
+
closeTextAsk();
|
|
1607
|
+
textAsk = { n: spec.n };
|
|
1608
|
+
if (spec.id === null) {
|
|
1609
|
+
return;
|
|
1610
|
+
}
|
|
1611
|
+
const listeners = new AbortController(), signal = listeners.signal;
|
|
1612
|
+
// Like the decor panel's world surface: gestures belong to the card,
|
|
1613
|
+
// never the canvas underneath it. No surface exists while it is closed.
|
|
1614
|
+
// It is drawn over every other control of the chrome, dimmed, so nothing
|
|
1615
|
+
// sits on the card or looks tappable through it.
|
|
1616
|
+
const shield = el('div', { position: 'absolute', inset: '0', zIndex: '10', background: 'rgba(0,0,0,0.35)', pointerEvents: 'auto', touchAction: 'none' }, root);
|
|
1617
|
+
for (const type of ['pointerdown', 'pointermove', 'pointerup', 'wheel', 'contextmenu', 'keydown', 'keyup', 'keypress']) {
|
|
1618
|
+
shield.addEventListener(type, (event) => {
|
|
1619
|
+
event.stopPropagation();
|
|
1620
|
+
if (event.target === shield) {
|
|
1621
|
+
event.preventDefault();
|
|
1622
|
+
}
|
|
1623
|
+
}, { signal, passive: false });
|
|
1624
|
+
}
|
|
1625
|
+
const card = el('div', { position: 'fixed', left: '50%', transform: 'translateX(-50%)', width: 'min(90vw, 320px)', boxSizing: 'border-box', pointerEvents: 'auto', display: 'flex', flexDirection: 'column', gap: '10px', padding: '14px', borderRadius: '12px', background: '#17120e', boxShadow: '0 4px 14px rgba(0,0,0,0.45)', fontSize: '14px' }, shield);
|
|
1626
|
+
card.setAttribute('role', 'dialog');
|
|
1627
|
+
card.setAttribute('aria-label', spec.title);
|
|
1628
|
+
const place = () => {
|
|
1629
|
+
const view = window.visualViewport;
|
|
1630
|
+
// Stay in the visible viewport as the phone keyboard rises.
|
|
1631
|
+
const bottom = view ? geometry.view().h - view.height - view.offsetTop : 0;
|
|
1632
|
+
card.style.bottom = `max(${bottom + 24}px, calc(env(safe-area-inset-bottom) + 24px))`;
|
|
1633
|
+
};
|
|
1634
|
+
place();
|
|
1635
|
+
window.visualViewport?.addEventListener('resize', place, { signal });
|
|
1636
|
+
window.visualViewport?.addEventListener('scroll', place, { signal });
|
|
1637
|
+
for (const type of ['pointerdown', 'mousedown', 'keydown', 'keyup']) {
|
|
1638
|
+
card.addEventListener(type, (event) => event.stopPropagation(), { signal });
|
|
1639
|
+
}
|
|
1640
|
+
el('div', { fontWeight: '600' }, card).textContent = spec.title;
|
|
1641
|
+
const input = el('input', { width: '100%', boxSizing: 'border-box', minHeight: '44px', padding: '8px 10px', borderRadius: '8px', border: '1px solid rgba(255,255,255,0.35)', background: 'rgba(255,255,255,0.1)', color: '#fff', font: '16px system-ui, sans-serif' }, card);
|
|
1642
|
+
input.type = 'text';
|
|
1643
|
+
// DOM maxlength counts UTF-16 units; the input handler limits code points.
|
|
1644
|
+
input.maxLength = 2 * spec.max;
|
|
1645
|
+
input.autocomplete = 'off';
|
|
1646
|
+
input.setAttribute('autocorrect', 'off');
|
|
1647
|
+
input.spellcheck = false;
|
|
1648
|
+
input.setAttribute('autocapitalize', 'words');
|
|
1649
|
+
input.setAttribute('aria-label', spec.title);
|
|
1650
|
+
const row = el('div', { display: 'flex', justifyContent: 'flex-end', gap: '8px' }, card);
|
|
1651
|
+
const ok = smallButton(row, 'OK', true), cancel = smallButton(row, 'Cancel', false);
|
|
1652
|
+
for (const button of [ok, cancel]) {
|
|
1653
|
+
button.type = 'button';
|
|
1654
|
+
button.style.minHeight = '44px';
|
|
1655
|
+
button.style.minWidth = '64px';
|
|
1656
|
+
button.style.touchAction = 'manipulation';
|
|
1657
|
+
}
|
|
1658
|
+
ok.disabled = true;
|
|
1659
|
+
ok.style.opacity = '0.45';
|
|
1660
|
+
const changed = () => {
|
|
1661
|
+
if (!input.composing) {
|
|
1662
|
+
input.value = Array.from(input.value).slice(0, spec.max).join('');
|
|
1663
|
+
}
|
|
1664
|
+
ok.disabled = input.composing || !validPrivateText(input.value, spec.max);
|
|
1665
|
+
ok.style.opacity = ok.disabled ? '0.45' : '';
|
|
1666
|
+
};
|
|
1667
|
+
input.addEventListener('compositionstart', () => { input.composing = true; ok.disabled = true; ok.style.opacity = '0.45'; }, { signal });
|
|
1668
|
+
input.addEventListener('compositionend', () => { input.composing = false; changed(); }, { signal });
|
|
1669
|
+
input.addEventListener('input', changed, { signal });
|
|
1670
|
+
const answer = (cancelled) => {
|
|
1671
|
+
if (!textAsk?.card || (!cancelled && (input.composing || !validPrivateText(input.value, spec.max)))) {
|
|
1672
|
+
return;
|
|
1673
|
+
}
|
|
1674
|
+
const text = cancelled ? null : input.value;
|
|
1675
|
+
closeTextAsk();
|
|
1676
|
+
handler(spec.id, spec.n, text);
|
|
1677
|
+
};
|
|
1678
|
+
ok.addEventListener('click', () => answer(false), { signal });
|
|
1679
|
+
cancel.addEventListener('click', () => answer(true), { signal });
|
|
1680
|
+
input.addEventListener('keydown', (event) => {
|
|
1681
|
+
event.stopPropagation();
|
|
1682
|
+
if (event.isComposing || event.keyCode === 229) {
|
|
1683
|
+
return;
|
|
1684
|
+
}
|
|
1685
|
+
if (event.key === 'Enter') {
|
|
1686
|
+
event.preventDefault();
|
|
1687
|
+
answer(false);
|
|
1688
|
+
}
|
|
1689
|
+
}, { signal });
|
|
1690
|
+
Object.assign(textAsk, { card, shield, input, listeners, onOpen, cancel: () => answer(true) });
|
|
1691
|
+
layoutOpenOverlays();
|
|
1692
|
+
onOpen?.(true);
|
|
1693
|
+
input.focus();
|
|
1694
|
+
},
|
|
1695
|
+
clearTextAsk,
|
|
1696
|
+
cancelTextAsk: () => textAsk?.cancel?.(),
|
|
1697
|
+
textAskOpen: () => !!textAsk?.card,
|
|
1698
|
+
textAskPending: (spec) => !!spec && spec.id !== null && (!textAsk || spec.n > textAsk.n),
|
|
1699
|
+
setCover(alpha, text, line = '') {
|
|
1700
|
+
if (line && !coverLine) {
|
|
1701
|
+
coverLine = el('div', { marginTop: '12px', width: 'min(84vw, 420px)', textAlign: 'center', overflowWrap: 'anywhere', fontSize: '12px', lineHeight: '1.5', color: '#e9c48f', opacity: '0.85' }, cover);
|
|
1702
|
+
}
|
|
1703
|
+
if (coverLine) {
|
|
1704
|
+
if (coverLine.textContent !== line) {
|
|
1705
|
+
coverLine.textContent = line;
|
|
1706
|
+
}
|
|
1707
|
+
coverLine.style.display = line ? 'block' : 'none';
|
|
1708
|
+
cover.style.flexDirection = line ? 'column' : '';
|
|
1709
|
+
}
|
|
612
1710
|
cover.style.opacity = String(alpha);
|
|
613
1711
|
cover.style.pointerEvents = alpha > 0.05 ? 'auto' : 'none';
|
|
614
1712
|
if (text !== undefined && coverText.textContent !== text) {
|
|
@@ -622,20 +1720,205 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
622
1720
|
back.textContent = text;
|
|
623
1721
|
}
|
|
624
1722
|
},
|
|
1723
|
+
setActions(items, handler, canAct, n, overflow = false, onOverflowOpen = () => {}) {
|
|
1724
|
+
if (safeInsets) {overflow = true;}
|
|
1725
|
+
if (overflow) {
|
|
1726
|
+
clearLegacyActions();
|
|
1727
|
+
actionOverflowOpen = onOverflowOpen;
|
|
1728
|
+
if (!actionOverflow) {
|
|
1729
|
+
actionOverflowObstacles = () => {
|
|
1730
|
+
// Decor mounts a z=3 layer here, with its entry button first. Its
|
|
1731
|
+
// full-view layer is never an obstacle; the entry button is.
|
|
1732
|
+
const decor = [...root.children].find((node) => node.style.zIndex === '3');
|
|
1733
|
+
const decorButton = decor?.style.display !== 'none' ? decor?.children[0] : null;
|
|
1734
|
+
return [
|
|
1735
|
+
back, hud, hudText, toast, askCard, sound?.button, sound?.card, stats,
|
|
1736
|
+
picker, pickerCard, talkButton, panel, grabButton, emoteButton, emoteRow,
|
|
1737
|
+
sayButton, sayCard, feed, sitButton, dock, doorsList, peopleList,
|
|
1738
|
+
nearButton, stuckChip, cabinet, ribbon, decorButton,
|
|
1739
|
+
].filter(Boolean).concat(externalEntries().map(([, item]) => item).filter((item) => item.kind !== 'text').map((item) => item.node));
|
|
1740
|
+
};
|
|
1741
|
+
actionOverflow = makeActionOverflow({
|
|
1742
|
+
root,
|
|
1743
|
+
...(safeInsets ? { edgeMax: true, readSafeInsets: () => safeLayout.view().insets } : {}),
|
|
1744
|
+
obstacles: actionOverflowObstacles,
|
|
1745
|
+
reserved: ({ w, h, safe }) => [
|
|
1746
|
+
// The native exit target lives outside this document's DOM.
|
|
1747
|
+
{ left: safe.left, right: safe.left + 64, top: safe.top, bottom: safe.top + 56 },
|
|
1748
|
+
{ left: w - safe.right - 64, right: w - safe.right, top: safe.top, bottom: safe.top + 56 },
|
|
1749
|
+
// Landscape gives its lower-left half to the movement stick.
|
|
1750
|
+
// Portrait retains twice playerRun's 56 px stick radius.
|
|
1751
|
+
landscapeViewport()
|
|
1752
|
+
? { left: safe.left, right: w / 2, top: h / 2, bottom: h - safe.bottom }
|
|
1753
|
+
: { left: safe.left, right: Math.min(w - safe.right, safe.left + 112), top: Math.max(safe.top, h - safe.bottom - 112), bottom: h - safe.bottom },
|
|
1754
|
+
// Safe-inset offers stay off the player's own avatar (last
|
|
1755
|
+
// drawn frame); the legacy overflow lane is unchanged.
|
|
1756
|
+
...(safeInsets && avatarReserve ? [avatarReserve] : []),
|
|
1757
|
+
],
|
|
1758
|
+
onOpen: (open) => actionOverflowOpen?.(open),
|
|
1759
|
+
focusFallback: () => [back, ...dock.children, picker, grabButton, emoteButton, sayButton]
|
|
1760
|
+
.find((node) => shownRect(node) && typeof node.focus === 'function') ?? null,
|
|
1761
|
+
});
|
|
1762
|
+
}
|
|
1763
|
+
syncActionSurfaces();
|
|
1764
|
+
actionOverflow.set(items, handler, canAct, n);
|
|
1765
|
+
syncOverflowSources();
|
|
1766
|
+
return;
|
|
1767
|
+
}
|
|
1768
|
+
if (actionOverflow) {
|
|
1769
|
+
actionOverflow.dispose();
|
|
1770
|
+
actionOverflow = null;
|
|
1771
|
+
syncOverflowSources();
|
|
1772
|
+
actionOverflowOpen = actionOverflowObstacles = null;
|
|
1773
|
+
}
|
|
1774
|
+
if (!items?.length) {
|
|
1775
|
+
clearLegacyActions();
|
|
1776
|
+
return;
|
|
1777
|
+
}
|
|
1778
|
+
actionHandler = handler;
|
|
1779
|
+
let created = false;
|
|
1780
|
+
const key = [n, ...items.flatMap(({ id, label }) => [id, label])];
|
|
1781
|
+
if (!Array.isArray(actionKey) || key.length !== actionKey.length || key.some((value, i) => value !== actionKey[i])) {
|
|
1782
|
+
clearLegacyActions();
|
|
1783
|
+
actionHandler = handler;
|
|
1784
|
+
actionKey = key;
|
|
1785
|
+
actionListeners = new AbortController();
|
|
1786
|
+
actionChips = el('div', { position: 'absolute', right: edge('right', 12), bottom: 'max(132px, calc(env(safe-area-inset-bottom) + 122px))', display: 'none', flexDirection: 'column-reverse', alignItems: 'flex-end', gap: '6px', maxWidth: 'calc(100vw - 24px)', pointerEvents: 'none' }, root);
|
|
1787
|
+
actionIdentity += 1; created = true;
|
|
1788
|
+
actionChips.addEventListener('pointerdown', (event) => event.stopPropagation(), { signal: actionListeners.signal });
|
|
1789
|
+
for (const item of items.slice(0, 3)) {
|
|
1790
|
+
const chip = el('button', { border: '0', borderRadius: '22px', minHeight: '44px', padding: '12px 20px', font: '600 16px/1.2 system-ui, sans-serif', color: '#26222b', background: '#f4c66c', cursor: 'pointer', touchAction: 'manipulation', pointerEvents: 'auto', maxWidth: '100%', overflowWrap: 'anywhere' }, actionChips);
|
|
1791
|
+
geometry.register(chip);
|
|
1792
|
+
chip.type = 'button';
|
|
1793
|
+
chip.tabIndex = -1;
|
|
1794
|
+
chip.textContent = item.label;
|
|
1795
|
+
const pointer = (event) => {
|
|
1796
|
+
event.preventDefault();
|
|
1797
|
+
event.stopPropagation();
|
|
1798
|
+
};
|
|
1799
|
+
chip.addEventListener('pointerdown', pointer, { signal: actionListeners.signal });
|
|
1800
|
+
chip.addEventListener('mousedown', pointer, { signal: actionListeners.signal });
|
|
1801
|
+
for (const type of ['keydown', 'keyup']) {
|
|
1802
|
+
chip.addEventListener(type, pointer, { signal: actionListeners.signal });
|
|
1803
|
+
}
|
|
1804
|
+
chip.addEventListener('click', (event) => {
|
|
1805
|
+
event.stopPropagation();
|
|
1806
|
+
chip.blur();
|
|
1807
|
+
if (actionChips && actionChips.style.display !== 'none') {
|
|
1808
|
+
onChip?.();
|
|
1809
|
+
actionHandler?.(item.id, n);
|
|
1810
|
+
}
|
|
1811
|
+
}, { signal: actionListeners.signal });
|
|
1812
|
+
}
|
|
1813
|
+
}
|
|
1814
|
+
const show = canAct && !pickerOpen && !sayOpen && !emotesOpen && !peopleOpen && !doorsOpen && !talkOpen;
|
|
1815
|
+
if (!show) {
|
|
1816
|
+
if (actionChips.style.display !== 'none') {actionChips.style.display = 'none';}
|
|
1817
|
+
placeActions(['hidden', actionKey], () => {});
|
|
1818
|
+
return;
|
|
1819
|
+
}
|
|
1820
|
+
// Decor mounts a z=3 layer here, with its entry button first. Measure
|
|
1821
|
+
// that button only when its layer is drawn, never the full-view layer.
|
|
1822
|
+
const decor = [...root.children].find((node) => node.style.zIndex === '3');
|
|
1823
|
+
const decorButton = decor?.style.display !== 'none' ? decor?.children[0] : null;
|
|
1824
|
+
const inputs = [grabButton, emoteButton, sayButton, sitButton, picker, talkButton, dock, nearButton,
|
|
1825
|
+
stuckChip, decorButton, hud, askCard, back, sound?.button, sound?.card];
|
|
1826
|
+
if (actionChips.style.display === 'none' && (!geometry.active() || created)) {actionChips.style.display = 'flex';}
|
|
1827
|
+
// Placement depends only on this frame's numbers and offer identity/copy.
|
|
1828
|
+
placeActions([actionIdentity, actionKey, show, geometry.view().w, geometry.view().h,
|
|
1829
|
+
geometry.rect(actionBottom).bottom, inputs.map((node) => node ? shownRect(node) : null),
|
|
1830
|
+
[...actionChips.children].map((chip) => [chip.textContent, actionSize(chip)])], () => {
|
|
1831
|
+
const column = [grabButton, emoteButton, sayButton, sitButton].map(shownRect).filter(Boolean);
|
|
1832
|
+
const controls = [picker, talkButton, dock, nearButton, stuckChip, decorButton].map(shownRect).filter(Boolean).concat(column);
|
|
1833
|
+
const above = [hud, askCard, back, sound?.button, sound?.card].map(shownRect).filter(Boolean);
|
|
1834
|
+
const overlaps = (a, b) => a.left < b.right && a.right > b.left;
|
|
1835
|
+
actionChips.style.display = 'flex';
|
|
1836
|
+
const chips = [...actionChips.children];
|
|
1837
|
+
// Restore trimmed chips and sample any first shown this frame before
|
|
1838
|
+
// trying both positions.
|
|
1839
|
+
for (const chip of chips) {
|
|
1840
|
+
chip.style.display = '';
|
|
1841
|
+
geometry.size(chip);
|
|
1842
|
+
}
|
|
1843
|
+
const edgeRight = 12, edgeLeft = 12;
|
|
1844
|
+
const place = (right, initialBottom) => {
|
|
1845
|
+
right = Math.max(right, edgeRight);
|
|
1846
|
+
actionChips.style.right = `${right}px`;
|
|
1847
|
+
actionChips.style.maxWidth = `${Math.max(0, geometry.view().w - right - edgeLeft)}px`;
|
|
1848
|
+
actionChips.style.bottom = initialBottom;
|
|
1849
|
+
// Candidates change maxWidth and can wrap chips differently. This
|
|
1850
|
+
// rare solve needs fresh layout; unchanged placement stays cached.
|
|
1851
|
+
const box = actionChips.getBoundingClientRect();
|
|
1852
|
+
let bottom = geometry.view().h - box.bottom;
|
|
1853
|
+
for (const r of controls) {
|
|
1854
|
+
if (overlaps(r, box)) {
|
|
1855
|
+
bottom = Math.max(bottom, geometry.view().h - r.top + 12);
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
actionChips.style.bottom = `${bottom}px`;
|
|
1859
|
+
const placed = geometry.active()
|
|
1860
|
+
? { left: box.left, right: box.right, width: box.width, height: box.height,
|
|
1861
|
+
top: geometry.view().h - bottom - box.height, bottom: geometry.view().h - bottom }
|
|
1862
|
+
: geometry.rect(actionChips);
|
|
1863
|
+
return placed.left >= edgeLeft && placed.top >= 12 && placed.bottom <= geometry.view().h - 12
|
|
1864
|
+
&& !above.some((r) => overlaps(r, placed) && r.bottom + 12 > placed.top);
|
|
1865
|
+
};
|
|
1866
|
+
// Identity determines which controls bound the stack from above, even
|
|
1867
|
+
// when a short frame puts speech or Grab in the top half of the view.
|
|
1868
|
+
const right = geometry.view().w - Math.min(geometry.view().w - edgeRight, ...column.map((r) => r.left)) + 12;
|
|
1869
|
+
for (let count = chips.length; count > 0; count -= 1) {
|
|
1870
|
+
// Trimming can narrow the stack enough to clear a HUD or decor
|
|
1871
|
+
// obstacle in the right column, so retry it before the fallback.
|
|
1872
|
+
if (place(edgeRight, 'max(132px, calc(env(safe-area-inset-bottom) + 122px))') || place(right, '12px')) {
|
|
1873
|
+
return;
|
|
1874
|
+
}
|
|
1875
|
+
// column-reverse puts the first offer at the bottom: trim from the top.
|
|
1876
|
+
chips[count - 1].style.display = 'none';
|
|
1877
|
+
}
|
|
1878
|
+
actionChips.style.display = 'none';
|
|
1879
|
+
});
|
|
1880
|
+
},
|
|
1881
|
+
clearActions,
|
|
1882
|
+
cancelActionOverflow: () => actionOverflow?.cancel?.() ?? false,
|
|
1883
|
+
actionOverflowOpen: () => actionOverflow?.isOpen?.() === true,
|
|
1884
|
+
// v1.67: called only in a decor place; the tray uses the same chrome root.
|
|
1885
|
+
decorRoot() {
|
|
1886
|
+
return root;
|
|
1887
|
+
},
|
|
1888
|
+
setDecorating(on) {
|
|
1889
|
+
hud.style.visibility = on ? 'hidden' : '';
|
|
1890
|
+
hudText.style.visibility = on ? 'hidden' : '';
|
|
1891
|
+
picker.style.visibility = on ? 'hidden' : '';
|
|
1892
|
+
back.style.zIndex = on ? '4' : '';
|
|
1893
|
+
back.style.top = on ? 'auto' : 'max(12px, env(safe-area-inset-top))';
|
|
1894
|
+
back.style.bottom = on ? 'max(196px, calc(env(safe-area-inset-bottom) + 186px))' : '';
|
|
1895
|
+
},
|
|
625
1896
|
setHud(spec, timerSeconds) {
|
|
626
1897
|
if (!spec) {
|
|
627
1898
|
hud.style.display = 'none';
|
|
1899
|
+
hudPromptAsked = false;
|
|
1900
|
+
syncHudPrompt();
|
|
628
1901
|
return;
|
|
629
1902
|
}
|
|
630
1903
|
hud.style.display = 'block';
|
|
631
|
-
|
|
1904
|
+
const title = spec.title ?? '';
|
|
1905
|
+
if (hudTitle.textContent !== title) {hudTitle.textContent = title;}
|
|
632
1906
|
const big = spec.big ?? (timerSeconds !== null ? timerSeconds.toFixed(1) : '');
|
|
633
|
-
hudBig.textContent = big;
|
|
634
|
-
|
|
635
|
-
|
|
1907
|
+
if (hudBig.textContent !== big) {hudBig.textContent = big;}
|
|
1908
|
+
const bigDisplay = big ? 'block' : 'none';
|
|
1909
|
+
if (hudBig.style.display !== bigDisplay) {hudBig.style.display = bigDisplay;}
|
|
1910
|
+
const prompt = firstPromptSentence(spec.text);
|
|
1911
|
+
if (hudText.textContent !== prompt) {hudText.textContent = prompt;}
|
|
1912
|
+
hudTitle.style.display = hudTitle.textContent ? 'block' : 'none';
|
|
1913
|
+
hudPromptAsked = Boolean(hudText.textContent);
|
|
1914
|
+
syncHudPrompt();
|
|
636
1915
|
if (hudClear) {
|
|
637
1916
|
layoutHudClear(big, spec.text ?? '');
|
|
638
1917
|
}
|
|
1918
|
+
if (import.meta.env?.DEV) {
|
|
1919
|
+
warnHudCopy(hudTitle, 'subtitle');
|
|
1920
|
+
warnHudCopy(hudText, 'prompt', 1);
|
|
1921
|
+
}
|
|
639
1922
|
},
|
|
640
1923
|
// Whether this place asks for a clear HUD (`hud.clear`, v1.26). Said each
|
|
641
1924
|
// frame before `setHud`; never said true, nothing of it is drawn.
|
|
@@ -655,8 +1938,145 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
655
1938
|
// `items` is [{ id, x, y, text, speech, npc, color }] in CSS pixels (a
|
|
656
1939
|
// `color` is a player's mark); anything not
|
|
657
1940
|
// listed is removed.
|
|
658
|
-
|
|
1941
|
+
// The HUD's box that this frame's flush will move labels out from under
|
|
1942
|
+
// (v1.26), or null when nothing will be moved: no clear HUD asked for, or
|
|
1943
|
+
// none drawn. For v1.43's rule, which must judge where labels end up.
|
|
1944
|
+
// v1.131: labels avoid this bottom pill separately from the top band.
|
|
1945
|
+
hudPromptBox() {
|
|
1946
|
+
return shownRect(hudText);
|
|
1947
|
+
},
|
|
1948
|
+
hudClearBox() {
|
|
1949
|
+
return hudClear && hud.style.display !== 'none' ? shownRect(hud) : null;
|
|
1950
|
+
},
|
|
1951
|
+
// How big a label with these words is drawn, `{ w, h }` in CSS pixels
|
|
1952
|
+
// (v1.43, for a deck whose labels are kept apart: `labelsNear.js`).
|
|
1953
|
+
// Keep a source node for each requested copy/style, not cached sizes.
|
|
1954
|
+
// Sources are sampled every frame and removed when no longer requested.
|
|
1955
|
+
measureLabel(text, speech = false, npc = false, padOccupancy = false) {
|
|
1956
|
+
const key = `${padOccupancy}:${speech}:${npc}:${desktop()}:${text}`;
|
|
1957
|
+
usedLabelMeasures.add(key);
|
|
1958
|
+
let node = labelMeasures.get(key);
|
|
1959
|
+
if (!node) {
|
|
1960
|
+
node = el('div', { position: 'fixed', left: '-10000px', top: '0', visibility: 'hidden', pointerEvents: 'none',
|
|
1961
|
+
font: '600 15px/1.3 system-ui, sans-serif', padding: '4px 10px',
|
|
1962
|
+
whiteSpace: padOccupancy ? 'pre-line' : speech ? 'normal' : 'nowrap', width: speech ? 'max-content' : 'auto',
|
|
1963
|
+
maxWidth: padOccupancy ? 'min(70vw, 320px)' : !speech ? 'none' : npc && desktop() ? 'min(62vw, 320px)' : '62vw',
|
|
1964
|
+
fontSize: speech ? '13px' : '14px', fontWeight: speech ? '500' : '600' });
|
|
1965
|
+
node.textContent = text;
|
|
1966
|
+
labelMeasures.set(key, node);
|
|
1967
|
+
}
|
|
1968
|
+
return geometry.size(node);
|
|
1969
|
+
},
|
|
1970
|
+
// A owns only this lazy, noninteractive caption. The projected surface
|
|
1971
|
+
// participates in the shared registry but is placed last, yielding to
|
|
1972
|
+
// every final control/card/label box rather than moving any of them.
|
|
1973
|
+
setPadContext(item) {
|
|
1974
|
+
const blocked = pickerOpen || sayOpen || emotesOpen || peopleOpen || doorsOpen || talkOpen ||
|
|
1975
|
+
!!textAsk?.card || !!placeMenu?.sheet || sound?.open || actionOverflow?.isOpen?.() ||
|
|
1976
|
+
externalEntries().some(([, surface]) => surface.kind === 'card' && shownRect(surface.node));
|
|
1977
|
+
if (!item || blocked) {
|
|
1978
|
+
if (padContext && padContext.node.style.visibility !== 'hidden') {padContext.node.style.visibility = 'hidden';}
|
|
1979
|
+
return;
|
|
1980
|
+
}
|
|
1981
|
+
if (!padContext) {
|
|
1982
|
+
const node = el('div', { position: 'absolute', left: '0px', top: '0px', width: 'max-content', maxWidth: 'min(70vw, 320px)',
|
|
1983
|
+
boxSizing: 'border-box', padding: '7px 12px', borderRadius: '12px', background: 'rgba(20,16,12,0.86)',
|
|
1984
|
+
pointerEvents: 'none', textAlign: 'center', visibility: 'hidden' }, root);
|
|
1985
|
+
node.dataset.hub = 'pad-context';
|
|
1986
|
+
const title = el('div', { fontSize: '16px', lineHeight: '1.25', overflowWrap: 'anywhere', overflow: 'hidden',
|
|
1987
|
+
display: '-webkit-box', webkitLineClamp: '2', webkitBoxOrient: 'vertical', textOverflow: 'ellipsis' }, node);
|
|
1988
|
+
const secondary = el('div', { fontSize: '13px', lineHeight: '1.3', fontWeight: '500' }, node);
|
|
1989
|
+
const probe = el('div', { position: 'fixed', inset: '0', visibility: 'hidden', pointerEvents: 'none',
|
|
1990
|
+
paddingTop: 'env(safe-area-inset-top)', paddingRight: 'env(safe-area-inset-right)',
|
|
1991
|
+
paddingBottom: 'env(safe-area-inset-bottom)', paddingLeft: 'env(safe-area-inset-left)' }, root);
|
|
1992
|
+
geometry.register(probe, { padding: true });
|
|
1993
|
+
padContext = { node, title, secondary, probe, id: null, text: null, line: null };
|
|
1994
|
+
api.safeSurface('pad-context', node, 'text', { projected: true, transient: true });
|
|
1995
|
+
}
|
|
1996
|
+
const { node, title, secondary, probe } = padContext;
|
|
1997
|
+
if (padContext.id !== item.id || padContext.text !== item.title || padContext.line !== item.secondary) {
|
|
1998
|
+
title.textContent = item.title;
|
|
1999
|
+
secondary.textContent = item.secondary;
|
|
2000
|
+
secondary.style.display = item.secondary ? 'block' : 'none';
|
|
2001
|
+
node.setAttribute('aria-label', item.title);
|
|
2002
|
+
node.setAttribute('title', item.title);
|
|
2003
|
+
padContext.id = item.id; padContext.text = item.title; padContext.line = item.secondary;
|
|
2004
|
+
}
|
|
2005
|
+
const view = geometry.view();
|
|
2006
|
+
const safe = safeLayout?.view().insets ?? geometry.padding(probe);
|
|
2007
|
+
const size = geometry.size(node);
|
|
2008
|
+
// The stuck chip is placed earlier this frame; read its new rect, not
|
|
2009
|
+
// the cached one from before it was shown or moved.
|
|
2010
|
+
if (stuckChip && stuckChip.style.display !== 'none') {geometry.invalidate(stuckChip);}
|
|
2011
|
+
const obstacles = surfaces().filter((entry) => entry.node !== node && entry.node !== probe).map((entry) => shownRect(entry.node)).filter(Boolean);
|
|
2012
|
+
if (worldAvatar) {obstacles.push(worldAvatar);}
|
|
2013
|
+
const reserved = [
|
|
2014
|
+
{ left: safe.left, right: safe.left + 64, top: safe.top, bottom: safe.top + 56 },
|
|
2015
|
+
{ left: view.w - safe.right - 64, right: view.w - safe.right, top: safe.top, bottom: safe.top + 56 },
|
|
2016
|
+
landscapeViewport()
|
|
2017
|
+
? { left: safe.left, right: view.w / 2, top: view.h / 2, bottom: view.h - safe.bottom }
|
|
2018
|
+
: { left: safe.left, right: safe.left + 112, top: view.h - safe.bottom - 112, bottom: view.h - safe.bottom },
|
|
2019
|
+
];
|
|
2020
|
+
const at = placePadContext([item, view, safe, size, obstacles, reserved], () => actionLayout({ view, safe, offers: [size], obstacles, reserved }));
|
|
2021
|
+
if (at) {
|
|
2022
|
+
const left = `${at.rect.left}px`, top = `${at.rect.top}px`;
|
|
2023
|
+
if (node.style.left !== left) {node.style.left = left;}
|
|
2024
|
+
if (node.style.top !== top) {node.style.top = top;}
|
|
2025
|
+
}
|
|
2026
|
+
const visibility = at ? '' : 'hidden';
|
|
2027
|
+
if (node.style.visibility !== visibility) {node.style.visibility = visibility;}
|
|
2028
|
+
},
|
|
2029
|
+
clearPadContext() {
|
|
2030
|
+
if (!padContext) {return;}
|
|
2031
|
+
api.safeSurface('pad-context', null);
|
|
2032
|
+
padContext.node.remove(); padContext.probe.remove(); padContext = null;
|
|
2033
|
+
},
|
|
2034
|
+
padOccupancyControls() {
|
|
2035
|
+
const decor = [...root.children].find((node) => node.style.zIndex === '3');
|
|
2036
|
+
const decorButton = decor?.style.display !== 'none' ? decor?.children[0] : null;
|
|
2037
|
+
const actionControls = [...root.children].flatMap((node) => node.dataset.hub === 'action-backdrop'
|
|
2038
|
+
? [...node.children].filter((child) => child.dataset.hub === 'action-sheet')
|
|
2039
|
+
: node.dataset.hub === 'action-rail' ? [node] : []);
|
|
2040
|
+
return [...actionControls, hud, hudText, askCard, back, sound?.button, sound?.card, toast, stats, talkButton, sitButton, nearButton, panel, dock, doorsList, peopleList, picker, grabButton, emoteButton, emoteRow, sayButton, sayCard, actionChips, stuckChip, decorButton, cabinet, ribbon].map(shownRect).filter(Boolean);
|
|
2041
|
+
},
|
|
2042
|
+
// E crowd names asks only on its opted-in late pass, after setLabels and
|
|
2043
|
+
// HUD clearance have put every ordinary DOM label at its final rectangle.
|
|
2044
|
+
// The summary from a prior frame has already been removed by setLabels.
|
|
2045
|
+
crowdNameLabelBoxes() {
|
|
2046
|
+
return [...labelNodes.entries()]
|
|
2047
|
+
.filter(([id]) => id !== 'crowd:summary')
|
|
2048
|
+
.map(([, node]) => shownRect(node))
|
|
2049
|
+
.filter(Boolean);
|
|
2050
|
+
},
|
|
2051
|
+
// E's late pass runs after ordinary labels have completed HUD clearance.
|
|
2052
|
+
// Touch only its one boxed summary so those final positions stay final.
|
|
2053
|
+
setCrowdNameSummary(item) {
|
|
2054
|
+
const id = 'crowd:summary';
|
|
2055
|
+
let node = labelNodes.get(id);
|
|
2056
|
+
if (!item) {
|
|
2057
|
+
node?.remove();
|
|
2058
|
+
labelNodes.delete(id);
|
|
2059
|
+
worldLayout?.flush();
|
|
2060
|
+
return;
|
|
2061
|
+
}
|
|
2062
|
+
if (!node) {
|
|
2063
|
+
node = el('div', { position: 'absolute', transform: 'translate(-50%, -100%)', padding: '4px 10px', borderRadius: '12px', background: 'rgba(15,12,10,0.7)', whiteSpace: 'nowrap', fontSize: '14px' }, labels);
|
|
2064
|
+
labelNodes.set(id, node);
|
|
2065
|
+
}
|
|
2066
|
+
node.style.left = `${(item.box.left + item.box.right) / 2}px`;
|
|
2067
|
+
node.style.top = `${item.box.bottom}px`;
|
|
2068
|
+
if (node.textContent !== item.text) {
|
|
2069
|
+
node.textContent = item.text;
|
|
2070
|
+
}
|
|
2071
|
+
worldLayout?.flush();
|
|
2072
|
+
},
|
|
2073
|
+
setLabels(items, preserveCrowdSummary = false) {
|
|
659
2074
|
const seen = new Set();
|
|
2075
|
+
// The top chrome an emote's emoji is kept from under (`emoteBubble.js`),
|
|
2076
|
+
// read once a call and only when an emote is drawn.
|
|
2077
|
+
let bands = null;
|
|
2078
|
+
// An emote put on its head: id -> the bottom it was put at.
|
|
2079
|
+
const emoteAt = new Map();
|
|
660
2080
|
for (const item of items) {
|
|
661
2081
|
seen.add(item.id);
|
|
662
2082
|
let node = labelNodes.get(item.id);
|
|
@@ -667,30 +2087,42 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
667
2087
|
// An NPC's line is kept on screen: a reply over one at the edge of the
|
|
668
2088
|
// view would otherwise be cut off mid-sentence. Other labels are
|
|
669
2089
|
// placed as they always were.
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
}
|
|
675
|
-
node.style.left = `${x}px`;
|
|
676
|
-
node.style.top = `${item.y}px`;
|
|
2090
|
+
// v1.43: an item that comes with its `box` (`labelsNear.js` `labelBox`:
|
|
2091
|
+
// measured for these words, kept on the screen, moved from under a
|
|
2092
|
+
// clear HUD) is put exactly there and moved by nothing after, so what
|
|
2093
|
+
// is drawn is what the rule judged. No other item has one.
|
|
677
2094
|
if (item.speech) {
|
|
678
2095
|
node.style.background = 'rgba(255,250,240,0.94)';
|
|
679
2096
|
node.style.color = '#2b2118';
|
|
680
2097
|
node.style.whiteSpace = 'normal';
|
|
681
|
-
if (item.npc) {
|
|
682
|
-
// Its own width, not what is left of the screen to its right
|
|
2098
|
+
if (item.npc || item.box) {
|
|
2099
|
+
// Its own width, not what is left of the screen to its right
|
|
2100
|
+
// (v1.43: so is any line that comes with its box, which was
|
|
2101
|
+
// measured that way).
|
|
683
2102
|
node.style.width = 'max-content';
|
|
684
2103
|
}
|
|
685
2104
|
node.style.maxWidth = item.npc && desktop() ? 'min(62vw, 320px)' : '62vw';
|
|
686
2105
|
node.style.fontSize = '13px';
|
|
687
2106
|
node.style.fontWeight = '500';
|
|
688
2107
|
}
|
|
2108
|
+
if (item.padOccupancy) {
|
|
2109
|
+
node.dataset.padOccupancy = '1';
|
|
2110
|
+
node.style.whiteSpace = 'pre-line';
|
|
2111
|
+
node.style.width = 'max-content';
|
|
2112
|
+
node.style.maxWidth = 'min(70vw, 320px)';
|
|
2113
|
+
} else if (node.dataset.padOccupancy === '1') {
|
|
2114
|
+
delete node.dataset.padOccupancy;
|
|
2115
|
+
node.style.whiteSpace = item.speech ? 'normal' : 'nowrap';
|
|
2116
|
+
node.style.width = item.speech ? 'max-content' : '';
|
|
2117
|
+
node.style.maxWidth = item.speech ? '62vw' : '';
|
|
2118
|
+
}
|
|
689
2119
|
if (item.emote && node.dataset.emote !== '1') {
|
|
690
2120
|
// An emote's emoji over a player: large, on nothing.
|
|
691
2121
|
node.dataset.emote = '1';
|
|
692
2122
|
node.style.background = 'transparent';
|
|
693
|
-
node.style.fontSize = '
|
|
2123
|
+
node.style.fontSize = '42px';
|
|
2124
|
+
// The glyph's own box, so it sits on the head it was put over.
|
|
2125
|
+
node.style.lineHeight = '1';
|
|
694
2126
|
node.style.padding = '0';
|
|
695
2127
|
node.style.textShadow = '0 2px 4px rgba(0,0,0,0.5)';
|
|
696
2128
|
}
|
|
@@ -709,19 +2141,56 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
709
2141
|
if (node.textContent !== item.text) {
|
|
710
2142
|
node.textContent = item.text;
|
|
711
2143
|
}
|
|
2144
|
+
let x = item.box ? (item.box.left + item.box.right) / 2 : item.x;
|
|
2145
|
+
node.style.left = `${x}px`;
|
|
2146
|
+
node.style.top = `${item.box ? item.box.bottom : item.y}px`;
|
|
2147
|
+
if (!item.box && item.npc) {
|
|
2148
|
+
const half = geometry.size(node).w / 2;
|
|
2149
|
+
x = Math.min(Math.max(item.x, half + 6), geometry.view().w - half - 6);
|
|
2150
|
+
node.style.left = `${x}px`;
|
|
2151
|
+
}
|
|
2152
|
+
if (item.emote && !item.box) {
|
|
2153
|
+
// An emote's emoji sits on its head (`emoteBubble.js`): just above
|
|
2154
|
+
// it, or beside it where above is off the view or under the top
|
|
2155
|
+
// chrome, and never under the top chrome. A clear HUD moves what is
|
|
2156
|
+
// under its own box (`keepClearOfHud` below).
|
|
2157
|
+
bands ??= [hud, hudText, askCard, back, sound?.button].map(shownRect).filter(Boolean);
|
|
2158
|
+
// Use this frame's sampled glyph size, including for repeated emoji.
|
|
2159
|
+
const size = geometry.size(node);
|
|
2160
|
+
const { w, h } = size;
|
|
2161
|
+
let placed = null;
|
|
2162
|
+
if (item.head) {
|
|
2163
|
+
placed = placeEmoteBubble(item.head, { w, h }, hudClear ? [] : bands, { w: geometry.view().w, h: geometry.view().h }, item.lift ?? 0);
|
|
2164
|
+
} else if (!hudClear && bands.length) {
|
|
2165
|
+
const { dx, dy } = emoteBubbleShift({ left: x - w / 2, right: x + w / 2, top: item.y - h, bottom: item.y }, bands, geometry.view().w);
|
|
2166
|
+
placed = dx !== 0 || dy !== 0 ? { left: x - w / 2 + dx, right: x + w / 2 + dx, top: item.y - h + dy, bottom: item.y + dy } : null;
|
|
2167
|
+
}
|
|
2168
|
+
// A head off the view: no bubble. Any other is shown again.
|
|
2169
|
+
const visibility = item.head && !placed ? 'hidden' : '';
|
|
2170
|
+
if ((node.style.visibility || '') !== visibility) {
|
|
2171
|
+
node.style.visibility = visibility;
|
|
2172
|
+
}
|
|
2173
|
+
if (placed) {
|
|
2174
|
+
node.style.left = `${(placed.left + placed.right) / 2}px`;
|
|
2175
|
+
node.style.top = `${placed.bottom}px`;
|
|
2176
|
+
emoteAt.set(item.id, placed.bottom);
|
|
2177
|
+
}
|
|
2178
|
+
}
|
|
712
2179
|
}
|
|
713
2180
|
for (const [id, node] of labelNodes) {
|
|
714
|
-
if (!seen.has(id)) {
|
|
2181
|
+
if (!seen.has(id) && !(preserveCrowdSummary && id === 'crowd:summary')) {
|
|
715
2182
|
node.remove();
|
|
716
2183
|
labelNodes.delete(id);
|
|
717
2184
|
}
|
|
718
2185
|
}
|
|
719
|
-
if (hudClear) {
|
|
2186
|
+
if (hudClear || hudText.style.display !== 'none') {
|
|
720
2187
|
keepClearOfHud(
|
|
721
2188
|
'labels',
|
|
722
|
-
|
|
2189
|
+
// Preplaced labels already clear the top band; the bottom pill
|
|
2190
|
+
// is reserved by this shared pass too.
|
|
2191
|
+
items.filter((item) => !item.box).map((item) => {
|
|
723
2192
|
const node = labelNodes.get(item.id);
|
|
724
|
-
return [node, parseFloat(node.style.left), item.y, 'bottom', item.text];
|
|
2193
|
+
return [node, parseFloat(node.style.left), emoteAt.get(item.id) ?? item.box?.bottom ?? item.y, 'bottom', item.text];
|
|
725
2194
|
}),
|
|
726
2195
|
);
|
|
727
2196
|
}
|
|
@@ -745,9 +2214,10 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
745
2214
|
}
|
|
746
2215
|
cabinet.style.display = 'block';
|
|
747
2216
|
// Kept on screen: a card over a cabinet at the edge of the view.
|
|
748
|
-
const
|
|
749
|
-
|
|
750
|
-
cabinet.style.
|
|
2217
|
+
const cabinetSize = geometry.size(cabinet);
|
|
2218
|
+
const half = cabinetSize.w / 2;
|
|
2219
|
+
cabinet.style.left = `${Math.min(Math.max(item.x, half + 6), geometry.view().w - half - 6)}px`;
|
|
2220
|
+
cabinet.style.top = `${Math.max(item.y, geometry.size(cabinet).h + 6)}px`;
|
|
751
2221
|
if (hudClear) {
|
|
752
2222
|
keepClearOfHud('cabinet', [[cabinet, parseFloat(cabinet.style.left), parseFloat(cabinet.style.top), 'bottom', cabinetKey]]);
|
|
753
2223
|
}
|
|
@@ -768,25 +2238,64 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
768
2238
|
if (hudClear) {
|
|
769
2239
|
keepClearOfHud('ribbon', [[ribbon, pos.x, pos.y, 'bottom', text]]);
|
|
770
2240
|
}
|
|
2241
|
+
placeToast();
|
|
771
2242
|
},
|
|
772
|
-
setToast(text) {
|
|
773
|
-
|
|
2243
|
+
setToast(text, { wrap = false } = {}) {
|
|
2244
|
+
if (text && wrap) {
|
|
2245
|
+
if (!toastWrap) {
|
|
2246
|
+
toastWrap = { maxWidth: toast.style.maxWidth, overflowWrap: toast.style.overflowWrap, textAlign: toast.style.textAlign };
|
|
2247
|
+
Object.assign(toast.style, { maxWidth: 'min(90vw, 480px)', overflowWrap: 'anywhere', textAlign: 'center' });
|
|
2248
|
+
}
|
|
2249
|
+
} else if (toastWrap) {
|
|
2250
|
+
Object.assign(toast.style, toastWrap);
|
|
2251
|
+
toastWrap = null;
|
|
2252
|
+
}
|
|
2253
|
+
const display = text ? 'block' : 'none';
|
|
2254
|
+
if (toast.style.display !== display) {
|
|
2255
|
+
toast.style.display = display;
|
|
2256
|
+
}
|
|
774
2257
|
if (text && toast.textContent !== text) {
|
|
775
2258
|
toast.textContent = text;
|
|
776
2259
|
}
|
|
2260
|
+
placeToast();
|
|
777
2261
|
},
|
|
778
|
-
showPicker(show, selected) {
|
|
2262
|
+
showPicker(show, selected, colors, invite = null) {
|
|
2263
|
+
invitePick = show ? invite?.onPick ?? null : null;
|
|
2264
|
+
if (invitePick && !inviteRow) {
|
|
2265
|
+
inviteRow = document.createElement('button');
|
|
2266
|
+
Object.assign(inviteRow.style, { minHeight: '44px', padding: '8px 12px', borderRadius: '12px', border: '1px solid rgba(255,255,255,0.4)', background: 'rgba(20,16,12,0.7)', color: '#fff', font: 'inherit', cursor: 'pointer', flex: 'none' });
|
|
2267
|
+
pickerCard.insertBefore(inviteRow, pickerClose);
|
|
2268
|
+
inviteRow.textContent = 'Invite a friend';
|
|
2269
|
+
inviteRow.type = 'button';
|
|
2270
|
+
inviteRow.addEventListener('click', (event) => {
|
|
2271
|
+
event.stopPropagation();
|
|
2272
|
+
if (!pickerOpen || !invitePick) {return;}
|
|
2273
|
+
const pick = invitePick;
|
|
2274
|
+
setPickerOpen(false);
|
|
2275
|
+
pick();
|
|
2276
|
+
});
|
|
2277
|
+
}
|
|
2278
|
+
if (inviteRow) {inviteRow.style.display = invitePick ? '' : 'none';}
|
|
2279
|
+
showColors(selected, colors);
|
|
779
2280
|
picker.style.display = show ? 'flex' : 'none';
|
|
780
2281
|
if (!show) {
|
|
781
2282
|
setPickerOpen(false);
|
|
782
2283
|
}
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
2284
|
+
// Asked every frame: written only when the character worn changes.
|
|
2285
|
+
if (selected !== pickerSelected) {
|
|
2286
|
+
pickerSelected = selected;
|
|
2287
|
+
pickerButtons.forEach((button, i) => {
|
|
2288
|
+
button.style.borderColor = i === selected ? '#f2c94c' : 'rgba(255,255,255,0.4)';
|
|
2289
|
+
button.style.background = i === selected ? 'rgba(242,201,76,0.22)' : 'rgba(20,16,12,0.7)';
|
|
2290
|
+
button.setAttribute('aria-pressed', String(i === selected));
|
|
2291
|
+
});
|
|
2292
|
+
}
|
|
2293
|
+
layoutLandscapeRail();
|
|
2294
|
+
fitPicker();
|
|
786
2295
|
},
|
|
787
2296
|
// The Graphics row: `mode` is the one picked ('auto', 'low' or 'high').
|
|
788
|
-
setGraphics(mode, onPick) {
|
|
789
|
-
graphics ??= buildGraphics();
|
|
2297
|
+
setGraphics(mode, onPick, weakest = false) {
|
|
2298
|
+
graphics ??= buildGraphics(weakest);
|
|
790
2299
|
graphics.onPick = onPick;
|
|
791
2300
|
for (const [m, button] of graphics.buttons) {
|
|
792
2301
|
button.style.borderColor = m === mode ? '#f2c94c' : 'rgba(255,255,255,0.4)';
|
|
@@ -814,6 +2323,7 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
814
2323
|
emoteButton.style.display = show ? 'block' : 'none';
|
|
815
2324
|
if (!show) {
|
|
816
2325
|
setEmotesOpen(false);
|
|
2326
|
+
layoutLandscapeRail();
|
|
817
2327
|
return;
|
|
818
2328
|
}
|
|
819
2329
|
const key = emotes.map(([id]) => id).join('|');
|
|
@@ -830,9 +2340,13 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
830
2340
|
event.stopPropagation();
|
|
831
2341
|
event.preventDefault();
|
|
832
2342
|
setEmotesOpen(false);
|
|
2343
|
+
if (onChip) {
|
|
2344
|
+
onChip();
|
|
2345
|
+
}
|
|
833
2346
|
emoteHandler(id);
|
|
834
2347
|
});
|
|
835
2348
|
}
|
|
2349
|
+
layoutLandscapeRail();
|
|
836
2350
|
},
|
|
837
2351
|
// `say` is { reactions: [emoji], phrases: [[id, words]] } to offer, or
|
|
838
2352
|
// null to hide the button; a pick calls the handler with { r } or { p }.
|
|
@@ -840,6 +2354,7 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
840
2354
|
sayButton.style.display = say ? 'block' : 'none';
|
|
841
2355
|
if (!say) {
|
|
842
2356
|
setSayOpen(false);
|
|
2357
|
+
layoutLandscapeRail();
|
|
843
2358
|
return;
|
|
844
2359
|
}
|
|
845
2360
|
const chat = say.chat ?? null;
|
|
@@ -850,12 +2365,18 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
850
2365
|
sayNote.textContent = chat.note ?? '';
|
|
851
2366
|
}
|
|
852
2367
|
// The field's own words (a deck with cues, v1.23): rewritten in place
|
|
853
|
-
// too. A chat part that names none
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
sayInput.
|
|
2368
|
+
// too. A chat part that names none reads 'Message…', as a field built
|
|
2369
|
+
// without them does.
|
|
2370
|
+
if (key === sayKey && sayInput && chat && sayInput.placeholder !== (chat.placeholder ?? 'Message…')) {
|
|
2371
|
+
sayInput.placeholder = chat.placeholder ?? 'Message…';
|
|
2372
|
+
if (chat.placeholder) {
|
|
2373
|
+
sayInput.setAttribute('aria-label', chat.label ?? chat.placeholder);
|
|
2374
|
+
} else {
|
|
2375
|
+
sayInput.removeAttribute('aria-label');
|
|
2376
|
+
}
|
|
857
2377
|
}
|
|
858
2378
|
if (key === sayKey) {
|
|
2379
|
+
layoutLandscapeRail();
|
|
859
2380
|
return;
|
|
860
2381
|
}
|
|
861
2382
|
sayKey = key;
|
|
@@ -865,6 +2386,9 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
865
2386
|
event.stopPropagation();
|
|
866
2387
|
event.preventDefault();
|
|
867
2388
|
setSayOpen(false);
|
|
2389
|
+
if (onChip) {
|
|
2390
|
+
onChip();
|
|
2391
|
+
}
|
|
868
2392
|
sayHandler(what);
|
|
869
2393
|
});
|
|
870
2394
|
const row = el('div', { display: 'flex', justifyContent: 'space-between' }, sayCard);
|
|
@@ -885,12 +2409,14 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
885
2409
|
sayInput = null;
|
|
886
2410
|
sayNote = null;
|
|
887
2411
|
if (!chat) {
|
|
2412
|
+
layoutLandscapeRail();
|
|
888
2413
|
return;
|
|
889
2414
|
}
|
|
890
2415
|
sayNote = el('div', { fontSize: '11px', fontWeight: '500', opacity: '0.7' }, sayCard);
|
|
891
2416
|
sayNote.textContent = chat.note ?? '';
|
|
892
2417
|
const line = el('div', { display: 'flex', gap: '6px', opacity: chat.input ? '1' : '0.5' }, sayCard);
|
|
893
2418
|
const input = el('input', { flex: '1', minWidth: '0', padding: '7px 9px', borderRadius: '8px', border: '1px solid rgba(255,255,255,0.3)', background: 'rgba(255,255,255,0.1)', color: '#fff', font: '500 14px system-ui, sans-serif' }, line);
|
|
2419
|
+
chatField(input, 'message');
|
|
894
2420
|
input.maxLength = 200;
|
|
895
2421
|
input.placeholder = chat.placeholder ?? 'Message…';
|
|
896
2422
|
if (chat.placeholder) {
|
|
@@ -934,15 +2460,19 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
934
2460
|
event.preventDefault();
|
|
935
2461
|
send();
|
|
936
2462
|
});
|
|
2463
|
+
layoutLandscapeRail();
|
|
937
2464
|
},
|
|
938
2465
|
// Whether the chat field has the keyboard (the game's keys are its own).
|
|
939
2466
|
chatFocused: () => sayInput !== null && document.activeElement === sayInput,
|
|
940
2467
|
// The lines of what was just said, oldest first; hidden while a list is open.
|
|
941
2468
|
// Each is `{ text, id }`; a line with an `id` is another player's chat
|
|
942
2469
|
// message: a tap on it asks whether to report it.
|
|
2470
|
+
setChatModeration(enabled) {
|
|
2471
|
+
chatModeration = enabled === true;
|
|
2472
|
+
},
|
|
943
2473
|
setFeed(lines) {
|
|
944
2474
|
const shown = doorsOpen || peopleOpen ? [] : lines;
|
|
945
|
-
const key = shown.map((line) => `${line.id ?? ''}:${line.text}`).join('\n');
|
|
2475
|
+
const key = `${chatModeration}:` + shown.map((line) => `${line.id ?? ''}:${line.text}`).join('\n');
|
|
946
2476
|
if (key === feedKey) {
|
|
947
2477
|
return;
|
|
948
2478
|
}
|
|
@@ -960,6 +2490,7 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
960
2490
|
event.stopPropagation();
|
|
961
2491
|
node.replaceChildren();
|
|
962
2492
|
node.style.display = 'flex';
|
|
2493
|
+
node.style.flexWrap = 'wrap';
|
|
963
2494
|
node.style.gap = '6px';
|
|
964
2495
|
node.style.alignItems = 'center';
|
|
965
2496
|
el('span', {}, node).textContent = 'Report this message?';
|
|
@@ -968,6 +2499,12 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
968
2499
|
node.remove();
|
|
969
2500
|
onReportChat(line);
|
|
970
2501
|
});
|
|
2502
|
+
if (chatModeration && line.userId) {
|
|
2503
|
+
smallButton(node, 'Report & block', true).addEventListener('pointerdown', (e) => {
|
|
2504
|
+
e.stopPropagation();
|
|
2505
|
+
onBlockChat(line);
|
|
2506
|
+
});
|
|
2507
|
+
}
|
|
971
2508
|
smallButton(node, 'Cancel', false).addEventListener('pointerdown', (e) => {
|
|
972
2509
|
e.stopPropagation();
|
|
973
2510
|
feedKey = '';
|
|
@@ -977,66 +2514,278 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
977
2514
|
},
|
|
978
2515
|
// The Sit / Stand button's word, or null to hide it.
|
|
979
2516
|
sitPrompt(text) {
|
|
2517
|
+
if (actMode) {text = null;}
|
|
980
2518
|
sitButton.style.display = text ? 'block' : 'none';
|
|
981
2519
|
if (text && sitButton.textContent !== text) {
|
|
982
2520
|
sitButton.textContent = text;
|
|
983
2521
|
}
|
|
2522
|
+
layoutLandscapeRail();
|
|
984
2523
|
},
|
|
985
2524
|
// The Grab button's word ("Grab" or "Throw"), or null to hide it.
|
|
986
2525
|
grabPrompt(text) {
|
|
2526
|
+
if (actMode) {text = null;}
|
|
987
2527
|
grabButton.style.display = text ? 'block' : 'none';
|
|
988
2528
|
if (text && grabButton.textContent !== text) {
|
|
989
2529
|
grabButton.textContent = text;
|
|
990
2530
|
grabButton.style.background = text === 'Throw' ? 'rgba(233,196,143,0.92)' : 'rgba(20,16,12,0.78)';
|
|
991
2531
|
grabButton.style.color = text === 'Throw' ? '#2b2118' : '#fff';
|
|
992
2532
|
}
|
|
2533
|
+
layoutLandscapeRail();
|
|
2534
|
+
},
|
|
2535
|
+
// Inline state only: prompt changes wake the Weakest panel pass without a layout read.
|
|
2536
|
+
hudPromptSignature() {
|
|
2537
|
+
const prompts = [sitButton, grabButton, talkButton, nearButton];
|
|
2538
|
+
const act = [...extraSurfaces].filter(([id]) => id.startsWith('act-prompt:'));
|
|
2539
|
+
return JSON.stringify([talkOpen, pickerOpen, sayOpen, emotesOpen, peopleOpen, doorsOpen, Boolean(placeMenu?.sheet), Boolean(textAsk?.card),
|
|
2540
|
+
prompts.map(node => [node.style.display, node.textContent]), askNow?.key, askNow?.text,
|
|
2541
|
+
act.map(([id, { node }]) => [id, node.textContent, node.getAttribute('aria-label'), node.style.opacity])]);
|
|
2542
|
+
},
|
|
2543
|
+
talkRect: () => shownRect(panel),
|
|
2544
|
+
// Every place clears the engine's Shift lock, independently of Chirp.
|
|
2545
|
+
layoutCompanion(parent) {
|
|
2546
|
+
const lock = parent?.querySelector?.('button[aria-label^="Shift lock"]');
|
|
2547
|
+
if (lock !== companionLock) {restoreCompanionLock(); companionLock = lock; fitPicker(true);}
|
|
2548
|
+
const rect = shownRect(lock);
|
|
2549
|
+
// A lock the strip hid keeps its reserve, or the sheet would then fit
|
|
2550
|
+
// the lane, show the lock, and turn back into the strip next frame.
|
|
2551
|
+
const lift = rect && (lock.style.visibility !== 'hidden' || companionLockVisibility !== null) ? rect.bottom - rect.top + 8 : 0;
|
|
2552
|
+
if (lift === lockLift) {return;}
|
|
2553
|
+
lockLift = lift;
|
|
2554
|
+
if (landscape) {
|
|
2555
|
+
layoutLandscapeRail();
|
|
2556
|
+
} else {
|
|
2557
|
+
for (const [node, bottom] of cornerBottoms) {node.style.bottom = lift ? `calc(${bottom} + ${lift}px)` : bottom;}
|
|
2558
|
+
}
|
|
2559
|
+
fitPicker(true);
|
|
2560
|
+
},
|
|
2561
|
+
setCompanionBadge(show, name, onOpen) {
|
|
2562
|
+
if (!show) {
|
|
2563
|
+
companionBadge?.remove();
|
|
2564
|
+
companionBadge = null;
|
|
2565
|
+
delete this.companionBadge;
|
|
2566
|
+
return;
|
|
2567
|
+
}
|
|
2568
|
+
if (!companionBadge) {
|
|
2569
|
+
companionBadge = el('button', { width: '44px', height: '44px', flex: '0 0 44px', boxSizing: 'border-box', padding: '8px', borderRadius: '50%', border: '1px solid rgba(255,255,255,0.4)', background: 'rgba(20,16,12,0.72)', cursor: 'pointer', pointerEvents: 'auto', touchAction: 'manipulation' }, dock);
|
|
2570
|
+
geometry.register(companionBadge);
|
|
2571
|
+
companionBadge.innerHTML = '<svg viewBox="0 0 28 28" width="26" height="26" aria-hidden="true"><path fill="#fff6e6" d="M3 6l11 5L24 3l-5 13-7 6-2-8z"/><path fill="#e8743b" d="M14 11l5 5-7 6 2-11zM19 16l7 1-6 3z"/></svg>';
|
|
2572
|
+
companionBadge.addEventListener('pointerdown', (event) => {
|
|
2573
|
+
event.stopPropagation();
|
|
2574
|
+
companionBadge.openCompanion?.();
|
|
2575
|
+
});
|
|
2576
|
+
this.companionBadge = companionBadge;
|
|
2577
|
+
}
|
|
2578
|
+
companionBadge.openCompanion = onOpen;
|
|
2579
|
+
companionBadge.setAttribute('aria-label', `Chat with ${name}`);
|
|
2580
|
+
showCompanionBadge();
|
|
2581
|
+
},
|
|
2582
|
+
// A 44 px hit area over the private follower; created only for chat.
|
|
2583
|
+
setCompanionTalk(screen, name, onOpen) {
|
|
2584
|
+
if (!screen || talkOpen || pickerOpen || peopleOpen || doorsOpen || sayOpen || emotesOpen) {
|
|
2585
|
+
this.companionTalkButton?.remove();
|
|
2586
|
+
delete this.companionTalkButton;
|
|
2587
|
+
return;
|
|
2588
|
+
}
|
|
2589
|
+
if (!this.companionTalkButton) {
|
|
2590
|
+
const button = el('button', { position: 'absolute', width: '44px', height: '44px', transform: 'translate(-50%, -50%)', pointerEvents: 'auto', background: 'transparent', border: 'none', padding: '0', cursor: 'pointer' }, root);
|
|
2591
|
+
button.addEventListener('pointerdown', (event) => {
|
|
2592
|
+
event.stopPropagation();
|
|
2593
|
+
button.openCompanion?.();
|
|
2594
|
+
});
|
|
2595
|
+
this.companionTalkButton = button;
|
|
2596
|
+
}
|
|
2597
|
+
this.companionTalkButton.openCompanion = onOpen;
|
|
2598
|
+
this.companionTalkButton.style.left = `${screen.x}px`;
|
|
2599
|
+
this.companionTalkButton.style.top = `${screen.y}px`;
|
|
2600
|
+
this.companionTalkButton.setAttribute('aria-label', `Chat with ${name}`);
|
|
2601
|
+
// Never over a control: a tap there is the control's.
|
|
2602
|
+
const controls = [picker, grabButton, emoteButton, sayButton, talkButton, sitButton, sound?.button, back, hud, hudText, askCard, actionChips].map(shownRect).filter(Boolean);
|
|
2603
|
+
const covers = controls.some((r) => r.left < screen.x + 22 && r.right > screen.x - 22 && r.top < screen.y + 22 && r.bottom > screen.y - 22);
|
|
2604
|
+
this.companionTalkButton.style.display = covers ? 'none' : 'block';
|
|
993
2605
|
},
|
|
994
2606
|
// The Talk button, for the NPC named, or hidden.
|
|
995
|
-
talkPrompt(name) {
|
|
2607
|
+
talkPrompt(name, mind = false) {
|
|
2608
|
+
if (actMode) {name = null;}
|
|
996
2609
|
const show = Boolean(name) && !talkOpen;
|
|
997
2610
|
talkButton.style.display = show ? 'block' : 'none';
|
|
998
|
-
|
|
2611
|
+
// A mind's button names it by first name: "Chat with Biscuit", not the
|
|
2612
|
+
// whole "Biscuit, the puppy" in three lines on a phone.
|
|
2613
|
+
const text = show ? (mind ? `Chat with ${name.split(',')[0].trim() || name}` : `Talk to ${name}`) : '';
|
|
999
2614
|
if (show && talkButton.textContent !== text) {
|
|
1000
2615
|
talkButton.textContent = text;
|
|
1001
2616
|
}
|
|
2617
|
+
layoutLandscapeRail();
|
|
1002
2618
|
},
|
|
1003
|
-
openTalk(name) {
|
|
2619
|
+
openTalk(name, { mind = false, canType = true } = {}) {
|
|
1004
2620
|
talkOpen = true;
|
|
2621
|
+
showCompanionBadge();
|
|
2622
|
+
panelMind = mind;
|
|
1005
2623
|
panelName.textContent = name;
|
|
2624
|
+
dropTyping();
|
|
1006
2625
|
panelLog.replaceChildren();
|
|
2626
|
+
panelOpening = null;
|
|
2627
|
+
followedLine = null;
|
|
2628
|
+
dropAsks();
|
|
2629
|
+
dropHint();
|
|
2630
|
+
panelInput.value = '';
|
|
2631
|
+
panelInput.placeholder = mind ? `Ask ${name.split(',')[0].trim()} anything…` : 'Say something…';
|
|
2632
|
+
panelSend.disabled = false;
|
|
2633
|
+
panelSend.style.opacity = '1';
|
|
2634
|
+
panelSend.textContent = 'Say';
|
|
1007
2635
|
panel.style.display = 'flex';
|
|
1008
2636
|
talkButton.style.display = 'none';
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
panelInput.focus({ preventScroll: true });
|
|
1013
|
-
}
|
|
2637
|
+
panelForm.style.display = 'none';
|
|
2638
|
+
setTalkTyping(canType);
|
|
2639
|
+
layoutLandscapeRail();
|
|
1014
2640
|
},
|
|
1015
2641
|
closeTalk() {
|
|
1016
2642
|
talkOpen = false;
|
|
2643
|
+
showCompanionBadge();
|
|
2644
|
+
panelOpening = null;
|
|
1017
2645
|
panel.style.display = 'none';
|
|
1018
2646
|
panelInput.blur();
|
|
2647
|
+
dropAsks();
|
|
2648
|
+
dropHint();
|
|
2649
|
+
dropTyping();
|
|
2650
|
+
layoutLandscapeRail();
|
|
2651
|
+
},
|
|
2652
|
+
talkTyping: setTalkTyping,
|
|
2653
|
+
// Plain muted words under the log (the opening), or null for none: why an
|
|
2654
|
+
// under-13 speaker has no field ("Talking with Biscuit is for players 13
|
|
2655
|
+
// and up"). Not a button.
|
|
2656
|
+
talkHint(text) {
|
|
2657
|
+
const words = talkOpen && typeof text === 'string' && text ? text : null;
|
|
2658
|
+
if ((panelHint?.textContent ?? null) === words) {
|
|
2659
|
+
return;
|
|
2660
|
+
}
|
|
2661
|
+
if (!words) {
|
|
2662
|
+
dropHint();
|
|
2663
|
+
} else {
|
|
2664
|
+
panelHint ??= el('div', { fontSize: '12px', fontWeight: '500', opacity: '0.7' }, panel);
|
|
2665
|
+
panel.insertBefore(panelHint, panelForm);
|
|
2666
|
+
panelHint.textContent = words;
|
|
2667
|
+
}
|
|
2668
|
+
layoutPanel();
|
|
2669
|
+
syncTalkSurfaces();
|
|
2670
|
+
},
|
|
2671
|
+
// A refused re-attach keeps the unsent question for the next open.
|
|
2672
|
+
talkDraft(text) {
|
|
2673
|
+
if (text !== undefined) {
|
|
2674
|
+
panelInput.value = text;
|
|
2675
|
+
}
|
|
2676
|
+
return panelInput.value;
|
|
2677
|
+
},
|
|
2678
|
+
// v1.47: replace the opening in place; questions and later lines stay put.
|
|
2679
|
+
talkOpening(text) {
|
|
2680
|
+
if (talkOpen && panelOpening) {
|
|
2681
|
+
panelOpening.textContent = text;
|
|
2682
|
+
placeToast();
|
|
2683
|
+
}
|
|
2684
|
+
},
|
|
2685
|
+
// v1.46: a mind's chips sit below its field; an empty list removes them.
|
|
2686
|
+
talkAsks(asks, onAsk) {
|
|
2687
|
+
const child = Array.isArray(asks) && typeof asks[0]?.id === 'string';
|
|
2688
|
+
const list = Array.isArray(asks) ? asks.slice(0, child ? 4 : 3) : [];
|
|
2689
|
+
if (!list.length) {
|
|
2690
|
+
dropAsks();
|
|
2691
|
+
return;
|
|
2692
|
+
}
|
|
2693
|
+
if (!panelAsks) {
|
|
2694
|
+
panelAsks = el('div', { display: 'none', flexWrap: 'wrap', gap: '6px' }, panel);
|
|
2695
|
+
geometry.register(panelAsks);
|
|
2696
|
+
if (!panelMind) {
|
|
2697
|
+
panel.insertBefore(panelAsks, panelForm);
|
|
2698
|
+
}
|
|
2699
|
+
}
|
|
2700
|
+
panelAsks.replaceChildren();
|
|
2701
|
+
panelChildAsks = child;
|
|
2702
|
+
asksHandler = onAsk;
|
|
2703
|
+
if (panelMind && !child) {
|
|
2704
|
+
el('span', { fontSize: '12px', opacity: '0.7', flexBasis: '100%', gridColumn: '1 / -1' }, panelAsks).textContent = 'or try:';
|
|
2705
|
+
}
|
|
2706
|
+
for (const ask of list) {
|
|
2707
|
+
const chip = el('button', { pointerEvents: 'auto', maxWidth: '100%', overflowWrap: 'anywhere', padding: '6px 11px', borderRadius: '14px', border: '1px solid rgba(233,196,143,0.7)', background: 'rgba(233,196,143,0.14)', color: '#f5dfbd', font: '600 13px/1.25 system-ui, sans-serif', textAlign: 'left', cursor: 'pointer' }, panelAsks);
|
|
2708
|
+
chip.type = 'button';
|
|
2709
|
+
chip.textContent = child ? ask.label : ask;
|
|
2710
|
+
chip.addEventListener('pointerdown', (event) => {
|
|
2711
|
+
event.stopPropagation();
|
|
2712
|
+
event.preventDefault();
|
|
2713
|
+
if (onChip) {
|
|
2714
|
+
onChip();
|
|
2715
|
+
}
|
|
2716
|
+
asksHandler?.(ask);
|
|
2717
|
+
});
|
|
2718
|
+
}
|
|
2719
|
+
layoutPanel();
|
|
2720
|
+
syncTalkSurfaces();
|
|
2721
|
+
followTalkLine();
|
|
1019
2722
|
},
|
|
1020
2723
|
// `note`, when given, is a small caption under the line (a scripted reply).
|
|
1021
2724
|
talkLine(who, text, note = null) {
|
|
2725
|
+
// v1.35: where the log was before this line: at its end, or scrolled
|
|
2726
|
+
// up by the player to read something earlier.
|
|
2727
|
+
const scroll = geometry.scroll(panelLog);
|
|
2728
|
+
const atEnd = scroll.height - scroll.top - scroll.client <= TALK_END_PX;
|
|
2729
|
+
if (who === 'them') {
|
|
2730
|
+
dropTyping();
|
|
2731
|
+
}
|
|
1022
2732
|
const line = el('div', { alignSelf: who === 'me' ? 'flex-end' : 'flex-start', maxWidth: '85%', padding: '5px 9px', borderRadius: '10px', background: who === 'me' ? 'rgba(233,196,143,0.25)' : 'rgba(255,250,240,0.94)', color: who === 'me' ? '#fff' : '#2b2118' }, panelLog);
|
|
2733
|
+
geometry.register(line);
|
|
1023
2734
|
line.textContent = text;
|
|
2735
|
+
if (who === 'them' && panelLog.childElementCount === 1) {
|
|
2736
|
+
panelOpening = line;
|
|
2737
|
+
}
|
|
1024
2738
|
if (note) {
|
|
1025
2739
|
el('div', { fontSize: '11px', fontStyle: 'italic', opacity: '0.65', marginTop: '2px' }, line).textContent = note;
|
|
1026
2740
|
}
|
|
1027
|
-
|
|
2741
|
+
let top = scroll.top;
|
|
2742
|
+
if (who === 'me') {
|
|
2743
|
+
// The player's own words: they have just sent them, show them.
|
|
2744
|
+
// The browser clamps to the live end without reading appended layout.
|
|
2745
|
+
top = geometry.active() ? Number.MAX_SAFE_INTEGER : geometry.scroll(panelLog).height;
|
|
2746
|
+
panelLog.scrollTop = top;
|
|
2747
|
+
} else if (atEnd) {
|
|
2748
|
+
// A reply is read from its first word: its top at the top of what
|
|
2749
|
+
// shows (the end of the log when the whole reply fits, as the
|
|
2750
|
+
// browser stops there). A player reading further up is left there.
|
|
2751
|
+
top = geometry.offsets(line).top - geometry.offsets(panelLog).top;
|
|
2752
|
+
panelLog.scrollTop = top;
|
|
2753
|
+
}
|
|
2754
|
+
followedLine = who === 'me' || atEnd ? line : null;
|
|
2755
|
+
followedScroll = geometry.active() ? top : panelLog.scrollTop;
|
|
2756
|
+
followedSnapshot = geometry.active() ? scroll : null;
|
|
2757
|
+
placeToast();
|
|
1028
2758
|
},
|
|
1029
2759
|
talkWaiting(waiting) {
|
|
1030
2760
|
panelSend.disabled = waiting;
|
|
1031
2761
|
panelSend.style.opacity = waiting ? '0.5' : '1';
|
|
1032
2762
|
panelSend.textContent = waiting ? '…' : 'Say';
|
|
2763
|
+
if (!waiting) {
|
|
2764
|
+
dropTyping();
|
|
2765
|
+
} else if (talkOpen && panelMind && !panelTyping) {
|
|
2766
|
+
const scroll = geometry.scroll(panelLog);
|
|
2767
|
+
const atEnd = scroll.height - scroll.top - scroll.client <= TALK_END_PX;
|
|
2768
|
+
panelTyping = el('div', { alignSelf: 'flex-start', display: 'flex', gap: '3px', padding: '5px 9px', borderRadius: '10px', background: 'rgba(255,250,240,0.94)', color: '#2b2118' }, panelLog);
|
|
2769
|
+
panelTyping.className = 'hub-npc-typing';
|
|
2770
|
+
panelTyping.setAttribute('role', 'status');
|
|
2771
|
+
panelTyping.setAttribute('aria-label', `${panelName.textContent} is typing`);
|
|
2772
|
+
for (let i = 0; i < 3; i++) {
|
|
2773
|
+
el('span', {}, panelTyping).textContent = '•';
|
|
2774
|
+
}
|
|
2775
|
+
if (atEnd) {
|
|
2776
|
+
panelLog.scrollTop = geometry.active() ? Number.MAX_SAFE_INTEGER : geometry.scroll(panelLog).height;
|
|
2777
|
+
}
|
|
2778
|
+
}
|
|
2779
|
+
placeToast();
|
|
1033
2780
|
},
|
|
1034
2781
|
talkFocused() {
|
|
1035
2782
|
return document.activeElement === panelInput;
|
|
1036
2783
|
},
|
|
1037
2784
|
// `doors` is [{ id, title }] to offer, or null for none; `goText` is the
|
|
1038
|
-
// word on each one's button ("Go", or "Go together" in a party).
|
|
1039
|
-
|
|
2785
|
+
// word on each one's button ("Go", or "Go together" in a party). `stuck`
|
|
2786
|
+
// (v1.33, a deck with `hub.stuck`) is `{ where, onPick }`, a "Stuck?" row
|
|
2787
|
+
// over the doors that goes back to the place's arrival; null for none.
|
|
2788
|
+
setDoors(doors, goText = 'Go', stuck = null, yours = null) {
|
|
1040
2789
|
const show = Array.isArray(doors) && doors.length > 0;
|
|
1041
2790
|
doorsButton.style.display = show ? 'block' : 'none';
|
|
1042
2791
|
if (!show) {
|
|
@@ -1044,23 +2793,53 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
1044
2793
|
doorsKey = '';
|
|
1045
2794
|
return;
|
|
1046
2795
|
}
|
|
1047
|
-
const
|
|
2796
|
+
const yourRows = yours?.rows?.slice(0, desktop() ? 5 : 3) ?? [];
|
|
2797
|
+
const yourKey = yours ? JSON.stringify([yourRows, yours.hearts ?? null]) : '';
|
|
2798
|
+
const key = `${yourKey}${goText}#${doors.map((d) => `${d.id}:${d.title ?? ''}:${d.featured ? 'f' : ''}${d.solo ? 's' : ''}${d.need ?? ''}`).join('|')}${stuck ? `#stuck:${stuck.where}` : ''}`;
|
|
2799
|
+
if (stuck) {
|
|
2800
|
+
stuckRowPick = stuck.onPick;
|
|
2801
|
+
}
|
|
1048
2802
|
if (key === doorsKey) {
|
|
1049
2803
|
return;
|
|
1050
2804
|
}
|
|
1051
2805
|
doorsKey = key;
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
const row = el('div', { display: 'flex', alignItems: 'center', gap: '8px' },
|
|
2806
|
+
doorsBody.replaceChildren();
|
|
2807
|
+
if (stuck) {
|
|
2808
|
+
const row = el('div', { display: 'flex', alignItems: 'center', gap: '8px', paddingBottom: '6px', borderBottom: '1px solid rgba(255,255,255,0.18)' }, doorsBody);
|
|
2809
|
+
row.dataset.hub = 'stuck-row';
|
|
2810
|
+
const words = el('div', { flex: '1', minWidth: '0' }, row);
|
|
2811
|
+
el('div', { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, words).textContent = 'Stuck?';
|
|
2812
|
+
el('div', { fontSize: '11px', fontWeight: '500', opacity: '0.7', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, words).textContent = stuck.where;
|
|
2813
|
+
const go = smallButton(row, 'Go', false);
|
|
2814
|
+
go.style.flex = 'none';
|
|
2815
|
+
go.setAttribute('aria-label', `Stuck? ${stuck.where}`);
|
|
2816
|
+
go.addEventListener('pointerdown', (event) => {
|
|
2817
|
+
event.stopPropagation();
|
|
2818
|
+
closeDoors();
|
|
2819
|
+
stuckRowPick();
|
|
2820
|
+
});
|
|
2821
|
+
}
|
|
2822
|
+
if (yourRows.length) {
|
|
2823
|
+
el('div', { fontSize: '13px', opacity: '0.8' }, doorsBody).textContent = 'Your games';
|
|
2824
|
+
}
|
|
2825
|
+
const listed = [...yourRows.map((r) => ({ ...doors.find((d) => d.id === r.door), title: r.title, line: r.line, yours: true })), ...doors];
|
|
2826
|
+
for (const [index, door] of listed.entries()) {
|
|
2827
|
+
if (index === yourRows.length && yourRows.length) {
|
|
2828
|
+
el('div', { fontSize: '13px', opacity: '0.8', borderTop: '1px solid rgba(255,255,255,0.18)', paddingTop: '8px' }, doorsBody).textContent = 'All doors';
|
|
2829
|
+
}
|
|
2830
|
+
const row = el('div', { display: 'flex', alignItems: 'center', gap: '8px' }, doorsBody);
|
|
1055
2831
|
// The title on a line of its own, with one short word under it on what
|
|
1056
2832
|
// the door takes (a solo game, how many it needs): beside the button
|
|
1057
2833
|
// they squeezed the title to a few letters.
|
|
1058
2834
|
const words = el('div', { flex: '1', minWidth: '0' }, row);
|
|
1059
2835
|
const name = el('div', { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, words);
|
|
1060
|
-
name.textContent = `${door.featured ? '★ ' : ''}${door.title ?? door.id}`;
|
|
1061
|
-
const takes = door.solo ? 'solo' : door.need ? `needs ${door.need}` : '';
|
|
2836
|
+
name.textContent = `${door.featured && !door.yours ? '★ ' : ''}${door.title ?? door.id}`;
|
|
2837
|
+
const takes = door.yours ? door.line : door.solo ? 'solo' : door.need ? `needs ${door.need}` : '';
|
|
1062
2838
|
if (takes) {
|
|
1063
|
-
el('div', { fontSize: '11px', fontWeight: '500', opacity: '0.7' }, words).textContent = takes;
|
|
2839
|
+
el('div', { fontSize: '11px', fontWeight: '500', opacity: '0.7', ...(door.yours ? { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } : {}) }, words).textContent = takes;
|
|
2840
|
+
}
|
|
2841
|
+
if (yours?.hearts) {
|
|
2842
|
+
heartButton(row, door.id, yours.hearts.includes(door.id));
|
|
1064
2843
|
}
|
|
1065
2844
|
const go = el('button', { padding: '5px 12px', borderRadius: '12px', border: 'none', background: '#e9c48f', color: '#2b2118', font: '700 13px system-ui, sans-serif', cursor: 'pointer' }, row);
|
|
1066
2845
|
// A party cannot go together through a door that takes one player.
|
|
@@ -1069,6 +2848,9 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
1069
2848
|
go.addEventListener('pointerdown', (event) => {
|
|
1070
2849
|
event.stopPropagation();
|
|
1071
2850
|
closeDoors();
|
|
2851
|
+
if (onChip) {
|
|
2852
|
+
onChip();
|
|
2853
|
+
}
|
|
1072
2854
|
onJumpDoor(door);
|
|
1073
2855
|
});
|
|
1074
2856
|
}
|
|
@@ -1096,11 +2878,11 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
1096
2878
|
const key = `${party ?? ''}#${people.map((p) => `${p.key}:${p.username ?? ''}:${p.mark ?? ''}:${(p.actions ?? []).map((a) => a.text).join(',')}:${p.door ?? ''}:${p.where ? 1 : 0}`).join('|')}`;
|
|
1097
2879
|
if (key !== peopleKey) {
|
|
1098
2880
|
peopleKey = key;
|
|
1099
|
-
|
|
2881
|
+
peopleBody.replaceChildren();
|
|
1100
2882
|
peopleRows.clear();
|
|
1101
2883
|
if (party) {
|
|
1102
2884
|
// The player's party: how many, and the way out of it.
|
|
1103
|
-
const head = el('div', { display: 'flex', alignItems: 'center', gap: '8px', paddingBottom: '4px', borderBottom: '1px solid rgba(255,255,255,0.18)' },
|
|
2885
|
+
const head = el('div', { display: 'flex', alignItems: 'center', gap: '8px', paddingBottom: '4px', borderBottom: '1px solid rgba(255,255,255,0.18)' }, peopleBody);
|
|
1104
2886
|
el('div', { flex: '1', fontSize: '12px', opacity: '0.8' }, head).textContent = party;
|
|
1105
2887
|
smallButton(head, 'Leave party', false).addEventListener('pointerdown', (event) => {
|
|
1106
2888
|
event.stopPropagation();
|
|
@@ -1123,6 +2905,12 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
1123
2905
|
// the friend themself. Anything not listed is removed.
|
|
1124
2906
|
setPointers(items) {
|
|
1125
2907
|
const seen = new Set();
|
|
2908
|
+
// The round buttons an edge chip is kept beside, never under (v1.38: a
|
|
2909
|
+
// chip at the right edge had half its words under the chat button).
|
|
2910
|
+
// Read once a call, and only when there is an edge chip.
|
|
2911
|
+
const buttons = items.some((item) => item.angle !== null && item.angle !== undefined)
|
|
2912
|
+
? [sayButton, emoteButton, grabButton, sound?.button].map(shownRect).filter(Boolean)
|
|
2913
|
+
: [];
|
|
1126
2914
|
for (const item of items) {
|
|
1127
2915
|
seen.add(item.id);
|
|
1128
2916
|
let node = pointerNodes.get(item.id);
|
|
@@ -1135,19 +2923,45 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
1135
2923
|
pointerNodes.set(item.id, node);
|
|
1136
2924
|
}
|
|
1137
2925
|
const edge = item.angle !== null && item.angle !== undefined;
|
|
1138
|
-
|
|
2926
|
+
const display = edge ? 'inline-block' : 'none';
|
|
2927
|
+
if (node.arrow.style.display !== display) {
|
|
2928
|
+
node.arrow.style.display = display;
|
|
2929
|
+
}
|
|
1139
2930
|
if (edge) {
|
|
1140
2931
|
node.arrow.style.transform = `rotate(${item.angle}rad)`;
|
|
1141
2932
|
}
|
|
1142
2933
|
if (node.words.textContent !== item.text) {
|
|
1143
2934
|
node.words.textContent = item.text;
|
|
1144
2935
|
}
|
|
1145
|
-
// Kept whole on screen; over a friend it sits above their head.
|
|
1146
|
-
const half = node.chip.offsetWidth / 2;
|
|
1147
|
-
const x = Math.min(Math.max(item.x, half + 6), window.innerWidth - half - 6);
|
|
1148
2936
|
node.chip.style.transform = edge ? 'translate(-50%, -50%)' : 'translate(-50%, -100%)';
|
|
1149
|
-
node.chip.style.left = `${x}px`;
|
|
2937
|
+
node.chip.style.left = `${item.x}px`;
|
|
1150
2938
|
node.chip.style.top = `${item.y}px`;
|
|
2939
|
+
// Kept whole on screen; over a friend it sits above their head.
|
|
2940
|
+
const size = geometry.size(node.chip);
|
|
2941
|
+
const half = size.w / 2;
|
|
2942
|
+
let x = Math.min(Math.max(item.x, half + 6), geometry.view().w - half - 6);
|
|
2943
|
+
let y = item.y;
|
|
2944
|
+
if (edge && buttons.length) {
|
|
2945
|
+
// The buttons stand in a column at the edge. A chip over any of them
|
|
2946
|
+
// goes to the left of them all; one too wide for that goes over the
|
|
2947
|
+
// whole column it lies across, or under it with no room over. So no
|
|
2948
|
+
// move away from one button can put it on another.
|
|
2949
|
+
const tall = size.h / 2;
|
|
2950
|
+
const across = (r) => x + half > r.left - 4 && x - half < r.right + 4;
|
|
2951
|
+
if (buttons.some((r) => across(r) && y + tall > r.top && y - tall < r.bottom)) {
|
|
2952
|
+
const left = Math.min(...buttons.map((r) => r.left)) - 6 - half;
|
|
2953
|
+
if (left >= half + 6) {
|
|
2954
|
+
x = left;
|
|
2955
|
+
} else {
|
|
2956
|
+
const column = buttons.filter(across);
|
|
2957
|
+
const over = Math.min(...column.map((r) => r.top)) - 6 - tall;
|
|
2958
|
+
y = over >= tall + 6 ? over : Math.max(...column.map((r) => r.bottom)) + 6 + tall;
|
|
2959
|
+
}
|
|
2960
|
+
}
|
|
2961
|
+
}
|
|
2962
|
+
if (node.chip.style.left !== `${x}px`) {node.chip.style.left = `${x}px`;}
|
|
2963
|
+
if (node.chip.style.top !== `${y}px`) {node.chip.style.top = `${y}px`;}
|
|
2964
|
+
node.y = y;
|
|
1151
2965
|
}
|
|
1152
2966
|
for (const [id, node] of pointerNodes) {
|
|
1153
2967
|
if (!seen.has(id)) {
|
|
@@ -1155,28 +2969,48 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
1155
2969
|
pointerNodes.delete(id);
|
|
1156
2970
|
}
|
|
1157
2971
|
}
|
|
1158
|
-
if (hudClear) {
|
|
2972
|
+
if (hudClear || hudText.style.display !== 'none') {
|
|
1159
2973
|
keepClearOfHud(
|
|
1160
2974
|
'pointers',
|
|
1161
2975
|
items.map((item) => {
|
|
1162
2976
|
const chip = pointerNodes.get(item.id).chip;
|
|
1163
2977
|
const edge = item.angle !== null && item.angle !== undefined;
|
|
1164
|
-
return [chip, parseFloat(chip.style.left), item.y, edge ? 'center' : 'bottom', `${edge ? '>' : ''}${item.text}`];
|
|
2978
|
+
return [chip, parseFloat(chip.style.left), pointerNodes.get(item.id).y, edge ? 'center' : 'bottom', `${edge ? '>' : ''}${item.text}`];
|
|
1165
2979
|
}),
|
|
1166
2980
|
);
|
|
1167
2981
|
}
|
|
1168
2982
|
},
|
|
2983
|
+
// Whether a card given to `setAsk` now would actually be displayed: not
|
|
2984
|
+
// while the page is hidden or between pagehide and pageshow. The hub
|
|
2985
|
+
// starts no ask lease while this is false.
|
|
2986
|
+
askShowable() {
|
|
2987
|
+
return !askHidden();
|
|
2988
|
+
},
|
|
1169
2989
|
// `ask` is { key, text, yes, no } (the words and the two buttons'), or
|
|
1170
2990
|
// null for none; an answer goes to `onAsk(ask, true | false)`.
|
|
1171
2991
|
setAsk(ask) {
|
|
1172
2992
|
askNow = ask;
|
|
1173
|
-
askCard.style.display = ask ? 'flex' : 'none';
|
|
2993
|
+
askCard.style.display = ask && !askHidden() ? 'flex' : 'none';
|
|
1174
2994
|
if (!ask || ask.key === askKey) {
|
|
1175
2995
|
return;
|
|
1176
2996
|
}
|
|
1177
2997
|
askKey = ask.key;
|
|
1178
2998
|
askCard.replaceChildren();
|
|
1179
|
-
|
|
2999
|
+
if (ask.kind === 'yours') {
|
|
3000
|
+
askCard.style.width = 'min(94vw, 420px)';
|
|
3001
|
+
} else if (askCard.style.width !== 'min(86vw, 320px)') {
|
|
3002
|
+
askCard.style.width = 'min(86vw, 320px)';
|
|
3003
|
+
}
|
|
3004
|
+
if (ask.kind === 'yours') {
|
|
3005
|
+
const words = el('div', { flex: '1', minWidth: '0', fontWeight: '600', overflow: 'hidden' }, askCard);
|
|
3006
|
+
el('div', { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, words).textContent = ask.text;
|
|
3007
|
+
el('div', { fontSize: '11px', fontWeight: '500', opacity: '0.7', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, words).textContent = ask.line;
|
|
3008
|
+
if (typeof ask.heart === 'boolean') {
|
|
3009
|
+
heartButton(askCard, ask.door, ask.heart, true);
|
|
3010
|
+
}
|
|
3011
|
+
} else {
|
|
3012
|
+
el('div', { flex: '1', minWidth: '0', fontWeight: '600' }, askCard).textContent = ask.text;
|
|
3013
|
+
}
|
|
1180
3014
|
for (const [text, answer] of [[ask.yes, true], [ask.no, false]]) {
|
|
1181
3015
|
smallButton(askCard, text, answer).addEventListener('pointerdown', (event) => {
|
|
1182
3016
|
event.stopPropagation();
|
|
@@ -1197,9 +3031,89 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
1197
3031
|
nearButton.textContent = text;
|
|
1198
3032
|
}
|
|
1199
3033
|
}
|
|
3034
|
+
layoutLandscapeRail();
|
|
3035
|
+
},
|
|
3036
|
+
// The "Stuck?" chip (v1.33): its words, or null to hide it; a press calls
|
|
3037
|
+
// `handler`. Never over an open card or list, like the invite button, and
|
|
3038
|
+
// never over the HUD, a question, another control, a cabinet's card or
|
|
3039
|
+
// the ribbon (`placeStuckChip`). Said last in a frame: after the other
|
|
3040
|
+
// setters and after `flushHudClear`, whose final boxes it is placed by.
|
|
3041
|
+
stuckPrompt(text, handler) {
|
|
3042
|
+
if (!text && !stuckChip) {
|
|
3043
|
+
return;
|
|
3044
|
+
}
|
|
3045
|
+
stuckChip ??= buildStuckChip();
|
|
3046
|
+
if (text) {
|
|
3047
|
+
stuckHandler = handler;
|
|
3048
|
+
if (stuckChip.textContent !== text) {
|
|
3049
|
+
stuckChip.textContent = text;
|
|
3050
|
+
}
|
|
3051
|
+
}
|
|
3052
|
+
const show = Boolean(text) && !sayOpen && !emotesOpen && !peopleOpen && !doorsOpen && !talkOpen;
|
|
3053
|
+
if (show && stuckChip.style.display !== 'block') {
|
|
3054
|
+
// Laid out before it is measured; nothing is painted in between.
|
|
3055
|
+
stuckChip.style.display = 'block';
|
|
3056
|
+
}
|
|
3057
|
+
// The toast leaves the chip's spot clear before the chip looks for the
|
|
3058
|
+
// toast, by where it hangs and not by whether it is drawn.
|
|
3059
|
+
const was = stuckSpot;
|
|
3060
|
+
if (show) {
|
|
3061
|
+
const w = geometry.size(stuckChip).w;
|
|
3062
|
+
const x = geometry.offsets(stuckChip).left;
|
|
3063
|
+
const y = geometry.offsets(stuckChip).top;
|
|
3064
|
+
const h = geometry.size(stuckChip).h;
|
|
3065
|
+
stuckSpot = was && was.left === x - w / 2 && was.right === x + w / 2 && was.top === y && was.bottom === y + h ? was : { left: x - w / 2, right: x + w / 2, top: y, bottom: y + h };
|
|
3066
|
+
} else {
|
|
3067
|
+
stuckSpot = null;
|
|
3068
|
+
}
|
|
3069
|
+
if (stuckSpot !== was) {
|
|
3070
|
+
placeToast();
|
|
3071
|
+
}
|
|
3072
|
+
if (!show || !placeStuckChip()) {
|
|
3073
|
+
stuckChip.style.display = 'none';
|
|
3074
|
+
}
|
|
3075
|
+
},
|
|
3076
|
+
// The sound control (a deck with `hub.soundscape`): `show` whether the
|
|
3077
|
+
// button is up, `state` `{ volume, muted }` (0 to 1), `handlers`
|
|
3078
|
+
// `{ onVolume(0..1), onMuted(bool) }`. Never called in a deck without the
|
|
3079
|
+
// key, and nothing of it exists until it is.
|
|
3080
|
+
soundControl(show, state, handlers) {
|
|
3081
|
+
if (!show && !sound) {
|
|
3082
|
+
return;
|
|
3083
|
+
}
|
|
3084
|
+
sound ??= buildSound();
|
|
3085
|
+
sound.handlers = handlers ?? sound.handlers;
|
|
3086
|
+
const percent = Math.round((state?.volume ?? 0) * 100);
|
|
3087
|
+
const muted = state?.muted === true;
|
|
3088
|
+
const key = `${show ? 1 : 0}|${muted ? 1 : 0}|${percent}|${stats.textContent ? 1 : 0}`;
|
|
3089
|
+
if (key === sound.key) {
|
|
3090
|
+
return;
|
|
3091
|
+
}
|
|
3092
|
+
sound.key = key;
|
|
3093
|
+
sound.muted = muted;
|
|
3094
|
+
if (!show) {
|
|
3095
|
+
sound.open = false;
|
|
3096
|
+
sound.card.style.display = 'none';
|
|
3097
|
+
}
|
|
3098
|
+
sound.button.style.display = show ? 'block' : 'none';
|
|
3099
|
+
// Under the frame-rate readout where that is up (`?hubstats`).
|
|
3100
|
+
const top = stats.textContent ? `max(${geometry.offsets(stats).top + geometry.size(stats).h + 6}px, ${soundTop})` : soundTop;
|
|
3101
|
+
sound.button.style.top = top;
|
|
3102
|
+
sound.card.style.top = `calc(${top} + 46px)`;
|
|
3103
|
+
layoutLandscapeRail();
|
|
3104
|
+
const quiet = muted || percent === 0;
|
|
3105
|
+
sound.button.textContent = quiet ? '🔇' : '🔊';
|
|
3106
|
+
sound.button.setAttribute('aria-label', quiet ? 'Sound: off' : `Sound: ${percent}%`);
|
|
3107
|
+
sound.mute.textContent = muted ? 'Unmute' : 'Mute';
|
|
3108
|
+
sound.slider.style.opacity = muted ? '0.5' : '1';
|
|
3109
|
+
// Not while the player drags it: the value is theirs then.
|
|
3110
|
+
if (document.activeElement !== sound.slider && sound.slider.value !== String(percent)) {
|
|
3111
|
+
sound.slider.value = String(percent);
|
|
3112
|
+
}
|
|
1200
3113
|
},
|
|
1201
3114
|
// Whether the People list is open (its rows' places are asked for then).
|
|
1202
3115
|
peopleOpen: () => peopleOpen,
|
|
3116
|
+
pickerSheetOpen: () => pickerOpen,
|
|
1203
3117
|
setStats(text) {
|
|
1204
3118
|
stats.style.display = text ? 'block' : 'none';
|
|
1205
3119
|
if (stats.textContent !== text) {
|
|
@@ -1207,14 +3121,84 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
|
|
|
1207
3121
|
}
|
|
1208
3122
|
},
|
|
1209
3123
|
dispose() {
|
|
3124
|
+
api.clearPadContext();
|
|
3125
|
+
askLifecycle.abort();
|
|
3126
|
+
if (placeMenu) {clearMenu();}
|
|
3127
|
+
if (textAsk) {
|
|
3128
|
+
clearTextAsk();
|
|
3129
|
+
}
|
|
3130
|
+
if (actionChips || actionOverflow) {
|
|
3131
|
+
clearActions();
|
|
3132
|
+
}
|
|
1210
3133
|
if (hudClearDrawn) {
|
|
1211
3134
|
restoreHudClear();
|
|
1212
3135
|
}
|
|
3136
|
+
worldLayout?.begin();
|
|
3137
|
+
safeLayout?.dispose();
|
|
3138
|
+
if (debugLayout && globalThis.castleHub?.layout === debugLayout) {
|
|
3139
|
+
delete globalThis.castleHub.layout;
|
|
3140
|
+
if (!Object.keys(globalThis.castleHub).length) {delete globalThis.castleHub;}
|
|
3141
|
+
}
|
|
3142
|
+
restoreCompanionLock();
|
|
3143
|
+
talkOpen = false;
|
|
3144
|
+
syncTalkCaption();
|
|
3145
|
+
geometry.dispose();
|
|
3146
|
+
unwatchViewport();
|
|
1213
3147
|
unguardKeys();
|
|
1214
3148
|
desktopQuery?.removeEventListener?.('change', layoutPanel);
|
|
3149
|
+
for (const node of labelMeasures.values()) {node.remove();}
|
|
1215
3150
|
root.remove();
|
|
1216
3151
|
},
|
|
1217
3152
|
};
|
|
3153
|
+
const surface = (id, node, kind = 'control', transient = false, margin) => ({ id, node, kind, transient, margin, projected: Boolean(worldLayout) && (kind === 'label' || (kind === 'pointer' && id !== 'stuck')) });
|
|
3154
|
+
const surfaces = () => [
|
|
3155
|
+
surface('hud', hud, 'hud', false, { top: 12 }),
|
|
3156
|
+
surface('hud-prompt', hudText, 'text', false, { bottom: 54 }),
|
|
3157
|
+
surface('back', back, 'control', false, { left: landscape ? 76 : 12, top: 12 }),
|
|
3158
|
+
{ ...surface('character', pickerToggle, 'control', false, { right: landscape ? 12 : 10, bottom: 10 }), stack: 3, stackNode: picker },
|
|
3159
|
+
surface('character-card', pickerCard, 'card'),
|
|
3160
|
+
{ ...surface('grab', grabButton), stack: 2 }, { ...surface('emote', emoteButton), stack: 1 }, { ...surface('quick-chat', sayButton), stack: 0 },
|
|
3161
|
+
surface('emotes', emoteRow, 'card'), surface('quick-chat-card', sayCard, 'card'),
|
|
3162
|
+
{ ...surface('sit', sitButton), stack: 6 }, { ...surface('talk', talkButton), stack: 7 }, { ...surface('near', nearButton), stack: 8 },
|
|
3163
|
+
surface('talk-card', panel, 'card'), surface('doors-card', doorsList, 'card'), surface('people-card', peopleList, 'card'),
|
|
3164
|
+
{ ...surface('navigation', dock, 'control', false, { left: 10, bottom: 10 }), reportNodes: () => [
|
|
3165
|
+
{ id: 'doors', kind: 'control', node: doorsButton }, { id: 'people', kind: 'control', node: peopleButton },
|
|
3166
|
+
{ id: 'companion-badge', kind: 'control', node: companionBadge },
|
|
3167
|
+
] },
|
|
3168
|
+
surface('sound', sound?.button, 'control', false, { right: 12, top: 64 }), surface('sound-card', sound?.card, 'card'),
|
|
3169
|
+
surface('actions', actionChips), surface('ask-card', askCard, 'card'),
|
|
3170
|
+
surface('menu', placeMenu?.sheet, 'card'), surface('text-ask', textAsk?.card, 'card'),
|
|
3171
|
+
surface('toast', toast, 'toast', true, { top: 12 }), surface('ribbon', ribbon, 'ribbon', true),
|
|
3172
|
+
surface('cabinet', cabinet, 'card', true), surface('feed', feed, 'text', true, { left: 10 }),
|
|
3173
|
+
surface('stats', stats, 'text', true, { right: 8, top: 8 }), surface('stuck', stuckChip, 'pointer', true),
|
|
3174
|
+
...[...labelNodes].map(([id, node]) => surface(`label:${id}`, node, 'label', true)),
|
|
3175
|
+
...[...pointerNodes].map(([id, item]) => surface(`pointer:${id}`, item.chip, 'pointer', true)),
|
|
3176
|
+
...externalEntries().map(([id, item]) => ({ ...surface(id, item.node, item.kind, item.kind === 'text'), ...item.placement, ...(id === 'engine-shift-lock' ? { stack: 4 } : {}) })),
|
|
3177
|
+
...(actionOverflow?.surfaces?.() ?? []).map((node, i) => surface(`action-overflow:${i}`, node, 'control')),
|
|
3178
|
+
...[...root.children].filter((node) => node.style.zIndex === '3').flatMap((node) => [...node.children]
|
|
3179
|
+
.map((child, i) => ({ child, i }))
|
|
3180
|
+
// Decorating's full-view world input layer is not a chrome box.
|
|
3181
|
+
.filter(({ child }) => !['0', '0px'].includes(child.style.inset) && (child.tagName === 'BUTTON' || child.style.pointerEvents === 'auto'))
|
|
3182
|
+
.map(({ child, i }) => ({ ...surface(`decor:${i}`, child, i === 0 ? 'control' : 'card'), ...(i === 0 ? { stack: 5 } : {}) }))),
|
|
3183
|
+
];
|
|
3184
|
+
// Register the static sources once, including flow controls reported by
|
|
3185
|
+
// a compound surface. Lazy elements register as they are constructed.
|
|
3186
|
+
for (const entry of surfaces()) {
|
|
3187
|
+
geometry.register(entry.node); geometry.register(entry.stackNode);
|
|
3188
|
+
for (const child of entry.reportNodes?.() ?? []) {geometry.register(child.node);}
|
|
3189
|
+
}
|
|
3190
|
+
if (worldLabelsDefault) {
|
|
3191
|
+
worldLayout = makeWorldLayout(surfaces, worldView, worldObstacles, geometry);
|
|
3192
|
+
}
|
|
3193
|
+
if (safeInsets) {
|
|
3194
|
+
safeLayout = makeSafeLayout({ root, hud: () => hud, entries: surfaces, onLayout: () => {
|
|
3195
|
+
if (actionOverflow && actionOverflowObstacles) {actionOverflow.reconcileWatch(actionOverflowObstacles()); actionOverflow.invalidate();}
|
|
3196
|
+
} });
|
|
3197
|
+
debugLayout = () => { safeLayout.flush(); worldLayout?.flush(); return safeLayout.report(); };
|
|
3198
|
+
(globalThis.castleHub ??= {}).layout = debugLayout;
|
|
3199
|
+
safeLayout.flush();
|
|
3200
|
+
}
|
|
3201
|
+
return api;
|
|
1218
3202
|
}
|
|
1219
3203
|
|
|
1220
3204
|
// Black or white, whichever reads on a `#rrggbb` background.
|