castle-web-cli 0.4.239 → 0.4.240

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 (386) hide show
  1. package/dist/agent.js +5 -1
  2. package/dist/api.d.ts +20 -0
  3. package/dist/api.js +57 -0
  4. package/dist/bundle.d.ts +38 -1
  5. package/dist/bundle.js +309 -13
  6. package/dist/castle-host/host.js +163 -11
  7. package/dist/castleJson.d.ts +10 -0
  8. package/dist/castleJson.js +46 -2
  9. package/dist/check.js +5 -2
  10. package/dist/devSessionServer.js +4 -1
  11. package/dist/devSessionStorage.d.ts +1 -0
  12. package/dist/devSessionStorage.js +32 -7
  13. package/dist/importOrder.d.ts +2 -0
  14. package/dist/importOrder.js +29 -0
  15. package/dist/index.js +6 -3
  16. package/dist/init.js +24 -2
  17. package/dist/platformDoc.js +2 -1
  18. package/dist/playPagePolicy.js +5 -1
  19. package/dist/resetLeaderboards.d.ts +8 -1
  20. package/dist/resetLeaderboards.js +43 -8
  21. package/dist/save-deck.d.ts +32 -2
  22. package/dist/save-deck.js +240 -39
  23. package/kits/base/CLAUDE.md +1 -1
  24. package/kits/base/castle.json +1 -1
  25. package/kits/base/sdk/README.md +174 -6
  26. package/kits/base/sdk/analytics.d.ts +8 -0
  27. package/kits/base/sdk/analytics.js +92 -0
  28. package/kits/base/sdk/castle.d.ts +5 -1
  29. package/kits/base/sdk/castle.js +2 -0
  30. package/kits/base/sdk/commands.d.ts +48 -0
  31. package/kits/base/sdk/commands.js +1 -0
  32. package/kits/base/sdk/debugConsole.d.ts +17 -0
  33. package/kits/base/sdk/debugConsole.js +154 -0
  34. package/kits/base/sdk/experiments.js +24 -1
  35. package/kits/base/sdk/hostRetry.d.ts +7 -0
  36. package/kits/base/sdk/hostRetry.js +57 -0
  37. package/kits/base/sdk/hub.d.ts +20 -2
  38. package/kits/base/sdk/hub.js +99 -13
  39. package/kits/base/sdk/multiplayer.d.ts +2 -0
  40. package/kits/base/sdk/multiplayer.js +168 -26
  41. package/kits/base/sdk/reconnectBudget.d.ts +6 -0
  42. package/kits/base/sdk/reconnectBudget.js +41 -1
  43. package/kits/base/sdk/runtime.js +36 -19
  44. package/kits/base/sdk/server/hub.d.ts +19 -0
  45. package/kits/base/sdk/server/hub.js +12 -0
  46. package/kits/base/sdk/server/platformHandle.d.ts +1 -0
  47. package/kits/base/sdk/server/wrapper.d.ts +1 -1
  48. package/kits/base/sdk/server/wrapper.js +26 -1
  49. package/kits/base/sdk/transport.d.ts +2 -1
  50. package/kits/base/sdk/transport.js +35 -0
  51. package/kits/hub-game/CLAUDE.md +66 -19
  52. package/kits/hub-game/code/client/act.js +9 -6
  53. package/kits/hub-game/code/client/actCore.js +26 -6
  54. package/kits/hub-game/code/client/actGateLog.js +36 -0
  55. package/kits/hub-game/code/client/actionOverflow.js +29 -8
  56. package/kits/hub-game/code/client/actionRailSurface.js +186 -0
  57. package/kits/hub-game/code/client/actionRailTree.js +173 -0
  58. package/kits/hub-game/code/client/askSurface.js +85 -0
  59. package/kits/hub-game/code/client/askTree.js +51 -0
  60. package/kits/hub-game/code/client/attention.js +31 -6
  61. package/kits/hub-game/code/client/ballot.js +42 -5
  62. package/kits/hub-game/code/client/ballotSurface.js +115 -0
  63. package/kits/hub-game/code/client/ballotTree.js +180 -0
  64. package/kits/hub-game/code/client/catchingUp.js +19 -0
  65. package/kits/hub-game/code/client/celebrate.js +66 -0
  66. package/kits/hub-game/code/client/chrome.js +473 -53
  67. package/kits/hub-game/code/client/companion.js +93 -23
  68. package/kits/hub-game/code/client/companionDress.js +1 -1
  69. package/kits/hub-game/code/client/cornerSurface.js +106 -0
  70. package/kits/hub-game/code/client/cornerTree.js +83 -0
  71. package/kits/hub-game/code/client/decor.js +20 -11
  72. package/kits/hub-game/code/client/deviceStorage.js +121 -0
  73. package/kits/hub-game/code/client/disguise.js +23 -0
  74. package/kits/hub-game/code/client/disguiseDraw.js +87 -0
  75. package/kits/hub-game/code/client/dockSurface.js +206 -0
  76. package/kits/hub-game/code/client/dockTree.js +232 -0
  77. package/kits/hub-game/code/client/earned.js +29 -0
  78. package/kits/hub-game/code/client/emoteSurface.js +188 -0
  79. package/kits/hub-game/code/client/emoteTree.js +264 -0
  80. package/kits/hub-game/code/client/farAvatars.js +4 -3
  81. package/kits/hub-game/code/client/fpsTelemetry.js +3 -1
  82. package/kits/hub-game/code/client/grab.js +121 -50
  83. package/kits/hub-game/code/client/holdShow.js +19 -0
  84. package/kits/hub-game/code/client/hookLayer.js +96 -12
  85. package/kits/hub-game/code/client/hubControls.js +7 -1
  86. package/kits/hub-game/code/client/hudSurface.js +11 -3
  87. package/kits/hub-game/code/client/hudTree.js +7 -4
  88. package/kits/hub-game/code/client/idle.js +21 -3
  89. package/kits/hub-game/code/client/invites.js +24 -3
  90. package/kits/hub-game/code/client/keys.js +15 -0
  91. package/kits/hub-game/code/client/labelsNear.js +8 -1
  92. package/kits/hub-game/code/client/layoutCache.js +57 -8
  93. package/kits/hub-game/code/client/loadingCover.js +53 -4
  94. package/kits/hub-game/code/client/menuIcons.js +15 -0
  95. package/kits/hub-game/code/client/menuSurface.js +102 -0
  96. package/kits/hub-game/code/client/menuTree.js +135 -0
  97. package/kits/hub-game/code/client/modelLook.js +41 -0
  98. package/kits/hub-game/code/client/pickerSurface.js +152 -0
  99. package/kits/hub-game/code/client/pickerTree.js +163 -0
  100. package/kits/hub-game/code/client/pushVisit.js +4 -2
  101. package/kits/hub-game/code/client/quality.js +188 -29
  102. package/kits/hub-game/code/client/qualityEntry.js +10 -1
  103. package/kits/hub-game/code/client/quickChatSurface.js +222 -0
  104. package/kits/hub-game/code/client/quickChatTree.js +201 -0
  105. package/kits/hub-game/code/client/rehello.js +75 -0
  106. package/kits/hub-game/code/client/renderVisibility.js +17 -0
  107. package/kits/hub-game/code/client/replay.js +118 -0
  108. package/kits/hub-game/code/client/role.js +3 -0
  109. package/kits/hub-game/code/client/safeLayout.js +441 -56
  110. package/kits/hub-game/code/client/safeStyle.js +13 -10
  111. package/kits/hub-game/code/client/say.js +2 -0
  112. package/kits/hub-game/code/client/soundSurface.js +77 -0
  113. package/kits/hub-game/code/client/soundTree.js +74 -0
  114. package/kits/hub-game/code/client/soundscape.js +12 -9
  115. package/kits/hub-game/code/client/soundscapeCues.js +1 -1
  116. package/kits/hub-game/code/client/state.js +67 -1
  117. package/kits/hub-game/code/client/stuckSurface.js +76 -0
  118. package/kits/hub-game/code/client/stuckTree.js +67 -0
  119. package/kits/hub-game/code/client/talk.js +42 -12
  120. package/kits/hub-game/code/client/talkTree.js +4 -2
  121. package/kits/hub-game/code/client/textAskSurface.js +147 -0
  122. package/kits/hub-game/code/client/textAskTree.js +67 -0
  123. package/kits/hub-game/code/client/tiers.js +252 -27
  124. package/kits/hub-game/code/client/together.js +4 -1
  125. package/kits/hub-game/code/client/uiDom.js +86 -8
  126. package/kits/hub-game/code/client/uiTree.js +33 -4
  127. package/kits/hub-game/code/client/vehicle.js +72 -51
  128. package/kits/hub-game/code/client/weakestTier.js +75 -31
  129. package/kits/hub-game/code/client/wear.js +159 -5
  130. package/kits/hub-game/code/client/worldLabels.js +205 -25
  131. package/kits/hub-game/code/companionSpec.js +4 -2
  132. package/kits/hub-game/code/server/act.js +3 -0
  133. package/kits/hub-game/code/server/actGate.js +83 -0
  134. package/kits/hub-game/code/server/actions.js +71 -15
  135. package/kits/hub-game/code/server/actors.js +20 -5
  136. package/kits/hub-game/code/server/analytics.js +35 -3
  137. package/kits/hub-game/code/server/ask.js +39 -3
  138. package/kits/hub-game/code/server/ballot.js +167 -4
  139. package/kits/hub-game/code/server/celebrate.js +64 -0
  140. package/kits/hub-game/code/server/companion.js +17 -2
  141. package/kits/hub-game/code/server/decor.js +11 -2
  142. package/kits/hub-game/code/server/disguise.js +63 -0
  143. package/kits/hub-game/code/server/earned.js +6 -2
  144. package/kits/hub-game/code/server/friendBests.js +13 -4
  145. package/kits/hub-game/code/server/friendsAmong.js +67 -8
  146. package/kits/hub-game/code/server/grab.js +12 -2
  147. package/kits/hub-game/code/server/heldOffers.js +142 -0
  148. package/kits/hub-game/code/server/holdShow.js +98 -0
  149. package/kits/hub-game/code/server/hub.js +851 -45
  150. package/kits/hub-game/code/server/idle.js +110 -9
  151. package/kits/hub-game/code/server/index.js +9 -0
  152. package/kits/hub-game/code/server/labels.js +13 -3
  153. package/kits/hub-game/code/server/manifest.js +94 -6
  154. package/kits/hub-game/code/server/menu.js +26 -3
  155. package/kits/hub-game/code/server/npcs.js +55 -9
  156. package/kits/hub-game/code/server/observe.js +67 -6
  157. package/kits/hub-game/code/server/players.js +8 -1
  158. package/kits/hub-game/code/server/replay.js +135 -0
  159. package/kits/hub-game/code/server/storageLimit.js +4 -1
  160. package/kits/hub-game/code/server/townDay.js +74 -0
  161. package/kits/hub-game/code/server/vehicle.js +3 -0
  162. package/kits/hub-game/code/server/vis.js +26 -4
  163. package/kits/hub-game/code/server/wallet.js +677 -0
  164. package/kits/hub-game/code/server/wear.js +13 -3
  165. package/kits/hub-game/code/server/writerLease.js +191 -0
  166. package/kits/hub-game/code/shared/act.js +1 -1
  167. package/kits/hub-game/code/shared/expression.js +6 -0
  168. package/kits/hub-game/code/shared/replay.js +37 -0
  169. package/kits/hub-game/code/systems/hub.js +427 -54
  170. package/kits/hub-game/docs/analytics.md +16 -2
  171. package/kits/hub-game/docs/contract.md +942 -99
  172. package/kits/hub-game/docs/home-pieces.md +5 -6
  173. package/kits/hub-game/docs/observed-progress.md +49 -1
  174. package/kits/hub-game/docs/vehicle-preset.md +23 -0
  175. package/kits/hub-game/index.html +1 -0
  176. package/kits/hub-game/models/hats/baker-cap.pxmodel +3 -3
  177. package/kits/hub-game/models/hats/bat-clip.pxmodel +3 -3
  178. package/kits/hub-game/models/hats/beekeeper.pxmodel +3 -3
  179. package/kits/hub-game/models/hats/cap.pxmodel +3 -3
  180. package/kits/hub-game/models/hats/captain.pxmodel +3 -3
  181. package/kits/hub-game/models/hats/chef-toque.pxmodel +3 -3
  182. package/kits/hub-game/models/hats/crooked-top.pxmodel +3 -3
  183. package/kits/hub-game/models/hats/delivery-cap.pxmodel +3 -3
  184. package/kits/hub-game/models/hats/fire-helmet.pxmodel +3 -3
  185. package/kits/hub-game/models/hats/flower-crown.pxmodel +3 -3
  186. package/kits/hub-game/models/hats/foam-crown.pxmodel +3 -3
  187. package/kits/hub-game/models/hats/hard-hat.pxmodel +3 -3
  188. package/kits/hub-game/models/hats/lantern.pxmodel +3 -3
  189. package/kits/hub-game/models/hats/laurel.pxmodel +3 -3
  190. package/kits/hub-game/models/hats/lighthouse.pxmodel +3 -3
  191. package/kits/hub-game/models/hats/nurse-cap.pxmodel +3 -3
  192. package/kits/hub-game/models/hats/police-cap.pxmodel +3 -3
  193. package/kits/hub-game/models/hats/sailor.pxmodel +3 -3
  194. package/kits/hub-game/models/hats/souwester.pxmodel +3 -3
  195. package/kits/hub-game/models/hats/straw.pxmodel +3 -3
  196. package/kits/hub-game/models/hats/sunflower.pxmodel +3 -3
  197. package/kits/hub-game/models/hats/sweatband.pxmodel +3 -3
  198. package/kits/hub-game/models/hats/teacher-beret.pxmodel +3 -3
  199. package/kits/hub-game/models/hats/witch.pxmodel +3 -3
  200. package/kits/hub-game/models/hold-show/daisy.pxmodel +231 -0
  201. package/kits/hub-game/models/hold-show/moonflower.pxmodel +171 -0
  202. package/kits/hub-game/models/hold-show/rose.pxmodel +191 -0
  203. package/kits/hub-game/models/hold-show/square/daisy.pxmodel +233 -0
  204. package/kits/hub-game/models/hold-show/square/moonflower.pxmodel +173 -0
  205. package/kits/hub-game/models/hold-show/square/rose.pxmodel +193 -0
  206. package/kits/hub-game/models/hold-show/square/sunflower.pxmodel +313 -0
  207. package/kits/hub-game/models/hold-show/square/tulip.pxmodel +133 -0
  208. package/kits/hub-game/models/hold-show/sunflower.pxmodel +311 -0
  209. package/kits/hub-game/models/hold-show/tulip.pxmodel +131 -0
  210. package/kits/hub-game/package-lock.json +3 -3
  211. package/kits/hub-game/package.json +4 -3
  212. package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +1 -0
  213. package/kits/hub-game/scripts/fixtures/hud-surface.json +12 -12
  214. package/kits/hub-game/scripts/fixtures/talk-surface.json +8 -8
  215. package/kits/hub-game/scripts/gen-hats.mjs +1 -1
  216. package/kits/hub-game/scripts/gen-hold-show.mjs +27 -0
  217. package/kits/hub-game/scripts/pack.mjs +89 -23
  218. package/kits/hub-game/scripts/test-act-client.mjs +5 -0
  219. package/kits/hub-game/scripts/test-act-core.mjs +32 -0
  220. package/kits/hub-game/scripts/test-act-gate.mjs +186 -0
  221. package/kits/hub-game/scripts/test-action-rail-crowded-dom.mjs +7 -1
  222. package/kits/hub-game/scripts/test-action-rail-default-dom.mjs +102 -0
  223. package/kits/hub-game/scripts/test-action-rail-never-silent-dom.mjs +50 -0
  224. package/kits/hub-game/scripts/test-action-rail-surface.mjs +368 -0
  225. package/kits/hub-game/scripts/test-action-rail-town-jobs-dom.mjs +118 -0
  226. package/kits/hub-game/scripts/test-actions-client.mjs +5 -3
  227. package/kits/hub-game/scripts/test-actions.mjs +24 -0
  228. package/kits/hub-game/scripts/test-actors.mjs +19 -0
  229. package/kits/hub-game/scripts/test-again-corner-dom.mjs +59 -0
  230. package/kits/hub-game/scripts/test-analytics.mjs +79 -0
  231. package/kits/hub-game/scripts/test-arrival-pose-server.mjs +25 -8
  232. package/kits/hub-game/scripts/test-ask-client.mjs +9 -0
  233. package/kits/hub-game/scripts/test-ask-surface.mjs +188 -0
  234. package/kits/hub-game/scripts/test-attention.mjs +43 -1
  235. package/kits/hub-game/scripts/test-ballot-sheet-dom.mjs +71 -0
  236. package/kits/hub-game/scripts/test-ballot-surface.mjs +276 -0
  237. package/kits/hub-game/scripts/test-ballot.mjs +420 -3
  238. package/kits/hub-game/scripts/test-ban-join.mjs +1 -1
  239. package/kits/hub-game/scripts/test-celebrate-client.mjs +62 -0
  240. package/kits/hub-game/scripts/test-celebrate.mjs +116 -0
  241. package/kits/hub-game/scripts/test-chat.mjs +73 -0
  242. package/kits/hub-game/scripts/test-companion-client.mjs +203 -21
  243. package/kits/hub-game/scripts/test-companion.mjs +110 -3
  244. package/kits/hub-game/scripts/test-control-layout-dom.mjs +57 -10
  245. package/kits/hub-game/scripts/test-corner-surface.mjs +268 -0
  246. package/kits/hub-game/scripts/test-decor-client.mjs +59 -3
  247. package/kits/hub-game/scripts/test-decor.mjs +27 -0
  248. package/kits/hub-game/scripts/test-device-class.mjs +4 -1
  249. package/kits/hub-game/scripts/test-disguise-client.mjs +281 -0
  250. package/kits/hub-game/scripts/test-disguise.mjs +176 -0
  251. package/kits/hub-game/scripts/test-dock-surface.mjs +404 -0
  252. package/kits/hub-game/scripts/test-door-stay-client.mjs +602 -0
  253. package/kits/hub-game/scripts/test-door-stay.mjs +613 -0
  254. package/kits/hub-game/scripts/test-earned-client.mjs +119 -0
  255. package/kits/hub-game/scripts/test-emote-surface.mjs +616 -0
  256. package/kits/hub-game/scripts/test-fps-telemetry.mjs +39 -4
  257. package/kits/hub-game/scripts/test-friend-bests.mjs +38 -12
  258. package/kits/hub-game/scripts/test-ghost-click-dom.mjs +75 -0
  259. package/kits/hub-game/scripts/test-grab-client.mjs +29 -2
  260. package/kits/hub-game/scripts/test-grab-orbit.mjs +260 -11
  261. package/kits/hub-game/scripts/test-grab.mjs +10 -1
  262. package/kits/hub-game/scripts/test-hats.mjs +28 -0
  263. package/kits/hub-game/scripts/test-held-offers.mjs +394 -0
  264. package/kits/hub-game/scripts/test-high-only.mjs +3 -3
  265. package/kits/hub-game/scripts/test-hold-show-client.mjs +175 -0
  266. package/kits/hub-game/scripts/test-hold-show.mjs +355 -0
  267. package/kits/hub-game/scripts/test-hub-controls.mjs +3 -1
  268. package/kits/hub-game/scripts/test-hub-idle.mjs +348 -0
  269. package/kits/hub-game/scripts/test-hub-leaving.mjs +21 -0
  270. package/kits/hub-game/scripts/test-hub-ops.mjs +119 -0
  271. package/kits/hub-game/scripts/test-hub-trip.mjs +240 -4
  272. package/kits/hub-game/scripts/test-hud-clear.mjs +83 -0
  273. package/kits/hub-game/scripts/test-hud-rate.mjs +2 -1
  274. package/kits/hub-game/scripts/test-idle.mjs +160 -0
  275. package/kits/hub-game/scripts/test-invites-client.mjs +53 -0
  276. package/kits/hub-game/scripts/test-labels.mjs +11 -0
  277. package/kits/hub-game/scripts/test-landscape-layout.mjs +20 -0
  278. package/kits/hub-game/scripts/test-loading-cover.mjs +67 -1
  279. package/kits/hub-game/scripts/test-manifest.mjs +27 -0
  280. package/kits/hub-game/scripts/test-menu-client.mjs +54 -5
  281. package/kits/hub-game/scripts/test-menu-surface.mjs +236 -0
  282. package/kits/hub-game/scripts/test-npcs.mjs +128 -0
  283. package/kits/hub-game/scripts/test-observed.mjs +171 -3
  284. package/kits/hub-game/scripts/test-pack.mjs +166 -0
  285. package/kits/hub-game/scripts/test-picker-surface.mjs +321 -0
  286. package/kits/hub-game/scripts/test-placeat-server.mjs +395 -0
  287. package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
  288. package/kits/hub-game/scripts/test-pointer-clear-dom.mjs +82 -0
  289. package/kits/hub-game/scripts/test-progress-reset.mjs +184 -6
  290. package/kits/hub-game/scripts/test-push-visit.mjs +9 -0
  291. package/kits/hub-game/scripts/test-quality.mjs +312 -9
  292. package/kits/hub-game/scripts/test-quick-chat-surface.mjs +511 -0
  293. package/kits/hub-game/scripts/test-rehello.mjs +237 -0
  294. package/kits/hub-game/scripts/test-rejoin-yaw.mjs +138 -0
  295. package/kits/hub-game/scripts/test-relations-among.mjs +13 -7
  296. package/kits/hub-game/scripts/test-relations-refresh.mjs +90 -2
  297. package/kits/hub-game/scripts/test-replay-client.mjs +110 -0
  298. package/kits/hub-game/scripts/test-replay.mjs +178 -0
  299. package/kits/hub-game/scripts/test-resume-held.mjs +13 -0
  300. package/kits/hub-game/scripts/test-resume-pose-server.mjs +43 -5
  301. package/kits/hub-game/scripts/test-role-client.mjs +2 -1
  302. package/kits/hub-game/scripts/test-safe-act.mjs +233 -0
  303. package/kits/hub-game/scripts/test-safe-caption.mjs +364 -0
  304. package/kits/hub-game/scripts/test-safe-layout.mjs +79 -0
  305. package/kits/hub-game/scripts/test-safe-prompt.mjs +163 -0
  306. package/kits/hub-game/scripts/test-sound-surface.mjs +256 -0
  307. package/kits/hub-game/scripts/test-soundscape.mjs +85 -2
  308. package/kits/hub-game/scripts/test-stuck-surface.mjs +174 -0
  309. package/kits/hub-game/scripts/test-stuck.mjs +31 -0
  310. package/kits/hub-game/scripts/test-talk-surface.mjs +23 -6
  311. package/kits/hub-game/scripts/test-talk-walk-dom.mjs +123 -0
  312. package/kits/hub-game/scripts/test-text-ask-surface.mjs +273 -0
  313. package/kits/hub-game/scripts/test-tiers.mjs +453 -3
  314. package/kits/hub-game/scripts/test-toast-no-row-dom.mjs +71 -0
  315. package/kits/hub-game/scripts/test-together.mjs +11 -0
  316. package/kits/hub-game/scripts/test-town-day.mjs +90 -0
  317. package/kits/hub-game/scripts/test-try-on.mjs +39 -0
  318. package/kits/hub-game/scripts/test-ui-dom-dom.mjs +49 -2
  319. package/kits/hub-game/scripts/test-ui-tree.mjs +28 -0
  320. package/kits/hub-game/scripts/test-vehicle-client.mjs +68 -1
  321. package/kits/hub-game/scripts/test-vis.mjs +145 -0
  322. package/kits/hub-game/scripts/test-wallet.mjs +650 -0
  323. package/kits/hub-game/scripts/test-weakest-tier.mjs +135 -1
  324. package/kits/hub-game/scripts/test-world-labels.mjs +340 -0
  325. package/kits/hub-game/scripts/test-writer-lease-server.mjs +234 -0
  326. package/kits/hub-game/scripts/test-writer-lease.mjs +281 -0
  327. package/kits/hub-game/scripts/writer-storage-fixture.mjs +37 -0
  328. package/kits/hub-game/tools/hubScene/export.mjs +6 -5
  329. package/kits/hub-game/tools/hubScene/hubdata.mjs +10 -0
  330. package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +36 -2
  331. package/kits/hub-game/tools/hubScene/validate-manifest.mjs +10 -2
  332. package/kits/multiplayer-3d/castle.json +5 -5
  333. package/kits/multiplayer-3d/code/client/resumeGate.js +49 -2
  334. package/kits/multiplayer-3d/code/server/ownership.js +25 -6
  335. package/kits/multiplayer-3d/code/server/world.js +19 -4
  336. package/kits/multiplayer-3d/code/systems/multiplayer.js +67 -11
  337. package/kits/multiplayer-3d/package-lock.json +1 -1
  338. package/kits/multiplayer-3d/package.json +2 -1
  339. package/kits/multiplayer-3d/scripts/test-ground-half.mjs +56 -0
  340. package/kits/multiplayer-3d/scripts/test-join-watchdog.mjs +54 -3
  341. package/kits/multiplayer-3d/scripts/test-owned-moves.mjs +190 -0
  342. package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +191 -5
  343. package/kits/multiplayer-3d/scripts/test-resync-reconnect.mjs +68 -0
  344. package/kits/physics-2d/castle.json +2 -2
  345. package/kits/physics-2d/engine/scene.js +10 -2
  346. package/kits/physics-3d/CLAUDE.md +14 -0
  347. package/kits/physics-3d/behaviors/Player.jsx +39 -3
  348. package/kits/physics-3d/castle.json +3 -3
  349. package/kits/physics-3d/docs/engine-model-cache.md +109 -0
  350. package/kits/physics-3d/docs/engine-player.md +76 -0
  351. package/kits/physics-3d/docs/engine-skip-work.md +16 -0
  352. package/kits/physics-3d/docs/pxmodel-format.md +5 -1
  353. package/kits/physics-3d/engine3d/gait.js +16 -8
  354. package/kits/physics-3d/engine3d/groundsize.js +23 -0
  355. package/kits/physics-3d/engine3d/kithooks.js +50 -0
  356. package/kits/physics-3d/engine3d/look.js +110 -17
  357. package/kits/physics-3d/engine3d/lookbake.js +19 -1
  358. package/kits/physics-3d/engine3d/materialpresets.js +3 -2
  359. package/kits/physics-3d/engine3d/modelcache.js +280 -0
  360. package/kits/physics-3d/engine3d/modelcachedigest.js +37 -0
  361. package/kits/physics-3d/engine3d/modelcachegate.js +69 -0
  362. package/kits/physics-3d/engine3d/modelrefs.js +13 -0
  363. package/kits/physics-3d/engine3d/optimize.js +20 -9
  364. package/kits/physics-3d/engine3d/playerRun.js +26 -1
  365. package/kits/physics-3d/engine3d/pxmodel.js +7 -3
  366. package/kits/physics-3d/engine3d/templatecache.js +722 -0
  367. package/kits/physics-3d/engine3d/world3d.js +211 -17
  368. package/kits/physics-3d/package-lock.json +1 -1
  369. package/kits/physics-3d/package.json +2 -1
  370. package/kits/physics-3d/play/behaviors/Player.js +43 -3
  371. package/kits/physics-3d/scripts/render.mjs +56 -8
  372. package/kits/physics-3d/scripts/template-cache-fixtures.mjs +37 -0
  373. package/kits/physics-3d/scripts/template-cache-v1-bytes.json +49 -0
  374. package/kits/physics-3d/scripts/test-gait.mjs +53 -9
  375. package/kits/physics-3d/scripts/test-ground-half.mjs +120 -0
  376. package/kits/physics-3d/scripts/test-model-cache.mjs +600 -0
  377. package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1 -0
  378. package/kits/physics-3d/scripts/test-sleeping-models.mjs +384 -0
  379. package/kits/physics-3d/scripts/test-template-cache-minified.mjs +106 -0
  380. package/kits/physics-3d/scripts/test-template-cache.mjs +519 -0
  381. package/kits/physics-3d/scripts/test-wall-slide.mjs +272 -0
  382. package/kits/physics-3d/systems/physics3d.js +51 -2
  383. package/kits/real-time/castle.json +2 -2
  384. package/kits/real-time/code/client/connection.js +3 -0
  385. package/package.json +2 -2
  386. package/vendor/three/examples/jsm/libs/fflate.module.js +2672 -0
