castle-web-cli 0.4.232 → 0.4.233

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (355) hide show
  1. package/dist/agent-failures.d.ts +8 -0
  2. package/dist/agent-failures.js +19 -2
  3. package/dist/agent-prompts.d.ts +1 -1
  4. package/dist/agent-prompts.js +10 -3
  5. package/dist/agent.d.ts +64 -3
  6. package/dist/agent.js +170 -81
  7. package/dist/castle-host/host.d.ts +1 -0
  8. package/dist/castle-host/host.js +51 -3
  9. package/dist/castleJson.d.ts +4 -2
  10. package/dist/castleJson.js +2 -0
  11. package/dist/check.d.ts +3 -1
  12. package/dist/check.js +11 -1
  13. package/dist/devSessionStorage.js +47 -1
  14. package/dist/importPinMismatch.d.ts +22 -0
  15. package/dist/importPinMismatch.js +77 -0
  16. package/dist/importRegression.js +3 -15
  17. package/dist/imports.d.ts +10 -3
  18. package/dist/imports.js +88 -20
  19. package/dist/index.js +5 -4
  20. package/dist/init.js +1 -1
  21. package/dist/platformDoc.js +22 -0
  22. package/dist/routerFences.d.ts +5 -0
  23. package/dist/routerFences.js +12 -2
  24. package/dist/save-deck.d.ts +5 -0
  25. package/dist/save-deck.js +37 -4
  26. package/dist/serve.js +3 -0
  27. package/dist/shell/assets/{index-D2tWM896.js → index-BjOxR-lW.js} +4 -4
  28. package/dist/shell/assets/index-MVLfNYd9.css +1 -0
  29. package/dist/shell/index.html +2 -2
  30. package/dist/taskSteer.d.ts +13 -0
  31. package/dist/taskSteer.js +22 -2
  32. package/kits/base/castle.json +1 -1
  33. package/kits/base/package-lock.json +1 -1
  34. package/kits/base/sdk/README.md +79 -2
  35. package/kits/base/sdk/avatar.d.ts +6 -2
  36. package/kits/base/sdk/avatar.js +12 -4
  37. package/kits/base/sdk/castle.d.ts +1 -1
  38. package/kits/base/sdk/commands.d.ts +14 -0
  39. package/kits/base/sdk/hub.d.ts +6 -2
  40. package/kits/base/sdk/hub.js +13 -0
  41. package/kits/base/sdk/multiplayer.js +17 -1
  42. package/kits/base/sdk/save.js +2 -1
  43. package/kits/base/sdk/server/hub.d.ts +87 -0
  44. package/kits/base/sdk/server/hub.js +70 -0
  45. package/kits/base/sdk/server/platformHandle.d.ts +31 -1
  46. package/kits/base/sdk/server/storage.d.ts +13 -0
  47. package/kits/base/sdk/server/storage.js +46 -0
  48. package/kits/base/sdk/server/wrapper.d.ts +36 -5
  49. package/kits/base/sdk/server/wrapper.js +83 -8
  50. package/kits/hub-game/CLAUDE.md +329 -11
  51. package/kits/hub-game/blueprints/avatar-10.scene +28 -0
  52. package/kits/hub-game/blueprints/avatar-11.scene +28 -0
  53. package/kits/hub-game/blueprints/avatar-12.scene +28 -0
  54. package/kits/hub-game/blueprints/avatar-13.scene +28 -0
  55. package/kits/hub-game/blueprints/avatar-14.scene +28 -0
  56. package/kits/hub-game/blueprints/avatar-15.scene +28 -0
  57. package/kits/hub-game/blueprints/avatar-4.scene +28 -0
  58. package/kits/hub-game/blueprints/avatar-5.scene +28 -0
  59. package/kits/hub-game/blueprints/avatar-6.scene +28 -0
  60. package/kits/hub-game/blueprints/avatar-7.scene +28 -0
  61. package/kits/hub-game/blueprints/avatar-8.scene +28 -0
  62. package/kits/hub-game/blueprints/avatar-9.scene +28 -0
  63. package/kits/hub-game/code/client/actorBudget.js +47 -0
  64. package/kits/hub-game/code/client/attention.js +11 -2
  65. package/kits/hub-game/code/client/avatar.js +309 -35
  66. package/kits/hub-game/code/client/avatarCap.js +228 -0
  67. package/kits/hub-game/code/client/avatarColors.js +70 -0
  68. package/kits/hub-game/code/client/avatarFaces.js +21 -0
  69. package/kits/hub-game/code/client/avatarShare.js +251 -0
  70. package/kits/hub-game/code/client/ballot.js +467 -0
  71. package/kits/hub-game/code/client/build.js +22 -0
  72. package/kits/hub-game/code/client/chrome.js +1144 -50
  73. package/kits/hub-game/code/client/companion.js +716 -0
  74. package/kits/hub-game/code/client/companionDress.js +99 -0
  75. package/kits/hub-game/code/client/decor.js +509 -0
  76. package/kits/hub-game/code/client/earned.js +131 -0
  77. package/kits/hub-game/code/client/emoteBubble.js +75 -0
  78. package/kits/hub-game/code/client/grab.js +339 -20
  79. package/kits/hub-game/code/client/hookLayer.js +299 -13
  80. package/kits/hub-game/code/client/idle.js +163 -22
  81. package/kits/hub-game/code/client/interestCap.js +81 -0
  82. package/kits/hub-game/code/client/keys.js +36 -0
  83. package/kits/hub-game/code/client/labelsNear.js +205 -0
  84. package/kits/hub-game/code/client/menuIcons.js +34 -0
  85. package/kits/hub-game/code/client/pack.js +6 -2
  86. package/kits/hub-game/code/client/packFormat.js +3 -3
  87. package/kits/hub-game/code/client/rehello.js +167 -0
  88. package/kits/hub-game/code/client/shot.js +92 -0
  89. package/kits/hub-game/code/client/sound.js +63 -8
  90. package/kits/hub-game/code/client/soundscape.js +1151 -0
  91. package/kits/hub-game/code/client/soundscapeActions.js +99 -0
  92. package/kits/hub-game/code/client/soundscapeAmbience.js +453 -0
  93. package/kits/hub-game/code/client/soundscapeBaked.js +143 -0
  94. package/kits/hub-game/code/client/soundscapeBusker.js +217 -0
  95. package/kits/hub-game/code/client/soundscapeCourt.js +200 -0
  96. package/kits/hub-game/code/client/soundscapeCrowd.js +331 -0
  97. package/kits/hub-game/code/client/soundscapeCues.js +362 -0
  98. package/kits/hub-game/code/client/soundscapeMap.js +181 -0
  99. package/kits/hub-game/code/client/soundscapeMarket.js +176 -0
  100. package/kits/hub-game/code/client/soundscapeMusic.js +126 -0
  101. package/kits/hub-game/code/client/soundscapeMusicEngine.js +460 -0
  102. package/kits/hub-game/code/client/soundscapeSimlish.js +737 -0
  103. package/kits/hub-game/code/client/soundscapeSongs.js +127 -0
  104. package/kits/hub-game/code/client/soundscapeSongsRound3.js +63 -0
  105. package/kits/hub-game/code/client/soundscapeSynthesis.js +168 -0
  106. package/kits/hub-game/code/client/soundscapeUi.js +211 -0
  107. package/kits/hub-game/code/client/soundscapeVoice.js +1209 -0
  108. package/kits/hub-game/code/client/soundscapeWaves.js +206 -0
  109. package/kits/hub-game/code/client/spin.js +101 -0
  110. package/kits/hub-game/code/client/state.js +109 -1
  111. package/kits/hub-game/code/client/stuck.js +259 -0
  112. package/kits/hub-game/code/client/talk.js +538 -47
  113. package/kits/hub-game/code/client/tiers.js +516 -27
  114. package/kits/hub-game/code/client/toastBand.js +37 -0
  115. package/kits/hub-game/code/client/together.js +32 -0
  116. package/kits/hub-game/code/client/visibility.js +43 -0
  117. package/kits/hub-game/code/client/wear.js +461 -170
  118. package/kits/hub-game/code/client/yours.js +199 -0
  119. package/kits/hub-game/code/companionSpec.js +45 -0
  120. package/kits/hub-game/code/privateText.js +7 -0
  121. package/kits/hub-game/code/server/actions.js +133 -0
  122. package/kits/hub-game/code/server/actors.js +9 -1
  123. package/kits/hub-game/code/server/ask.js +155 -0
  124. package/kits/hub-game/code/server/ballot.js +539 -0
  125. package/kits/hub-game/code/server/cells.js +100 -0
  126. package/kits/hub-game/code/server/companion.js +82 -0
  127. package/kits/hub-game/code/server/cues.js +70 -0
  128. package/kits/hub-game/code/server/decor.js +269 -0
  129. package/kits/hub-game/code/server/earned.js +461 -0
  130. package/kits/hub-game/code/server/friendBests.js +166 -0
  131. package/kits/hub-game/code/server/friendsAmong.js +232 -0
  132. package/kits/hub-game/code/server/history.js +5 -0
  133. package/kits/hub-game/code/server/hub.js +1254 -50
  134. package/kits/hub-game/code/server/idle.js +30 -11
  135. package/kits/hub-game/code/server/index.js +2 -2
  136. package/kits/hub-game/code/server/labels.js +28 -2
  137. package/kits/hub-game/code/server/manifest.js +378 -7
  138. package/kits/hub-game/code/server/menu.js +133 -0
  139. package/kits/hub-game/code/server/npcs.js +830 -80
  140. package/kits/hub-game/code/server/party.js +2 -2
  141. package/kits/hub-game/code/server/players.js +22 -0
  142. package/kits/hub-game/code/server/shot.js +110 -0
  143. package/kits/hub-game/code/server/standing.js +124 -0
  144. package/kits/hub-game/code/server/vis.js +113 -0
  145. package/kits/hub-game/code/server/wear.js +12 -0
  146. package/kits/hub-game/code/server/yours.js +59 -0
  147. package/kits/hub-game/code/shared/cues.js +9 -0
  148. package/kits/hub-game/code/shared/decor.js +41 -0
  149. package/kits/hub-game/code/shared/shot.js +19 -0
  150. package/kits/hub-game/code/shared/spin.js +57 -0
  151. package/kits/hub-game/code/systems/hub.js +845 -95
  152. package/kits/hub-game/docs/content-pack.md +1 -1
  153. package/kits/hub-game/docs/contract.md +2244 -61
  154. package/kits/hub-game/docs/home-pieces.md +64 -0
  155. package/kits/hub-game/models/avatar-10.pxmodel +28 -0
  156. package/kits/hub-game/models/avatar-11.pxmodel +28 -0
  157. package/kits/hub-game/models/avatar-12.pxmodel +27 -0
  158. package/kits/hub-game/models/avatar-13.pxmodel +24 -0
  159. package/kits/hub-game/models/avatar-14.pxmodel +29 -0
  160. package/kits/hub-game/models/avatar-15.pxmodel +24 -0
  161. package/kits/hub-game/models/avatar-4.pxmodel +29 -0
  162. package/kits/hub-game/models/avatar-5.pxmodel +27 -0
  163. package/kits/hub-game/models/avatar-6.pxmodel +26 -0
  164. package/kits/hub-game/models/avatar-7.pxmodel +25 -0
  165. package/kits/hub-game/models/avatar-8.pxmodel +24 -0
  166. package/kits/hub-game/models/avatar-9.pxmodel +30 -0
  167. package/kits/hub-game/models/earned/badge-round.pxmodel +100 -0
  168. package/kits/hub-game/models/earned/badge-shield.pxmodel +117 -0
  169. package/kits/hub-game/models/earned/badge-star.pxmodel +87 -0
  170. package/kits/hub-game/models/earned/belt-plain.pxmodel +72 -0
  171. package/kits/hub-game/models/earned/held-ball.pxmodel +43 -0
  172. package/kits/hub-game/models/earned/held-lantern.pxmodel +85 -0
  173. package/kits/hub-game/models/earned/held-net.pxmodel +57 -0
  174. package/kits/hub-game/models/earned/held-trophy.pxmodel +109 -0
  175. package/kits/hub-game/models/earned/pin-round.pxmodel +62 -0
  176. package/kits/hub-game/models/earned/sash-plain.pxmodel +66 -0
  177. package/kits/hub-game/models/earned/square/belt-plain.pxmodel +104 -0
  178. package/kits/hub-game/models/earned/square/sash-plain.pxmodel +98 -0
  179. package/kits/hub-game/models/hats/bat-clip.pxmodel +206 -0
  180. package/kits/hub-game/models/hats/beekeeper.pxmodel +149 -0
  181. package/kits/hub-game/models/hats/cap.pxmodel +162 -0
  182. package/kits/hub-game/models/hats/captain.pxmodel +178 -0
  183. package/kits/hub-game/models/hats/crooked-top.pxmodel +172 -0
  184. package/kits/hub-game/models/hats/flower-crown.pxmodel +451 -0
  185. package/kits/hub-game/models/hats/foam-crown.pxmodel +179 -0
  186. package/kits/hub-game/models/hats/lantern.pxmodel +230 -0
  187. package/kits/hub-game/models/hats/laurel.pxmodel +533 -0
  188. package/kits/hub-game/models/hats/lighthouse.pxmodel +96 -0
  189. package/kits/hub-game/models/hats/sailor.pxmodel +141 -0
  190. package/kits/hub-game/models/hats/souwester.pxmodel +131 -0
  191. package/kits/hub-game/models/hats/straw.pxmodel +139 -0
  192. package/kits/hub-game/models/hats/sunflower.pxmodel +406 -0
  193. package/kits/hub-game/models/hats/sweatband.pxmodel +112 -0
  194. package/kits/hub-game/models/hats/witch.pxmodel +147 -0
  195. package/kits/hub-game/package-lock.json +2 -0
  196. package/kits/hub-game/package.json +2 -1
  197. package/kits/hub-game/scripts/check.mjs +78 -11
  198. package/kits/hub-game/scripts/companion-follower-wire.json +1 -0
  199. package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +121 -0
  200. package/kits/hub-game/scripts/fixtures/decor-keyless.json +293 -0
  201. package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +23 -0
  202. package/kits/hub-game/scripts/fixtures/fake-dom.mjs +107 -0
  203. package/kits/hub-game/scripts/fixtures/interest-legacy.json +385 -0
  204. package/kits/hub-game/scripts/fixtures/npc-notes-v1.77.jsonl +4 -0
  205. package/kits/hub-game/scripts/fixtures/vis-shared-wire.json +1 -0
  206. package/kits/hub-game/scripts/gen-avatars.mjs +933 -16
  207. package/kits/hub-game/scripts/gen-earned.mjs +285 -0
  208. package/kits/hub-game/scripts/gen-hats.mjs +827 -0
  209. package/kits/hub-game/scripts/grab.before-orbit.mjs +400 -0
  210. package/kits/hub-game/scripts/soundscape-wave-analysis.mjs +125 -0
  211. package/kits/hub-game/scripts/test-actions-client.mjs +488 -0
  212. package/kits/hub-game/scripts/test-actions.mjs +298 -0
  213. package/kits/hub-game/scripts/test-actor-budget.mjs +44 -0
  214. package/kits/hub-game/scripts/test-actors.mjs +19 -17
  215. package/kits/hub-game/scripts/test-ask-client.mjs +358 -0
  216. package/kits/hub-game/scripts/test-ask.mjs +269 -0
  217. package/kits/hub-game/scripts/test-attention.mjs +10 -1
  218. package/kits/hub-game/scripts/test-avatar-cap.mjs +379 -0
  219. package/kits/hub-game/scripts/test-avatar-colors.mjs +72 -0
  220. package/kits/hub-game/scripts/test-avatar-models.mjs +181 -0
  221. package/kits/hub-game/scripts/test-avatar-share.mjs +318 -0
  222. package/kits/hub-game/scripts/test-avatar-wire.mjs +753 -0
  223. package/kits/hub-game/scripts/test-avatar.mjs +540 -7
  224. package/kits/hub-game/scripts/test-ballot.mjs +1001 -0
  225. package/kits/hub-game/scripts/test-build.mjs +31 -0
  226. package/kits/hub-game/scripts/test-cells.mjs +71 -0
  227. package/kits/hub-game/scripts/test-chat.mjs +662 -0
  228. package/kits/hub-game/scripts/test-classic.mjs +2 -0
  229. package/kits/hub-game/scripts/test-companion-chat.mjs +198 -0
  230. package/kits/hub-game/scripts/test-companion-client.mjs +1167 -0
  231. package/kits/hub-game/scripts/test-companion.mjs +259 -0
  232. package/kits/hub-game/scripts/test-decor-client.mjs +303 -0
  233. package/kits/hub-game/scripts/test-decor.mjs +457 -0
  234. package/kits/hub-game/scripts/test-earned-client.mjs +459 -0
  235. package/kits/hub-game/scripts/test-earned.mjs +1194 -0
  236. package/kits/hub-game/scripts/test-emote-bubble.mjs +110 -0
  237. package/kits/hub-game/scripts/test-friend-bests.mjs +435 -0
  238. package/kits/hub-game/scripts/test-grab-orbit.mjs +918 -0
  239. package/kits/hub-game/scripts/test-grab.mjs +7 -0
  240. package/kits/hub-game/scripts/test-hats.mjs +422 -168
  241. package/kits/hub-game/scripts/test-hub-leaving.mjs +203 -0
  242. package/kits/hub-game/scripts/test-hub-ops.mjs +439 -2
  243. package/kits/hub-game/scripts/test-hub-trip.mjs +716 -2
  244. package/kits/hub-game/scripts/test-hud-clear.mjs +328 -4
  245. package/kits/hub-game/scripts/test-idle.mjs +361 -1
  246. package/kits/hub-game/scripts/test-interest-cap.mjs +36 -0
  247. package/kits/hub-game/scripts/test-interest-cells.mjs +493 -0
  248. package/kits/hub-game/scripts/test-interest-client.mjs +118 -0
  249. package/kits/hub-game/scripts/test-keys.mjs +46 -1
  250. package/kits/hub-game/scripts/test-labels.mjs +596 -0
  251. package/kits/hub-game/scripts/test-manifest.mjs +207 -0
  252. package/kits/hub-game/scripts/test-menu-client.mjs +480 -0
  253. package/kits/hub-game/scripts/test-menu.mjs +296 -0
  254. package/kits/hub-game/scripts/test-npcs.mjs +1718 -12
  255. package/kits/hub-game/scripts/test-object-entry.mjs +76 -0
  256. package/kits/hub-game/scripts/test-pack.mjs +7 -0
  257. package/kits/hub-game/scripts/test-picker.mjs +314 -0
  258. package/kits/hub-game/scripts/test-rehello.mjs +1039 -0
  259. package/kits/hub-game/scripts/test-relations-among.mjs +222 -0
  260. package/kits/hub-game/scripts/test-relations-refresh.mjs +188 -0
  261. package/kits/hub-game/scripts/test-shot.mjs +756 -0
  262. package/kits/hub-game/scripts/test-soundscape.mjs +5432 -0
  263. package/kits/hub-game/scripts/test-spin.mjs +314 -0
  264. package/kits/hub-game/scripts/test-standing.mjs +416 -0
  265. package/kits/hub-game/scripts/test-stuck.mjs +1903 -0
  266. package/kits/hub-game/scripts/test-tier-cells.mjs +706 -0
  267. package/kits/hub-game/scripts/test-tiers-render.mjs +339 -0
  268. package/kits/hub-game/scripts/test-tiers.mjs +477 -2
  269. package/kits/hub-game/scripts/test-toast-band.mjs +61 -0
  270. package/kits/hub-game/scripts/test-try-on.mjs +22 -22
  271. package/kits/hub-game/scripts/test-vis.mjs +343 -0
  272. package/kits/hub-game/scripts/test-visibility.mjs +134 -0
  273. package/kits/hub-game/scripts/test-yours-chrome.mjs +166 -0
  274. package/kits/hub-game/scripts/test-yours.mjs +372 -0
  275. package/kits/multiplayer-3d/CLAUDE.md +50 -0
  276. package/kits/multiplayer-3d/castle.json +5 -5
  277. package/kits/multiplayer-3d/code/client/avatars.js +7 -0
  278. package/kits/multiplayer-3d/code/client/gait.js +65 -0
  279. package/kits/multiplayer-3d/code/client/nameTags.js +59 -4
  280. package/kits/multiplayer-3d/code/options.js +5 -0
  281. package/kits/multiplayer-3d/code/server/ownership.js +10 -2
  282. package/kits/multiplayer-3d/code/server/sceneBodies.js +12 -0
  283. package/kits/multiplayer-3d/code/server/world.js +7 -0
  284. package/kits/multiplayer-3d/code/systems/multiplayer.js +74 -4
  285. package/kits/multiplayer-3d/package.json +2 -1
  286. package/kits/multiplayer-3d/scripts/fixtures/README.md +11 -0
  287. package/kits/multiplayer-3d/scripts/fixtures/ownership-legacy.json +2 -0
  288. package/kits/multiplayer-3d/scripts/ownership-harness.mjs +102 -0
  289. package/kits/multiplayer-3d/scripts/ownership-loader.mjs +46 -0
  290. package/kits/multiplayer-3d/scripts/ownership-worker.mjs +15 -0
  291. package/kits/multiplayer-3d/scripts/record-ownership-session.mjs +98 -0
  292. package/kits/multiplayer-3d/scripts/test-eligible-claims.mjs +167 -0
  293. package/kits/multiplayer-3d/scripts/test-own-name-tag.mjs +247 -0
  294. package/kits/physics-2d/CLAUDE.md +9 -0
  295. package/kits/physics-2d/castle.json +2 -2
  296. package/kits/physics-2d/engine/scene.js +253 -1
  297. package/kits/physics-2d/engine/skyKey.js +129 -0
  298. package/kits/physics-2d/engine/stillClock.js +106 -0
  299. package/kits/physics-2d/engine/updateBudget.js +21 -0
  300. package/kits/physics-2d/scripts/test-skip-unchanged.mjs +326 -1
  301. package/kits/physics-3d/CLAUDE.md +1169 -30
  302. package/kits/physics-3d/behaviors/Player.jsx +629 -72
  303. package/kits/physics-3d/castle.json +3 -3
  304. package/kits/physics-3d/docs/pxmodel-format.md +8 -0
  305. package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +69 -13
  306. package/kits/physics-3d/engine3d/actornode.js +86 -0
  307. package/kits/physics-3d/engine3d/animationBudget.js +23 -0
  308. package/kits/physics-3d/engine3d/editorWorld.js +6 -0
  309. package/kits/physics-3d/engine3d/emptynodes.js +232 -0
  310. package/kits/physics-3d/engine3d/framecap.js +96 -0
  311. package/kits/physics-3d/engine3d/gait.js +118 -0
  312. package/kits/physics-3d/engine3d/kithooks.js +47 -0
  313. package/kits/physics-3d/engine3d/look.js +507 -48
  314. package/kits/physics-3d/engine3d/lookbake.js +208 -0
  315. package/kits/physics-3d/engine3d/materialpresets.js +2 -0
  316. package/kits/physics-3d/engine3d/motion.js +39 -10
  317. package/kits/physics-3d/engine3d/nearshadows.js +37 -19
  318. package/kits/physics-3d/engine3d/optimize.js +9 -5
  319. package/kits/physics-3d/engine3d/orbitinput.js +487 -9
  320. package/kits/physics-3d/engine3d/orbitlens.js +48 -0
  321. package/kits/physics-3d/engine3d/ownmodel.js +213 -0
  322. package/kits/physics-3d/engine3d/pxmodel.js +42 -11
  323. package/kits/physics-3d/engine3d/shadowfade.js +882 -0
  324. package/kits/physics-3d/engine3d/sky.js +547 -0
  325. package/kits/physics-3d/engine3d/skylife.js +306 -0
  326. package/kits/physics-3d/engine3d/unchanged.js +11 -0
  327. package/kits/physics-3d/engine3d/viewrange.js +52 -0
  328. package/kits/physics-3d/engine3d/world3d.js +796 -69
  329. package/kits/physics-3d/main.jsx +5 -0
  330. package/kits/physics-3d/package.json +1 -1
  331. package/kits/physics-3d/scripts/look-baseline.mjs +155 -0
  332. package/kits/physics-3d/scripts/test-camera-orbit.mjs +2563 -80
  333. package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +1 -1
  334. package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +435 -0
  335. package/kits/physics-3d/scripts/test-frame-cap.mjs +452 -0
  336. package/kits/physics-3d/scripts/test-gait.mjs +387 -0
  337. package/kits/physics-3d/scripts/test-look-bake.mjs +1056 -0
  338. package/kits/physics-3d/scripts/test-model-parse-cache.mjs +92 -0
  339. package/kits/physics-3d/scripts/test-near-shadows.mjs +3 -0
  340. package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1920 -0
  341. package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +545 -0
  342. package/kits/physics-3d/scripts/test-orbit-shot.mjs +583 -0
  343. package/kits/physics-3d/scripts/test-orbit-view.mjs +230 -0
  344. package/kits/physics-3d/scripts/test-skip-empty-nodes.mjs +845 -0
  345. package/kits/physics-3d/scripts/test-sky.mjs +2470 -0
  346. package/kits/physics-3d/scripts/test-static-actors.mjs +8 -1
  347. package/kits/physics-3d/scripts/test-static-scenery.mjs +2171 -0
  348. package/kits/physics-3d/scripts/test-steady-hover.mjs +2 -0
  349. package/kits/physics-3d/scripts/test-view-range.mjs +260 -0
  350. package/kits/physics-3d/systems/physics3d.js +383 -6
  351. package/kits/real-time/castle.json +2 -2
  352. package/kits/real-time/code/server/gameHooks.js +7 -0
  353. package/kits/real-time/code/server/session.js +97 -19
  354. package/package.json +2 -2
  355. package/dist/shell/assets/index-Cf61cNfT.css +0 -1
