castle-web-cli 0.4.231 → 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 (368) 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/serverBundle.js +5 -3
  28. package/dist/shell/assets/{index-D2tWM896.js → index-BjOxR-lW.js} +4 -4
  29. package/dist/shell/assets/index-MVLfNYd9.css +1 -0
  30. package/dist/shell/index.html +2 -2
  31. package/dist/taskSteer.d.ts +13 -0
  32. package/dist/taskSteer.js +22 -2
  33. package/kits/base/castle.json +1 -1
  34. package/kits/base/package-lock.json +1 -1
  35. package/kits/base/sdk/README.md +79 -2
  36. package/kits/base/sdk/avatar.d.ts +6 -2
  37. package/kits/base/sdk/avatar.js +12 -4
  38. package/kits/base/sdk/castle.d.ts +1 -1
  39. package/kits/base/sdk/commands.d.ts +14 -0
  40. package/kits/base/sdk/hub.d.ts +6 -2
  41. package/kits/base/sdk/hub.js +13 -0
  42. package/kits/base/sdk/multiplayer.js +17 -1
  43. package/kits/base/sdk/save.js +2 -1
  44. package/kits/base/sdk/server/hub.d.ts +87 -0
  45. package/kits/base/sdk/server/hub.js +70 -0
  46. package/kits/base/sdk/server/platformHandle.d.ts +31 -1
  47. package/kits/base/sdk/server/storage.d.ts +13 -0
  48. package/kits/base/sdk/server/storage.js +46 -0
  49. package/kits/base/sdk/server/wrapper.d.ts +36 -5
  50. package/kits/base/sdk/server/wrapper.js +83 -8
  51. package/kits/hub-game/CLAUDE.md +352 -12
  52. package/kits/hub-game/blueprints/avatar-10.scene +28 -0
  53. package/kits/hub-game/blueprints/avatar-11.scene +28 -0
  54. package/kits/hub-game/blueprints/avatar-12.scene +28 -0
  55. package/kits/hub-game/blueprints/avatar-13.scene +28 -0
  56. package/kits/hub-game/blueprints/avatar-14.scene +28 -0
  57. package/kits/hub-game/blueprints/avatar-15.scene +28 -0
  58. package/kits/hub-game/blueprints/avatar-4.scene +28 -0
  59. package/kits/hub-game/blueprints/avatar-5.scene +28 -0
  60. package/kits/hub-game/blueprints/avatar-6.scene +28 -0
  61. package/kits/hub-game/blueprints/avatar-7.scene +28 -0
  62. package/kits/hub-game/blueprints/avatar-8.scene +28 -0
  63. package/kits/hub-game/blueprints/avatar-9.scene +28 -0
  64. package/kits/hub-game/code/client/actorBudget.js +47 -0
  65. package/kits/hub-game/code/client/attention.js +11 -2
  66. package/kits/hub-game/code/client/avatar.js +345 -32
  67. package/kits/hub-game/code/client/avatarCap.js +228 -0
  68. package/kits/hub-game/code/client/avatarColors.js +70 -0
  69. package/kits/hub-game/code/client/avatarFaces.js +21 -0
  70. package/kits/hub-game/code/client/avatarShare.js +251 -0
  71. package/kits/hub-game/code/client/ballot.js +467 -0
  72. package/kits/hub-game/code/client/build.js +22 -0
  73. package/kits/hub-game/code/client/chat.js +12 -0
  74. package/kits/hub-game/code/client/chrome.js +1334 -50
  75. package/kits/hub-game/code/client/companion.js +716 -0
  76. package/kits/hub-game/code/client/companionDress.js +99 -0
  77. package/kits/hub-game/code/client/decor.js +509 -0
  78. package/kits/hub-game/code/client/earned.js +131 -0
  79. package/kits/hub-game/code/client/emoteBubble.js +75 -0
  80. package/kits/hub-game/code/client/grab.js +363 -20
  81. package/kits/hub-game/code/client/hats.js +26 -0
  82. package/kits/hub-game/code/client/hookLayer.js +328 -15
  83. package/kits/hub-game/code/client/hudClear.js +126 -0
  84. package/kits/hub-game/code/client/idle.js +163 -22
  85. package/kits/hub-game/code/client/interestCap.js +81 -0
  86. package/kits/hub-game/code/client/keys.js +36 -0
  87. package/kits/hub-game/code/client/labelsNear.js +205 -0
  88. package/kits/hub-game/code/client/menuIcons.js +34 -0
  89. package/kits/hub-game/code/client/pack.js +6 -2
  90. package/kits/hub-game/code/client/packFormat.js +3 -3
  91. package/kits/hub-game/code/client/rehello.js +167 -0
  92. package/kits/hub-game/code/client/shot.js +92 -0
  93. package/kits/hub-game/code/client/sound.js +63 -8
  94. package/kits/hub-game/code/client/soundscape.js +1151 -0
  95. package/kits/hub-game/code/client/soundscapeActions.js +99 -0
  96. package/kits/hub-game/code/client/soundscapeAmbience.js +453 -0
  97. package/kits/hub-game/code/client/soundscapeBaked.js +143 -0
  98. package/kits/hub-game/code/client/soundscapeBusker.js +217 -0
  99. package/kits/hub-game/code/client/soundscapeCourt.js +200 -0
  100. package/kits/hub-game/code/client/soundscapeCrowd.js +331 -0
  101. package/kits/hub-game/code/client/soundscapeCues.js +362 -0
  102. package/kits/hub-game/code/client/soundscapeMap.js +181 -0
  103. package/kits/hub-game/code/client/soundscapeMarket.js +176 -0
  104. package/kits/hub-game/code/client/soundscapeMusic.js +126 -0
  105. package/kits/hub-game/code/client/soundscapeMusicEngine.js +460 -0
  106. package/kits/hub-game/code/client/soundscapeSimlish.js +737 -0
  107. package/kits/hub-game/code/client/soundscapeSongs.js +127 -0
  108. package/kits/hub-game/code/client/soundscapeSongsRound3.js +63 -0
  109. package/kits/hub-game/code/client/soundscapeSynthesis.js +168 -0
  110. package/kits/hub-game/code/client/soundscapeUi.js +211 -0
  111. package/kits/hub-game/code/client/soundscapeVoice.js +1209 -0
  112. package/kits/hub-game/code/client/soundscapeWaves.js +206 -0
  113. package/kits/hub-game/code/client/spin.js +101 -0
  114. package/kits/hub-game/code/client/state.js +131 -1
  115. package/kits/hub-game/code/client/stuck.js +259 -0
  116. package/kits/hub-game/code/client/talk.js +538 -47
  117. package/kits/hub-game/code/client/tiers.js +541 -27
  118. package/kits/hub-game/code/client/toastBand.js +37 -0
  119. package/kits/hub-game/code/client/together.js +98 -1
  120. package/kits/hub-game/code/client/visibility.js +43 -0
  121. package/kits/hub-game/code/client/wear.js +470 -97
  122. package/kits/hub-game/code/client/yours.js +199 -0
  123. package/kits/hub-game/code/companionSpec.js +45 -0
  124. package/kits/hub-game/code/privateText.js +7 -0
  125. package/kits/hub-game/code/server/actions.js +133 -0
  126. package/kits/hub-game/code/server/actors.js +14 -1
  127. package/kits/hub-game/code/server/ask.js +155 -0
  128. package/kits/hub-game/code/server/ballot.js +539 -0
  129. package/kits/hub-game/code/server/cells.js +100 -0
  130. package/kits/hub-game/code/server/companion.js +82 -0
  131. package/kits/hub-game/code/server/cues.js +70 -0
  132. package/kits/hub-game/code/server/decor.js +269 -0
  133. package/kits/hub-game/code/server/earned.js +461 -0
  134. package/kits/hub-game/code/server/friendBests.js +166 -0
  135. package/kits/hub-game/code/server/friendsAmong.js +232 -0
  136. package/kits/hub-game/code/server/grab.js +296 -11
  137. package/kits/hub-game/code/server/history.js +5 -0
  138. package/kits/hub-game/code/server/hub.js +1317 -52
  139. package/kits/hub-game/code/server/idle.js +30 -11
  140. package/kits/hub-game/code/server/index.js +2 -2
  141. package/kits/hub-game/code/server/labels.js +28 -2
  142. package/kits/hub-game/code/server/manifest.js +424 -8
  143. package/kits/hub-game/code/server/menu.js +133 -0
  144. package/kits/hub-game/code/server/npcs.js +830 -80
  145. package/kits/hub-game/code/server/party.js +13 -2
  146. package/kits/hub-game/code/server/players.js +22 -0
  147. package/kits/hub-game/code/server/say.js +8 -2
  148. package/kits/hub-game/code/server/shot.js +110 -0
  149. package/kits/hub-game/code/server/standing.js +124 -0
  150. package/kits/hub-game/code/server/vis.js +113 -0
  151. package/kits/hub-game/code/server/wear.js +128 -11
  152. package/kits/hub-game/code/server/yours.js +59 -0
  153. package/kits/hub-game/code/shared/cues.js +9 -0
  154. package/kits/hub-game/code/shared/decor.js +41 -0
  155. package/kits/hub-game/code/shared/shot.js +19 -0
  156. package/kits/hub-game/code/shared/spin.js +57 -0
  157. package/kits/hub-game/code/systems/hub.js +1083 -85
  158. package/kits/hub-game/docs/content-pack.md +1 -1
  159. package/kits/hub-game/docs/contract.md +2440 -61
  160. package/kits/hub-game/docs/home-pieces.md +64 -0
  161. package/kits/hub-game/models/avatar-10.pxmodel +28 -0
  162. package/kits/hub-game/models/avatar-11.pxmodel +28 -0
  163. package/kits/hub-game/models/avatar-12.pxmodel +27 -0
  164. package/kits/hub-game/models/avatar-13.pxmodel +24 -0
  165. package/kits/hub-game/models/avatar-14.pxmodel +29 -0
  166. package/kits/hub-game/models/avatar-15.pxmodel +24 -0
  167. package/kits/hub-game/models/avatar-4.pxmodel +29 -0
  168. package/kits/hub-game/models/avatar-5.pxmodel +27 -0
  169. package/kits/hub-game/models/avatar-6.pxmodel +26 -0
  170. package/kits/hub-game/models/avatar-7.pxmodel +25 -0
  171. package/kits/hub-game/models/avatar-8.pxmodel +24 -0
  172. package/kits/hub-game/models/avatar-9.pxmodel +30 -0
  173. package/kits/hub-game/models/earned/badge-round.pxmodel +100 -0
  174. package/kits/hub-game/models/earned/badge-shield.pxmodel +117 -0
  175. package/kits/hub-game/models/earned/badge-star.pxmodel +87 -0
  176. package/kits/hub-game/models/earned/belt-plain.pxmodel +72 -0
  177. package/kits/hub-game/models/earned/held-ball.pxmodel +43 -0
  178. package/kits/hub-game/models/earned/held-lantern.pxmodel +85 -0
  179. package/kits/hub-game/models/earned/held-net.pxmodel +57 -0
  180. package/kits/hub-game/models/earned/held-trophy.pxmodel +109 -0
  181. package/kits/hub-game/models/earned/pin-round.pxmodel +62 -0
  182. package/kits/hub-game/models/earned/sash-plain.pxmodel +66 -0
  183. package/kits/hub-game/models/earned/square/belt-plain.pxmodel +104 -0
  184. package/kits/hub-game/models/earned/square/sash-plain.pxmodel +98 -0
  185. package/kits/hub-game/models/hats/bat-clip.pxmodel +206 -0
  186. package/kits/hub-game/models/hats/beekeeper.pxmodel +149 -0
  187. package/kits/hub-game/models/hats/cap.pxmodel +162 -0
  188. package/kits/hub-game/models/hats/captain.pxmodel +178 -0
  189. package/kits/hub-game/models/hats/crooked-top.pxmodel +172 -0
  190. package/kits/hub-game/models/hats/flower-crown.pxmodel +451 -0
  191. package/kits/hub-game/models/hats/foam-crown.pxmodel +179 -0
  192. package/kits/hub-game/models/hats/lantern.pxmodel +230 -0
  193. package/kits/hub-game/models/hats/laurel.pxmodel +533 -0
  194. package/kits/hub-game/models/hats/lighthouse.pxmodel +96 -0
  195. package/kits/hub-game/models/hats/sailor.pxmodel +141 -0
  196. package/kits/hub-game/models/hats/souwester.pxmodel +131 -0
  197. package/kits/hub-game/models/hats/straw.pxmodel +139 -0
  198. package/kits/hub-game/models/hats/sunflower.pxmodel +406 -0
  199. package/kits/hub-game/models/hats/sweatband.pxmodel +112 -0
  200. package/kits/hub-game/models/hats/witch.pxmodel +147 -0
  201. package/kits/hub-game/package-lock.json +2 -0
  202. package/kits/hub-game/package.json +2 -1
  203. package/kits/hub-game/scripts/check.mjs +78 -11
  204. package/kits/hub-game/scripts/companion-follower-wire.json +1 -0
  205. package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +121 -0
  206. package/kits/hub-game/scripts/fixtures/decor-keyless.json +293 -0
  207. package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +23 -0
  208. package/kits/hub-game/scripts/fixtures/fake-dom.mjs +107 -0
  209. package/kits/hub-game/scripts/fixtures/interest-legacy.json +385 -0
  210. package/kits/hub-game/scripts/fixtures/npc-notes-v1.77.jsonl +4 -0
  211. package/kits/hub-game/scripts/fixtures/vis-shared-wire.json +1 -0
  212. package/kits/hub-game/scripts/gen-avatars.mjs +933 -16
  213. package/kits/hub-game/scripts/gen-earned.mjs +285 -0
  214. package/kits/hub-game/scripts/gen-hats.mjs +827 -0
  215. package/kits/hub-game/scripts/grab.before-orbit.mjs +400 -0
  216. package/kits/hub-game/scripts/soundscape-wave-analysis.mjs +125 -0
  217. package/kits/hub-game/scripts/test-actions-client.mjs +488 -0
  218. package/kits/hub-game/scripts/test-actions.mjs +298 -0
  219. package/kits/hub-game/scripts/test-actor-budget.mjs +44 -0
  220. package/kits/hub-game/scripts/test-actors.mjs +19 -17
  221. package/kits/hub-game/scripts/test-ask-client.mjs +358 -0
  222. package/kits/hub-game/scripts/test-ask.mjs +269 -0
  223. package/kits/hub-game/scripts/test-attention.mjs +10 -1
  224. package/kits/hub-game/scripts/test-avatar-cap.mjs +379 -0
  225. package/kits/hub-game/scripts/test-avatar-colors.mjs +72 -0
  226. package/kits/hub-game/scripts/test-avatar-models.mjs +181 -0
  227. package/kits/hub-game/scripts/test-avatar-share.mjs +318 -0
  228. package/kits/hub-game/scripts/test-avatar-wire.mjs +753 -0
  229. package/kits/hub-game/scripts/test-avatar.mjs +540 -7
  230. package/kits/hub-game/scripts/test-ballot.mjs +1001 -0
  231. package/kits/hub-game/scripts/test-build.mjs +31 -0
  232. package/kits/hub-game/scripts/test-cells.mjs +71 -0
  233. package/kits/hub-game/scripts/test-chat.mjs +694 -0
  234. package/kits/hub-game/scripts/test-classic.mjs +2 -0
  235. package/kits/hub-game/scripts/test-companion-chat.mjs +198 -0
  236. package/kits/hub-game/scripts/test-companion-client.mjs +1167 -0
  237. package/kits/hub-game/scripts/test-companion.mjs +259 -0
  238. package/kits/hub-game/scripts/test-decor-client.mjs +303 -0
  239. package/kits/hub-game/scripts/test-decor.mjs +457 -0
  240. package/kits/hub-game/scripts/test-earned-client.mjs +459 -0
  241. package/kits/hub-game/scripts/test-earned.mjs +1194 -0
  242. package/kits/hub-game/scripts/test-emote-bubble.mjs +110 -0
  243. package/kits/hub-game/scripts/test-friend-bests.mjs +435 -0
  244. package/kits/hub-game/scripts/test-grab-client.mjs +186 -3
  245. package/kits/hub-game/scripts/test-grab-orbit.mjs +918 -0
  246. package/kits/hub-game/scripts/test-grab.mjs +864 -3
  247. package/kits/hub-game/scripts/test-hats.mjs +483 -0
  248. package/kits/hub-game/scripts/test-hub-leaving.mjs +203 -0
  249. package/kits/hub-game/scripts/test-hub-ops.mjs +439 -2
  250. package/kits/hub-game/scripts/test-hub-trip.mjs +1228 -1
  251. package/kits/hub-game/scripts/test-hud-clear.mjs +1000 -0
  252. package/kits/hub-game/scripts/test-idle.mjs +361 -1
  253. package/kits/hub-game/scripts/test-interest-cap.mjs +36 -0
  254. package/kits/hub-game/scripts/test-interest-cells.mjs +493 -0
  255. package/kits/hub-game/scripts/test-interest-client.mjs +118 -0
  256. package/kits/hub-game/scripts/test-keys.mjs +46 -1
  257. package/kits/hub-game/scripts/test-labels.mjs +596 -0
  258. package/kits/hub-game/scripts/test-manifest.mjs +282 -0
  259. package/kits/hub-game/scripts/test-menu-client.mjs +480 -0
  260. package/kits/hub-game/scripts/test-menu.mjs +296 -0
  261. package/kits/hub-game/scripts/test-npcs.mjs +1718 -12
  262. package/kits/hub-game/scripts/test-object-entry.mjs +76 -0
  263. package/kits/hub-game/scripts/test-pack.mjs +7 -0
  264. package/kits/hub-game/scripts/test-party.mjs +22 -1
  265. package/kits/hub-game/scripts/test-picker.mjs +314 -0
  266. package/kits/hub-game/scripts/test-rehello.mjs +1039 -0
  267. package/kits/hub-game/scripts/test-relations-among.mjs +222 -0
  268. package/kits/hub-game/scripts/test-relations-refresh.mjs +188 -0
  269. package/kits/hub-game/scripts/test-say.mjs +59 -2
  270. package/kits/hub-game/scripts/test-shot.mjs +756 -0
  271. package/kits/hub-game/scripts/test-soundscape.mjs +5432 -0
  272. package/kits/hub-game/scripts/test-spin.mjs +314 -0
  273. package/kits/hub-game/scripts/test-standing.mjs +416 -0
  274. package/kits/hub-game/scripts/test-stuck.mjs +1903 -0
  275. package/kits/hub-game/scripts/test-tier-cells.mjs +706 -0
  276. package/kits/hub-game/scripts/test-tiers-render.mjs +339 -0
  277. package/kits/hub-game/scripts/test-tiers.mjs +666 -3
  278. package/kits/hub-game/scripts/test-toast-band.mjs +61 -0
  279. package/kits/hub-game/scripts/test-try-on.mjs +940 -0
  280. package/kits/hub-game/scripts/test-vis.mjs +343 -0
  281. package/kits/hub-game/scripts/test-visibility.mjs +134 -0
  282. package/kits/hub-game/scripts/test-yours-chrome.mjs +166 -0
  283. package/kits/hub-game/scripts/test-yours.mjs +372 -0
  284. package/kits/multiplayer-3d/CLAUDE.md +50 -0
  285. package/kits/multiplayer-3d/castle.json +5 -5
  286. package/kits/multiplayer-3d/code/client/avatars.js +7 -0
  287. package/kits/multiplayer-3d/code/client/gait.js +65 -0
  288. package/kits/multiplayer-3d/code/client/nameTags.js +59 -4
  289. package/kits/multiplayer-3d/code/options.js +5 -0
  290. package/kits/multiplayer-3d/code/server/ownership.js +10 -2
  291. package/kits/multiplayer-3d/code/server/sceneBodies.js +12 -0
  292. package/kits/multiplayer-3d/code/server/world.js +7 -0
  293. package/kits/multiplayer-3d/code/systems/multiplayer.js +74 -4
  294. package/kits/multiplayer-3d/package.json +2 -1
  295. package/kits/multiplayer-3d/scripts/fixtures/README.md +11 -0
  296. package/kits/multiplayer-3d/scripts/fixtures/ownership-legacy.json +2 -0
  297. package/kits/multiplayer-3d/scripts/ownership-harness.mjs +102 -0
  298. package/kits/multiplayer-3d/scripts/ownership-loader.mjs +46 -0
  299. package/kits/multiplayer-3d/scripts/ownership-worker.mjs +15 -0
  300. package/kits/multiplayer-3d/scripts/record-ownership-session.mjs +98 -0
  301. package/kits/multiplayer-3d/scripts/test-eligible-claims.mjs +167 -0
  302. package/kits/multiplayer-3d/scripts/test-own-name-tag.mjs +247 -0
  303. package/kits/physics-2d/CLAUDE.md +9 -0
  304. package/kits/physics-2d/castle.json +2 -2
  305. package/kits/physics-2d/engine/scene.js +288 -1
  306. package/kits/physics-2d/engine/skyKey.js +129 -0
  307. package/kits/physics-2d/engine/stillClock.js +106 -0
  308. package/kits/physics-2d/engine/updateBudget.js +21 -0
  309. package/kits/physics-2d/scripts/test-skip-unchanged.mjs +370 -1
  310. package/kits/physics-3d/CLAUDE.md +1391 -0
  311. package/kits/physics-3d/behaviors/Player.jsx +921 -3
  312. package/kits/physics-3d/castle.json +3 -3
  313. package/kits/physics-3d/docs/pxmodel-format.md +12 -0
  314. package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +98 -10
  315. package/kits/physics-3d/engine3d/actornode.js +86 -0
  316. package/kits/physics-3d/engine3d/animationBudget.js +23 -0
  317. package/kits/physics-3d/engine3d/editorWorld.js +6 -0
  318. package/kits/physics-3d/engine3d/emptynodes.js +232 -0
  319. package/kits/physics-3d/engine3d/framecap.js +96 -0
  320. package/kits/physics-3d/engine3d/gait.js +118 -0
  321. package/kits/physics-3d/engine3d/kithooks.js +47 -0
  322. package/kits/physics-3d/engine3d/look.js +507 -48
  323. package/kits/physics-3d/engine3d/lookbake.js +208 -0
  324. package/kits/physics-3d/engine3d/materialpresets.js +2 -0
  325. package/kits/physics-3d/engine3d/motion.js +39 -10
  326. package/kits/physics-3d/engine3d/nearshadows.js +37 -19
  327. package/kits/physics-3d/engine3d/optimize.js +58 -5
  328. package/kits/physics-3d/engine3d/orbitinput.js +755 -0
  329. package/kits/physics-3d/engine3d/orbitlens.js +48 -0
  330. package/kits/physics-3d/engine3d/ownmodel.js +213 -0
  331. package/kits/physics-3d/engine3d/pxmodel.js +42 -11
  332. package/kits/physics-3d/engine3d/shadowfade.js +882 -0
  333. package/kits/physics-3d/engine3d/sky.js +547 -0
  334. package/kits/physics-3d/engine3d/skylife.js +306 -0
  335. package/kits/physics-3d/engine3d/unchanged.js +11 -0
  336. package/kits/physics-3d/engine3d/viewrange.js +52 -0
  337. package/kits/physics-3d/engine3d/world3d.js +870 -87
  338. package/kits/physics-3d/main.jsx +5 -0
  339. package/kits/physics-3d/package.json +1 -1
  340. package/kits/physics-3d/scripts/Player.before-orbit.mjs +310 -0
  341. package/kits/physics-3d/scripts/Scene3DPlayer.before-orbit.jsx +337 -0
  342. package/kits/physics-3d/scripts/look-baseline.mjs +155 -0
  343. package/kits/physics-3d/scripts/test-camera-follow.mjs +12 -2
  344. package/kits/physics-3d/scripts/test-camera-orbit.mjs +4588 -0
  345. package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +787 -0
  346. package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +435 -0
  347. package/kits/physics-3d/scripts/test-frame-cap.mjs +452 -0
  348. package/kits/physics-3d/scripts/test-gait.mjs +387 -0
  349. package/kits/physics-3d/scripts/test-look-bake.mjs +1056 -0
  350. package/kits/physics-3d/scripts/test-model-parse-cache.mjs +92 -0
  351. package/kits/physics-3d/scripts/test-near-shadows.mjs +3 -0
  352. package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1920 -0
  353. package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +545 -0
  354. package/kits/physics-3d/scripts/test-orbit-shot.mjs +583 -0
  355. package/kits/physics-3d/scripts/test-orbit-view.mjs +230 -0
  356. package/kits/physics-3d/scripts/test-skip-empty-nodes.mjs +845 -0
  357. package/kits/physics-3d/scripts/test-sky.mjs +2470 -0
  358. package/kits/physics-3d/scripts/test-static-actors.mjs +13 -1
  359. package/kits/physics-3d/scripts/test-static-passes.mjs +1 -1
  360. package/kits/physics-3d/scripts/test-static-scenery.mjs +2171 -0
  361. package/kits/physics-3d/scripts/test-steady-hover.mjs +635 -0
  362. package/kits/physics-3d/scripts/test-view-range.mjs +260 -0
  363. package/kits/physics-3d/systems/physics3d.js +474 -12
  364. package/kits/real-time/castle.json +2 -2
  365. package/kits/real-time/code/server/gameHooks.js +7 -0
  366. package/kits/real-time/code/server/session.js +97 -19
  367. package/package.json +2 -2
  368. package/dist/shell/assets/index-Cf61cNfT.css +0 -1
