castle-web-cli 0.4.232 → 0.4.233

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.
Files changed (355) hide show
  1. package/dist/agent-failures.d.ts +8 -0
  2. package/dist/agent-failures.js +19 -2
  3. package/dist/agent-prompts.d.ts +1 -1
  4. package/dist/agent-prompts.js +10 -3
  5. package/dist/agent.d.ts +64 -3
  6. package/dist/agent.js +170 -81
  7. package/dist/castle-host/host.d.ts +1 -0
  8. package/dist/castle-host/host.js +51 -3
  9. package/dist/castleJson.d.ts +4 -2
  10. package/dist/castleJson.js +2 -0
  11. package/dist/check.d.ts +3 -1
  12. package/dist/check.js +11 -1
  13. package/dist/devSessionStorage.js +47 -1
  14. package/dist/importPinMismatch.d.ts +22 -0
  15. package/dist/importPinMismatch.js +77 -0
  16. package/dist/importRegression.js +3 -15
  17. package/dist/imports.d.ts +10 -3
  18. package/dist/imports.js +88 -20
  19. package/dist/index.js +5 -4
  20. package/dist/init.js +1 -1
  21. package/dist/platformDoc.js +22 -0
  22. package/dist/routerFences.d.ts +5 -0
  23. package/dist/routerFences.js +12 -2
  24. package/dist/save-deck.d.ts +5 -0
  25. package/dist/save-deck.js +37 -4
  26. package/dist/serve.js +3 -0
  27. package/dist/shell/assets/{index-D2tWM896.js → index-BjOxR-lW.js} +4 -4
  28. package/dist/shell/assets/index-MVLfNYd9.css +1 -0
  29. package/dist/shell/index.html +2 -2
  30. package/dist/taskSteer.d.ts +13 -0
  31. package/dist/taskSteer.js +22 -2
  32. package/kits/base/castle.json +1 -1
  33. package/kits/base/package-lock.json +1 -1
  34. package/kits/base/sdk/README.md +79 -2
  35. package/kits/base/sdk/avatar.d.ts +6 -2
  36. package/kits/base/sdk/avatar.js +12 -4
  37. package/kits/base/sdk/castle.d.ts +1 -1
  38. package/kits/base/sdk/commands.d.ts +14 -0
  39. package/kits/base/sdk/hub.d.ts +6 -2
  40. package/kits/base/sdk/hub.js +13 -0
  41. package/kits/base/sdk/multiplayer.js +17 -1
  42. package/kits/base/sdk/save.js +2 -1
  43. package/kits/base/sdk/server/hub.d.ts +87 -0
  44. package/kits/base/sdk/server/hub.js +70 -0
  45. package/kits/base/sdk/server/platformHandle.d.ts +31 -1
  46. package/kits/base/sdk/server/storage.d.ts +13 -0
  47. package/kits/base/sdk/server/storage.js +46 -0
  48. package/kits/base/sdk/server/wrapper.d.ts +36 -5
  49. package/kits/base/sdk/server/wrapper.js +83 -8
  50. package/kits/hub-game/CLAUDE.md +329 -11
  51. package/kits/hub-game/blueprints/avatar-10.scene +28 -0
  52. package/kits/hub-game/blueprints/avatar-11.scene +28 -0
  53. package/kits/hub-game/blueprints/avatar-12.scene +28 -0
  54. package/kits/hub-game/blueprints/avatar-13.scene +28 -0
  55. package/kits/hub-game/blueprints/avatar-14.scene +28 -0
  56. package/kits/hub-game/blueprints/avatar-15.scene +28 -0
  57. package/kits/hub-game/blueprints/avatar-4.scene +28 -0
  58. package/kits/hub-game/blueprints/avatar-5.scene +28 -0
  59. package/kits/hub-game/blueprints/avatar-6.scene +28 -0
  60. package/kits/hub-game/blueprints/avatar-7.scene +28 -0
  61. package/kits/hub-game/blueprints/avatar-8.scene +28 -0
  62. package/kits/hub-game/blueprints/avatar-9.scene +28 -0
  63. package/kits/hub-game/code/client/actorBudget.js +47 -0
  64. package/kits/hub-game/code/client/attention.js +11 -2
  65. package/kits/hub-game/code/client/avatar.js +309 -35
  66. package/kits/hub-game/code/client/avatarCap.js +228 -0
  67. package/kits/hub-game/code/client/avatarColors.js +70 -0
  68. package/kits/hub-game/code/client/avatarFaces.js +21 -0
  69. package/kits/hub-game/code/client/avatarShare.js +251 -0
  70. package/kits/hub-game/code/client/ballot.js +467 -0
  71. package/kits/hub-game/code/client/build.js +22 -0
  72. package/kits/hub-game/code/client/chrome.js +1144 -50
  73. package/kits/hub-game/code/client/companion.js +716 -0
  74. package/kits/hub-game/code/client/companionDress.js +99 -0
  75. package/kits/hub-game/code/client/decor.js +509 -0
  76. package/kits/hub-game/code/client/earned.js +131 -0
  77. package/kits/hub-game/code/client/emoteBubble.js +75 -0
  78. package/kits/hub-game/code/client/grab.js +339 -20
  79. package/kits/hub-game/code/client/hookLayer.js +299 -13
  80. package/kits/hub-game/code/client/idle.js +163 -22
  81. package/kits/hub-game/code/client/interestCap.js +81 -0
  82. package/kits/hub-game/code/client/keys.js +36 -0
  83. package/kits/hub-game/code/client/labelsNear.js +205 -0
  84. package/kits/hub-game/code/client/menuIcons.js +34 -0
  85. package/kits/hub-game/code/client/pack.js +6 -2
  86. package/kits/hub-game/code/client/packFormat.js +3 -3
  87. package/kits/hub-game/code/client/rehello.js +167 -0
  88. package/kits/hub-game/code/client/shot.js +92 -0
  89. package/kits/hub-game/code/client/sound.js +63 -8
  90. package/kits/hub-game/code/client/soundscape.js +1151 -0
  91. package/kits/hub-game/code/client/soundscapeActions.js +99 -0
  92. package/kits/hub-game/code/client/soundscapeAmbience.js +453 -0
  93. package/kits/hub-game/code/client/soundscapeBaked.js +143 -0
  94. package/kits/hub-game/code/client/soundscapeBusker.js +217 -0
  95. package/kits/hub-game/code/client/soundscapeCourt.js +200 -0
  96. package/kits/hub-game/code/client/soundscapeCrowd.js +331 -0
  97. package/kits/hub-game/code/client/soundscapeCues.js +362 -0
  98. package/kits/hub-game/code/client/soundscapeMap.js +181 -0
  99. package/kits/hub-game/code/client/soundscapeMarket.js +176 -0
  100. package/kits/hub-game/code/client/soundscapeMusic.js +126 -0
  101. package/kits/hub-game/code/client/soundscapeMusicEngine.js +460 -0
  102. package/kits/hub-game/code/client/soundscapeSimlish.js +737 -0
  103. package/kits/hub-game/code/client/soundscapeSongs.js +127 -0
  104. package/kits/hub-game/code/client/soundscapeSongsRound3.js +63 -0
  105. package/kits/hub-game/code/client/soundscapeSynthesis.js +168 -0
  106. package/kits/hub-game/code/client/soundscapeUi.js +211 -0
  107. package/kits/hub-game/code/client/soundscapeVoice.js +1209 -0
  108. package/kits/hub-game/code/client/soundscapeWaves.js +206 -0
  109. package/kits/hub-game/code/client/spin.js +101 -0
  110. package/kits/hub-game/code/client/state.js +109 -1
  111. package/kits/hub-game/code/client/stuck.js +259 -0
  112. package/kits/hub-game/code/client/talk.js +538 -47
  113. package/kits/hub-game/code/client/tiers.js +516 -27
  114. package/kits/hub-game/code/client/toastBand.js +37 -0
  115. package/kits/hub-game/code/client/together.js +32 -0
  116. package/kits/hub-game/code/client/visibility.js +43 -0
  117. package/kits/hub-game/code/client/wear.js +461 -170
  118. package/kits/hub-game/code/client/yours.js +199 -0
  119. package/kits/hub-game/code/companionSpec.js +45 -0
  120. package/kits/hub-game/code/privateText.js +7 -0
  121. package/kits/hub-game/code/server/actions.js +133 -0
  122. package/kits/hub-game/code/server/actors.js +9 -1
  123. package/kits/hub-game/code/server/ask.js +155 -0
  124. package/kits/hub-game/code/server/ballot.js +539 -0
  125. package/kits/hub-game/code/server/cells.js +100 -0
  126. package/kits/hub-game/code/server/companion.js +82 -0
  127. package/kits/hub-game/code/server/cues.js +70 -0
  128. package/kits/hub-game/code/server/decor.js +269 -0
  129. package/kits/hub-game/code/server/earned.js +461 -0
  130. package/kits/hub-game/code/server/friendBests.js +166 -0
  131. package/kits/hub-game/code/server/friendsAmong.js +232 -0
  132. package/kits/hub-game/code/server/history.js +5 -0
  133. package/kits/hub-game/code/server/hub.js +1254 -50
  134. package/kits/hub-game/code/server/idle.js +30 -11
  135. package/kits/hub-game/code/server/index.js +2 -2
  136. package/kits/hub-game/code/server/labels.js +28 -2
  137. package/kits/hub-game/code/server/manifest.js +378 -7
  138. package/kits/hub-game/code/server/menu.js +133 -0
  139. package/kits/hub-game/code/server/npcs.js +830 -80
  140. package/kits/hub-game/code/server/party.js +2 -2
  141. package/kits/hub-game/code/server/players.js +22 -0
  142. package/kits/hub-game/code/server/shot.js +110 -0
  143. package/kits/hub-game/code/server/standing.js +124 -0
  144. package/kits/hub-game/code/server/vis.js +113 -0
  145. package/kits/hub-game/code/server/wear.js +12 -0
  146. package/kits/hub-game/code/server/yours.js +59 -0
  147. package/kits/hub-game/code/shared/cues.js +9 -0
  148. package/kits/hub-game/code/shared/decor.js +41 -0
  149. package/kits/hub-game/code/shared/shot.js +19 -0
  150. package/kits/hub-game/code/shared/spin.js +57 -0
  151. package/kits/hub-game/code/systems/hub.js +845 -95
  152. package/kits/hub-game/docs/content-pack.md +1 -1
  153. package/kits/hub-game/docs/contract.md +2244 -61
  154. package/kits/hub-game/docs/home-pieces.md +64 -0
  155. package/kits/hub-game/models/avatar-10.pxmodel +28 -0
  156. package/kits/hub-game/models/avatar-11.pxmodel +28 -0
  157. package/kits/hub-game/models/avatar-12.pxmodel +27 -0
  158. package/kits/hub-game/models/avatar-13.pxmodel +24 -0
  159. package/kits/hub-game/models/avatar-14.pxmodel +29 -0
  160. package/kits/hub-game/models/avatar-15.pxmodel +24 -0
  161. package/kits/hub-game/models/avatar-4.pxmodel +29 -0
  162. package/kits/hub-game/models/avatar-5.pxmodel +27 -0
  163. package/kits/hub-game/models/avatar-6.pxmodel +26 -0
  164. package/kits/hub-game/models/avatar-7.pxmodel +25 -0
  165. package/kits/hub-game/models/avatar-8.pxmodel +24 -0
  166. package/kits/hub-game/models/avatar-9.pxmodel +30 -0
  167. package/kits/hub-game/models/earned/badge-round.pxmodel +100 -0
  168. package/kits/hub-game/models/earned/badge-shield.pxmodel +117 -0
  169. package/kits/hub-game/models/earned/badge-star.pxmodel +87 -0
  170. package/kits/hub-game/models/earned/belt-plain.pxmodel +72 -0
  171. package/kits/hub-game/models/earned/held-ball.pxmodel +43 -0
  172. package/kits/hub-game/models/earned/held-lantern.pxmodel +85 -0
  173. package/kits/hub-game/models/earned/held-net.pxmodel +57 -0
  174. package/kits/hub-game/models/earned/held-trophy.pxmodel +109 -0
  175. package/kits/hub-game/models/earned/pin-round.pxmodel +62 -0
  176. package/kits/hub-game/models/earned/sash-plain.pxmodel +66 -0
  177. package/kits/hub-game/models/earned/square/belt-plain.pxmodel +104 -0
  178. package/kits/hub-game/models/earned/square/sash-plain.pxmodel +98 -0
  179. package/kits/hub-game/models/hats/bat-clip.pxmodel +206 -0
  180. package/kits/hub-game/models/hats/beekeeper.pxmodel +149 -0
  181. package/kits/hub-game/models/hats/cap.pxmodel +162 -0
  182. package/kits/hub-game/models/hats/captain.pxmodel +178 -0
  183. package/kits/hub-game/models/hats/crooked-top.pxmodel +172 -0
  184. package/kits/hub-game/models/hats/flower-crown.pxmodel +451 -0
  185. package/kits/hub-game/models/hats/foam-crown.pxmodel +179 -0
  186. package/kits/hub-game/models/hats/lantern.pxmodel +230 -0
  187. package/kits/hub-game/models/hats/laurel.pxmodel +533 -0
  188. package/kits/hub-game/models/hats/lighthouse.pxmodel +96 -0
  189. package/kits/hub-game/models/hats/sailor.pxmodel +141 -0
  190. package/kits/hub-game/models/hats/souwester.pxmodel +131 -0
  191. package/kits/hub-game/models/hats/straw.pxmodel +139 -0
  192. package/kits/hub-game/models/hats/sunflower.pxmodel +406 -0
  193. package/kits/hub-game/models/hats/sweatband.pxmodel +112 -0
  194. package/kits/hub-game/models/hats/witch.pxmodel +147 -0
  195. package/kits/hub-game/package-lock.json +2 -0
  196. package/kits/hub-game/package.json +2 -1
  197. package/kits/hub-game/scripts/check.mjs +78 -11
  198. package/kits/hub-game/scripts/companion-follower-wire.json +1 -0
  199. package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +121 -0
  200. package/kits/hub-game/scripts/fixtures/decor-keyless.json +293 -0
  201. package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +23 -0
  202. package/kits/hub-game/scripts/fixtures/fake-dom.mjs +107 -0
  203. package/kits/hub-game/scripts/fixtures/interest-legacy.json +385 -0
  204. package/kits/hub-game/scripts/fixtures/npc-notes-v1.77.jsonl +4 -0
  205. package/kits/hub-game/scripts/fixtures/vis-shared-wire.json +1 -0
  206. package/kits/hub-game/scripts/gen-avatars.mjs +933 -16
  207. package/kits/hub-game/scripts/gen-earned.mjs +285 -0
  208. package/kits/hub-game/scripts/gen-hats.mjs +827 -0
  209. package/kits/hub-game/scripts/grab.before-orbit.mjs +400 -0
  210. package/kits/hub-game/scripts/soundscape-wave-analysis.mjs +125 -0
  211. package/kits/hub-game/scripts/test-actions-client.mjs +488 -0
  212. package/kits/hub-game/scripts/test-actions.mjs +298 -0
  213. package/kits/hub-game/scripts/test-actor-budget.mjs +44 -0
  214. package/kits/hub-game/scripts/test-actors.mjs +19 -17
  215. package/kits/hub-game/scripts/test-ask-client.mjs +358 -0
  216. package/kits/hub-game/scripts/test-ask.mjs +269 -0
  217. package/kits/hub-game/scripts/test-attention.mjs +10 -1
  218. package/kits/hub-game/scripts/test-avatar-cap.mjs +379 -0
  219. package/kits/hub-game/scripts/test-avatar-colors.mjs +72 -0
  220. package/kits/hub-game/scripts/test-avatar-models.mjs +181 -0
  221. package/kits/hub-game/scripts/test-avatar-share.mjs +318 -0
  222. package/kits/hub-game/scripts/test-avatar-wire.mjs +753 -0
  223. package/kits/hub-game/scripts/test-avatar.mjs +540 -7
  224. package/kits/hub-game/scripts/test-ballot.mjs +1001 -0
  225. package/kits/hub-game/scripts/test-build.mjs +31 -0
  226. package/kits/hub-game/scripts/test-cells.mjs +71 -0
  227. package/kits/hub-game/scripts/test-chat.mjs +662 -0
  228. package/kits/hub-game/scripts/test-classic.mjs +2 -0
  229. package/kits/hub-game/scripts/test-companion-chat.mjs +198 -0
  230. package/kits/hub-game/scripts/test-companion-client.mjs +1167 -0
  231. package/kits/hub-game/scripts/test-companion.mjs +259 -0
  232. package/kits/hub-game/scripts/test-decor-client.mjs +303 -0
  233. package/kits/hub-game/scripts/test-decor.mjs +457 -0
  234. package/kits/hub-game/scripts/test-earned-client.mjs +459 -0
  235. package/kits/hub-game/scripts/test-earned.mjs +1194 -0
  236. package/kits/hub-game/scripts/test-emote-bubble.mjs +110 -0
  237. package/kits/hub-game/scripts/test-friend-bests.mjs +435 -0
  238. package/kits/hub-game/scripts/test-grab-orbit.mjs +918 -0
  239. package/kits/hub-game/scripts/test-grab.mjs +7 -0
  240. package/kits/hub-game/scripts/test-hats.mjs +422 -168
  241. package/kits/hub-game/scripts/test-hub-leaving.mjs +203 -0
  242. package/kits/hub-game/scripts/test-hub-ops.mjs +439 -2
  243. package/kits/hub-game/scripts/test-hub-trip.mjs +716 -2
  244. package/kits/hub-game/scripts/test-hud-clear.mjs +328 -4
  245. package/kits/hub-game/scripts/test-idle.mjs +361 -1
  246. package/kits/hub-game/scripts/test-interest-cap.mjs +36 -0
  247. package/kits/hub-game/scripts/test-interest-cells.mjs +493 -0
  248. package/kits/hub-game/scripts/test-interest-client.mjs +118 -0
  249. package/kits/hub-game/scripts/test-keys.mjs +46 -1
  250. package/kits/hub-game/scripts/test-labels.mjs +596 -0
  251. package/kits/hub-game/scripts/test-manifest.mjs +207 -0
  252. package/kits/hub-game/scripts/test-menu-client.mjs +480 -0
  253. package/kits/hub-game/scripts/test-menu.mjs +296 -0
  254. package/kits/hub-game/scripts/test-npcs.mjs +1718 -12
  255. package/kits/hub-game/scripts/test-object-entry.mjs +76 -0
  256. package/kits/hub-game/scripts/test-pack.mjs +7 -0
  257. package/kits/hub-game/scripts/test-picker.mjs +314 -0
  258. package/kits/hub-game/scripts/test-rehello.mjs +1039 -0
  259. package/kits/hub-game/scripts/test-relations-among.mjs +222 -0
  260. package/kits/hub-game/scripts/test-relations-refresh.mjs +188 -0
  261. package/kits/hub-game/scripts/test-shot.mjs +756 -0
  262. package/kits/hub-game/scripts/test-soundscape.mjs +5432 -0
  263. package/kits/hub-game/scripts/test-spin.mjs +314 -0
  264. package/kits/hub-game/scripts/test-standing.mjs +416 -0
  265. package/kits/hub-game/scripts/test-stuck.mjs +1903 -0
  266. package/kits/hub-game/scripts/test-tier-cells.mjs +706 -0
  267. package/kits/hub-game/scripts/test-tiers-render.mjs +339 -0
  268. package/kits/hub-game/scripts/test-tiers.mjs +477 -2
  269. package/kits/hub-game/scripts/test-toast-band.mjs +61 -0
  270. package/kits/hub-game/scripts/test-try-on.mjs +22 -22
  271. package/kits/hub-game/scripts/test-vis.mjs +343 -0
  272. package/kits/hub-game/scripts/test-visibility.mjs +134 -0
  273. package/kits/hub-game/scripts/test-yours-chrome.mjs +166 -0
  274. package/kits/hub-game/scripts/test-yours.mjs +372 -0
  275. package/kits/multiplayer-3d/CLAUDE.md +50 -0
  276. package/kits/multiplayer-3d/castle.json +5 -5
  277. package/kits/multiplayer-3d/code/client/avatars.js +7 -0
  278. package/kits/multiplayer-3d/code/client/gait.js +65 -0
  279. package/kits/multiplayer-3d/code/client/nameTags.js +59 -4
  280. package/kits/multiplayer-3d/code/options.js +5 -0
  281. package/kits/multiplayer-3d/code/server/ownership.js +10 -2
  282. package/kits/multiplayer-3d/code/server/sceneBodies.js +12 -0
  283. package/kits/multiplayer-3d/code/server/world.js +7 -0
  284. package/kits/multiplayer-3d/code/systems/multiplayer.js +74 -4
  285. package/kits/multiplayer-3d/package.json +2 -1
  286. package/kits/multiplayer-3d/scripts/fixtures/README.md +11 -0
  287. package/kits/multiplayer-3d/scripts/fixtures/ownership-legacy.json +2 -0
  288. package/kits/multiplayer-3d/scripts/ownership-harness.mjs +102 -0
  289. package/kits/multiplayer-3d/scripts/ownership-loader.mjs +46 -0
  290. package/kits/multiplayer-3d/scripts/ownership-worker.mjs +15 -0
  291. package/kits/multiplayer-3d/scripts/record-ownership-session.mjs +98 -0
  292. package/kits/multiplayer-3d/scripts/test-eligible-claims.mjs +167 -0
  293. package/kits/multiplayer-3d/scripts/test-own-name-tag.mjs +247 -0
  294. package/kits/physics-2d/CLAUDE.md +9 -0
  295. package/kits/physics-2d/castle.json +2 -2
  296. package/kits/physics-2d/engine/scene.js +253 -1
  297. package/kits/physics-2d/engine/skyKey.js +129 -0
  298. package/kits/physics-2d/engine/stillClock.js +106 -0
  299. package/kits/physics-2d/engine/updateBudget.js +21 -0
  300. package/kits/physics-2d/scripts/test-skip-unchanged.mjs +326 -1
  301. package/kits/physics-3d/CLAUDE.md +1169 -30
  302. package/kits/physics-3d/behaviors/Player.jsx +629 -72
  303. package/kits/physics-3d/castle.json +3 -3
  304. package/kits/physics-3d/docs/pxmodel-format.md +8 -0
  305. package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +69 -13
  306. package/kits/physics-3d/engine3d/actornode.js +86 -0
  307. package/kits/physics-3d/engine3d/animationBudget.js +23 -0
  308. package/kits/physics-3d/engine3d/editorWorld.js +6 -0
  309. package/kits/physics-3d/engine3d/emptynodes.js +232 -0
  310. package/kits/physics-3d/engine3d/framecap.js +96 -0
  311. package/kits/physics-3d/engine3d/gait.js +118 -0
  312. package/kits/physics-3d/engine3d/kithooks.js +47 -0
  313. package/kits/physics-3d/engine3d/look.js +507 -48
  314. package/kits/physics-3d/engine3d/lookbake.js +208 -0
  315. package/kits/physics-3d/engine3d/materialpresets.js +2 -0
  316. package/kits/physics-3d/engine3d/motion.js +39 -10
  317. package/kits/physics-3d/engine3d/nearshadows.js +37 -19
  318. package/kits/physics-3d/engine3d/optimize.js +9 -5
  319. package/kits/physics-3d/engine3d/orbitinput.js +487 -9
  320. package/kits/physics-3d/engine3d/orbitlens.js +48 -0
  321. package/kits/physics-3d/engine3d/ownmodel.js +213 -0
  322. package/kits/physics-3d/engine3d/pxmodel.js +42 -11
  323. package/kits/physics-3d/engine3d/shadowfade.js +882 -0
  324. package/kits/physics-3d/engine3d/sky.js +547 -0
  325. package/kits/physics-3d/engine3d/skylife.js +306 -0
  326. package/kits/physics-3d/engine3d/unchanged.js +11 -0
  327. package/kits/physics-3d/engine3d/viewrange.js +52 -0
  328. package/kits/physics-3d/engine3d/world3d.js +796 -69
  329. package/kits/physics-3d/main.jsx +5 -0
  330. package/kits/physics-3d/package.json +1 -1
  331. package/kits/physics-3d/scripts/look-baseline.mjs +155 -0
  332. package/kits/physics-3d/scripts/test-camera-orbit.mjs +2563 -80
  333. package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +1 -1
  334. package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +435 -0
  335. package/kits/physics-3d/scripts/test-frame-cap.mjs +452 -0
  336. package/kits/physics-3d/scripts/test-gait.mjs +387 -0
  337. package/kits/physics-3d/scripts/test-look-bake.mjs +1056 -0
  338. package/kits/physics-3d/scripts/test-model-parse-cache.mjs +92 -0
  339. package/kits/physics-3d/scripts/test-near-shadows.mjs +3 -0
  340. package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1920 -0
  341. package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +545 -0
  342. package/kits/physics-3d/scripts/test-orbit-shot.mjs +583 -0
  343. package/kits/physics-3d/scripts/test-orbit-view.mjs +230 -0
  344. package/kits/physics-3d/scripts/test-skip-empty-nodes.mjs +845 -0
  345. package/kits/physics-3d/scripts/test-sky.mjs +2470 -0
  346. package/kits/physics-3d/scripts/test-static-actors.mjs +8 -1
  347. package/kits/physics-3d/scripts/test-static-scenery.mjs +2171 -0
  348. package/kits/physics-3d/scripts/test-steady-hover.mjs +2 -0
  349. package/kits/physics-3d/scripts/test-view-range.mjs +260 -0
  350. package/kits/physics-3d/systems/physics3d.js +383 -6
  351. package/kits/real-time/castle.json +2 -2
  352. package/kits/real-time/code/server/gameHooks.js +7 -0
  353. package/kits/real-time/code/server/session.js +97 -19
  354. package/package.json +2 -2
  355. package/dist/shell/assets/index-Cf61cNfT.css +0 -1
