castle-web-cli 0.4.233 → 0.4.235

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 (383) hide show
  1. package/dist/api.d.ts +11 -0
  2. package/dist/api.js +43 -0
  3. package/dist/bundle.d.ts +64 -0
  4. package/dist/bundle.js +558 -2
  5. package/dist/castle-host/host.d.ts +17 -2
  6. package/dist/castle-host/host.js +793 -36
  7. package/dist/castleJson.d.ts +20 -1
  8. package/dist/castleJson.js +44 -2
  9. package/dist/check.js +9 -2
  10. package/dist/chunkLoader.d.ts +3 -0
  11. package/dist/chunkLoader.js +111 -0
  12. package/dist/devParty.d.ts +26 -0
  13. package/dist/devParty.js +231 -0
  14. package/dist/devSaveStorage.js +4 -0
  15. package/dist/devSessionStorage.js +3 -1
  16. package/dist/devSocial.d.ts +24 -0
  17. package/dist/devSocial.js +70 -0
  18. package/dist/ide.d.ts +2 -0
  19. package/dist/ide.js +119 -15
  20. package/dist/index.js +8 -2
  21. package/dist/init.js +1 -1
  22. package/dist/save-deck.d.ts +20 -1
  23. package/dist/save-deck.js +141 -5
  24. package/dist/serve.js +29 -11
  25. package/dist/shell/assets/{index-BjOxR-lW.js → index-DulbYIJm.js} +97 -97
  26. package/dist/shell/index.html +1 -1
  27. package/dist/vitePlugins.d.ts +2 -1
  28. package/dist/vitePlugins.js +13 -0
  29. package/kits/base/castle.json +1 -1
  30. package/kits/base/sdk/README.md +266 -3
  31. package/kits/base/sdk/castle.d.ts +7 -3
  32. package/kits/base/sdk/castle.js +2 -0
  33. package/kits/base/sdk/commands.d.ts +162 -1
  34. package/kits/base/sdk/commands.js +3 -0
  35. package/kits/base/sdk/display.d.ts +3 -0
  36. package/kits/base/sdk/display.js +9 -3
  37. package/kits/base/sdk/hub.d.ts +33 -6
  38. package/kits/base/sdk/hub.js +68 -5
  39. package/kits/base/sdk/hubRejoin.d.ts +4 -0
  40. package/kits/base/sdk/hubRejoin.js +15 -0
  41. package/kits/base/sdk/multiplayer.d.ts +7 -1
  42. package/kits/base/sdk/multiplayer.js +147 -40
  43. package/kits/base/sdk/multiplayerProtocol.d.ts +2 -0
  44. package/kits/base/sdk/party.d.ts +23 -0
  45. package/kits/base/sdk/party.js +91 -0
  46. package/kits/base/sdk/reconnectBudget.d.ts +23 -0
  47. package/kits/base/sdk/reconnectBudget.js +96 -0
  48. package/kits/base/sdk/save.d.ts +38 -1
  49. package/kits/base/sdk/save.js +79 -6
  50. package/kits/base/sdk/server/hub.d.ts +31 -1
  51. package/kits/base/sdk/server/hub.js +50 -3
  52. package/kits/base/sdk/server/platformHandle.d.ts +13 -1
  53. package/kits/base/sdk/server/storage.d.ts +4 -0
  54. package/kits/base/sdk/server/storage.js +19 -3
  55. package/kits/base/sdk/server/wrapper.d.ts +7 -1
  56. package/kits/base/sdk/server/wrapper.js +10 -1
  57. package/kits/base/sdk/social.d.ts +9 -0
  58. package/kits/base/sdk/social.js +5 -0
  59. package/kits/hub-game/CLAUDE.md +123 -3
  60. package/kits/hub-game/README.md +63 -0
  61. package/kits/hub-game/castle.json +5 -5
  62. package/kits/hub-game/code/client/act.js +312 -0
  63. package/kits/hub-game/code/client/actionLayout.js +147 -0
  64. package/kits/hub-game/code/client/actionOverflow.js +556 -0
  65. package/kits/hub-game/code/client/arrivalCamera.js +50 -0
  66. package/kits/hub-game/code/client/askSlot.js +117 -0
  67. package/kits/hub-game/code/client/avatar.js +4 -2
  68. package/kits/hub-game/code/client/avatarShare.js +2 -0
  69. package/kits/hub-game/code/client/backVisibility.js +13 -0
  70. package/kits/hub-game/code/client/ballot.js +15 -10
  71. package/kits/hub-game/code/client/build.js +16 -0
  72. package/kits/hub-game/code/client/chat.js +41 -5
  73. package/kits/hub-game/code/client/chatModeration.js +5 -0
  74. package/kits/hub-game/code/client/chrome.js +1148 -258
  75. package/kits/hub-game/code/client/crowdNames.js +241 -0
  76. package/kits/hub-game/code/client/decor.js +10 -4
  77. package/kits/hub-game/code/client/defaultEnvironment.js +194 -0
  78. package/kits/hub-game/code/client/doorErrors.js +39 -0
  79. package/kits/hub-game/code/client/fall.js +18 -0
  80. package/kits/hub-game/code/client/farAvatars.js +233 -0
  81. package/kits/hub-game/code/client/firstJoin.js +9 -2
  82. package/kits/hub-game/code/client/fpsTelemetry.js +50 -0
  83. package/kits/hub-game/code/client/frameBatch.js +5 -0
  84. package/kits/hub-game/code/client/grab.js +31 -11
  85. package/kits/hub-game/code/client/hookLayer.js +87 -8
  86. package/kits/hub-game/code/client/hudCopy.js +51 -0
  87. package/kits/hub-game/code/client/hudRate.js +20 -0
  88. package/kits/hub-game/code/client/idle.js +14 -2
  89. package/kits/hub-game/code/client/invites.js +231 -0
  90. package/kits/hub-game/code/client/joinError.js +9 -0
  91. package/kits/hub-game/code/client/labelsNear.js +31 -2
  92. package/kits/hub-game/code/client/landscapeLayout.js +17 -0
  93. package/kits/hub-game/code/client/layoutCache.js +264 -0
  94. package/kits/hub-game/code/client/loadTelemetry.js +20 -0
  95. package/kits/hub-game/code/client/loadingCover.js +148 -0
  96. package/kits/hub-game/code/client/loadingEntry.js +8 -0
  97. package/kits/hub-game/code/client/menuRows.js +43 -0
  98. package/kits/hub-game/code/client/modelReady.js +7 -0
  99. package/kits/hub-game/code/client/padCueArrival.js +23 -0
  100. package/kits/hub-game/code/client/padCues.js +112 -0
  101. package/kits/hub-game/code/client/padOccupancy.js +88 -0
  102. package/kits/hub-game/code/client/padReadability.js +26 -0
  103. package/kits/hub-game/code/client/padRings.js +69 -0
  104. package/kits/hub-game/code/client/pushVisit.js +14 -0
  105. package/kits/hub-game/code/client/quality.js +205 -0
  106. package/kits/hub-game/code/client/qualityEntry.js +55 -0
  107. package/kits/hub-game/code/client/safeLayout.js +338 -0
  108. package/kits/hub-game/code/client/safeStyle.js +42 -0
  109. package/kits/hub-game/code/client/say.js +12 -3
  110. package/kits/hub-game/code/client/shot.js +64 -10
  111. package/kits/hub-game/code/client/shotFit.js +56 -0
  112. package/kits/hub-game/code/client/signIn.js +28 -0
  113. package/kits/hub-game/code/client/state.js +53 -0
  114. package/kits/hub-game/code/client/talk.js +209 -45
  115. package/kits/hub-game/code/client/tiers.js +68 -66
  116. package/kits/hub-game/code/client/together.js +7 -2
  117. package/kits/hub-game/code/client/weakestLookBake.js +92 -0
  118. package/kits/hub-game/code/client/weakestTier.js +295 -0
  119. package/kits/hub-game/code/client/worldLabels.js +241 -0
  120. package/kits/hub-game/code/client/yours.js +10 -9
  121. package/kits/hub-game/code/npcDisplayText.js +55 -0
  122. package/kits/hub-game/code/server/act.js +124 -0
  123. package/kits/hub-game/code/server/actions.js +6 -1
  124. package/kits/hub-game/code/server/actors.js +2 -1
  125. package/kits/hub-game/code/server/analytics.js +83 -0
  126. package/kits/hub-game/code/server/anonymousEntry.js +49 -0
  127. package/kits/hub-game/code/server/arrivalPose.js +36 -0
  128. package/kits/hub-game/code/server/companion.js +28 -3
  129. package/kits/hub-game/code/server/doorAnalytics.js +52 -0
  130. package/kits/hub-game/code/server/earned.js +22 -5
  131. package/kits/hub-game/code/server/frameBatch.js +183 -0
  132. package/kits/hub-game/code/server/friendsAmong.js +49 -9
  133. package/kits/hub-game/code/server/history.js +2 -0
  134. package/kits/hub-game/code/server/hub.js +1306 -95
  135. package/kits/hub-game/code/server/idle.js +30 -1
  136. package/kits/hub-game/code/server/index.js +26 -4
  137. package/kits/hub-game/code/server/invites.js +19 -0
  138. package/kits/hub-game/code/server/labels.js +9 -1
  139. package/kits/hub-game/code/server/loadAbandon.js +106 -0
  140. package/kits/hub-game/code/server/manifest.js +211 -3
  141. package/kits/hub-game/code/server/menu.js +31 -3
  142. package/kits/hub-game/code/server/npcs.js +226 -64
  143. package/kits/hub-game/code/server/observe.js +408 -0
  144. package/kits/hub-game/code/server/padOccupancy.js +85 -0
  145. package/kits/hub-game/code/server/players.js +9 -1
  146. package/kits/hub-game/code/server/resumePose.js +152 -0
  147. package/kits/hub-game/code/server/say.js +1 -1
  148. package/kits/hub-game/code/server/standing.js +4 -5
  149. package/kits/hub-game/code/server/storageLimit.js +187 -0
  150. package/kits/hub-game/code/server/vis.js +67 -5
  151. package/kits/hub-game/code/shared/act.js +35 -0
  152. package/kits/hub-game/code/shared/danceIdle.js +28 -0
  153. package/kits/hub-game/code/shared/loadStages.js +12 -0
  154. package/kits/hub-game/code/shared/quality.js +74 -0
  155. package/kits/hub-game/code/shared/say.js +2 -0
  156. package/kits/hub-game/code/shared/shot.js +35 -1
  157. package/kits/hub-game/code/systems/hub.js +970 -169
  158. package/kits/hub-game/docs/analytics.md +279 -0
  159. package/kits/hub-game/docs/contract.md +1259 -42
  160. package/kits/hub-game/docs/home-pieces.md +9 -2
  161. package/kits/hub-game/docs/observed-progress.md +252 -0
  162. package/kits/hub-game/main.jsx +2 -0
  163. package/kits/hub-game/package-lock.json +10 -3
  164. package/kits/hub-game/package.json +6 -3
  165. package/kits/hub-game/play/player.js +142 -0
  166. package/kits/hub-game/play/registry.js +47 -0
  167. package/kits/hub-game/play.jsx +37 -0
  168. package/kits/hub-game/scripts/check.mjs +39 -5
  169. package/kits/hub-game/scripts/companion-follower-wire.json +1 -1
  170. package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +11 -0
  171. package/kits/hub-game/scripts/fixtures/decor-keyless.json +5 -5
  172. package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +3 -0
  173. package/kits/hub-game/scripts/fixtures/fake-dom.mjs +19 -3
  174. package/kits/hub-game/scripts/fixtures/interest-legacy.json +3 -3
  175. package/kits/hub-game/scripts/fixtures/vis-shared-wire.json +1 -1
  176. package/kits/hub-game/scripts/pose-storage-fixture.mjs +46 -0
  177. package/kits/hub-game/scripts/test-act-client.mjs +186 -0
  178. package/kits/hub-game/scripts/test-act.mjs +171 -0
  179. package/kits/hub-game/scripts/test-action-layout.mjs +80 -0
  180. package/kits/hub-game/scripts/test-action-observers.mjs +46 -0
  181. package/kits/hub-game/scripts/test-actions-client.mjs +367 -2
  182. package/kits/hub-game/scripts/test-actors.mjs +20 -7
  183. package/kits/hub-game/scripts/test-analytics.mjs +76 -0
  184. package/kits/hub-game/scripts/test-anonymous-entry.mjs +28 -0
  185. package/kits/hub-game/scripts/test-arrival-pose-server.mjs +196 -0
  186. package/kits/hub-game/scripts/test-arrival-pose.mjs +24 -0
  187. package/kits/hub-game/scripts/test-ask-slot.mjs +85 -0
  188. package/kits/hub-game/scripts/test-avatar-wire.mjs +49 -10
  189. package/kits/hub-game/scripts/test-avatar.mjs +44 -0
  190. package/kits/hub-game/scripts/test-back-visibility.mjs +82 -0
  191. package/kits/hub-game/scripts/test-ballot.mjs +11 -4
  192. package/kits/hub-game/scripts/test-ban-join.mjs +121 -13
  193. package/kits/hub-game/scripts/test-build.mjs +20 -2
  194. package/kits/hub-game/scripts/test-chat.mjs +206 -5
  195. package/kits/hub-game/scripts/test-companion-chat.mjs +20 -2
  196. package/kits/hub-game/scripts/test-control-layout-dom.mjs +120 -0
  197. package/kits/hub-game/scripts/test-crowd-names.mjs +205 -0
  198. package/kits/hub-game/scripts/test-decor-client.mjs +45 -4
  199. package/kits/hub-game/scripts/test-decor.mjs +7 -0
  200. package/kits/hub-game/scripts/test-default-environment-root.mjs +95 -0
  201. package/kits/hub-game/scripts/test-default-environment.mjs +267 -0
  202. package/kits/hub-game/scripts/test-door-analytics.mjs +58 -0
  203. package/kits/hub-game/scripts/test-door-jump.mjs +100 -0
  204. package/kits/hub-game/scripts/test-earned.mjs +33 -3
  205. package/kits/hub-game/scripts/test-far-avatars.mjs +340 -0
  206. package/kits/hub-game/scripts/test-fps-telemetry.mjs +112 -0
  207. package/kits/hub-game/scripts/test-frame-batch.mjs +252 -0
  208. package/kits/hub-game/scripts/test-fresh-friends.mjs +118 -0
  209. package/kits/hub-game/scripts/test-grab-orbit.mjs +47 -4
  210. package/kits/hub-game/scripts/test-high-only.mjs +170 -0
  211. package/kits/hub-game/scripts/test-hub-ops.mjs +321 -2
  212. package/kits/hub-game/scripts/test-hub-trip.mjs +879 -11
  213. package/kits/hub-game/scripts/test-hud-clear.mjs +162 -59
  214. package/kits/hub-game/scripts/test-hud-defects-dom.mjs +100 -0
  215. package/kits/hub-game/scripts/test-hud-rate.mjs +224 -0
  216. package/kits/hub-game/scripts/test-hud-safe-visibility-dom.mjs +83 -0
  217. package/kits/hub-game/scripts/test-idle.mjs +66 -0
  218. package/kits/hub-game/scripts/test-interest-cells.mjs +20 -0
  219. package/kits/hub-game/scripts/test-interest.mjs +15 -0
  220. package/kits/hub-game/scripts/test-invites-client.mjs +430 -0
  221. package/kits/hub-game/scripts/test-invites.mjs +109 -0
  222. package/kits/hub-game/scripts/test-labels.mjs +71 -3
  223. package/kits/hub-game/scripts/test-landscape-layout.mjs +194 -0
  224. package/kits/hub-game/scripts/test-list-scroll-dom.mjs +49 -0
  225. package/kits/hub-game/scripts/test-load-abandon.mjs +246 -0
  226. package/kits/hub-game/scripts/test-loading-cover.mjs +162 -0
  227. package/kits/hub-game/scripts/test-manifest.mjs +265 -0
  228. package/kits/hub-game/scripts/test-menu-client.mjs +105 -0
  229. package/kits/hub-game/scripts/test-menu.mjs +23 -0
  230. package/kits/hub-game/scripts/test-npcs.mjs +917 -10
  231. package/kits/hub-game/scripts/test-observed.mjs +745 -0
  232. package/kits/hub-game/scripts/test-pad-cues.mjs +304 -0
  233. package/kits/hub-game/scripts/test-pad-occupancy.mjs +177 -0
  234. package/kits/hub-game/scripts/test-picker.mjs +234 -7
  235. package/kits/hub-game/scripts/test-placement-cache.mjs +690 -0
  236. package/kits/hub-game/scripts/test-progress-reset.mjs +559 -0
  237. package/kits/hub-game/scripts/test-push-visit.mjs +26 -0
  238. package/kits/hub-game/scripts/test-quality.mjs +385 -0
  239. package/kits/hub-game/scripts/test-rehello.mjs +699 -5
  240. package/kits/hub-game/scripts/test-resume-action-order.mjs +598 -0
  241. package/kits/hub-game/scripts/test-resume-held.mjs +239 -0
  242. package/kits/hub-game/scripts/test-resume-pose.mjs +142 -0
  243. package/kits/hub-game/scripts/test-safe-events-dom.mjs +116 -0
  244. package/kits/hub-game/scripts/test-safe-layout.mjs +330 -0
  245. package/kits/hub-game/scripts/test-say.mjs +1 -1
  246. package/kits/hub-game/scripts/test-shot.mjs +145 -0
  247. package/kits/hub-game/scripts/test-signin-client.mjs +45 -0
  248. package/kits/hub-game/scripts/test-soundscape.mjs +22 -17
  249. package/kits/hub-game/scripts/test-standing.mjs +35 -2
  250. package/kits/hub-game/scripts/test-storage-limit.mjs +333 -0
  251. package/kits/hub-game/scripts/test-stuck.mjs +5 -4
  252. package/kits/hub-game/scripts/test-talk-overlay-dom.mjs +130 -0
  253. package/kits/hub-game/scripts/test-tiers-render.mjs +86 -13
  254. package/kits/hub-game/scripts/test-tiers.mjs +7 -8
  255. package/kits/hub-game/scripts/test-vis.mjs +433 -6
  256. package/kits/hub-game/scripts/test-weakest-tier.mjs +924 -0
  257. package/kits/hub-game/scripts/test-world-labels.mjs +367 -0
  258. package/kits/hub-game/scripts/test-yours-chrome.mjs +50 -6
  259. package/kits/hub-game/scripts/test-yours.mjs +39 -8
  260. package/kits/multiplayer-3d/castle.json +5 -5
  261. package/kits/multiplayer-3d/code/client/joinFailure.js +27 -0
  262. package/kits/multiplayer-3d/code/client/resumeGate.js +139 -0
  263. package/kits/multiplayer-3d/code/systems/multiplayer.js +369 -30
  264. package/kits/multiplayer-3d/package-lock.json +8 -1
  265. package/kits/multiplayer-3d/package.json +2 -1
  266. package/kits/multiplayer-3d/scripts/test-join-watchdog.mjs +436 -0
  267. package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +624 -0
  268. package/kits/physics-2d/CLAUDE.md +10 -1
  269. package/kits/physics-2d/castle.json +2 -2
  270. package/kits/physics-2d/engine/frozenActors.js +233 -0
  271. package/kits/physics-2d/engine/scene.js +87 -5
  272. package/kits/physics-2d/eslint.config.js +1 -1
  273. package/kits/physics-2d/play/behaviors/AnalogStick.js +198 -0
  274. package/kits/physics-2d/play/behaviors/Camera.js +40 -0
  275. package/kits/physics-2d/play/behaviors/Collider.js +122 -0
  276. package/kits/physics-2d/play/behaviors/Draggable.js +115 -0
  277. package/kits/physics-2d/play/behaviors/Goal.js +46 -0
  278. package/kits/physics-2d/play/behaviors/Joints.js +126 -0
  279. package/kits/physics-2d/play/behaviors/Layout.js +71 -0
  280. package/kits/physics-2d/play/behaviors/RigidBody.js +57 -0
  281. package/kits/physics-2d/play/behaviors/Slingshot.js +142 -0
  282. package/kits/physics-2d/play/behaviors/SoundPlayer.js +263 -0
  283. package/kits/physics-2d/play/behaviors/Sprite.js +406 -0
  284. package/kits/physics-2d/play/behaviors/Style.js +209 -0
  285. package/kits/physics-2d/play/behaviors/Text.js +85 -0
  286. package/kits/physics-2d/play/behaviors/Video.js +93 -0
  287. package/kits/physics-3d/CLAUDE.md +25 -1651
  288. package/kits/physics-3d/behaviors/Body.jsx +3 -0
  289. package/kits/physics-3d/behaviors/Model.jsx +3 -0
  290. package/kits/physics-3d/behaviors/Player.jsx +35 -18
  291. package/kits/physics-3d/behaviors/Shape.jsx +3 -0
  292. package/kits/physics-3d/behaviors/Solid.jsx +3 -0
  293. package/kits/physics-3d/behaviors/Transform.jsx +3 -0
  294. package/kits/physics-3d/castle.json +3 -3
  295. package/kits/physics-3d/docs/engine-camera.md +542 -0
  296. package/kits/physics-3d/docs/engine-frame-cap.md +136 -0
  297. package/kits/physics-3d/docs/engine-load.md +149 -0
  298. package/kits/physics-3d/docs/engine-look.md +114 -0
  299. package/kits/physics-3d/docs/engine-shadows.md +372 -0
  300. package/kits/physics-3d/docs/engine-skip-work.md +187 -0
  301. package/kits/physics-3d/docs/engine-sky.md +198 -0
  302. package/kits/physics-3d/docs/engine-static-actors.md +226 -0
  303. package/kits/physics-3d/docs/engine-view.md +37 -0
  304. package/kits/physics-3d/docs/pxmodel-format.md +1 -1
  305. package/kits/physics-3d/engine3d/PlayOnly3D.jsx +5 -1
  306. package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +19 -333
  307. package/kits/physics-3d/engine3d/actornode.js +1 -0
  308. package/kits/physics-3d/engine3d/branches.js +3 -13
  309. package/kits/physics-3d/engine3d/cage.js +2 -7
  310. package/kits/physics-3d/engine3d/cageops.js +2 -17
  311. package/kits/physics-3d/engine3d/dataBehaviors.js +12 -0
  312. package/kits/physics-3d/engine3d/framecap.js +4 -1
  313. package/kits/physics-3d/engine3d/frozenphysics.js +140 -0
  314. package/kits/physics-3d/engine3d/frozenstatics.js +273 -0
  315. package/kits/physics-3d/engine3d/gait.js +8 -0
  316. package/kits/physics-3d/engine3d/initialModelFiles.js +18 -0
  317. package/kits/physics-3d/engine3d/look.js +7 -0
  318. package/kits/physics-3d/engine3d/modelFiles.js +3 -17
  319. package/kits/physics-3d/engine3d/modelMath.js +49 -0
  320. package/kits/physics-3d/engine3d/modelready.js +16 -0
  321. package/kits/physics-3d/engine3d/motion.js +3 -3
  322. package/kits/physics-3d/engine3d/nearshadows.js +77 -10
  323. package/kits/physics-3d/engine3d/orbitinput.js +59 -25
  324. package/kits/physics-3d/engine3d/partgeometry.js +1 -16
  325. package/kits/physics-3d/engine3d/paths.js +1 -9
  326. package/kits/physics-3d/engine3d/playTimings.js +50 -0
  327. package/kits/physics-3d/engine3d/playerRun.js +372 -0
  328. package/kits/physics-3d/engine3d/pxmodel.js +3 -3
  329. package/kits/physics-3d/engine3d/rapier.js +27 -0
  330. package/kits/physics-3d/engine3d/scatter.js +1 -11
  331. package/kits/physics-3d/engine3d/shadowfade.js +23 -15
  332. package/kits/physics-3d/engine3d/sky.js +1 -1
  333. package/kits/physics-3d/engine3d/squarefirst.js +177 -0
  334. package/kits/physics-3d/engine3d/stillshadows.js +399 -0
  335. package/kits/physics-3d/engine3d/sweep.js +1 -25
  336. package/kits/physics-3d/engine3d/world3d.js +468 -18
  337. package/kits/physics-3d/eslint.config.js +2 -1
  338. package/kits/physics-3d/main.jsx +6 -3
  339. package/kits/physics-3d/package-lock.json +7 -0
  340. package/kits/physics-3d/package.json +5 -1
  341. package/kits/physics-3d/play/behaviors/Body.js +31 -0
  342. package/kits/physics-3d/play/behaviors/Door.js +37 -0
  343. package/kits/physics-3d/play/behaviors/Lookable.js +16 -0
  344. package/kits/physics-3d/play/behaviors/Model.js +23 -0
  345. package/kits/physics-3d/play/behaviors/Pickup.js +46 -0
  346. package/kits/physics-3d/play/behaviors/Player.js +1204 -0
  347. package/kits/physics-3d/play/behaviors/Shape.js +47 -0
  348. package/kits/physics-3d/play/behaviors/Solid.js +16 -0
  349. package/kits/physics-3d/play/behaviors/Transform.js +29 -0
  350. package/kits/physics-3d/pnpm-lock.yaml +8 -0
  351. package/kits/physics-3d/scripts/bench-shadow-fade.mjs +37 -0
  352. package/kits/physics-3d/scripts/build-rapier-gz.mjs +56 -0
  353. package/kits/physics-3d/scripts/frozen-statics-fixture.mjs +141 -0
  354. package/kits/physics-3d/scripts/test-camera-follow.mjs +5 -1
  355. package/kits/physics-3d/scripts/test-camera-orbit.mjs +52 -4
  356. package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +1 -1
  357. package/kits/physics-3d/scripts/test-empty-gait-hints.mjs +89 -0
  358. package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +6 -3
  359. package/kits/physics-3d/scripts/test-frame-cap.mjs +1 -1
  360. package/kits/physics-3d/scripts/test-frozen-nested.mjs +49 -0
  361. package/kits/physics-3d/scripts/test-frozen-statics-legacy-physics2d.mjs +123 -0
  362. package/kits/physics-3d/scripts/test-frozen-statics.mjs +434 -0
  363. package/kits/physics-3d/scripts/test-look-bake.mjs +1 -1
  364. package/kits/physics-3d/scripts/test-near-shadows.mjs +2 -2
  365. package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +88 -7
  366. package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +40 -3
  367. package/kits/physics-3d/scripts/test-orbit-shot.mjs +75 -1
  368. package/kits/physics-3d/scripts/test-rapier-gz.mjs +106 -0
  369. package/kits/physics-3d/scripts/test-sky.mjs +1 -1
  370. package/kits/physics-3d/scripts/test-square-first.mjs +921 -0
  371. package/kits/physics-3d/scripts/test-static-actors.mjs +3 -1
  372. package/kits/physics-3d/scripts/test-static-physics.mjs +4 -1
  373. package/kits/physics-3d/scripts/test-static-scenery.mjs +5 -2
  374. package/kits/physics-3d/scripts/test-steady-hover.mjs +5 -2
  375. package/kits/physics-3d/scripts/test-still-shadows.mjs +477 -0
  376. package/kits/physics-3d/systems/physics3d.js +37 -4
  377. package/kits/real-time/castle.json +2 -2
  378. package/kits/real-time/code/client/connection.js +33 -10
  379. package/kits/real-time/code/client/gameHooks.js +2 -0
  380. package/kits/real-time/code/client/joinOverlay.js +9 -4
  381. package/kits/real-time/code/server/session.js +6 -4
  382. package/kits/real-time/package-lock.json +1 -1
  383. package/package.json +2 -2