@@ -0,0 +1,203 @@
1
+ // Leaving lines (contract v1.52): private, latched, absent from snapshots.
2
+ import assert from 'node:assert/strict';
3
+ import { register } from 'node:module';
4
+
5
+ const sceneStub = 'export const readScene = () => globalThis.__hubTestActors ?? [];';
6
+ const avatarsStub = 'export function dropMissing() {}';
7
+ register(
8
+ `data:text/javascript,${encodeURIComponent(`
9
+ import { readFile } from 'node:fs/promises';
10
+ import { fileURLToPath } from 'node:url';
11
+ const stubs = {
12
+ '@imports/castle.multiplayer-3d/code/server/sceneBodies.js': 'data:text/javascript,${encodeURIComponent(sceneStub)}',
13
+ '@imports/castle.multiplayer-3d/code/client/avatars.js': 'data:text/javascript,${encodeURIComponent(avatarsStub)}',
14
+ 'castle-web-sdk': ${JSON.stringify(new URL('./fixtures/sdk-stub.mjs', import.meta.url).href)},
15
+ };
16
+ export async function resolve(specifier, context, next) {
17
+ 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 };
18
+ 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 };
19
+ if (stubs[specifier]) {
20
+ return { url: stubs[specifier], shortCircuit: true };
21
+ }
22
+ return next(specifier, context);
23
+ }
24
+ // The hook layer reads the deck's castle.json through the bundler.
25
+ export async function load(url, context, next) {
26
+ if (url.endsWith('/code/client/hookLayer.js')) {
27
+ const source = await readFile(fileURLToPath(url), 'utf8');
28
+ return { format: 'module', source: source.replaceAll('import.meta.glob(', '(() => ({}))('), shortCircuit: true };
29
+ }
30
+ return next(url, context);
31
+ }
32
+ `)}`,
33
+ );
34
+
35
+ const { layer } = await import('../code/server/hub.js');
36
+ const hook = (await import('../code/client/hookLayer.js')).default;
37
+ const State = await import('../code/client/state.js');
38
+
39
+ globalThis.__hubTestActors = [
40
+ { id: 'spawn', components: { Player: {}, Transform: { x: 0, y: 1, z: 0 } } },
41
+ ];
42
+ function boot(hooks = {}) {
43
+ const sent = [];
44
+ const players = [{ playerId: 'p1', username: 'ada' }, { playerId: 'p2', username: 'bo' }];
45
+ const session = { sessionId: 'test', players, send: (id, msg) => sent.push([id, msg]), broadcast() {} };
46
+ const world = { timeMs: 0, players: new Map(players.map(({ playerId }) => [playerId,
47
+ { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } }])),
48
+ bodies: new Map(), scenePath: 'scenes/main.scene' };
49
+ let hub;
50
+ const server = layer({ server: { maxPlayers: 8 }, hub: { contract: 1, title: 'Town' } },
51
+ { ready(ctx) { hub = ctx; }, ...hooks }, {}, () => true);
52
+ server.sceneFor(session);
53
+ server.ready(world);
54
+ const hello = (id, extra = {}) => server.message(session, { playerId: id }, { k: 'hub-hello', avatar: 1, ...extra });
55
+ const step = () => { server.place(world); server.step(world); };
56
+ return { server, world, session, sent, hub, hello, step };
57
+ }
58
+
59
+ let n = 0;
60
+ function test(name, fn) {
61
+ fn();
62
+ n += 1;
63
+ console.log(`ok: ${name}`);
64
+ }
65
+ const leaving = (r) => r.sent.filter(([, msg]) => msg.k === 'hub-leaving');
66
+ const noSnapshotField = (snapshot) => assert.ok(Object.keys(snapshot ?? {}).every((key) => !/leaving/i.test(key)));
67
+
68
+ test('friends wanted is latched privately by the client and cleared on a session switch', () => {
69
+ State.clear();
70
+ assert.equal(State.hub.friendsWanted, false);
71
+ hook.message({ files: {} }, { k: 'hub-friends-wanted' });
72
+ assert.equal(State.hub.friendsWanted, true);
73
+ hook.message({ files: {} }, { k: 'hub-friends-wanted' });
74
+ assert.equal(State.hub.friendsWanted, true);
75
+ State.clear();
76
+ assert.equal(State.hub.friendsWanted, false);
77
+ });
78
+
79
+ test('a place that never calls leaving has no traffic or snapshot field, even for later joins', () => {
80
+ const r = boot();
81
+ const before = r.server.join();
82
+ r.hello('p1');
83
+ r.step();
84
+ noSnapshotField(r.server.join());
85
+ noSnapshotField(r.server.delta());
86
+ r.hello('p2');
87
+ r.step();
88
+ noSnapshotField(r.server.join());
89
+ assert.deepEqual(leaving(r), []);
90
+ // A clear on an unused line is accepted and sends nothing either.
91
+ assert.equal(r.hub.leaving('p1', null), true);
92
+ assert.equal(r.hub.leaving('p1', ' '), true);
93
+ noSnapshotField(before);
94
+ assert.deepEqual(leaving(r), []);
95
+ });
96
+
97
+ test('leaving is private, trimmed, cut, latched and replaced; null and empty clear', () => {
98
+ const r = boot();
99
+ r.hello('p1');
100
+ assert.equal(r.hub.leaving('p1', ' Your lantern is waiting '), true);
101
+ assert.equal(r.hub.leaving('p1', 'Your lantern is waiting'), true);
102
+ r.step();
103
+ r.hello('p2');
104
+ r.step();
105
+ assert.deepEqual(leaving(r), [['p1', { k: 'hub-leaving', text: 'Your lantern is waiting' }]]);
106
+ noSnapshotField(r.server.join());
107
+ noSnapshotField(r.server.delta());
108
+ r.hub.leaving('p1', 'x'.repeat(140));
109
+ assert.equal(leaving(r).at(-1)[1].text, 'x'.repeat(120));
110
+ r.hub.leaving('p1', null);
111
+ r.hub.leaving('p1', null);
112
+ assert.equal(leaving(r).length, 3);
113
+ assert.deepEqual(leaving(r).at(-1), ['p1', { k: 'hub-leaving', text: null }]);
114
+ r.hub.leaving('p1', 'Next time');
115
+ r.hub.leaving('p1', ' ');
116
+ assert.equal(leaving(r).length, 5);
117
+ assert.equal(leaving(r).at(-1)[1].text, null);
118
+ });
119
+
120
+ test('invalid leaving arguments warn once per refusal and preserve the previous line', () => {
121
+ const r = boot();
122
+ r.hub.leaving('p1', 'Kept');
123
+ const warnings = [];
124
+ const warn = console.warn;
125
+ console.warn = (text) => warnings.push(text);
126
+ try {
127
+ for (let i = 0; i < 2; i += 1) {
128
+ for (const value of [undefined, 5, {}, []]) assert.equal(r.hub.leaving('p1', value), false);
129
+ for (const id of [undefined, 5, 'missing']) assert.equal(r.hub.leaving(id, 'Ignored'), false);
130
+ }
131
+ } finally { console.warn = warn; }
132
+ assert.equal(warnings.length, 2);
133
+ assert.deepEqual(leaving(r), [['p1', { k: 'hub-leaving', text: 'Kept' }]]);
134
+ });
135
+
136
+ test('fresh hellos replay only that player\'s latch; avatar changes and a new visit get nothing', () => {
137
+ const r = boot();
138
+ r.hello('p1');
139
+ r.step();
140
+ r.hub.leaving('p1', 'Next visit');
141
+ r.hello('p1', { again: true });
142
+ assert.equal(leaving(r).length, 1);
143
+ for (let i = 0; i < 2; i += 1) {
144
+ State.clear(); // A reload/reconnect retains the id, but loses client state.
145
+ assert.equal(State.hub.leaving, null);
146
+ const before = r.sent.length;
147
+ r.hello('p1');
148
+ const replay = r.sent.slice(before).filter(([, msg]) => msg.k === 'hub-leaving');
149
+ assert.deepEqual(replay, [['p1', { k: 'hub-leaving', text: 'Next visit' }]]);
150
+ hook.message({ files: {} }, replay[0][1]);
151
+ assert.equal(State.hub.leaving, 'Next visit');
152
+ r.hub.leaving('p1', 'Next visit');
153
+ assert.equal(leaving(r).length, i + 2, 'identical calls remain suppressed after replay');
154
+ r.hello('p2');
155
+ assert.equal(leaving(r).length, i + 2, 'no replay to another player');
156
+ }
157
+ r.world.players.delete('p1');
158
+ r.session.players = r.session.players.filter((p) => p.playerId !== 'p1');
159
+ r.step();
160
+ r.world.players.set('p1', { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
161
+ r.hello('p1');
162
+ r.step();
163
+ assert.equal(leaving(r).length, 3);
164
+ State.clear();
165
+ });
166
+
167
+ test('a cleared leaving latch sends nothing on a fresh hello', () => {
168
+ const r = boot();
169
+ r.hello('p1');
170
+ r.hub.leaving('p1', 'Next visit');
171
+ r.hub.leaving('p1', null);
172
+ const before = leaving(r).length;
173
+ r.hello('p1');
174
+ assert.equal(leaving(r).length, before);
175
+ });
176
+
177
+ test('the real client hook keeps the latest line and clears on null and Hub.clear', () => {
178
+ State.clear();
179
+ assert.equal(State.hub.leaving, null);
180
+ const scene = { files: {} };
181
+ hook.message(scene, { k: 'hub-leaving', text: 'Next visit' });
182
+ assert.equal(State.hub.leaving, 'Next visit');
183
+ hook.message(scene, { k: 'hub-leaving', text: 'Replaced' });
184
+ assert.equal(State.hub.leaving, 'Replaced');
185
+ hook.message(scene, { k: 'hub-leaving', text: null });
186
+ assert.equal(State.hub.leaving, null);
187
+ hook.message(scene, { k: 'hub-leaving', text: 'Again' });
188
+ State.clear();
189
+ assert.equal(State.hub.leaving, null);
190
+ });
191
+ test('the line is delivered before an immediate end, and a call before hello is forgotten on disconnect', () => {
192
+ const r = boot();
193
+ r.hub.leaving('p1', 'Next time');
194
+ r.hub.end(['p1']);
195
+ assert.deepEqual(r.sent.filter(([, msg]) => ['hub-leaving', 'hub-end'].includes(msg.k)).map(([, msg]) => msg.k), ['hub-leaving', 'hub-end']);
196
+ r.world.players.delete('p1');
197
+ r.session.players = r.session.players.filter((p) => p.playerId !== 'p1');
198
+ r.step();
199
+ r.world.players.set('p1', { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
200
+ assert.equal(r.hub.leaving('p1', 'Next time'), true);
201
+ assert.equal(leaving(r).length, 2, 'a new visit stores and sends the same words anew');
202
+ });
203
+ console.log(`hub leaving: ${n} tests passed`);
@@ -102,7 +102,7 @@ function platformHub(answers = {}) {
102
102
  };
103
103
  }
104
104
 
105
- function boot(s, hooks = {}) {
105
+ function boot(s, hooks = {}, json = castleJson) {
106
106
  let ctx = null;
107
107
  const arrived = [];
108
108
  const deck = {
@@ -114,7 +114,7 @@ function boot(s, hooks = {}) {
114
114
  },
115
115
  ...hooks,
116
116
  };
117
- const h = layer(castleJson, deck, {}, sceneExists);
117
+ const h = layer(json, deck, {}, sceneExists);
118
118
  h.sceneFor(s.session);
119
119
  const world = sim();
120
120
  h.ready(world);
@@ -263,6 +263,268 @@ await test("a board that leaves the group unsaid keeps the door's props", async
263
263
  }
264
264
  });
265
265
 
266
+ await test("a 46-door place reads every board, including the 17th door's event and group", async () => {
267
+ const actors = globalThis.__hubTestActors;
268
+ const ids = Array.from({ length: 46 }, (_, i) => `game-${i}`);
269
+ const event = { open: true };
270
+ const boards = Object.fromEntries(ids.map((id, i) => [id, {
271
+ title: `Game ${i}`, minPlayers: 1, maxPlayers: 8, lateJoin: true, top: [],
272
+ ...(i === 16 ? { event } : {}),
273
+ }]));
274
+ globalThis.__hubTestActors = [actors[0], ...ids.map((id, i) => ({
275
+ id: `${id}-door`,
276
+ components: {
277
+ HubDoor: { id, to: `deck:${id}`, title: i === 16 ? 'Foot Race' : id, minPlayers: 2, lateJoin: false },
278
+ Transform: { x: 5, y: 0, z: 5 },
279
+ },
280
+ }))];
281
+ try {
282
+ const p = platformHub({ read: (input) => ({
283
+ players: {}, boards: Object.fromEntries((input.doorIds ?? []).map((id) => [id, boards[id]])),
284
+ }) });
285
+ const s = session({ hub: p.hub });
286
+ const { h, world, ctx } = boot(s);
287
+ const race = ctx().doors()[16];
288
+ assert.deepEqual(
289
+ { title: race.title, minPlayers: race.minPlayers, lateJoin: race.lateJoin },
290
+ { title: 'Foot Race', minPlayers: 2, lateJoin: false },
291
+ );
292
+ h.place(world);
293
+ await flush();
294
+ const reads = p.calls.filter(([k]) => k === 'read').map(([, input]) => input.doorIds);
295
+ assert.deepEqual(reads.map((doorIds) => doorIds.length), [16, 16, 14]);
296
+ assert.deepEqual(reads.flat(), ids);
297
+ assert.deepEqual(ctx().doors().map((door) => ({
298
+ id: door.id, title: door.title, minPlayers: door.minPlayers, maxPlayers: door.maxPlayers, lateJoin: door.lateJoin,
299
+ })), ids.map((id, i) => ({
300
+ id, title: `Game ${i}`, minPlayers: 1, maxPlayers: 8, lateJoin: true,
301
+ })));
302
+ assert.deepEqual(
303
+ { minPlayers: race.minPlayers, lateJoin: race.lateJoin },
304
+ { minPlayers: 1, lateJoin: true },
305
+ );
306
+ assert.deepEqual(ctx().board(ids[16]).event, event);
307
+ assert.equal(h.join().hubDoors.find((door) => door.id === ids[16]).title, 'Event · Game 16');
308
+ } finally {
309
+ globalThis.__hubTestActors = actors;
310
+ }
311
+ });
312
+
313
+ await test('a small place keeps the same board read inputs, doors before cabinets', async () => {
314
+ const actors = globalThis.__hubTestActors;
315
+ const ids = ['race', 'cab-a', 'hill', 'tag', 'cab-b', 'maze', 'ball'];
316
+ globalThis.__hubTestActors = [actors[0], ...ids.map((id) => ({
317
+ id: `${id}-door`,
318
+ components: {
319
+ HubDoor: { id, to: `deck:${id}`, ...(id.startsWith('cab-') ? { kind: 'cabinet' } : {}) },
320
+ Transform: { x: 5, y: 0, z: 5 },
321
+ },
322
+ }))];
323
+ try {
324
+ const p = platformHub();
325
+ const s = session({ hub: p.hub });
326
+ const { h, world } = boot(s);
327
+ h.place(world);
328
+ await flush();
329
+ assert.deepEqual(p.calls.filter(([k]) => k === 'read').map(([, input]) => input), [
330
+ { doorIds: ['race', 'hill', 'tag', 'maze', 'ball'] },
331
+ { doorIds: ['cab-a', 'cab-b'] },
332
+ ]);
333
+ } finally {
334
+ globalThis.__hubTestActors = actors;
335
+ }
336
+ });
337
+
338
+ await test('a place reads every cabinet board, six cabinets per read', async () => {
339
+ const actors = globalThis.__hubTestActors;
340
+ const ids = Array.from({ length: 17 }, (_, i) => `cab-${i}`);
341
+ globalThis.__hubTestActors = [actors[0], ...ids.map((id) => ({
342
+ id: `${id}-door`,
343
+ components: { HubDoor: { id, to: 'deck:classic', kind: 'cabinet' }, Transform: { x: 5, y: 0, z: 5 } },
344
+ }))];
345
+ try {
346
+ const p = platformHub({ read: (input) => ({
347
+ players: {}, boards: Object.fromEntries((input.doorIds ?? []).map((id) => [id, { title: id, top: [] }])),
348
+ }) });
349
+ const s = session({ hub: p.hub });
350
+ const { h, world, ctx } = boot(s);
351
+ h.place(world);
352
+ await flush();
353
+ const reads = p.calls.filter(([k]) => k === 'read').map(([, input]) => input.doorIds);
354
+ assert.deepEqual(reads.map((doorIds) => doorIds.length), [6, 6, 5]);
355
+ assert.deepEqual(reads.flat(), ids);
356
+ assert.deepEqual(ctx().doors().map((door) => door.title), ids);
357
+ } finally {
358
+ globalThis.__hubTestActors = actors;
359
+ }
360
+ });
361
+
362
+ await test('board batches run one at a time, even when a scan takes more than a minute', async () => {
363
+ const actors = globalThis.__hubTestActors;
364
+ const realNow = Date.now;
365
+ const doorIds = Array.from({ length: 46 }, (_, i) => `game-${i}`);
366
+ const cabinetIds = Array.from({ length: 31 }, (_, i) => `cab-${i}`);
367
+ const ids = [...doorIds, ...cabinetIds];
368
+ globalThis.__hubTestActors = [actors[0], ...ids.map((id) => ({
369
+ id: `${id}-door`,
370
+ components: {
371
+ HubDoor: { id, to: `deck:${id}`, ...(id.startsWith('cab-') ? { kind: 'cabinet' } : {}) },
372
+ Transform: { x: 5, y: 0, z: 5 },
373
+ },
374
+ }))];
375
+ let inFlight = 0;
376
+ let mostInFlight = 0;
377
+ const pending = [];
378
+ try {
379
+ const p = platformHub({ read: () => new Promise((resolve) => {
380
+ inFlight += 1;
381
+ mostInFlight = Math.max(mostInFlight, inFlight);
382
+ pending.push(() => {
383
+ inFlight -= 1;
384
+ resolve({ players: {}, boards: {} });
385
+ });
386
+ }) });
387
+ const s = session({ hub: p.hub });
388
+ const { h, world } = boot(s);
389
+ h.place(world);
390
+ await flush();
391
+ assert.equal(p.calls.length, 1, 'only the first batch starts before it settles');
392
+ Date.now = () => realNow() + 61000;
393
+ h.place(world);
394
+ await flush();
395
+ assert.equal(p.calls.length, 1, 'a new minute does not overlap the unfinished scan');
396
+ for (let i = 0; i < 9; i += 1) {
397
+ assert.equal(p.calls.length, i + 1);
398
+ assert.equal(inFlight, 1);
399
+ pending.shift()();
400
+ await flush();
401
+ }
402
+ assert.equal(mostInFlight, 1);
403
+ assert.equal(inFlight, 0);
404
+ const reads = p.calls.map(([, input]) => input.doorIds);
405
+ assert.deepEqual(reads.map((batch) => batch.length), [16, 16, 14, 6, 6, 6, 6, 6, 1]);
406
+ assert.deepEqual(reads.flat(), ids);
407
+ } finally {
408
+ Date.now = realNow;
409
+ globalThis.__hubTestActors = actors;
410
+ }
411
+ });
412
+
413
+ await test('a failed board chunk keeps its previous rows while other chunks and cabinet cards refresh', async () => {
414
+ const actors = globalThis.__hubTestActors;
415
+ const realNow = Date.now;
416
+ const warn = console.warn;
417
+ const warnings = [];
418
+ console.warn = (message) => warnings.push(message);
419
+ let now = realNow();
420
+ Date.now = () => now;
421
+ const ids = [...Array.from({ length: 46 }, (_, i) => `game-${i}`), 'cab-a'];
422
+ globalThis.__hubTestActors = [actors[0], ...ids.map((id) => ({
423
+ id: `${id}-door`,
424
+ components: {
425
+ HubDoor: { id, to: `deck:${id}`, title: id, ...(id === 'cab-a' ? { kind: 'cabinet' } : {}) },
426
+ Transform: { x: 5, y: 0, z: 5 },
427
+ },
428
+ }))];
429
+ let refresh = false;
430
+ try {
431
+ const p = platformHub({ read: (input) => {
432
+ if (!input.doorIds) {
433
+ return { players: {}, boards: {} };
434
+ }
435
+ if (refresh && input.doorIds.includes('game-20')) {
436
+ throw Object.assign(new Error('middle chunk failed'), { code: 'CAULDRON_STORAGE_TIMEOUT' });
437
+ }
438
+ const prefix = refresh ? 'New' : 'Old';
439
+ return { players: {}, boards: Object.fromEntries(input.doorIds
440
+ .filter((id) => !refresh || id !== 'game-2')
441
+ .map((id) => [id, {
442
+ title: `${prefix} ${id}`, minPlayers: 1, lateJoin: true, top: [],
443
+ ...(id === 'cab-a' ? { classic: { deckId: 'classic-a', title: `${prefix} cabinet`, label: 'Daily Score', top: [] } } : {}),
444
+ }])) };
445
+ } });
446
+ const s = session({ hub: p.hub });
447
+ const { h, world, ctx } = boot(s);
448
+ hello(h, s, 'p1');
449
+ h.place(world);
450
+ await flush();
451
+ h.place(world);
452
+ h.step(world, []);
453
+ assert.equal(ctx().board('game-20').title, 'Old game-20');
454
+ assert.equal(ctx().board('game-45').title, 'Old game-45');
455
+ assert.equal(s.sent.find(([, msg]) => msg.k === 'hub-cabinet')[1].card.title, 'Old cabinet');
456
+ const previous = ids.slice(16, 32).map((id) => ctx().board(id));
457
+ s.sent.length = 0;
458
+ p.calls.length = 0;
459
+ refresh = true;
460
+ // This actor no longer names a destination, so it leaves doors(h).
461
+ globalThis.__hubTestActors.find((actor) => actor.id === 'game-45-door').components.HubDoor.to = 'removed';
462
+ now += 61000;
463
+ world.timeMs += 61000;
464
+ h.place(world);
465
+ await flush();
466
+ h.step(world, []);
467
+ const reads = p.calls.filter(([, input]) => input.doorIds).map(([, input]) => input.doorIds);
468
+ assert.deepEqual(reads.map((batch) => batch.length), [16, 16, 13, 1]);
469
+ assert.equal(ctx().board('game-0').title, 'New game-0');
470
+ assert.equal(ctx().board('game-32').title, 'New game-32');
471
+ assert.deepEqual(ids.slice(16, 32).map((id) => ctx().board(id)), previous);
472
+ assert.equal(ctx().board('game-2'), null, 'a successful read that omits a row removes the old board');
473
+ assert.equal(ctx().board('game-45'), null, 'a removed door loses its old board');
474
+ assert.equal(s.sent.find(([, msg]) => msg.k === 'hub-cabinet')[1].card.title, 'New cabinet');
475
+ assert.deepEqual(warnings, ['[hub] boards refused (CAULDRON_STORAGE_TIMEOUT): middle chunk failed']);
476
+ h.place(world);
477
+ await flush();
478
+ assert.deepEqual(ids.slice(16, 32).map((id) => ctx().board(id)), previous, 'failed rows survive the next tick');
479
+ assert.equal(p.calls.filter(([, input]) => input.doorIds).length, 4, 'no retry before the next minute');
480
+ } finally {
481
+ console.warn = warn;
482
+ Date.now = realNow;
483
+ globalThis.__hubTestActors = actors;
484
+ }
485
+ });
486
+
487
+ await test('an arrival is kept where it was put while late move reports pull at it (v1.40)', async () => {
488
+ const p = platformHub({ read: () => ({ players: {}, boards: {} }) });
489
+ const s = session({ hub: p.hub });
490
+ const { h, world, arrived, ctx } = boot(s, {
491
+ arrive(hub, group) {
492
+ arrived.push(...group);
493
+ for (const g of group) {
494
+ hub.placeAt(g.playerId, { x: -3.2, y: 1.2, z: -28.67 }, 90);
495
+ }
496
+ },
497
+ });
498
+ hello(h, s, 'p1');
499
+ h.place(world);
500
+ await flush();
501
+ h.place(world);
502
+ assert.equal(arrived.length, 1);
503
+ const body = world.players.get('p1');
504
+ assert.deepEqual([body.at.x, body.at.z], [-3.2, -28.67], 'where the place put them');
505
+ // The client's reports still name the spawn: the movement clamp lets each
506
+ // pull the body a step toward it. The next tick puts it back.
507
+ for (let i = 0; i < 5; i += 1) {
508
+ body.at = { x: body.at.x + 0.1, y: body.at.y, z: body.at.z + 0.9 };
509
+ world.timeMs += 50;
510
+ h.place(world);
511
+ assert.deepEqual([body.at.x, body.at.z], [-3.2, -28.67], `put back on tick ${i}`);
512
+ }
513
+ // Not a hold: a small step is the player's own, and after the moment so is any.
514
+ body.at = { x: -3.25, y: body.at.y, z: -28.67 };
515
+ h.place(world);
516
+ assert.equal(body.at.x, -3.25, 'a step inside the slack stands');
517
+ const realNow = Date.now;
518
+ Date.now = () => realNow() + 700;
519
+ try {
520
+ body.at = { x: -1, y: body.at.y, z: -26 };
521
+ h.place(world);
522
+ assert.deepEqual([body.at.x, body.at.z], [-1, -26], 'free to walk once the moment is over');
523
+ } finally {
524
+ Date.now = realNow;
525
+ }
526
+ });
527
+
266
528
  await test('a player who jumped to a friend arrives beside them, facing them', async () => {
267
529
  const s = session();
268
530
  const { h, world } = boot(s);
@@ -832,4 +1094,179 @@ await test("a goal label is one player's own; for everyone it is a sign", async
832
1094
  assert.equal(h.labelsMe.get('p1').has('door'), false);
833
1095
  });
834
1096
 
1097
+ await test('v1.81: only exactly edge:false on a private goal round-trips; absent keeps the old bytes', async () => {
1098
+ const { setLabel, wireLabel } = await import('../code/server/labels.js');
1099
+ const h = { labels: new Map(), labelsMe: new Map(), sim: { timeMs: 1000 } };
1100
+ const options = { style: 'goal', to: ['p1'] };
1101
+ const mine = () => h.labelsMe.get('p1').get('shop');
1102
+ const stored = { text: 'Hats', style: 'goal', until: null, npc: false };
1103
+ const wire = { text: 'Hats', style: 'goal' };
1104
+ setLabel(h, 'shop', 'Hats', options);
1105
+ assert.deepEqual(mine(), stored);
1106
+ assert.equal(JSON.stringify(wireLabel(mine())), JSON.stringify(wire));
1107
+ setLabel(h, 'shop', 'Hats', { ...options, edge: false });
1108
+ assert.deepEqual(mine(), { ...stored, edge: false });
1109
+ assert.deepEqual(wireLabel(mine()), { ...wire, edge: false });
1110
+ setLabel(h, 'shop', 'Hats', { ...options, edge: false, distanceM: 42 });
1111
+ assert.deepEqual(wireLabel(mine()), { ...wire, distanceM: 42, edge: false });
1112
+ setLabel(h, 'shop', 'Hats', { ...options, edge: false, distance: false });
1113
+ assert.deepEqual(wireLabel(mine()), { ...wire, distance: false, edge: false });
1114
+ for (const edge of [undefined, null, true, 0, '', 'false', {}, []]) {
1115
+ setLabel(h, 'shop', 'Hats', { ...options, edge });
1116
+ assert.deepEqual(mine(), stored);
1117
+ assert.equal(JSON.stringify(wireLabel(mine())), JSON.stringify(wire));
1118
+ }
1119
+ for (const style of ['tag', 'sign', 'speech']) {
1120
+ setLabel(h, 'shop', 'Hats', { ...options, style, edge: false });
1121
+ assert.ok(!('edge' in mine()));
1122
+ assert.deepEqual(wireLabel(mine()), { text: 'Hats', style });
1123
+ }
1124
+ setLabel(h, 'shop', 'Hats', { style: 'goal', edge: false });
1125
+ assert.ok(!('edge' in h.labels.get('shop')));
1126
+ assert.deepEqual(wireLabel(h.labels.get('shop')), { text: 'Hats', style: 'sign' });
1127
+ });
1128
+
1129
+ await test('v1.39: a goal may say which distance its pointer shows, and no other label carries the keys', async () => {
1130
+ const { setLabel, wireLabel } = await import('../code/server/labels.js');
1131
+ const h = { labels: new Map(), labelsMe: new Map(), sim: { timeMs: 1000 } };
1132
+ const mine = () => h.labelsMe.get('p1').get('corner');
1133
+ // Without the option a goal is stored and sent exactly as it was.
1134
+ setLabel(h, 'corner', 'Mill', { style: 'goal', to: ['p1'] });
1135
+ assert.deepEqual(mine(), { text: 'Mill', style: 'goal', until: null, npc: false });
1136
+ assert.deepEqual(wireLabel(mine()), { text: 'Mill', style: 'goal' });
1137
+ // A number of metres to show instead of the measured one, to the whole metre.
1138
+ setLabel(h, 'corner', 'Mill', { style: 'goal', to: ['p1'], distanceM: 83.6 });
1139
+ assert.deepEqual(wireLabel(mine()), { text: 'Mill', style: 'goal', distanceM: 84 });
1140
+ setLabel(h, 'corner', 'Mill', { style: 'goal', to: ['p1'], distanceM: 0 });
1141
+ assert.deepEqual(wireLabel(mine()), { text: 'Mill', style: 'goal', distanceM: 0 });
1142
+ // None at all.
1143
+ setLabel(h, 'corner', 'Mill', { style: 'goal', to: ['p1'], distance: false });
1144
+ assert.deepEqual(wireLabel(mine()), { text: 'Mill', style: 'goal', distance: false });
1145
+ setLabel(h, 'corner', 'Mill', { style: 'goal', to: ['p1'], distance: false, distanceM: 12 });
1146
+ assert.deepEqual(wireLabel(mine()), { text: 'Mill', style: 'goal', distance: false }, 'none wins');
1147
+ // Anything else is ignored: measured, as today.
1148
+ for (const junk of [{ distanceM: -1 }, { distanceM: NaN }, { distanceM: Infinity }, { distanceM: '40' }, { distanceM: null }, { distance: true }, { distance: 0 }, { distance: 'no' }]) {
1149
+ setLabel(h, 'corner', 'Mill', { style: 'goal', to: ['p1'], ...junk });
1150
+ assert.deepEqual(wireLabel(mine()), { text: 'Mill', style: 'goal' }, JSON.stringify(junk));
1151
+ }
1152
+ // Only a goal: a tag, a sign, speech and a goal for everyone (a sign) carry neither.
1153
+ for (const options of [{ to: ['p1'] }, { style: 'sign', to: ['p1'] }, { style: 'speech', to: ['p1'] }]) {
1154
+ setLabel(h, 'corner', 'Mill', { ...options, distanceM: 40, distance: false });
1155
+ assert.deepEqual(Object.keys(wireLabel(mine())).sort(), ['style', 'text']);
1156
+ }
1157
+ setLabel(h, 'corner', 'Mill', { style: 'goal', distanceM: 40 });
1158
+ assert.deepEqual(wireLabel(h.labels.get('corner')), { text: 'Mill', style: 'sign' });
1159
+ // Expiry is what it was: `ttlMs` from now each time the label is set, none without it.
1160
+ setLabel(h, 'corner', 'Mill', { style: 'goal', to: ['p1'], distanceM: 40, ttlMs: 5000 });
1161
+ assert.equal(mine().until, 6000);
1162
+ h.sim.timeMs = 2000;
1163
+ setLabel(h, 'corner', 'Mill', { style: 'goal', to: ['p1'], distanceM: 39, ttlMs: 5000 });
1164
+ assert.equal(mine().until, 7000);
1165
+ setLabel(h, 'corner', 'Mill', { style: 'goal', to: ['p1'], distanceM: 38 });
1166
+ assert.equal(mine().until, null);
1167
+ // Cleared like any label.
1168
+ setLabel(h, 'corner', null, { to: ['p1'] });
1169
+ assert.equal(h.labelsMe.get('p1').has('corner'), false);
1170
+ });
1171
+
1172
+
1173
+ await test('yourGames: private rows from the existing read, latched and resent to a fresh client', async () => {
1174
+ const p = platformHub({ read: (input) => input.userIds ? { players: {
1175
+ 101: { avatar: 1, hearts: ['race'], recent: [{ deckId: 'race-deck', place: 'race', score: 12, at: new Date().toISOString() }], records: [] },
1176
+ 102: { avatar: 1, hearts: [], recent: [], records: [] },
1177
+ } } : { boards: { race: { toDeckId: 'race-deck', unit: 'ms' } } } });
1178
+ const s = session({ hub: p.hub });
1179
+ const json = structuredClone(castleJson);
1180
+ json.hub.yourGames = true;
1181
+ const { h, world } = boot(s, {}, json);
1182
+ for (const { playerId } of PLAYERS) hello(h, s, playerId);
1183
+ h.place(world, []);
1184
+ await flush();
1185
+ h.step(world, []);
1186
+ const mine = () => s.sent.filter(([, msg]) => msg.k === 'hub-yours');
1187
+ assert.equal(mine().length, 1);
1188
+ assert.equal(mine()[0][0], 'p1');
1189
+ assert.equal(mine()[0][1].rows[0].door, 'race');
1190
+ assert.equal(mine()[0][1].rows[0].line, 'Last 12 ms');
1191
+ assert.ok(Number.isFinite(mine()[0][1].rows[0].lastAt));
1192
+ h.step(world, []);
1193
+ assert.equal(mine().length, 1);
1194
+ hello(h, s, 'p1', { again: true });
1195
+ h.step(world, []);
1196
+ assert.equal(mine().length, 1, 'avatar hello keeps latch');
1197
+ hello(h, s, 'p1');
1198
+ h.step(world, []);
1199
+ assert.equal(mine().length, 2, 'fresh client gets private rows again');
1200
+ assert.equal(p.calls.filter(([k]) => k === 'read').length, 2, 'only the normal player and board reads');
1201
+ });
1202
+
1203
+ await test('yourGames: closed event gates cannot crowd playable doors out of the five rows', async () => {
1204
+ const actors = globalThis.__hubTestActors;
1205
+ const ids = ['gate0', 'gate1', 'gate2', 'gate3', 'gate4', 'play0', 'play1', 'play2', 'play3', 'play4', 'open-gate'];
1206
+ globalThis.__hubTestActors = [actors[0], ...ids.map((id) => ({
1207
+ id: `${id}-actor`,
1208
+ components: { HubDoor: { id, to: `deck:${id}`, title: id }, Transform: { x: 5, y: 0, z: 5 } },
1209
+ }))];
1210
+ try {
1211
+ const p = platformHub({ read: (input) => input.userIds ? { players: {
1212
+ 101: { hearts: ids.slice(0, 8), recent: ids.slice(8).map((id) => ({ deckId: id, place: 'main', score: 2, at: new Date().toISOString() })), records: [] },
1213
+ } } : { boards: Object.fromEntries(ids.map((id) => [id, {
1214
+ toDeckId: id, unit: 'points', ...(id.startsWith('gate') || id === 'open-gate' ? { event: { open: id === 'open-gate' } } : {}),
1215
+ }])) } });
1216
+ const s = session({ hub: p.hub });
1217
+ const json = structuredClone(castleJson);
1218
+ json.hub.yourGames = true;
1219
+ const { h, world } = boot(s, {}, json);
1220
+ hello(h, s, 'p1');
1221
+ h.place(world, []);
1222
+ await flush();
1223
+ h.step(world, []);
1224
+ const listed = h.join().hubDoors;
1225
+ assert.deepEqual(listed.map((d) => d.id), ids.slice(5), 'Doors list excludes closed gates and keeps an open gate');
1226
+ const rows = s.sent.find(([id, msg]) => id === 'p1' && msg.k === 'hub-yours')[1].rows;
1227
+ assert.deepEqual(rows.map((r) => r.door), ids.slice(5, 10), 'cap applies after excluding five closed hearted gates');
1228
+ assert.ok(rows.every((r) => listed.some((d) => d.id === r.door)));
1229
+ } finally {
1230
+ globalThis.__hubTestActors = actors;
1231
+ }
1232
+ });
1233
+
1234
+ await test('sixteen avatars (v1.51): a place takes 0-15 from the hello and from ghost, and anything else as before', async () => {
1235
+ const { AVATARS } = await import('../code/server/hub.js');
1236
+ // The client's count is held to this one in test-avatar.mjs.
1237
+ // What a v1.51 client draws a player as: `hubAv2` where it names them, else `hubAv`.
1238
+ const wornBy = (h, playerId) => {
1239
+ const snapshot = h.join();
1240
+ return snapshot.hubAv2?.[playerId] ?? snapshot.hubAv[playerId];
1241
+ };
1242
+ assert.equal(AVATARS, 16);
1243
+ // The dev serve: the hello is all there is.
1244
+ {
1245
+ const s = session();
1246
+ const { h } = boot(s);
1247
+ for (const [said, worn] of [[4, 4], [9, 9], [15, 15], [0, 0], [3, 3], [16, 0], [255, 0], [-1, 0], [9.5, 0], ['9', 0], [null, 0]]) {
1248
+ hello(h, s, 'p1', { avatar: said });
1249
+ assert.equal(wornBy(h, 'p1'), worn, `hello ${JSON.stringify(said)}`);
1250
+ }
1251
+ // `hubAv` names a stand-in from the first four, `hubAv2` what is worn (test-avatar-wire.mjs).
1252
+ hello(h, s, 'p2', { avatar: 12 });
1253
+ assert.deepEqual(h.join().hubAv, { p1: 0, p2: 0 });
1254
+ assert.deepEqual(h.join().hubAv2, { p2: 12 });
1255
+ }
1256
+ // With ghost: its word replaces the hello's, a new character included; one past the kit's is not taken.
1257
+ for (const [ghost, said, worn] of [[9, 1, 9], [15, 15, 15], [16, 2, 2], [-1, 3, 3], [4.5, 1, 1]]) {
1258
+ const p = platformHub({ read: (input) => (input.userIds ? { players: { 101: { avatar: ghost, records: [], recent: [] } }, boards: {} } : { players: {}, boards: {} }) });
1259
+ const s = session({ hub: p.hub });
1260
+ const { h, world } = boot(s);
1261
+ hello(h, s, 'p1', { avatar: said });
1262
+ h.place(world);
1263
+ await flush();
1264
+ h.place(world);
1265
+ assert.equal(wornBy(h, 'p1'), worn, `ghost ${ghost}, hello ${said}`);
1266
+ // A pick after the read wins, a new character as any other.
1267
+ hello(h, s, 'p1', { avatar: 7 });
1268
+ assert.equal(wornBy(h, 'p1'), 7);
1269
+ }
1270
+ });
1271
+
835
1272
  console.log(`hub ops: ${n} tests passed`);