@@ -1,3 +1,5 @@
1
+ import { makeVisibility } from '../client/visibility.js';
2
+ import { makeActorBudget } from '../client/actorBudget.js';
1
3
  // The hub system: the door, and everything a place draws that a game cannot.
2
4
  // It runs after the engine's behaviors every frame and owns the trip between
3
5
  // places -- the door animation, the scene swap and session switch under its
@@ -8,7 +10,8 @@
8
10
  // the place's loose objects where it offers that (`client/grab.js`), and idle
9
11
  // play -- emotes, seats and the place's sounds -- where it offers that
10
12
  // (`client/idle.js`, `client/sound.js`), and, in a deck that asks for it, a
11
- // cheaper picture on a slow device (`client/tiers.js`).
13
+ // cheaper picture on a slow device (`client/tiers.js`) and the sounds the kit
14
+ // makes itself (`client/soundscape.js`).
12
15
  //
13
16
  // One engine, one iframe (HUB.md decision 2): going through a door unloads this
14
17
  // place's scene, loads the next one's (`scene.requestedScene`), and moves the
@@ -24,27 +27,41 @@
24
27
 
25
28
  import * as castleSdk from 'castle-web-sdk';
26
29
  import { attend, fadeNames, makeAttention } from '../client/attention.js';
30
+ import { chromeItem, labelBox, near, nearFor } from '../client/labelsNear.js';
27
31
  import { doorPoint } from '../client/doorFrame.js';
28
32
  import * as Avatar from '../client/avatar.js';
33
+ import * as Rehello from '../client/rehello.js';
34
+ import * as AvatarCap from '../client/avatarCap.js';
35
+ import * as AvatarShare from '../client/avatarShare.js';
36
+ import { makeYours } from '../client/yours.js';
29
37
  import * as Cabinets from '../client/cabinets.js';
30
38
  import { CHAT_BUBBLE_MS, makeChat } from '../client/chat.js';
31
39
  import { makeChrome } from '../client/chrome.js';
32
40
  import * as Packs from '../client/pack.js';
33
41
  import * as Hub from '../client/state.js';
42
+ import { clearShot } from '../client/shot.js';
34
43
  import { makeGrab } from '../client/grab.js';
35
44
  import { makeIdle } from '../client/idle.js';
45
+ import { makeDecor } from '../client/decor.js';
36
46
  import { makeSay, REACTIONS } from '../client/say.js';
