castle-web-cli 0.4.239 → 0.4.241

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 (396) hide show
  1. package/dist/agent.js +5 -1
  2. package/dist/api.d.ts +20 -0
  3. package/dist/api.js +57 -0
  4. package/dist/bundle.d.ts +38 -1
  5. package/dist/bundle.js +309 -13
  6. package/dist/castle-host/host.js +163 -11
  7. package/dist/castleJson.d.ts +10 -0
  8. package/dist/castleJson.js +46 -2
  9. package/dist/check.js +5 -2
  10. package/dist/devSessionServer.js +4 -1
  11. package/dist/devSessionStorage.d.ts +1 -0
  12. package/dist/devSessionStorage.js +32 -7
  13. package/dist/importOrder.d.ts +2 -0
  14. package/dist/importOrder.js +29 -0
  15. package/dist/index.js +6 -3
  16. package/dist/init.js +24 -2
  17. package/dist/multiplayerDoc.d.ts +1 -1
  18. package/dist/multiplayerDoc.js +2 -0
  19. package/dist/platformDoc.js +3 -2
  20. package/dist/playPagePolicy.js +5 -1
  21. package/dist/resetLeaderboards.d.ts +8 -1
  22. package/dist/resetLeaderboards.js +43 -8
  23. package/dist/roomLogs.d.ts +1 -0
  24. package/dist/roomLogs.js +30 -6
  25. package/dist/save-deck.d.ts +32 -2
  26. package/dist/save-deck.js +240 -39
  27. package/kits/base/CLAUDE.md +1 -1
  28. package/kits/base/castle.json +1 -1
  29. package/kits/base/sdk/README.md +174 -6
  30. package/kits/base/sdk/analytics.d.ts +8 -0
  31. package/kits/base/sdk/analytics.js +92 -0
  32. package/kits/base/sdk/castle.d.ts +5 -1
  33. package/kits/base/sdk/castle.js +2 -0
  34. package/kits/base/sdk/commands.d.ts +48 -0
  35. package/kits/base/sdk/commands.js +1 -0
  36. package/kits/base/sdk/debugConsole.d.ts +17 -0
  37. package/kits/base/sdk/debugConsole.js +154 -0
  38. package/kits/base/sdk/experiments.js +24 -1
  39. package/kits/base/sdk/hostRetry.d.ts +7 -0
  40. package/kits/base/sdk/hostRetry.js +57 -0
  41. package/kits/base/sdk/hub.d.ts +20 -2
  42. package/kits/base/sdk/hub.js +99 -13
  43. package/kits/base/sdk/multiplayer.d.ts +2 -0
  44. package/kits/base/sdk/multiplayer.js +168 -26
  45. package/kits/base/sdk/reconnectBudget.d.ts +6 -0
  46. package/kits/base/sdk/reconnectBudget.js +41 -1
  47. package/kits/base/sdk/runtime.js +36 -19
  48. package/kits/base/sdk/server/hub.d.ts +19 -0
  49. package/kits/base/sdk/server/hub.js +12 -0
  50. package/kits/base/sdk/server/platformHandle.d.ts +1 -0
  51. package/kits/base/sdk/server/wrapper.d.ts +1 -1
  52. package/kits/base/sdk/server/wrapper.js +26 -1
  53. package/kits/base/sdk/transport.d.ts +2 -1
  54. package/kits/base/sdk/transport.js +35 -0
  55. package/kits/hub-game/CLAUDE.md +66 -19
  56. package/kits/hub-game/code/client/act.js +9 -6
  57. package/kits/hub-game/code/client/actCore.js +26 -6
  58. package/kits/hub-game/code/client/actGateLog.js +36 -0
  59. package/kits/hub-game/code/client/actionOverflow.js +29 -8
  60. package/kits/hub-game/code/client/actionRailSurface.js +186 -0
  61. package/kits/hub-game/code/client/actionRailTree.js +173 -0
  62. package/kits/hub-game/code/client/askSurface.js +85 -0
  63. package/kits/hub-game/code/client/askTree.js +51 -0
  64. package/kits/hub-game/code/client/attention.js +31 -6
  65. package/kits/hub-game/code/client/ballot.js +42 -5
  66. package/kits/hub-game/code/client/ballotSurface.js +115 -0
  67. package/kits/hub-game/code/client/ballotTree.js +180 -0
  68. package/kits/hub-game/code/client/catchingUp.js +19 -0
  69. package/kits/hub-game/code/client/celebrate.js +66 -0
  70. package/kits/hub-game/code/client/chrome.js +481 -57
  71. package/kits/hub-game/code/client/companion.js +93 -23
  72. package/kits/hub-game/code/client/companionDress.js +1 -1
  73. package/kits/hub-game/code/client/cornerSurface.js +106 -0
  74. package/kits/hub-game/code/client/cornerTree.js +83 -0
  75. package/kits/hub-game/code/client/decor.js +20 -11
  76. package/kits/hub-game/code/client/deviceStorage.js +121 -0
  77. package/kits/hub-game/code/client/disguise.js +23 -0
  78. package/kits/hub-game/code/client/disguiseDraw.js +87 -0
  79. package/kits/hub-game/code/client/dockSurface.js +206 -0
  80. package/kits/hub-game/code/client/dockTree.js +232 -0
  81. package/kits/hub-game/code/client/earned.js +29 -0
  82. package/kits/hub-game/code/client/emoteSurface.js +188 -0
  83. package/kits/hub-game/code/client/emoteTree.js +264 -0
  84. package/kits/hub-game/code/client/farAvatars.js +4 -3
  85. package/kits/hub-game/code/client/fpsTelemetry.js +3 -1
  86. package/kits/hub-game/code/client/grab.js +121 -50
  87. package/kits/hub-game/code/client/holdShow.js +19 -0
  88. package/kits/hub-game/code/client/hookLayer.js +96 -12
  89. package/kits/hub-game/code/client/hubControls.js +7 -1
  90. package/kits/hub-game/code/client/hudSurface.js +11 -3
  91. package/kits/hub-game/code/client/hudTree.js +7 -4
  92. package/kits/hub-game/code/client/idle.js +21 -3
  93. package/kits/hub-game/code/client/invites.js +24 -3
  94. package/kits/hub-game/code/client/keys.js +15 -0
  95. package/kits/hub-game/code/client/labelsNear.js +8 -1
  96. package/kits/hub-game/code/client/layoutCache.js +57 -8
  97. package/kits/hub-game/code/client/loadingCover.js +53 -4
  98. package/kits/hub-game/code/client/menuIcons.js +15 -0
  99. package/kits/hub-game/code/client/menuSurface.js +102 -0
  100. package/kits/hub-game/code/client/menuTree.js +135 -0
  101. package/kits/hub-game/code/client/modelLook.js +41 -0
  102. package/kits/hub-game/code/client/padCues.js +11 -7
  103. package/kits/hub-game/code/client/padReadability.js +3 -3
  104. package/kits/hub-game/code/client/pickerSurface.js +152 -0
  105. package/kits/hub-game/code/client/pickerTree.js +163 -0
  106. package/kits/hub-game/code/client/pushVisit.js +4 -2
  107. package/kits/hub-game/code/client/quality.js +188 -29
  108. package/kits/hub-game/code/client/qualityEntry.js +10 -1
  109. package/kits/hub-game/code/client/quickChatSurface.js +222 -0
  110. package/kits/hub-game/code/client/quickChatTree.js +201 -0
  111. package/kits/hub-game/code/client/rehello.js +75 -0
  112. package/kits/hub-game/code/client/renderVisibility.js +17 -0
  113. package/kits/hub-game/code/client/replay.js +118 -0
  114. package/kits/hub-game/code/client/role.js +3 -0
  115. package/kits/hub-game/code/client/safeLayout.js +441 -56
  116. package/kits/hub-game/code/client/safeStyle.js +13 -10
  117. package/kits/hub-game/code/client/say.js +2 -0
  118. package/kits/hub-game/code/client/soundSurface.js +77 -0
  119. package/kits/hub-game/code/client/soundTree.js +74 -0
  120. package/kits/hub-game/code/client/soundscape.js +12 -9
  121. package/kits/hub-game/code/client/soundscapeCues.js +1 -1
  122. package/kits/hub-game/code/client/state.js +67 -1
  123. package/kits/hub-game/code/client/stuckSurface.js +76 -0
  124. package/kits/hub-game/code/client/stuckTree.js +67 -0
  125. package/kits/hub-game/code/client/talk.js +42 -12
  126. package/kits/hub-game/code/client/talkTree.js +4 -2
  127. package/kits/hub-game/code/client/textAskSurface.js +147 -0
  128. package/kits/hub-game/code/client/textAskTree.js +67 -0
  129. package/kits/hub-game/code/client/tiers.js +252 -27
  130. package/kits/hub-game/code/client/together.js +4 -1
  131. package/kits/hub-game/code/client/uiDom.js +86 -8
  132. package/kits/hub-game/code/client/uiTree.js +33 -4
  133. package/kits/hub-game/code/client/vehicle.js +72 -51
  134. package/kits/hub-game/code/client/weakestTier.js +75 -31
  135. package/kits/hub-game/code/client/wear.js +159 -5
  136. package/kits/hub-game/code/client/worldLabels.js +205 -25
  137. package/kits/hub-game/code/companionSpec.js +4 -2
  138. package/kits/hub-game/code/server/act.js +3 -0
  139. package/kits/hub-game/code/server/actGate.js +83 -0
  140. package/kits/hub-game/code/server/actions.js +71 -15
  141. package/kits/hub-game/code/server/actors.js +20 -5
  142. package/kits/hub-game/code/server/analytics.js +35 -3
  143. package/kits/hub-game/code/server/ask.js +39 -3
  144. package/kits/hub-game/code/server/ballot.js +167 -4
  145. package/kits/hub-game/code/server/celebrate.js +64 -0
  146. package/kits/hub-game/code/server/companion.js +17 -2
  147. package/kits/hub-game/code/server/decor.js +11 -2
  148. package/kits/hub-game/code/server/disguise.js +63 -0
  149. package/kits/hub-game/code/server/earned.js +6 -2
  150. package/kits/hub-game/code/server/friendBests.js +13 -4
  151. package/kits/hub-game/code/server/friendsAmong.js +67 -8
  152. package/kits/hub-game/code/server/grab.js +12 -2
  153. package/kits/hub-game/code/server/heldOffers.js +142 -0
  154. package/kits/hub-game/code/server/holdShow.js +98 -0
  155. package/kits/hub-game/code/server/hub.js +991 -72
  156. package/kits/hub-game/code/server/idle.js +110 -9
  157. package/kits/hub-game/code/server/index.js +9 -0
  158. package/kits/hub-game/code/server/labels.js +13 -3
  159. package/kits/hub-game/code/server/manifest.js +94 -6
  160. package/kits/hub-game/code/server/menu.js +26 -3
  161. package/kits/hub-game/code/server/npcs.js +55 -9
  162. package/kits/hub-game/code/server/observe.js +67 -6
  163. package/kits/hub-game/code/server/players.js +14 -2
  164. package/kits/hub-game/code/server/replay.js +135 -0
  165. package/kits/hub-game/code/server/standing.js +7 -3
  166. package/kits/hub-game/code/server/storageLimit.js +4 -1
  167. package/kits/hub-game/code/server/townDay.js +74 -0
  168. package/kits/hub-game/code/server/vehicle.js +3 -0
  169. package/kits/hub-game/code/server/vis.js +26 -4
  170. package/kits/hub-game/code/server/wallet.js +677 -0
  171. package/kits/hub-game/code/server/wear.js +13 -3
  172. package/kits/hub-game/code/server/writerLease.js +191 -0
  173. package/kits/hub-game/code/shared/act.js +1 -1
  174. package/kits/hub-game/code/shared/expression.js +6 -0
  175. package/kits/hub-game/code/shared/replay.js +37 -0
  176. package/kits/hub-game/code/systems/hub.js +429 -55
  177. package/kits/hub-game/docs/analytics.md +16 -2
  178. package/kits/hub-game/docs/contract.md +956 -101
  179. package/kits/hub-game/docs/home-pieces.md +5 -6
  180. package/kits/hub-game/docs/observed-progress.md +49 -1
  181. package/kits/hub-game/docs/vehicle-preset.md +23 -0
  182. package/kits/hub-game/index.html +1 -0
  183. package/kits/hub-game/models/hats/baker-cap.pxmodel +3 -3
  184. package/kits/hub-game/models/hats/bat-clip.pxmodel +3 -3
  185. package/kits/hub-game/models/hats/beekeeper.pxmodel +3 -3
  186. package/kits/hub-game/models/hats/cap.pxmodel +3 -3
  187. package/kits/hub-game/models/hats/captain.pxmodel +3 -3
  188. package/kits/hub-game/models/hats/chef-toque.pxmodel +3 -3
  189. package/kits/hub-game/models/hats/crooked-top.pxmodel +3 -3
  190. package/kits/hub-game/models/hats/delivery-cap.pxmodel +3 -3
  191. package/kits/hub-game/models/hats/fire-helmet.pxmodel +3 -3
  192. package/kits/hub-game/models/hats/flower-crown.pxmodel +3 -3
  193. package/kits/hub-game/models/hats/foam-crown.pxmodel +3 -3
  194. package/kits/hub-game/models/hats/hard-hat.pxmodel +3 -3
  195. package/kits/hub-game/models/hats/lantern.pxmodel +3 -3
  196. package/kits/hub-game/models/hats/laurel.pxmodel +3 -3
  197. package/kits/hub-game/models/hats/lighthouse.pxmodel +3 -3
  198. package/kits/hub-game/models/hats/nurse-cap.pxmodel +3 -3
  199. package/kits/hub-game/models/hats/police-cap.pxmodel +3 -3
  200. package/kits/hub-game/models/hats/sailor.pxmodel +3 -3
  201. package/kits/hub-game/models/hats/souwester.pxmodel +3 -3
  202. package/kits/hub-game/models/hats/straw.pxmodel +3 -3
  203. package/kits/hub-game/models/hats/sunflower.pxmodel +3 -3
  204. package/kits/hub-game/models/hats/sweatband.pxmodel +3 -3
  205. package/kits/hub-game/models/hats/teacher-beret.pxmodel +3 -3
  206. package/kits/hub-game/models/hats/witch.pxmodel +3 -3
  207. package/kits/hub-game/models/hold-show/daisy.pxmodel +231 -0
  208. package/kits/hub-game/models/hold-show/moonflower.pxmodel +171 -0
  209. package/kits/hub-game/models/hold-show/rose.pxmodel +191 -0
  210. package/kits/hub-game/models/hold-show/square/daisy.pxmodel +233 -0
  211. package/kits/hub-game/models/hold-show/square/moonflower.pxmodel +173 -0
  212. package/kits/hub-game/models/hold-show/square/rose.pxmodel +193 -0
  213. package/kits/hub-game/models/hold-show/square/sunflower.pxmodel +313 -0
  214. package/kits/hub-game/models/hold-show/square/tulip.pxmodel +133 -0
  215. package/kits/hub-game/models/hold-show/sunflower.pxmodel +311 -0
  216. package/kits/hub-game/models/hold-show/tulip.pxmodel +131 -0
  217. package/kits/hub-game/package-lock.json +3 -3
  218. package/kits/hub-game/package.json +4 -3
  219. package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +1 -0
  220. package/kits/hub-game/scripts/fixtures/hud-surface.json +12 -12
  221. package/kits/hub-game/scripts/fixtures/talk-surface.json +8 -8
  222. package/kits/hub-game/scripts/gen-hats.mjs +1 -1
  223. package/kits/hub-game/scripts/gen-hold-show.mjs +27 -0
  224. package/kits/hub-game/scripts/pack.mjs +89 -23
  225. package/kits/hub-game/scripts/test-act-client.mjs +5 -0
  226. package/kits/hub-game/scripts/test-act-core.mjs +32 -0
  227. package/kits/hub-game/scripts/test-act-gate.mjs +186 -0
  228. package/kits/hub-game/scripts/test-action-rail-crowded-dom.mjs +7 -1
  229. package/kits/hub-game/scripts/test-action-rail-default-dom.mjs +102 -0
  230. package/kits/hub-game/scripts/test-action-rail-never-silent-dom.mjs +50 -0
  231. package/kits/hub-game/scripts/test-action-rail-surface.mjs +368 -0
  232. package/kits/hub-game/scripts/test-action-rail-town-jobs-dom.mjs +118 -0
  233. package/kits/hub-game/scripts/test-actions-client.mjs +5 -3
  234. package/kits/hub-game/scripts/test-actions.mjs +24 -0
  235. package/kits/hub-game/scripts/test-actors.mjs +19 -0
  236. package/kits/hub-game/scripts/test-again-corner-dom.mjs +59 -0
  237. package/kits/hub-game/scripts/test-analytics.mjs +79 -0
  238. package/kits/hub-game/scripts/test-arrival-pose-server.mjs +25 -8
  239. package/kits/hub-game/scripts/test-ask-client.mjs +9 -0
  240. package/kits/hub-game/scripts/test-ask-surface.mjs +188 -0
  241. package/kits/hub-game/scripts/test-attention.mjs +43 -1
  242. package/kits/hub-game/scripts/test-ballot-sheet-dom.mjs +71 -0
  243. package/kits/hub-game/scripts/test-ballot-surface.mjs +276 -0
  244. package/kits/hub-game/scripts/test-ballot.mjs +421 -4
  245. package/kits/hub-game/scripts/test-ban-join.mjs +1 -1
  246. package/kits/hub-game/scripts/test-celebrate-client.mjs +62 -0
  247. package/kits/hub-game/scripts/test-celebrate.mjs +116 -0
  248. package/kits/hub-game/scripts/test-chat.mjs +73 -0
  249. package/kits/hub-game/scripts/test-companion-client.mjs +203 -21
  250. package/kits/hub-game/scripts/test-companion.mjs +110 -3
  251. package/kits/hub-game/scripts/test-control-layout-dom.mjs +57 -10
  252. package/kits/hub-game/scripts/test-corner-surface.mjs +268 -0
  253. package/kits/hub-game/scripts/test-decor-client.mjs +59 -3
  254. package/kits/hub-game/scripts/test-decor.mjs +27 -0
  255. package/kits/hub-game/scripts/test-device-class.mjs +4 -1
  256. package/kits/hub-game/scripts/test-disguise-client.mjs +281 -0
  257. package/kits/hub-game/scripts/test-disguise.mjs +176 -0
  258. package/kits/hub-game/scripts/test-dock-surface.mjs +404 -0
  259. package/kits/hub-game/scripts/test-door-stay-client.mjs +602 -0
  260. package/kits/hub-game/scripts/test-door-stay.mjs +613 -0
  261. package/kits/hub-game/scripts/test-earned-client.mjs +119 -0
  262. package/kits/hub-game/scripts/test-emote-surface.mjs +616 -0
  263. package/kits/hub-game/scripts/test-fps-telemetry.mjs +39 -4
  264. package/kits/hub-game/scripts/test-friend-bests.mjs +38 -12
  265. package/kits/hub-game/scripts/test-ghost-click-dom.mjs +75 -0
  266. package/kits/hub-game/scripts/test-grab-client.mjs +29 -2
  267. package/kits/hub-game/scripts/test-grab-orbit.mjs +260 -11
  268. package/kits/hub-game/scripts/test-grab.mjs +10 -1
  269. package/kits/hub-game/scripts/test-hats.mjs +28 -0
  270. package/kits/hub-game/scripts/test-held-offers.mjs +394 -0
  271. package/kits/hub-game/scripts/test-high-only.mjs +3 -3
  272. package/kits/hub-game/scripts/test-hold-show-client.mjs +175 -0
  273. package/kits/hub-game/scripts/test-hold-show.mjs +355 -0
  274. package/kits/hub-game/scripts/test-hub-controls.mjs +3 -1
  275. package/kits/hub-game/scripts/test-hub-idle.mjs +348 -0
  276. package/kits/hub-game/scripts/test-hub-leaving.mjs +21 -0
  277. package/kits/hub-game/scripts/test-hub-ops.mjs +119 -0
  278. package/kits/hub-game/scripts/test-hub-trip.mjs +240 -4
  279. package/kits/hub-game/scripts/test-hud-clear.mjs +83 -0
  280. package/kits/hub-game/scripts/test-hud-rate.mjs +2 -1
  281. package/kits/hub-game/scripts/test-idle.mjs +160 -0
  282. package/kits/hub-game/scripts/test-invites-client.mjs +53 -0
  283. package/kits/hub-game/scripts/test-labels.mjs +11 -0
  284. package/kits/hub-game/scripts/test-landscape-layout.mjs +20 -0
  285. package/kits/hub-game/scripts/test-loading-cover.mjs +67 -1
  286. package/kits/hub-game/scripts/test-manifest.mjs +27 -0
  287. package/kits/hub-game/scripts/test-menu-client.mjs +54 -5
  288. package/kits/hub-game/scripts/test-menu-surface.mjs +236 -0
  289. package/kits/hub-game/scripts/test-npcs.mjs +128 -0
  290. package/kits/hub-game/scripts/test-observed.mjs +171 -3
  291. package/kits/hub-game/scripts/test-pack.mjs +166 -0
  292. package/kits/hub-game/scripts/test-pad-cues.mjs +39 -0
  293. package/kits/hub-game/scripts/test-picker-surface.mjs +321 -0
  294. package/kits/hub-game/scripts/test-placeat-server.mjs +648 -0
  295. package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
  296. package/kits/hub-game/scripts/test-pointer-clear-dom.mjs +82 -0
  297. package/kits/hub-game/scripts/test-progress-reset.mjs +184 -6
  298. package/kits/hub-game/scripts/test-push-visit.mjs +9 -0
  299. package/kits/hub-game/scripts/test-quality.mjs +312 -9
  300. package/kits/hub-game/scripts/test-quick-chat-surface.mjs +511 -0
  301. package/kits/hub-game/scripts/test-rehello.mjs +242 -3
  302. package/kits/hub-game/scripts/test-rejoin-yaw.mjs +138 -0
  303. package/kits/hub-game/scripts/test-relations-among.mjs +13 -7
  304. package/kits/hub-game/scripts/test-relations-refresh.mjs +90 -2
  305. package/kits/hub-game/scripts/test-replay-client.mjs +110 -0
  306. package/kits/hub-game/scripts/test-replay.mjs +178 -0
  307. package/kits/hub-game/scripts/test-resume-held.mjs +13 -0
  308. package/kits/hub-game/scripts/test-resume-pose-server.mjs +43 -5
  309. package/kits/hub-game/scripts/test-role-client.mjs +2 -1
  310. package/kits/hub-game/scripts/test-safe-act.mjs +233 -0
  311. package/kits/hub-game/scripts/test-safe-caption.mjs +364 -0
  312. package/kits/hub-game/scripts/test-safe-layout.mjs +79 -0
  313. package/kits/hub-game/scripts/test-safe-prompt.mjs +163 -0
  314. package/kits/hub-game/scripts/test-sound-surface.mjs +256 -0
  315. package/kits/hub-game/scripts/test-soundscape.mjs +85 -2
  316. package/kits/hub-game/scripts/test-standing.mjs +135 -2
  317. package/kits/hub-game/scripts/test-stuck-surface.mjs +174 -0
  318. package/kits/hub-game/scripts/test-stuck.mjs +36 -1
  319. package/kits/hub-game/scripts/test-talk-surface.mjs +23 -6
  320. package/kits/hub-game/scripts/test-talk-walk-dom.mjs +123 -0
  321. package/kits/hub-game/scripts/test-text-ask-surface.mjs +273 -0
  322. package/kits/hub-game/scripts/test-tiers.mjs +453 -3
  323. package/kits/hub-game/scripts/test-toast-no-row-dom.mjs +71 -0
  324. package/kits/hub-game/scripts/test-together.mjs +11 -0
  325. package/kits/hub-game/scripts/test-town-day.mjs +90 -0
  326. package/kits/hub-game/scripts/test-try-on.mjs +39 -0
  327. package/kits/hub-game/scripts/test-ui-dom-dom.mjs +49 -2
  328. package/kits/hub-game/scripts/test-ui-tree.mjs +28 -0
  329. package/kits/hub-game/scripts/test-vehicle-client.mjs +68 -1
  330. package/kits/hub-game/scripts/test-vis.mjs +145 -0
  331. package/kits/hub-game/scripts/test-wallet.mjs +650 -0
  332. package/kits/hub-game/scripts/test-weakest-tier.mjs +135 -1
  333. package/kits/hub-game/scripts/test-world-labels.mjs +340 -0
  334. package/kits/hub-game/scripts/test-writer-lease-server.mjs +234 -0
  335. package/kits/hub-game/scripts/test-writer-lease.mjs +281 -0
  336. package/kits/hub-game/scripts/writer-storage-fixture.mjs +37 -0
  337. package/kits/hub-game/tools/hubScene/export.mjs +6 -5
  338. package/kits/hub-game/tools/hubScene/hubdata.mjs +10 -0
  339. package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +36 -2
  340. package/kits/hub-game/tools/hubScene/validate-manifest.mjs +10 -2
  341. package/kits/multiplayer-3d/castle.json +5 -5
  342. package/kits/multiplayer-3d/code/client/resumeGate.js +66 -2
  343. package/kits/multiplayer-3d/code/server/ownership.js +25 -6
  344. package/kits/multiplayer-3d/code/server/world.js +19 -4
  345. package/kits/multiplayer-3d/code/systems/multiplayer.js +108 -18
  346. package/kits/multiplayer-3d/package-lock.json +1 -1
  347. package/kits/multiplayer-3d/package.json +2 -1
  348. package/kits/multiplayer-3d/scripts/test-ground-half.mjs +56 -0
  349. package/kits/multiplayer-3d/scripts/test-join-watchdog.mjs +54 -3
  350. package/kits/multiplayer-3d/scripts/test-owned-moves.mjs +190 -0
  351. package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +417 -5
  352. package/kits/multiplayer-3d/scripts/test-resync-reconnect.mjs +68 -0
  353. package/kits/physics-2d/castle.json +2 -2
  354. package/kits/physics-2d/engine/scene.js +10 -2
  355. package/kits/physics-3d/CLAUDE.md +14 -0
  356. package/kits/physics-3d/behaviors/Player.jsx +39 -3
  357. package/kits/physics-3d/castle.json +3 -3
  358. package/kits/physics-3d/docs/engine-model-cache.md +109 -0
  359. package/kits/physics-3d/docs/engine-player.md +76 -0
  360. package/kits/physics-3d/docs/engine-skip-work.md +16 -0
  361. package/kits/physics-3d/docs/pxmodel-format.md +5 -1
  362. package/kits/physics-3d/engine3d/gait.js +16 -8
  363. package/kits/physics-3d/engine3d/groundsize.js +23 -0
  364. package/kits/physics-3d/engine3d/kithooks.js +50 -0
  365. package/kits/physics-3d/engine3d/look.js +110 -17
  366. package/kits/physics-3d/engine3d/lookbake.js +19 -1
  367. package/kits/physics-3d/engine3d/materialpresets.js +3 -2
  368. package/kits/physics-3d/engine3d/modelcache.js +280 -0
  369. package/kits/physics-3d/engine3d/modelcachedigest.js +37 -0
  370. package/kits/physics-3d/engine3d/modelcachegate.js +69 -0
  371. package/kits/physics-3d/engine3d/modelrefs.js +13 -0
  372. package/kits/physics-3d/engine3d/optimize.js +20 -9
  373. package/kits/physics-3d/engine3d/playerRun.js +26 -1
  374. package/kits/physics-3d/engine3d/pxmodel.js +7 -3
  375. package/kits/physics-3d/engine3d/templatecache.js +722 -0
  376. package/kits/physics-3d/engine3d/world3d.js +211 -17
  377. package/kits/physics-3d/package-lock.json +1 -1
  378. package/kits/physics-3d/package.json +2 -1
  379. package/kits/physics-3d/play/behaviors/Player.js +43 -3
  380. package/kits/physics-3d/scripts/render.mjs +56 -8
  381. package/kits/physics-3d/scripts/template-cache-fixtures.mjs +37 -0
  382. package/kits/physics-3d/scripts/template-cache-v1-bytes.json +49 -0
  383. package/kits/physics-3d/scripts/test-coaxial-escape.mjs +176 -0
  384. package/kits/physics-3d/scripts/test-gait.mjs +53 -9
  385. package/kits/physics-3d/scripts/test-ground-half.mjs +120 -0
  386. package/kits/physics-3d/scripts/test-model-cache.mjs +600 -0
  387. package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1 -0
  388. package/kits/physics-3d/scripts/test-sleeping-models.mjs +384 -0
  389. package/kits/physics-3d/scripts/test-template-cache-minified.mjs +106 -0
  390. package/kits/physics-3d/scripts/test-template-cache.mjs +519 -0
  391. package/kits/physics-3d/scripts/test-wall-slide.mjs +272 -0
  392. package/kits/physics-3d/systems/physics3d.js +59 -2
  393. package/kits/real-time/castle.json +2 -2
  394. package/kits/real-time/code/client/connection.js +3 -0
  395. package/package.json +2 -2
  396. package/vendor/three/examples/jsm/libs/fflate.module.js +2672 -0
