castle-web-cli 0.4.238 → 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 (404) 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 +218 -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 +22 -3
  16. package/dist/init.js +24 -2
  17. package/dist/multiplayerDoc.d.ts +1 -1
  18. package/dist/multiplayerDoc.js +9 -0
  19. package/dist/platformDoc.js +4 -2
  20. package/dist/playPagePolicy.d.ts +1 -0
  21. package/dist/playPagePolicy.js +12 -3
  22. package/dist/resetLeaderboards.d.ts +8 -1
  23. package/dist/resetLeaderboards.js +43 -8
  24. package/dist/roomLogs.d.ts +39 -0
  25. package/dist/roomLogs.js +166 -0
  26. package/dist/save-deck.d.ts +32 -2
  27. package/dist/save-deck.js +240 -39
  28. package/kits/base/CLAUDE.md +2 -1
  29. package/kits/base/castle.json +1 -1
  30. package/kits/base/sdk/README.md +240 -8
  31. package/kits/base/sdk/analytics.d.ts +8 -0
  32. package/kits/base/sdk/analytics.js +92 -0
  33. package/kits/base/sdk/castle.d.ts +8 -2
  34. package/kits/base/sdk/castle.js +3 -0
  35. package/kits/base/sdk/commands.d.ts +79 -0
  36. package/kits/base/sdk/commands.js +1 -0
  37. package/kits/base/sdk/debugConsole.d.ts +17 -0
  38. package/kits/base/sdk/debugConsole.js +154 -0
  39. package/kits/base/sdk/experiments.js +24 -1
  40. package/kits/base/sdk/hostRetry.d.ts +7 -0
  41. package/kits/base/sdk/hostRetry.js +57 -0
  42. package/kits/base/sdk/hub.d.ts +20 -2
  43. package/kits/base/sdk/hub.js +99 -13
  44. package/kits/base/sdk/multiplayer.d.ts +2 -0
  45. package/kits/base/sdk/multiplayer.js +198 -26
  46. package/kits/base/sdk/reconnectBudget.d.ts +6 -0
  47. package/kits/base/sdk/reconnectBudget.js +41 -1
  48. package/kits/base/sdk/rooms.d.ts +11 -0
  49. package/kits/base/sdk/rooms.js +22 -0
  50. package/kits/base/sdk/runtime.js +36 -19
  51. package/kits/base/sdk/server/hub.d.ts +19 -0
  52. package/kits/base/sdk/server/hub.js +12 -0
  53. package/kits/base/sdk/server/platformHandle.d.ts +1 -0
  54. package/kits/base/sdk/server/wrapper.d.ts +1 -1
  55. package/kits/base/sdk/server/wrapper.js +26 -1
  56. package/kits/base/sdk/store.d.ts +8 -2
  57. package/kits/base/sdk/store.js +5 -1
  58. package/kits/base/sdk/transport.d.ts +2 -1
  59. package/kits/base/sdk/transport.js +35 -0
  60. package/kits/hub-game/CLAUDE.md +66 -19
  61. package/kits/hub-game/castle.json +4 -4
  62. package/kits/hub-game/code/client/act.js +9 -6
  63. package/kits/hub-game/code/client/actCore.js +26 -6
  64. package/kits/hub-game/code/client/actGateLog.js +36 -0
  65. package/kits/hub-game/code/client/actionOverflow.js +29 -8
  66. package/kits/hub-game/code/client/actionRailSurface.js +186 -0
  67. package/kits/hub-game/code/client/actionRailTree.js +173 -0
  68. package/kits/hub-game/code/client/askSurface.js +85 -0
  69. package/kits/hub-game/code/client/askTree.js +51 -0
  70. package/kits/hub-game/code/client/attention.js +31 -6
  71. package/kits/hub-game/code/client/ballot.js +42 -5
  72. package/kits/hub-game/code/client/ballotSurface.js +115 -0
  73. package/kits/hub-game/code/client/ballotTree.js +180 -0
  74. package/kits/hub-game/code/client/catchingUp.js +19 -0
  75. package/kits/hub-game/code/client/celebrate.js +66 -0
  76. package/kits/hub-game/code/client/chrome.js +474 -53
  77. package/kits/hub-game/code/client/companion.js +93 -23
  78. package/kits/hub-game/code/client/companionDress.js +1 -1
  79. package/kits/hub-game/code/client/cornerSurface.js +106 -0
  80. package/kits/hub-game/code/client/cornerTree.js +83 -0
  81. package/kits/hub-game/code/client/decor.js +20 -11
  82. package/kits/hub-game/code/client/deviceStorage.js +121 -0
  83. package/kits/hub-game/code/client/disguise.js +23 -0
  84. package/kits/hub-game/code/client/disguiseDraw.js +87 -0
  85. package/kits/hub-game/code/client/dockSurface.js +206 -0
  86. package/kits/hub-game/code/client/dockTree.js +232 -0
  87. package/kits/hub-game/code/client/earned.js +29 -0
  88. package/kits/hub-game/code/client/emoteSurface.js +188 -0
  89. package/kits/hub-game/code/client/emoteTree.js +264 -0
  90. package/kits/hub-game/code/client/farAvatars.js +4 -3
  91. package/kits/hub-game/code/client/fpsTelemetry.js +3 -1
  92. package/kits/hub-game/code/client/grab.js +121 -50
  93. package/kits/hub-game/code/client/holdShow.js +19 -0
  94. package/kits/hub-game/code/client/hookLayer.js +96 -12
  95. package/kits/hub-game/code/client/hubControls.js +7 -1
  96. package/kits/hub-game/code/client/hudSurface.js +11 -3
  97. package/kits/hub-game/code/client/hudTree.js +7 -4
  98. package/kits/hub-game/code/client/idle.js +21 -3
  99. package/kits/hub-game/code/client/invites.js +24 -3
  100. package/kits/hub-game/code/client/keys.js +15 -0
  101. package/kits/hub-game/code/client/labelsNear.js +8 -1
  102. package/kits/hub-game/code/client/layoutCache.js +57 -8
  103. package/kits/hub-game/code/client/loadingCover.js +53 -4
  104. package/kits/hub-game/code/client/menuIcons.js +15 -0
  105. package/kits/hub-game/code/client/menuRows.js +8 -2
  106. package/kits/hub-game/code/client/menuSurface.js +102 -0
  107. package/kits/hub-game/code/client/menuTree.js +135 -0
  108. package/kits/hub-game/code/client/modelLook.js +41 -0
  109. package/kits/hub-game/code/client/pickerSurface.js +152 -0
  110. package/kits/hub-game/code/client/pickerTree.js +163 -0
  111. package/kits/hub-game/code/client/pushVisit.js +4 -2
  112. package/kits/hub-game/code/client/quality.js +188 -29
  113. package/kits/hub-game/code/client/qualityEntry.js +10 -1
  114. package/kits/hub-game/code/client/quickChatSurface.js +222 -0
  115. package/kits/hub-game/code/client/quickChatTree.js +201 -0
  116. package/kits/hub-game/code/client/rehello.js +75 -0
  117. package/kits/hub-game/code/client/renderVisibility.js +17 -0
  118. package/kits/hub-game/code/client/replay.js +118 -0
  119. package/kits/hub-game/code/client/role.js +3 -0
  120. package/kits/hub-game/code/client/safeLayout.js +441 -56
  121. package/kits/hub-game/code/client/safeStyle.js +13 -10
  122. package/kits/hub-game/code/client/say.js +2 -0
  123. package/kits/hub-game/code/client/soundSurface.js +77 -0
  124. package/kits/hub-game/code/client/soundTree.js +74 -0
  125. package/kits/hub-game/code/client/soundscape.js +12 -9
  126. package/kits/hub-game/code/client/soundscapeCues.js +1 -1
  127. package/kits/hub-game/code/client/state.js +67 -1
  128. package/kits/hub-game/code/client/stuckSurface.js +76 -0
  129. package/kits/hub-game/code/client/stuckTree.js +67 -0
  130. package/kits/hub-game/code/client/talk.js +42 -12
  131. package/kits/hub-game/code/client/talkTree.js +4 -2
  132. package/kits/hub-game/code/client/textAskSurface.js +147 -0
  133. package/kits/hub-game/code/client/textAskTree.js +67 -0
  134. package/kits/hub-game/code/client/tiers.js +252 -27
  135. package/kits/hub-game/code/client/together.js +4 -1
  136. package/kits/hub-game/code/client/uiDom.js +86 -8
  137. package/kits/hub-game/code/client/uiTree.js +33 -4
  138. package/kits/hub-game/code/client/vehicle.js +75 -52
  139. package/kits/hub-game/code/client/weakestTier.js +75 -31
  140. package/kits/hub-game/code/client/wear.js +159 -5
  141. package/kits/hub-game/code/client/worldLabels.js +215 -26
  142. package/kits/hub-game/code/companionSpec.js +4 -2
  143. package/kits/hub-game/code/server/act.js +3 -0
  144. package/kits/hub-game/code/server/actGate.js +83 -0
  145. package/kits/hub-game/code/server/actions.js +71 -15
  146. package/kits/hub-game/code/server/actors.js +20 -5
  147. package/kits/hub-game/code/server/analytics.js +40 -15
  148. package/kits/hub-game/code/server/ask.js +39 -3
  149. package/kits/hub-game/code/server/ballot.js +167 -4
  150. package/kits/hub-game/code/server/celebrate.js +64 -0
  151. package/kits/hub-game/code/server/companion.js +17 -2
  152. package/kits/hub-game/code/server/decor.js +11 -2
  153. package/kits/hub-game/code/server/disguise.js +63 -0
  154. package/kits/hub-game/code/server/doorAnalytics.js +2 -5
  155. package/kits/hub-game/code/server/earned.js +6 -2
  156. package/kits/hub-game/code/server/friendBests.js +13 -4
  157. package/kits/hub-game/code/server/friendsAmong.js +67 -8
  158. package/kits/hub-game/code/server/grab.js +12 -2
  159. package/kits/hub-game/code/server/heldOffers.js +142 -0
  160. package/kits/hub-game/code/server/holdShow.js +98 -0
  161. package/kits/hub-game/code/server/hub.js +854 -45
  162. package/kits/hub-game/code/server/idle.js +110 -9
  163. package/kits/hub-game/code/server/index.js +9 -0
  164. package/kits/hub-game/code/server/labels.js +13 -3
  165. package/kits/hub-game/code/server/loadAbandon.js +2 -5
  166. package/kits/hub-game/code/server/manifest.js +94 -6
  167. package/kits/hub-game/code/server/menu.js +26 -3
  168. package/kits/hub-game/code/server/npcs.js +55 -9
  169. package/kits/hub-game/code/server/observe.js +67 -6
  170. package/kits/hub-game/code/server/players.js +8 -1
  171. package/kits/hub-game/code/server/replay.js +135 -0
  172. package/kits/hub-game/code/server/storageLimit.js +4 -1
  173. package/kits/hub-game/code/server/townDay.js +74 -0
  174. package/kits/hub-game/code/server/trackQueue.js +29 -0
  175. package/kits/hub-game/code/server/vehicle.js +3 -0
  176. package/kits/hub-game/code/server/vis.js +26 -4
  177. package/kits/hub-game/code/server/wallet.js +677 -0
  178. package/kits/hub-game/code/server/wear.js +13 -3
  179. package/kits/hub-game/code/server/writerLease.js +191 -0
  180. package/kits/hub-game/code/shared/act.js +1 -1
  181. package/kits/hub-game/code/shared/expression.js +6 -0
  182. package/kits/hub-game/code/shared/replay.js +37 -0
  183. package/kits/hub-game/code/systems/hub.js +437 -57
  184. package/kits/hub-game/docs/analytics.md +20 -3
  185. package/kits/hub-game/docs/contract.md +942 -99
  186. package/kits/hub-game/docs/home-pieces.md +5 -6
  187. package/kits/hub-game/docs/observed-progress.md +49 -1
  188. package/kits/hub-game/docs/vehicle-preset.md +23 -0
  189. package/kits/hub-game/index.html +1 -0
  190. package/kits/hub-game/models/hats/baker-cap.pxmodel +3 -3
  191. package/kits/hub-game/models/hats/bat-clip.pxmodel +3 -3
  192. package/kits/hub-game/models/hats/beekeeper.pxmodel +3 -3
  193. package/kits/hub-game/models/hats/cap.pxmodel +3 -3
  194. package/kits/hub-game/models/hats/captain.pxmodel +3 -3
  195. package/kits/hub-game/models/hats/chef-toque.pxmodel +3 -3
  196. package/kits/hub-game/models/hats/crooked-top.pxmodel +3 -3
  197. package/kits/hub-game/models/hats/delivery-cap.pxmodel +3 -3
  198. package/kits/hub-game/models/hats/fire-helmet.pxmodel +3 -3
  199. package/kits/hub-game/models/hats/flower-crown.pxmodel +3 -3
  200. package/kits/hub-game/models/hats/foam-crown.pxmodel +3 -3
  201. package/kits/hub-game/models/hats/hard-hat.pxmodel +3 -3
  202. package/kits/hub-game/models/hats/lantern.pxmodel +3 -3
  203. package/kits/hub-game/models/hats/laurel.pxmodel +3 -3
  204. package/kits/hub-game/models/hats/lighthouse.pxmodel +3 -3
  205. package/kits/hub-game/models/hats/nurse-cap.pxmodel +3 -3
  206. package/kits/hub-game/models/hats/police-cap.pxmodel +3 -3
  207. package/kits/hub-game/models/hats/sailor.pxmodel +3 -3
  208. package/kits/hub-game/models/hats/souwester.pxmodel +3 -3
  209. package/kits/hub-game/models/hats/straw.pxmodel +3 -3
  210. package/kits/hub-game/models/hats/sunflower.pxmodel +3 -3
  211. package/kits/hub-game/models/hats/sweatband.pxmodel +3 -3
  212. package/kits/hub-game/models/hats/teacher-beret.pxmodel +3 -3
  213. package/kits/hub-game/models/hats/witch.pxmodel +3 -3
  214. package/kits/hub-game/models/hold-show/daisy.pxmodel +231 -0
  215. package/kits/hub-game/models/hold-show/moonflower.pxmodel +171 -0
  216. package/kits/hub-game/models/hold-show/rose.pxmodel +191 -0
  217. package/kits/hub-game/models/hold-show/square/daisy.pxmodel +233 -0
  218. package/kits/hub-game/models/hold-show/square/moonflower.pxmodel +173 -0
  219. package/kits/hub-game/models/hold-show/square/rose.pxmodel +193 -0
  220. package/kits/hub-game/models/hold-show/square/sunflower.pxmodel +313 -0
  221. package/kits/hub-game/models/hold-show/square/tulip.pxmodel +133 -0
  222. package/kits/hub-game/models/hold-show/sunflower.pxmodel +311 -0
  223. package/kits/hub-game/models/hold-show/tulip.pxmodel +131 -0
  224. package/kits/hub-game/package-lock.json +3 -3
  225. package/kits/hub-game/package.json +4 -3
  226. package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +1 -0
  227. package/kits/hub-game/scripts/fixtures/hud-surface.json +12 -12
  228. package/kits/hub-game/scripts/fixtures/talk-surface.json +8 -8
  229. package/kits/hub-game/scripts/gen-hats.mjs +1 -1
  230. package/kits/hub-game/scripts/gen-hold-show.mjs +27 -0
  231. package/kits/hub-game/scripts/pack.mjs +89 -23
  232. package/kits/hub-game/scripts/test-act-client.mjs +5 -0
  233. package/kits/hub-game/scripts/test-act-core.mjs +32 -0
  234. package/kits/hub-game/scripts/test-act-gate.mjs +186 -0
  235. package/kits/hub-game/scripts/test-action-rail-crowded-dom.mjs +7 -1
  236. package/kits/hub-game/scripts/test-action-rail-default-dom.mjs +102 -0
  237. package/kits/hub-game/scripts/test-action-rail-never-silent-dom.mjs +50 -0
  238. package/kits/hub-game/scripts/test-action-rail-surface.mjs +368 -0
  239. package/kits/hub-game/scripts/test-action-rail-town-jobs-dom.mjs +118 -0
  240. package/kits/hub-game/scripts/test-actions-client.mjs +5 -3
  241. package/kits/hub-game/scripts/test-actions.mjs +24 -0
  242. package/kits/hub-game/scripts/test-actors.mjs +19 -0
  243. package/kits/hub-game/scripts/test-again-corner-dom.mjs +59 -0
  244. package/kits/hub-game/scripts/test-analytics.mjs +80 -1
  245. package/kits/hub-game/scripts/test-arrival-pose-server.mjs +25 -8
  246. package/kits/hub-game/scripts/test-ask-client.mjs +9 -0
  247. package/kits/hub-game/scripts/test-ask-surface.mjs +188 -0
  248. package/kits/hub-game/scripts/test-attention.mjs +43 -1
  249. package/kits/hub-game/scripts/test-ballot-sheet-dom.mjs +71 -0
  250. package/kits/hub-game/scripts/test-ballot-surface.mjs +276 -0
  251. package/kits/hub-game/scripts/test-ballot.mjs +420 -3
  252. package/kits/hub-game/scripts/test-ban-join.mjs +1 -1
  253. package/kits/hub-game/scripts/test-celebrate-client.mjs +62 -0
  254. package/kits/hub-game/scripts/test-celebrate.mjs +116 -0
  255. package/kits/hub-game/scripts/test-chat.mjs +73 -0
  256. package/kits/hub-game/scripts/test-companion-client.mjs +203 -21
  257. package/kits/hub-game/scripts/test-companion.mjs +110 -3
  258. package/kits/hub-game/scripts/test-control-layout-dom.mjs +57 -10
  259. package/kits/hub-game/scripts/test-corner-surface.mjs +268 -0
  260. package/kits/hub-game/scripts/test-decor-client.mjs +59 -3
  261. package/kits/hub-game/scripts/test-decor.mjs +27 -0
  262. package/kits/hub-game/scripts/test-device-class.mjs +4 -1
  263. package/kits/hub-game/scripts/test-disguise-client.mjs +281 -0
  264. package/kits/hub-game/scripts/test-disguise.mjs +176 -0
  265. package/kits/hub-game/scripts/test-dock-surface.mjs +404 -0
  266. package/kits/hub-game/scripts/test-door-analytics.mjs +1 -1
  267. package/kits/hub-game/scripts/test-door-stay-client.mjs +602 -0
  268. package/kits/hub-game/scripts/test-door-stay.mjs +613 -0
  269. package/kits/hub-game/scripts/test-earned-client.mjs +119 -0
  270. package/kits/hub-game/scripts/test-emote-surface.mjs +616 -0
  271. package/kits/hub-game/scripts/test-fps-telemetry.mjs +39 -4
  272. package/kits/hub-game/scripts/test-friend-bests.mjs +38 -12
  273. package/kits/hub-game/scripts/test-ghost-click-dom.mjs +75 -0
  274. package/kits/hub-game/scripts/test-grab-client.mjs +29 -2
  275. package/kits/hub-game/scripts/test-grab-orbit.mjs +260 -11
  276. package/kits/hub-game/scripts/test-grab.mjs +10 -1
  277. package/kits/hub-game/scripts/test-hats.mjs +28 -0
  278. package/kits/hub-game/scripts/test-held-offers.mjs +394 -0
  279. package/kits/hub-game/scripts/test-high-only.mjs +3 -3
  280. package/kits/hub-game/scripts/test-hold-show-client.mjs +175 -0
  281. package/kits/hub-game/scripts/test-hold-show.mjs +355 -0
  282. package/kits/hub-game/scripts/test-hub-controls.mjs +3 -1
  283. package/kits/hub-game/scripts/test-hub-idle.mjs +348 -0
  284. package/kits/hub-game/scripts/test-hub-leaving.mjs +21 -0
  285. package/kits/hub-game/scripts/test-hub-ops.mjs +147 -0
  286. package/kits/hub-game/scripts/test-hub-trip.mjs +260 -5
  287. package/kits/hub-game/scripts/test-hud-clear.mjs +83 -0
  288. package/kits/hub-game/scripts/test-hud-rate.mjs +2 -1
  289. package/kits/hub-game/scripts/test-idle.mjs +160 -0
  290. package/kits/hub-game/scripts/test-invites-client.mjs +53 -0
  291. package/kits/hub-game/scripts/test-labels.mjs +11 -0
  292. package/kits/hub-game/scripts/test-landscape-layout.mjs +20 -0
  293. package/kits/hub-game/scripts/test-load-abandon.mjs +2 -2
  294. package/kits/hub-game/scripts/test-loading-cover.mjs +67 -1
  295. package/kits/hub-game/scripts/test-manifest.mjs +27 -0
  296. package/kits/hub-game/scripts/test-menu-client.mjs +55 -6
  297. package/kits/hub-game/scripts/test-menu-surface.mjs +236 -0
  298. package/kits/hub-game/scripts/test-npcs.mjs +128 -0
  299. package/kits/hub-game/scripts/test-observed.mjs +171 -3
  300. package/kits/hub-game/scripts/test-pack.mjs +166 -0
  301. package/kits/hub-game/scripts/test-picker-surface.mjs +321 -0
  302. package/kits/hub-game/scripts/test-placeat-server.mjs +395 -0
  303. package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
  304. package/kits/hub-game/scripts/test-pointer-clear-dom.mjs +82 -0
  305. package/kits/hub-game/scripts/test-progress-reset.mjs +184 -6
  306. package/kits/hub-game/scripts/test-push-visit.mjs +9 -0
  307. package/kits/hub-game/scripts/test-quality.mjs +312 -9
  308. package/kits/hub-game/scripts/test-quick-chat-surface.mjs +511 -0
  309. package/kits/hub-game/scripts/test-rehello.mjs +237 -0
  310. package/kits/hub-game/scripts/test-rejoin-yaw.mjs +138 -0
  311. package/kits/hub-game/scripts/test-relations-among.mjs +13 -7
  312. package/kits/hub-game/scripts/test-relations-refresh.mjs +90 -2
  313. package/kits/hub-game/scripts/test-replay-client.mjs +110 -0
  314. package/kits/hub-game/scripts/test-replay.mjs +178 -0
  315. package/kits/hub-game/scripts/test-resume-held.mjs +13 -0
  316. package/kits/hub-game/scripts/test-resume-pose-server.mjs +43 -5
  317. package/kits/hub-game/scripts/test-resync.mjs +13 -0
  318. package/kits/hub-game/scripts/test-role-client.mjs +10 -3
  319. package/kits/hub-game/scripts/test-safe-act.mjs +233 -0
  320. package/kits/hub-game/scripts/test-safe-caption.mjs +364 -0
  321. package/kits/hub-game/scripts/test-safe-layout.mjs +79 -0
  322. package/kits/hub-game/scripts/test-safe-prompt.mjs +163 -0
  323. package/kits/hub-game/scripts/test-sound-surface.mjs +256 -0
  324. package/kits/hub-game/scripts/test-soundscape.mjs +85 -2
  325. package/kits/hub-game/scripts/test-stuck-surface.mjs +174 -0
  326. package/kits/hub-game/scripts/test-stuck.mjs +31 -0
  327. package/kits/hub-game/scripts/test-talk-surface.mjs +23 -6
  328. package/kits/hub-game/scripts/test-talk-walk-dom.mjs +123 -0
  329. package/kits/hub-game/scripts/test-text-ask-surface.mjs +273 -0
  330. package/kits/hub-game/scripts/test-tiers.mjs +453 -3
  331. package/kits/hub-game/scripts/test-toast-no-row-dom.mjs +71 -0
  332. package/kits/hub-game/scripts/test-together.mjs +11 -0
  333. package/kits/hub-game/scripts/test-town-day.mjs +90 -0
  334. package/kits/hub-game/scripts/test-track-queue.mjs +64 -0
  335. package/kits/hub-game/scripts/test-try-on.mjs +39 -0
  336. package/kits/hub-game/scripts/test-ui-dom-dom.mjs +49 -2
  337. package/kits/hub-game/scripts/test-ui-tree.mjs +28 -0
  338. package/kits/hub-game/scripts/test-vehicle-client.mjs +77 -1
  339. package/kits/hub-game/scripts/test-vis.mjs +145 -0
  340. package/kits/hub-game/scripts/test-wallet.mjs +650 -0
  341. package/kits/hub-game/scripts/test-weakest-tier.mjs +135 -1
  342. package/kits/hub-game/scripts/test-world-labels.mjs +380 -0
  343. package/kits/hub-game/scripts/test-writer-lease-server.mjs +234 -0
  344. package/kits/hub-game/scripts/test-writer-lease.mjs +281 -0
  345. package/kits/hub-game/scripts/writer-storage-fixture.mjs +37 -0
  346. package/kits/hub-game/tools/hubScene/export.mjs +6 -5
  347. package/kits/hub-game/tools/hubScene/hubdata.mjs +10 -0
  348. package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +48 -2
  349. package/kits/hub-game/tools/hubScene/validate-manifest.mjs +21 -3
  350. package/kits/multiplayer-3d/castle.json +5 -5
  351. package/kits/multiplayer-3d/code/client/resumeGate.js +49 -2
  352. package/kits/multiplayer-3d/code/server/ownership.js +25 -6
  353. package/kits/multiplayer-3d/code/server/world.js +19 -4
  354. package/kits/multiplayer-3d/code/systems/multiplayer.js +67 -11
  355. package/kits/multiplayer-3d/package-lock.json +1 -1
  356. package/kits/multiplayer-3d/package.json +2 -1
  357. package/kits/multiplayer-3d/scripts/test-ground-half.mjs +56 -0
  358. package/kits/multiplayer-3d/scripts/test-join-watchdog.mjs +54 -3
  359. package/kits/multiplayer-3d/scripts/test-owned-moves.mjs +190 -0
  360. package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +191 -5
  361. package/kits/multiplayer-3d/scripts/test-resync-reconnect.mjs +68 -0
  362. package/kits/physics-2d/castle.json +2 -2
  363. package/kits/physics-2d/engine/scene.js +10 -2
  364. package/kits/physics-3d/CLAUDE.md +14 -0
  365. package/kits/physics-3d/behaviors/Player.jsx +39 -3
  366. package/kits/physics-3d/castle.json +3 -3
  367. package/kits/physics-3d/docs/engine-model-cache.md +109 -0
  368. package/kits/physics-3d/docs/engine-player.md +76 -0
  369. package/kits/physics-3d/docs/engine-skip-work.md +16 -0
  370. package/kits/physics-3d/docs/pxmodel-format.md +5 -1
  371. package/kits/physics-3d/engine3d/gait.js +16 -8
  372. package/kits/physics-3d/engine3d/groundsize.js +23 -0
  373. package/kits/physics-3d/engine3d/kithooks.js +50 -0
  374. package/kits/physics-3d/engine3d/look.js +110 -17
  375. package/kits/physics-3d/engine3d/lookbake.js +19 -1
  376. package/kits/physics-3d/engine3d/materialpresets.js +3 -2
  377. package/kits/physics-3d/engine3d/modelcache.js +280 -0
  378. package/kits/physics-3d/engine3d/modelcachedigest.js +37 -0
  379. package/kits/physics-3d/engine3d/modelcachegate.js +69 -0
  380. package/kits/physics-3d/engine3d/modelrefs.js +13 -0
  381. package/kits/physics-3d/engine3d/optimize.js +20 -9
  382. package/kits/physics-3d/engine3d/playerRun.js +26 -1
  383. package/kits/physics-3d/engine3d/pxmodel.js +7 -3
  384. package/kits/physics-3d/engine3d/templatecache.js +722 -0
  385. package/kits/physics-3d/engine3d/world3d.js +211 -17
  386. package/kits/physics-3d/package-lock.json +1 -1
  387. package/kits/physics-3d/package.json +2 -1
  388. package/kits/physics-3d/play/behaviors/Player.js +43 -3
  389. package/kits/physics-3d/scripts/render.mjs +56 -8
  390. package/kits/physics-3d/scripts/template-cache-fixtures.mjs +37 -0
  391. package/kits/physics-3d/scripts/template-cache-v1-bytes.json +49 -0
  392. package/kits/physics-3d/scripts/test-gait.mjs +53 -9
  393. package/kits/physics-3d/scripts/test-ground-half.mjs +120 -0
  394. package/kits/physics-3d/scripts/test-model-cache.mjs +600 -0
  395. package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1 -0
  396. package/kits/physics-3d/scripts/test-sleeping-models.mjs +384 -0
  397. package/kits/physics-3d/scripts/test-template-cache-minified.mjs +106 -0
  398. package/kits/physics-3d/scripts/test-template-cache.mjs +519 -0
  399. package/kits/physics-3d/scripts/test-wall-slide.mjs +272 -0
  400. package/kits/physics-3d/systems/physics3d.js +51 -2
  401. package/kits/real-time/castle.json +2 -2
  402. package/kits/real-time/code/client/connection.js +3 -0
  403. package/package.json +2 -2
  404. package/vendor/three/examples/jsm/libs/fflate.module.js +2672 -0