@@ -9,7 +9,7 @@
9
9
  import assert from 'node:assert/strict';
10
10
  import { register } from 'node:module';
11
11
 
12
- const sdkStub = 'export const Hub = globalThis.__tripHub; export const User = { getCurrent: async () => { globalThis.__yoursUserReads = (globalThis.__yoursUserReads ?? 0) + 1; return { userId: \"101\", isAnonymous: false }; } };';
12
+ const sdkStub = 'export const Hub = globalThis.__tripHub; export const User = { getCurrent: async () => { globalThis.__yoursUserReads = (globalThis.__yoursUserReads ?? 0) + 1; return globalThis.__tripUser ? globalThis.__tripUser() : { userId: \"101\", isAnonymous: false }; } };';
13
13
  const packStub = `
14
14
  export const loadPack = (...args) => globalThis.__tripLoadPack(...args);
15
15
  export const cachedPacks = () => [];
@@ -21,9 +21,13 @@ const mediaStub = 'export const initialMedia = {}; export const playMedia = () =
21
21
  register(
22
22
  'data:text/javascript,' +
23
23
  encodeURIComponent(`
24
+ import { readFile } from 'node:fs/promises';
25
+ import { fileURLToPath } from 'node:url';
24
26
  export async function resolve(specifier, context, next) {
25
27
  if (['pxmodel', 'optimize', 'look', 'lookbake'].some((m) => specifier === '@imports/castle.physics-3d/engine3d/' + m)) return { url: ${JSON.stringify(new URL('./fixtures/engine-models-stub.mjs', import.meta.url).href)}, shortCircuit: true };
26
28
  if (specifier === '@imports/castle.physics-3d/engine3d/orbitlens.js') return { url: ${JSON.stringify(new URL('../../physics-3d/engine3d/orbitlens.js', import.meta.url).href)}, shortCircuit: true };
29
+ if (specifier === '@imports/castle.real-time/code/client/messages.js') return { url: ${JSON.stringify(new URL('../../real-time/code/client/messages.js', import.meta.url).href)}, shortCircuit: true };
30
+ if (specifier === '@imports/castle.multiplayer-3d/code/client/avatars.js') return { url: 'data:text/javascript,export const dropMissing = () => {};', shortCircuit: true };
27
31
  if (specifier === 'castle-web-sdk') {
28
32
  return { url: ${JSON.stringify('data:text/javascript,' + encodeURIComponent(sdkStub))}, shortCircuit: true };
29
33
  }
@@ -34,14 +38,21 @@ register(
34
38
  return { url: ${JSON.stringify('data:text/javascript,' + encodeURIComponent(packStub))}, shortCircuit: true };
35
39
  }
36
40
  return next(specifier, context);
41
+ }
42
+ export async function load(url, context, next) {
43
+ if (url.endsWith('/code/client/hookLayer.js')) {
44
+ const source = await readFile(fileURLToPath(url), 'utf8');
45
+ return { format: 'module', source: source.replaceAll('import.meta.glob(', '(() => ({}))('), shortCircuit: true };
46
+ }
47
+ return next(url, context);
37
48
  }`),
38
49
  );
39
50
 
40
51
  const calls = [];
41
52
  const answers = {};
42
53
  globalThis.__tripHub = {
43
- go: async (doorId) => {
44
- calls.push(['go', doorId]);
54
+ go: async (doorId, ...options) => {
55
+ calls.push(['go', doorId, ...options]);
45
56
  if (answers.goError) {
46
57
  throw Object.assign(new Error('refused'), { code: answers.goError });
47
58
  }
@@ -92,6 +103,8 @@ globalThis.__tripLoadPack = async (sha, url) => {
92
103
 
93
104
  const { installSystem, BANNED_TEXT } = await import('../code/systems/hub.js');
94
105
  const HubState = await import('../code/client/state.js');
106
+ const HookLayer = (await import('../code/client/hookLayer.js')).default;
107
+ const { packPlayer } = await import('../../multiplayer-3d/code/client/poses.js');
95
108
  const ShotClient = await import('../code/client/shot.js');
96
109
  const { receiveShot } = ShotClient;
97
110
  const clearShot = () => ShotClient.clearShot();
@@ -146,6 +159,288 @@ async function test(name, fn) {
146
159
  n += 1;
147
160
  }
148
161
 
162
+ await test('v1.125 same-id replay stays one invitation; a new identity receives a new occurrence', async () => {
163
+ const { system, scene } = setup();
164
+ const seen = cueChrome(system);
165
+ system.talk.reset = () => {};
166
+ const local = { id: 'me', components: { Transform: { x: 0, z: 0 } } };
167
+ system.scene = scene;
168
+ HubState.hub.place = { id: 'main', title: 'Town', result: null };
169
+ HookLayer.message(scene, { k: 'hub-party', members: null, away: 0, invite: { from: 'p2', username: 'bo' } });
170
+ system.drawChrome(scene, local, 0);
171
+ assert.equal(seen.ask?.kind, 'invite');
172
+ system.drawChrome(scene, local, 12_000);
173
+ assert.equal(seen.ask, null, 'the displayed invitation expires');
174
+ const first = HubState.hub.inviteOccurrence;
175
+ HookLayer.message(scene, { k: 'hub-party', members: null, away: 0, invite: { from: 'p2', username: 'bo' } });
176
+ system.drawChrome(scene, local, 30_000);
177
+ assert.equal(seen.ask, null, 'an indistinguishable same-id replay remains the expired observable offer');
178
+ assert.equal(HubState.hub.inviteOccurrence.n, first.n);
179
+
180
+ system.newIdentity();
181
+ assert.equal(HubState.hub.inviteOccurrence, null, 'the old identity cannot retain a server invitation');
182
+ HubState.hub.place = { id: 'main', title: 'Town', result: null };
183
+ HookLayer.message(scene, { k: 'hub-party', members: null, away: 0, invite: { from: 'p2', username: 'bo' } });
184
+ system.drawChrome(scene, local, 31_000);
185
+ assert.equal(seen.ask?.kind, 'invite', 'a later invitation to the new identity is a new offer');
186
+ assert.ok(HubState.hub.inviteOccurrence.n > first.n);
187
+ HubState.clear();
188
+ });
189
+
190
+ await test('v1.125 receipt-boundary clear then same-sender invite is a later occurrence before render', async () => {
191
+ const { system, scene } = setup();
192
+ try {
193
+ HubState.clear();
194
+ HookLayer.message(scene, { k: 'hub-party', invite: { from: 'p2', username: 'bo' } });
195
+ const first = system.ask();
196
+ HookLayer.message(scene, { k: 'hub-party', invite: null });
197
+ HookLayer.message(scene, { k: 'hub-party', invite: { from: 'p2', username: 'bo' } });
198
+ const later = system.ask();
199
+ assert.notEqual(later.key, first.key, 'the clear is observed even when neither packet rendered');
200
+ HookLayer.message(scene, { k: 'hub-party', invite: { from: 'p2', username: 'bo' } });
201
+ assert.equal(system.ask().key, later.key, 'indistinguishable same-sender packets remain one observable offer');
202
+ } finally {
203
+ HubState.clear();
204
+ }
205
+ });
206
+
207
+ await test('a returned ask placement latches only after hub-arrived and an own clamp or later WORLD', () => {
208
+ const scene = { files: {} };
209
+ const system = { net: { selfId: () => 'me' } };
210
+ const playerRow = (id, clamped) => JSON.parse(JSON.stringify([
211
+ id,
212
+ ...packPlayer({ x: 0.9, y: 0, z: -1.4 }, 0, clamped),
213
+ ]));
214
+ HubState.clear();
215
+ HookLayer.state(scene, { k: 'w', ps: [playerRow('me', false)] }, system);
216
+ assert.equal(HubState.hub.arrivalPlaced, false, 'the session\'s initial WORLD is not an arrival placement');
217
+ HookLayer.message(scene, { k: 'hub-arrived', facing: 0 });
218
+ HookLayer.state(scene, { ps: [playerRow('other', true), playerRow('me', false)] }, system);
219
+ assert.equal(HubState.hub.arrivalPlaced, false, 'another player and an ordinary own row do not place this client');
220
+ const clamped = playerRow('me', true);
221
+ assert.equal(clamped[5], 1, 'the production wire packer serialises a clamp as numeric 1');
222
+ HookLayer.state(scene, { ps: [clamped] }, system);
223
+ assert.equal(HubState.hub.arrivalPlaced, true, 'the post-arrived numeric wire clamp is authoritative');
224
+
225
+ HubState.clear();
226
+ HookLayer.message(scene, { k: 'hub-arrived', facing: 0 });
227
+ HookLayer.state(scene, { k: 'w', ps: [playerRow('me', false)] }, system);
228
+ assert.equal(HubState.hub.arrivalPlaced, true, 'a later WORLD after hub-arrived is authoritative on reconnect');
229
+ HubState.clear();
230
+ });
231
+
232
+ await test('v1.125 new identity preserves an expired Your games occurrence', async () => {
233
+ const { system, scene } = setup();
234
+ system.scene = scene;
235
+ const before = { key: 'yours:before', slotKey: 'yours:4:return:1', kind: 'yours' };
236
+ const redrawn = { key: 'yours:after', slotKey: before.slotKey, kind: 'yours' };
237
+ system.askSlot.display(before, { x: 0, z: 0 }, new Set(), 0);
238
+ system.askSlot.frame({ x: 0, z: 0 }, new Set(), 12_000);
239
+ system.newIdentity();
240
+ assert.equal(system.askSlot.display(redrawn, { x: 0, z: 0 }, new Set(), 30_000), null);
241
+ HubState.clear();
242
+ });
243
+
244
+ await test('v1.125 a stale card tap sends nothing after another ask takes the slot', async () => {
245
+ const { system, scene } = setup();
246
+ const sent = [];
247
+ scene.multiplayer.net = { send: (msg) => sent.push(msg) };
248
+ scene.actorWith = () => ({ components: { Transform: { x: 0, z: 0 } } });
249
+ system.talk = { talking: () => false };
250
+ HubState.hub.place = { title: 'Town', result: null };
251
+ HubState.hub.doors = [{ id: 'race', title: 'Foot Race' }];
252
+ HubState.hub.party = { members: null, away: 0, invite: null, proposal: null };
253
+ system.playAsk = { from: 'p2', name: 'bo', door: 'race', until: performance.now() + 20_000 };
254
+ const stale = system.ask();
255
+ system.askSlot.display(stale, { x: 0, z: 0 }, new Set(), performance.now());
256
+ HubState.hub.party.proposal = { id: 9, door: 'race', by: 'p3', username: 'dee', asked: true };
257
+ system.answer(scene, stale, true, true);
258
+ assert.deepEqual(sent, [], 'the old play action cannot jump after a proposal replaces it');
259
+ HubState.clear();
260
+ });
261
+
262
+ await test('v1.125 higher-priority chrome delays first display without pausing a shown lease', async () => {
263
+ try {
264
+ HubState.clear();
265
+ const { system, scene } = setup();
266
+ const seen = cueChrome(system);
267
+ const sent = [];
268
+ scene.multiplayer.net = { send: (msg) => sent.push(msg), others: () => new Map(), selfId: () => 'me' };
269
+ HubState.hub.place = { id: 'main', title: 'Town', result: null };
270
+ HubState.hub.doors = [{ id: 'race', title: 'Foot Race' }];
271
+ const local = { id: 'me', components: { Transform: { x: 0, z: 0 } } };
272
+ system.playAsk = { from: 'p2', name: 'bo', door: 'race', until: 60_000 };
273
+
274
+ for (const field of ['askInput', 'menuInput', 'actionInput']) {
275
+ system[field] = {};
276
+ system.drawChrome(scene, local, 1_000);
277
+ assert.equal(seen.ask, null, `${field} shields the shared ask`);
278
+ delete system[field];
279
+ }
280
+ system.decor = { opened: () => true };
281
+ system.drawChrome(scene, local, 8_000);
282
+ assert.equal(seen.ask, null, 'decorating shields the shared ask');
283
+ system.decor = { opened: () => false };
284
+ system.drawChrome(scene, local, 9_000);
285
+ assert.equal(seen.ask?.kind, 'play', 'lease starts when chrome can first display the card');
286
+
287
+ system.actionInput = {};
288
+ system.drawChrome(scene, local, 20_999);
289
+ assert.equal(seen.ask, null, 'shown card is covered while the action shield is open');
290
+ delete system.actionInput;
291
+ system.drawChrome(scene, local, 21_000);
292
+ assert.equal(seen.ask, null, 'covering a shown card does not pause its 12-second lease');
293
+ assert.deepEqual(sent, [], 'passive expiry emits no decline or other wire message');
294
+ } finally {
295
+ HubState.clear();
296
+ }
297
+ });
298
+
299
+ await test('v1.125 a hidden or suspended page starts no lease before the card can display', async () => {
300
+ try {
301
+ HubState.clear();
302
+ const { system, scene } = setup();
303
+ const seen = cueChrome(system);
304
+ let showable = false;
305
+ system.chrome.askShowable = () => showable;
306
+ scene.multiplayer.net = { send() {}, others: () => new Map(), selfId: () => 'me' };
307
+ HubState.hub.place = { id: 'main', title: 'Town', result: null };
308
+ HubState.hub.doors = [{ id: 'race', title: 'Foot Race' }];
309
+ const local = { id: 'me', components: { Transform: { x: 0, z: 0 } } };
310
+ system.playAsk = { from: 'p2', name: 'bo', door: 'race', until: 60_000 };
311
+ system.drawChrome(scene, local, 0);
312
+ assert.equal(seen.ask, null, 'nothing is drawn on a hidden page');
313
+ assert.equal(system.askSlot.known(system.ask(0)), false, 'a hidden frame starts no lease');
314
+ showable = true;
315
+ system.drawChrome(scene, local, 12_000);
316
+ assert.equal(seen.ask?.kind, 'play', 'foregrounding at 12 s shows the unseen offer');
317
+ system.drawChrome(scene, local, 23_999);
318
+ assert.equal(seen.ask?.kind, 'play', 'its lease starts at that first actual display');
319
+ showable = false;
320
+ system.drawChrome(scene, local, 24_000);
321
+ showable = true;
322
+ system.drawChrome(scene, local, 24_001);
323
+ assert.equal(seen.ask, null, 'a hidden page still ages a lease that was already shown');
324
+ } finally {
325
+ HubState.clear();
326
+ }
327
+ });
328
+
329
+ await test('v1.125 a tap on a redrawn Your games presentation keeps the live lease', async () => {
330
+ const oldYours = HubState.deck.yourGames;
331
+ const savedPerformance = globalThis.performance;
332
+ try {
333
+ HubState.clear();
334
+ HubState.deck.yourGames = true;
335
+ let now = 1_000;
336
+ globalThis.performance = { now: () => now };
337
+ const { system, scene } = setup();
338
+ scene.multiplayer.net = { send() {} };
339
+ scene.actorWith = () => ({ components: { Transform: { x: 0, z: 0 } } });
340
+ system.talk = { talking: () => false };
341
+ HubState.hub.place = { id: 'main', title: 'Town', result: null };
342
+ const drawn = { key: 'yours:s1:house::', slotKey: 's1', kind: 'yours', door: 'house', yes: 'Go', no: 'Not now' };
343
+ let card = drawn;
344
+ let dismissed = 0;
345
+ system.yours = { ask: () => card, dismiss() { dismissed += 1; } };
346
+ system.askSlot.display(drawn, { x: 0, z: 0 }, new Set(), now);
347
+ card = { ...drawn, key: 'yours:s1:house:house:' };
348
+ now = 2_000;
349
+ system.answer(scene, drawn, false, true);
350
+ assert.equal(dismissed, 0, 'a stale presentation is not acted on');
351
+ assert.equal(system.askSlot.expired(drawn), false, 'and does not consume the lease');
352
+ system.answer(scene, card, false, true);
353
+ assert.equal(dismissed, 1, 'a tap on the current presentation still answers the offer');
354
+ assert.equal(system.askSlot.expired(card), true);
355
+ } finally {
356
+ globalThis.performance = savedPerformance;
357
+ HubState.deck.yourGames = oldYours;
358
+ HubState.clear();
359
+ }
360
+ });
361
+
362
+ await test('v1.125 an ask-card heart honours the lease', async () => {
363
+ const oldYours = HubState.deck.yourGames;
364
+ const savedPerformance = globalThis.performance;
365
+ try {
366
+ HubState.clear();
367
+ HubState.deck.yourGames = true;
368
+ let now = 1_000;
369
+ globalThis.performance = { now: () => now };
370
+ const { system, scene } = setup();
371
+ scene.actorWith = () => ({ components: { Transform: { x: 0, z: 0 } } });
372
+ system.talk = { talking: () => false };
373
+ HubState.hub.place = { id: 'main', title: 'Town', result: null };
374
+ const card = { key: 'yours:s1:house::', slotKey: 's1', kind: 'yours', door: 'house', heart: false, yes: 'Go', no: 'Not now' };
375
+ const toggled = [];
376
+ system.yours = { ask: () => card, dismiss() {}, toggle: (door) => toggled.push(door) };
377
+ system.askSlot.display(card, { x: 0, z: 0 }, new Set(), now);
378
+ now = 12_999;
379
+ system.heartAsk(scene, card, 'house');
380
+ assert.deepEqual(toggled, ['house'], 'a heart inside the lease toggles');
381
+ assert.equal(system.askSlot.expired(card), false, 'a heart does not consume the card');
382
+ system.heartAsk(scene, card, 'other');
383
+ assert.deepEqual(toggled, ['house'], 'only the door the card names');
384
+ now = 13_000;
385
+ system.heartAsk(scene, card, 'house');
386
+ assert.deepEqual(toggled, ['house'], 'a heart at the expiry boundary changes nothing');
387
+ } finally {
388
+ globalThis.performance = savedPerformance;
389
+ HubState.deck.yourGames = oldYours;
390
+ HubState.clear();
391
+ }
392
+ });
393
+
394
+ await test('v1.125 play, follow and Play again deadlines are pending-only after first display', async () => {
395
+ const oldCues = HubState.deck.cues;
396
+ const oldYours = HubState.deck.yourGames;
397
+ const savedPerformance = globalThis.performance;
398
+ try {
399
+ HubState.deck.cues = true;
400
+ HubState.deck.yourGames = false;
401
+ HubState.hub.place = { id: 'main', title: 'Town', result: null };
402
+ HubState.hub.doors = [{ id: 'race', title: 'Foot Race' }];
403
+ for (const kind of ['play', 'follow', 'again']) {
404
+ const { system } = setup();
405
+ if (kind === 'again') {
406
+ system.againAsk = { door: 'race', until: 20_000 };
407
+ } else {
408
+ system.playAsk = { from: 'p2', name: 'bo', door: 'race', until: 20_000, ...(kind === 'follow' ? { went: true } : {}) };
409
+ }
410
+ const card = system.ask(15_000);
411
+ assert.equal(card.kind, kind === 'again' ? 'again' : 'play');
412
+ system.askSlot.display(card, { x: 0, z: 0 }, new Set(), 15_000);
413
+ assert.equal(system.ask(26_999)?.key, card.key, `${kind} survives its producer deadline`);
414
+ assert.equal(system.askSlot.accepts(card, { x: 0, z: 0 }, new Set(), 26_999), true, `${kind} remains actionable for the full lease`);
415
+ assert.equal(system.askSlot.accepts(card, { x: 0, z: 0 }, new Set(), 27_000), false, `${kind} expires at first display plus 12 seconds`);
416
+ system.retireExpiredAsk(system.ask(27_000));
417
+ assert.equal(kind === 'again' ? system.againAsk : system.playAsk, null, `${kind} source retires without resurrection`);
418
+ }
419
+ const { system } = setup();
420
+ system.playAsk = { from: 'p2', name: 'bo', door: 'race', until: 20_000 };
421
+ assert.equal(system.ask(20_000), null, 'an undisplayed pending offer still ends at its producer deadline');
422
+
423
+ let now = 26_999;
424
+ globalThis.performance = { now: () => now };
425
+ const active = setup();
426
+ const sent = [];
427
+ active.scene.multiplayer.net = { send: (msg) => sent.push(msg) };
428
+ active.scene.actorWith = () => ({ components: { Transform: { x: 0, z: 0 } } });
429
+ active.system.talk = { talking: () => false };
430
+ active.system.jumpSentAt = -Infinity;
431
+ active.system.playAsk = { from: 'p2', name: 'bo', door: 'race', until: 20_000 };
432
+ const actionable = active.system.ask(15_000);
433
+ active.system.askSlot.display(actionable, { x: 0, z: 0 }, new Set(), 15_000);
434
+ active.system.answer(active.scene, actionable, true, true);
435
+ assert.deepEqual(sent, [{ k: 'hub-door-jump', door: 'race' }], 'the action still works after the producer deadline and before lease expiry');
436
+ } finally {
437
+ globalThis.performance = savedPerformance;
438
+ HubState.deck.cues = oldCues;
439
+ HubState.deck.yourGames = oldYours;
440
+ HubState.clear();
441
+ }
442
+ });
443
+
149
444
  await test('a fired pad is Hub.go, then the pack the handoff names, then a hub join', async () => {
150
445
  const { system, scene } = setup();
151
446
  answers.go = handoff();
@@ -475,6 +770,45 @@ await test('a place behind a door whose server is replaced under a player: left
475
770
  assert.equal(r.system.toast.text, 'The game ended');
476
771
  assert.deepEqual(r.switched, []);
477
772
 
773
+ // A game that ended while the player was away, seen as they come back: the
774
+ // multiplayer kit's cover is up over the place as it was, so the way back
775
+ // starts under the trip's cover, fully down in that same frame, rather than
776
+ // playing the door beat over the old scene.
777
+ for (const place of [{ title: 'Foot Race', result: {} }, { title: 'Pebble Cove' }]) {
778
+ const { system, scene } = setup();
779
+ const covers = [];
780
+ system.chrome.setCover = (...args) => covers.push(args[0]);
781
+ scene.multiplayer = { ...mpStub(scene), net: null, returning: () => true };
782
+ scene.multiplayer.target = { mode: 'hub', handoff: { sessionId: 'cove-1' } };
783
+ scene.persistent.hubDepth = 1;
784
+ scene.persistent.hubTickets = [{ scene: 'scenes/main.scene', title: 'Town', door: 'cove', hub: true, join: { mode: 'public' } }];
785
+ HubState.hub.place = place;
786
+ answers.back = handoff();
787
+ system.lastNet = closedNet();
788
+ system.watchSession(scene, scene.multiplayer);
789
+ assert.ok(system.trip, `${place.title}: on its way back`);
790
+ system.stepTrip(scene, scene.multiplayer, null, performance.now());
791
+ assert.equal(covers[0], 1, `${place.title}: the first cover drawn is fully down`);
792
+ await flush();
793
+ }
794
+ // Not returning: the beat plays, and the cover comes down over it.
795
+ {
796
+ const { system, scene } = setup();
797
+ const covers = [];
798
+ system.chrome.setCover = (...args) => covers.push(args[0]);
799
+ scene.multiplayer = { ...mpStub(scene), net: null, returning: () => false };
800
+ scene.multiplayer.target = { mode: 'hub', handoff: { sessionId: 'cove-1' } };
801
+ scene.persistent.hubDepth = 1;
802
+ scene.persistent.hubTickets = [{ scene: 'scenes/main.scene', title: 'Town', door: 'cove', hub: true, join: { mode: 'public' } }];
803
+ HubState.hub.place = { title: 'Foot Race', result: {} };
804
+ answers.back = handoff();
805
+ system.lastNet = closedNet();
806
+ system.watchSession(scene, scene.multiplayer);
807
+ system.stepTrip(scene, scene.multiplayer, null, performance.now());
808
+ assert.equal(covers[0], 0, 'the beat starts uncovered');
809
+ await flush();
810
+ }
811
+
478
812
  // Barred from the hub: nothing is asked.
479
813
  r = run({ error: 'CAULDRON_HUB_BANNED' });
480
814
  await flush();
@@ -518,6 +852,46 @@ await test("a game's end waits out a pending join, settles once it resolves else
518
852
  assert.notEqual(system.pendingEnd, null);
519
853
  });
520
854
 
855
+ await test("a game's end that meets a player coming back from away leaves at once, under the cover", async () => {
856
+ for (const returning of [true, false]) {
857
+ const { system, scene } = setup();
858
+ const backs = [];
859
+ system.back = (_scene, opts) => backs.push(opts ?? {});
860
+ Object.assign(scene.multiplayer, { joinState: () => 'joined', net: null, placed: () => false, returning: () => returning, target: { mode: 'named', key: 'game' } });
861
+ HubState.hub.commands.push({ k: 'hub-end', why: 'end' });
862
+ system.runCommands(scene, 1000);
863
+ system.stepEnd(scene, scene.multiplayer, 1000);
864
+ if (returning) {
865
+ assert.deepEqual(backs, [{ covered: true }], 'no end pause, and no beat over the old place');
866
+ } else {
867
+ assert.deepEqual(backs, [], 'the end pause first');
868
+ system.stepEnd(scene, scene.multiplayer, system.pendingEnd);
869
+ assert.deepEqual(backs, [{ covered: false }]);
870
+ }
871
+ }
872
+ });
873
+
874
+ await test('a returning game with no ticket (a fresh instance, or a town root) also leaves under the cover', async () => {
875
+ for (const place of [{ id: 'race', title: 'Foot Race', result: {} }, { id: 'main', title: 'Town' }]) {
876
+ const { system, scene } = setup();
877
+ const covers = [];
878
+ system.chrome.setCover = (...args) => covers.push(args[0]);
879
+ scene.multiplayer = { ...mpStub(scene), net: null, joinState: () => 'joined', returning: () => true };
880
+ scene.multiplayer.target = { mode: 'named', key: 'game' };
881
+ scene.persistent.hubTickets = [];
882
+ HubState.hub.place = place;
883
+ HubState.hub.commands.push({ k: 'hub-end', why: 'end' });
884
+ const now = performance.now();
885
+ system.runCommands(scene, now);
886
+ system.stepEnd(scene, scene.multiplayer, now);
887
+ assert.ok(system.trip, `${place.title}: on its way`);
888
+ system.stepTrip(scene, scene.multiplayer, null, performance.now());
889
+ assert.equal(covers[0], 1, `${place.title}: the first cover drawn is fully down`);
890
+ await flush();
891
+ }
892
+ HubState.hub.place = null;
893
+ });
894
+
521
895
  await test('with no ticket in a place joined by a hub trip, Hub.back leads wherever ghost says', async () => {
522
896
  const { system, scene } = setup();
523
897
  scene.multiplayer.target = { mode: 'hub', handoff: handoff() };
@@ -553,7 +927,7 @@ function mpStub(scene, state = 'joining') {
553
927
  // Through the opening, to the moment the trip switches sessions.
554
928
  async function toSwitch(system, scene, mp) {
555
929
  await flush();
556
- system.trip.startedAt -= 10000;
930
+ system.trip.startedAt = -10000;
557
931
  system.stepTrip(scene, mp, null, 0);
558
932
  }
559
933
 
@@ -1028,13 +1402,112 @@ await test('a failed door at the root of the trail rejoins the join the runtime
1028
1402
  assert.deepEqual(calls.map((c) => c[0]), ['go', 'loadPack']);
1029
1403
  });
1030
1404
 
1031
- await test('Back at the root of the trail is not Hub.back', async () => {
1032
- const { system, scene } = setup();
1033
- scene.multiplayer.target = { mode: 'hub', handoff: handoff({ nonce: 'spent' }) };
1034
- scene.persistent.hubDepth = 0;
1035
- system.back(scene);
1036
- assert.equal(system.trip.target.join.mode, 'named');
1037
- assert.deepEqual(calls, []);
1405
+ await test('Back at a town root without a ticket rejoins the root join, or public when unset', async () => {
1406
+ const place = HubState.hub.place;
1407
+ const quiet = console.warn;
1408
+ try {
1409
+ for (const town of [{ id: 'main', title: 'Town' }, null]) {
1410
+ for (const root of [{ mode: 'public', destination: { routeId: 'town', slot: 'main' } }, undefined]) {
1411
+ const { system, scene } = setup();
1412
+ HubState.hub.place = town;
1413
+ scene.multiplayer.target = { mode: 'hub', handoff: handoff({ nonce: 'spent' }) };
1414
+ scene.persistent.hubDepth = 0;
1415
+ scene.persistent.hubRootJoin = root;
1416
+ const warnings = [];
1417
+ console.warn = (...args) => warnings.push(args);
1418
+ system.back(scene, { lost: 1 });
1419
+ assert.deepEqual(system.trip.target.join, root ?? { mode: 'public' });
1420
+ if (root) assert.equal(system.trip.target.join, root);
1421
+ assert.notEqual(system.trip.target.join.mode, 'named');
1422
+ assert.equal(system.trip.target.scene, system.scenePath);
1423
+ assert.equal(system.trip.target.title, town?.title ?? '');
1424
+ assert.equal(system.trip.target.exitDoor, null);
1425
+ assert.deepEqual(system.trip.target.arrive, { door: null, party: 1, returning: false });
1426
+ assert.equal(system.trip.target.lost, 1);
1427
+ assert.match(warnings[0][0], /town root without a ticket/);
1428
+ assert.match(warnings[0][1], /HubSystem.back/);
1429
+ assert.deepEqual(calls, []);
1430
+ }
1431
+ }
1432
+ } finally {
1433
+ HubState.hub.place = place;
1434
+ console.warn = quiet;
1435
+ }
1436
+ });
1437
+
1438
+ await test('Back at a game root without a ticket still starts a fresh named round', async () => {
1439
+ const place = HubState.hub.place;
1440
+ try {
1441
+ for (const prefix of ['', 'deck:race/']) {
1442
+ const { system, scene } = setup();
1443
+ HubState.hub.place = { id: 'race', title: 'Race', result: {} };
1444
+ scene.content = { sessionKeyPrefix: prefix };
1445
+ scene.persistent.hubDepth = 0;
1446
+ scene.persistent.hubRootJoin = { mode: 'public' };
1447
+ system.back(scene);
1448
+ assert.equal(system.trip.target.join.mode, 'named');
1449
+ assert.ok(system.trip.target.join.key.startsWith(`${prefix}hub.race.`));
1450
+ assert.match(system.trip.target.join.key.slice(`${prefix}hub.race.`.length), /^[a-z0-9]+$/);
1451
+ assert.deepEqual(calls, []);
1452
+ }
1453
+ } finally {
1454
+ HubState.hub.place = place;
1455
+ }
1456
+ });
1457
+
1458
+ await test('Back at a town root settles an ended town visit, so the end does not send the player Back again', async () => {
1459
+ const place = HubState.hub.place;
1460
+ const quiet = console.warn;
1461
+ try {
1462
+ console.warn = () => {};
1463
+ const { system, scene } = setup();
1464
+ HubState.hub.place = { id: 'main', title: 'Town' };
1465
+ scene.multiplayer.target = { mode: 'public' };
1466
+ scene.persistent.hubDepth = 0;
1467
+ system.pendingEnd = 1;
1468
+ system.endSession = 'public:';
1469
+ system.back(scene);
1470
+ assert.deepEqual(system.trip.target.join, { mode: 'public' });
1471
+ assert.equal(system.pendingEnd, null);
1472
+ assert.equal(system.endSession, null);
1473
+ } finally {
1474
+ HubState.hub.place = place;
1475
+ console.warn = quiet;
1476
+ }
1477
+ });
1478
+
1479
+ await test('Back at a game root whose place a close cleared is still a fresh named round', async () => {
1480
+ const place = HubState.hub.place;
1481
+ try {
1482
+ const { system, scene } = setup();
1483
+ HubState.hub.place = null;
1484
+ system.knownPlace = { id: 'race', title: 'Race', result: {} };
1485
+ scene.multiplayer.target = { mode: 'public' };
1486
+ scene.persistent.hubDepth = 0;
1487
+ scene.persistent.hubRootJoin = { mode: 'public' };
1488
+ system.back(scene);
1489
+ assert.equal(system.trip.target.join.mode, 'named');
1490
+ assert.deepEqual(calls, []);
1491
+ } finally {
1492
+ HubState.hub.place = place;
1493
+ }
1494
+ });
1495
+
1496
+ await test('Back at a town root joined by a named key (a dev place) keeps the fresh named place', async () => {
1497
+ const place = HubState.hub.place;
1498
+ try {
1499
+ const { system, scene } = setup();
1500
+ HubState.hub.place = { id: 'main', title: 'Town' };
1501
+ scene.multiplayer.target = { mode: 'named', key: 'hub.main.original' };
1502
+ scene.persistent.hubDepth = 0;
1503
+ scene.persistent.hubRootJoin = { mode: 'public' };
1504
+ system.back(scene);
1505
+ assert.equal(system.trip.target.join.mode, 'named');
1506
+ assert.match(system.trip.target.join.key, /^hub\.main\.[a-z0-9]+$/);
1507
+ assert.deepEqual(calls, []);
1508
+ } finally {
1509
+ HubState.hub.place = place;
1510
+ }
1038
1511
  });
1039
1512
 
1040
1513
  await test('the root join is remembered at the first hub trip only', async () => {
@@ -1413,6 +1886,143 @@ await test('People: a game lists who may be reported, only where the host runs t
1413
1886
  HubState.hub.whereAt = {};
1414
1887
  });
1415
1888
 
1889
+ await test('People: Join on a friend at home in their House goes through the House door with the owner; other friends keep the door jump', async () => {
1890
+ const { system, scene } = setup();
1891
+ const sent = [];
1892
+ scene.multiplayer.net = { others: () => new Map(), userId: () => null, send: (msg) => sent.push(msg) };
1893
+ HubState.hub.place = { title: 'Town', result: null };
1894
+ HubState.hub.doors = [{ id: 'race', title: 'Foot Race' }, { id: 'home-1', title: 'Your House' }];
1895
+ const friends = [
1896
+ { userId: '13', username: 'fay', here: false, door: 'home-1', home: true, ownerUserId: '13' },
1897
+ { userId: '11', username: 'dee', here: false, door: 'race' },
1898
+ // A host that predates owners: no home, so the pad, as before.
1899
+ { userId: '14', username: 'gus', here: false, door: 'home-1' },
1900
+ { userId: '15', username: 'hal', here: false, door: 'home-1', home: true, ownerUserId: 'not an id' },
1901
+ ];
1902
+ system.friendsAll = friends;
1903
+ const rows = system.people(scene, false);
1904
+ assert.deepEqual(
1905
+ rows.map((row) => [row.username, row.where, row.actions.map((a) => a.id).join(), row.door, row.owner ?? null]),
1906
+ [
1907
+ ['fay', "inside fay's House", 'door', 'home-1', '13'],
1908
+ ['dee', 'inside Foot Race', 'door', 'race', null],
1909
+ ['gus', 'inside Your House', 'door', 'home-1', null],
1910
+ ['hal', 'inside Your House', 'door', 'home-1', null],
1911
+ ],
1912
+ );
1913
+
1914
+ // Join asks the place, which ends the visit here as any door's trip does
1915
+ // and sends this player through with the owner (`hub-go` carrying it).
1916
+ system.join(scene, rows[0], 'door');
1917
+ assert.deepEqual(sent, [{ k: 'hub-house-visit', door: 'home-1', owner: '13' }], 'no walk to the pad');
1918
+ assert.equal(system.toast.text, "Going to fay's House");
1919
+ assert.equal(system.trip ?? null, null, 'nothing travels until the place says so');
1920
+ answers.go = handoff();
1921
+ system.goHub(scene, { k: 'hub-go', door: 'home-1', key: null, place: null, scene: null, title: 'Your House', party: 1, owner: '13' });
1922
+ await flush();
1923
+ assert.deepEqual(calls[0], ['go', 'home-1', { ownerUserId: '13' }], 'Hub.go names the owner');
1924
+ assert.equal(system.trip.target.retryOwner, '13', 'a retried acquisition keeps the owner');
1925
+ sent.length = 0;
1926
+
1927
+ // Not at home: the door jump, and Hub.go is never asked from here.
1928
+ const plain = setup();
1929
+ plain.scene.multiplayer.net = { others: () => new Map(), userId: () => null, send: (msg) => sent.push(msg) };
1930
+ plain.system.friendsAll = friends;
1931
+ const again = plain.system.people(plain.scene, false);
1932
+ plain.system.join(plain.scene, again[1], 'door');
1933
+ plain.system.jumpSentAt = -Infinity;
1934
+ plain.system.join(plain.scene, again[2], 'door');
1935
+ await flush();
1936
+ assert.deepEqual(sent, [{ k: 'hub-door-jump', door: 'race' }, { k: 'hub-door-jump', door: 'home-1' }]);
1937
+ assert.equal(calls.some(([c]) => c === 'go'), false);
1938
+ assert.equal(plain.system.trip ?? null, null);
1939
+ HubState.hub.place = null;
1940
+ HubState.hub.doors = [];
1941
+ });
1942
+
1943
+ await test('a door trip without an owner calls Hub.go with the door alone', async () => {
1944
+ const { system, scene } = setup();
1945
+ answers.go = handoff();
1946
+ system.goHub(scene, { door: 'home-1', key: null, title: 'Your House' });
1947
+ await flush();
1948
+ assert.deepEqual(calls[0], ['go', 'home-1']);
1949
+ assert.equal(system.trip.target.retryOwner, null);
1950
+ });
1951
+
1952
+ await test('v1.122 play cards: friends/party far, strangers near, bounded across doors', async () => {
1953
+ const { system } = setup();
1954
+ const oldPolicy = HubState.deck.playCards;
1955
+ const oldParty = HubState.hub.party;
1956
+ const oldDoors = HubState.hub.doors;
1957
+ const at = { p2: { x: 12, z: 0 }, p3: { x: 11, z: 0 } };
1958
+ const local = { components: { Transform: { x: 0, z: 0 } } };
1959
+ const scene = {
1960
+ multiplayer: {
1961
+ net: { userId: (id) => ({ p2: '102', p3: '103' })[id] },
1962
+ players: { get: (id) => at[id] ? { samples: [{ pose: [at[id].x, 1, at[id].z, 0] }] } : null },
1963
+ avatars: { actors: new Map([['p2', 'p2'], ['p3', 'p3']]) },
1964
+ },
1965
+ getActor: (id) => at[id] ? { components: { Transform: at[id] } } : null,
1966
+ };
1967
+ const offer = (id, door, now) => system.offerPlay(scene, local, now, id, id, door);
1968
+ try {
1969
+ HubState.deck.playCards = true;
1970
+ HubState.hub.party = { members: null, away: 0, invite: null, proposal: null };
1971
+ HubState.hub.doors = [{ id: 'race', title: 'Race' }, { id: 'tiles', title: 'Tiles' }];
1972
+ offer('p2', 'race', 1000);
1973
+ assert.equal(system.playAsk.from, 'p2', '12 m stranger included');
1974
+ const first = system.playAsk;
1975
+ offer('p3', 'tiles', 2000);
1976
+ assert.equal(system.playAsk, first, 'another stranger cannot replace the live card');
1977
+ offer('p2', 'tiles', 3000);
1978
+ assert.equal(system.playAsk, first, 'cycling doors cannot extend the card');
1979
+ system.playAsk = null; // Not now.
1980
+ offer('p2', 'tiles', 22000);
1981
+ assert.equal(system.playAsk, null, 'cooldown applies across doors after dismissal');
1982
+ offer('p2', 'tiles', 60999);
1983
+ assert.equal(system.playAsk, null);
1984
+ offer('p2', 'tiles', 61000);
1985
+ assert.equal(system.playAsk.door, 'tiles', '60 s permits another card');
1986
+ offer('p3', 'race', 81000);
1987
+ assert.equal(system.playAsk.from, 'p3', 'expiry frees the stranger slot');
1988
+ system.playAsk = null;
1989
+ // The rendered pose deliberately disagrees with the network position.
1990
+ scene.getActor = () => ({ components: { Transform: { x: 11.98, z: 0 } } });
1991
+ at.p2.x = 12.2;
1992
+ offer('p2', 'race', 150000);
1993
+ assert.equal(system.playAsk, null, 'far stranger refused');
1994
+ scene.getActor = () => ({ components: { Transform: { x: 12.2, z: 0 } } });
1995
+ at.p2.x = 11.98;
1996
+ offer('p2', 'race', 150001);
1997
+ assert.equal(system.playAsk.from, 'p2', 'near network pose wins over far rendered pose');
1998
+ system.playAsk = null;
1999
+ delete at.p2;
2000
+ offer('p2', 'race', 250001);
2001
+ assert.equal(system.playAsk, null, 'missing pose refused');
2002
+ at.p2 = { x: 500, z: 0 };
2003
+ system.friendsAll = [{ userId: 102, here: true }];
2004
+ offer('p2', 'race', 250002);
2005
+ assert.equal(system.playAsk.from, 'p2', 'mutual friend far included');
2006
+ assert.equal(system.playAsk.stranger, false);
2007
+ system.playAsk = null;
2008
+ system.friendsAll = [];
2009
+ HubState.hub.party.members = ['p2'];
2010
+ offer('p2', 'tiles', 250003);
2011
+ assert.equal(system.playAsk.from, 'p2', 'party member far included');
2012
+ system.playAsk = null;
2013
+ HubState.hub.party.members = null;
2014
+ HubState.deck.playCards = false;
2015
+ offer('p2', 'race', 350000);
2016
+ assert.deepEqual(system.playAsk, { from: 'p2', name: 'p2', door: 'race', until: 370000 }, 'keyless card shape and far policy unchanged');
2017
+ offer('p2', 'tiles', 350001);
2018
+ assert.equal(system.playAsk.door, 'tiles', 'keyless cooldown remains per door');
2019
+ } finally {
2020
+ HubState.deck.playCards = oldPolicy;
2021
+ HubState.hub.party = oldParty;
2022
+ HubState.hub.doors = oldDoors;
2023
+ }
2024
+ });
2025
+
1416
2026
  await test('a sent chat line says whom it reached', async () => {
1417
2027
  const { system } = setup();
1418
2028
  let status = 'sent';
@@ -2001,6 +2611,54 @@ await test('cues: the chat field says who reads it or why it is off, and chat pe
2001
2611
  }
2002
2612
  });
2003
2613
 
2614
+ // A guest (their own account is anonymous) is over 13 like any other player:
2615
+ // their chat field reads exactly what a signed-in player's does, on or off,
2616
+ // cues or not, in a town or behind a door, and in a place that names guests.
2617
+ await test('a guest\'s chat field reads what a signed-in player\'s does: no sign-in hint', async () => {
2618
+ const why = 'Typed chat is for friends who follow each other. Emotes work with everyone.';
2619
+ const off = "Chat isn't available on this account";
2620
+ try {
2621
+ for (const cues of [true, false]) {
2622
+ const today = cues ? { input: false, note: why, placeholder: 'Friends only', label: why } : { input: false, note: off };
2623
+ const on = { input: true, note: 'Chat reaches amy', ...(cues ? { placeholder: 'To your follows…', label: 'Message · only players you follow each other with' } : {}) };
2624
+ for (const anonymousEntry of [false, true]) {
2625
+ for (const user of [{ userId: '101', isAnonymous: true }, { userId: '101', isAnonymous: false }]) {
2626
+ const what = `cues ${cues}, anonymousEntry ${anonymousEntry}, anonymous ${user.isAnonymous}`;
2627
+ const { system, scene } = setup();
2628
+ HubState.deck.cues = cues;
2629
+ HubState.hub.place = { title: 'Town', result: null, ...(anonymousEntry ? { anonymousEntry: true } : {}) };
2630
+ if (anonymousEntry && user.isAnonymous) {HubState.hub.guests = new Set(['me']);}
2631
+ const seen = cueChrome(system);
2632
+ townNet(scene, new Map([['p2', 'bo'], ['p4', 'amy']]), { me: '101', p2: '102', p4: '104' });
2633
+ const chat = { canChat: false, peers: [], incoming: [], available: () => true, frame() {}, soon() {} };
2634
+ system.chat = chat;
2635
+ globalThis.__tripUser = () => user;
2636
+ system.drawChrome(scene, null, 1000);
2637
+ await flush();
2638
+ system.drawChrome(scene, null, 1100);
2639
+ assert.deepEqual(seen.say.chat, today, `${what}: off`);
2640
+ chat.canChat = true;
2641
+ chat.peers = ['104'];
2642
+ system.drawChrome(scene, null, 1200);
2643
+ assert.deepEqual(seen.say.chat, on, `${what}: on`);
2644
+ chat.canChat = false;
2645
+ chat.peers = [];
2646
+ // Behind a door: the game's chat is left as the host answers it.
2647
+ HubState.hub.place = { title: 'Foot Race', result: { outcomes: ['win'] } };
2648
+ system.drawChrome(scene, null, 1300);
2649
+ assert.deepEqual(seen.say.chat, { input: false, note: off }, `${what}: behind a door`);
2650
+ delete HubState.hub.guests;
2651
+ resetTown();
2652
+ }
2653
+ }
2654
+ }
2655
+ } finally {
2656
+ delete globalThis.__tripUser;
2657
+ delete HubState.hub.guests;
2658
+ resetTown();
2659
+ }
2660
+ });
2661
+
2004
2662
  // A phrase id the kit does not have.
2005
2663
  const GONE = 'join';
2006
2664
  await test('Doors > Go sends what it always did, cues or not: a jump alone, a proposal to a party here, a jump to a solo door; an unknown phrase heard is nothing', async () => {
@@ -2410,6 +3068,7 @@ await test('yourGames v1.54: keyless sends nothing; offers obey party, solo, inv
2410
3068
  const at = performance.now();
2411
3069
  system.finishTrip(scene, { n: 1, startedAt: at, marks: { covered: at, arrived: at, firstFrame: at, revealed: at }, target: { arrive: { door, returning: true } } });
2412
3070
  };
3071
+ HubState.hub.arrivalPlaced = true;
2413
3072
  back('race');
2414
3073
  HubState.hub.party.members = ['p2'];
2415
3074
  system.drawChrome(scene, null, performance.now());
@@ -2447,6 +3106,109 @@ await test('yourGames v1.54: keyless sends nothing; offers obey party, solo, inv
2447
3106
  }
2448
3107
  });
2449
3108
 
3109
+ await test('a returned Your games card starts at the authoritative town pose and keeps that lease through reconnect', async () => {
3110
+ const oldYours = HubState.deck.yourGames;
3111
+ try {
3112
+ HubState.clear();
3113
+ HubState.deck.yourGames = true;
3114
+ const { system, scene } = setup();
3115
+ const seen = cueChrome(system);
3116
+ system.talk.reset = () => {};
3117
+ system.chrome.setCover = () => {};
3118
+ system.scene = scene;
3119
+ townNet(scene, new Map(), {});
3120
+ HubState.hub.place = { id: 'main', title: 'Town', result: null };
3121
+ HubState.hub.doors = [{ id: 'house', title: 'Your house' }];
3122
+ HubState.hub.yours = { rows: [{ door: 'house', title: 'Your house', line: '', hearted: false }], hearts: [] };
3123
+ globalThis.__tripHub.hearts = async () => ({ status: 'ok', hearts: [] });
3124
+ const local = { id: 'me', components: { Transform: { x: 1.1, z: 9 } } };
3125
+
3126
+ system.drawChrome(scene, local, 0);
3127
+ await flush();
3128
+ system.drawChrome(scene, local, 1);
3129
+ system.answer(scene, seen.ask, false);
3130
+ system.drawChrome(scene, local, 2);
3131
+ assert.equal(seen.ask, null, 'the ordinary arrival card is out of the way');
3132
+
3133
+ const at = performance.now();
3134
+ system.finishTrip(scene, { n: 1, startedAt: at, timedOut: false, marks: { covered: at, arrived: at, firstFrame: at, revealed: at }, target: { arrive: { door: 'house', returning: true } } });
3135
+ system.drawChrome(scene, local, 700);
3136
+ assert.equal(seen.ask, null, 'the return offer has no card or lease at the scene spawn');
3137
+ HubState.hub.arrivalPlaced = true;
3138
+ const readBeforeDisplay = system.ask(700);
3139
+ assert.equal(readBeforeDisplay?.requiresArrivalPlacement, true, 'the returned occurrence carries its placement requirement');
3140
+ assert.equal(system.askSlot.known(readBeforeDisplay), false, 'reading a ready ask does not count as its first display');
3141
+
3142
+ system.newIdentity();
3143
+ HubState.hub.place = { id: 'main', title: 'Town', result: null };
3144
+ HubState.hub.doors = [{ id: 'house', title: 'Your house' }];
3145
+ HubState.hub.yours = { rows: [{ door: 'house', title: 'Your house', line: '', hearted: false }], hearts: [] };
3146
+ assert.equal(HubState.hub.arrivalPlaced, false);
3147
+ system.drawChrome(scene, local, 750);
3148
+ assert.equal(seen.ask, null, 'a session clear still withholds an occurrence that was read but never displayed');
3149
+ assert.equal(system.askSlot.known(readBeforeDisplay), false);
3150
+
3151
+ HookLayer.message(scene, { k: 'hub-arrived', facing: 0 });
3152
+ HookLayer.state(scene, { ps: [['me', ...packPlayer({ x: 0.9, y: 0, z: -1.4 }, 0, true)]] }, { net: scene.multiplayer.net });
3153
+ Object.assign(local.components.Transform, { x: 0.9, z: -1.4 });
3154
+ system.drawChrome(scene, local, 800);
3155
+ assert.equal(seen.ask?.kind, 'yours', 'the next hub frame displays at the applied town pose');
3156
+ const shown = seen.ask;
3157
+
3158
+ system.newIdentity();
3159
+ HubState.hub.place = { id: 'main', title: 'Town', result: null };
3160
+ HubState.hub.doors = [{ id: 'house', title: 'Your house' }];
3161
+ HubState.hub.yours = { rows: [{ door: 'house', title: 'Your house', line: '', hearted: false }], hearts: [] };
3162
+ assert.equal(HubState.hub.arrivalPlaced, false);
3163
+ system.drawChrome(scene, local, 12_799);
3164
+ assert.equal(seen.ask?.slotKey, shown.slotKey, 'a known lease remains visible through reconnect without a new placement receipt');
3165
+ system.drawChrome(scene, local, 12_800);
3166
+ assert.equal(seen.ask, null, 'reconnect does not restart the original twelve-second deadline');
3167
+
3168
+ HookLayer.message(scene, { k: 'hub-arrived', facing: 0 });
3169
+ HookLayer.state(scene, { ps: [['me', ...packPlayer({ x: 0.9, y: 0, z: -1.4 }, 0, true)]] }, { net: scene.multiplayer.net });
3170
+ const again = performance.now();
3171
+ system.finishTrip(scene, { n: 2, startedAt: again, timedOut: false, marks: { covered: again, arrived: again, firstFrame: again, revealed: again }, target: { arrive: { door: 'house', returning: true } } });
3172
+ system.drawChrome(scene, local, 13_000);
3173
+ assert.notEqual(seen.ask?.slotKey, shown.slotKey, 'a later return is a distinct occurrence');
3174
+ local.components.Transform.x += 3;
3175
+ system.drawChrome(scene, local, 13_000);
3176
+ assert.equal(seen.ask, null, 'three metres from its actual display pose expires the card');
3177
+ } finally {
3178
+ HubState.deck.yourGames = oldYours;
3179
+ delete globalThis.__tripHub.hearts;
3180
+ HubState.clear();
3181
+ }
3182
+ });
3183
+
3184
+ await test('a timed-out or lost return waits for a later authoritative placement', () => {
3185
+ const oldYours = HubState.deck.yourGames;
3186
+ try {
3187
+ HubState.clear();
3188
+ HubState.deck.yourGames = true;
3189
+ for (const fallback of [{ timedOut: true }, { lost: 'join closed' }]) {
3190
+ HubState.clear();
3191
+ const { system, scene } = setup();
3192
+ const label = Object.keys(fallback)[0];
3193
+ const card = { key: `yours:return:${label}`, slotKey: `yours:return:${label}`, kind: 'yours', requiresArrivalPlacement: true };
3194
+ system.yours = { returned() {}, ask: () => card };
3195
+ const at = performance.now();
3196
+ system.finishTrip(scene, { n: 1, startedAt: at, ...fallback, marks: { covered: at, revealed: at }, target: { arrive: { door: 'house', returning: true } } });
3197
+ assert.equal(system.ask(), null, `${label} return remains withheld at the unplaced spawn`);
3198
+ assert.equal(system.askSlot.known(card), false);
3199
+
3200
+ HookLayer.message(scene, { k: 'hub-arrived', facing: 0 });
3201
+ const packed = JSON.parse(JSON.stringify(['me', ...packPlayer({ x: 0.9, y: 0, z: -1.4 }, 0, true)]));
3202
+ assert.equal(packed[5], 1, 'the late placement uses the production numeric clamp flag');
3203
+ HookLayer.state(scene, { ps: [packed] }, { net: { selfId: () => 'me' } });
3204
+ assert.equal(system.ask(), card, `${label} return becomes eligible after authoritative placement`);
3205
+ }
3206
+ } finally {
3207
+ HubState.deck.yourGames = oldYours;
3208
+ HubState.clear();
3209
+ }
3210
+ });
3211
+
2450
3212
  // v1.61: exercise the production lifecycle methods, including direct door
2451
3213
  // travel that starts without a hub-go message.
2452
3214
  for (const [name, leave] of [
@@ -2742,4 +3504,110 @@ await test('packets queued under the old player id are dropped at the identity b
2742
3504
 
2743
3505
  console.warn = warn;
2744
3506
  console.log = log;
3507
+
3508
+ await test('scene invite rail: town, House, game; opt-out and stale picks remain dormant', async () => {
3509
+ for (const result of [null, {}]) {
3510
+ const { system, scene } = setup();
3511
+ cueChrome(system);
3512
+ townNet(scene, new Map(), {});
3513
+ system.scene = scene;
3514
+ scene.data = { engine: {} };
3515
+ HubState.hub.place = { title: result ? 'Door' : 'House or town', result, invite: true };
3516
+ let draw, opens = [];
3517
+ system.chrome.showPicker = (...args) => { draw = args; };
3518
+ system.invites = { canInvite: () => true, open: (share) => opens.push(share) };
3519
+ for (const marker of [undefined, false, 'true', true]) {
3520
+ scene.data.engine.hubInviteRail = marker;
3521
+ system.drawChrome(scene, null, performance.now());
3522
+ assert.equal(draw[3] !== undefined, marker === true && !result);
3523
+ assert.equal(draw[0], !result);
3524
+ }
3525
+ if (result) {assert.deepEqual(opens, []); HubState.clear(); continue;}
3526
+ draw[3].onPick();
3527
+ assert.deepEqual(opens, [true]);
3528
+ const stale = draw[3].onPick;
3529
+ // A guest is over 13 like anyone else: the host's canInvite answer decides.
3530
+ HubState.hub.guests = new Set(['me']);
3531
+ system.drawChrome(scene, null, performance.now());
3532
+ assert.notEqual(draw[3], undefined, 'a guest the host can invite sees the invite entry');
3533
+ draw[3].onPick();
3534
+ assert.deepEqual(opens, [true, true], 'a guest the host can invite can open it');
3535
+ opens.pop();
3536
+ delete HubState.hub.guests;
3537
+ system.invites.canInvite = () => false;
3538
+ system.drawChrome(scene, null, performance.now());
3539
+ assert.equal(draw[3], undefined, 'unresolved identity has no invite entry');
3540
+ stale();
3541
+ system.invites.canInvite = () => true;
3542
+ system.trip = { phase: 'open' }; stale(); system.trip = null;
3543
+ const net = scene.multiplayer.net;
3544
+ scene.multiplayer.net = {}; stale(); scene.multiplayer.net = net;
3545
+ const place = HubState.hub.place;
3546
+ HubState.hub.place = { ...place }; stale(); HubState.hub.place = place;
3547
+ scene.data.engine.hubInviteRail = false; stale();
3548
+ assert.deepEqual(opens, [true]);
3549
+ scene.data.engine.hubInviteRail = true;
3550
+ HubState.hub.place = { ...place, invite: false };
3551
+ system.drawChrome(scene, null, performance.now());
3552
+ assert.equal(draw[3], undefined, 'marker cannot invent authored invite capability');
3553
+ HubState.clear();
3554
+ }
3555
+ });
3556
+
2745
3557
  console.log(`hub trips: ${n} tests passed`);
3558
+
3559
+ await test('early proxy not_running retries the same door once with a fresh acquisition under cover', async () => {
3560
+ const { system, scene } = setup(); const mp = mpStub(scene);
3561
+ answers.go = handoff(); system.goHub(scene, { door: 'race', title: 'Foot Race' });
3562
+ await toSwitch(system, scene, mp);
3563
+ const trip = system.trip; trip.target.acquiredAt = 0;
3564
+ mp.state = 'failed'; mp.joinFailure = { code: 'MULTIPLAYER_CONNECTION_FAILED', closeCode: 4404 };
3565
+ system.stepTrip(scene, mp, null, 1500);
3566
+ assert.equal(trip.phase, 'retrying-door');
3567
+ system.stepTrip(scene, mp, null, 3999);
3568
+ assert.equal(calls.filter(c => c[0] === 'go').length, 1);
3569
+ answers.go = handoff({ nonce: 'fresh' });
3570
+ system.stepTrip(scene, mp, null, 4000); await flush();
3571
+ system.stepTrip(scene, mp, null, 4001);
3572
+ assert.equal(trip.phase, 'committing');
3573
+ assert.equal(mp.switched.at(-1).handoff.nonce, 'fresh');
3574
+ assert.equal(scene.persistent.hubTickets.length, 1);
3575
+ assert.equal(scene.persistent.hubDepth ?? 0, 0);
3576
+ assert.equal(scene.requestedScene, undefined);
3577
+ assert.deepEqual(calls.map(c => c[0]), ['go', 'loadPack', 'cancel', 'go', 'loadPack']);
3578
+ mp.state = 'joined'; system.stepTrip(scene, mp, null, 4002);
3579
+ assert.equal(scene.persistent.hubDepth, 1);
3580
+ });
3581
+ for (const [code, age, retried] of [[4401, 1000, false], [1013, 1000, false], [4404, 5001, false], [4404, 1000, true]]) {
3582
+ await test(`door retry limit: close ${code}, age ${age}, already retried ${retried}`, async () => {
3583
+ const { system, scene } = setup(); const mp = mpStub(scene);
3584
+ answers.go = handoff(); system.goHub(scene, { door: 'race' }); await toSwitch(system, scene, mp);
3585
+ system.trip.target.acquiredAt = 0; system.trip.doorRetried = retried;
3586
+ mp.state = 'failed'; mp.joinFailure = { code: 'MULTIPLAYER_CONNECTION_FAILED', closeCode: code };
3587
+ system.stepTrip(scene, mp, null, age);
3588
+ assert.notEqual(system.trip?.phase, 'retrying-door');
3589
+ assert.equal(calls.filter(c => c[0] === 'go').length, 1);
3590
+ });
3591
+ }
3592
+ console.log(`hub trips with retry: ${n} tests passed`);
3593
+
3594
+ for (const failure of ['refused', 'pack', 'timeout']) {
3595
+ await test(`failed door reacquisition recovers the closed source session: ${failure}`, async () => {
3596
+ const { system, scene } = setup(); const mp = mpStub(scene);
3597
+ answers.go = handoff(); system.goHub(scene, { door: 'race' }); await toSwitch(system, scene, mp);
3598
+ system.trip.target.acquiredAt = 0;
3599
+ mp.state = 'failed'; mp.joinFailure = { code: 'MULTIPLAYER_CONNECTION_FAILED', closeCode: 4404 };
3600
+ system.stepTrip(scene, mp, null, 1000);
3601
+ if (failure === 'refused') answers.go = { status: 'full' };
3602
+ if (failure === 'pack') answers.loadPackError = true;
3603
+ system.stepTrip(scene, mp, null, 3500); await flush();
3604
+ if (failure === 'timeout') { system.trip.target.pending.done = false; }
3605
+ system.stepTrip(scene, mp, null, failure === 'timeout' ? 100000 : 3501);
3606
+ assert.equal(system.trip.target.join.mode, 'public');
3607
+ assert.equal(system.trip.target.scene, 'scenes/main.scene');
3608
+ assert.equal(scene.requestedScene, undefined);
3609
+ assert.equal(scene.persistent.hubTickets.length, 0);
3610
+ assert.equal(scene.persistent.hubDepth ?? 0, 0);
3611
+ });
3612
+ }
3613
+ console.log(`hub trips with retry failures: ${n} tests passed`);