@@ -240,6 +240,33 @@ test('manifest refuses malformed bounds, layers, ids, unknown fields and house s
240
240
  assert.equal(Manifest.readManifest(json({ house })).manifest, null);
241
241
  }
242
242
  });
243
+ test('action tiles route pick without stock, refuse locked/non-action/missing ids and share the op budget', () => {
244
+ const r = boot({ decor });
245
+ r.say('p1', { k: 'decor', op: 'pick', item: 'build' });
246
+ r.hub.decor.open('p1', { ...spec(), items: [item, { ...item, id: 'build', action: true, count: 0 },
247
+ { ...item, id: 'locked', action: true, locked: { price: '120 ▲' } }] });
248
+ for (const id of ['chair', 'locked', 'missing']) r.say('p1', { k: 'decor', op: 'pick', item: id });
249
+ r.say('p2', { k: 'decor', op: 'pick', item: 'build' });
250
+ r.say('p1', { k: 'decor', op: 'pick', item: 'build', extra: true });
251
+ assert.deepEqual(r.ops, []);
252
+ r.say('p1', { k: 'decor', op: 'pick', item: 'build' });
253
+ assert.deepEqual(r.ops, [['p1', { op: 'pick', item: 'build' }]], 'zero stock still routes the action');
254
+ r.ops.length = 0;
255
+ r.tick(1000);
256
+ r.hub.decor.update('p1', { items: [{ ...item, id: 'build', action: true }] });
257
+ r.say('p1', { k: 'decor', op: 'place', item: 'build', x: 0, z: 0, rot: 0 });
258
+ assert.deepEqual(r.ops, [], 'actions cannot be placed even with stock');
259
+ for (let i = 0; i < 10; i++) r.say('p1', { k: 'decor', op: 'pick', item: 'build' });
260
+ assert.deepEqual(r.ops, Array.from({ length: 8 }, () => ['p1', { op: 'pick', item: 'build' }]));
261
+ r.say('p1', { k: 'decor', op: 'close' });
262
+ assert.equal(r.ops.length, 8, 'pick spends the ordinary budget');
263
+ r.tick(1000);
264
+ r.say('p1', { k: 'decor', op: 'pick', item: 'build' });
265
+ assert.equal(r.ops.length, 9);
266
+ for (const change of [{ action: false }, { action: 'true' }, { action: true, count: undefined }, { action: true, w: 0 }, { action: true, layer: 'missing' }]) {
267
+ assert.throws(() => r.hub.decor.open('p1', { ...spec(), items: [{ ...item, ...change }] }), TypeError);
268
+ }
269
+ });
243
270
  test('exact catalogue limits are accepted; malformed rotated bounds and duplicate ids are refused', () => {
244
271
  const h = { actors, place: { decor: { ...decor, grid: { ...decor.grid, w: 16, d: 16 } } }, spawned: new Map(Array.from({ length: 64 }, (_, i) => [`copy-${i}`, {}])) };
245
272
  const max = {
@@ -55,7 +55,10 @@ console.log('device class layout, edges, invalid inputs, presence and round trip
55
55
 
56
56
  // Run the actual hello method without loading the rendering engine.
57
57
  const source = readFileSync(new URL('../code/systems/hub.js', import.meta.url), 'utf8');
58
- const method = source.slice(source.indexOf(' sendHello(scene,'), source.indexOf('\n // Hide what the place hid'));
58
+ // The method alone: from its signature to its own closing brace, whatever
59
+ // the class puts after it.
60
+ const helloAt = source.indexOf(' sendHello(scene,');
61
+ const method = source.slice(helloAt, source.indexOf('\n }\n', helloAt) + 4);
59
62
  function hello(globals = {}, encoder = encode) {
60
63
  const messages = [];
61
64
  const context = { ...globals, encodeDeviceClass: encoder, Hub: { hub: {}, deck: {} },
@@ -0,0 +1,281 @@
1
+ // Disguise v1.196: real model build, controller seam, seats and cleanup.
2
+ import assert from 'node:assert/strict';
3
+ import fs from 'node:fs';
4
+ import { register } from 'node:module';
5
+ import { Group, PerspectiveCamera, Scene, SpriteMaterial } from 'three';
6
+ const root = new URL('../../', import.meta.url).href;
7
+ register(`data:text/javascript,${encodeURIComponent(`
8
+ export async function resolve(specifier, context, next) {
9
+ if (specifier === 'three') return { url: ${JSON.stringify(import.meta.resolve('three'))}, shortCircuit: true };
10
+ if (specifier === '@imports/castle.physics-2d/engine/art') return { url: 'data:text/javascript,export const renderArtFrame=()=>null;export const artReady=()=>false;export const artFrameCount=()=>0;', shortCircuit: true };
11
+ if (specifier.startsWith('@imports/')) {
12
+ const file = specifier.replace('@imports/castle.', '');
13
+ return { url: ${JSON.stringify(root)} + file + (file.endsWith('.js') ? '' : '.js'), shortCircuit: true };
14
+ }
15
+ try {return await next(specifier, context);} catch(e) {
16
+ if (specifier.startsWith('.') && !specifier.endsWith('.js')) return next(specifier + '.js', context);
17
+ throw e;
18
+ }
19
+ }
20
+ `)}`);
21
+ const { makeInstances, drawInstances, removeInstances } = await import('@imports/castle.physics-3d/engine3d/optimize');
22
+ const { buildModelNode, parseModelCached } = await import('@imports/castle.physics-3d/engine3d/pxmodel');
23
+ const { makeDisguise } = await import('../code/client/disguiseDraw.js');
24
+ const { makeFarAvatars } = await import('../code/client/farAvatars.js');
25
+ const { canCacheStill } = await import('@imports/castle.physics-3d/engine3d/stillshadows');
26
+ const { disguiseMap, disguisedFor, disguiseBody } = await import('../code/client/disguise.js');
27
+ const { deck, hub, clear } = await import('../code/client/state.js');
28
+ const { applyPlayerVisibility, filterQualityScene, makeQualityVisit, qualityPlayers, resetQualityVisit } = await import('../code/client/quality.js');
29
+ const { makeWear, makeEarned, makeRole, makeHoldShow } = await import('../code/client/wear.js');
30
+ const { makeSay } = await import('../code/client/say.js');
31
+ const { makeIdle } = await import('../code/client/idle.js');
32
+ const { makeCompanion } = await import('../code/client/companion.js');
33
+ const { roleItems } = await import('../code/client/role.js');
34
+ const model = JSON.stringify({ format: 'pxmodel', parts: [{ id: 'box', kind: 'box', width: 1, height: 1, depth: 1, color: '#00ff00' }] });
35
+ function boot(viewer = 'me') {
36
+ clear();
37
+ const local = { id: 'local', components: { Player: {}, Transform: { x: 0, y: 0, z: 0 } } };
38
+ const other = { id: 'other', components: { Transform: { x: 1, y: 0, z: 1 } } };
39
+ const look = { id: 'look', components: { Model: { file: 'look.pxmodel', scale: 2, yOffset: 0.2 } } };
40
+ const actors = new Map([local, other, look].map(a => [a.id, a]));
41
+ const nodes = new Map();
42
+ for (const actor of [local, other]) {
43
+ const node = new Group(), rig = new Group(), hidden = new Group(), wearable = new Group();
44
+ rig.userData.modelParts = new Map(); node.userData.modelParts = rig.userData.modelParts;
45
+ hidden.visible = false; node.add(rig, hidden, wearable); nodes.set(actor.id, { node });
46
+ }
47
+ const material = new SpriteMaterial(), tags = new Map([['p', { sprite: { material } }]]);
48
+ const scene = { files: { 'look.pxmodel': model }, sprites: {},
49
+ getActor: id => actors.get(id), actorWith: () => local,
50
+ three: { nodes, scene: new Scene(), camera: new PerspectiveCamera() },
51
+ multiplayer: { net: { selfId: () => viewer }, avatars: { actors: new Map([['p', 'other']]), tags } },
52
+ };
53
+ return { scene, local, nodes, material, view: makeDisguise() };
54
+ }
55
+ const rows = to => [['p', 'look', to]];
56
+ {
57
+ // An unused visit keeps still-shadow caching and the exact callback it received.
58
+ const { scene, local, nodes, view } = boot(), root = scene.three.scene;
59
+ const original = root.onBeforeRender;
60
+ const renderer = { shadowMap: { render() {} }, capabilities: {}, renderBufferDirect() {} };
61
+ assert.equal(canCacheStill(renderer, root), true);
62
+ view.draw(scene, local); view.draw(scene, local);
63
+ assert.equal(root.onBeforeRender, original); assert.equal(canCacheStill(renderer, root), true);
64
+ hub.disguises = disguiseMap(rows(null)); view.draw(scene, local);
65
+ assert.notEqual(root.onBeforeRender, original); assert.equal(canCacheStill(renderer, root), false);
66
+ hub.disguises.clear(); view.draw(scene, local);
67
+ assert.equal(root.onBeforeRender, original); assert.equal(canCacheStill(renderer, root), true);
68
+ assert.equal(nodes.get('other').node.children[0].visible, true);
69
+ let calls = 0;
70
+ const previous = function () {assert.equal(this, root); calls++;};
71
+ root.onBeforeRender = previous;
72
+ hub.disguises = disguiseMap(rows(null)); view.draw(scene, local);
73
+ const render = root.onBeforeRender;
74
+ render.call(root); assert.equal(calls, 1);
75
+ hub.disguises.clear(); render.call(root);
76
+ assert.equal(calls, 2); assert.equal(root.onBeforeRender, previous, 'render-time clear restores the previous callback');
77
+ assert.equal(nodes.get('other').node.children[0].visible, true);
78
+ hub.disguises = disguiseMap(rows(null)); view.draw(scene, local); view.clear();
79
+ assert.equal(root.onBeforeRender, previous, 'lifecycle cleanup restores the previous callback');
80
+ }
81
+ {
82
+ // A disguise cleared under the Low cull's hook unhooks once on top again, so High
83
+ // gives the original back: neither hook outlives its owner in either order.
84
+ const { scene, local, view } = boot(), root = scene.three.scene, original = root.onBeforeRender;
85
+ let tier = 'high';
86
+ const q = makeQualityVisit({ current: () => tier }); q.warned = true;
87
+ const quality = deck.quality; deck.quality = { low: { players: 1 } };
88
+ scene.getActors = () => []; filterQualityScene(scene, { actors: [] }, q);
89
+ hub.disguises = disguiseMap(rows(null)); view.draw(scene, local);
90
+ tier = 'low'; qualityPlayers(scene, q, 0);
91
+ hub.disguises.clear(); view.draw(scene, local); root.onBeforeRender();
92
+ tier = 'high'; qualityPlayers(scene, q, 1); root.onBeforeRender();
93
+ assert.equal(root.onBeforeRender, original, 'a disguise cleared under Low leaves no hook');
94
+ tier = 'low'; qualityPlayers(scene, q, 2);
95
+ hub.disguises = disguiseMap(rows(null)); view.draw(scene, local);
96
+ tier = 'high'; qualityPlayers(scene, q, 3); root.onBeforeRender();
97
+ hub.disguises.clear(); view.draw(scene, local); root.onBeforeRender();
98
+ assert.equal(root.onBeforeRender, original, 'a Low hook released under a disguise leaves no hook');
99
+ deck.quality = quality;
100
+ }
101
+ {
102
+ // Far-avatar and disguise hides release independently, including under a Low cull.
103
+ for (const farFirst of [true, false]) {
104
+ const { scene, local, nodes, material, view } = boot();
105
+ const root = scene.three.scene, entry = nodes.get('other'), rig = entry.node.children[0];
106
+ const template = buildModelNode(parseModelCached(model), {}, {}, 'look.pxmodel', ['look.pxmodel'], { optimize: true });
107
+ entry.modelKey = 'avatar'; scene.three.models = new Map([['avatar', { template }]]);
108
+ for (const { node } of nodes.values()) {root.add(node);}
109
+ entry.node.position.x = 20;
110
+ const far = makeFarAvatars(), q = makeQualityVisit({ current: () => 'low' });
111
+ far.update(scene, ['other'], 'local', true, 0);
112
+ assert.equal(far.size, 1); assert.equal(rig.visible, false);
113
+ hub.disguises = disguiseMap(rows(null)); view.draw(scene, local);
114
+ q.culled.add('other'); applyPlayerVisibility(scene, q);
115
+ if (farFirst) {
116
+ entry.node.position.x = 2; far.update(scene, ['other'], 'local', true, 250);
117
+ assert.equal(far.size, 0); assert.equal(rig.visible, false, 'disguise retains its hide after the far owner releases');
118
+ view.draw(scene, local);
119
+ hub.disguises.clear(); view.draw(scene, local);
120
+ assert.equal(rig.visible, true, 'no owner still hides the rig');
121
+ } else {
122
+ hub.disguises.clear(); view.draw(scene, local);
123
+ assert.equal(rig.visible, false, 'the far owner retains its hide after disguise clears');
124
+ entry.node.position.x = 2; far.update(scene, ['other'], 'local', true, 250);
125
+ assert.equal(far.size, 0); assert.equal(rig.visible, true);
126
+ }
127
+ assert.equal(entry.node.visible, false); assert.equal(material.visible, false, 'quality remains hidden');
128
+ resetQualityVisit(q);
129
+ assert.equal(entry.node.visible, true); assert.equal(rig.visible, true); assert.equal(material.visible, true);
130
+ far.clear(); view.clear();
131
+ }
132
+ }
133
+ {
134
+ const { scene, local, nodes, material, view } = boot();
135
+ const node = nodes.get('other').node, [rig, hidden, wearable] = node.children;
136
+ view.draw(scene, local); assert.equal(node.children.length, 3);
137
+ hub.disguises = disguiseMap(rows(null)); view.draw(scene, local);
138
+ const group = node.children.find(c => c.name === 'hub:disguise');
139
+ assert.ok(group); assert.equal(group.visible, true); assert.equal(group.children[0].scale.x, 2); assert.equal(group.children[0].position.y, 0.2);
140
+ assert.equal(rig.visible, false); assert.equal(hidden.visible, false); assert.equal(wearable.visible, false);
141
+ assert.equal(material.visible, false); assert.equal(node.visible, true);
142
+ view.draw(scene, local); assert.equal(node.children.find(c => c.name === 'hub:disguise'), group);
143
+ hub.disguises.clear(); view.draw(scene, local);
144
+ assert.equal(group.parent, null); assert.equal(rig.visible, true); assert.equal(hidden.visible, false); assert.equal(wearable.visible, true); assert.equal(material.visible, true);
145
+ view.clear();
146
+ }
147
+ {
148
+ const { scene, local, nodes, material, view } = boot();
149
+ const node = nodes.get('other').node;
150
+ hub.disguises = disguiseMap(rows(['someone'])); view.draw(scene, local);
151
+ assert.equal(node.children.length, 3); assert.equal(material.visible, true);
152
+ hub.disguises = disguiseMap(rows(['me'])); view.draw(scene, local);
153
+ assert.equal(node.children.at(-1).name, 'hub:disguise'); assert.equal(material.visible, false);
154
+ hub.disguises = disguiseMap([['p', null, ['me']]]); view.draw(scene, local);
155
+ assert.equal(node.children.length, 3); assert.equal(node.children[0].visible, true); assert.equal(node.children[2].visible, true); assert.equal(material.visible, false);
156
+ assert.equal(disguisedFor('me', 'p'), true); assert.equal(disguiseBody('me', 'p'), false);
157
+ hub.disguises = disguiseMap(rows([])); view.draw(scene, local); assert.equal(material.visible, true);
158
+ view.clear();
159
+ }
160
+ {
161
+ const { scene, local, nodes, view } = boot('p');
162
+ const node = nodes.get('local').node, [rig, , wearable] = node.children;
163
+ for (const to of [null, [], ['p'], ['someone']]) {
164
+ hub.disguises = disguiseMap(rows(to)); view.draw(scene, local);
165
+ assert.ok(node.children.find(c => c.name === 'hub:disguise'));
166
+ assert.equal(rig.visible, false); assert.equal(wearable.visible, true);
167
+ assert.equal(disguisedFor('p', 'p'), false); assert.equal(disguiseBody('p', 'p'), false);
168
+ }
169
+ hub.disguises = disguiseMap([['p', null, null]]); view.draw(scene, local); assert.equal(rig.visible, true);
170
+ view.clear();
171
+ }
172
+ {
173
+ // Render-time replacement cannot flash, and the old clone is released.
174
+ const { scene, local, nodes, view } = boot();
175
+ hub.disguises = disguiseMap(rows(null)); view.draw(scene, local);
176
+ const old = nodes.get('other').node.children.at(-1), node = new Group(), rig = new Group();
177
+ node.add(rig); nodes.set('other', { node });
178
+ scene.three.scene.onBeforeRender();
179
+ assert.equal(old.parent, null); assert.equal(rig.visible, false); assert.equal(node.children.at(-1).name, 'hub:disguise');
180
+ view.clear(); assert.equal(rig.visible, true); assert.equal(node.children.length, 1);
181
+ }
182
+ {
183
+ // The two owners of a name material may hide/restore in either order.
184
+ for (const qualityFirst of [true, false]) {
185
+ const { scene, local, nodes, material, view } = boot();
186
+ const q = makeQualityVisit({ current: () => 'low' }); q.culled.add('other');
187
+ hub.disguises = disguiseMap(rows(null));
188
+ if (qualityFirst) {applyPlayerVisibility(scene, q); view.draw(scene, local);}
189
+ else {view.draw(scene, local); applyPlayerVisibility(scene, q);}
190
+ assert.equal(nodes.get('other').node.visible, false); assert.equal(material.visible, false);
191
+ scene.three.scene.onBeforeRender(); assert.equal(nodes.get('other').node.visible, false);
192
+ hub.disguises.clear(); view.draw(scene, local);
193
+ assert.equal(material.visible, false, 'clearing disguise keeps quality hidden');
194
+ resetQualityVisit(q); assert.equal(material.visible, true); assert.equal(nodes.get('other').node.visible, true);
195
+ hub.disguises = disguiseMap(rows(null)); view.draw(scene, local); q.culled.add('other'); applyPlayerVisibility(scene, q);
196
+ resetQualityVisit(q); assert.equal(material.visible, false, 'clearing quality keeps disguise hidden');
197
+ view.clear(); assert.equal(material.visible, true);
198
+ }
199
+ const { scene, local, material, view } = boot(); material.visible = false;
200
+ hub.disguises = disguiseMap(rows(null)); view.draw(scene, local); view.clear(); assert.equal(material.visible, false, 'pre-existing hide is preserved');
201
+ }
202
+ {
203
+ assert.equal(disguiseMap(Array(300).fill(['p', null, null])).size, 1);
204
+ assert.equal(disguiseMap(Array.from({ length: 300 }, (_, i) => [`p${i}`, null, null])).size, 256);
205
+ assert.equal(disguiseMap([null, [], [1, null, null], ['p', 1, null], ['p', null, [1]], ['p', null, Array(257).fill('v')], ['p', null, Array(1)]]).size, 0);
206
+ const to = ['b', 'a', 'b']; const map = disguiseMap([['p', null, to]]); to.push('c');
207
+ assert.deepEqual(map.get('p').to, ['a', 'b']);
208
+ // Run hookLayer's actual field parser, including absent-place cleanup.
209
+ const source = fs.readFileSync(new URL('../code/client/hookLayer.js', import.meta.url), 'utf8');
210
+ const a = source.indexOf(" if (Object.hasOwn(msg, 'hubDisguise'))");
211
+ const b = source.indexOf(' // v1.6:', a);
212
+ const receive = Function('msg', 'hub', 'disguiseMap', source.slice(a, b));
213
+ receive({ hubDisguise: rows(null) }, hub, disguiseMap); assert.equal(hub.disguises.get('p').look, 'look');
214
+ receive({}, hub, disguiseMap); assert.equal(hub.disguises.size, 1);
215
+ receive({ hubPlace: {} }, hub, disguiseMap); assert.equal(hub.disguises.size, 0);
216
+ receive({ hubDisguise: [] }, hub, disguiseMap); assert.equal(hub.disguises.size, 0);
217
+ }
218
+ {
219
+ const { scene, local } = boot();
220
+ const wear = makeWear(), earned = makeEarned(), role = makeRole(), flowers = makeHoldShow();
221
+ const items = new Map([['p', { kind: 'aura', color: '#00ff00', rarity: 1 }]]);
222
+ wear.frame(scene, local, items); assert.ok(scene.three.nodes.get('other').node.children.length > 3);
223
+ hub.disguises = disguiseMap(rows(null)); wear.frame(scene, local, items);
224
+ assert.equal(scene.three.nodes.get('other').node.children.length, 3);
225
+ const fit = () => null;
226
+ earned.frame(scene, local, new Map([['p', { class: 'held', shape: 'flower', color: '#00ff00' }]]), fit);
227
+ role.frame(scene, local, new Map([['p', { top: 'vest', tool: 'torch', color: '#00ff00' }]]), fit);
228
+ flowers.frame(scene, local, new Map([['p', { shape: 'flower', color: '#00ff00' }]]), fit);
229
+ assert.equal(earned.size, 0); assert.equal(role.size, 0); assert.equal(flowers.size, 0);
230
+ const project = () => ({ x: 1, y: 1 });
231
+ const roles = new Map([['p', { label: 'Role', color: '#00ff00' }]]);
232
+ assert.deepEqual(roleItems(scene, local, {}, {}, roles, project), []);
233
+ const source = fs.readFileSync(new URL('../code/systems/hub.js', import.meta.url), 'utf8');
234
+ const a = source.indexOf(' markItems(scene, local, cam, view) {'), b = source.indexOf(' measure(', a);
235
+ const marks = Function('Hub', 'disguiseTags', 'project', 'return ({' + source.slice(a, b) + '});');
236
+ const { disguiseTags } = await import('../code/client/disguise.js');
237
+ hub.marks = { p: { text: 'Mark' } };
238
+ assert.deepEqual(marks({ hub }, disguiseTags, project).markItems(scene, local, {}, {}), []);
239
+ hub.disguises = disguiseMap([['p', null, null]]); wear.frame(scene, local, items);
240
+ assert.ok(scene.three.nodes.get('other').node.children.length > 3, 'look-less keeps wearables');
241
+ assert.deepEqual(roleItems(scene, local, {}, {}, roles, project), []);
242
+ wear.clear(); earned.clear(); role.clear(); flowers.clear();
243
+ }
244
+ {
245
+ const { scene, local } = boot(), project = () => ({ x: 1, y: 1 });
246
+ const say = makeSay(), idle = makeIdle({}), companion = makeCompanion();
247
+ hub.saidEvents.push({ player: 'p', r: 0 }); say.frame(0, 'me', () => 'Player');
248
+ hub.lastT = 0; hub.lastAt = performance.now();
249
+ hub.emotes = { p: { id: 'wave', at: 0, until: 2000 } };
250
+ hub.glow = new Set(['p']); hub.avatars = new Map([['p', 0]]);
251
+ const bubbles = () => say.labels(scene, local, {}, {}, project, 'me');
252
+ const emotes = () => idle.labels(scene, local, {}, {}, project);
253
+ const drawCompanion = () => companion.frame(scene, local, hub, 0.016, 0, true);
254
+ assert.equal(bubbles().length, 1); assert.equal(emotes().length, 1);
255
+ drawCompanion(); assert.equal(scene.three.nodes.get('other').node.children.length, 4);
256
+ hub.disguises = disguiseMap(rows(null));
257
+ assert.equal(bubbles().length, 0); assert.equal(emotes().length, 0);
258
+ drawCompanion(); assert.equal(scene.three.nodes.get('other').node.children.length, 3);
259
+ hub.disguises = disguiseMap([['p', null, null]]);
260
+ assert.equal(bubbles().length, 1); assert.equal(emotes().length, 1);
261
+ drawCompanion(); assert.equal(scene.three.nodes.get('other').node.children.length, 4);
262
+ hub.disguises.clear(); companion.dispose(); idle.release(); say.clear();
263
+ }
264
+ {
265
+ const { scene, local, nodes, view } = boot();
266
+ const template = buildModelNode(parseModelCached(model), {}, {}, 'look.pxmodel');
267
+ const instances = makeInstances(template, scene.three.scene), rig = nodes.get('other').node.children[0];
268
+ scene.three.camera = null; scene.three.instances = new Map([['avatar', instances]]);
269
+ instances.rigs.add(rig); drawInstances(instances, null);
270
+ assert.ok(instances.parts.every(part => part.mesh.count > 0));
271
+ view.draw(scene, local);
272
+ hub.disguises = disguiseMap(rows(null)); view.draw(scene, local); scene.three.scene.onBeforeRender();
273
+ assert.ok(instances.parts.every(part => part.mesh.count === 0), 'shared original model is hidden before render');
274
+ hub.disguises.clear(); view.draw(scene, local);
275
+ assert.ok(instances.parts.every(part => part.mesh.count > 0), 'shared model restored');
276
+ hub.disguises = disguiseMap(rows(null)); view.draw(scene, local); view.clear();
277
+ assert.ok(instances.parts.every(part => part.mesh.count > 0), 'cleanup restores shared model');
278
+ removeInstances(instances);
279
+ }
280
+ clear(); assert.equal(hub.disguises.size, 0);
281
+ console.log('ok: disguise wire, viewer/self selection, clones, restoration, late render, quality and decorations');
@@ -0,0 +1,176 @@
1
+ // Disguise v1.196: real hub layer, fake transport/body, no Rapier needed.
2
+ import assert from 'node:assert/strict';
3
+ import { register } from 'node:module';
4
+ const sceneStub = 'export const readScene = () => globalThis.__hubTestActors ?? [];';
5
+ register(`data:text/javascript,${encodeURIComponent(`
6
+ export async function resolve(specifier, context, next) {
7
+ if (specifier === '@imports/castle.multiplayer-3d/code/server/sceneBodies.js') return { url: ${JSON.stringify('data:text/javascript,' + encodeURIComponent(sceneStub))}, shortCircuit: true };
8
+ if (specifier === '@imports/castle.multiplayer-3d/code/server/players.js') return { url: 'data:text/javascript,export function setPose(sim,id,msg){sim.reports.push([id,msg])}', shortCircuit: true };
9
+ if (specifier === '@imports/castle.multiplayer-3d/code/server/limits.js') return { url: 'data:text/javascript,export const readPoint=()=>null', shortCircuit: true };
10
+ return next(specifier, context);
11
+ }
12
+ `)}`);
13
+ const { layer } = await import('../code/server/hub.js');
14
+ const { hubPlayers } = await import('../code/server/players.js');
15
+ const spec = { look: 'car', seats: [[1, 0, 1], [-1, 0.3, 0]], horn: 'sounds/horn.wav' };
16
+ let clock = 1_800_000_000_000;
17
+ const realNow = Date.now;
18
+ Date.now = () => clock;
19
+ function boot({ retained = false, count = 3, arrived = true, grab = false, grabHook } = {}) {
20
+ globalThis.__hubTestActors = [
21
+ { id: 'spawn', components: { Player: {}, Transform: { x: 0, y: 1, z: 0 } } },
22
+ { id: 'car', components: { Model: { file: 'car.pxmodel' }, Transform: {} } },
23
+ { id: 'bench', components: { HubSeat: {}, Transform: {}, Shape: { kind: 'box', height: 0.3 } } },
24
+ { id: 'door', components: { HubDoor: { id: 'game', to: 'game' }, Transform: {} } },
25
+ ...(grab ? [{ id: 'crate', components: { Transform: { x: 0, y: 1, z: 1 }, Shape: { kind: 'box' }, Body: { type: 'dynamic' } } }] : []),
26
+ ];
27
+ const sent = [], broadcast = [], left = [];
28
+ const players = Array.from({ length: count }, (_, i) => ({ playerId: `p${i + 1}`, username: `user${i}`, userId: `${i + 1}` }));
29
+ const session = { sessionId: 'dev', players: [...players], send: (id, msg) => sent.push([id, msg]), broadcast: msg => broadcast.push(msg) };
30
+ const body = () => ({ at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
31
+ const sim = { timeMs: 0, scenePath: retained ? 'scenes/game.scene' : 'scenes/main.scene', players: new Map(players.map(p => [p.playerId, body()])), objects: new Map(), bodies: new Map(), reports: [] };
32
+ let hub;
33
+ const opts = { title: 'Town', contract: 1, stuck: true, idle: { seats: true, sounds: ['sounds/horn.wav'] }, places: { game: { title: 'Game', scene: 'scenes/game.scene', result: {}, ...(retained ? { resume: { keep: true } } : {}) } } };
34
+ if (grab) {opts.grab = grab;}
35
+ if (retained) {session.place = 'game'; opts.places.game.idle = opts.idle;}
36
+ // resolvePlace reads session's authoritative place field.
37
+ const hooks = { ready(ctx) {hub = ctx;}, leave(ctx, id) {left.push(id);}, grab: grabHook };
38
+ const server = layer({ server: { maxPlayers: Math.max(8, count) }, hub: opts }, hooks, { game: hooks }, () => true);
39
+ server.sceneFor(session); server.ready(sim);
40
+ const say = (id, data) => server.message(session, { playerId: id }, data);
41
+ const tick = (ms = 50) => {sim.timeMs += ms; clock += ms; server.place(sim); server.step(sim, []);};
42
+ if (arrived) {players.forEach(p => say(p.playerId, { k: 'hub-hello', avatar: 0, party: 1 }));
43
+ tick(2000); tick(5000);}
44
+ for (const p of sim.players.values()) {p.at = { x: 0, y: 1, z: 0 };}
45
+ const drop = id => {session.players.splice(session.players.findIndex(p => p.playerId === id), 1); sim.players.delete(id);};
46
+ const back = id => {session.players.push(players.find(p => p.playerId === id)); sim.players.set(id, body()); say(id, { k: 'hub-hello', avatar: 0, party: 1, resume: true });};
47
+ return { hub, server, sim, session, sent, broadcast, say, tick, drop, back, left };
48
+ }
49
+ let n = 0;
50
+ function test(name, fn) {fn(); n++; console.log(`ok: ${name}`);}
51
+ try {
52
+ test('unused snapshot and delta remain byte-identical', () => {
53
+ const r = boot(), snapshot = JSON.stringify(r.server.join());
54
+ assert.equal(r.hub.disguised('p1'), null);
55
+ assert.equal(JSON.stringify(r.server.join()), snapshot);
56
+ assert.equal(Object.hasOwn(JSON.parse(snapshot), 'hubDisguise'), false);
57
+ r.server.delta(); const before = JSON.stringify(r.server.delta());
58
+ r.hub.disguised('p1'); assert.equal(JSON.stringify(r.server.delta()), before);
59
+ r.tick(); assert.equal(Object.hasOwn(r.server.delta() ?? {}, 'hubDisguise'), false);
60
+ });
61
+ test('set/read copies, sorting, latch, clear and empty field after first use', () => {
62
+ const r = boot(); r.server.delta();
63
+ const to = ['p3', 'p2', 'p3'];
64
+ assert.equal(r.hub.disguise('p2', { look: 'car', to }), true);
65
+ to.push('p1');
66
+ assert.equal(r.hub.disguise('p1', {}), true);
67
+ const copy = r.hub.disguised('p2'); copy.to.push('other'); copy.look = 'other';
68
+ assert.deepEqual(r.hub.disguised('p2'), { look: 'car', to: ['p2', 'p3'] });
69
+ assert.deepEqual(r.server.delta().hubDisguise, [['p1', null, null], ['p2', 'car', ['p2', 'p3']]]);
70
+ assert.equal(r.server.delta(), null);
71
+ r.tick(250); assert.equal(r.hub.disguise('p1', null), true); assert.equal(r.hub.disguise('p2', null), true);
72
+ assert.equal(r.hub.disguised('p1'), null);
73
+ assert.deepEqual(r.server.delta().hubDisguise, []);
74
+ assert.deepEqual(r.server.join().hubDisguise, []);
75
+ assert.equal(r.server.delta(), null);
76
+ const fresh = boot(); assert.equal(fresh.hub.disguise('p1', null), true);
77
+ assert.deepEqual(fresh.server.join().hubDisguise, []);
78
+ });
79
+ test('shape, look, to bounds, presence and held refusals warn once', () => {
80
+ const r = boot(), warnings = [], previous = console.warn;
81
+ console.warn = text => warnings.push(text);
82
+ try {
83
+ for (const value of [undefined, false, 'car', [], { other: 1 }, { look: null }, { look: 'bench' },
84
+ { to: null }, { to: 'p2' }, { to: [1] }, { to: Array(1) }, { to: Array(257).fill('p2') }]) {
85
+ assert.equal(r.hub.disguise('p1', value), false);
86
+ }
87
+ const count = warnings.length;
88
+ r.hub.disguise('p1', { to: [1] }); assert.equal(warnings.length, count);
89
+ assert.equal(r.hub.disguise('unknown', {}), false);
90
+ assert.equal(r.hub.disguise('p1', { look: 'car' }), true); r.hub.hold('p1'); assert.equal(r.hub.disguise('p1', {}), false);
91
+ assert.equal(r.hub.disguise('p1', null), true); assert.equal(r.hub.disguised('p1'), null); r.hub.release('p1');
92
+ assert.equal(boot({ arrived: false }).hub.disguise('p1', {}), false);
93
+ assert.equal(r.hub.disguise('p1', { to: Array.from({ length: 256 }, (_, i) => `viewer${i}`) }), true);
94
+ assert.equal(r.hub.disguised('p1').to.length, 256);
95
+ } finally {console.warn = previous;}
96
+ });
97
+ test('drivers/riders refuse disguise; disguised walkers refuse drive and ride', () => {
98
+ const r = boot();
99
+ assert.equal(r.hub.drive('p1', spec), true); assert.equal(r.hub.ride('p2', 'p1', 1), true);
100
+ assert.equal(r.hub.disguise('p1', {}), false); assert.equal(r.hub.disguise('p2', { look: 'car' }), false);
101
+ assert.equal(r.hub.disguise('p3', { look: 'car' }), true);
102
+ assert.equal(r.hub.drive('p3', spec), false);
103
+ r.hub.ride('p2', null); assert.equal(r.hub.ride('p3', 'p1', 1), false);
104
+ r.hub.disguise('p3', null); assert.equal(r.hub.ride('p3', 'p1', 1), true);
105
+ });
106
+ test('grab and look disguise refuse each other, including a disguise inside the grab hook', () => {
107
+ const start = (grab, grabHook) => {
108
+ const r = boot({ grab, grabHook });
109
+ r.sim.objects.set('crate', { owner: 'p1', claimable: true, body: { translation: () => ({ x: 0, y: 1, z: 1 }) } });
110
+ return r;
111
+ };
112
+ for (const grab of [true, { keepHeld: true }]) {
113
+ const r = start(grab);
114
+ r.say('p1', { k: 'hub-grab', actor: 'crate', op: 'grab' });
115
+ assert.equal(r.hub.holding('p1'), 'crate');
116
+ assert.equal(r.hub.disguise('p1', { look: 'car' }), false);
117
+ assert.equal(r.hub.disguised('p1'), null);
118
+ assert.equal(r.hub.disguise('p1', {}), true, 'tag-only disguise may start during an existing grab');
119
+ assert.equal(r.hub.holding('p1'), 'crate');
120
+ r.say('p1', { k: 'hub-grab', actor: 'crate', op: 'throw' });
121
+ assert.equal(r.hub.holding('p1'), null, 'existing grabs may still be thrown');
122
+ {
123
+ const t = start(grab); assert.equal(t.hub.disguise('p1', {}), true);
124
+ t.say('p1', { k: 'hub-grab', actor: 'crate', op: 'grab' });
125
+ assert.equal(t.hub.holding('p1'), 'crate', 'a tag-only disguise may grab');
126
+ }
127
+ for (const spec of [{ look: 'car' }]) {
128
+ let asked = 0;
129
+ const s = start(grab, () => {asked++;});
130
+ assert.equal(s.hub.disguise('p1', spec), true);
131
+ s.say('p1', { k: 'hub-grab', actor: 'crate', op: 'grab' });
132
+ assert.equal(s.hub.holding('p1'), null); assert.equal(asked, 0);
133
+ assert.ok(s.sent.some(([id, msg]) => id === 'p1' && msg.k === 'hub-grab-deny' && msg.actor === 'crate'));
134
+ s.hub.disguise('p1', null); s.say('p1', { k: 'hub-grab', actor: 'crate', op: 'grab' });
135
+ assert.equal(s.hub.holding('p1'), 'crate'); assert.equal(asked, 1);
136
+ }
137
+ const s = start(grab, (ctx, id) => {assert.equal(ctx.disguise(id, { look: 'car' }), true);});
138
+ s.say('p1', { k: 'hub-grab', actor: 'crate', op: 'grab' });
139
+ assert.equal(s.hub.holding('p1'), null); assert.ok(s.hub.disguised('p1'));
140
+ assert.ok(s.sent.some(([, msg]) => msg.k === 'hub-grab-deny'));
141
+ if (grab.keepHeld) {assert.equal(s.sim.objects.get('crate').claimable, true, 'refused grab never pins the actor');}
142
+ }
143
+ });
144
+ test('250 ms latest-value coalescing is independent per player', () => {
145
+ const r = boot(); r.server.delta();
146
+ r.hub.disguise('p1', { look: 'car' }); assert.deepEqual(r.server.delta().hubDisguise, [['p1', 'car', null]]);
147
+ r.tick(100); r.hub.disguise('p1', { to: ['p2'] }); r.hub.disguise('p1', { to: ['p3'] });
148
+ assert.deepEqual(r.hub.disguised('p1'), { look: null, to: ['p3'] });
149
+ assert.equal(Object.hasOwn(r.server.delta() ?? {}, 'hubDisguise'), false);
150
+ r.hub.disguise('p2', {}); assert.deepEqual(r.server.delta().hubDisguise, [['p1', 'car', null], ['p2', null, null]]);
151
+ r.tick(149); assert.equal(Object.hasOwn(r.server.delta() ?? {}, 'hubDisguise'), false);
152
+ r.tick(1); assert.deepEqual(r.server.delta().hubDisguise, [['p1', null, ['p3']], ['p2', null, null]]);
153
+ r.hub.disguise('p1', null); assert.equal(Object.hasOwn(r.server.delta() ?? {}, 'hubDisguise'), false);
154
+ r.tick(250); assert.deepEqual(r.server.delta().hubDisguise, [['p2', null, null]]);
155
+ });
156
+ test('leave/forget, kit trip, end and changed account clear the visit disguise', () => {
157
+ let r = boot(); r.hub.disguise('p1', {}); r.server.delta(); r.drop('p1'); r.tick();
158
+ assert.equal(r.hub.disguised('p1'), null); assert.deepEqual(r.server.delta().hubDisguise, []);
159
+ r = boot(); r.hub.disguise('p1', {}); r.hub.go('game', ['p1']);
160
+ assert.equal(r.hub.disguised('p1'), null); assert.equal(r.hub.disguise('p1', {}), false);
161
+ r = boot(); r.hub.disguise('p1', {}); r.hub.end(['p1']); assert.equal(r.hub.disguised('p1'), null);
162
+ assert.equal(r.hub.disguise('p1', {}), false);
163
+ r = boot(); r.hub.disguise('p1', {}); r.server.join();
164
+ r.session.players.find(p => p.playerId === 'p1').userId = 'replacement'; r.tick();
165
+ assert.equal(r.hub.disguised('p1'), null); assert.deepEqual(r.server.join().hubDisguise, []);
166
+ });
167
+ test('retained resume keeps disguise; expiry clears it', () => {
168
+ const r = boot({ retained: true }); r.hub.disguise('p1', { look: 'car' });
169
+ r.drop('p1'); r.tick(); r.tick(30000);
170
+ assert.deepEqual(r.hub.disguised('p1'), { look: 'car', to: null });
171
+ r.back('p1'); r.tick(); assert.deepEqual(r.server.join().hubDisguise, [['p1', 'car', null]]); assert.deepEqual(r.left, []);
172
+ r.drop('p1'); r.tick(); r.tick(60000); assert.equal(r.hub.disguised('p1'), null); assert.deepEqual(r.left, ['p1']);
173
+ });
174
+ const r = boot(); r.hub.disguise('p1', {}); await r.server.shutdown(); assert.equal(r.hub.disguised('p1'), null);
175
+ } finally {Date.now = realNow;}
176
+ console.log(`ok: ${n} disguise server cases`);