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
@@ -20,6 +20,7 @@ register(
20
20
  );
21
21
 
22
22
  const Avatar = await import('../code/client/avatar.js');
23
+ const { deck } = await import('../code/client/state.js');
23
24
 
24
25
  // A host whose answers the test releases by hand, in any order.
25
26
  function host() {
@@ -38,7 +39,7 @@ function host() {
38
39
  await new Promise((r) => setTimeout(r, 0));
39
40
  };
40
41
  return {
41
- api: { get: () => call('get'), set: (avatar) => call('set', avatar) },
42
+ api: { get: () => call('get'), set: (avatar, options) => call('set', options === undefined ? avatar : { avatar, ...options }) },
42
43
  calls,
43
44
  inFlight: () => pending.map((p) => (p.arg === undefined ? [p.name] : [p.name, p.arg])),
44
45
  reply: (value, pick) => settle(pick, (p) => p.resolve(value)),
@@ -75,7 +76,7 @@ await test("wears the account's avatar once the host answers, and reads it once"
75
76
  });
76
77
 
77
78
  await test('without a platform avatar the stand-in pick is worn and chosen', async () => {
78
- for (const settle of [(h) => h.reply(unavailable), (h) => h.fail({ code: 'UNKNOWN_COMMAND' }), (h) => h.reply(ok(Avatar.AVATARS))]) {
79
+ for (const settle of [(h) => h.reply(unavailable), (h) => h.reply(ok(Avatar.AVATARS))]) {
79
80
  const h = host();
80
81
  const scene = { persistent: { hubAvatar: 1 } };
81
82
  Avatar.resetPlatformForTests(h.api);
@@ -95,6 +96,254 @@ await test('without a platform avatar the stand-in pick is worn and chosen', asy
95
96
  assert.equal(Avatar.current(scene), 0);
96
97
  });
97
98
 
99
+ // Only the avatar module uses this clock; host settlement still flushes normally.
100
+ function fakeClock() {
101
+ let now = 0;
102
+ let id = 0;
103
+ const timers = new Map();
104
+ const flush = async () => { for (let i = 0; i < 8; i++) { await Promise.resolve(); } };
105
+ return {
106
+ now: () => now,
107
+ setTimeout(fn, delay) { const key = ++id; timers.set(key, { at: now + delay, fn }); return key; },
108
+ clearTimeout(key) { timers.delete(key); },
109
+ pending: () => timers.size,
110
+ async advance(ms) {
111
+ const end = now + ms;
112
+ await flush();
113
+ for (;;) {
114
+ const next = [...timers].sort((a, b) => a[1].at - b[1].at)[0];
115
+ if (!next || next[1].at > end) { break; }
116
+ now = next[1].at;
117
+ timers.delete(next[0]);
118
+ next[1].fn();
119
+ await flush();
120
+ }
121
+ now = end;
122
+ await flush();
123
+ },
124
+ };
125
+ }
126
+
127
+ await test('transport read failures retry once per runtime and write a pick after recovery', async () => {
128
+ const clock = fakeClock();
129
+ const h = host();
130
+ h.api.colors = true;
131
+ const scene = { persistent: { hubAvatar: 1 } };
132
+ const warn = console.warn;
133
+ const warnings = [];
134
+ console.warn = (...args) => warnings.push(args);
135
+ try {
136
+ Avatar.resetPlatformForTests(h.api, clock);
137
+ Avatar.load(scene);
138
+ await h.fail({ code: 'CASTLE_HOST_UNAVAILABLE' });
139
+ Avatar.choose(scene, 9);
140
+ Avatar.load(scene);
141
+ assert.equal(Avatar.diagnostics().state, 'loading');
142
+ assert.equal(Avatar.current(scene), 9);
143
+ assert.equal(scene.persistent.hubAvatar, 1);
144
+ assert.deepEqual(h.inFlight(), []);
145
+ await clock.advance(1999);
146
+ assert.equal(h.calls.length, 1);
147
+ await clock.advance(1);
148
+ assert.deepEqual(h.inFlight(), [['get']]);
149
+ Avatar.load(scene);
150
+ await clock.advance(4000);
151
+ assert.equal(h.calls.length, 2, 'no read overlaps a pending read');
152
+ await h.fail(new Error('timeout'));
153
+ await clock.advance(3999);
154
+ assert.equal(h.calls.length, 2);
155
+ await clock.advance(1);
156
+ await h.reply({ ...ok(2), color: 3 });
157
+ assert.equal(Avatar.diagnostics().state, 'ready');
158
+ assert.equal(Avatar.colorsAvailable(), true);
159
+ assert.equal(Avatar.diagnostics().color, 3);
160
+ assert.equal(Avatar.diagnostics().retries, 2);
161
+ assert.equal(Avatar.diagnostics().lastError, 'Error');
162
+ assert.equal(Object.isFrozen(Avatar.diagnostics()), true);
163
+ assert.deepEqual(h.inFlight(), [['set', 9]]);
164
+ await h.reply({ ...ok(9), color: 0 });
165
+ assert.equal(Avatar.current(scene), 9);
166
+ assert.equal(clock.pending(), 0);
167
+ assert.equal(warnings.length, 1, 'only the first failure warns');
168
+ assert.match(warnings[0][0], /^\[hub\] platform avatar /);
169
+ } finally { console.warn = warn; Avatar.resetPlatformForTests(null); }
170
+ });
171
+
172
+ await test('read retry budget keeps the pick on give-up', async () => {
173
+ const clock = fakeClock();
174
+ const scene = { persistent: { hubAvatar: 1 } };
175
+ let reads = 0;
176
+ const warn = console.warn;
177
+ const warnings = [];
178
+ console.warn = (...args) => warnings.push(args);
179
+ try {
180
+ // A synchronous throw is a transport failure too.
181
+ Avatar.resetPlatformForTests({ get() { reads++; throw new Error('not listening'); } }, clock);
182
+ Avatar.load(scene);
183
+ Avatar.choose(scene, 3);
184
+ await clock.advance(179999);
185
+ assert.equal(Avatar.diagnostics().state, 'loading');
186
+ await clock.advance(1);
187
+ assert.equal(Avatar.diagnostics().state, 'none');
188
+ assert.equal(scene.persistent.hubAvatar, 3);
189
+ assert.equal(Avatar.current(scene), 3);
190
+ assert.equal(reads, 9);
191
+ assert.equal(clock.pending(), 0);
192
+ assert.equal(warnings.length, 2);
193
+ assert.match(warnings[1][0], /gave up/);
194
+ Avatar.load(scene);
195
+ await clock.advance(30000);
196
+ assert.equal(reads, 9, 'giving up ends the runtime read chain');
197
+ } finally { console.warn = warn; Avatar.resetPlatformForTests(null); }
198
+ });
199
+
200
+ await test('time spent awaiting a read counts against the retry budget', async () => {
201
+ const h = host();
202
+ const clock = fakeClock();
203
+ Avatar.resetPlatformForTests(h.api, clock);
204
+ Avatar.load({});
205
+ await clock.advance(179000);
206
+ await h.fail({ code: 'CASTLE_HOST_UNAVAILABLE' });
207
+ await clock.advance(999);
208
+ assert.equal(Avatar.diagnostics().state, 'loading');
209
+ await clock.advance(1);
210
+ assert.equal(Avatar.diagnostics().state, 'none');
211
+ assert.deepEqual(h.calls, [['get']]);
212
+ assert.equal(clock.pending(), 0);
213
+ });
214
+
215
+ await test('an unavailable answer ends read retries immediately', async () => {
216
+ const h = host();
217
+ const clock = fakeClock();
218
+ const scene = { persistent: {} };
219
+ Avatar.resetPlatformForTests(h.api, clock);
220
+ Avatar.load(scene);
221
+ Avatar.choose(scene, 2);
222
+ await h.reply(unavailable);
223
+ assert.equal(Avatar.diagnostics().state, 'none');
224
+ assert.equal(scene.persistent.hubAvatar, 2);
225
+ await clock.advance(180000);
226
+ assert.deepEqual(h.calls, [['get']]);
227
+ assert.equal(clock.pending(), 0);
228
+ });
229
+
230
+ await test('an UNKNOWN_COMMAND read uses the stand-in immediately without retrying', async () => {
231
+ const h = host();
232
+ const clock = fakeClock();
233
+ const scene = { persistent: { hubAvatar: 1 } };
234
+ Avatar.resetPlatformForTests(h.api, clock);
235
+ Avatar.load(scene);
236
+ Avatar.choose(scene, 2);
237
+ await h.fail({ code: 'UNKNOWN_COMMAND' });
238
+ assert.equal(Avatar.diagnostics().state, 'none');
239
+ assert.equal(Avatar.current(scene), 2);
240
+ assert.equal(scene.persistent.hubAvatar, 2);
241
+ assert.equal(clock.pending(), 0);
242
+ Avatar.load(scene);
243
+ await clock.advance(180000);
244
+ assert.deepEqual(h.calls, [['get']]);
245
+ });
246
+
247
+ for (const code of ['PERMISSION_DENIED', 'UNKNOWN_COMMAND']) {
248
+ await test(`a ${code} write undoes the pick without retrying and allows a newer pick`, async () => {
249
+ const h = host();
250
+ const clock = fakeClock();
251
+ const scene = { persistent: {} };
252
+ Avatar.resetPlatformForTests(h.api, clock);
253
+ Avatar.load(scene);
254
+ await h.reply(ok(1));
255
+ Avatar.choose(scene, 2);
256
+ assert.equal(Avatar.current(scene), 2);
257
+ await h.fail({ code });
258
+ assert.equal(Avatar.current(scene), 1);
259
+ assert.equal(Avatar.diagnostics().state, 'ready');
260
+ assert.equal(clock.pending(), 0);
261
+ assert.deepEqual(h.inFlight(), []);
262
+ Avatar.choose(scene, 3);
263
+ assert.deepEqual(h.inFlight(), [['set', 3]]);
264
+ await h.reply(ok(3));
265
+ assert.equal(Avatar.current(scene), 3);
266
+ await clock.advance(180000);
267
+ assert.deepEqual(h.calls, [['get'], ['set', 2], ['set', 3]]);
268
+ assert.equal(clock.pending(), 0);
269
+ });
270
+ }
271
+
272
+ await test('a CASTLE_HOST_UNAVAILABLE write succeeds on its next attempt', async () => {
273
+ const h = host();
274
+ const clock = fakeClock();
275
+ const scene = { persistent: {} };
276
+ Avatar.resetPlatformForTests(h.api, clock);
277
+ Avatar.load(scene);
278
+ await h.reply(ok(1));
279
+ Avatar.choose(scene, 2);
280
+ await h.fail({ code: 'CASTLE_HOST_UNAVAILABLE' });
281
+ assert.equal(Avatar.current(scene), 2);
282
+ assert.equal(clock.pending(), 1);
283
+ assert.deepEqual(h.inFlight(), []);
284
+ await clock.advance(1999);
285
+ assert.deepEqual(h.calls, [['get'], ['set', 2]]);
286
+ await clock.advance(1);
287
+ assert.deepEqual(h.inFlight(), [['set', 2]]);
288
+ await h.reply(ok(2));
289
+ assert.equal(Avatar.current(scene), 2);
290
+ assert.equal(clock.pending(), 0);
291
+ await clock.advance(180000);
292
+ assert.deepEqual(h.calls, [['get'], ['set', 2], ['set', 2]]);
293
+ });
294
+
295
+ await test('transport write retries preserve the exact character and colour with newer picks queued', async () => {
296
+ const h = host();
297
+ h.api.colors = true;
298
+ const clock = fakeClock();
299
+ const scene = { persistent: {} };
300
+ Avatar.resetPlatformForTests(h.api, clock);
301
+ Avatar.load(scene);
302
+ await h.reply({ ...ok(9), color: 2 });
303
+ Avatar.chooseColor(scene, 4);
304
+ await h.fail({ code: 'CASTLE_HOST_UNAVAILABLE' });
305
+ Avatar.choose(scene, 3);
306
+ assert.equal(Avatar.current(scene), 3);
307
+ assert.deepEqual(h.inFlight(), []);
308
+ await clock.advance(2000);
309
+ assert.deepEqual(h.inFlight(), [['set', { avatar: 9, color: 4 }]]);
310
+ await h.fail(new Error('timeout'));
311
+ await clock.advance(4000);
312
+ assert.deepEqual(h.inFlight(), [['set', { avatar: 9, color: 4 }]]);
313
+ await h.reply({ ...ok(9), color: 4 });
314
+ assert.deepEqual(h.inFlight(), [['set', 3]]);
315
+ await h.reply(ok(3));
316
+ assert.equal(Avatar.current(scene), 3);
317
+ assert.equal(clock.pending(), 0);
318
+ });
319
+
320
+ await test('write retries are bounded and an unavailable retry still keeps the stand-in', async () => {
321
+ const h = host();
322
+ const clock = fakeClock();
323
+ const scene = { persistent: {} };
324
+ Avatar.resetPlatformForTests(h.api, clock);
325
+ Avatar.load(scene);
326
+ await h.reply(ok(1));
327
+ const set = h.api.set;
328
+ let writes = 0;
329
+ h.api.set = () => { writes++; return Promise.reject(new Error('timeout')); };
330
+ Avatar.choose(scene, 2);
331
+ await clock.advance(179999);
332
+ assert.equal(Avatar.current(scene), 2);
333
+ await clock.advance(1);
334
+ assert.equal(Avatar.current(scene), 1, 'exhausted write restores the confirmed pick');
335
+ assert.equal(Avatar.diagnostics().state, 'ready');
336
+ assert.equal(writes, 9);
337
+ assert.equal(clock.pending(), 0);
338
+ h.api.set = set;
339
+ Avatar.choose(scene, 3);
340
+ await h.fail(new Error('timeout'));
341
+ await clock.advance(2000);
342
+ await h.reply(unavailable);
343
+ assert.equal(scene.persistent.hubAvatar, 3);
344
+ assert.equal(Avatar.diagnostics().state, 'none');
345
+ });
346
+
98
347
  await test("a pick is the account's: worn at once, kept as ghost answers", async () => {
99
348
  const h = host();
100
349
  const scene = { persistent: {} };
@@ -234,12 +483,15 @@ const at = (href) => {
234
483
  return { hostname: url.hostname, search: url.search };
235
484
  };
236
485
  const blueprintOf = (file) => JSON.stringify({ actors: [{ components: { Model: { file } } }] });
486
+ // Toon has all sixteen (v1.51); the other sets draw the first four.
487
+ const SET_AVATARS = 4;
488
+ const countIn = (style) => (style === 'toon' ? Avatar.AVATARS : SET_AVATARS);
237
489
  // A deck's files with the kit imported: toon and one more set.
238
490
  const deckFiles = (...styles) => {
239
491
  const files = {};
240
492
  for (const style of ['toon', ...styles]) {
241
493
  const dir = style === 'toon' ? '' : `${style}/`;
242
- for (let i = 0; i < Avatar.AVATARS; i++) {
494
+ for (let i = 0; i < countIn(style); i++) {
243
495
  files[`imports/castle.hub-game/blueprints/${dir}avatar-${i}.scene`] = blueprintOf(`models/${dir}avatar-${i}.pxmodel`);
244
496
  }
245
497
  }
@@ -252,14 +504,16 @@ await test('with nothing said the set is toon, and everything is where it was',
252
504
  Avatar.resetStyleForTests(undefined);
253
505
  assert.equal(Avatar.style(), 'toon');
254
506
  const files = deckFiles('blocky', 'bean', 'pixel');
255
- const toonTops = [1.38, 1.5, 1.42, 1.56];
507
+ const toonTops = [1.38, 1.5, 1.42, 1.56, 1.31, 1.39, 1.59, 1.29, 1.24, 1.37, 1.38, 1.51, 1.44, 1.38, 1.37, 1.37];
508
+ assert.equal(toonTops.length, Avatar.AVATARS);
256
509
  for (let i = 0; i < Avatar.AVATARS; i++) {
257
510
  assert.equal(Avatar.blueprint(files, i), `imports/castle.hub-game/blueprints/avatar-${i}.scene`);
258
511
  assert.equal(Avatar.model(files, i), `imports/castle.hub-game/models/avatar-${i}.pxmodel`);
259
512
  assert.equal(Avatar.top(i), toonTops[i]);
260
513
  assert.equal(Avatar.drawn(files, i), 'toon');
261
514
  }
262
- assert.equal(Avatar.top(9), 1.65);
515
+ assert.equal(Avatar.top(Avatar.AVATARS), 1.65);
516
+ assert.equal(Avatar.top(99), 1.65);
263
517
  assert.equal(Avatar.blueprint(null, 0), null);
264
518
  });
265
519
 
@@ -404,7 +658,7 @@ await test("a set these files do not have is drawn from toon's, at toon's height
404
658
  assert.equal(Avatar.drawn(null, 0), 'bean');
405
659
  });
406
660
 
407
- await test("every set has four blueprints shaped like toon's, models with the parts the walk moves, art it can find and a height", async () => {
661
+ await test("toon has sixteen blueprints and every other set four, shaped like toon's, with models that have the parts the walk moves, art they can find and a height", async () => {
408
662
  const kit = new URL('../', import.meta.url);
409
663
  const refs = (value, out = []) => {
410
664
  if (typeof value === 'string') {
@@ -416,7 +670,10 @@ await test("every set has four blueprints shaped like toon's, models with the pa
416
670
  };
417
671
  for (const style of Avatar.STYLES) {
418
672
  const dir = style === 'toon' ? '' : `${style}/`;
419
- for (let i = 0; i < Avatar.AVATARS; i++) {
673
+ // No file past a set's own: the kit ships nothing it does not draw.
674
+ await assert.rejects(readFile(new URL(`blueprints/${dir}avatar-${countIn(style)}.scene`, kit), 'utf8'), { code: 'ENOENT' });
675
+ await assert.rejects(readFile(new URL(`models/${dir}avatar-${countIn(style)}.pxmodel`, kit), 'utf8'), { code: 'ENOENT' });
676
+ for (let i = 0; i < countIn(style); i++) {
420
677
  const path = `blueprints/${dir}avatar-${i}.scene`;
421
678
  const text = await readFile(new URL(path, kit), 'utf8');
422
679
  const files = { [path]: text };
@@ -452,6 +709,145 @@ await test("every set has four blueprints shaped like toon's, models with the pa
452
709
  }
453
710
  });
454
711
 
712
+ // --- sixteen avatars (v1.51) ---
713
+
714
+ await test('sixteen avatars: every index has a blueprint, a model, a height and a hat fit', async () => {
715
+ assert.equal(Avatar.AVATARS, 16);
716
+ const kit = new URL('../', import.meta.url);
717
+ const files = {};
718
+ for (let i = 0; i < Avatar.AVATARS; i++) {
719
+ files[`blueprints/avatar-${i}.scene`] = await readFile(new URL(`blueprints/avatar-${i}.scene`, kit), 'utf8');
720
+ }
721
+ const models = new Set();
722
+ for (let i = 0; i < Avatar.AVATARS; i++) {
723
+ assert.equal(Avatar.blueprint(files, i, 'toon'), `blueprints/avatar-${i}.scene`);
724
+ const model = Avatar.model(files, i, 'toon');
725
+ assert.equal(model, `models/avatar-${i}.pxmodel`);
726
+ models.add(await readFile(new URL(model, kit), 'utf8'));
727
+ const top = Avatar.top(i, 'toon');
728
+ assert.ok(top >= 1.2 && top <= 1.75, `avatar ${i} top ${top}`);
729
+ const fit = Avatar.hatFit(i, 'toon');
730
+ assert.ok(Array.isArray(fit) && fit.length === 3 && fit.every(Number.isFinite), `avatar ${i} hat fit`);
731
+ assert.equal(Avatar.known(i), i);
732
+ // The body is the first avatar's: only the name and the model differ.
733
+ const { name, actors } = JSON.parse(files[`blueprints/avatar-${i}.scene`]);
734
+ assert.equal(name, `Avatar ${i + 1}`);
735
+ const first = JSON.parse(files['blueprints/avatar-0.scene']).actors;
736
+ first[0].components.Model.file = model;
737
+ assert.deepEqual(actors, first, `blueprints/avatar-${i}.scene`);
738
+ }
739
+ // Sixteen different characters.
740
+ assert.equal(models.size, Avatar.AVATARS);
741
+ // The place's server takes exactly the indexes the client draws.
742
+ const server = await readFile(new URL('code/server/hub.js', kit), 'utf8');
743
+ assert.equal(Number(/^export const AVATARS = (\d+);$/m.exec(server)[1]), Avatar.AVATARS);
744
+ });
745
+
746
+ await test("a set draws 4-15 from toon's blueprint, at toon's height and hat fit", () => {
747
+ const files = deckFiles('blocky', 'bean', 'pixel');
748
+ for (const style of ['blocky', 'bean', 'pixel']) {
749
+ Avatar.resetStyleForTests({ location: undefined, experiment: () => style });
750
+ assert.equal(Avatar.style(), style);
751
+ for (let i = 0; i < Avatar.AVATARS; i++) {
752
+ const own = i < SET_AVATARS;
753
+ const dir = own ? `${style}/` : '';
754
+ assert.equal(Avatar.blueprint(files, i), `imports/castle.hub-game/blueprints/${dir}avatar-${i}.scene`, `${style} ${i}`);
755
+ assert.equal(Avatar.model(files, i), `imports/castle.hub-game/models/${dir}avatar-${i}.pxmodel`, `${style} ${i}`);
756
+ assert.equal(Avatar.drawn(files, i), own ? style : 'toon', `${style} ${i}`);
757
+ // What the hub system asks: the height and fit of the set really drawn.
758
+ const drawn = Avatar.drawn(files, i);
759
+ assert.equal(Avatar.top(i, drawn), Avatar.top(i, own ? style : 'toon'));
760
+ assert.equal(Avatar.hatFit(i, drawn), Avatar.hatFit(i, own ? style : 'toon'));
761
+ // And asked of the set itself (before the files are known, `drawn` is
762
+ // the set asked for): toon's numbers for an index the set has no row
763
+ // for, never undefined.
764
+ assert.equal(Avatar.drawn(null, i), style);
765
+ const top = Avatar.top(i, style);
766
+ const fit = Avatar.hatFit(i, style);
767
+ assert.ok(Number.isFinite(top) && Array.isArray(fit) && fit.every(Number.isFinite), `${style} ${i}`);
768
+ if (!own) {
769
+ assert.equal(top, Avatar.top(i, 'toon'), `${style} ${i}`);
770
+ assert.equal(fit, Avatar.hatFit(i, 'toon'), `${style} ${i}`);
771
+ }
772
+ }
773
+ // The first four are the set's own, as they were.
774
+ assert.notDeepEqual([0, 1, 2, 3].map((i) => Avatar.top(i, style)), [0, 1, 2, 3].map((i) => Avatar.top(i, 'toon')));
775
+ }
776
+ Avatar.resetStyleForTests(undefined);
777
+ });
778
+
779
+ await test('a new stand-in can wear any known avatar; stored choices are kept', async () => {
780
+ const random = Math.random;
781
+ try {
782
+ // Every bucket's edges, including the top of the random range.
783
+ const seen = new Set();
784
+ for (let index = 0; index < Avatar.AVATARS; index++) {
785
+ for (const roll of [index / Avatar.AVATARS, (index + 1 - 0.000001) / Avatar.AVATARS]) {
786
+ Math.random = () => roll;
787
+ Avatar.resetPlatformForTests(null);
788
+ const scene = {};
789
+ Avatar.load(scene);
790
+ const worn = Avatar.current(scene);
791
+ assert.equal(worn, index, `roll ${roll} gave ${worn}`);
792
+ assert.equal(Avatar.known(worn), worn, 'the stand-in is always a known index');
793
+ assert.equal(scene.persistent.hubAvatar, worn);
794
+ assert.equal(Avatar.current(scene), worn, 'the local choice is kept');
795
+ seen.add(worn);
796
+ }
797
+ }
798
+ assert.deepEqual([...seen], Array.from({ length: 16 }, (_, index) => index));
799
+ } finally {
800
+ Math.random = random;
801
+ }
802
+ // One kept from before is kept, a new one included, and a pick of a new one is worn.
803
+ Avatar.resetPlatformForTests(null);
804
+ for (const kept of [0, 3, 4, 15]) {
805
+ assert.equal(Avatar.current({ persistent: { hubAvatar: kept } }), kept);
806
+ }
807
+ const scene = { persistent: { hubAvatar: 2 } };
808
+ Avatar.choose(scene, 15);
809
+ assert.equal(Avatar.current(scene), 15);
810
+ for (const bad of [16, -1, 4.5, '9', null, undefined, NaN, Infinity]) {
811
+ Avatar.choose(scene, bad);
812
+ assert.equal(Avatar.current(scene), 15, String(bad));
813
+ }
814
+ // The account's avatar may be a new one; the host is asked for it and told of a pick as before.
815
+ const h = host();
816
+ const account = { persistent: { hubAvatar: 1 } };
817
+ await ready(h, 9, account);
818
+ assert.equal(Avatar.current(account), 9);
819
+ Avatar.choose(account, 12);
820
+ assert.equal(Avatar.current(account), 12);
821
+ await h.reply(ok(12), setOf(12));
822
+ assert.equal(Avatar.current(account), 12);
823
+ assert.deepEqual(h.calls, [['get'], ['set', 12]]);
824
+ assert.equal(account.persistent.hubAvatar, 1, 'the stand-in is left alone');
825
+ });
826
+
827
+ await test('an index past this kit (a later kit) is drawn as one of the first four, and anything else as nobody', () => {
828
+ for (let i = 0; i < Avatar.AVATARS; i++) {
829
+ assert.equal(Avatar.known(i), i);
830
+ }
831
+ assert.deepEqual([16, 17, 18, 19, 20, 255, 1000].map(Avatar.known), [0, 1, 2, 3, 0, 3, 0]);
832
+ for (const bad of [-1, -16, 1.5, 16.5, '2', '16', null, undefined, NaN, Infinity, {}, true]) {
833
+ assert.equal(Avatar.known(bad), null, String(bad));
834
+ }
835
+ // Drawn and dressed by it: a blueprint these files have, toon's row for it.
836
+ const files = deckFiles('bean');
837
+ for (const which of ['toon', 'bean']) {
838
+ const index = Avatar.known(21);
839
+ assert.equal(index, 1);
840
+ assert.ok(Avatar.blueprint(files, index, which));
841
+ assert.ok(Number.isFinite(Avatar.top(index, Avatar.drawn(files, index, which))));
842
+ assert.ok(Array.isArray(Avatar.hatFit(index, Avatar.drawn(files, index, which))));
843
+ }
844
+ // The index itself has nothing here, and asking is safe.
845
+ assert.equal(Avatar.blueprint(files, 21), null);
846
+ assert.equal(Avatar.model(files, 21), null);
847
+ assert.equal(Avatar.top(21), 1.65);
848
+ assert.equal(Avatar.hatFit(21), null);
849
+ });
850
+
455
851
  Avatar.resetStyleForTests(undefined);
456
852
 
457
853
  await test('the pack exporter and the town overlay know every set, and only the sets', async () => {
@@ -469,4 +865,141 @@ await test('the pack exporter and the town overlay know every set, and only the
469
865
  }
470
866
  });
471
867
 
868
+ await test('an old host has no colour picker or colour writes, even with a stored stand-in colour', async () => {
869
+ const h = host();
870
+ const scene = { persistent: { hubAvatar: 2, hubAvatarColor: 3 } };
871
+ Avatar.resetPlatformForTests(h.api);
872
+ Avatar.load(scene);
873
+ assert.equal(Avatar.currentColor(scene), 0);
874
+ assert.equal(Avatar.colorsAvailable(), false);
875
+ await h.reply(ok(2));
876
+ Avatar.chooseColor(scene, 3);
877
+ assert.deepEqual(h.calls, [['get']]);
878
+ Avatar.choose(scene, 1);
879
+ await h.reply(ok(1));
880
+ assert.deepEqual(h.calls, [['get'], ['set', 1]]);
881
+ assert.equal(Avatar.currentColor(scene), 0);
882
+ });
883
+
884
+ await test('colours are confirmed, refused, and queued with character picks in order', async () => {
885
+ const h = host();
886
+ h.api.colors = true;
887
+ const scene = { persistent: {} };
888
+ Avatar.resetPlatformForTests(h.api);
889
+ Avatar.load(scene);
890
+ await h.reply({ ...ok(9), color: 2 });
891
+ assert.equal(Avatar.colorsAvailable(), true);
892
+ assert.equal(Avatar.currentColor(scene), 2);
893
+ Avatar.chooseColor(scene, 4);
894
+ assert.equal(Avatar.currentColor(scene), 4);
895
+ await h.reply({ ...ok(9), color: 3 });
896
+ assert.equal(Avatar.currentColor(scene), 3, 'ghost confirms what was actually kept');
897
+ Avatar.chooseColor(scene, 5);
898
+ await h.fail({ code: 'INVALID_ARGUMENT' });
899
+ assert.equal(Avatar.currentColor(scene), 3, 'refusal restores the confirmed colour');
900
+ Avatar.chooseColor(scene, 1);
901
+ Avatar.choose(scene, 2);
902
+ Avatar.chooseColor(scene, 4);
903
+ await h.reply({ ...ok(9), color: 1 });
904
+ assert.equal(Avatar.current(scene), 2);
905
+ assert.equal(Avatar.currentColor(scene), 4);
906
+ await h.reply({ ...ok(2), color: 4 });
907
+ Avatar.choose(scene, 1);
908
+ assert.equal(Avatar.currentColor(scene), 0);
909
+ await h.reply({ ...ok(1), color: 0 });
910
+ assert.deepEqual(h.calls, [['get'], ['set', { avatar: 9, color: 4 }], ['set', { avatar: 9, color: 5 }], ['set', { avatar: 9, color: 1 }], ['set', { avatar: 2, color: 4 }], ['set', 1]]);
911
+ });
912
+
913
+ await test('a colour host needs the exact SDK marker, even with manifest opt-in', async () => {
914
+ for (const marker of [undefined, false, 1, 'true', true]) {
915
+ for (const optIn of [false, true]) {
916
+ const h = host();
917
+ if (marker !== undefined) { h.api.colors = marker; }
918
+ deck.avatarColors = optIn;
919
+ const setArgs = [];
920
+ const set = h.api.set;
921
+ h.api.set = (...args) => { setArgs.push(args); return set(...args); };
922
+ const scene = { persistent: { hubAvatar: 9, hubAvatarColor: 3 } };
923
+ Avatar.resetPlatformForTests(h.api);
924
+ Avatar.load(scene);
925
+ await h.reply({ ...ok(9), color: 2 });
926
+ assert.equal(Avatar.colorsAvailable(), marker === true);
927
+ assert.equal(Avatar.currentColor(scene), marker === true ? 2 : 0);
928
+ Avatar.chooseColor(scene, 4);
929
+ if (marker === true) {
930
+ assert.deepEqual(setArgs, [[9, { color: 4 }]]);
931
+ await h.reply({ ...ok(9), color: 4 });
932
+ } else {
933
+ assert.deepEqual(setArgs, []);
934
+ }
935
+ Avatar.choose(scene, 1);
936
+ assert.deepEqual(setArgs.at(-1), [1], 'character picks retain one argument');
937
+ await h.reply({ ...ok(1), color: 0 });
938
+ }
939
+ }
940
+ delete deck.avatarColors;
941
+ });
942
+
943
+ await test('stand-in colours are dormant without an exact manifest opt-in', async () => {
944
+ for (const avatarColors of [undefined, false, 1, 'true']) {
945
+ if (avatarColors === undefined) {
946
+ delete deck.avatarColors;
947
+ } else {
948
+ deck.avatarColors = avatarColors;
949
+ }
950
+ const scene = { persistent: { hubAvatar: 9, hubAvatarColor: 3 } };
951
+ Avatar.resetPlatformForTests(null);
952
+ Avatar.load(scene);
953
+ assert.equal(Avatar.colorsAvailable(), false);
954
+ assert.equal(Avatar.currentColor(scene), 0);
955
+ Avatar.chooseColor(scene, 2);
956
+ assert.deepEqual(scene.persistent, { hubAvatar: 9, hubAvatarColor: 3 });
957
+ Avatar.choose(scene, 10);
958
+ assert.deepEqual(scene.persistent, { hubAvatar: 10, hubAvatarColor: 3 });
959
+ const empty = {};
960
+ Avatar.chooseColor(empty, 2);
961
+ assert.deepEqual(empty, {}, 'a dormant pick does not initialise an avatar');
962
+ }
963
+ delete deck.avatarColors;
964
+ const h = host();
965
+ const scene = { persistent: { hubAvatar: 9, hubAvatarColor: 3 } };
966
+ Avatar.resetPlatformForTests(h.api);
967
+ Avatar.load(scene);
968
+ await h.reply(unavailable);
969
+ assert.equal(Avatar.colorsAvailable(), false);
970
+ Avatar.chooseColor(scene, 2);
971
+ assert.equal(Avatar.currentColor(scene), 0);
972
+ assert.deepEqual(scene.persistent, { hubAvatar: 9, hubAvatarColor: 3 });
973
+ });
974
+
975
+ await test('opted-in stand-in colours persist and clear on a character change, including an unavailable write', async () => {
976
+ deck.avatarColors = true;
977
+ const scene = { persistent: { hubAvatar: 9 } };
978
+ Avatar.resetPlatformForTests(null);
979
+ Avatar.load(scene);
980
+ assert.equal(Avatar.colorsAvailable(), true);
981
+ Avatar.chooseColor(scene, 2);
982
+ assert.equal(scene.persistent.hubAvatarColor, 2);
983
+ for (const bad of [-1, 6, 1.5, '2', null]) {
984
+ Avatar.chooseColor(scene, bad);
985
+ assert.equal(Avatar.currentColor(scene), 2);
986
+ }
987
+ Avatar.choose(scene, 9);
988
+ assert.equal(Avatar.currentColor(scene), 2);
989
+ Avatar.choose(scene, 10);
990
+ assert.equal(Avatar.currentColor(scene), 0);
991
+ delete deck.avatarColors;
992
+ const h = host();
993
+ await ready(h, 10, scene);
994
+ // Both get's colour field and the SDK marker unlock writes.
995
+ h.api.colors = true;
996
+ Avatar.resetPlatformForTests(h.api);
997
+ Avatar.load(scene);
998
+ await h.reply({ ...ok(10), color: 0 });
999
+ Avatar.chooseColor(scene, 3);
1000
+ await h.reply(unavailable);
1001
+ assert.equal(scene.persistent.hubAvatarColor, 3);
1002
+ assert.equal(Avatar.currentColor(scene), 3);
1003
+ });
1004
+
472
1005
  console.log(`hub-game avatar: ${n} tests passed`);