@@ -0,0 +1,348 @@
1
+ // Seats, emotes and holds in a blocked pair (contract v1.183): the shared
2
+ // `hubSeated`, `hubEmotes` and `held` leave out every player a block hides
3
+ // from someone here, exactly as `hubAv` does, and each viewer is told alone
4
+ // (`hub-idle`) of those it may see -- itself included. A place with no blocks
5
+ // sends what it always did and never a `hub-idle` (code/server/idle.js,
6
+ // hub.js; code/client/state.js, hookLayer.js).
7
+ //
8
+ // The server is the kit's layer on a fake session, as test-try-on runs it;
9
+ // the client is the kit's real hook layer fed the messages that server wrote.
10
+ //
11
+ // `HUB_IDLE_BASELINE=<dir>` points at another copy of this kit (say
12
+ // `git archive <commit> kits/hub-game/code | tar -x -C <dir>` and the path to
13
+ // `kits/hub-game` in it): a story with no blocks is then run on that copy's
14
+ // server too and compared byte for byte. `npm run check` runs this without
15
+ // one; it needs nothing installed.
16
+
17
+ import assert from 'node:assert/strict';
18
+ import { register } from 'node:module';
19
+ import { pathToFileURL } from 'node:url';
20
+ import path from 'node:path';
21
+
22
+ const sceneStub = 'export const readScene = () => globalThis.__hubTestActors ?? [];';
23
+ const avatarsStub = 'export function dropMissing() {}';
24
+ register(
25
+ `data:text/javascript,${encodeURIComponent(`
26
+ import { readFile } from 'node:fs/promises';
27
+ import { fileURLToPath } from 'node:url';
28
+ const stubs = {
29
+ '@imports/castle.multiplayer-3d/code/server/sceneBodies.js': 'data:text/javascript,${encodeURIComponent(sceneStub)}',
30
+ '@imports/castle.multiplayer-3d/code/client/avatars.js': 'data:text/javascript,${encodeURIComponent(avatarsStub)}',
31
+ 'castle-web-sdk': ${JSON.stringify(new URL('./fixtures/sdk-stub.mjs', import.meta.url).href)},
32
+ };
33
+ export async function resolve(specifier, context, next) {
34
+ 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 };
35
+ 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 };
36
+ if (stubs[specifier]) {
37
+ return { url: stubs[specifier], shortCircuit: true };
38
+ }
39
+ return next(specifier, context);
40
+ }
41
+ export async function load(url, context, next) {
42
+ if (url.endsWith('/code/client/hookLayer.js')) {
43
+ const source = await readFile(fileURLToPath(url), 'utf8');
44
+ return { format: 'module', source: source.replaceAll('import.meta.glob(', '(() => ({}))('), shortCircuit: true };
45
+ }
46
+ return next(url, context);
47
+ }
48
+ `)}`,
49
+ );
50
+
51
+ async function kit(root) {
52
+ const at = (file) => pathToFileURL(path.join(root, file)).href;
53
+ return { layer: (await import(at('code/server/hub.js'))).layer };
54
+ }
55
+
56
+ const here = await kit(path.join(import.meta.dirname, '..'));
57
+ const baseline = process.env.HUB_IDLE_BASELINE ? await kit(path.resolve(process.env.HUB_IDLE_BASELINE)) : null;
58
+ const hookLayer = (await import('../code/client/hookLayer.js')).default;
59
+ const State = await import('../code/client/state.js');
60
+
61
+ const bench = { kind: 'box', width: 2.4, height: 0.5, depth: 0.6 };
62
+ globalThis.__hubTestActors = [
63
+ { id: 'spawn', components: { Player: {}, Transform: { x: 0, y: 1, z: 0 } } },
64
+ { id: 'bench-a', components: { Transform: { x: 1, y: 0.25, z: 0, rotationY: 90 }, Shape: bench, Solid: {}, HubSeat: { face: 180 } } },
65
+ { id: 'bench-b', components: { Transform: { x: -1, y: 0.25, z: 0 }, Shape: bench, Solid: {}, HubSeat: {} } },
66
+ ];
67
+ const castleJson = { server: { maxPlayers: 8 }, hub: { contract: 1, title: 'Park', idle: { emotes: true, seats: true } } };
68
+ const flush = () => new Promise((resolve) => setImmediate(resolve));
69
+ const ROSTER = ['p1', 'p2', 'p3'].map((playerId, i) => ({ playerId, userId: String(101 + i), username: playerId, isAnonymous: false }));
70
+ const p1p2 = (x, y) => [x, y].sort().join() === 'p1,p2';
71
+
72
+ function room(layer, { hides = null } = {}) {
73
+ const log = [];
74
+ const players = ROSTER.map((p) => ({ ...p }));
75
+ const platform = {
76
+ place: 'main',
77
+ title: 'Town',
78
+ result: null,
79
+ arrival: () => null,
80
+ reportResult: async () => ({ recorded: true }),
81
+ updatePad: async () => ({ status: 'gathering', members: [] }),
82
+ readResults: async (input) => ({ players: Object.fromEntries((input.userIds ?? []).map((id) => [id, { avatar: 1, recent: [], records: [] }])), boards: {} }),
83
+ };
84
+ if (hides) {
85
+ platform.hiddenPair = hides;
86
+ }
87
+ const session = {
88
+ sessionId: 's-1',
89
+ place: null,
90
+ players,
91
+ hub: platform,
92
+ send: (playerId, data) => log.push(['send', playerId, JSON.stringify(data)]),
93
+ broadcast: (data) => log.push(['broadcast', JSON.stringify(data)]),
94
+ };
95
+ let ctx = null;
96
+ const h = layer(castleJson, { ready: (hub) => (ctx = hub) }, {}, () => true);
97
+ h.sceneFor(session);
98
+ const world = { timeMs: 0, players: new Map(), bodies: new Map(), objects: new Map(), scenePath: 'scenes/main.scene' };
99
+ const body = () => ({ at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
100
+ h.ready(world);
101
+ return {
102
+ h,
103
+ log,
104
+ world,
105
+ hub: () => ctx,
106
+ join() {
107
+ const snapshot = h.join();
108
+ log.push(['join', JSON.stringify(snapshot)]);
109
+ return snapshot;
110
+ },
111
+ delta() {
112
+ const delta = h.delta();
113
+ log.push(['delta', JSON.stringify(delta)]);
114
+ return delta;
115
+ },
116
+ async tick(ms = 50) {
117
+ world.timeMs += ms;
118
+ h.place(world);
119
+ await flush();
120
+ world.timeMs += ms;
121
+ h.place(world);
122
+ h.step(world);
123
+ },
124
+ enter(playerId) {
125
+ world.players.set(playerId, body());
126
+ if (!players.some((p) => p.playerId === playerId)) {
127
+ players.push({ ...ROSTER.find((p) => p.playerId === playerId) });
128
+ }
129
+ this.hello(playerId);
130
+ },
131
+ hello(playerId, extra = {}) {
132
+ h.message(session, { playerId }, { k: 'hub-hello', avatar: 1, from: null, party: 1, ...extra });
133
+ },
134
+ say(playerId, data) {
135
+ h.message(session, { playerId }, data);
136
+ },
137
+ exit(playerId) {
138
+ world.players.delete(playerId);
139
+ const at = players.findIndex((p) => p.playerId === playerId);
140
+ if (at >= 0) {
141
+ players.splice(at, 1);
142
+ }
143
+ },
144
+ };
145
+ }
146
+
147
+ const idleAlone = (log) => log.filter((e) => e[0] === 'send' && JSON.parse(e[2]).k === 'hub-idle').map((e) => [e[1], JSON.parse(e[2])]);
148
+
149
+ // Everyone in; p1 emotes and sits (which holds them), p3 is held by the place.
150
+ async function story(layer, hides) {
151
+ const r = room(layer, { hides });
152
+ for (const id of ['p1', 'p2', 'p3']) {
153
+ r.enter(id);
154
+ }
155
+ await r.tick();
156
+ await r.tick(1000);
157
+ for (const p of r.world.players.values()) {
158
+ p.at = { x: 0, y: 1, z: 0 };
159
+ }
160
+ r.join();
161
+ r.delta();
162
+ r.say('p1', { k: 'hub-emote', id: 'wave' });
163
+ r.say('p1', { k: 'hub-sit', seat: 'bench-a' });
164
+ r.hub().hold('p3');
165
+ await r.tick();
166
+ r.join();
167
+ r.delta();
168
+ return r;
169
+ }
170
+
171
+ function client(viewer) {
172
+ State.clear();
173
+ const scene = { files: null };
174
+ return {
175
+ hub: State.hub,
176
+ feed(log) {
177
+ for (const entry of log) {
178
+ if (entry[0] === 'join' || entry[0] === 'delta') {
179
+ const msg = JSON.parse(entry[1]);
180
+ if (msg) {
181
+ hookLayer.state(scene, msg, null);
182
+ }
183
+ } else if (entry[0] === 'send' && entry[1] === viewer) {
184
+ hookLayer.message(scene, JSON.parse(entry[2]));
185
+ }
186
+ }
187
+ return { seated: { ...State.hub.seated }, emotes: Object.keys(State.hub.emotes).sort(), held: [...State.hub.held].sort() };
188
+ },
189
+ };
190
+ }
191
+
192
+ console.log = () => {};
193
+ const say = console.info;
194
+ let n = 0;
195
+ async function test(name, fn) {
196
+ try {
197
+ await fn();
198
+ } catch (err) {
199
+ console.error(`FAIL ${name}`);
200
+ throw err;
201
+ }
202
+ n += 1;
203
+ }
204
+
205
+ await test('no blocks: shared fields list everyone and no hub-idle is ever sent', async () => {
206
+ const r = await story(here.layer, null);
207
+ const snap = r.h.join();
208
+ assert.deepEqual(snap.hubSeated, { p1: 'bench-a' });
209
+ assert.deepEqual(Object.keys(snap.hubEmotes), ['p1']);
210
+ assert.deepEqual([...snap.held].sort(), ['p1', 'p3']);
211
+ assert.deepEqual(idleAlone(r.log), []);
212
+ // A rejoin in a place that never sent one sends none either.
213
+ r.hello('p3');
214
+ await r.tick();
215
+ r.exit('p3');
216
+ await r.tick();
217
+ r.enter('p3');
218
+ await r.tick();
219
+ assert.deepEqual(idleAlone(r.log), []);
220
+ assert.ok(!r.log.some((e) => e.join().includes('hub-idle')));
221
+ // Hosts that answer no pair are the same as no host answer at all.
222
+ const quiet = await story(here.layer, () => false);
223
+ assert.equal(JSON.stringify(quiet.log), JSON.stringify((await story(here.layer, null)).log));
224
+ });
225
+
226
+ if (baseline) {
227
+ await test('no blocks: every byte the baseline kit wrote', async () => {
228
+ for (const hides of [null, () => false]) {
229
+ const a = await story(baseline.layer, hides);
230
+ const b = await story(here.layer, hides);
231
+ assert.equal(JSON.stringify(b.log), JSON.stringify(a.log));
232
+ }
233
+ });
234
+ }
235
+
236
+ await test('a blocked pair leaves the shared fields; the third sees them alone, the other member never does', async () => {
237
+ const r = await story(here.layer, p1p2);
238
+ for (const [kind, json] of r.log) {
239
+ if (kind !== 'join' && kind !== 'delta') {continue;}
240
+ const msg = JSON.parse(json);
241
+ for (const field of ['hubSeated', 'hubEmotes']) {
242
+ assert.ok(!Object.hasOwn(msg?.[field] ?? {}, 'p1') && !Object.hasOwn(msg?.[field] ?? {}, 'p2'), `${kind} ${field}`);
243
+ }
244
+ assert.ok(!(msg?.held ?? []).includes('p1'), `${kind} held`);
245
+ }
246
+ const snap = r.h.join();
247
+ assert.deepEqual(snap.held, ['p3'], 'an unblocked player stays in the shared list');
248
+ const alone = idleAlone(r.log);
249
+ const last = (to) => alone.filter(([id]) => id === to).at(-1)?.[1];
250
+ assert.deepEqual(last('p3').hubSeated, { p1: 'bench-a' });
251
+ assert.deepEqual(Object.keys(last('p3').hubEmotes), ['p1']);
252
+ assert.deepEqual(last('p3').held, ['p1']);
253
+ // A player sees itself.
254
+ assert.deepEqual(last('p1').hubSeated, { p1: 'bench-a' });
255
+ assert.deepEqual(last('p1').held, ['p1']);
256
+ // The other member of the pair hears nothing of p1, ever.
257
+ for (const [to, msg] of alone) {
258
+ if (to === 'p2') {
259
+ assert.deepEqual(msg, { k: 'hub-idle', hubSeated: {}, hubEmotes: {}, held: [] });
260
+ }
261
+ }
262
+ assert.equal(last('p2'), undefined, 'nothing to tell p2, so nothing sent');
263
+ // The same, unchanged, is not sent again.
264
+ const before = alone.length;
265
+ await r.tick();
266
+ assert.equal(idleAlone(r.log).length, before);
267
+ // Client merge: p3 sees p1 and p3; p2 sees only p3; p1 sees itself and p3.
268
+ assert.deepEqual(client('p3').feed(r.log), { seated: { p1: 'bench-a' }, emotes: ['p1'], held: ['p1', 'p3'] });
269
+ assert.deepEqual(client('p2').feed(r.log), { seated: {}, emotes: [], held: ['p3'] });
270
+ assert.deepEqual(client('p1').feed(r.log), { seated: { p1: 'bench-a' }, emotes: ['p1'], held: ['p1', 'p3'] });
271
+ // Standing up clears it in the next whole message.
272
+ r.log.length = 0;
273
+ r.say('p1', { k: 'hub-stand' });
274
+ await r.tick();
275
+ assert.deepEqual(idleAlone(r.log).find(([to]) => to === 'p3')?.[1].hubSeated, {});
276
+ });
277
+
278
+ await test('a fresh join resends hub-idle; an avatar change does not', async () => {
279
+ const r = await story(here.layer, p1p2);
280
+ r.log.length = 0;
281
+ r.hello('p3', { again: true });
282
+ await r.tick();
283
+ assert.deepEqual(idleAlone(r.log), []);
284
+ r.hello('p3', { resume: true });
285
+ await r.tick();
286
+ const resent = idleAlone(r.log);
287
+ assert.equal(resent.length, 1);
288
+ assert.equal(resent[0][0], 'p3');
289
+ assert.deepEqual(resent[0][1].hubSeated, { p1: 'bench-a' });
290
+ // p2 joins afresh too: it is sent its (empty) view whole, to clear what it held.
291
+ r.log.length = 0;
292
+ r.hello('p2');
293
+ await r.tick();
294
+ assert.deepEqual(idleAlone(r.log), [['p2', { k: 'hub-idle', hubSeated: {}, hubEmotes: {}, held: [] }]]);
295
+ });
296
+
297
+ await test('the block lifting puts the pair back in the shared fields and clears hub-idle', async () => {
298
+ let blocked = true;
299
+ const r = await story(here.layer, (x, y) => blocked && p1p2(x, y));
300
+ const from = r.log.length;
301
+ blocked = false;
302
+ await r.tick();
303
+ r.delta();
304
+ const after = r.log.slice(from);
305
+ const delta = JSON.parse(after.find((e) => e[0] === 'delta')[1]);
306
+ assert.deepEqual(delta.hubSeated, { p1: 'bench-a' });
307
+ assert.deepEqual([...delta.held].sort(), ['p1', 'p3']);
308
+ for (const [, msg] of idleAlone(after)) {
309
+ assert.deepEqual(msg, { k: 'hub-idle', hubSeated: {}, hubEmotes: {}, held: [] });
310
+ }
311
+ assert.deepEqual(idleAlone(after).map(([to]) => to).sort(), ['p1', 'p3']);
312
+ assert.deepEqual(client('p3').feed(r.log), { seated: { p1: 'bench-a' }, emotes: ['p1'], held: ['p1', 'p3'] });
313
+ assert.deepEqual(client('p2').feed(r.log), { seated: { p1: 'bench-a' }, emotes: ['p1'], held: ['p1', 'p3'] });
314
+ });
315
+
316
+ await test('leaving forgets what a player was sent alone', async () => {
317
+ const r = await story(here.layer, p1p2);
318
+ assert.ok(r.log.some((e) => e[0] === 'send' && e[1] === 'p3' && e[2].includes('hub-idle')));
319
+ r.exit('p3');
320
+ await r.tick();
321
+ await r.tick();
322
+ r.log.length = 0;
323
+ r.enter('p3');
324
+ await r.tick();
325
+ await r.tick(1000);
326
+ assert.equal(idleAlone(r.log).filter(([to]) => to === 'p3').length, 1, 'told once again as a newcomer');
327
+ });
328
+
329
+ await test('client: the private block is whole each time and a clear empties it', () => {
330
+ const page = client('p3');
331
+ const scene = { files: null };
332
+ hookLayer.state(scene, { hubPlace: { id: 'main' }, hubSeated: { p3: 'bench-b' }, hubEmotes: { p3: { id: 'wave', at: 0, until: 9e9 } }, held: ['p3'] }, null);
333
+ hookLayer.message(scene, { k: 'hub-idle', hubSeated: { p1: 'bench-a' }, hubEmotes: { p1: { id: 'cheer', at: 0, until: 9e9 } }, held: ['p1'] });
334
+ assert.deepEqual(page.hub.seated, { p3: 'bench-b', p1: 'bench-a' });
335
+ assert.deepEqual(Object.keys(page.hub.emotes).sort(), ['p1', 'p3']);
336
+ assert.deepEqual([...page.hub.held].sort(), ['p1', 'p3']);
337
+ // A shared delta keeps the private part laid over it.
338
+ hookLayer.state(scene, { hubSeated: {} }, null);
339
+ assert.deepEqual(page.hub.seated, { p1: 'bench-a' });
340
+ hookLayer.message(scene, { k: 'hub-idle', hubSeated: {}, hubEmotes: {}, held: [] });
341
+ assert.deepEqual(page.hub.seated, {});
342
+ assert.deepEqual([...page.hub.held], ['p3']);
343
+ hookLayer.message(scene, { k: 'hub-idle', hubSeated: { p1: 'bench-a' }, held: ['p1'] });
344
+ State.clear();
345
+ assert.deepEqual([page.hub.seated, page.hub.seatedMe, page.hub.emotesMe, page.hub.heldMe.size, page.hub.held.size], [{}, {}, {}, 0, 0]);
346
+ });
347
+
348
+ say(`test-hub-idle: ${n} passed`);
@@ -35,6 +35,7 @@ register(
35
35
  const { layer } = await import('../code/server/hub.js');
36
36
  const hook = (await import('../code/client/hookLayer.js')).default;
37
37
  const State = await import('../code/client/state.js');
38
+ const { catchingDim, catchingLine } = await import('../code/client/catchingUp.js');
38
39
 
39
40
  globalThis.__hubTestActors = [
40
41
  { id: 'spawn', components: { Player: {}, Transform: { x: 0, y: 1, z: 0 } } },
@@ -76,6 +77,26 @@ test('friends wanted is latched privately by the client and cleared on a session
76
77
  assert.equal(State.hub.friendsWanted, false);
77
78
  });
78
79
 
80
+ test('v1.204: hub-progress keeps its first start until it ends, and a session switch clears it', () => {
81
+ State.clear();
82
+ assert.equal(State.hub.catching, null);
83
+ hook.message({ files: {} }, { k: 'hub-progress', catching: true });
84
+ const since = State.hub.catching;
85
+ assert.equal(typeof since, 'number');
86
+ hook.message({ files: {} }, { k: 'hub-progress', catching: true });
87
+ assert.equal(State.hub.catching, since, 'a resent start keeps the first');
88
+ hook.message({ files: {} }, { k: 'hub-progress', catching: false });
89
+ assert.equal(State.hub.catching, null);
90
+ hook.message({ files: {} }, { k: 'hub-progress', catching: true });
91
+ State.clear();
92
+ assert.equal(State.hub.catching, null);
93
+ assert.equal(catchingDim(null, 1e9), false);
94
+ assert.equal(catchingDim(0, 249), false);
95
+ assert.equal(catchingDim(0, 250), true);
96
+ assert.equal(catchingLine(0, 29_999), 'Catching up, try again in a moment');
97
+ assert.equal(catchingLine(0, 30_000), 'Still catching up, re-enter the town if this lasts');
98
+ });
99
+
79
100
  test('a place that never calls leaving has no traffic or snapshot field, even for later joins', () => {
80
101
  const r = boot();
81
102
  const before = r.server.join();
@@ -1168,6 +1168,53 @@ await test('a mark that arrives while a fire is pending keeps that player from g
1168
1168
  assert.deepEqual(goes, ['p2']);
1169
1169
  });
1170
1170
 
1171
+ await test('a fire answered after a player reconnected goes to the new connection, never the dropped one', async () => {
1172
+ const p = platformHub();
1173
+ let answer = null;
1174
+ p.hub.updatePad = (input) => {
1175
+ p.calls.push(['pad', input]);
1176
+ return input.fire ? new Promise((resolve) => { answer = () => resolve({ status: 'fired', members: [...input.memberUserIds] }); }) : Promise.resolve({ status: 'gathering', members: [] });
1177
+ };
1178
+ const s = session({ hub: p.hub });
1179
+ const { ctx } = boot(s);
1180
+ const hub = ctx();
1181
+ hub.pad('race', ['p1', 'p2']);
1182
+ assert.ok(hub.go('race', ['p1', 'p2']));
1183
+ // p1 drops and comes back as a new connection of the same account; p2 drops for good.
1184
+ s.session.players = [{ playerId: 'p1b', userId: '101', username: 'ada', isAnonymous: false }, PLAYERS[2]];
1185
+ answer();
1186
+ await flush();
1187
+ const goes = s.sent.filter(([, d]) => d.k === 'hub-go').map(([id]) => id);
1188
+ assert.deepEqual(goes, ['p1b']);
1189
+ assert.ok(!s.sent.some(([id]) => id === 'p1' || id === 'p2'), 'nothing is sent to a dropped connection');
1190
+ });
1191
+
1192
+ await test('a go while the fire is still out sends no second fire', async () => {
1193
+ const p = platformHub();
1194
+ let answer = null;
1195
+ p.hub.updatePad = (input) => {
1196
+ p.calls.push(['pad', input]);
1197
+ return input.fire ? new Promise((resolve) => { answer = () => resolve({ status: 'fired', members: [...input.memberUserIds] }); }) : Promise.resolve({ status: 'gathering', members: [] });
1198
+ };
1199
+ const s = session({ hub: p.hub });
1200
+ const { ctx } = boot(s);
1201
+ const hub = ctx();
1202
+ hub.pad('race', ['p1']);
1203
+ const first = hub.go('race', ['p1']);
1204
+ assert.ok(first);
1205
+ assert.equal(hub.go('race', ['p1']), first, 'the same pad for players it already names');
1206
+ assert.equal(hub.go('race', ['p1', 'p2']), null, 'a player the pending fire does not name is not sent');
1207
+ assert.equal(p.calls.filter((c) => c[0] === 'pad' && c[1].fire).length, 1);
1208
+ answer();
1209
+ await flush();
1210
+ assert.deepEqual(s.sent.filter(([, d]) => d.k === 'hub-go').map(([id]) => id), ['p1']);
1211
+ // Once it settles, the one left out goes through a new pad.
1212
+ assert.ok(hub.go('race', ['p2']));
1213
+ answer();
1214
+ await flush();
1215
+ assert.deepEqual(s.sent.filter(([, d]) => d.k === 'hub-go').map(([id]) => id), ['p1', 'p2']);
1216
+ });
1217
+
1171
1218
  await test('players whose app has door trips gather and go exactly as before', async () => {
1172
1219
  const p = platformHub();
1173
1220
  const s = session({ hub: p.hub });
@@ -1611,6 +1658,32 @@ await test('private goal coordinates stay out of shared snapshots and blocked re
1611
1658
  assert.ok(!JSON.stringify(h.join()).includes('81.25'), 'unscoped sign ignores coordinates');
1612
1659
  });
1613
1660
 
1661
+ await test('v1.201 self-anchored goals reach only their recipients, with a bounded rise', async () => {
1662
+ const s = session({ hub: platformHub().hub });
1663
+ const { h, world, ctx } = boot(s);
1664
+ assert.equal(ctx().goalSelf, true);
1665
+ for (const { playerId } of PLAYERS) hello(h, s, playerId);
1666
+ h.place(world); await flush(); h.place(world);
1667
+ const last = (id) => s.sent.filter(([to, data]) => to === id && data.k === 'hub-labels').at(-1)?.[1].labels ?? {};
1668
+ ctx().label('race-door', 'You', { style: 'goal', to: ['p1'], distance: false, at: 'self', rise: 0.4 });
1669
+ h.step(world);
1670
+ assert.deepEqual(last('p1')['race-door'], { text: 'You', style: 'goal', distance: false, at: 'self', rise: 0.4 });
1671
+ assert.ok(!last('p2')['race-door'], 'another player is never sent it');
1672
+ ctx().label('race-door', 'You', { style: 'goal', to: ['p1'], at: 'self', rise: 12 });
1673
+ h.step(world);
1674
+ assert.equal(last('p1')['race-door'].rise, 4);
1675
+ for (const rise of [-1, NaN, '1', 0]) {
1676
+ ctx().label('race-door', 'You', { style: 'goal', to: ['p1'], at: 'self', rise });
1677
+ h.step(world);
1678
+ assert.deepEqual(last('p1')['race-door'], { text: 'You', style: 'goal', at: 'self' }, `rise ${String(rise)} dropped`);
1679
+ }
1680
+ ctx().label('race-door', 'You', { style: 'goal', at: 'self', rise: 1 });
1681
+ assert.ok(!JSON.stringify(h.join()).includes('"self"'), 'a shared sign ignores self');
1682
+ ctx().label('race-door', 'You', { style: 'tag', to: ['p1'], at: 'self', rise: 1 });
1683
+ h.step(world);
1684
+ assert.deepEqual(last('p1')['race-door'], { text: 'You', style: 'tag' }, 'a private tag ignores self');
1685
+ });
1686
+
1614
1687
 
1615
1688
 
1616
1689
 
@@ -1678,6 +1751,52 @@ await test('a stored resume pose is not restored for an arrival ghost placed thr
1678
1751
  assert.ok(Math.hypot(at('p2').x - cold.at.x, at('p2').z - cold.at.z) < 0.01, `rejoin without a door keeps its stored pose ${JSON.stringify(at('p2'))}`);
1679
1752
  });
1680
1753
 
1754
+ // Pad safety: a restored pose keeps 2.5 m from every pad's edge
1755
+ // (code/server/hub.js COLD_POSE_PAD_CLEAR_M). p1 left the Town standing on
1756
+ // the race pad (radius 2.3 at 5,9); p2 left `p2z` along the pad's axis.
1757
+ async function coldPoseNearPad(p2z) {
1758
+ const { store } = await import('../code/server/resumePose.js');
1759
+ const { poseStorage } = await import('./pose-storage-fixture.mjs');
1760
+ const pad = { id: 'race-pad', components: { HubPad: { door: 'race', radius: 2.3 }, Transform: { x: 5, y: 0, z: 9 } } };
1761
+ globalThis.__hubTestActors.push(pad);
1762
+ try {
1763
+ const p = platformHub({});
1764
+ p.hub.arrival = () => null;
1765
+ const s = session({ hub: p.hub });
1766
+ s.session.storage = { deck: poseStorage() };
1767
+ const poses = { 101: { at: { x: 5.5, y: 1, z: 8.5 }, facing: 0.5 }, 102: { at: { x: 5, y: 1, z: p2z }, facing: 0.5 } };
1768
+ for (const [userId, pose] of Object.entries(poses)) {
1769
+ const earlier = store(s.session, 'main');
1770
+ await earlier.take(userId);
1771
+ await earlier.end(userId, pose);
1772
+ }
1773
+ const json = { ...castleJson, hub: { ...castleJson.hub, resumePose: true } };
1774
+ const { h, world, arrived } = boot(s, {}, json);
1775
+ hello(h, s, 'p1');
1776
+ hello(h, s, 'p2');
1777
+ for (let i = 0; i < 10 && arrived.length < 2; i++) {
1778
+ await flush();
1779
+ h.place(world);
1780
+ }
1781
+ assert.equal(arrived.length, 2);
1782
+ const at = (id) => world.players.get(id).at;
1783
+ assert.ok(Math.hypot(at('p1').x - 5, at('p1').z - 9) > 2.3, `not back on the pad ${JSON.stringify(at('p1'))}`);
1784
+ return Math.hypot(at('p2').x - 5, at('p2').z - p2z);
1785
+ } finally {
1786
+ globalThis.__hubTestActors.splice(globalThis.__hubTestActors.indexOf(pad), 1);
1787
+ }
1788
+ }
1789
+
1790
+ await test('a stored resume pose on a door pad is not restored onto it; one 2.7 m off its edge is', async () => {
1791
+ const moved = await coldPoseNearPad(14);
1792
+ assert.ok(moved < 0.01, `a pose 2.7 m off the pad edge is kept (moved ${moved})`);
1793
+ });
1794
+
1795
+ await test('a stored resume pose 2.0 m from a door pad edge is not restored', async () => {
1796
+ const moved = await coldPoseNearPad(13.3);
1797
+ assert.ok(moved > 0.01, `a pose inside the 2.5 m clearance is dropped (moved ${moved})`);
1798
+ });
1799
+
1681
1800
  console.log(`hub ops: ${n} tests passed`);
1682
1801
 
1683
1802
  // Opt-in exists after actual layer construction, before authored hooks run.