47
+ import { cardFor, forget as forgetBallot, held as ballotHeld, makeBallot } from '../client/ballot.js';
37
48
  import { makeSound } from '../client/sound.js';
49
+ import { makeSoundscape } from '../client/soundscape.js';
50
+ import { addSpinner, findSpinners, spinFrame } from '../client/spin.js';
51
+ import { makeStuck, resetStuck, STUCK_EVERY_MS, stuckDone, stuckFrame, stuckText, stuckWhere, walkInput } from '../client/stuck.js';
38
52
  import { makeTalk } from '../client/talk.js';
53
+ import { makeInterestCap } from '../client/interestCap.js';
39
54
  import { makeTiers } from '../client/tiers.js';
40
- import { makeTogether, pointerAt } from '../client/together.js';
41
- import { makeWear } from '../client/wear.js';
55
+ import { goalPointers, goalText, makeTogether, pointerAt } from '../client/together.js';
56
+ import { makeEarned, makeWear } from '../client/wear.js';
57
+ import { makeCompanion } from '../client/companion.js';
42
58
 
43
59
  // The door's three beats, in milliseconds: the door opens and the camera goes
44
60
  // through it while the cover comes down; the swap and join happen under the
45
61
  // cover; the cover lifts as the camera pulls back from the arrival.
46
62
  const OPEN_MS = 650;
47
63
  const REVEAL_MS = 700;
64
+ const LEAVING_MS = 2800;
48
65
  const LOADING_LIMIT_MS = 15000;
49
66
  // How long the cover waits for the place to say where it put this player
50
67
  // after the session has placed them, before it lifts anyway.