@@ -0,0 +1,1039 @@
1
+ // A connection the place let go comes back (a phone's app switch): the
2
+ // client's own resume hello (client/rehello.js) and the place's late greet
3
+ // (greetLate, 3 s) arrive the player once between them, in either order, and
4
+ // either one clears what the client still holds privately; a repeated hello
5
+ // from a player still arrived is idempotent; a game (`result`) takes neither,
6
+ // unless its place says `resume: true` (v1.72).
7
+ // Real hub server hooks.
8
+ import assert from 'node:assert/strict';
9
+ import { register } from 'node:module';
10
+
11
+ register(`data:text/javascript,${encodeURIComponent(`
12
+ export async function resolve(specifier, context, next) {
13
+ if (specifier === '@imports/castle.multiplayer-3d/code/server/sceneBodies.js') return { url: 'data:text/javascript,export const readScene = () => globalThis.__hubTestActors;', shortCircuit: true };
14
+ if (context.parentURL?.includes('/kits/base/sdk/') && specifier.startsWith('.') && !specifier.endsWith('.js')) return next(specifier + '.js', context);
15
+ return next(specifier, context);
16
+ }
17
+ `)}`);
18
+ const { layer } = await import('../code/server/hub.js');
19
+ const { helloAfter, takesEnd } = await import('../code/client/rehello.js');
20
+
21
+ const actors = [
22
+ { id: 'player', components: { Player: {}, Transform: { x: 0, y: 1, z: 0 } } },
23
+ { id: 'floor', components: { Transform: { x: -4, y: 0, z: -3 }, Shape: { kind: 'box', width: 8, height: 0.1, depth: 7 } } },
24
+ ];
25
+ const json = (keys = {}) => ({ server: { maxPlayers: 8 }, hub: { contract: 1, title: 'Town', ...keys } });
26
+ const players = () => [
27
+ { playerId: 'p1', userId: '101', username: 'Ada', isAnonymous: false },
28
+ { playerId: 'p2', userId: '102', username: 'Bo', isAnonymous: false },
29
+ ];
30
+ const body = () => ({ at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
31
+
32
+ function boot(keys = {}, more = {}) {
33
+ const sent = [];
34
+ const arrivals = [];
35
+ const leaves = [];
36
+ let ctx = null;
37
+ const hooks = {
38
+ ready(c) {
39
+ ctx = c;
40
+ },
41
+ arrive(c, group) {
42
+ arrivals.push(group.map((p) => ({ playerId: p.playerId, from: p.from, fromDeckId: p.fromDeckId, party: p.party, near: p.near })));
43
+ more.arrive?.(c, group);
44
+ },
45
+ fall: more.fall,
46
+ resume: more.resume,
47
+ leave(ctx, playerId) {
48
+ leaves.push(playerId);
49
+ more.leave?.(ctx, playerId);
50
+ },
51
+ };
52
+ const engine = {
53
+ createBody(sim, actor, at) {
54
+ return { at: { ...at }, setEnabled() {}, setNextKinematicTranslation() {}, setNextKinematicRotation() {} };
55
+ },
56
+ removeActor(sim, id) {
57
+ sim.bodies.delete(id);
58
+ sim.objects.delete(id);
59
+ },
60
+ };
61
+ globalThis.__hubTestActors = structuredClone(more.actors ?? actors);
62
+ const server = layer(json(keys), hooks, {}, () => true, () => null, null, engine);
63
+ const session = {
64
+ sessionId: 'dev',
65
+ players: players(),
66
+ hub: more.doors
67
+ ? { arrival: (id) => more.doors.get(id) ?? null, readResults: async () => ({ players: {}, boards: {} }), reportResult: async () => ({ recorded: true }) }
68
+ : null,
69
+ send(id, msg) {
70
+ sent.push([id, structuredClone(msg)]);
71
+ },
72
+ broadcast(msg) {
73
+ sent.push(['all', structuredClone(msg)]);
74
+ },
75
+ };
76
+ const world = { timeMs: 0, scenePath: 'scenes/main.scene', objects: new Map(), bodies: new Map(), players: new Map(players().map((p) => [p.playerId, body()])) };
77
+ for (const actor of more.actors ?? []) {
78
+ if (actor.components.HubNpc) {
79
+ const at = actor.components.Transform;
80
+ world.bodies.set(actor.id, { translation: () => at, rotation: () => ({ x: 0, y: 0, z: 0, w: 1 }), setNextKinematicRotation() {} });
81
+ }
82
+ }
83
+ server.sceneFor(session);
84
+ server.ready(world);
85
+ const say = (id, data) => server.message(session, { playerId: id }, data);
86
+ const tick = (ms = 50) => {
87
+ world.timeMs += ms;
88
+ server.place(world);
89
+ server.step(world, []);
90
+ };
91
+ // Everyone says hello and is arrived: p2 came through a door with a friend.
92
+ say('p1', { k: 'hub-hello', avatar: 0, party: 1 });
93
+ say('p2', { k: 'hub-hello', avatar: 3, party: 1, from: 'race', near: '101' });
94
+ tick(2000);
95
+ tick();
96
+ const arrivedTimes = (id) => arrivals.filter((g) => g.some((p) => p.playerId === id)).length;
97
+ // The platform reports p2 gone and the real-time server removes its body.
98
+ const drop = () => {
99
+ session.players = session.players.filter((p) => p.playerId !== 'p2');
100
+ world.players.delete('p2');
101
+ };
102
+ // The SDK resumes the same connection: the same player id, a new body.
103
+ const back = () => {
104
+ session.players.push({ playerId: 'p2', userId: '102', username: 'Bo', isAnonymous: false });
105
+ world.players.set('p2', body());
106
+ };
107
+ return { server, session, world, sent, arrivals, leaves, say, tick, drop, back, arrivedTimes, ctx: () => ctx };
108
+ }
109
+
110
+ // The client's re-hello (client/rehello.js, sendHello): fresh, a party of one.
111
+ const rehello = { k: 'hub-hello', avatar: 3, party: 1, from: 'race', carry: null, resume: true };
112
+ const result = { result: { score: { unit: 's', better: 'lower' } } };
113
+
114
+ let passed = 0;
115
+ function test(name, fn) {
116
+ fn();
117
+ passed += 1;
118
+ console.log(`ok: ${name}`);
119
+ }
120
+ const toP2 = (r, from) => r.sent.slice(from).filter(([id]) => id === 'p2').map(([, m]) => m);
121
+
122
+ // v1.88: a fresh client under an id the place retained has none of its
123
+ // private channels. Re-send only what was non-empty, to that player alone.
124
+ const privateChannels = [
125
+ {
126
+ k: 'hub-hud',
127
+ set: (r, id) => r.ctx().setHud({ title: 'Mine', text: 'Private HUD' }, id),
128
+ clear: (r) => r.ctx().setHud(null, 'p2'),
129
+ value: { k: 'hub-hud', hud: { title: 'Mine', text: 'Private HUD' } },
130
+ empty: { k: 'hub-hud', hud: null },
131
+ },
132
+ {
133
+ k: 'hub-labels',
134
+ set: (r, id) => r.ctx().label('floor', 'My boat', { to: [id], style: 'sign' }),
135
+ clear: (r) => r.ctx().label('floor', null, { to: ['p2'] }),
136
+ value: { k: 'hub-labels', labels: { floor: { text: 'My boat', style: 'sign' } } },
137
+ empty: { k: 'hub-labels', labels: {} },
138
+ },
139
+ {
140
+ k: 'hub-tune',
141
+ set: (r, id) => assert.equal(r.ctx().tune(id, { speed: 2, jump: 1.5 }), true),
142
+ clear: (r) => assert.equal(r.ctx().tune('p2', null), true),
143
+ value: { k: 'hub-tune', tune: { speed: 2, jump: 1.5 } },
144
+ empty: { k: 'hub-tune', tune: null },
145
+ },
146
+ {
147
+ k: 'hub-av',
148
+ // Each player in a hidden pair sees their own avatar privately.
149
+ set(r) {
150
+ r.session.hub = {
151
+ arrival: () => null,
152
+ readResults: async () => ({ players: {}, boards: {} }),
153
+ hiddenPair: () => true,
154
+ };
155
+ },
156
+ clear: (r) => {
157
+ r.session.hub.hiddenPair = () => false;
158
+ },
159
+ value: { k: 'hub-av', hubAv: { p2: 3 } },
160
+ empty: { k: 'hub-av', hubAv: {} },
161
+ },
162
+ ];
163
+ const privateMessages = (r, from) => r.sent.slice(from).filter(([, m]) => privateChannels.some(({ k }) => m.k === k));
164
+ const freshHello = { k: 'hub-hello', avatar: 3, party: 1 };
165
+
166
+ for (const channel of privateChannels) {
167
+ const withPrivate = () => {
168
+ const r = boot();
169
+ const from = r.sent.length;
170
+ channel.set(r, 'p1');
171
+ channel.set(r, 'p2');
172
+ r.tick();
173
+ assert.deepEqual(toP2(r, from).filter((m) => m.k === channel.k), [channel.value], 'the private value was sent once');
174
+ r.tick();
175
+ assert.deepEqual(toP2(r, from).filter((m) => m.k === channel.k), [channel.value], 'equal values were suppressed');
176
+ return r;
177
+ };
178
+
179
+ test(`retained id: fresh hello replays ${channel.k} once to its owner alone`, () => {
180
+ const r = withPrivate();
181
+ const from = r.sent.length;
182
+ // No tick sees the drop, so the place never lets this player go.
183
+ r.drop();
184
+ r.back();
185
+ r.say('p2', freshHello);
186
+ assert.deepEqual(privateMessages(r, from), [], 'the replay waits for the tick');
187
+ r.tick();
188
+ assert.deepEqual(privateMessages(r, from), [['p2', channel.value]], 'only the saying player gets the current value');
189
+ r.tick();
190
+ assert.deepEqual(privateMessages(r, from), [['p2', channel.value]], 'no second send on the following tick');
191
+ assert.deepEqual(r.leaves, [], 'the player was retained');
192
+ assert.equal(r.arrivedTimes('p2'), 1, 'no second arrival');
193
+ });
194
+
195
+ test(`retained id: fresh hello sends no ${channel.k} where none was ever set`, () => {
196
+ const r = boot();
197
+ // Another player's private state must not be replayed either.
198
+ if (channel.k !== 'hub-av') {
199
+ channel.set(r, 'p1');
200
+ }
201
+ r.tick();
202
+ assert.ok(!r.sent.some(([id, m]) => id === 'p2' && m.k === channel.k), 'no value was ever sent');
203
+ const from = r.sent.length;
204
+ r.say('p2', freshHello);
205
+ r.tick();
206
+ r.tick();
207
+ assert.deepEqual(privateMessages(r, from), [], 'absent channels stay silent for everyone');
208
+ });
209
+
210
+ test(`retained id: fresh hello sends no ${channel.k} after its empty value was sent`, () => {
211
+ const r = withPrivate();
212
+ const cleared = r.sent.length;
213
+ channel.clear(r);
214
+ r.tick();
215
+ assert.deepEqual(toP2(r, cleared).filter((m) => m.k === channel.k), [channel.empty], 'the default was sent');
216
+ const from = r.sent.length;
217
+ r.say('p2', freshHello);
218
+ r.tick();
219
+ r.tick();
220
+ assert.deepEqual(privateMessages(r, from), [], 'default channels stay silent for everyone');
221
+ });
222
+
223
+ test(`retained id: a resume hello re-sends a ${channel.k} clear the held client may have missed, once`, () => {
224
+ const r = withPrivate();
225
+ r.drop();
226
+ r.back();
227
+ // The clear goes out while the connection is away; the client keeps the old value.
228
+ channel.clear(r);
229
+ r.tick();
230
+ const from = r.sent.length;
231
+ r.say('p2', { ...freshHello, resume: true });
232
+ r.tick();
233
+ assert.deepEqual(privateMessages(r, from), [['p2', channel.empty]], 'the empty value goes again to its owner alone');
234
+ r.tick();
235
+ assert.deepEqual(privateMessages(r, from), [['p2', channel.empty]], 'no second send on the following tick');
236
+ });
237
+
238
+ test(`retained id: a resume hello sends no ${channel.k} where none was ever set`, () => {
239
+ const r = boot();
240
+ r.tick();
241
+ const from = r.sent.length;
242
+ r.say('p2', { ...freshHello, resume: true });
243
+ r.tick();
244
+ r.tick();
245
+ assert.deepEqual(privateMessages(r, from), [], 'unused channels stay silent');
246
+ });
247
+
248
+ test(`retained id: an again hello replays no ${channel.k}`, () => {
249
+ const r = withPrivate();
250
+ const from = r.sent.length;
251
+ r.say('p2', { ...freshHello, again: true });
252
+ r.tick();
253
+ r.tick();
254
+ assert.deepEqual(privateMessages(r, from), [], 'an avatar-only hello replays nothing');
255
+ });
256
+ }
257
+
258
+ test('the client hello comes first: arrived again once, its stale HUD and leaving line cleared, no greet after', () => {
259
+ const r = boot();
260
+ r.ctx().setHud({ title: 'Hi', big: 'B', text: 'Mine' }, 'p2');
261
+ r.tick();
262
+ r.drop();
263
+ r.tick();
264
+ assert.deepEqual(r.leaves, ['p2'], 'the leave ran');
265
+ r.back();
266
+ r.tick(500);
267
+ const from = r.sent.length;
268
+ r.say('p2', rehello);
269
+ r.tick(2000);
270
+ r.tick();
271
+ assert.equal(r.arrivedTimes('p2'), 2, 'arrived again');
272
+ const got = toP2(r, from);
273
+ assert.ok(got.some((m) => m.k === 'hub-arrived'), 'told it arrived');
274
+ assert.ok(got.some((m) => m.k === 'hub-hud' && m.hud === null), 'the stale private HUD is cleared');
275
+ assert.ok(got.some((m) => m.k === 'hub-leaving' && m.text === null), 'a stale leaving line is cleared');
276
+ for (let i = 0; i < 10; i += 1) r.tick(1000);
277
+ assert.equal(r.arrivedTimes('p2'), 2, 'the late greet does not fire on top');
278
+ assert.equal(r.arrivedTimes('p1'), 1, 'nobody else arrives again');
279
+ });
280
+
281
+ test('the place greets first and the client hello lands after: one arrive', () => {
282
+ const r = boot();
283
+ r.drop();
284
+ r.tick();
285
+ r.back();
286
+ for (let i = 0; i < 5; i += 1) r.tick(1000);
287
+ assert.equal(r.arrivedTimes('p2'), 2, 'the late greet arrived it');
288
+ const from = r.sent.length;
289
+ r.say('p2', rehello);
290
+ for (let i = 0; i < 5; i += 1) r.tick(1000);
291
+ assert.equal(r.arrivedTimes('p2'), 2, 'the client hello did not arrive it again');
292
+ assert.ok(!toP2(r, from).some((m) => m.k === 'hub-leaving' && m.text === null), 'and is not treated as a return twice');
293
+ });
294
+
295
+ test('the client hello lands in the tick the greet fires, and again after: one arrive', () => {
296
+ const r = boot();
297
+ r.drop();
298
+ r.tick();
299
+ r.back();
300
+ r.tick(1000);
301
+ r.tick(3100);
302
+ r.say('p2', rehello);
303
+ r.tick();
304
+ r.say('p2', rehello);
305
+ for (let i = 0; i < 5; i += 1) r.tick(1000);
306
+ assert.equal(r.arrivedTimes('p2'), 2);
307
+ assert.deepEqual(r.leaves, ['p2']);
308
+ });
309
+
310
+ test('a repeated hello from a player the place still has is idempotent', () => {
311
+ const r = boot();
312
+ const arrivedAt = r.ctx().players().find((p) => p.playerId === 'p2').arrivedAt;
313
+ assert.equal(typeof arrivedAt, 'number');
314
+ const from = r.sent.length;
315
+ // The connection came back before the place's tick saw it go: it never
316
+ // forgot the player, and the client's hello is a repeat.
317
+ r.drop();
318
+ r.back();
319
+ r.tick();
320
+ r.say('p2', rehello);
321
+ r.say('p2', rehello);
322
+ for (let i = 0; i < 6; i += 1) r.tick(1000);
323
+ assert.equal(r.arrivedTimes('p2'), 1, 'the arrive hook ran once');
324
+ assert.deepEqual(r.leaves, [], 'no leave');
325
+ assert.ok(!toP2(r, from).some((m) => m.k === 'hub-arrived'), 'not told it arrived again');
326
+ // A repeat with another avatar and another door: only the avatar changes.
327
+ r.say('p2', { ...rehello, avatar: 5, from: 'other', near: '999', party: 4 });
328
+ r.tick(2000);
329
+ r.tick();
330
+ assert.equal(r.arrivedTimes('p2'), 1);
331
+ assert.equal(r.server.join().hubAv2?.p2, 5, 'the new avatar is worn');
332
+ assert.equal(r.ctx().players().find((p) => p.playerId === 'p2').arrivedAt, arrivedAt, 'its arrival kept');
333
+ });
334
+
335
+ test('a game (result) takes neither the greet nor a client resume hello from a player it let go', () => {
336
+ const r = boot(result);
337
+ r.drop();
338
+ r.tick();
339
+ r.back();
340
+ r.tick(500);
341
+ r.say('p2', rehello);
342
+ for (let i = 0; i < 8; i += 1) r.tick(1000);
343
+ assert.equal(r.arrivedTimes('p2'), 1, 'not arrived again');
344
+ assert.deepEqual(r.leaves, ['p2']);
345
+ });
346
+
347
+ test('two resume hellos in one tick: the stale ballot card and HUD are each cleared once', () => {
348
+ const r = boot({ ballot: true });
349
+ r.ctx().setHud({ title: 'Hi', big: 'B', text: 'Mine' }, 'p2');
350
+ assert.equal(r.ctx().ballot(['p2'], { mode: 'vote', faces: [{ playerId: 'p1' }, { playerId: 'p2' }] }), true);
351
+ r.tick();
352
+ r.drop();
353
+ r.tick();
354
+ r.back();
355
+ r.tick(500);
356
+ const from = r.sent.length;
357
+ r.say('p2', rehello);
358
+ r.say('p2', rehello);
359
+ r.tick();
360
+ r.tick();
361
+ const got = toP2(r, from);
362
+ assert.equal(got.filter((m) => m.k === 'hub-ballot-card' && m.card === null).length, 1, 'one card clear');
363
+ assert.equal(got.filter((m) => m.k === 'hub-hud' && m.hud === null).length, 1, 'one HUD clear');
364
+ assert.equal(got.filter((m) => m.k === 'hub-leaving' && m.text === null).length, 1, 'one leaving clear');
365
+ assert.equal(r.arrivedTimes('p2'), 2, 'arrived again once');
366
+ });
367
+
368
+ // v1.72: a game whose place says `resume: true` is greeted and re-helloed as any place.
369
+ const resumeGame = { ...result, resume: true };
370
+ const pose = { look: { x: 1, y: 2, z: 3 }, distance: 8, pitch: 30, yaw: 45 };
371
+
372
+ test('a resume game: the client hello after a leave arrives once, with its HUD and shot back', () => {
373
+ const r = boot(resumeGame);
374
+ r.ctx().setHud({ title: 'Talk', big: '0:30', text: 'Mine' }, 'p2');
375
+ assert.equal(r.ctx().shot('p2', pose), true);
376
+ r.tick();
377
+ r.drop();
378
+ r.tick();
379
+ assert.deepEqual(r.leaves, ['p2'], 'the leave ran');
380
+ assert.equal(r.ctx().shot('p2', pose), false, 'no shot for a player let go');
381
+ r.back();
382
+ r.tick(500);
383
+ const from = r.sent.length;
384
+ r.say('p2', rehello);
385
+ r.tick(2000);
386
+ r.tick();
387
+ assert.equal(r.arrivedTimes('p2'), 2, 'arrived again, once');
388
+ r.ctx().setHud({ title: 'Vote', big: '0:20', text: 'Mine' }, 'p2');
389
+ assert.equal(r.ctx().shot('p2', { ...pose, yaw: 50 }), true, 'hub.shot is accepted again');
390
+ r.tick();
391
+ const got = toP2(r, from);
392
+ assert.ok(got.some((m) => m.k === 'hub-arrived'), 'told it arrived');
393
+ assert.ok(got.some((m) => m.k === 'hub-hud' && m.hud?.title === 'Vote'), 'a live HUD');
394
+ assert.ok(got.some((m) => m.k === 'hub-shot' && m.shot?.yaw === 50), 'the shot');
395
+ for (let i = 0; i < 10; i += 1) r.tick(1000);
396
+ assert.equal(r.arrivedTimes('p2'), 2, 'the late greet does not fire on top');
397
+ assert.equal(r.arrivedTimes('p1'), 1);
398
+ assert.deepEqual(r.leaves, ['p2']);
399
+ });
400
+
401
+ test('a resume game: a player it still has is not arrived again, and is re-sent its HUD', () => {
402
+ const r = boot(resumeGame);
403
+ r.ctx().setHud({ title: 'Talk', big: '0:30', text: 'Mine' }, 'p2');
404
+ r.tick();
405
+ const arrivedAt = r.ctx().players().find((p) => p.playerId === 'p2').arrivedAt;
406
+ r.drop();
407
+ r.back();
408
+ r.tick();
409
+ const from = r.sent.length;
410
+ r.say('p2', rehello);
411
+ r.say('p2', rehello);
412
+ for (let i = 0; i < 6; i += 1) r.tick(1000);
413
+ assert.equal(r.arrivedTimes('p2'), 1, 'the arrive hook ran once');
414
+ assert.deepEqual(r.leaves, []);
415
+ const got = toP2(r, from);
416
+ assert.ok(!got.some((m) => m.k === 'hub-arrived'), 'not told it arrived again');
417
+ assert.ok(got.some((m) => m.k === 'hub-hud' && m.hud?.title === 'Talk'), 'its HUD goes again');
418
+ assert.ok(!got.some((m) => m.k === 'hub-leaving'), 'no leaving line it never had');
419
+ assert.equal(r.ctx().players().find((p) => p.playerId === 'p2').arrivedAt, arrivedAt, 'its arrival kept');
420
+ });
421
+
422
+ test('a resume game: the greet first, then the client hello: one arrive, and it keeps its door', () => {
423
+ const r = boot(resumeGame);
424
+ r.drop();
425
+ r.tick();
426
+ r.back();
427
+ for (let i = 0; i < 5; i += 1) r.tick(1000);
428
+ assert.equal(r.arrivedTimes('p2'), 2, 'the late greet arrived it');
429
+ assert.equal(r.arrivals.at(-1).find((p) => p.playerId === 'p2').from, 'race', 'the door it first came by, though the greet names none');
430
+ r.say('p2', rehello);
431
+ for (let i = 0; i < 5; i += 1) r.tick(1000);
432
+ assert.equal(r.arrivedTimes('p2'), 2, 'the client hello did not arrive it again');
433
+ assert.deepEqual(r.leaves, ['p2']);
434
+ });
435
+
436
+ test('a resume game: the client hello in the tick the greet fires, and again: one arrive', () => {
437
+ const r = boot(resumeGame);
438
+ r.drop();
439
+ r.tick();
440
+ r.back();
441
+ r.tick(1000);
442
+ r.tick(3100);
443
+ r.say('p2', rehello);
444
+ r.tick();
445
+ r.say('p2', rehello);
446
+ for (let i = 0; i < 5; i += 1) r.tick(1000);
447
+ assert.equal(r.arrivedTimes('p2'), 2);
448
+ assert.deepEqual(r.leaves, ['p2']);
449
+ });
450
+
451
+ test('a resume game: a result reported before the leave is kept, so a second is refused', () => {
452
+ const r = boot(resumeGame);
453
+ assert.equal(r.ctx().result('p2', { outcome: 'win', score: 12 }), true);
454
+ r.drop();
455
+ r.tick();
456
+ r.back();
457
+ r.say('p2', rehello);
458
+ r.tick(2000);
459
+ r.tick();
460
+ assert.equal(r.arrivedTimes('p2'), 2);
461
+ assert.equal(r.ctx().result('p2', { outcome: 'lose', score: 11 }), false, 'already reported');
462
+ });
463
+
464
+ test('a resume game: one who left with no result may still report one, once', () => {
465
+ const r = boot(resumeGame);
466
+ r.drop();
467
+ r.tick();
468
+ r.back();
469
+ for (let i = 0; i < 5; i += 1) r.tick(1000);
470
+ assert.equal(r.arrivedTimes('p2'), 2);
471
+ assert.equal(r.ctx().result('p2', { outcome: 'win', score: 12 }), true);
472
+ assert.equal(r.ctx().result('p2', { outcome: 'win', score: 10 }), false);
473
+ });
474
+
475
+ test('review I1: a result the leave hook reports is kept, so after resume a second is refused (one hub-result sent)', () => {
476
+ const r = boot(resumeGame, { leave: (ctx, id) => assert.equal(ctx.result(id, { outcome: 'win', score: 3 }), true) });
477
+ r.drop();
478
+ r.tick();
479
+ r.back();
480
+ r.say('p2', rehello);
481
+ r.tick(2000);
482
+ r.tick();
483
+ assert.equal(r.arrivedTimes('p2'), 2);
484
+ assert.equal(r.ctx().result('p2', { outcome: 'lose', score: 1 }), false, 'already reported in the leave');
485
+ assert.equal(r.sent.filter(([id, m]) => id === 'p2' && m.k === 'hub-result').length, 1, 'one result sent');
486
+ });
487
+
488
+ test('review I2: the visit deadline is set once: 30 s max, a drop at 25 s, resumed, ended at 30 s', () => {
489
+ const r = boot({ ...resumeGame, maxDurationSec: 30 });
490
+ const firstAt = r.ctx().players().find((p) => p.playerId === 'p2').arrivedAt;
491
+ while (r.world.timeMs < firstAt + 25000) r.tick(500);
492
+ r.drop();
493
+ r.tick();
494
+ r.back();
495
+ r.say('p2', rehello);
496
+ r.tick(2000);
497
+ r.tick();
498
+ assert.equal(r.arrivedTimes('p2'), 2);
499
+ const ends = () => r.sent.filter(([id, m]) => id === 'p2' && m.k === 'hub-end');
500
+ while (r.world.timeMs < firstAt + 29500) r.tick(500);
501
+ assert.equal(ends().length, 0, 'not before 30 s');
502
+ while (r.world.timeMs < firstAt + 30500) r.tick(250);
503
+ assert.deepEqual(ends().map(([, m]) => m), [{ k: 'hub-end', why: 'time' }], 'ended at the first deadline');
504
+ // Without the key the same drop starts the clock again (unchanged).
505
+ const plain = boot({ maxDurationSec: 30 });
506
+ const at = plain.ctx().players().find((p) => p.playerId === 'p2').arrivedAt;
507
+ plain.drop();
508
+ plain.tick();
509
+ plain.back();
510
+ while (plain.world.timeMs < at + 5000) plain.tick(500);
511
+ plain.say('p2', rehello);
512
+ plain.tick(2000);
513
+ plain.tick();
514
+ assert.ok(plain.ctx().players().find((p) => p.playerId === 'p2').arrivedAt > at);
515
+ });
516
+
517
+ test('review I3: an ended visit hears the end again on resume, marked again; the client takes it only if not already ending', () => {
518
+ const r = boot({ ...resumeGame, maxDurationSec: 30 });
519
+ while (!r.sent.some(([id, m]) => id === 'p2' && m.k === 'hub-end')) r.tick(500);
520
+ r.drop();
521
+ r.tick();
522
+ r.back();
523
+ const from = r.sent.length;
524
+ r.say('p2', rehello);
525
+ r.tick(2000);
526
+ r.tick();
527
+ const got = toP2(r, from);
528
+ const arrived = got.findIndex((m) => m.k === 'hub-arrived');
529
+ const end = got.findIndex((m) => m.k === 'hub-end');
530
+ assert.ok(arrived >= 0 && end > arrived, 'arrived, then the end again');
531
+ assert.deepEqual(got[end], { k: 'hub-end', why: 'time', again: true });
532
+ assert.equal(got.filter((m) => m.k === 'hub-end').length, 1, 'once');
533
+ assert.equal(r.ctx().shot('p2', pose), false, 'still ended: no shot');
534
+ // A resume hello while still here and ended: the end once more.
535
+ const at2 = r.sent.length;
536
+ r.say('p2', rehello);
537
+ assert.equal(toP2(r, at2).filter((m) => m.k === 'hub-end' && m.again).length, 1);
538
+ // The client: an end said again does not restart one already pending.
539
+ assert.equal(takesEnd({ k: 'hub-end', why: 'time', again: true }, 1000, 's1', 's1'), false);
540
+ assert.equal(takesEnd({ k: 'hub-end', why: 'time', again: true }, null, null, 's1'), true, 'one that missed it ends');
541
+ assert.equal(takesEnd({ k: 'hub-end', why: 'time', again: true }, 1000, 's0', 's1'), true, 'another session');
542
+ assert.equal(takesEnd({ k: 'hub-end', why: 'time' }, 1000, 's1', 's1'), true, 'a plain end as before');
543
+ });
544
+
545
+ test('review I4: provenance is written once: greet first, client hello, drop, hello again: the door kept', () => {
546
+ const r = boot(resumeGame);
547
+ const bare = { ...rehello };
548
+ delete bare.from;
549
+ r.drop();
550
+ r.tick();
551
+ r.back();
552
+ for (let i = 0; i < 5; i += 1) r.tick(1000);
553
+ assert.equal(r.arrivedTimes('p2'), 2, 'the greet arrived it');
554
+ r.say('p2', bare); // the client's own hello, naming no door
555
+ r.tick();
556
+ r.drop();
557
+ r.tick();
558
+ r.back();
559
+ r.say('p2', bare);
560
+ r.tick(2000);
561
+ r.tick();
562
+ assert.equal(r.arrivedTimes('p2'), 3);
563
+ assert.equal(r.arrivals.at(-1).find((p) => p.playerId === 'p2').from, 'race', 'the first door, kept');
564
+ });
565
+
566
+ test('review I4: a first visit by no door keeps none: a resume whose hello or platform arrival names one is not taken', () => {
567
+ // Dev (the client's word): p1 came by no door.
568
+ const r = boot(resumeGame);
569
+ assert.equal(r.arrivals[0].find((p) => p.playerId === 'p1').from, null);
570
+ r.session.players = r.session.players.filter((p) => p.playerId !== 'p1');
571
+ r.world.players.delete('p1');
572
+ r.tick();
573
+ r.session.players.push({ playerId: 'p1', userId: '101', username: 'Ada', isAnonymous: false });
574
+ r.world.players.set('p1', body());
575
+ r.say('p1', { ...rehello, avatar: 0, from: 'other' });
576
+ r.tick(2000);
577
+ r.tick();
578
+ assert.equal(r.arrivedTimes('p1'), 2);
579
+ assert.equal(r.arrivals.at(-1).find((p) => p.playerId === 'p1').from, null, 'from stays none');
580
+ });
581
+
582
+ // Where the host has hub ops (ghost's arrival, an async read to wait for).
583
+ {
584
+ const flush = () => new Promise((resolve) => setImmediate(resolve));
585
+ const doors = new Map();
586
+ const plat = boot(resumeGame, { doors });
587
+ const settle = async () => {
588
+ for (let i = 0; i < 4; i += 1) {
589
+ await flush();
590
+ plat.tick(1000);
591
+ }
592
+ };
593
+ await settle();
594
+ const first = plat.arrivals.flat().find((p) => p.playerId === 'p2');
595
+ assert.equal(first.from, null, 'p2 came by no door');
596
+ assert.equal(first.fromDeckId, null);
597
+ doors.set('p2', { doorId: 'other', fromDeckId: 'deckOther' });
598
+ plat.drop();
599
+ plat.tick();
600
+ plat.back();
601
+ plat.say('p2', rehello);
602
+ await settle();
603
+ assert.equal(plat.arrivedTimes('p2'), 2);
604
+ const again = plat.arrivals.at(-1).find((p) => p.playerId === 'p2');
605
+ assert.equal(again.from, null, 'from stays none');
606
+ assert.equal(again.fromDeckId, null, 'fromDeckId stays none');
607
+ // A repeated hello while still here cannot write it either.
608
+ plat.say('p2', rehello);
609
+ plat.drop();
610
+ plat.tick();
611
+ plat.back();
612
+ plat.say('p2', rehello);
613
+ await settle();
614
+ assert.equal(plat.arrivedTimes('p2'), 3);
615
+ assert.deepEqual([plat.arrivals.at(-1).find((p) => p.playerId === 'p2').from, plat.arrivals.at(-1).find((p) => p.playerId === 'p2').fromDeckId], [null, null]);
616
+ passed += 1;
617
+ console.log('ok: review I4: with hub ops, a platform arrival naming a door on resume does not replace none');
618
+ }
619
+
620
+ test('keys absent: a game without resume sends the same bytes whether or not the client re-hellos', () => {
621
+ const trace = (rehelloToo) => {
622
+ const r = boot(result);
623
+ r.ctx().setHud({ title: 'Talk', big: '0:30', text: 'Mine' }, 'p2');
624
+ r.tick();
625
+ r.drop();
626
+ r.tick();
627
+ r.back();
628
+ r.tick(500);
629
+ if (rehelloToo) {
630
+ r.say('p2', rehello);
631
+ }
632
+ for (let i = 0; i < 8; i += 1) r.tick(1000);
633
+ assert.equal(r.arrivedTimes('p2'), 1);
634
+ assert.ok(!('resume' in r.server.join({ playerId: 'p1' }).hubPlace), 'no resume key in its place');
635
+ return JSON.stringify(r.sent);
636
+ };
637
+ assert.equal(trace(true), trace(false));
638
+ });
639
+
640
+ // v1.89: a retained hello can reinstall deck-owned HUD/pointers after replay.
641
+ test('resume hook: retained fresh/resume hellos notify after private replay, coalesced per step', () => {
642
+ const calls = [];
643
+ let r;
644
+ r = boot({}, { resume(c, { playerId: id }) {
645
+ assert.equal(c, r.ctx());
646
+ calls.push(id);
647
+ const messages = toP2(r, from);
648
+ for (const key of ['hub-hud', 'hub-labels', 'hub-tune', 'hub-av']) {
649
+ assert.ok(messages.some((m) => m.k === key), `${key} sent before resume`);
650
+ }
651
+ c.setHud({ title: 'Current step' }, id);
652
+ } });
653
+ assert.deepEqual(calls, [], 'first arrivals do not notify');
654
+ r.ctx().setHud({ title: 'Previous step' }, 'p2');
655
+ r.ctx().label('floor', 'Pointer', { to: ['p2'], style: 'sign' });
656
+ r.ctx().tune('p2', { speed: 2 });
657
+ privateChannels.find((c) => c.k === 'hub-av').set(r, 'p2');
658
+ r.tick();
659
+ let from = r.sent.length;
660
+ r.say('p2', { k: 'hub-hello', avatar: 3 });
661
+ r.say('p2', { k: 'hub-hello', avatar: 3 });
662
+ assert.deepEqual(calls, [], 'deferred until replay sends');
663
+ r.tick();
664
+ assert.deepEqual(calls, ['p2']);
665
+ r.tick();
666
+ assert.ok(toP2(r, from).some((m) => m.k === 'hub-hud' && m.hud?.title === 'Current step'));
667
+ from = r.sent.length;
668
+ r.say('p2', rehello);
669
+ r.tick();
670
+ assert.deepEqual(calls, ['p2', 'p2']);
671
+ r.say('p2', { ...rehello, again: true });
672
+ r.tick();
673
+ assert.deepEqual(calls, ['p2', 'p2'], 'avatar-change hello excluded');
674
+ assert.equal(r.arrivedTimes('p2'), 1);
675
+ assert.deepEqual(r.leaves, []);
676
+ });
677
+
678
+ test('resume hook: genuine re-arrivals do not notify and a leave cancels queued retained hello', () => {
679
+ const calls = [];
680
+ const r = boot({}, { resume(c, { playerId: id }) { calls.push(id); } });
681
+ r.say('p2', rehello);
682
+ r.drop();
683
+ r.tick();
684
+ r.back();
685
+ r.say('p2', rehello);
686
+ r.tick();
687
+ assert.deepEqual(calls, []);
688
+ assert.equal(r.arrivedTimes('p2'), 2);
689
+ assert.deepEqual(r.leaves, ['p2']);
690
+ });
691
+
692
+ test('resume hook: missing hook preserves wire bytes for a retained hello', () => {
693
+ const trace = (hook) => {
694
+ const r = boot({}, hook ? { resume() {} } : {});
695
+ r.ctx().setHud({ title: 'Same' }, 'p2');
696
+ r.tick();
697
+ const from = r.sent.length;
698
+ r.say('p2', rehello);
699
+ r.tick();
700
+ return JSON.stringify(r.sent.slice(from));
701
+ };
702
+ assert.equal(trace(false), trace(true));
703
+ });
704
+
705
+ test('resume hook: avatar update preserves an already queued signal and hook errors are contained', () => {
706
+ const calls = [];
707
+ const r = boot({}, { resume(c, { playerId: id }) {
708
+ calls.push(id);
709
+ throw Error('deck hook failure');
710
+ } });
711
+ r.say('p2', rehello);
712
+ r.say('p2', { ...rehello, again: true, avatar: 2 });
713
+ r.say('p1', { k: 'hub-hello', avatar: 0, resume: true });
714
+ assert.doesNotThrow(() => r.tick());
715
+ assert.deepEqual(calls, ['p2', 'p1']);
716
+ r.tick();
717
+ assert.deepEqual(calls, ['p2', 'p1'], 'failed hooks are not retried');
718
+ });
719
+
720
+ // v1.89: advance a wall clock independently of simulation time. A suspended
721
+ // tab must not extend the grace by stopping its own frames.
722
+ function keeping(fn) {
723
+ const realNow = Date.now;
724
+ let now = realNow();
725
+ Date.now = () => now;
726
+ try {
727
+ fn((ms) => {
728
+ now += ms;
729
+ });
730
+ } finally {
731
+ Date.now = realNow;
732
+ }
733
+ }
734
+ const keepGame = { ...result, resume: { keep: true } };
735
+
736
+ test('keep resume: 30 s same-id return restores position, arrival, hold and tuning with no hooks', () =>
737
+ keeping((advance) => {
738
+ const r = boot(keepGame);
739
+ const at = { x: 2, y: 1, z: 3 };
740
+ r.ctx().placeAt('p2', at, 90);
741
+ r.ctx().hold('p2');
742
+ assert.equal(r.ctx().tune('p2', { speed: 2, jump: 1.5 }), true);
743
+ r.ctx().setHud({ title: 'Still playing' }, 'p2');
744
+ r.tick();
745
+ const arrivedAt = r
746
+ .ctx()
747
+ .players()
748
+ .find((p) => p.playerId === 'p2').arrivedAt;
749
+ r.drop();
750
+ r.tick();
751
+ advance(30000);
752
+ r.tick(30000);
753
+ assert.deepEqual(r.leaves, []);
754
+ r.back();
755
+ const from = r.sent.length;
756
+ r.say('p2', rehello); // hello before the first returning tick
757
+ r.tick();
758
+ assert.deepEqual(r.world.players.get('p2').at, at);
759
+ assert.equal(r.world.players.get('p2').facing, Math.PI / 2);
760
+ assert.equal(r.world.players.get('p2').maxSpeed, 24);
761
+ assert.ok(r.server.join({ playerId: 'p2' }).held.includes('p2'));
762
+ assert.equal(
763
+ r
764
+ .ctx()
765
+ .players()
766
+ .find((p) => p.playerId === 'p2').arrivedAt,
767
+ arrivedAt,
768
+ );
769
+ assert.equal(r.arrivedTimes('p2'), 1);
770
+ assert.deepEqual(r.leaves, []);
771
+ assert.ok(toP2(r, from).some((m) => m.k === 'hub-hud' && m.hud?.title === 'Still playing'));
772
+ assert.ok(toP2(r, from).some((m) => m.k === 'hub-tune' && m.tune?.speed === 2));
773
+ assert.equal(r.ctx().tune('p2', { speed: 1.5 }), true);
774
+ assert.equal(r.ctx().result('p2', { score: 8 }), true);
775
+ assert.equal(r.ctx().result('p2', { score: 9 }), false);
776
+ r.drop();
777
+ r.tick();
778
+ advance(60000);
779
+ r.tick();
780
+ r.tick();
781
+ assert.deepEqual(r.leaves, ['p2'], 'leave once at grace expiry');
782
+ }));
783
+
784
+ test('keep resume: silent return and repeated hellos never re-arrive or reset a result', () =>
785
+ keeping((advance) => {
786
+ const r = boot(keepGame);
787
+ r.ctx().placeAt('p2', { x: 2, y: 1, z: 2 });
788
+ assert.equal(r.ctx().result('p2', { score: 1 }), true);
789
+ r.tick();
790
+ r.drop();
791
+ r.tick();
792
+ advance(30000);
793
+ r.back();
794
+ r.tick(30000); // no client hello: same position and replay from the server
795
+ assert.deepEqual(r.world.players.get('p2').at, { x: 2, y: 1, z: 2 });
796
+ r.say('p2', rehello);
797
+ r.say('p2', rehello);
798
+ r.tick();
799
+ assert.equal(r.arrivedTimes('p2'), 1);
800
+ assert.deepEqual(r.leaves, []);
801
+ assert.equal(r.ctx().result('p2', { score: 2 }), false);
802
+ }));
803
+
804
+ test('resume hook: keep-mode silent return notifies once and expired return arrives instead', () =>
805
+ keeping((advance) => {
806
+ const calls = [];
807
+ const r = boot(keepGame, { resume(c, { playerId: id }) { calls.push(id); } });
808
+ r.drop();
809
+ r.tick();
810
+ advance(30000);
811
+ r.back();
812
+ r.tick();
813
+ assert.deepEqual(calls, ['p2']);
814
+ r.say('p2', rehello);
815
+ r.tick();
816
+ assert.deepEqual(calls, ['p2'], 'late client hello shares the silent-return signal');
817
+ r.drop();
818
+ r.tick();
819
+ advance(60000);
820
+ r.back();
821
+ r.say('p2', rehello);
822
+ r.tick();
823
+ assert.deepEqual(calls, ['p2']);
824
+ assert.equal(r.arrivedTimes('p2'), 2);
825
+ }));
826
+
827
+ test('keep resume: return at 60 s is fresh, including hello before reconcile', () =>
828
+ keeping((advance) => {
829
+ const r = boot(keepGame);
830
+ assert.equal(r.ctx().result('p2', { score: 1 }), true);
831
+ r.ctx().hold('p2', { x: 2, y: 1, z: 3 });
832
+ r.ctx().tune('p2', { speed: 2 });
833
+ r.tick();
834
+ const arrivedAt = r
835
+ .ctx()
836
+ .players()
837
+ .find((p) => p.playerId === 'p2').arrivedAt;
838
+ r.drop();
839
+ r.tick();
840
+ advance(60000);
841
+ r.back();
842
+ r.say('p2', rehello);
843
+ r.tick(60000);
844
+ r.tick();
845
+ assert.deepEqual(r.leaves, ['p2']);
846
+ assert.equal(r.arrivedTimes('p2'), 2);
847
+ assert.ok(
848
+ r
849
+ .ctx()
850
+ .players()
851
+ .find((p) => p.playerId === 'p2').arrivedAt > arrivedAt,
852
+ );
853
+ assert.ok(!r.server.join({ playerId: 'p2' }).held.includes('p2'));
854
+ assert.equal(r.world.players.get('p2').maxSpeed, undefined);
855
+ assert.equal(r.ctx().result('p2', { score: 2 }), true, 'new visit is eligible');
856
+ }));
857
+
858
+ test('keep resume: the original duration cap and fall hook work after return', () =>
859
+ keeping((advance) => {
860
+ let falls = 0;
861
+ const r = boot(
862
+ { ...keepGame, maxDurationSec: 40, fallY: -5 },
863
+ {
864
+ fall: () => {
865
+ falls += 1;
866
+ },
867
+ },
868
+ );
869
+ r.drop();
870
+ r.tick();
871
+ advance(30000);
872
+ r.back();
873
+ r.tick(30000);
874
+ r.world.players.get('p2').at.y = -10;
875
+ r.tick();
876
+ assert.ok(r.world.players.get('p2').at.y >= -5, 'fall is caught');
877
+ assert.equal(falls, 1, 'deck fall hook remains eligible');
878
+ while (r.world.timeMs < 42500) r.tick(500);
879
+ assert.ok(toP2(r, 0).some((m) => m.k === 'hub-end' && m.why === 'time'));
880
+ assert.equal(r.arrivedTimes('p2'), 1);
881
+ }));
882
+
883
+ test('keep resume: shutdown drains a retained absent player once', async () => {
884
+ // Shutdown runs its synchronous leave drain before its first await.
885
+ const r = boot(keepGame);
886
+ r.drop();
887
+ r.tick();
888
+ const shut = r.server.shutdown();
889
+ assert.deepEqual(r.leaves, ['p1', 'p2']);
890
+ await shut;
891
+ });
892
+
893
+ {
894
+ const r = boot({
895
+ ...keepGame,
896
+ unlocks: [
897
+ {
898
+ id: 'ribbon',
899
+ class: 'sash',
900
+ shape: 'sash-plain',
901
+ name: 'Ribbon',
902
+ deed: 'Finish',
903
+ color: '#ff0000',
904
+ },
905
+ ],
906
+ });
907
+ r.drop();
908
+ r.tick();
909
+ r.back();
910
+ r.tick();
911
+ const receipt = await r.ctx().unlock('p2', 'ribbon');
912
+ assert.equal(receipt?.isNew, true, 'unlock accepted after retained resume');
913
+ assert.equal(receipt?.saved, false, 'dev unlock is session-only');
914
+ passed += 1;
915
+ console.log('ok: keep resume: unlock remains eligible after same-id return');
916
+ }
917
+
918
+ test('keep resume: body replacement between ticks restores the old pose', () => {
919
+ const r = boot(keepGame);
920
+ r.ctx().placeAt('p2', { x: 2, y: 1, z: 3 });
921
+ r.tick();
922
+ r.drop();
923
+ r.back();
924
+ r.tick();
925
+ assert.deepEqual(r.world.players.get('p2').at, { x: 2, y: 1, z: 3 });
926
+ assert.deepEqual(r.leaves, []);
927
+ assert.equal(r.arrivedTimes('p2'), 1);
928
+ });
929
+
930
+ test('keep resume: travel from the first arrive bypasses retention before any pose snapshot', () => {
931
+ const r = boot({ ...keepGame, places: { lobby: { title: 'Lobby', scene: 'scenes/lobby.scene' } } }, {
932
+ actors: [...actors, { id: 'door', components: { HubDoor: { id: 'out', to: 'lobby' }, Transform: { x: 5, y: 0, z: 5 } } }],
933
+ arrive: (hub, group) => {
934
+ if (group.some((p) => p.playerId === 'p2')) assert.ok(hub.go('out', ['p2']));
935
+ },
936
+ });
937
+ assert.ok(toP2(r, 0).some((m) => m.k === 'hub-go'));
938
+ r.drop();
939
+ r.tick();
940
+ r.tick();
941
+ assert.deepEqual(r.leaves, ['p2'], 'explicit trip leaves exactly once without waiting');
942
+ r.back();
943
+ r.say('p2', rehello);
944
+ r.tick(2000);
945
+ r.tick();
946
+ assert.equal(r.arrivedTimes('p2'), 2, 'a return after travel is a fresh arrival');
947
+ });
948
+
949
+ test('resume hook: retained hello without a body is ignored safely', () => {
950
+ const calls = [];
951
+ const r = boot({}, { resume(c, { playerId }) { calls.push(playerId); } });
952
+ r.drop();
953
+ assert.doesNotThrow(() => r.say('p2', rehello));
954
+ r.tick();
955
+ assert.deepEqual(calls, []);
956
+ });
957
+
958
+ test('resume hook: travel cancels pending signals and failed travel allows a later resume', () => {
959
+ const calls = [];
960
+ const r = boot({ places: { lobby: { title: 'Lobby', scene: 'scenes/lobby.scene' } } }, {
961
+ actors: [...actors, { id: 'door', components: { HubDoor: { id: 'out', to: 'lobby' }, Transform: { x: 5, y: 0, z: 5 } } }],
962
+ resume(c, { playerId }) { calls.push(playerId); },
963
+ });
964
+ r.say('p2', rehello);
965
+ assert.ok(r.ctx().go('out', ['p2']));
966
+ r.say('p2', rehello);
967
+ r.tick();
968
+ assert.deepEqual(calls, [], 'travel cancels earlier and later retained hellos');
969
+ r.say('p2', { k: 'hub-shut', door: 'out' });
970
+ r.say('p2', rehello);
971
+ r.tick();
972
+ assert.deepEqual(calls, ['p2'], 'a failed trip does not permanently block resumes');
973
+ });
974
+
975
+ test('which hello a connection that came back says (helloAfter)', () => {
976
+ assert.equal(helloAfter(null, false), 'none', 'nothing came back: none');
977
+ assert.equal(helloAfter(null, true), 'none');
978
+ assert.equal(helloAfter('world', true), 'none', 'a game under the same id: none (the old way)');
979
+ assert.equal(helloAfter('self', true), 'fresh', 'a game under a new id: a fresh hello');
980
+ assert.equal(helloAfter('world', false), 'resume', 'a place under the same id: resume');
981
+ assert.equal(helloAfter('self', false), 'resume', 'a place under a new id: resume, as before');
982
+ // v1.72: the third input, the place's `resume`.
983
+ assert.equal(helloAfter('world', true, true), 'resume', 'a resume game under the same id: resume');
984
+ assert.equal(helloAfter('world', true, false), 'none', 'a game without the key: none');
985
+ assert.equal(helloAfter('self', true, true), 'fresh', 'a resume game under a new id: fresh');
986
+ assert.equal(helloAfter(null, true, true), 'none');
987
+ assert.equal(helloAfter('world', false, true), 'resume');
988
+ assert.equal(helloAfter('self', false, false), 'resume');
989
+ // Fails if the third input is ignored: the same first two, different answers.
990
+ assert.notEqual(helloAfter('world', true, true), helloAfter('world', true, false));
991
+ });
992
+
993
+ test('a game: a fresh hello from the same account under a new player id arrives once; the old id left once', () => {
994
+ const r = boot(result);
995
+ r.drop();
996
+ r.tick();
997
+ assert.deepEqual(r.leaves, ['p2'], 'the old id left');
998
+ // The connection is re-acquired under a new id (past the window, or a refused token).
999
+ r.session.players.push({ playerId: 'p9', userId: '102', username: 'Bo', isAnonymous: false });
1000
+ r.world.players.set('p9', { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
1001
+ for (let i = 0; i < 6; i += 1) r.tick(1000);
1002
+ assert.equal(r.arrivedTimes('p9'), 0, 'a game never greets for a new id');
1003
+ r.say('p9', { k: 'hub-hello', avatar: 3, from: null, party: 1, carry: null });
1004
+ r.tick(2000);
1005
+ r.tick();
1006
+ assert.equal(r.arrivedTimes('p9'), 1, 'arrived at once');
1007
+ r.say('p9', { k: 'hub-hello', avatar: 3, from: null, party: 1, carry: null });
1008
+ for (let i = 0; i < 4; i += 1) r.tick(1000);
1009
+ assert.equal(r.arrivedTimes('p9'), 1, 'and once');
1010
+ assert.equal(r.arrivedTimes('p2'), 1, 'the old id is not arrived again');
1011
+ assert.deepEqual(r.leaves, ['p2']);
1012
+ // A result is one per player id: the old id's (reported at its leave, while
1013
+ // known) and the new id's are separate entries.
1014
+ assert.equal(r.ctx().result('p9', { outcome: 'win', score: 12 }), true);
1015
+ assert.equal(r.ctx().result('p9', { outcome: 'win', score: 11 }), false, 'a second for the new id is refused');
1016
+ });
1017
+
1018
+ console.log(`rehello: ${passed} tests passed`);
1019
+
1020
+ // v1.90: real hello transport replays the private opt-in preference only to
1021
+ // its player, including a missed clear on a retained client.
1022
+ {
1023
+ const r = boot({}, { actors: [...actors, { id: 'rowan', components: {
1024
+ Transform: { x: 1, y: 1, z: 0 }, Body: { type: 'kinematic' }, HubNpc: { name: 'Rowan' },
1025
+ } }] });
1026
+ assert.ok(!r.sent.some(([, m]) => m.k === 'hub-npc-preferred'));
1027
+ assert.equal(r.ctx().preferNpc('p2', 'rowan'), true);
1028
+ let from = r.sent.length;
1029
+ r.say('p2', rehello); r.tick();
1030
+ assert.deepEqual(r.sent.slice(from).filter(([, m]) => m.k === 'hub-npc-preferred'), [
1031
+ ['p2', { k: 'hub-npc-preferred', npc: 'rowan' }],
1032
+ ]);
1033
+ r.ctx().preferNpc('p2', null);
1034
+ from = r.sent.length;
1035
+ r.say('p2', rehello); r.tick();
1036
+ assert.deepEqual(r.sent.slice(from).filter(([, m]) => m.k === 'hub-npc-preferred'), [
1037
+ ['p2', { k: 'hub-npc-preferred', npc: null }],
1038
+ ]);
1039
+ }