@@ -0,0 +1,613 @@
1
+ // v1.169 server: a player's own door end is tagged on the wire, and `hub-stay`
2
+ // undoes only that end, in a place without a result, holding the door shut
3
+ // until the player steps off it. Real hub hooks; `npm run check` runs this.
4
+ import assert from 'node:assert/strict';
5
+ import { register } from 'node:module';
6
+ import { poseStorage } from './pose-storage-fixture.mjs';
7
+
8
+ register(`data:text/javascript,${encodeURIComponent(`
9
+ export async function resolve(specifier, context, next) {
10
+ if (specifier === '@imports/castle.multiplayer-3d/code/server/sceneBodies.js') return { url: 'data:text/javascript,export const readScene = () => globalThis.__hubTestActors;', shortCircuit: true };
11
+ if (context.parentURL?.includes('/kits/base/sdk/') && specifier.startsWith('.') && !specifier.endsWith('.js')) return next(specifier + '.js', context);
12
+ return next(specifier, context);
13
+ }
14
+ `)}`);
15
+ const { layer } = await import('../code/server/hub.js');
16
+
17
+ const actors = [
18
+ // The door zone is x > 5; the prompt there is in reach only inside it.
19
+ { id: 'sign', components: { HubAct: { id: 'read', verb: 'Read', reach: 2, hold: false }, Transform: { x: 10, y: 1, z: 0 } } },
20
+ { id: 'player', components: { Player: {}, Transform: { x: 0, y: 1, z: 0 } } },
21
+ ];
22
+ let wallNow = 100000;
23
+ Date.now = () => wallNow;
24
+ const players = [
25
+ { playerId: 'p1', userId: '101', username: 'Ada', isAnonymous: false },
26
+ { playerId: 'p2', userId: '102', username: 'Bo', isAnonymous: false },
27
+ ];
28
+ // `door`: the place's step ends a player in the zone through their own door,
29
+ // every step they stand there (a place that asks again, as a level would).
30
+ function boot({ keys = {}, door = true, hooks = {}, storage = null, progress = null } = {}) {
31
+ const sent = [], asked = [];
32
+ let hub;
33
+ const allHooks = {
34
+ ready(ctx) { hub = ctx; },
35
+ step(ctx) {
36
+ if (!door) {return;}
37
+ for (const [id, body] of world.players) {
38
+ if (body.at.x > 5) {
39
+ asked.push(id);
40
+ ctx.end([id], { door: 'front-door' });
41
+ }
42
+ }
43
+ },
44
+ ...hooks,
45
+ };
46
+ globalThis.__hubTestActors = structuredClone(actors);
47
+ const engine = {
48
+ createBody(sim, actor, at) {
49
+ return { at: { ...at }, setEnabled() {}, setNextKinematicTranslation(p) { this.at = { ...p }; }, setNextKinematicRotation() {} };
50
+ },
51
+ removeActor(sim, id) { sim.bodies.delete(id); sim.objects.delete(id); },
52
+ };
53
+ const json = { ...(progress ? { deckId: 'door-stay-test' } : {}), server: { maxPlayers: 8 }, hub: { contract: 1, title: 'House', act: true, ...keys } };
54
+ const server = layer(json, allHooks, {}, () => true, () => null, null, engine);
55
+ const session = { sessionId: 'dev', players: [...players], hub: null, ...(storage || progress ? { storage: { ...(storage ? { deck: storage } : {}), ...(progress ? { playthrough: progress } : {}) } } : {}), send(id, msg) { sent.push([id, structuredClone(msg)]); }, broadcast(msg) { sent.push(['all', structuredClone(msg)]); } };
56
+ const world = { timeMs: 0, scenePath: 'scenes/main.scene', objects: new Map(), bodies: new Map(), players: new Map(players.map((p) => [p.playerId, { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } }])) };
57
+ server.sceneFor(session);
58
+ server.ready(world);
59
+ // The client says hub-stay with the number of the door end it stayed: the
60
+ // latest tagged end it heard, unless a test names one (or none) itself.
61
+ const lastEnd = (id) => sent.filter(([to, m]) => to === id && m.k === 'hub-end' && m.door !== undefined).at(-1)?.[1].end ?? 1;
62
+ const say = (id, data) => server.message(session, { playerId: id },
63
+ data?.k === 'hub-stay' && !Object.hasOwn(data, 'end') ? { ...data, end: lastEnd(id) } : data);
64
+ for (const id of ['p1', 'p2']) {
65
+ say(id, { k: 'hub-hello', avatar: 0, party: 1 });
66
+ }
67
+ server.place(world);
68
+ const tick = (ms = 50) => { wallNow += ms; world.timeMs += ms; server.place(world); server.step(world, []); };
69
+ tick(3000);
70
+ const at = (x) => { world.players.get('p1').at.x = x; };
71
+ // Ends as the client reads them; their numbers are checked on their own (`numbers`).
72
+ const ends = () => sent.filter(([id, m]) => id === 'p1' && m.k === 'hub-end').map(([, m]) => { const { end: _n, ...rest } = m; return rest; });
73
+ const prompts = () => sent.filter(([id, m]) => id === 'p1' && m.k === 'hub-prompts').at(-1)?.[1].items.map((i) => i.id) ?? [];
74
+ const numbers = () => sent.filter(([id, m]) => id === 'p1' && m.k === 'hub-end').map(([, m]) => m.end ?? null);
75
+ const acks = () => sent.filter(([id, m]) => id === 'p1' && m.k === 'hub-stayed').map(([, m]) => m.end);
76
+ return { server, session, world, get hub() { return hub; }, sent, asked, say, tick, at, ends, numbers, acks, prompts };
77
+ }
78
+
79
+ const log = console.log;
80
+ console.log = () => {};
81
+ let n = 0;
82
+ function test(name, fn) {
83
+ try {
84
+ fn();
85
+ } catch (err) {
86
+ console.log = log;
87
+ console.error(`not ok: ${name}`);
88
+ throw err;
89
+ }
90
+ n += 1;
91
+ }
92
+
93
+ test('a door end is tagged once; hub-stay un-ends, restores Act and holds the door until step-off', () => {
94
+ const r = boot();
95
+ r.at(10);
96
+ r.tick();
97
+ assert.deepEqual(r.ends(), [{ k: 'hub-end', why: 'end', door: 'front-door' }], 'the end names the door');
98
+ for (let i = 0; i < 5; i += 1) {r.tick();}
99
+ assert.equal(r.ends().length, 1, 'a place that keeps asking says the end once');
100
+ assert.deepEqual(r.prompts(), [], 'an ended player is offered nothing');
101
+ assert.equal(r.say('p1', { k: 'hub-stay' }), undefined);
102
+ assert.deepEqual(r.prompts(), ['read'], 'Act prompts are replayed at once');
103
+ const asked = r.asked.length;
104
+ for (let i = 0; i < 10; i += 1) {r.tick();}
105
+ assert.ok(r.asked.length > asked, 'the place still asks while they stand in the door');
106
+ assert.equal(r.ends().length, 1, 'held shut while they stand in it');
107
+ assert.deepEqual(r.prompts(), ['read'], 'still in the place');
108
+ r.say('p1', { k: 'hub-act', id: 'read', n: 1 });
109
+ // Stepping off lets it go; walking back in fires it again.
110
+ r.at(0);
111
+ r.tick();
112
+ r.tick();
113
+ r.at(10);
114
+ r.tick();
115
+ assert.deepEqual(r.ends().at(-1), { k: 'hub-end', why: 'end', door: 'front-door' });
116
+ assert.equal(r.ends().length, 2, 'the door works again after a step off');
117
+ // A second stay for the same end is honoured once more, and an extra one is not.
118
+ r.say('p1', { k: 'hub-stay' });
119
+ r.at(0);
120
+ r.tick();
121
+ r.tick();
122
+ r.say('p1', { k: 'hub-stay' });
123
+ r.tick();
124
+ assert.deepEqual(r.ends().length, 2);
125
+ // p2 never heard any of it.
126
+ assert.ok(!r.sent.some(([id, m]) => id === 'p2' && m.k === 'hub-end'));
127
+ });
128
+
129
+ test('a stay is numbered to its end and acknowledged; a repeat is acknowledged again and changes nothing', () => {
130
+ const r = boot();
131
+ r.at(10);
132
+ r.tick();
133
+ assert.deepEqual(r.numbers(), [1], 'the door end carries its number');
134
+ r.say('p1', { k: 'hub-stay', end: 1 });
135
+ r.tick();
136
+ assert.deepEqual(r.prompts(), ['read']);
137
+ assert.deepEqual(r.acks(), [1], 'the stay is answered with its end');
138
+ // Its answer was lost: the client says it again behind a resume hello.
139
+ const prompts = r.sent.filter(([, m]) => m.k === 'hub-prompts').length;
140
+ r.say('p1', { k: 'hub-stay', end: 1 });
141
+ assert.deepEqual(r.acks(), [1, 1], 'answered again');
142
+ assert.equal(r.sent.filter(([, m]) => m.k === 'hub-prompts').length, prompts, 'nothing replayed, nothing undone');
143
+ // After a later end that is not the door, a repeat cannot undo it.
144
+ r.hub.end(['p1']);
145
+ r.say('p1', { k: 'hub-stay', end: 1 });
146
+ r.tick();
147
+ assert.deepEqual(r.prompts(), [], 'the later end stands');
148
+ });
149
+
150
+ test('a stay with no end, a wrong end, or extra keys is ignored', () => {
151
+ const r = boot();
152
+ r.at(10);
153
+ r.tick();
154
+ const tries = [{ k: 'hub-stay', end: undefined }, { k: 'hub-stay', end: 2 }, { k: 'hub-stay', end: 0 }, { k: 'hub-stay', end: '1' }, { k: 'hub-stay', end: 1, x: 1 }];
155
+ for (const data of tries) {r.server.message(r.session, { playerId: 'p1' }, data);}
156
+ r.server.message(r.session, { playerId: 'p1' }, { k: 'hub-stay' });
157
+ r.tick();
158
+ assert.deepEqual(r.prompts(), [], 'still ended');
159
+ assert.deepEqual(r.acks(), [], 'and nothing answered');
160
+ r.say('p1', { k: 'hub-stay', end: 1 });
161
+ assert.deepEqual(r.prompts(), ['read'], 'the right number stays it');
162
+ });
163
+
164
+ test("Sol #3: an old stay, resent after its answer was lost, cannot undo a newer door end", () => {
165
+ const r = boot();
166
+ r.at(10);
167
+ r.tick();
168
+ r.say('p1', { k: 'hub-stay', end: 1 });
169
+ r.tick();
170
+ assert.deepEqual(r.prompts(), ['read'], 'the first end is stayed (its answer is lost on the way)');
171
+ // Online, the guest steps off and walks into the door again: end 2.
172
+ r.at(0);
173
+ r.tick();
174
+ r.tick();
175
+ r.at(10);
176
+ r.tick();
177
+ assert.deepEqual(r.numbers(), [1, 2], 'the newer end has a newer number');
178
+ // On resume the client says its old stay again.
179
+ r.say('p1', { k: 'hub-stay', end: 1 });
180
+ r.tick();
181
+ assert.deepEqual(r.prompts(), [], 'the newer end stands');
182
+ assert.deepEqual(r.acks(), [1, 1], 'the old stay is only acknowledged again');
183
+ // The newer end's own stay still works.
184
+ r.say('p1', { k: 'hub-stay', end: 2 });
185
+ assert.deepEqual(r.prompts(), ['read']);
186
+ assert.deepEqual(r.acks(), [1, 1, 2]);
187
+ });
188
+
189
+ test('hub-stay is ignored for a kick-style end, and an end since the door takes the tag away', () => {
190
+ const r = boot({ door: false });
191
+ r.at(10);
192
+ r.tick();
193
+ r.hub.end(['p1']);
194
+ assert.deepEqual(r.ends(), [{ k: 'hub-end', why: 'end' }], 'no tag outside a door');
195
+ r.say('p1', { k: 'hub-stay' });
196
+ r.tick();
197
+ assert.deepEqual(r.prompts(), [], 'still ended');
198
+ // Everyone at once is never a door, even with the option.
199
+ r.hub.end(null, { door: 'front-door' });
200
+ assert.ok(r.sent.filter(([, m]) => m.k === 'hub-end').every(([, m]) => m.door === undefined));
201
+ // The door first, then the owner's end: the stay is refused.
202
+ const s = boot();
203
+ s.at(10);
204
+ s.tick();
205
+ s.hub.end(['p1']);
206
+ assert.deepEqual(s.ends().map((m) => m.door ?? null), ['front-door', null]);
207
+ s.say('p1', { k: 'hub-stay' });
208
+ s.tick();
209
+ assert.deepEqual(s.prompts(), [], 'a kick after the door still completes');
210
+ // A malformed door option ends untagged.
211
+ const t = boot({ door: false });
212
+ t.hub.end(['p1'], { door: 'no spaces!' });
213
+ assert.deepEqual(t.ends(), [{ k: 'hub-end', why: 'end' }]);
214
+ });
215
+
216
+ test('a result place never tags its ends, and ignores hub-stay', () => {
217
+ const r = boot({ keys: { result: {} } });
218
+ r.at(10);
219
+ r.tick();
220
+ assert.ok(r.ends().length >= 1);
221
+ assert.ok(r.ends().every((m) => m.door === undefined), 'a game end carries no door');
222
+ const before = r.ends().length;
223
+ r.say('p1', { k: 'hub-stay' });
224
+ r.tick();
225
+ assert.deepEqual(r.prompts(), [], 'still ended');
226
+ assert.ok(r.ends().length >= before);
227
+ });
228
+
229
+ test('an end the player\'s own Act press makes is tagged with its id', () => {
230
+ const r = boot({ door: false, hooks: { message(ctx, player, data) { if (data.k === 'hub-act') {ctx.end([player.playerId]);} } } });
231
+ r.at(10);
232
+ r.tick();
233
+ assert.deepEqual(r.prompts(), ['read']);
234
+ r.say('p1', { k: 'hub-act', id: 'read', n: 1 });
235
+ assert.deepEqual(r.ends(), [{ k: 'hub-end', why: 'end', door: 'read' }]);
236
+ r.say('p1', { k: 'hub-stay' });
237
+ assert.deepEqual(r.prompts(), ['read'], 'back, with the prompt');
238
+ // The press's tag is only for its own hook: a later end is untagged.
239
+ r.tick();
240
+ r.tick();
241
+ r.hub.end(['p1']);
242
+ assert.deepEqual(r.ends().at(-1), { k: 'hub-end', why: 'end' });
243
+ });
244
+
245
+ test('an unknown hub-stay from a player who is not ended changes nothing', () => {
246
+ const r = boot();
247
+ const before = r.sent.length;
248
+ r.say('p1', { k: 'hub-stay' });
249
+ assert.equal(r.sent.length, before);
250
+ });
251
+
252
+ test('review: the door tag survives a resume hello, so the stay after it un-ends with Act back', () => {
253
+ const r = boot();
254
+ r.at(10);
255
+ r.tick();
256
+ assert.equal(r.ends().at(-1)?.door, 'front-door');
257
+ // The client's resume hello comes before its hub-stay.
258
+ r.say('p1', { k: 'hub-hello', avatar: 0, party: 1, resume: true });
259
+ r.tick();
260
+ r.say('p1', { k: 'hub-stay' });
261
+ r.tick();
262
+ assert.deepEqual(r.prompts(), ['read'], 'un-ended, prompts back');
263
+ for (let i = 0; i < 5; i += 1) {r.tick();}
264
+ assert.equal(r.ends().length, 1, 'and the door is held');
265
+ });
266
+
267
+ test('review: inside a press, only a one-player list naming the presser is tagged', () => {
268
+ let how = null;
269
+ const r = boot({ door: false, hooks: { message(ctx, player, data) { if (data.k === 'hub-act') {ctx.end(...how(player.playerId));} } } });
270
+ r.at(10);
271
+ r.world.players.get('p2').at.x = 10;
272
+ r.tick();
273
+ const press = (n, fn) => { how = fn; r.say('p1', { k: 'hub-act', id: 'read', n }); };
274
+ press(1, () => [null]);
275
+ press(2, () => [['p1', 'p2']]);
276
+ press(3, () => [['p2']]);
277
+ const tagged = r.sent.filter(([, m]) => m.k === 'hub-end' && m.door !== undefined);
278
+ assert.deepEqual(tagged, [], 'no whole-place, multi-player or other-player end is a door');
279
+ assert.ok(r.sent.some(([id, m]) => id === 'p2' && m.k === 'hub-end'), 'they still ended');
280
+ });
281
+
282
+ const poseSaved = async (stayed) => {
283
+ const storage = poseStorage();
284
+ const r = boot({ keys: { resumePose: true }, storage });
285
+ for (let i = 0; i < 20; i += 1) {await new Promise((resolve) => setTimeout(resolve, 0));}
286
+ // Arrivals wait for the pose read, and then hold the arrival a moment.
287
+ for (let i = 0; i < 4; i += 1) {r.tick(3000);}
288
+ if (stayed) {
289
+ r.at(10);
290
+ r.tick();
291
+ assert.equal(r.ends().at(-1)?.door, 'front-door');
292
+ r.say('p1', { k: 'hub-stay' });
293
+ r.at(0);
294
+ r.tick();
295
+ r.tick();
296
+ }
297
+ for (let i = 0; i < 20; i += 1) {await new Promise((resolve) => setTimeout(resolve, 0));}
298
+ r.tick();
299
+ await r.server.shutdown();
300
+ return [...storage.rows.keys()].filter((key) => key.includes('101') && key.endsWith(':pose'));
301
+ };
302
+
303
+ // The place's own view of who is here, as the House keeps it: a door end
304
+ // asked only for players its arrive hook has and its leave hook has not let go.
305
+ // mode: 'late' (stay once arrived), 'early' (stay right after the resume
306
+ // hello, before arrival), 'none' (no stay), 'fresh' (a first hello, then a
307
+ // stay), 'kick' / 'all' (an untagged end for them, or for everyone, after they
308
+ // were let go, then a resume hello and a stay).
309
+ const replaced = async (mode) => {
310
+ const stays = mode === 'late' || mode === 'early';
311
+ const here = new Set();
312
+ const r = boot({
313
+ keys: { resumePose: true },
314
+ storage: poseStorage(),
315
+ door: false,
316
+ hooks: {
317
+ arrive(ctx, group) { for (const p of group) {here.add(p.playerId);} },
318
+ leave(ctx, id) { here.delete(id); },
319
+ step(ctx) {
320
+ for (const id of here) {
321
+ if (r.world.players.get(id)?.at.x > 5) {
322
+ r.asked.push(id);
323
+ ctx.end([id], { door: 'front-door' });
324
+ }
325
+ }
326
+ },
327
+ },
328
+ });
329
+ const settle = async () => { for (let i = 0; i < 20; i += 1) {await new Promise((resolve) => setTimeout(resolve, 0));} };
330
+ await settle();
331
+ for (let i = 0; i < 4; i += 1) {r.tick(3000);}
332
+ assert.ok(here.has('p1'), 'arrived');
333
+ r.at(10);
334
+ r.world.players.get('p1').at.z = 1;
335
+ r.tick();
336
+ assert.deepEqual(r.ends(), [{ k: 'hub-end', why: 'end', door: 'front-door' }]);
337
+ // The connection drops and comes back on a replacement body, at the spawn.
338
+ r.world.players.set('p1', { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
339
+ r.tick();
340
+ if (mode === 'kick') {r.hub.end(['p1']);}
341
+ if (mode === 'all') {r.hub.end();}
342
+ r.say('p1', { k: 'hub-hello', avatar: 0, party: 1, ...(mode === 'fresh' ? {} : { resume: true }) });
343
+ if (mode === 'early') {r.say('p1', { k: 'hub-stay' });}
344
+ await settle();
345
+ for (let i = 0; i < 4; i += 1) {r.tick(3000);}
346
+ // (An end for a player already let go leaves them departing, as before
347
+ // v1.169; whether they arrive again is not this test's business.)
348
+ if (mode !== 'kick' && mode !== 'all') {assert.ok(here.has('p1'), 'arrived again, afresh');}
349
+ const body = () => r.world.players.get('p1').at;
350
+ if (mode === 'early') {
351
+ assert.ok(Math.abs(body().x - 10) < 0.01 && Math.abs(body().z - 1) < 0.01, `an early stay is applied after arrival placed them, at ${JSON.stringify(body())}`);
352
+ } else {
353
+ assert.ok(body().x < 5, 'at the arrival spot, not the door');
354
+ assert.deepEqual(r.prompts(), [], 'still ended until a stay');
355
+ }
356
+ if (mode === 'kick' || mode === 'all') {
357
+ r.say('p1', { k: 'hub-stay' });
358
+ for (let i = 0; i < 5; i += 1) {r.tick();}
359
+ assert.ok(body().x < 5, `${mode}: a later end took the door's stay away`);
360
+ assert.deepEqual(r.prompts(), [], `${mode}: still ended`);
361
+ assert.deepEqual(r.ends().map((m) => m.door ?? null), ['front-door', null], `${mode}: the later end was untagged`);
362
+ } else if (mode === 'fresh') {
363
+ // A first hello is a new visit: the record is dropped, and a stay moves nobody.
364
+ r.say('p1', { k: 'hub-stay' });
365
+ assert.ok(body().x < 5, 'a fresh visit is never put back on the door');
366
+ } else if (stays) {
367
+ if (mode === 'late') {r.say('p1', { k: 'hub-stay' });}
368
+ assert.ok(Math.abs(body().x - 10) < 0.01 && Math.abs(body().z - 1) < 0.01, `back where the end left them, at ${JSON.stringify(body())}`);
369
+ r.tick();
370
+ assert.deepEqual(r.prompts(), ['read'], 'un-ended, prompts back');
371
+ const asked = r.asked.length;
372
+ for (let i = 0; i < 10; i += 1) {r.tick();}
373
+ assert.ok(r.asked.length > asked, 'the place asks while they stand in the door');
374
+ assert.equal(r.ends().length, 1, 'held until they step off');
375
+ r.at(0);
376
+ r.tick();
377
+ r.tick();
378
+ r.at(10);
379
+ r.tick();
380
+ assert.equal(r.ends().length, 2, 'then the door works again');
381
+ } else {
382
+ for (let i = 0; i < 10; i += 1) {r.tick();}
383
+ assert.ok(body().x < 5, 'never put back on the door');
384
+ assert.deepEqual(r.prompts(), [], 'the end stands');
385
+ }
386
+ };
387
+
388
+ // End numbers rise for the session: a let-go and a fresh hello do not reset them.
389
+ const risingNumbers = async () => {
390
+ const flush = async () => { for (let i = 0; i < 20; i += 1) {await new Promise((resolve) => setTimeout(resolve, 0));} };
391
+ const r = boot({ keys: { resumePose: true }, storage: poseStorage() });
392
+ for (let i = 0; i < 4; i += 1) {await flush(); r.tick(3000);}
393
+ r.at(10);
394
+ r.tick();
395
+ r.session.players = r.session.players.filter((p) => p.playerId !== 'p1');
396
+ const body = r.world.players.get('p1');
397
+ r.world.players.delete('p1');
398
+ r.tick(1000);
399
+ r.session.players = [...r.session.players, players.find((p) => p.playerId === 'p1')];
400
+ body.at = { x: 0, y: 1, z: 0 };
401
+ r.world.players.set('p1', body);
402
+ r.say('p1', { k: 'hub-hello', avatar: 0, party: 1 });
403
+ for (let i = 0; i < 4; i += 1) {await flush(); r.tick(3000);}
404
+ r.at(10);
405
+ r.tick();
406
+ const numbers = r.numbers().filter((x) => x !== null);
407
+ assert.ok(numbers.length >= 2 && numbers.at(-1) > numbers[0], `monotonic: ${JSON.stringify(numbers)}`);
408
+ r.say('p1', { k: 'hub-stay', end: numbers[0] });
409
+ r.tick();
410
+ assert.deepEqual(r.prompts(), [], 'a stale number never matches the newer record');
411
+ };
412
+
413
+ // A door end, then the visit let go with no entry left (resumePose without a
414
+ // pose store: away past the window), then an untagged end for them or for
415
+ // everyone. A resume hello and a hub-stay afterwards must change nothing.
416
+ const letGoThenEnd = (mode) => {
417
+ const here = new Set();
418
+ let r = null;
419
+ r = boot({
420
+ keys: { resumePose: true },
421
+ door: false,
422
+ hooks: {
423
+ arrive(ctx, group) { for (const p of group) {here.add(p.playerId);} },
424
+ leave(ctx, id) { here.delete(id); },
425
+ step(ctx) {
426
+ for (const id of here) {
427
+ if (r?.world.players.get(id)?.at.x > 5) {ctx.end([id], { door: 'front-door' });}
428
+ }
429
+ },
430
+ },
431
+ });
432
+ for (let i = 0; i < 4; i += 1) {r.tick(3000);}
433
+ r.at(10);
434
+ r.tick();
435
+ assert.equal(r.ends().at(-1)?.door, 'front-door');
436
+ const body = r.world.players.get('p1');
437
+ r.world.players.delete('p1');
438
+ r.tick();
439
+ r.tick(6 * 60000);
440
+ r.tick();
441
+ assert.ok(!here.has('p1'), 'let go');
442
+ if (mode === 'kick') {r.hub.end(['p1']);} else {r.hub.end();}
443
+ body.at = { x: 0, y: 1, z: 0 };
444
+ r.world.players.set('p1', body);
445
+ r.say('p1', { k: 'hub-hello', avatar: 0, party: 1, resume: true });
446
+ for (let i = 0; i < 4; i += 1) {r.tick(3000);}
447
+ assert.ok(here.has('p1'), 'arrived again');
448
+ r.say('p1', { k: 'hub-stay' });
449
+ for (let i = 0; i < 5; i += 1) {r.tick();}
450
+ assert.ok(r.world.players.get('p1').at.x < 5, `${mode}: the later end took the door's stay away`);
451
+ };
452
+
453
+ // QA: the client says hub-stay once it is placed again, which reaches the
454
+ // server right after its resume hello, while that hello's progress read is in
455
+ // flight (or, from a socket that came back early, before the hello). The kit
456
+ // dropped every client message during a progress read, so the House never
457
+ // heard the stay and the guest stayed ended for good.
458
+ const progressStay = async (when) => {
459
+ const here = new Set();
460
+ let r = null;
461
+ const flush = async () => { for (let i = 0; i < 20; i += 1) {await new Promise((resolve) => setTimeout(resolve, 0));} };
462
+ r = boot({
463
+ keys: { resumePose: true },
464
+ storage: poseStorage(),
465
+ progress: () => new Promise((resolve) => setTimeout(() => resolve({ resetGeneration: 0 }), 5)),
466
+ door: false,
467
+ hooks: {
468
+ arrive(ctx, group) { for (const p of group) {here.add(p.playerId);} },
469
+ leave(ctx, id) { here.delete(id); },
470
+ step(ctx) {
471
+ for (const id of here) {
472
+ if (r?.world.players.get(id)?.at.x > 5) {ctx.end([id], { door: 'front-door' });}
473
+ }
474
+ },
475
+ },
476
+ });
477
+ for (let i = 0; i < 6; i += 1) {await flush(); r.tick(3000);}
478
+ assert.ok(here.has('p1'), 'arrived');
479
+ r.at(10);
480
+ r.world.players.get('p1').at.z = 1;
481
+ r.tick();
482
+ assert.equal(r.ends().at(-1)?.door, 'front-door');
483
+ // The socket drops: the session lets the player and body go.
484
+ r.session.players = r.session.players.filter((p) => p.playerId !== 'p1');
485
+ r.world.players.delete('p1');
486
+ for (let i = 0; i < 4; i += 1) {r.tick(1000);}
487
+ assert.ok(!here.has('p1'), 'let go');
488
+ // Back under the same player id, on a new body at the spawn.
489
+ r.session.players = [...r.session.players, players.find((p) => p.playerId === 'p1')];
490
+ r.world.players.set('p1', { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
491
+ r.tick();
492
+ if (when === 'before-hello') {r.say('p1', { k: 'hub-stay' });}
493
+ r.say('p1', { k: 'hub-hello', avatar: 0, party: 1, resume: true });
494
+ if (when === 'after-hello' || when === 'account-swap') {r.say('p1', { k: 'hub-stay' });}
495
+ if (when === 'account-swap') {
496
+ // The trusted roster now names another account on this player id, while
497
+ // the stay waits on the hello's progress read and arrival.
498
+ r.session.players = r.session.players.map((p) => (p.playerId === 'p1' ? { ...p, userId: '199', username: 'Cy' } : p));
499
+ for (let i = 0; i < 6; i += 1) {await flush(); r.tick(3000);}
500
+ const at = r.world.players.get('p1').at;
501
+ assert.ok(!(Math.abs(at.x - 10) < 0.01 && Math.abs(at.z - 1) < 0.01), `account-swap: never put back on the previous account's door pose, at ${JSON.stringify(at)}`);
502
+ assert.deepEqual(r.prompts(), [], 'account-swap: the previous account\'s end is not undone');
503
+ // The record is gone: the old account's stay cannot come back either.
504
+ r.session.players = r.session.players.map((p) => (p.playerId === 'p1' ? players.find((q) => q.playerId === 'p1') : p));
505
+ r.say('p1', { k: 'hub-stay' });
506
+ for (let i = 0; i < 3; i += 1) {await flush(); r.tick(3000);}
507
+ assert.ok(!(Math.abs(r.world.players.get('p1').at.x - 10) < 0.01), 'account-swap: a later stay finds no record');
508
+ return;
509
+ }
510
+ for (let i = 0; i < 6; i += 1) {await flush(); r.tick(3000);}
511
+ assert.ok(here.has('p1'), 'arrived again');
512
+ const at = r.world.players.get('p1').at;
513
+ assert.ok(Math.abs(at.x - 10) < 0.01 && Math.abs(at.z - 1) < 0.01, `${when}: the stay was heard and put them back, at ${JSON.stringify(at)}`);
514
+ assert.deepEqual(r.prompts(), ['read'], `${when}: un-ended, prompts back`);
515
+ const ends = r.ends().length;
516
+ for (let i = 0; i < 5; i += 1) {r.tick();}
517
+ assert.equal(r.ends().length, ends, `${when}: the door is held while they stand in it`);
518
+ r.at(0);
519
+ r.tick();
520
+ r.tick();
521
+ r.at(10);
522
+ r.tick();
523
+ assert.equal(r.ends().length, ends + 1, `${when}: and works again online after a step off`);
524
+ };
525
+
526
+ // Sol: an arrived player whose stay waits on their resume hello's progress
527
+ // read, out of the roster just while that read settles, then back on the same
528
+ // body before the session lets them go. The record must survive, so the
529
+ // client's next numbered stay is heard.
530
+ const rosterBlip = async () => {
531
+ let r = null;
532
+ let release = null;
533
+ const flush = async () => { for (let i = 0; i < 20; i += 1) {await new Promise((resolve) => setTimeout(resolve, 0));} };
534
+ r = boot({ progress: () => new Promise((resolve) => { release = () => resolve({ resetGeneration: 0 }); }) });
535
+ for (let i = 0; i < 6; i += 1) {release?.(); await flush(); r.tick(3000);}
536
+ r.at(10);
537
+ r.tick();
538
+ assert.equal(r.ends().at(-1)?.door, 'front-door');
539
+ release = null;
540
+ r.say('p1', { k: 'hub-hello', avatar: 0, party: 1, resume: true });
541
+ r.tick();
542
+ r.say('p1', { k: 'hub-stay' });
543
+ assert.deepEqual(r.prompts(), [], 'roster-blip: deferred behind the read');
544
+ assert.ok(release, 'roster-blip: a progress read is in flight');
545
+ const member = r.session.players.find((p) => p.playerId === 'p1');
546
+ r.session.players = r.session.players.filter((p) => p.playerId !== 'p1');
547
+ release();
548
+ await flush();
549
+ r.session.players = [...r.session.players, member];
550
+ r.say('p1', { k: 'hub-stay' });
551
+ r.tick();
552
+ assert.deepEqual(r.prompts(), ['read'], 'roster-blip: the record survived, and the retry is heard');
553
+ assert.ok(r.sent.some(([id, m]) => id === 'p1' && m.k === 'hub-stayed'), 'roster-blip: acknowledged');
554
+ };
555
+
556
+ console.log = log;
557
+ {
558
+ console.log = () => {};
559
+ try {
560
+ await rosterBlip();
561
+ } catch (err) {
562
+ console.log = log;
563
+ console.error('not ok: a stay kept through a roster blip during its progress read');
564
+ throw err;
565
+ }
566
+ n += 1;
567
+ try {
568
+ await risingNumbers();
569
+ } catch (err) {
570
+ console.log = log;
571
+ console.error('not ok: end numbers keep rising across a let-go and a fresh hello');
572
+ throw err;
573
+ }
574
+ n += 1;
575
+ for (const when of ['after-hello', 'before-hello', 'account-swap']) {
576
+ try {
577
+ await progressStay(when);
578
+ } catch (err) {
579
+ console.log = log;
580
+ console.error(`not ok: a stay around a progress read, ${when}`);
581
+ throw err;
582
+ }
583
+ n += 1;
584
+ }
585
+ for (const mode of ['kick', 'all']) {
586
+ try {
587
+ letGoThenEnd(mode);
588
+ } catch (err) {
589
+ console.log = log;
590
+ console.error(`not ok: let go, then ${mode}`);
591
+ throw err;
592
+ }
593
+ n += 1;
594
+ }
595
+ for (const mode of ['late', 'early', 'none', 'fresh']) {
596
+ try {
597
+ await replaced(mode);
598
+ } catch (err) {
599
+ console.log = log;
600
+ console.error(`not ok: replacement body, ${mode}`);
601
+ throw err;
602
+ }
603
+ n += 1;
604
+ }
605
+ // Baseline: a player who never went near the door has their pose kept.
606
+ const baseline = await poseSaved(false);
607
+ const ended = await poseSaved(true);
608
+ console.log = log;
609
+ assert.equal(baseline.length, 1, 'baseline: the pose is kept at shutdown');
610
+ assert.equal(ended.length, 1, 'review: a stayed player takes the pose lease again and their pose is kept');
611
+ n += 1;
612
+ }
613
+ console.log(`door stay: ${n} tests passed`);