@@ -186,6 +203,7 @@ class HubSystem {
186
203
  this.trip = null;
187
204
  this.pendingEnd = null;
188
205
  this.endSession = null;
206
+ this.endLeaving = null;
189
207
  this.helloNet = null;
190
208
  this.helloAvatar = null;
191
209
  this.scenePath = null;
@@ -194,8 +212,14 @@ class HubSystem {
194
212
  this.stash = new Map();
195
213
  this.tinted = new Map();
196
214
  this.spawnedHere = new Set();
215
+ // Turning displays (v1.55, `client/spin.js`): the scene data last looked
216
+ // through for `HubSpin`, and its turners -- null where nothing turns.
217
+ this.spinData = null;
218
+ this.spin = null;
197
219
  this.wear = makeWear();
220
+ this.earned = makeEarned();
198
221
  this.toast = { text: '', until: 0 };
222
+ this.leavingToast = null;
199
223
  this.stats = statsWanted();
200
224
  this.frames = 0;
201
225
  this.fpsAt = 0;
@@ -209,6 +233,8 @@ class HubSystem {
209
233
  // People list marks them and points the way to them).
210
234
  this.friendsAll = null;
211
235
  this.friendsAt = -Infinity;
236
+ this.friendsGameAt = -Infinity;
237
+ this.friendsGameWarm = false;
212
238
  this.friendsAsking = false;
213
239
  this.friendsOff = false;
214
240
  // Whether this host runs the hub (it answered Hub.friends), so takes
@@ -246,36 +272,42 @@ class HubSystem {
246
272
  this.partyAccepted = null;
247
273
  }
248
274
 
249
- // Other players' names in a town: near ones only, and smaller
250
- // (`attention.js`). After the multiplayer kit has placed them this frame.
275
+ // Other players' names in a town: near ones only, and smaller; never the
276
+ // player's own in a place (`attention.js`). After the multiplayer kit has placed them this frame.
251
277
  fadeNames(scene) {
252
278
  const place = Hub.hub.place;
253
279
  const town = Boolean(place && !place.result && !this.trip);
254
- fadeNames(scene.multiplayer, scene.actorWith('Player')?.components.Transform, town, this.namesTouched);
280
+ fadeNames(scene.multiplayer, scene.actorWith('Player')?.components.Transform, town, this.namesTouched, Boolean(place));
255
281
  }
256
282
 
257
- afterBehaviors(scene) {
283
+ afterBehaviors(scene, dt) {
258
284
  const mp = scene.multiplayer;
259
285
  if (!mp) {
260
286
  return;
261
287
  }
262
288
  const now = performance.now();
263
289
  this.chrome ??= makeChrome({
264
- onBack: () => this.back(scene),
290
+ onBack: () => this.backFromControl(scene),
265
291
  onAvatar: (i) => Avatar.choose(scene, i),
292
+ onColor: (color) => Avatar.chooseColor(scene, color),
266
293
  avatarCount: Avatar.AVATARS,
267
294
  onPerson: (person, action) => this.join(this.scene, person, action),
268
295
  onJumpDoor: (door) => this.goDoor(this.scene, door),
296
+ onHeart: (door) => this.yours?.toggle(door),
269
297
  onAsk: (ask, yes) => this.answer(this.scene, ask, yes),
270
298
  onLeaveParty: () => this.scene?.multiplayer?.net?.send({ k: 'hub-party', op: 'leave' }),
271
299
  onReportChat: (line) => this.reportChat(line),
272
300
  onReport: (person) => this.report(person),
301
+ ...(Hub.deck.soundscape?.ui === true ? { onChip: () => this.soundscape?.cue('tap', performance.now()) } : {}),
273
302
  });
274
303
  Avatar.load(scene);
275
304
  this.talk ??= makeTalk(this.chrome);
276
305
  this.grab ??= makeGrab(this.chrome);
277
306
  this.idle ??= makeIdle(this.chrome);
278
307
  this.sound ??= makeSound();
308
+ if (Hub.deck.soundscape && !this.soundscape) {
309
+ this.hearPlace();
310
+ }
279
311
  if (!this.sayHooked) {
280
312
  this.sayHooked = true;
281
313
  this.chrome.onSay?.((what) => this.saying(what));
@@ -285,13 +317,14 @@ class HubSystem {
285
317
  // answered the way the kit's own is: back through the door (contract §5).
286
318
  if (!this.backHooked && typeof castleSdk.Hub?.onBack === 'function') {
287
319
  this.backHooked = true;
288
- castleSdk.Hub.onBack(() => this.back(this.scene));
320
+ castleSdk.Hub.onBack(() => this.backFromControl(this.scene));
289
321
  }
290
322
  const per = (scene.persistent ??= {});
291
323
  per.hubTickets ??= [];
292
324
  this.keepResident(scene, per.hubTickets);
293
325
  // A handle for test drivers and phone measurements.
294
- globalThis.__hub = { scene, system: this, state: Hub.hub };
326
+ globalThis.__hub = { scene, system: this, state: Hub.hub, ...(Hub.deck.build ? { build: Hub.deck.build } : {}) };
327
+ Object.defineProperty(globalThis.__hub, 'avatarPlatform', { enumerable: true, get: Avatar.diagnostics });
295
328
  globalThis.__hubPacks ??= () => Packs.cachedPacks().length;
296
329
 
297
330
  if (sceneKeyOf(scene) !== this.sceneKey) {
@@ -302,8 +335,13 @@ class HubSystem {
302
335
  this.applyTune(local);
303
336
  this.watchSession(scene, mp);
304
337
  this.sayHello(scene, mp);
338
+ if (Hub.hub.place?.visibility === true || this.visibility) {
339
+ this.visibility ??= makeVisibility();
340
+ this.visibility.sync(mp.net, this.sceneKey, Hub.hub.place?.visibility === true && !this.trip);
341
+ }
305
342
  this.followPlace(scene);
306
343
  this.holdFall(scene, local);
344
+ this.turnSpinners(scene, dt);
307
345
  this.applySpawns(scene);
308
346
  this.applyTints(scene);
309
347
  // Visibility is applied once more after every other system: the
@@ -313,42 +351,185 @@ class HubSystem {
313
351
  this.lateFor = scene;
314
352
  this.registerLate(scene);
315
353
  }
354
+ this.registerInterest(scene);
316
355
  this.applyVisibility(scene);
317
356
  this.applyWear(scene);
357
+ // Different characters draw from shared materials (`avatarShare.js`).
358
+ AvatarShare.share(scene, [local?.id, ...(mp?.avatars?.actors?.values() ?? [])]);
318
359
  this.adoptLate(scene);
319
360
  this.runCommands(scene, now);
320
361
  this.askFriends(scene, mp, now);
321
362
  this.together.frame(mp, this.friendsAll, !this.trip && this.pendingEnd === null, now, this.chrome.peopleOpen?.() === true);
322
363
 
364
+ if (!Hub.hub.place?.decor && this.decor) {
365
+ this.decor.dispose();
366
+ this.decor = null;
367
+ }
368
+ if (Hub.hub.place?.decor && !this.decor) {
369
+ this.decor = makeDecor(this.chrome);
370
+ }
371
+ this.decor?.frame(scene, mp, local, !this.trip && this.pendingEnd === null && !this.talk.talking());
372
+ const decorating = this.decor?.opened() === true;
323
373
  this.stepEnd(scene, mp, now);
324
374
  const held = Hub.hub.held.has(mp.net?.selfId?.());
375
+ // v1.68, rule B (`client/ballot.js`): the choice card runs only while
376
+ // its one gate holds a card (`ballotHeld`), which a place without
377
+ // `ballot` never does; when it lets go (another connection), the sheet
378
+ // goes, once. While a card is up it holds the bottom of the screen, and
379
+ // what it would cover (emotes, Sit, Say, the dock, the feed) waits.
380
+ // `cardFor` lets go of a card of another connection, so the gate is read
381
+ // again after it, before anything is made or drawn.
382
+ const card = ballotHeld ? cardFor(mp.net ?? null) : null;
383
+ if (ballotHeld) {
384
+ // A chip tap sounds as the chrome's do, only with UI cues.
385
+ this.ballot ??= makeBallot({
386
+ send: (ids) => this.scene?.multiplayer?.net?.send({ k: 'hub-ballot', ...ids }),
387
+ ...(Hub.deck.soundscape?.ui === true ? { onChip: () => this.soundscape?.cue('tap', performance.now()) } : {}),
388
+ });
389
+ this.carded = card !== null && !this.trip;
390
+ } else if (this.ballot) {
391
+ this.ballot.dispose();
392
+ this.ballot = null;
393
+ this.carded = false;
394
+ }
395
+ // Resolve incoming conversations before a pending prompt can take focus.
396
+ // An already-open prompt yields as a cancel, before NPC chrome opens.
397
+ // NPC events belong to this client only, even for a shared body.
398
+ if (Hub.hub.place?.ask === true && this.askInput &&
399
+ (card !== null || this.talk.talking() || Hub.hub.npcEvents.some((msg) => msg.k === 'hub-npc' && msg.open))) {
400
+ this.chrome.cancelTextAsk();
401
+ }
402
+ if (this.menuInput && (card !== null || this.talk.talking() ||
403
+ (Hub.hub.place?.ask === true && this.chrome.textAskPending(Hub.hub.ask)) ||
404
+ Hub.hub.npcEvents.some((msg) => msg.k === 'hub-npc' && msg.open))) {
405
+ this.chrome.cancelMenu();
406
+ }
325
407
  this.talk.frame(scene, mp, !this.trip && this.pendingEnd === null);
408
+ if (Hub.hub.place?.ask === true) {
409
+ this.askDrawn = true;
410
+ Hub.hub.askClose ??= () => this.clearTextAsk();
411
+ const canAsk = !this.trip && this.pendingEnd === null && !decorating && card === null && !this.talk.talking();
412
+ this.chrome.setTextAsk(canAsk ? Hub.hub.ask : null,
413
+ (id, n, text) => mp.net?.send({ k: 'hub-answer', id, n, text }),
414
+ (open) => {
415
+ if (open) {
416
+ this.askInput = holdAskInput(scene);
417
+ } else if (this.askInput) {
418
+ this.askInput.release();
419
+ delete this.askInput;
420
+ }
421
+ });
422
+ } else if (this.askDrawn) {
423
+ this.clearTextAsk();
424
+ }
425
+ if (Hub.hub.place?.menu === true) {
426
+ this.menuDrawn = true;
427
+ Hub.hub.menuClose ??= () => this.clearMenu();
428
+ const canMenu = !this.trip && this.pendingEnd === null && !decorating && card === null && !this.talk.talking() && !this.askInput;
429
+ this.chrome.setMenu(canMenu ? Hub.hub.menu : null,
430
+ (id, n) => mp.net?.send({ k: 'hub-menu-pick', id, n }),
431
+ (open) => {
432
+ if (open) {
433
+ this.menuInput = holdAskInput(scene);
434
+ } else if (this.menuInput) {
435
+ this.menuInput.release();
436
+ delete this.menuInput;
437
+ }
438
+ });
439
+ } else if (this.menuDrawn) {
440
+ this.clearMenu();
441
+ }
442
+ if (Hub.hub.menu?.spec?.face !== undefined && !held &&
443
+ !Object.hasOwn(Hub.hub.seated, mp.net?.selfId?.()) && scene.cameraControl === 'orbit') {
444
+ const face = this.chrome.menuFace();
445
+ if (Number.isFinite(face) && local?.components.Transform) {
446
+ // Player keeps radians; normal move reports pack the visible yaw from degrees.
447
+ local.runtime.facing = face * Math.PI / 180;
448
+ local.components.Transform.rotationY = face;
449
+ }
450
+ }
326
451
  // Idle play (v1.6): before input is locked, since a sitter's move is
327
452
  // what gets them up (a seat is a hold).
328
- this.idle.frame(scene, mp, local, !this.trip && this.pendingEnd === null && !this.talk.talking(), this.sceneKey);
453
+ this.idle.frame(scene, mp, local, !this.trip && this.pendingEnd === null && !this.talk.talking() && !decorating && !this.carded, this.sceneKey);
329
454
  this.idle.draw(scene, local);
330
- this.sound.frame(scene, local, !this.trip);
331
- if (this.trip || held || this.talk.typing() || this.chrome.chatFocused?.()) {
455
+ // The soundscape, only in a deck with `hub.soundscape`: its sound control
456
+ // also says how loud the place's own files play. Without the key the
457
+ // place's sounds are asked for exactly as they always were.
458
+ if (Hub.deck.soundscape) {
459
+ this.chrome.soundControl?.(!this.trip, this.soundscape.settings(), this.soundHandlers);
460
+ } else {
461
+ this.sound.frame(scene, local, !this.trip);
462
+ }
463
+ if (this.trip || held || this.talk.typing() || this.chrome.chatFocused?.() || decorating || this.askInput || this.menuInput) {
332
464
  lockInput(scene);
333
465
  // Under the engine's orbit camera key the player's drags and wheel do
334
466
  // not move the trip's camera, nor queue up for after it.
335
- if (this.trip && scene.cameraControl === 'orbit') {
467
+ if ((this.trip || decorating || this.askInput || this.menuInput) && scene.cameraControl === 'orbit') {
336
468
  scene.lookInput?.lock?.();
337
469
  }
338
470
  }
339
471
  // Grabbing and throwing (v1.3), in a place that offers it: after this
340
472
  // frame's physics step, before the multiplayer kit reports what it owns.
341
- this.grab.frame(scene, mp, local, !this.trip && this.pendingEnd === null && !this.talk.talking());
473
+ this.grab.frame(scene, mp, local, !this.trip && this.pendingEnd === null && !this.talk.talking() && !decorating);
342
474
  if (this.trip) {
343
475
  this.stepTrip(scene, mp, local, now);
344
476
  } else if (!Hub.hub.faced) {
345
477
  // A join that was not a trip (the first one) faces the arrival too.
346
478
  this.faceArrival(scene);
347
479
  }
480
+ if (Hub.hub.place?.companion === true) {
481
+ this.companion ??= makeCompanion({ idle: Hub.deck.companionIdle === true });
482
+ const cam = scene.three?.camera;
483
+ const view = { w: window.innerWidth, h: window.innerHeight };
484
+ const framing = cam ? {
485
+ camera: { position: cam.position, forward: cam.getWorldDirection(cam.position.clone()) },
486
+ panel: this.chrome.talkRect?.(), view,
487
+ project: (at) => project(cam, at.x, at.y, at.z, view),
488
+ } : null;
489
+ const chat = Hub.hub.place?.companionChat && this.talk.talkingToCompanion?.() ? framing ?? {} : null;
490
+ const activity = { ...framing, chatting: this.talk.talking() };
491
+ const busy = Boolean(this.talk.talkingWith()?.startsWith('companion:') || now < (this.companionTappedUntil ?? -Infinity));
492
+ this.companion.frame(scene, local, Hub.hub, dt, now, !this.trip && this.pendingEnd === null, chat, busy, activity);
493
+ } else if (this.companion) {
494
+ this.companion.dispose();
495
+ delete this.companion;
496
+ delete this.companionTappedUntil;
497
+ }
348
498
  this.drawChrome(scene, local, now);
499
+ if (Hub.hub.place?.actions === true) {
500
+ this.actionsDrawn = true;
501
+ this.chrome.setActions(Hub.hub.actions?.items ?? null, (id, n) => mp.net?.send({ k: 'hub-action', id, n }), !this.trip && this.pendingEnd === null && !this.talk.talking() && !decorating && !this.carded && !this.askInput && !this.menuInput, Hub.hub.actions?.n);
502
+ } else if (this.actionsDrawn) {
503
+ this.chrome.clearActions();
504
+ delete this.actionsDrawn;
505
+ }
506
+ // v1.68: the choice card, only where it was made above.
507
+ if (this.ballot) {
508
+ const box = this.carded ? this.chrome.hudClearBox?.() : null;
509
+ this.ballot.frame(this.carded ? cardFor(mp.net ?? null) : null, Hub.hub.place?.ballot?.lines ?? [], mp.net?.selfId?.() ?? null, Hub.simNow(), box ? box.bottom : 0);
510
+ }
349
511
  this.measure(scene, mp, now);
350
512
  }
351
513
 
514
+ // The soundscape (`client/soundscape.js`), only in a deck whose castle.json
515
+ // asks (`hub.soundscape`): without it this is never called, and no context,
516
+ // listener, storage read or chrome of it is made. Made with the chrome, and
517
+ // put away with it (`dispose`): an NPC's line in the talk panel is heard as
518
+ // the panel is given it, by this player alone.
519
+ hearPlace() {
520
+ const soundscape = makeSoundscape(Hub.deck.soundscape, { onHide: () => this.sound?.hush(), isOn: () => !this.trip, loudestLoop: () => this.sound?.loudestLoop() ?? 0 });
521
+ this.soundscape = soundscape;
522
+ this.sound?.filterEvents?.(soundscape.live);
523
+ this.soundHandlers = { onVolume: (volume) => soundscape.setVolume(volume), onMuted: (muted) => soundscape.setMuted(muted) };
524
+ const talkLine = this.chrome.talkLine;
525
+ this.chrome.talkLine = (who, text, note) => {
526
+ talkLine(who, text, note);
527
+ if (who === 'them') {
528
+ soundscape.say(this.scene, this.talk?.talkingWith() ?? null, text, performance.now());
529
+ }
530
+ };
531
+ }
532
+
352
533
  // Device tiers (`client/tiers.js`), only in a deck whose castle.json asks
353
534
  // (`hub.tiers`): without it this is never called, nothing of theirs is made
354
535
  // or run, and the place is drawn and behaves exactly as it did. A frame
@@ -369,9 +550,40 @@ class HubSystem {
369
550
  }
370
551
  const counts = !this.trip && this.pendingEnd === null && mp?.placed?.() === true;
371
552
  this.tiers.frame(scene, counts, now);
553
+ if (Hub.deck.lowActorBudget) {
554
+ this.actorBudget ??= makeActorBudget();
555
+ this.actorBudget(scene, this.tiers.current() === 'low' && !scene.content, now);
556
+ }
557
+ if (Hub.hub.place?.interest === 'cells') {
558
+ this.interestTier = this.tiers.current();
559
+ }
372
560
  globalThis.__hub.tier = this.tiers.handle;
373
561
  }
374
562
 
563
+ interestFrame(scene, now) {
564
+ if (Hub.hub.place?.interest !== 'cells' || !scene.multiplayer?.net) {
565
+ this.interestCap = null;
566
+ return;
567
+ }
568
+ if (!this.interestCap || this.interestPlace !== Hub.hub.place) {
569
+ this.interestCap = makeInterestCap(Hub.hub.place.nearestPlayers ?? 1000);
570
+ this.interestPlace = Hub.hub.place;
571
+ }
572
+ const counts = !this.trip && this.pendingEnd === null && scene.multiplayer.placed?.() === true;
573
+ const cap = this.interestCap.frame(now, this.interestTier ?? 'high', counts);
574
+ if (cap !== null) {
575
+ scene.multiplayer.net.send({ k: 'hub-cap', n: cap });
576
+ }
577
+ }
578
+
579
+ registerInterest(scene) {
580
+ if (Hub.hub.place?.interest !== 'cells' || typeof scene.registerSystem !== 'function' || this.interestScenes?.has(scene)) {
581
+ return;
582
+ }
583
+ (this.interestScenes ??= new WeakSet()).add(scene);
584
+ scene.registerSystem({ afterBehaviors: (s) => this.interestFrame(s, performance.now()) });
585
+ }
586
+
375
587
  // The systems that run after every other one, registered once per runtime.
376
588
  registerLate(scene) {
377
589
  scene.registerSystem({
@@ -387,6 +599,34 @@ class HubSystem {
387
599
  if (Hub.deck.tiers) {
388
600
  scene.registerSystem({ afterBehaviors: (s) => this.deviceTier(s, s.multiplayer, performance.now()) });
389
601
  }
602
+ // Complete sound recovery after every system, including the transport
603
+ // drain. A keyless deck registers no sound completion hook.
604
+ if (Hub.deck.soundscape) {
605
+ // Resident scenes can be entered again. Their existing hook already
606
+ // refers to this system; registering twice would count one frame twice.
607
+ if (this.soundScenes?.has(scene)) {
608
+ return;
609
+ }
610
+ (this.soundScenes ??= new WeakSet()).add(scene);
611
+ scene.registerSystem({ afterBehaviors: (s) => {
612
+ const local = s.actorWith('Player');
613
+ const now = performance.now();
614
+ // A drain after the hub frame can still hand the panel a reply. Do
615
+ // that before recovery completes, so a quiet reply cannot escape
616
+ // into the next live frame's panel queue.
617
+ if (Hub.hub.npcEvents.length) {
618
+ this.talk?.frame(s, s.multiplayer, !this.trip && this.pendingEnd === null);
619
+ }
620
+ if (this.soundscape) {
621
+ const level = this.soundscape.frame(s, s.multiplayer, local, !this.trip, this.talk?.talkingWith() ?? null, now);
622
+ if (Hub.hub.npcEvents.length) {
623
+ this.talk?.frame(s, s.multiplayer, !this.trip && this.pendingEnd === null);
624
+ }
625
+ this.sound.frame(s, local, !this.trip, level);
626
+ this.soundscape.completeFrame(s, s.multiplayer, local, !this.trip, this.talk?.talkingWith() ?? null, now);
627
+ }
628
+ } });
629
+ }
390
630
  }
391
631
 
392
632
  // The places this player will walk back into stay built while they are away
@@ -428,15 +668,46 @@ class HubSystem {
428
668
  scene.physics3d?.setVelocity?.(local, { x: 0, y: 0, z: 0 });
429
669
  }
430
670
 
671
+ clearMenu() {
672
+ if (this.menuDrawn) {
673
+ this.chrome?.clearMenu();
674
+ delete this.menuDrawn;
675
+ }
676
+ delete Hub.hub.menuClose;
677
+ }
678
+
679
+ clearTextAsk() {
680
+ if (this.askDrawn) {
681
+ this.chrome?.clearTextAsk();
682
+ delete this.askDrawn;
683
+ }
684
+ delete Hub.hub.askClose;
685
+ }
686
+
431
687
  enterScene(scene) {
688
+ if (this.sceneKey !== null && this.sceneKey !== undefined && this.menuDrawn) {
689
+ this.clearMenu();
690
+ delete Hub.hub.menu;
691
+ }
692
+ if (this.sceneKey !== null && this.sceneKey !== undefined && this.askDrawn) {
693
+ this.clearTextAsk();
694
+ delete Hub.hub.ask;
695
+ }
696
+ clearShot();
432
697
  this.scenePath = scene.currentScenePath;
433
698
  this.sceneKey = sceneKeyOf(scene);
434
699
  this.doorBase.clear();
435
700
  this.stash.clear();
436
701
  this.tinted.clear();
437
702
  this.spawnedHere.clear();
703
+ this.companion?.clear();
438
704
  this.wear.clear(scene);
705
+ this.earned.clear();
439
706
  this.idle?.release();
707
+ if (this.decor) {
708
+ this.decor.dispose();
709
+ this.decor = null;
710
+ }
440
711
  // What was said in the place just left stays there.
441
712
  this.say.clear();
442
713
  this.together.clear();
@@ -444,18 +715,35 @@ class HubSystem {
444
715
  this.wentAsk = null;
445
716
  this.againAsk = null;
446
717
  this.playAsked.clear();
718
+ this.yours?.clear();
447
719
  }
448
720
 
449
721
  // Every scene load, the same scene reloaded included: the actors are the
450
722
  // file's again, so what was dropped, painted or spawned in them is gone.
451
723
  reset(scene) {
724
+ if (this.menuDrawn) {
725
+ this.clearMenu();
726
+ delete Hub.hub.menu;
727
+ }
728
+ if (this.askDrawn) {
729
+ this.clearTextAsk();
730
+ delete Hub.hub.ask;
731
+ }
732
+ clearShot();
733
+ this.companion?.clear();
734
+ if (this.decor) {
735
+ this.decor.dispose();
736
+ this.decor = null;
737
+ }
452
738
  this.stash.clear();
453
739
  this.tinted.clear();
454
740
  this.spawnedHere.clear();
455
741
  if (scene) {
456
742
  this.wear.clear(scene);
743
+ this.earned.clear();
457
744
  } else {
458
745
  this.wear.forget();
746
+ this.earned.forget();
459
747
  }
460
748
  }
461
749
 
@@ -465,7 +753,9 @@ class HubSystem {
465
753
  applyWear(scene) {
466
754
  const self = scene.multiplayer?.net?.selfId?.() ?? null;
467
755
  const style = Avatar.style();
468
- const indexOf = (playerId) => (playerId === self ? Avatar.current(scene) : Hub.hub.avatars.get(playerId));
756
+ // Dressed as the avatar drawn: `known` for the others, or the stand-in
757
+ // the cap draws (`avatarCap.js`), as the hook layer draws them.
758
+ const indexOf = (playerId) => (playerId === self ? Avatar.current(scene) : AvatarCap.shown(playerId));
469
759
  this.wear.frame(
470
760
  scene,
471
761
  scene.actorWith('Player'),
@@ -481,6 +771,14 @@ class HubSystem {
481
771
  return Avatar.hatFit(index, Avatar.drawn(scene.files, index, style));
482
772
  },
483
773
  );
774
+ // Earned items (v1.53): no work at all while nobody shows one and
775
+ // nothing is drawn.
776
+ if (Hub.hub.earned.size > 0 || this.earned.size > 0) {
777
+ this.earned.frame(scene, scene.actorWith('Player'), Hub.hub.earned, (playerId) => {
778
+ const index = indexOf(playerId);
779
+ return Avatar.earnedFit(index, Avatar.drawn(scene.files, index, style));
780
+ });
781
+ }
484
782
  }
485
783
 
486
784
  // The place's tuning of this player's own controller (`hub.tune`): the
@@ -514,7 +812,7 @@ class HubSystem {
514
812
  if (!model) {
515
813
  return;
516
814
  }
517
- const file = Avatar.model(scene.files, Avatar.current(scene));
815
+ const file = Avatar.model(scene.files, Avatar.current(scene), Avatar.style(), Avatar.currentColor(scene));
518
816
  if (file && model.file !== file) {
519
817
  model.file = file;
520
818
  }
@@ -525,57 +823,140 @@ class HubSystem {
525
823
  // out at once, so arrival never waits on the avatar; when the avatar
526
824
  // changes (the platform's answer, a pick) it says hello again and the place
527
825
  // redraws the body in the new one.
826
+ //
827
+ // A connection that comes back to a session that let it go (a phone's app
828
+ // switch: the platform reported a leave and the place forgot the player) says
829
+ // hello again, in every place but a game that did not opt in to `resume`
830
+ // (`client/rehello.js` says how that is seen), without waiting for the place's own greet: a fresh hello, so the
831
+ // place re-sends what it had sent, from a party of one and carrying nothing
832
+ // (it has arrived once already), keeping this client's chat and start. A
833
+ // place that still has the player arrived does not arrive them again.
528
834
  sayHello(scene, mp) {
529
835
  const net = mp.net;
530
836
  if (!net) {
531
837
  return;
532
838
  }
533
839
  const avatar = Avatar.current(scene);
534
- if (net === this.helloNet && avatar === this.helloAvatar) {
840
+ const color = Avatar.currentColor(scene);
841
+ if (net === this.helloNet) {
842
+ const back = Rehello.resumed(mp, net, this.helloMark);
843
+ // (Another player id was reset for by `newIdentity`, already.) A game
844
+ // (a place with `result`) back under the same id keeps the old way, as
845
+ // its server does, unless its place says `resume: true` (v1.72); under a
846
+ // new id it is a session that never arrived this player, which an
847
+ // ordinary first hello does (`helloAfter`).
848
+ const place = Hub.hub.place ?? this.identityPlace;
849
+ const say = Rehello.helloAfter(back, Boolean(place?.result), place?.resume === true);
850
+ if (say !== 'none') {
851
+ console.log(`[hub] the connection came back (${back}): saying a ${say} hello`);
852
+ this.sendHello(scene, mp, net, avatar, say === 'resume' ? { resume: true } : { solo: true });
853
+ if (back === 'world') {
854
+ this.talk?.resume();
855
+ }
856
+ return;
857
+ }
858
+ if (back) {
859
+ this.helloMark = Rehello.mark(mp, net);
860
+ }
861
+ }
862
+ if (net === this.helloNet && avatar === this.helloAvatar && color === (this.helloColor ?? 0)) {
535
863
  return;
536
864
  }
537
865
  // The same session again (the avatar changed): the place keeps what it
538
866
  // knows this client holds (a cabinet's card, v1.7).
539
867
  const again = net === this.helloNet;
540
868
  if (!again) {
541
- // A player who walks in (no door, no jump to a friend) starts beside a
542
- // friend or party member who is already here, once, if one turns up in
543
- // the first moments and the player has not walked off.
544
- const arrivingNow = scene.persistent?.hubArriving ?? null;
545
- this.startNear = !arrivingNow?.door && typeof arrivingNow?.near !== 'string' ? { until: performance.now() + START_NEAR_MS, at: null, asked: false } : null;
546
- this.friendsAt = -Infinity;
547
- // Another session (a door, a layer): what was said in the last one stays there.
548
- this.say.clear();
549
- this.together.clear();
550
- this.playAsk = null;
551
- this.wentAsk = null;
552
- this.againAsk = null;
553
- this.playAsked.clear();
554
- this.chat.reset();
555
- if (Hub.deck.cues) {
556
- this.hereCues = [];
557
- this.besideTold = null;
558
- this.rosterSeen = new Set();
559
- // The party this session is first told of is the one the player had.
560
- this.partyCarryUntil = this.partyLast?.members ? performance.now() + PARTY_CARRY_MS : 0;
561
- this.partyLast = null;
562
- this.partySettleUntil = performance.now() + PARTY_SETTLE_MS;
563
- this.partyAccepted = null;
564
- }
869
+ this.identityPlace = null;
870
+ this.freshSession(scene);
871
+ }
872
+ this.sendHello(scene, mp, net, avatar, { again });
873
+ }
874
+
875
+ // The same connection under another player id is another session: what the
876
+ // old one sent this player (its HUD, tune, decor, card, shot, labels, holds
877
+ // and the snapshot's state) goes before the new one's packets are applied,
878
+ // as on any switch of session, along with what this client kept of it.
879
+ newIdentity() {
880
+ console.log('[hub] the connection has a new player id: a new session');
881
+ this.identityPlace = Hub.hub.place ?? this.identityPlace;
882
+ Hub.clear();
883
+ if (ballotHeld) {
884
+ forgetBallot();
885
+ }
886
+ if (this.scene) {
887
+ this.freshSession(this.scene);
888
+ }
889
+ // A recovery, not a walk-in: no automatic start beside a friend.
890
+ this.startNear = null;
891
+ }
892
+
893
+ // What this client keeps of one session, cleared when it joins another.
894
+ freshSession(scene) {
895
+ // A player who walks in (no door, no jump to a friend) starts beside a
896
+ // friend or party member who is already here, once, if one turns up in
897
+ // the first moments and the player has not walked off.
898
+ const arrivingNow = scene.persistent?.hubArriving ?? null;
899
+ this.startNear = !arrivingNow?.door && typeof arrivingNow?.near !== 'string' ? { until: performance.now() + START_NEAR_MS, at: null, asked: false } : null;
900
+ this.friendsAt = -Infinity;
901
+ this.friendsGameAt = -Infinity;
902
+ this.friendsGameWarm = false;
903
+ // Another session (a door, a layer): what was said in the last one stays there.
904
+ this.companion?.clear();
905
+ this.say.clear();
906
+ this.together.clear();
907
+ this.playAsk = null;
908
+ this.wentAsk = null;
909
+ this.againAsk = null;
910
+ this.playAsked.clear();
911
+ this.chat.reset();
912
+ this.talk?.reset();
913
+ if (Hub.deck.cues) {
914
+ this.hereCues = [];
915
+ this.besideTold = null;
916
+ this.rosterSeen = new Set();
917
+ // The party this session is first told of is the one the player had.
918
+ this.partyCarryUntil = this.partyLast?.members ? performance.now() + PARTY_CARRY_MS : 0;
919
+ this.partyLast = null;
920
+ this.partySettleUntil = performance.now() + PARTY_SETTLE_MS;
921
+ this.partyAccepted = null;
922
+ }
923
+ }
924
+
925
+ // `solo`: a party of one carrying nothing and naming no friend, as `resume`
926
+ // is, without saying it resumes (a game's new session, `helloAfter`).
927
+ sendHello(scene, mp, net, avatar, { again = false, resume = false, solo = resume } = {}) {
928
+ if (resume && (this.menuDrawn || Object.hasOwn(Hub.hub, 'menu'))) {
929
+ this.clearMenu();
930
+ delete Hub.hub.menu;
931
+ }
932
+ if (resume && Object.hasOwn(Hub.hub, 'companion')) {
933
+ delete Hub.hub.companion;
934
+ this.companion?.clear();
935
+ }
936
+ if (resume && (this.askDrawn || Object.hasOwn(Hub.hub, 'ask'))) {
937
+ this.clearTextAsk();
938
+ delete Hub.hub.ask;
939
+ }
940
+ if (resume && Object.hasOwn(Hub.hub, 'actions')) {
941
+ delete Hub.hub.actions;
565
942
  }
566
943
  this.helloNet = net;
567
944
  this.helloAvatar = avatar;
945
+ this.helloColor = Avatar.currentColor(scene);
946
+ this.helloMark = Rehello.mark(mp, net, () => this.newIdentity());
568
947
  const per = scene.persistent;
569
948
  const arriving = per.hubArriving ?? null;
570
949
  net.send({
571
950
  k: 'hub-hello',
572
951
  avatar,
952
+ ...(Number.isInteger(this.helloColor) && this.helloColor > 0 ? { color: this.helloColor } : {}),
573
953
  from: arriving?.door ?? null,
574
- party: arriving?.party ?? 1,
575
- carry: arriving?.returning && per.hubResult ? { result: per.hubResult } : null,
954
+ party: solo ? 1 : arriving?.party ?? 1,
955
+ carry: !solo && arriving?.returning && per.hubResult ? { result: per.hubResult } : null,
576
956
  // A jump to a friend: the place puts this player beside them.
577
- ...(typeof arriving?.near === 'string' ? { near: arriving.near } : {}),
957
+ ...(!solo && typeof arriving?.near === 'string' ? { near: arriving.near } : {}),
578
958
  ...(again ? { again: true } : {}),
959
+ ...(resume ? { resume: true } : {}),
579
960
  });
580
961
  }
581
962
 
@@ -586,11 +967,14 @@ class HubSystem {
586
967
  // An actor the place moves (`hub.move`) has its pose written by the network
587
968
  // each frame it moves, which lifts it back up: it is dropped again, and
588
969
  // shown again by lifting it from wherever it is.
970
+ // The engine is told before each write (`scene.touch`): a scene may hold
971
+ // the actor still (physics-3d `"engine": { "staticActors": true }`).
589
972
  applyVisibility(scene) {
590
973
  for (const id of Hub.hub.hidden) {
591
974
  const t = scene.getActor(id)?.components.Transform;
592
975
  if (t && t.y > -HIDE_DROP_M / 2) {
593
976
  this.stash.set(id, true);
977
+ scene.touch?.(id);
594
978
  t.y -= HIDE_DROP_M;
595
979
  }
596
980
  }
@@ -599,6 +983,7 @@ class HubSystem {
599
983
  this.stash.delete(id);
600
984
  const t = scene.getActor(id)?.components.Transform;
601
985
  if (t && t.y < -HIDE_DROP_M / 2) {
986
+ scene.touch?.(id);
602
987
  t.y += HIDE_DROP_M;
603
988
  }
604
989
  }
@@ -628,6 +1013,9 @@ class HubSystem {
628
1013
  components.Transform = { ...components.Transform, x: copy.x, y: copy.y, z: copy.z, rotationY: copy.rotationY };
629
1014
  scene.spawnActor({ id, components });
630
1015
  this.spawnedHere.add(id);
1016
+ if (components.HubSpin) {
1017
+ this.spin = addSpinner(this.spin, id, components);
1018
+ }
631
1019
  }
632
1020
  for (const id of this.spawnedHere) {
633
1021
  if (!Object.hasOwn(want, id)) {
@@ -641,6 +1029,20 @@ class HubSystem {
641
1029
  }
642
1030
  }
643
1031
 
1032
+ // Turning displays (contract §10, v1.55): the scene's `HubSpin` actors are
1033
+ // found once per scene load, by the loaded data's identity, and copies as
1034
+ // they are spawned (`applySpawns`). A scene with none leaves `this.spin`
1035
+ // null and nothing is turned, touched or written.
1036
+ turnSpinners(scene, dt) {
1037
+ if (scene.data !== this.spinData) {
1038
+ this.spinData = scene.data;
1039
+ this.spin = findSpinners(scene.data?.actors);
1040
+ }
1041
+ if (this.spin) {
1042
+ spinFrame(this.spin, scene, dt, Hub.hub.hidden);
1043
+ }
1044
+ }
1045
+
644
1046
  // Paint what the place painted, and put back what it stopped painting
645
1047
  // (`hub.tint`, contract §10). A Shape that glows glows in its new colour.
646
1048
  applyTints(scene) {
@@ -654,6 +1056,7 @@ class HubSystem {
654
1056
  this.tinted.set(id, { color: shape.color, tint: shape.tint, emissive: shape.emissive });
655
1057
  }
656
1058
  // A textured face takes its colour from `tint`, a plain one from `color`.
1059
+ scene.touch?.(id);
657
1060
  shape.color = color;
658
1061
  shape.tint = color;
659
1062
  if (glows(this.tinted.get(id).emissive)) {
@@ -665,6 +1068,7 @@ class HubSystem {
665
1068
  this.tinted.delete(id);
666
1069
  const shape = scene.getActor(id)?.components.Shape;
667
1070
  if (shape) {
1071
+ scene.touch?.(id);
668
1072
  shape.color = authored.color;
669
1073
  shape.tint = authored.tint;
670
1074
  shape.emissive = authored.emissive;
@@ -726,7 +1130,10 @@ class HubSystem {
726
1130
  runCommands(scene, now) {
727
1131
  while (Hub.hub.commands.length && !this.trip) {
728
1132
  const msg = Hub.hub.commands.shift();
729
- if (msg.k === 'hub-go' && msg.classic) {
1133
+ if (msg.k === 'hub-home-unlock') {
1134
+ // v1.77: a harbour boat deed names the Harbour; anything else is the house.
1135
+ this.toast = { text: msg.to === 'boat' ? 'Sent to your boat at the Harbour' : 'Sent to your house', until: now + TOAST_MS };
1136
+ } else if (msg.k === 'hub-go' && msg.classic) {
730
1137
  // A cabinet: the host plays a classic deck; this place waits (v1.7).
731
1138
  this.goClassic(scene, msg);
732
1139
  } else if (msg.k === 'hub-go' && !msg.key) {
@@ -736,9 +1143,10 @@ class HubSystem {
736
1143
  this.go(scene, msg);
737
1144
  } else if (msg.k === 'hub-result') {
738
1145
  scene.persistent.hubResult = { ...msg.result, at: Date.now() };
739
- } else if (msg.k === 'hub-end') {
1146
+ } else if (msg.k === 'hub-end' && Rehello.takesEnd(msg, this.pendingEnd, this.endSession, sessionKey(scene))) {
740
1147
  this.pendingEnd = now + END_PAUSE_MS;
741
1148
  this.endSession = sessionKey(scene);
1149
+ this.endLeaving = null;
742
1150
  const r = scene.persistent.hubResult;
743
1151
  this.toast = { text: r && Date.now() - r.at < 30000 ? resultLine(r) : 'Game over', until: now + END_PAUSE_MS + 200 };
744
1152
  }
@@ -874,7 +1282,7 @@ class HubSystem {
874
1282
  stepClassic(scene, trip, mp, now) {
875
1283
  const pending = trip.target.pending;
876
1284
  trip.marks.covered ??= now;
877
- this.chrome.setCover(1, trip.target.title);
1285
+ this.setTripCover(1, trip);
878
1286
  if (!pending.done && now - trip.startedAt < CLASSIC_LIMIT_MS) {
879
1287
  return;
880
1288
  }
@@ -931,6 +1339,7 @@ class HubSystem {
931
1339
  // retries no failed hub join, and `AWAY_JOIN` is one it could not make
932
1340
  // anyway. The next `switchSession` (Back) clears that.
933
1341
  leaveSession(scene, mp) {
1342
+ clearShot();
934
1343
  mp.switchSession(scene, AWAY_JOIN, { quiet: true });
935
1344
  mp.joinFailed = true;
936
1345
  this.helloNet = null;
@@ -1116,16 +1525,16 @@ class HubSystem {
1116
1525
  }
1117
1526
 
1118
1527
  // Who of the player's friends is in another layer of this place, asked every
1119
- // little while from a place that is not a game. Dormant on a host that cannot
1120
- // say: `unavailable` (no hub support) or a refusal (a host from before
1121
- // friends) stops asking for the life of the runtime; a failed ask is retried.
1528
+ // little while from a town; a requesting game asks at once, after 20 s,
1529
+ // then every 90 s. Dormant on a host that cannot say: `unavailable`
1530
+ // (no hub support) or a refusal (a host from before friends) stops asking for the life of the runtime; a failed ask is retried.
1122
1531
  askFriends(scene, mp, now) {
1123
1532
  if (this.friendsOff || this.friendsAsking || typeof castleSdk.Hub?.friends !== 'function') {
1124
1533
  return;
1125
1534
  }
1126
1535
  const place = Hub.hub.place;
1127
1536
  const idle = !this.trip && this.pendingEnd === null && (mp.joinState?.() ?? 'joined') === 'joined';
1128
- if (!place || place.result || !idle) {
1537
+ if (!place || (place.result && !Hub.hub.friendsWanted) || !idle) {
1129
1538
  return;
1130
1539
  }
1131
1540
  // Cues (v1.23): someone here is not named by the host as a friend, and
@@ -1136,8 +1545,11 @@ class HubSystem {
1136
1545
  // 1 s of any ask.
1137
1546
  // One that cannot be sent (a trip, a join still pending) reaches none of
1138
1547
  // this and is simply tried again when it can be, owing nothing it missed.
1139
- const onTime = now - this.friendsAt >= FRIENDS_EVERY_MS;
1548
+ const game = Boolean(place.result);
1549
+ const gameEvery = this.friendsGameWarm ? 20000 : 90000;
1550
+ const onTime = game ? now - this.friendsGameAt >= gameEvery : now - this.friendsAt >= FRIENDS_EVERY_MS;
1140
1551
  const early =
1552
+ !game &&
1141
1553
  !onTime &&
1142
1554
  Hub.deck.cues &&
1143
1555
  now - this.friendsEarlyAt >= FRIENDS_EARLY_PAIR_MS &&
@@ -1148,6 +1560,12 @@ class HubSystem {
1148
1560
  return;
1149
1561
  }
1150
1562
  this.friendsAt = now;
1563
+ if (game) {
1564
+ // The first ask may precede the heartbeat roster. One warm-up ask
1565
+ // 20 s later writes the seen marker after the player reaches it.
1566
+ this.friendsGameWarm = this.friendsGameAt === -Infinity;
1567
+ this.friendsGameAt = now;
1568
+ }
1151
1569
  this.friendsAsking = true;
1152
1570
  if (Hub.deck.cues) {
1153
1571
  // Sent: the bounds count from here, and the steps come due are spent.
@@ -1236,6 +1654,68 @@ class HubSystem {
1236
1654
  }
1237
1655
  }
1238
1656
 
1657
+ // "Stuck?" (v1.33, `client/stuck.js`), only in a deck whose castle.json asks
1658
+ // (`hub.stuck`): without it this is never called and nothing of it is made.
1659
+ // A chip is offered to a player who has walked for a few seconds and got
1660
+ // nowhere; nothing moves them but their own tap. Only in a town that says
1661
+ // it takes it (`hubStuck`), and never to a player the place holds.
1662
+ offerUnstick(scene, local, town, now) {
1663
+ const offer = town ? Hub.hub.stuck : null;
1664
+ const t = local?.components.Transform;
1665
+ const selfId = scene.multiplayer?.net?.selfId?.();
1666
+ if (!offer || !t || Hub.hub.held.has(selfId)) {
1667
+ if (this.stuck) {
1668
+ resetStuck(this.stuck);
1669
+ this.stuckShown = false;
1670
+ this.chrome.stuckPrompt?.(null);
1671
+ }
1672
+ return;
1673
+ }
1674
+ this.stuck ??= makeStuck();
1675
+ const walking = walkInput(scene.keys, scene.moveInput, scene.cameraControl === 'orbit');
1676
+ const hidden = globalThis.document?.visibilityState === 'hidden';
1677
+ const shown = stuckFrame(this.stuck, { key: `${this.sceneKey}|${Hub.hub.place.id}`, x: t.x, z: t.z, walking, hidden }, now);
1678
+ let text = shown ? stuckText(offer.to) : null;
1679
+ if (offer.hook) {
1680
+ // v1.39, a place that picks the spot itself: asked, as the chip comes
1681
+ // up, what a tap would do from here; until it answers the words name
1682
+ // nowhere. And what it did, once the player has tapped.
1683
+ if (shown && !this.stuckShown) {
1684
+ Hub.hub.stuckTo = null;
1685
+ scene.multiplayer?.net?.send({ k: 'hub-unstick', ask: true });
1686
+ }
1687
+ const says = Hub.hub.stuckTo;
1688
+ text = shown ? (says ? stuckText(says.to, says.spot) : stuckText(null, true)) : null;
1689
+ const done = Hub.hub.unstuck;
1690
+ if (done) {
1691
+ Hub.hub.unstuck = null;
1692
+ this.toast = { text: stuckDone(done.to, done.spot), until: now + TOAST_MS };
1693
+ }
1694
+ }
1695
+ this.stuckShown = shown;
1696
+ this.chrome.stuckPrompt?.(text, () => this.unstick(this.scene));
1697
+ }
1698
+
1699
+ // A tap on the chip or the Doors row: the place is asked to put this player
1700
+ // back at its arrival (`hub-unstick`), at most as often as it would answer.
1701
+ unstick(scene) {
1702
+ const net = scene?.multiplayer?.net;
1703
+ const now = performance.now();
1704
+ const offer = Hub.hub.stuck;
1705
+ if (!Hub.deck.stuck || !net || this.trip || !offer || now - (this.unstuckAt ?? -Infinity) < STUCK_EVERY_MS) {
1706
+ return;
1707
+ }
1708
+ this.unstuckAt = now;
1709
+ if (this.stuck) {
1710
+ resetStuck(this.stuck);
1711
+ }
1712
+ this.sendJump(net, { k: 'hub-unstick' });
1713
+ // A place that picks the spot says where it was (`hub-jumped`), and is quoted then.
1714
+ if (!offer.hook) {
1715
+ this.toast = { text: stuckWhere(offer.to), until: now + TOAST_MS };
1716
+ }
1717
+ }
1718
+
1239
1719
  // Go, from the Doors list: onto that door's pad. In a party the door is
1240
1720
  // proposed to the party too, and each member who says yes lands on the pad.
1241
1721
  goDoor(scene, door) {
@@ -1374,7 +1854,10 @@ class HubSystem {
1374
1854
  }
1375
1855
  // Cues (v1.29): back from a game with nothing else asked -- the same game
1376
1856
  // again, with the party when there is one (the Doors list's own Go).
1377
- const again = Hub.deck.cues ? this.againAsk : null;
1857
+ if (Hub.deck.yourGames && !proposal) {
1858
+ return this.yours?.ask(Hub.hub.yours, Hub.hub.doors, Hub.hub.party.members, performance.now()) ?? null;
1859
+ }
1860
+ const again = Hub.deck.cues && !Hub.deck.yourGames ? this.againAsk : null;
1378
1861
  const door = again && performance.now() < again.until ? Hub.hub.doors.find((d) => d.id === again.door) : null;
1379
1862
  if (door) {
1380
1863
  const together = Hub.hub.party.members?.length && !door.solo;
@@ -1388,6 +1871,17 @@ class HubSystem {
1388
1871
  if (!net || !ask) {
1389
1872
  return;
1390
1873
  }
1874
+ if (ask.kind === 'yours') {
1875
+ const current = this.ask();
1876
+ if (!Hub.deck.yourGames || current?.key !== ask.key || this.trip || Hub.hub.place?.result) {
1877
+ return;
1878
+ }
1879
+ this.yours.dismiss();
1880
+ if (yes) {
1881
+ this.goDoor(scene, Hub.hub.doors.find((d) => d.id === ask.door));
1882
+ }
1883
+ return;
1884
+ }
1391
1885
  if (ask.kind === 'again') {
1392
1886
  // Only the offer that is up: one whose time ran out, or that a later
1393
1887
  // return replaced, is answered by nothing.
@@ -1511,9 +2005,18 @@ class HubSystem {
1511
2005
  });
1512
2006
  }
1513
2007
 
2008
+ // A user Back first dismisses the menu; automatic travel still uses back.
2009
+ backFromControl(scene) {
2010
+ if (this.chrome?.menuOpen?.()) {
2011
+ this.chrome.cancelMenu();
2012
+ return;
2013
+ }
2014
+ this.back(scene);
2015
+ }
2016
+
1514
2017
  // Back through the door this player came in by (contract §5). With no ticket
1515
2018
  // -- a game played on its own -- it is a fresh instance of the same place.
1516
- back(scene, { covered = false, attempt = 0, lost = 0, away = null } = {}) {
2019
+ back(scene, { covered = false, attempt = 0, lost = 0, away = null, previousTrip = null } = {}) {
1517
2020
  // Away in a classic deck (v1.7): Back is the way out, cover already down.
1518
2021
  if (this.trip?.phase === 'away') {
1519
2022
  away = this.trip.target;
@@ -1554,7 +2057,7 @@ class HubSystem {
1554
2057
  attempt,
1555
2058
  lost,
1556
2059
  away,
1557
- });
2060
+ }, previousTrip);
1558
2061
  if (covered && this.trip) {
1559
2062
  this.trip.startedAt -= OPEN_MS;
1560
2063
  }
@@ -1571,7 +2074,7 @@ class HubSystem {
1571
2074
  exitDoor: null,
1572
2075
  arrive: { door: null, party: 1, returning: false },
1573
2076
  lost,
1574
- });
2077
+ }, previousTrip);
1575
2078
  return;
1576
2079
  }
1577
2080
  this.startTrip(scene, {
@@ -1587,32 +2090,73 @@ class HubSystem {
1587
2090
  arrive: { door: ticket.door, party: ticket.party ?? 1, returning: true },
1588
2091
  ticket,
1589
2092
  lost,
1590
- });
2093
+ }, previousTrip);
1591
2094
  if (covered && this.trip) {
1592
2095
  // Straight to the swap: the door already closed over the player.
1593
2096
  this.trip.startedAt -= OPEN_MS;
1594
2097
  }
1595
2098
  }
1596
2099
 
1597
- startTrip(scene, target) {
2100
+ startTrip(scene, target, previousTrip = null) {
1598
2101
  if (this.trip) {
1599
2102
  return;
1600
2103
  }
2104
+ clearShot();
2105
+ if (Hub.deck.soundscape?.ui === true && target.exitDoor) {
2106
+ this.soundscape?.cue('door', performance.now());
2107
+ }
1601
2108
  const cam = scene.three?.camera;
2109
+ const startedAt = performance.now();
2110
+ // Local screenshot fixture, like hubFriends: never on a hosted page.
2111
+ const { hostname, search } = globalThis.location ?? {};
2112
+ const devLine = hostname === 'localhost' || hostname === '127.0.0.1'
2113
+ ? new URLSearchParams(search ?? '').get('hubLeaving')?.trim().slice(0, 120)
2114
+ : null;
2115
+ previousTrip ??= this.pendingEnd !== null ? this.endLeaving : null;
2116
+ const leaving = previousTrip ? previousTrip.leaving : target.classic || target.away ? null : Hub.hub.leaving ?? (devLine || null);
2117
+ const leavingUntil = previousTrip ? previousTrip.leavingUntil : startedAt + LEAVING_MS;
2118
+ // The toast as the trip began: one set after this (feedback during the trip) wins over the line.
2119
+ const toastAtStart = previousTrip?.toastAtStart ?? this.toast;
2120
+ this.leavingToast = null;
1602
2121
  this.tripCount += 1;
1603
2122
  this.trip = {
1604
2123
  n: this.tripCount,
1605
2124
  target,
1606
2125
  phase: 'opening',
1607
2126
  from: this.scenePath,
1608
- startedAt: performance.now(),
2127
+ startedAt,
2128
+ leaving,
2129
+ leavingUntil,
2130
+ toastAtStart,
1609
2131
  cam0: cam ? { x: cam.position.x, y: cam.position.y, z: cam.position.z } : null,
1610
2132
  heapBefore: heapMB(),
1611
2133
  marks: {},
1612
2134
  };
2135
+ if (this.pendingEnd !== null) {
2136
+ this.endLeaving ??= { leaving, leavingUntil, toastAtStart };
2137
+ }
1613
2138
  scene.persistent.hubArriving = target.arrive;
1614
2139
  }
1615
2140
 
2141
+ setTripCover(alpha, trip) {
2142
+ if (trip.leaving && !trip.shut) {
2143
+ this.chrome.setCover(alpha, trip.target.title, trip.leaving);
2144
+ } else {
2145
+ this.chrome.setCover(alpha, trip.target.title);
2146
+ }
2147
+ }
2148
+
2149
+ showLeaving(scene, trip, now) {
2150
+ if (!trip.leaving || trip.shut || trip.lost || trip.timedOut || now >= trip.leavingUntil) {
2151
+ return;
2152
+ }
2153
+ const r = scene.persistent.hubResult;
2154
+ const back = trip.target.arrive?.returning && r ? `Back from ${resultLine(r)}` : '';
2155
+ // Capture once: later feedback must stay ahead, even on another reveal frame.
2156
+ this.leavingToast ??= { previousToast: trip.toastAtStart ?? this.toast, until: trip.leavingUntil };
2157
+ this.leavingToast.text = back ? `${back.slice(0, 80)} · ${trip.leaving}` : trip.leaving;
2158
+ }
2159
+
1616
2160
  stepTrip(scene, mp, local, now) {
1617
2161
  const trip = this.trip;
1618
2162
  const elapsed = now - trip.startedAt;
@@ -1621,7 +2165,7 @@ class HubSystem {
1621
2165
  const t = clamp01(elapsed / OPEN_MS);
1622
2166
  const door = trip.target.exitDoor ? scene.getActor(trip.target.exitDoor) : null;
1623
2167
  if (door) {
1624
- this.swingDoor(door, ease(t));
2168
+ this.swingDoor(door, ease(t), scene);
1625
2169
  }
1626
2170
  if (cam && trip.cam0) {
1627
2171
  const e = ease(t);
@@ -1647,7 +2191,7 @@ class HubSystem {
1647
2191
  cam.lookAt(lt.x, lt.y + 0.8, lt.z);
1648
2192
  }
1649
2193
  }
1650
- this.chrome.setCover(clamp01((t - 0.4) / 0.6), trip.target.title);
2194
+ this.setTripCover(clamp01((t - 0.4) / 0.6), trip);
1651
2195
  if (t >= 1 && trip.target.classic) {
1652
2196
  this.stepClassic(scene, trip, mp, now);
1653
2197
  return;
@@ -1675,11 +2219,11 @@ class HubSystem {
1675
2219
  return;
1676
2220
  }
1677
2221
  if (trip.phase === 'away') {
1678
- this.chrome.setCover(1, trip.target.title);
2222
+ this.setTripCover(1, trip);
1679
2223
  return;
1680
2224
  }
1681
2225
  if (trip.phase === 'committing') {
1682
- this.chrome.setCover(1, trip.target.title);
2226
+ this.setTripCover(1, trip);
1683
2227
  const state = mp.joinState();
1684
2228
  // 'lost' was committed too: the loading phase recovers from it.
1685
2229
  if (state === 'joined' || state === 'lost') {
@@ -1693,7 +2237,7 @@ class HubSystem {
1693
2237
  return;
1694
2238
  }
1695
2239
  if (trip.phase === 'loading') {
1696
- this.chrome.setCover(1, trip.target.title);
2240
+ this.setTripCover(1, trip);
1697
2241
  if (scene.mountError) {
1698
2242
  this.mountFailed(scene, trip, now);
1699
2243
  return;
@@ -1732,7 +2276,7 @@ class HubSystem {
1732
2276
  this.faceArrival(scene);
1733
2277
  const door = trip.target.arriveDoor ? scene.getActor(doorActor(scene, trip.target.arriveDoor)) : null;
1734
2278
  if (door) {
1735
- this.swingDoor(door, 1);
2279
+ this.swingDoor(door, 1, scene);
1736
2280
  }
1737
2281
  const lt = local?.components.Transform;
1738
2282
  const base = door ? (this.doorBase.get(door.id) ?? door.components.Transform) : null;
@@ -1744,10 +2288,14 @@ class HubSystem {
1744
2288
  // player came through, and the door swings shut behind them.
1745
2289
  const t = clamp01((now - trip.revealAt) / REVEAL_MS);
1746
2290
  trip.marks.firstFrame ??= now;
1747
- this.chrome.setCover(1 - clamp01(t / 0.6), trip.target.title);
2291
+ const cover = 1 - clamp01(t / 0.6);
2292
+ this.setTripCover(cover, trip);
2293
+ if (cover <= 0.05) {
2294
+ this.showLeaving(scene, trip, now);
2295
+ }
1748
2296
  const door = trip.target.arriveDoor ? scene.getActor(doorActor(scene, trip.target.arriveDoor)) : null;
1749
2297
  if (door) {
1750
- this.swingDoor(door, 1 - ease(clamp01((t - 0.35) / 0.65)));
2298
+ this.swingDoor(door, 1 - ease(clamp01((t - 0.35) / 0.65)), scene);
1751
2299
  }
1752
2300
  const lt = local?.components.Transform;
1753
2301
  const follow = local && cam ? followCamera(scene, local) : null;
@@ -1772,7 +2320,7 @@ class HubSystem {
1772
2320
  return true;
1773
2321
  }
1774
2322
  trip.marks.covered ??= now;
1775
- this.chrome.setCover(1, trip.target.title);
2323
+ this.setTripCover(1, trip);
1776
2324
  // A retried way back has its own deadline, from when it was asked again.
1777
2325
  if (!pending.done && now - (trip.target.pendingFrom ?? trip.startedAt) < LOADING_LIMIT_MS) {
1778
2326
  return false;
@@ -1883,7 +2431,7 @@ class HubSystem {
1883
2431
  scene.mountError = null;
1884
2432
  this.trip = null;
1885
2433
  this.toast = { text: 'That door is stuck', until: now + TOAST_MS };
1886
- this.back(scene, { covered: true });
2434
+ this.back(scene, { covered: true, previousTrip: trip });
1887
2435
  }
1888
2436
 
1889
2437
  // The host committed this hub trip, and the session it led to closed before
@@ -1923,7 +2471,7 @@ class HubSystem {
1923
2471
  this.toast = { text: trip.target.stuck ?? 'That door is stuck', until: now + TOAST_MS };
1924
2472
  // Both counts ride along, so a way that alternates between a lost join
1925
2473
  // and an uncommitted one still runs out.
1926
- this.back(scene, { covered: true, attempt: trip.target.attempt ?? 0, lost: tries + 1 });
2474
+ this.back(scene, { covered: true, attempt: trip.target.attempt ?? 0, lost: tries + 1, previousTrip: trip });
1927
2475
  if (!this.trip) {
1928
2476
  this.chrome.setCover(0);
1929
2477
  }
@@ -1970,13 +2518,13 @@ class HubSystem {
1970
2518
  title: '',
1971
2519
  exitDoor: null,
1972
2520
  arrive: { door: null, party: 1, returning: false },
1973
- });
2521
+ }, trip);
1974
2522
  if (this.trip) {
1975
2523
  this.trip.startedAt -= OPEN_MS;
1976
2524
  }
1977
2525
  return;
1978
2526
  }
1979
- this.back(scene, { covered: true });
2527
+ this.back(scene, { covered: true, previousTrip: trip });
1980
2528
  return;
1981
2529
  }
1982
2530
  if (trip.target.pushedTicket) {
@@ -1995,20 +2543,20 @@ class HubSystem {
1995
2543
  exitDoor: null,
1996
2544
  arriveDoor: ticket.door,
1997
2545
  arrive: { door: ticket.door, party: ticket.party ?? 1, returning: true },
1998
- });
2546
+ }, trip);
1999
2547
  if (this.trip) {
2000
2548
  this.trip.startedAt -= OPEN_MS;
2001
2549
  }
2002
2550
  return;
2003
2551
  }
2004
- this.back(scene, { covered: true });
2552
+ this.back(scene, { covered: true, previousTrip: trip });
2005
2553
  return;
2006
2554
  }
2007
2555
  if (trip.target.ticket) {
2008
2556
  per.hubTickets.push(trip.target.ticket);
2009
2557
  }
2010
2558
  if ((trip.target.attempt ?? 0) < 1) {
2011
- this.back(scene, { covered: true, attempt: (trip.target.attempt ?? 0) + 1, lost: trip.target.lost ?? 0, away: trip.target.away ?? null });
2559
+ this.back(scene, { covered: true, attempt: (trip.target.attempt ?? 0) + 1, lost: trip.target.lost ?? 0, away: trip.target.away ?? null, previousTrip: trip });
2012
2560
  }
2013
2561
  if (!this.trip && trip.target.away) {
2014
2562
  // The way back from a classic deck did not commit: still away.
@@ -2047,6 +2595,7 @@ class HubSystem {
2047
2595
  settleEnd(scene) {
2048
2596
  if (this.pendingEnd !== null && sessionKey(scene) !== this.endSession) {
2049
2597
  this.pendingEnd = null;
2598
+ this.endLeaving = null;
2050
2599
  }
2051
2600
  }
2052
2601
 
@@ -2055,6 +2604,9 @@ class HubSystem {
2055
2604
  // PI - camAngle.
2056
2605
  faceArrival(scene) {
2057
2606
  if (Hub.hub.arrivedFacing !== null) {
2607
+ if (Hub.deck.soundscape?.ui === true && !this.trip && !Hub.hub.faced) {
2608
+ this.soundscape?.uiArrival(performance.now());
2609
+ }
2058
2610
  scene.persistent.camAngle = Math.PI - Hub.hub.arrivedFacing;
2059
2611
  // Under the engine's orbit camera key the character's facing is not
2060
2612
  // PI - camAngle: it is asked for.
@@ -2067,11 +2619,17 @@ class HubSystem {
2067
2619
 
2068
2620
  finishTrip(scene, trip) {
2069
2621
  this.trip = null;
2622
+ if (Hub.deck.soundscape?.ui === true && !trip.shut && !trip.lost && !trip.timedOut && Hub.hub.arrivedFacing !== null) {
2623
+ this.soundscape?.uiArrival(performance.now());
2624
+ }
2070
2625
  this.chrome.setCover(0);
2626
+ this.showLeaving(scene, trip, performance.now());
2071
2627
  // A new place or layer: ask again who is elsewhere.
2072
2628
  this.friends = null;
2073
2629
  this.friendsAll = null;
2074
2630
  this.friendsAt = -Infinity;
2631
+ this.friendsGameAt = -Infinity;
2632
+ this.friendsGameWarm = false;
2075
2633
  const m = trip.marks;
2076
2634
  const start = trip.startedAt;
2077
2635
  const record = {
@@ -2106,22 +2664,37 @@ class HubSystem {
2106
2664
  (globalThis.__hubTrips ??= []).push(record);
2107
2665
  console.log(`[hub-trip] ${JSON.stringify(record)}`);
2108
2666
  const r = scene.persistent.hubResult;
2109
- if (trip.target.arrive?.returning && r) {
2667
+ if (trip.target.arrive?.returning && r && (!this.leavingToast || this.toast === this.leavingToast.previousToast)) {
2110
2668
  this.toast = { text: `Back from ${resultLine(r)}`, until: performance.now() + TOAST_MS };
2669
+ // The arrival result is already part of the leaving toast, not new feedback.
2670
+ if (this.leavingToast) {
2671
+ this.leavingToast.previousToast = this.toast;
2672
+ }
2111
2673
  }
2112
- if (Hub.deck.cues && trip.target.arrive?.returning && trip.target.arrive.door) {
2674
+ if (Hub.deck.yourGames && trip.target.arrive?.returning && trip.target.arrive.door) {
2675
+ this.yourGames().returned(trip.target.arrive.door, r);
2676
+ }
2677
+ if (Hub.deck.cues && !Hub.deck.yourGames && trip.target.arrive?.returning && trip.target.arrive.door) {
2113
2678
  // Cues: a next step, put once the player is back in the town, whether
2114
2679
  // or not the game had a result to tell.
2115
2680
  this.againAsk = { door: trip.target.arrive.door, until: performance.now() + AGAIN_ASK_MS };
2116
2681
  }
2117
2682
  }
2118
2683
 
2684
+ yourGames() {
2685
+ this.yours ??= makeYours(castleSdk.Hub, castleSdk.User, (text) => {
2686
+ this.toast = { text, until: performance.now() + TOAST_MS };
2687
+ });
2688
+ return this.yours;
2689
+ }
2690
+
2119
2691
  // Swing a door leaf open by `amount` (0 shut, 1 open) about its left edge,
2120
2692
  // in the door's own frame, so a door turned to face any way opens the same.
2121
- swingDoor(door, amount) {
2693
+ swingDoor(door, amount, scene) {
2122
2694
  if (isCabinet(door)) {
2123
2695
  return;
2124
2696
  }
2697
+ scene?.touch?.(door.id);
2125
2698
  const t = door.components.Transform;
2126
2699
  if (!this.doorBase.has(door.id)) {
2127
2700
  this.doorBase.set(door.id, { x: t.x, z: t.z, rotationY: t.rotationY ?? 0 });
@@ -2152,10 +2725,19 @@ class HubSystem {
2152
2725
  (away || (idle && this.pendingEnd === null)) && !(scene.persistent.hubDepth > 0) && (inGame || Boolean(ticket)),
2153
2726
  ticket?.title ?? 'Again',
2154
2727
  );
2155
- chrome.showPicker(idle && place !== null && !inGame && !this.talk.talking(), Avatar.current(scene));
2156
- const free = idle && place !== null && this.pendingEnd === null && !this.talk.talking();
2728
+ chrome.showPicker(idle && place !== null && !inGame && !this.talk.talking() && !this.carded, Avatar.current(scene), { available: Avatar.colorsAvailable(), style: Avatar.style(), color: Avatar.currentColor(scene), files: scene.files, model: Avatar.colorsAvailable() && Avatar.style() === 'toon' ? Avatar.model(scene.files, Avatar.current(scene), 'toon') : null });
2729
+ const free = idle && place !== null && this.pendingEnd === null && !this.talk.talking() && !this.carded;
2157
2730
  const town = free && !inGame;
2158
- chrome.setDoors?.(town ? Hub.hub.doors : null, Hub.hub.party.members?.length ? 'Go together' : 'Go');
2731
+ // "Stuck?" (v1.33), only in a deck with `hub.stuck`, and there only in a
2732
+ // place that says it takes it (a town): a row over the Doors list.
2733
+ const stuckRow = Hub.deck.stuck && town && Hub.hub.stuck ? { where: Hub.hub.stuck.hook ? stuckWhere(null, true) : stuckWhere(Hub.hub.stuck.to), onPick: () => this.unstick(this.scene) } : null;
2734
+ let yours = null;
2735
+ if (Hub.deck.yourGames) {
2736
+ const controller = this.yourGames();
2737
+ controller.frame(town, Hub.hub.yours, now);
2738
+ yours = { rows: controller.rows(Hub.hub.yours, Hub.hub.doors), ...controller.controls() };
2739
+ }
2740
+ chrome.setDoors?.(town ? Hub.hub.doors : null, Hub.hub.party.members?.length ? 'Go together' : 'Go', stuckRow, yours);
2159
2741
  chrome.setPeople?.(free ? this.people(scene, inGame) : null, town ? this.together.partyLine() : null);
2160
2742
  chrome.setAsk?.(town ? this.ask() : null);
2161
2743
  this.startBeside(scene, local, town, now);
@@ -2271,7 +2853,7 @@ class HubSystem {
2271
2853
  chatPart.label = chatPart.input ? CHAT_HINT.label : CHAT_HINT.why;
2272
2854
  }
2273
2855
  chrome.setSay?.(free ? { reactions: REACTIONS, phrases: this.say.phrases(), chat: chatPart } : null);
2274
- chrome.setFeed?.(idle && place !== null ? this.say.feed() : []);
2856
+ chrome.setFeed?.(idle && place !== null && !this.carded ? this.say.feed() : []);
2275
2857
  // Standing still beside someone: a small button invites them.
2276
2858
  const beside = town && !Hub.hub.party.invite && local ? this.together.beside(scene, local) : null;
2277
2859
  chrome.nearPrompt?.(
@@ -2319,7 +2901,7 @@ class HubSystem {
2319
2901
  const at = scene.getActor(id)?.components.Transform;
2320
2902
  if (at && label.style === 'goal') {
2321
2903
  // Where the place is sending this player (v1.13): a pointer, not a label.
2322
- goals.push({ id, at, text: label.text });
2904
+ goals.push({ id, at, label });
2323
2905
  } else if (at) {
2324
2906
  // A sign is drawn at any distance in a town: a street's name, or a
2325
2907
  // word the player must see from where they stand.
@@ -2338,22 +2920,28 @@ class HubSystem {
2338
2920
  now,
2339
2921
  )
2340
2922
  : null;
2341
- for (const { id, at, label, always } of placed) {
2342
- const opacity = shown && !always ? shown.get(id) : 1;
2343
- const screen = opacity ? project(cam, at.x, at.y + 1.6, at.z, view) : null;
2344
- if (screen) {
2345
- labels.push({ id, x: screen.x, y: screen.y, text: label.text, speech: label.style === 'speech', npc: label.npc === true, opacity });
2923
+ if (shown && Hub.deck.labels && chrome.measureLabel) {
2924
+ // `hub.labels: "near"` (v1.43): signs near the player only, no two
2925
+ // world labels overlapping, three at most (`labelsNear.js`).
2926
+ labels.push(...this.nearLabels(scene, placed, lt, cam, view, now));
2927
+ } else {
2928
+ for (const { id, at, label, always } of placed) {
2929
+ const opacity = shown && !always ? shown.get(id) : 1;
2930
+ const screen = opacity ? project(cam, at.x, at.y + 1.6, at.z, view) : null;
2931
+ if (screen) {
2932
+ labels.push({ id, x: screen.x, y: screen.y, text: label.text, speech: label.style === 'speech', npc: label.npc === true, opacity });
2933
+ }
2346
2934
  }
2347
2935
  }
2348
2936
  }
2349
2937
  const pointers = cam && idle && place && !inGame && this.pendingEnd === null ? this.together.pointers(scene, local, cam, view) : [];
2350
2938
  const me = local?.components.Transform;
2351
2939
  if (cam && me && this.pendingEnd === null) {
2352
- // The nearest goals, each with how far it is.
2353
- const near = goals.map((g) => ({ ...g, d: Math.hypot(g.at.x - me.x, g.at.z - me.z) })).sort((a, b) => a.d - b.d);
2354
- for (const g of near.slice(0, GOALS_MAX)) {
2355
- pointers.push(pointerAt(cam, view, { x: g.at.x, y: g.at.y + 1.6, z: g.at.z }, `goal:${g.id}`, g.d > GOAL_NEAR_M ? `${g.text} · ${Math.round(g.d)} m` : g.text));
2356
- }
2940
+ // The nearest drawable goals, each with how far it is.
2941
+ const near = goals.map((g) => ({ ...g, d: Math.hypot(g.at.x - me.x, g.at.z - me.z) }));
2942
+ pointers.push(...goalPointers(near, GOALS_MAX, (g) =>
2943
+ pointerAt(cam, view, { x: g.at.x, y: g.at.y + 1.6, z: g.at.z }, `goal:${g.id}`, goalText(g.label, g.d, GOAL_NEAR_M)),
2944
+ ));
2357
2945
  }
2358
2946
  chrome.setPointers?.(pointers);
2359
2947
  if (cam && idle) {
@@ -2361,7 +2949,25 @@ class HubSystem {
2361
2949
  labels.push(...this.idle.labels(scene, local, cam, view, project));
2362
2950
  labels.push(...this.say.labels(scene, local, cam, view, project, scene.multiplayer?.net?.selfId?.() ?? null));
2363
2951
  }
2952
+ if (Hub.hub.place?.companion === true && cam && idle) {
2953
+ labels.push(...(this.companion?.labels(cam, view, project, now) ?? []));
2954
+ }
2364
2955
  chrome.setLabels(labels);
2956
+ if (place?.companionChat) {
2957
+ const canTalk = cam && idle && this.pendingEnd === null && !this.talk.talking() && this.decor?.opened() !== true && !this.carded;
2958
+ chrome.layoutCompanion?.(scene.three?.renderer?.domElement?.parentElement);
2959
+ chrome.setCompanionBadge?.(Boolean(canTalk && Hub.hub.companion?.c && place.companion === true && local), place.companionChat.name, () => this.talk.openCompanion(scene));
2960
+ this.companionTalkDrawn = true;
2961
+ chrome.setCompanionTalk?.(canTalk ? this.companion?.screen(cam, view, project) : null, place.companionChat.name, () => {
2962
+ this.companionTappedUntil = now + 3000;
2963
+ this.talk.openCompanion(scene);
2964
+ });
2965
+ } else if (this.companionTalkDrawn) {
2966
+ chrome.setCompanionBadge?.(false);
2967
+ chrome.layoutCompanion?.(null);
2968
+ chrome.setCompanionTalk(null);
2969
+ delete this.companionTalkDrawn;
2970
+ }
2365
2971
 
2366
2972
  const lt = local?.components.Transform;
2367
2973
  // The card of the cabinet this player stands nearest (v1.7).
@@ -2369,12 +2975,73 @@ class HubSystem {
2369
2975
  const r = scene.persistent.hubResult;
2370
2976
  const showRibbon = !inGame && idle && r && Date.now() - r.at < RIBBON_MS && lt && cam;
2371
2977
  chrome.setRibbon(showRibbon ? project(cam, lt.x, lt.y + 1.7, lt.z, view) : null, r ? `🏅 ${resultLine(r)}` : '');
2372
- chrome.setToast(now < this.toast.until ? this.toast.text : '');
2978
+ const leaving = this.leavingToast && now < this.leavingToast.until && this.toast === this.leavingToast.previousToast;
2979
+ const toast = leaving ? this.leavingToast : this.toast;
2980
+ if (leaving) {
2981
+ chrome.setToast(toast.text, { wrap: true });
2982
+ } else {
2983
+ chrome.setToast(now < toast.until ? toast.text : '');
2984
+ }
2373
2985
  // A clear HUD (v1.26): everything drawn above is measured, then moved
2374
2986
  // out from under it, once for the frame. Never said in any other place.
2375
2987
  if (this.hudClear) {
2376
2988
  chrome.flushHudClear?.();
2377
2989
  }
2990
+ // "Stuck?" (v1.33), last of all: the chip is measured after every other
2991
+ // chrome element has its final rect for this frame -- after every setter
2992
+ // above, and after a clear HUD's flush has moved labels, pointers, a
2993
+ // cabinet's card and the ribbon out from under the HUD. Nothing above
2994
+ // knows of the chip or makes way for it: the chip is the one that yields,
2995
+ // and is not drawn where a card or the ribbon now lies; labels and
2996
+ // pointers pass under it (`chrome.stuckPrompt`).
2997
+ if (Hub.deck.stuck) {
2998
+ this.offerUnstick(scene, local, town, now);
2999
+ }
3000
+ }
3001
+
3002
+ // A town's world labels under `hub.labels: "near"` (v1.43): the plate and
3003
+ // the line the attention rule picked this frame (`attend` has just run) and
3004
+ // every sign, each with where its label would lie, handed to `near`.
3005
+ //
3006
+ // The rule's state is one visit's (`nearFor`): another scene, the scene
3007
+ // loaded again, another connection or the hub's state cleared, and it
3008
+ // starts again.
3009
+ //
3010
+ // Label boxes are final when the rule judges them, because the chrome draws
3011
+ // from them: `labelBox` is the one place a world label's box is worked out
3012
+ // (its size for these words, kept on the screen, moved from under a clear
3013
+ // HUD -- `setHud` has run, so the HUD's box is this frame's), the rule is
3014
+ // given that box, and the same box goes to `setLabels`, which puts the
3015
+ // label exactly there and moves it no more. A label whose style changes
3016
+ // gets a node of its own (the chrome styles a node once), so the node drawn
3017
+ // is always one measured as it is styled.
3018
+ nearLabels(scene, placed, lt, cam, view, now) {
3019
+ const chrome = this.chrome;
3020
+ const mine = Hub.hub.labelsMe;
3021
+ const state = nearFor((this.nearHeld ??= {}), { scene: sceneKeyOf(scene), data: scene.data, net: scene.multiplayer?.net ?? null, place: Hub.hub.place });
3022
+ const hud = chrome.hudClearBox?.() ?? null;
3023
+ const items = [];
3024
+ const drawn = new Map();
3025
+ for (const { id, at, label, always } of placed) {
3026
+ const speech = label.style === 'speech';
3027
+ const kind = always ? 'sign' : speech ? 'speech' : 'plate';
3028
+ const pick = !always && id === (speech ? this.attention.speech : this.attention.plate);
3029
+ // A plate or a line the attention rule passed over: only one still fading.
3030
+ if (!always && !pick && !state.alpha.has(id)) {
3031
+ continue;
3032
+ }
3033
+ const npc = label.npc === true;
3034
+ const screen = project(cam, at.x, at.y + 1.6, at.z, view);
3035
+ const box = screen ? labelBox(screen.x, screen.y, chrome.measureLabel(label.text, speech, npc), npc, view, hud) : null;
3036
+ items.push({ id, kind, pick, d: Math.hypot(at.x - lt.x, at.z - lt.z), mine: Object.hasOwn(mine, id), box });
3037
+ drawn.set(id, { text: label.text, speech, npc, box });
3038
+ }
3039
+ const out = [];
3040
+ for (const [id, opacity] of near(state, items, view, now)) {
3041
+ const d = drawn.get(id);
3042
+ out.push(chromeItem(id, d.text, d.speech, d.npc, d.box, opacity));
3043
+ }
3044
+ return out;
2378
3045
  }
2379
3046
 
2380
3047
  // The People list's rows. In a town: everyone here and the player's
@@ -2465,6 +3132,17 @@ class HubSystem {
2465
3132
  }
2466
3133
 
2467
3134
  dispose() {
3135
+ this.visibility?.sync(null, null, false);
3136
+ this.visibility = null;
3137
+ if (this.menuDrawn) {this.clearMenu();}
3138
+ if (this.askDrawn) {
3139
+ this.clearTextAsk();
3140
+ }
3141
+ clearShot();
3142
+ if (this.decor) {
3143
+ this.decor.dispose();
3144
+ this.decor = null;
3145
+ }
2468
3146
  this.chrome?.dispose();
2469
3147
  this.chrome = null;
2470
3148
  this.talk = null;
@@ -2474,6 +3152,17 @@ class HubSystem {
2474
3152
  this.idle = null;
2475
3153
  this.sound?.dispose();
2476
3154
  this.sound = null;
3155
+ this.soundscape?.dispose();
3156
+ this.soundscape = null;
3157
+ if (this.ballot) {
3158
+ this.ballot.dispose();
3159
+ this.ballot = null;
3160
+ }
3161
+ // What players wear hangs on the avatars' nodes and holds shares of the
3162
+ // hat builds: given back with the runtime.
3163
+ this.companion?.dispose();
3164
+ this.wear?.clear();
3165
+ this.earned?.clear();
2477
3166
  }
2478
3167
  }
2479
3168
 
@@ -2533,6 +3222,67 @@ function doorActor(scene, door) {
2533
3222
  return null;
2534
3223
  }
2535
3224
 
3225
+ // SceneRuntime has no before-behavior system hook. While this card alone is
3226
+ // open, clear inputs at the entry to the same update that Player runs in,
3227
+ // including capped frames' lent presses; restore the method on every close.
3228
+ function holdAskInput(scene) {
3229
+ const active = scene.moveInput?.active;
3230
+ const ownUpdate = Object.getOwnPropertyDescriptor(scene, 'update');
3231
+ const update = scene.update;
3232
+ const hold = () => {
3233
+ lockInput(scene);
3234
+ scene.moveInput?.consumeJump?.();
3235
+ const player = scene.actorWith?.('Player');
3236
+ if (player?.runtime) {
3237
+ player.runtime.jumpBuffer = 0;
3238
+ }
3239
+ if (scene.cameraControl === 'orbit') {
3240
+ scene.lookInput?.lock?.();
3241
+ }
3242
+ };
3243
+ // Captured/locked canvas pointers can bypass the DOM shield. Block their
3244
+ // new drags too, while still letting pointerup clean up an older gesture.
3245
+ const listeners = new AbortController();
3246
+ for (const type of ['pointerdown', 'pointermove', 'mousedown', 'wheel']) {
3247
+ globalThis.addEventListener?.(type, (event) => {
3248
+ if (event.target?.tagName === 'CANVAS') {
3249
+ event.stopImmediatePropagation();
3250
+ event.preventDefault();
3251
+ }
3252
+ }, { capture: true, passive: false, signal: listeners.signal });
3253
+ }
3254
+ // Drop any drag already held when the prompt took the screen.
3255
+ scene.lookInput?.cancel?.();
3256
+ // A desktop mouse lock would keep the cursor in the canvas, out of reach of
3257
+ // the card: let it go (the orbit input hears the change and drops its own).
3258
+ if (globalThis.document?.pointerLockElement) {
3259
+ globalThis.document.exitPointerLock?.();
3260
+ }
3261
+ hold();
3262
+ const guardedUpdate = function (...args) {
3263
+ hold();
3264
+ return update.apply(this, args);
3265
+ };
3266
+ if (typeof update === 'function') {
3267
+ scene.update = guardedUpdate;
3268
+ }
3269
+ return {
3270
+ release() {
3271
+ listeners.abort();
3272
+ if (scene.update === guardedUpdate) {
3273
+ if (ownUpdate) {
3274
+ Object.defineProperty(scene, 'update', ownUpdate);
3275
+ } else {
3276
+ delete scene.update;
3277
+ }
3278
+ }
3279
+ if (scene.moveInput) {
3280
+ scene.moveInput.active = active;
3281
+ }
3282
+ },
3283
+ };
3284
+ }
3285
+
2536
3286
  function lockInput(scene) {
2537
3287
  scene.keys?.clear?.();
2538
3288
  if (scene.moveInput) {