castle-web-cli 0.4.238 → 0.4.240

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (404) hide show
  1. package/dist/agent.js +5 -1
  2. package/dist/api.d.ts +20 -0
  3. package/dist/api.js +57 -0
  4. package/dist/bundle.d.ts +38 -1
  5. package/dist/bundle.js +309 -13
  6. package/dist/castle-host/host.js +218 -11
  7. package/dist/castleJson.d.ts +10 -0
  8. package/dist/castleJson.js +46 -2
  9. package/dist/check.js +5 -2
  10. package/dist/devSessionServer.js +4 -1
  11. package/dist/devSessionStorage.d.ts +1 -0
  12. package/dist/devSessionStorage.js +32 -7
  13. package/dist/importOrder.d.ts +2 -0
  14. package/dist/importOrder.js +29 -0
  15. package/dist/index.js +22 -3
  16. package/dist/init.js +24 -2
  17. package/dist/multiplayerDoc.d.ts +1 -1
  18. package/dist/multiplayerDoc.js +9 -0
  19. package/dist/platformDoc.js +4 -2
  20. package/dist/playPagePolicy.d.ts +1 -0
  21. package/dist/playPagePolicy.js +12 -3
  22. package/dist/resetLeaderboards.d.ts +8 -1
  23. package/dist/resetLeaderboards.js +43 -8
  24. package/dist/roomLogs.d.ts +39 -0
  25. package/dist/roomLogs.js +166 -0
  26. package/dist/save-deck.d.ts +32 -2
  27. package/dist/save-deck.js +240 -39
  28. package/kits/base/CLAUDE.md +2 -1
  29. package/kits/base/castle.json +1 -1
  30. package/kits/base/sdk/README.md +240 -8
  31. package/kits/base/sdk/analytics.d.ts +8 -0
  32. package/kits/base/sdk/analytics.js +92 -0
  33. package/kits/base/sdk/castle.d.ts +8 -2
  34. package/kits/base/sdk/castle.js +3 -0
  35. package/kits/base/sdk/commands.d.ts +79 -0
  36. package/kits/base/sdk/commands.js +1 -0
  37. package/kits/base/sdk/debugConsole.d.ts +17 -0
  38. package/kits/base/sdk/debugConsole.js +154 -0
  39. package/kits/base/sdk/experiments.js +24 -1
  40. package/kits/base/sdk/hostRetry.d.ts +7 -0
  41. package/kits/base/sdk/hostRetry.js +57 -0
  42. package/kits/base/sdk/hub.d.ts +20 -2
  43. package/kits/base/sdk/hub.js +99 -13
  44. package/kits/base/sdk/multiplayer.d.ts +2 -0
  45. package/kits/base/sdk/multiplayer.js +198 -26
  46. package/kits/base/sdk/reconnectBudget.d.ts +6 -0
  47. package/kits/base/sdk/reconnectBudget.js +41 -1
  48. package/kits/base/sdk/rooms.d.ts +11 -0
  49. package/kits/base/sdk/rooms.js +22 -0
  50. package/kits/base/sdk/runtime.js +36 -19
  51. package/kits/base/sdk/server/hub.d.ts +19 -0
  52. package/kits/base/sdk/server/hub.js +12 -0
  53. package/kits/base/sdk/server/platformHandle.d.ts +1 -0
  54. package/kits/base/sdk/server/wrapper.d.ts +1 -1
  55. package/kits/base/sdk/server/wrapper.js +26 -1
  56. package/kits/base/sdk/store.d.ts +8 -2
  57. package/kits/base/sdk/store.js +5 -1
  58. package/kits/base/sdk/transport.d.ts +2 -1
  59. package/kits/base/sdk/transport.js +35 -0
  60. package/kits/hub-game/CLAUDE.md +66 -19
  61. package/kits/hub-game/castle.json +4 -4
  62. package/kits/hub-game/code/client/act.js +9 -6
  63. package/kits/hub-game/code/client/actCore.js +26 -6
  64. package/kits/hub-game/code/client/actGateLog.js +36 -0
  65. package/kits/hub-game/code/client/actionOverflow.js +29 -8
  66. package/kits/hub-game/code/client/actionRailSurface.js +186 -0
  67. package/kits/hub-game/code/client/actionRailTree.js +173 -0
  68. package/kits/hub-game/code/client/askSurface.js +85 -0
  69. package/kits/hub-game/code/client/askTree.js +51 -0
  70. package/kits/hub-game/code/client/attention.js +31 -6
  71. package/kits/hub-game/code/client/ballot.js +42 -5
  72. package/kits/hub-game/code/client/ballotSurface.js +115 -0
  73. package/kits/hub-game/code/client/ballotTree.js +180 -0
  74. package/kits/hub-game/code/client/catchingUp.js +19 -0
  75. package/kits/hub-game/code/client/celebrate.js +66 -0
  76. package/kits/hub-game/code/client/chrome.js +474 -53
  77. package/kits/hub-game/code/client/companion.js +93 -23
  78. package/kits/hub-game/code/client/companionDress.js +1 -1
  79. package/kits/hub-game/code/client/cornerSurface.js +106 -0
  80. package/kits/hub-game/code/client/cornerTree.js +83 -0
  81. package/kits/hub-game/code/client/decor.js +20 -11
  82. package/kits/hub-game/code/client/deviceStorage.js +121 -0
  83. package/kits/hub-game/code/client/disguise.js +23 -0
  84. package/kits/hub-game/code/client/disguiseDraw.js +87 -0
  85. package/kits/hub-game/code/client/dockSurface.js +206 -0
  86. package/kits/hub-game/code/client/dockTree.js +232 -0
  87. package/kits/hub-game/code/client/earned.js +29 -0
  88. package/kits/hub-game/code/client/emoteSurface.js +188 -0
  89. package/kits/hub-game/code/client/emoteTree.js +264 -0
  90. package/kits/hub-game/code/client/farAvatars.js +4 -3
  91. package/kits/hub-game/code/client/fpsTelemetry.js +3 -1
  92. package/kits/hub-game/code/client/grab.js +121 -50
  93. package/kits/hub-game/code/client/holdShow.js +19 -0
  94. package/kits/hub-game/code/client/hookLayer.js +96 -12
  95. package/kits/hub-game/code/client/hubControls.js +7 -1
  96. package/kits/hub-game/code/client/hudSurface.js +11 -3
  97. package/kits/hub-game/code/client/hudTree.js +7 -4
  98. package/kits/hub-game/code/client/idle.js +21 -3
  99. package/kits/hub-game/code/client/invites.js +24 -3
  100. package/kits/hub-game/code/client/keys.js +15 -0
  101. package/kits/hub-game/code/client/labelsNear.js +8 -1
  102. package/kits/hub-game/code/client/layoutCache.js +57 -8
  103. package/kits/hub-game/code/client/loadingCover.js +53 -4
  104. package/kits/hub-game/code/client/menuIcons.js +15 -0
  105. package/kits/hub-game/code/client/menuRows.js +8 -2
  106. package/kits/hub-game/code/client/menuSurface.js +102 -0
  107. package/kits/hub-game/code/client/menuTree.js +135 -0
  108. package/kits/hub-game/code/client/modelLook.js +41 -0
  109. package/kits/hub-game/code/client/pickerSurface.js +152 -0
  110. package/kits/hub-game/code/client/pickerTree.js +163 -0
  111. package/kits/hub-game/code/client/pushVisit.js +4 -2
  112. package/kits/hub-game/code/client/quality.js +188 -29
  113. package/kits/hub-game/code/client/qualityEntry.js +10 -1
  114. package/kits/hub-game/code/client/quickChatSurface.js +222 -0
  115. package/kits/hub-game/code/client/quickChatTree.js +201 -0
  116. package/kits/hub-game/code/client/rehello.js +75 -0
  117. package/kits/hub-game/code/client/renderVisibility.js +17 -0
  118. package/kits/hub-game/code/client/replay.js +118 -0
  119. package/kits/hub-game/code/client/role.js +3 -0
  120. package/kits/hub-game/code/client/safeLayout.js +441 -56
  121. package/kits/hub-game/code/client/safeStyle.js +13 -10
  122. package/kits/hub-game/code/client/say.js +2 -0
  123. package/kits/hub-game/code/client/soundSurface.js +77 -0
  124. package/kits/hub-game/code/client/soundTree.js +74 -0
  125. package/kits/hub-game/code/client/soundscape.js +12 -9
  126. package/kits/hub-game/code/client/soundscapeCues.js +1 -1
  127. package/kits/hub-game/code/client/state.js +67 -1
  128. package/kits/hub-game/code/client/stuckSurface.js +76 -0
  129. package/kits/hub-game/code/client/stuckTree.js +67 -0
  130. package/kits/hub-game/code/client/talk.js +42 -12
  131. package/kits/hub-game/code/client/talkTree.js +4 -2
  132. package/kits/hub-game/code/client/textAskSurface.js +147 -0
  133. package/kits/hub-game/code/client/textAskTree.js +67 -0
  134. package/kits/hub-game/code/client/tiers.js +252 -27
  135. package/kits/hub-game/code/client/together.js +4 -1
  136. package/kits/hub-game/code/client/uiDom.js +86 -8
  137. package/kits/hub-game/code/client/uiTree.js +33 -4
  138. package/kits/hub-game/code/client/vehicle.js +75 -52
  139. package/kits/hub-game/code/client/weakestTier.js +75 -31
  140. package/kits/hub-game/code/client/wear.js +159 -5
  141. package/kits/hub-game/code/client/worldLabels.js +215 -26
  142. package/kits/hub-game/code/companionSpec.js +4 -2
  143. package/kits/hub-game/code/server/act.js +3 -0
  144. package/kits/hub-game/code/server/actGate.js +83 -0
  145. package/kits/hub-game/code/server/actions.js +71 -15
  146. package/kits/hub-game/code/server/actors.js +20 -5
  147. package/kits/hub-game/code/server/analytics.js +40 -15
  148. package/kits/hub-game/code/server/ask.js +39 -3
  149. package/kits/hub-game/code/server/ballot.js +167 -4
  150. package/kits/hub-game/code/server/celebrate.js +64 -0
  151. package/kits/hub-game/code/server/companion.js +17 -2
  152. package/kits/hub-game/code/server/decor.js +11 -2
  153. package/kits/hub-game/code/server/disguise.js +63 -0
  154. package/kits/hub-game/code/server/doorAnalytics.js +2 -5
  155. package/kits/hub-game/code/server/earned.js +6 -2
  156. package/kits/hub-game/code/server/friendBests.js +13 -4
  157. package/kits/hub-game/code/server/friendsAmong.js +67 -8
  158. package/kits/hub-game/code/server/grab.js +12 -2
  159. package/kits/hub-game/code/server/heldOffers.js +142 -0
  160. package/kits/hub-game/code/server/holdShow.js +98 -0
  161. package/kits/hub-game/code/server/hub.js +854 -45
  162. package/kits/hub-game/code/server/idle.js +110 -9
  163. package/kits/hub-game/code/server/index.js +9 -0
  164. package/kits/hub-game/code/server/labels.js +13 -3
  165. package/kits/hub-game/code/server/loadAbandon.js +2 -5
  166. package/kits/hub-game/code/server/manifest.js +94 -6
  167. package/kits/hub-game/code/server/menu.js +26 -3
  168. package/kits/hub-game/code/server/npcs.js +55 -9
  169. package/kits/hub-game/code/server/observe.js +67 -6
  170. package/kits/hub-game/code/server/players.js +8 -1
  171. package/kits/hub-game/code/server/replay.js +135 -0
  172. package/kits/hub-game/code/server/storageLimit.js +4 -1
  173. package/kits/hub-game/code/server/townDay.js +74 -0
  174. package/kits/hub-game/code/server/trackQueue.js +29 -0
  175. package/kits/hub-game/code/server/vehicle.js +3 -0
  176. package/kits/hub-game/code/server/vis.js +26 -4
  177. package/kits/hub-game/code/server/wallet.js +677 -0
  178. package/kits/hub-game/code/server/wear.js +13 -3
  179. package/kits/hub-game/code/server/writerLease.js +191 -0
  180. package/kits/hub-game/code/shared/act.js +1 -1
  181. package/kits/hub-game/code/shared/expression.js +6 -0
  182. package/kits/hub-game/code/shared/replay.js +37 -0
  183. package/kits/hub-game/code/systems/hub.js +437 -57
  184. package/kits/hub-game/docs/analytics.md +20 -3
  185. package/kits/hub-game/docs/contract.md +942 -99
  186. package/kits/hub-game/docs/home-pieces.md +5 -6
  187. package/kits/hub-game/docs/observed-progress.md +49 -1
  188. package/kits/hub-game/docs/vehicle-preset.md +23 -0
  189. package/kits/hub-game/index.html +1 -0
  190. package/kits/hub-game/models/hats/baker-cap.pxmodel +3 -3
  191. package/kits/hub-game/models/hats/bat-clip.pxmodel +3 -3
  192. package/kits/hub-game/models/hats/beekeeper.pxmodel +3 -3
  193. package/kits/hub-game/models/hats/cap.pxmodel +3 -3
  194. package/kits/hub-game/models/hats/captain.pxmodel +3 -3
  195. package/kits/hub-game/models/hats/chef-toque.pxmodel +3 -3
  196. package/kits/hub-game/models/hats/crooked-top.pxmodel +3 -3
  197. package/kits/hub-game/models/hats/delivery-cap.pxmodel +3 -3
  198. package/kits/hub-game/models/hats/fire-helmet.pxmodel +3 -3
  199. package/kits/hub-game/models/hats/flower-crown.pxmodel +3 -3
  200. package/kits/hub-game/models/hats/foam-crown.pxmodel +3 -3
  201. package/kits/hub-game/models/hats/hard-hat.pxmodel +3 -3
  202. package/kits/hub-game/models/hats/lantern.pxmodel +3 -3
  203. package/kits/hub-game/models/hats/laurel.pxmodel +3 -3
  204. package/kits/hub-game/models/hats/lighthouse.pxmodel +3 -3
  205. package/kits/hub-game/models/hats/nurse-cap.pxmodel +3 -3
  206. package/kits/hub-game/models/hats/police-cap.pxmodel +3 -3
  207. package/kits/hub-game/models/hats/sailor.pxmodel +3 -3
  208. package/kits/hub-game/models/hats/souwester.pxmodel +3 -3
  209. package/kits/hub-game/models/hats/straw.pxmodel +3 -3
  210. package/kits/hub-game/models/hats/sunflower.pxmodel +3 -3
  211. package/kits/hub-game/models/hats/sweatband.pxmodel +3 -3
  212. package/kits/hub-game/models/hats/teacher-beret.pxmodel +3 -3
  213. package/kits/hub-game/models/hats/witch.pxmodel +3 -3
  214. package/kits/hub-game/models/hold-show/daisy.pxmodel +231 -0
  215. package/kits/hub-game/models/hold-show/moonflower.pxmodel +171 -0
  216. package/kits/hub-game/models/hold-show/rose.pxmodel +191 -0
  217. package/kits/hub-game/models/hold-show/square/daisy.pxmodel +233 -0
  218. package/kits/hub-game/models/hold-show/square/moonflower.pxmodel +173 -0
  219. package/kits/hub-game/models/hold-show/square/rose.pxmodel +193 -0
  220. package/kits/hub-game/models/hold-show/square/sunflower.pxmodel +313 -0
  221. package/kits/hub-game/models/hold-show/square/tulip.pxmodel +133 -0
  222. package/kits/hub-game/models/hold-show/sunflower.pxmodel +311 -0
  223. package/kits/hub-game/models/hold-show/tulip.pxmodel +131 -0
  224. package/kits/hub-game/package-lock.json +3 -3
  225. package/kits/hub-game/package.json +4 -3
  226. package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +1 -0
  227. package/kits/hub-game/scripts/fixtures/hud-surface.json +12 -12
  228. package/kits/hub-game/scripts/fixtures/talk-surface.json +8 -8
  229. package/kits/hub-game/scripts/gen-hats.mjs +1 -1
  230. package/kits/hub-game/scripts/gen-hold-show.mjs +27 -0
  231. package/kits/hub-game/scripts/pack.mjs +89 -23
  232. package/kits/hub-game/scripts/test-act-client.mjs +5 -0
  233. package/kits/hub-game/scripts/test-act-core.mjs +32 -0
  234. package/kits/hub-game/scripts/test-act-gate.mjs +186 -0
  235. package/kits/hub-game/scripts/test-action-rail-crowded-dom.mjs +7 -1
  236. package/kits/hub-game/scripts/test-action-rail-default-dom.mjs +102 -0
  237. package/kits/hub-game/scripts/test-action-rail-never-silent-dom.mjs +50 -0
  238. package/kits/hub-game/scripts/test-action-rail-surface.mjs +368 -0
  239. package/kits/hub-game/scripts/test-action-rail-town-jobs-dom.mjs +118 -0
  240. package/kits/hub-game/scripts/test-actions-client.mjs +5 -3
  241. package/kits/hub-game/scripts/test-actions.mjs +24 -0
  242. package/kits/hub-game/scripts/test-actors.mjs +19 -0
  243. package/kits/hub-game/scripts/test-again-corner-dom.mjs +59 -0
  244. package/kits/hub-game/scripts/test-analytics.mjs +80 -1
  245. package/kits/hub-game/scripts/test-arrival-pose-server.mjs +25 -8
  246. package/kits/hub-game/scripts/test-ask-client.mjs +9 -0
  247. package/kits/hub-game/scripts/test-ask-surface.mjs +188 -0
  248. package/kits/hub-game/scripts/test-attention.mjs +43 -1
  249. package/kits/hub-game/scripts/test-ballot-sheet-dom.mjs +71 -0
  250. package/kits/hub-game/scripts/test-ballot-surface.mjs +276 -0
  251. package/kits/hub-game/scripts/test-ballot.mjs +420 -3
  252. package/kits/hub-game/scripts/test-ban-join.mjs +1 -1
  253. package/kits/hub-game/scripts/test-celebrate-client.mjs +62 -0
  254. package/kits/hub-game/scripts/test-celebrate.mjs +116 -0
  255. package/kits/hub-game/scripts/test-chat.mjs +73 -0
  256. package/kits/hub-game/scripts/test-companion-client.mjs +203 -21
  257. package/kits/hub-game/scripts/test-companion.mjs +110 -3
  258. package/kits/hub-game/scripts/test-control-layout-dom.mjs +57 -10
  259. package/kits/hub-game/scripts/test-corner-surface.mjs +268 -0
  260. package/kits/hub-game/scripts/test-decor-client.mjs +59 -3
  261. package/kits/hub-game/scripts/test-decor.mjs +27 -0
  262. package/kits/hub-game/scripts/test-device-class.mjs +4 -1
  263. package/kits/hub-game/scripts/test-disguise-client.mjs +281 -0
  264. package/kits/hub-game/scripts/test-disguise.mjs +176 -0
  265. package/kits/hub-game/scripts/test-dock-surface.mjs +404 -0
  266. package/kits/hub-game/scripts/test-door-analytics.mjs +1 -1
  267. package/kits/hub-game/scripts/test-door-stay-client.mjs +602 -0
  268. package/kits/hub-game/scripts/test-door-stay.mjs +613 -0
  269. package/kits/hub-game/scripts/test-earned-client.mjs +119 -0
  270. package/kits/hub-game/scripts/test-emote-surface.mjs +616 -0
  271. package/kits/hub-game/scripts/test-fps-telemetry.mjs +39 -4
  272. package/kits/hub-game/scripts/test-friend-bests.mjs +38 -12
  273. package/kits/hub-game/scripts/test-ghost-click-dom.mjs +75 -0
  274. package/kits/hub-game/scripts/test-grab-client.mjs +29 -2
  275. package/kits/hub-game/scripts/test-grab-orbit.mjs +260 -11
  276. package/kits/hub-game/scripts/test-grab.mjs +10 -1
  277. package/kits/hub-game/scripts/test-hats.mjs +28 -0
  278. package/kits/hub-game/scripts/test-held-offers.mjs +394 -0
  279. package/kits/hub-game/scripts/test-high-only.mjs +3 -3
  280. package/kits/hub-game/scripts/test-hold-show-client.mjs +175 -0
  281. package/kits/hub-game/scripts/test-hold-show.mjs +355 -0
  282. package/kits/hub-game/scripts/test-hub-controls.mjs +3 -1
  283. package/kits/hub-game/scripts/test-hub-idle.mjs +348 -0
  284. package/kits/hub-game/scripts/test-hub-leaving.mjs +21 -0
  285. package/kits/hub-game/scripts/test-hub-ops.mjs +147 -0
  286. package/kits/hub-game/scripts/test-hub-trip.mjs +260 -5
  287. package/kits/hub-game/scripts/test-hud-clear.mjs +83 -0
  288. package/kits/hub-game/scripts/test-hud-rate.mjs +2 -1
  289. package/kits/hub-game/scripts/test-idle.mjs +160 -0
  290. package/kits/hub-game/scripts/test-invites-client.mjs +53 -0
  291. package/kits/hub-game/scripts/test-labels.mjs +11 -0
  292. package/kits/hub-game/scripts/test-landscape-layout.mjs +20 -0
  293. package/kits/hub-game/scripts/test-load-abandon.mjs +2 -2
  294. package/kits/hub-game/scripts/test-loading-cover.mjs +67 -1
  295. package/kits/hub-game/scripts/test-manifest.mjs +27 -0
  296. package/kits/hub-game/scripts/test-menu-client.mjs +55 -6
  297. package/kits/hub-game/scripts/test-menu-surface.mjs +236 -0
  298. package/kits/hub-game/scripts/test-npcs.mjs +128 -0
  299. package/kits/hub-game/scripts/test-observed.mjs +171 -3
  300. package/kits/hub-game/scripts/test-pack.mjs +166 -0
  301. package/kits/hub-game/scripts/test-picker-surface.mjs +321 -0
  302. package/kits/hub-game/scripts/test-placeat-server.mjs +395 -0
  303. package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
  304. package/kits/hub-game/scripts/test-pointer-clear-dom.mjs +82 -0
  305. package/kits/hub-game/scripts/test-progress-reset.mjs +184 -6
  306. package/kits/hub-game/scripts/test-push-visit.mjs +9 -0
  307. package/kits/hub-game/scripts/test-quality.mjs +312 -9
  308. package/kits/hub-game/scripts/test-quick-chat-surface.mjs +511 -0
  309. package/kits/hub-game/scripts/test-rehello.mjs +237 -0
  310. package/kits/hub-game/scripts/test-rejoin-yaw.mjs +138 -0
  311. package/kits/hub-game/scripts/test-relations-among.mjs +13 -7
  312. package/kits/hub-game/scripts/test-relations-refresh.mjs +90 -2
  313. package/kits/hub-game/scripts/test-replay-client.mjs +110 -0
  314. package/kits/hub-game/scripts/test-replay.mjs +178 -0
  315. package/kits/hub-game/scripts/test-resume-held.mjs +13 -0
  316. package/kits/hub-game/scripts/test-resume-pose-server.mjs +43 -5
  317. package/kits/hub-game/scripts/test-resync.mjs +13 -0
  318. package/kits/hub-game/scripts/test-role-client.mjs +10 -3
  319. package/kits/hub-game/scripts/test-safe-act.mjs +233 -0
  320. package/kits/hub-game/scripts/test-safe-caption.mjs +364 -0
  321. package/kits/hub-game/scripts/test-safe-layout.mjs +79 -0
  322. package/kits/hub-game/scripts/test-safe-prompt.mjs +163 -0
  323. package/kits/hub-game/scripts/test-sound-surface.mjs +256 -0
  324. package/kits/hub-game/scripts/test-soundscape.mjs +85 -2
  325. package/kits/hub-game/scripts/test-stuck-surface.mjs +174 -0
  326. package/kits/hub-game/scripts/test-stuck.mjs +31 -0
  327. package/kits/hub-game/scripts/test-talk-surface.mjs +23 -6
  328. package/kits/hub-game/scripts/test-talk-walk-dom.mjs +123 -0
  329. package/kits/hub-game/scripts/test-text-ask-surface.mjs +273 -0
  330. package/kits/hub-game/scripts/test-tiers.mjs +453 -3
  331. package/kits/hub-game/scripts/test-toast-no-row-dom.mjs +71 -0
  332. package/kits/hub-game/scripts/test-together.mjs +11 -0
  333. package/kits/hub-game/scripts/test-town-day.mjs +90 -0
  334. package/kits/hub-game/scripts/test-track-queue.mjs +64 -0
  335. package/kits/hub-game/scripts/test-try-on.mjs +39 -0
  336. package/kits/hub-game/scripts/test-ui-dom-dom.mjs +49 -2
  337. package/kits/hub-game/scripts/test-ui-tree.mjs +28 -0
  338. package/kits/hub-game/scripts/test-vehicle-client.mjs +77 -1
  339. package/kits/hub-game/scripts/test-vis.mjs +145 -0
  340. package/kits/hub-game/scripts/test-wallet.mjs +650 -0
  341. package/kits/hub-game/scripts/test-weakest-tier.mjs +135 -1
  342. package/kits/hub-game/scripts/test-world-labels.mjs +380 -0
  343. package/kits/hub-game/scripts/test-writer-lease-server.mjs +234 -0
  344. package/kits/hub-game/scripts/test-writer-lease.mjs +281 -0
  345. package/kits/hub-game/scripts/writer-storage-fixture.mjs +37 -0
  346. package/kits/hub-game/tools/hubScene/export.mjs +6 -5
  347. package/kits/hub-game/tools/hubScene/hubdata.mjs +10 -0
  348. package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +48 -2
  349. package/kits/hub-game/tools/hubScene/validate-manifest.mjs +21 -3
  350. package/kits/multiplayer-3d/castle.json +5 -5
  351. package/kits/multiplayer-3d/code/client/resumeGate.js +49 -2
  352. package/kits/multiplayer-3d/code/server/ownership.js +25 -6
  353. package/kits/multiplayer-3d/code/server/world.js +19 -4
  354. package/kits/multiplayer-3d/code/systems/multiplayer.js +67 -11
  355. package/kits/multiplayer-3d/package-lock.json +1 -1
  356. package/kits/multiplayer-3d/package.json +2 -1
  357. package/kits/multiplayer-3d/scripts/test-ground-half.mjs +56 -0
  358. package/kits/multiplayer-3d/scripts/test-join-watchdog.mjs +54 -3
  359. package/kits/multiplayer-3d/scripts/test-owned-moves.mjs +190 -0
  360. package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +191 -5
  361. package/kits/multiplayer-3d/scripts/test-resync-reconnect.mjs +68 -0
  362. package/kits/physics-2d/castle.json +2 -2
  363. package/kits/physics-2d/engine/scene.js +10 -2
  364. package/kits/physics-3d/CLAUDE.md +14 -0
  365. package/kits/physics-3d/behaviors/Player.jsx +39 -3
  366. package/kits/physics-3d/castle.json +3 -3
  367. package/kits/physics-3d/docs/engine-model-cache.md +109 -0
  368. package/kits/physics-3d/docs/engine-player.md +76 -0
  369. package/kits/physics-3d/docs/engine-skip-work.md +16 -0
  370. package/kits/physics-3d/docs/pxmodel-format.md +5 -1
  371. package/kits/physics-3d/engine3d/gait.js +16 -8
  372. package/kits/physics-3d/engine3d/groundsize.js +23 -0
  373. package/kits/physics-3d/engine3d/kithooks.js +50 -0
  374. package/kits/physics-3d/engine3d/look.js +110 -17
  375. package/kits/physics-3d/engine3d/lookbake.js +19 -1
  376. package/kits/physics-3d/engine3d/materialpresets.js +3 -2
  377. package/kits/physics-3d/engine3d/modelcache.js +280 -0
  378. package/kits/physics-3d/engine3d/modelcachedigest.js +37 -0
  379. package/kits/physics-3d/engine3d/modelcachegate.js +69 -0
  380. package/kits/physics-3d/engine3d/modelrefs.js +13 -0
  381. package/kits/physics-3d/engine3d/optimize.js +20 -9
  382. package/kits/physics-3d/engine3d/playerRun.js +26 -1
  383. package/kits/physics-3d/engine3d/pxmodel.js +7 -3
  384. package/kits/physics-3d/engine3d/templatecache.js +722 -0
  385. package/kits/physics-3d/engine3d/world3d.js +211 -17
  386. package/kits/physics-3d/package-lock.json +1 -1
  387. package/kits/physics-3d/package.json +2 -1
  388. package/kits/physics-3d/play/behaviors/Player.js +43 -3
  389. package/kits/physics-3d/scripts/render.mjs +56 -8
  390. package/kits/physics-3d/scripts/template-cache-fixtures.mjs +37 -0
  391. package/kits/physics-3d/scripts/template-cache-v1-bytes.json +49 -0
  392. package/kits/physics-3d/scripts/test-gait.mjs +53 -9
  393. package/kits/physics-3d/scripts/test-ground-half.mjs +120 -0
  394. package/kits/physics-3d/scripts/test-model-cache.mjs +600 -0
  395. package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1 -0
  396. package/kits/physics-3d/scripts/test-sleeping-models.mjs +384 -0
  397. package/kits/physics-3d/scripts/test-template-cache-minified.mjs +106 -0
  398. package/kits/physics-3d/scripts/test-template-cache.mjs +519 -0
  399. package/kits/physics-3d/scripts/test-wall-slide.mjs +272 -0
  400. package/kits/physics-3d/systems/physics3d.js +51 -2
  401. package/kits/real-time/castle.json +2 -2
  402. package/kits/real-time/code/client/connection.js +3 -0
  403. package/package.json +2 -2
  404. package/vendor/three/examples/jsm/libs/fflate.module.js +2672 -0
@@ -1,4 +1,5 @@
1
1
  import assert from 'node:assert/strict';
2
+ import fs from 'node:fs';
2
3
  import { register } from 'node:module';
3
4
  import * as A from '../code/server/analytics.js';
4
5
  import * as DoorAnalytics from '../code/server/doorAnalytics.js';
@@ -20,7 +21,7 @@ for (const analyticsV111 of [false, 1, 'true', {}, null]) assert(readManifest(ca
20
21
  const calls = [];
21
22
  const device = encodeDeviceClass({ lowMemory: true, cores: 4, dpr: 2, width: 360, height: 800, deviceMemory: 2 });
22
23
  const h = { place: { analytics: true }, manifest: {}, sim: { timeMs: 0 }, players: new Map([['p', { arrived: true }]]),
23
- session: { hub: { track: (id, event) => { calls.push([id, event]); return Promise.resolve(true); } } }, analytics: A.create() };
24
+ session: { hub: { track: (id, event) => { calls.push([id, event]); return true; } } }, analytics: A.create() };
24
25
  A.arrive(h, [{ playerId: 'p', userId: '42' }]);
25
26
  assert.equal(calls.at(-1)[1].kind, A.EVENTS.arrive);
26
27
  assert.equal(calls.at(-1)[1].value, 0, 'missing device records unknown');
@@ -168,3 +169,81 @@ DoorAnalytics.arrive({ place: { result: {} }, players: new Map([['p', { arrived:
168
169
  session: { hub: { track: (id, event) => { doorEvents.push(event); return true; } } } }, [{ playerId: 'p', device }]);
169
170
  assert.deepEqual(doorEvents, [{ kind: DoorAnalytics.EVENTS.round_start, value: 1, result: 0 }], 'door round value remains group size');
170
171
  console.log('arrival device values, deferred first visits, hello validation and old clients: passed');
172
+
173
+ // The first room (experiments/hub-nux) on its own manifest: one player, no
174
+ // result, out by `hub.end` (its way back). That end is the visit's
175
+ // session_end, sent while the player is still connected; the way back may hold
176
+ // the connection open for minutes, and its eventual drop and leave add nothing.
177
+ {
178
+ const room = JSON.parse(fs.readFileSync(new URL('../../../experiments/hub-nux/castle.json', import.meta.url), 'utf8'));
179
+ assert.equal(room.hub.analytics, true);
180
+ assert(!room.hub.result, 'the room has no result');
181
+ const realNow = Date.now, realLog = console.log;
182
+ let wall = 0;
183
+ Date.now = () => wall;
184
+ console.log = () => {};
185
+ try {
186
+ const run = async () => {
187
+ const rows = [], sent = [];
188
+ let ctx;
189
+ const session = { sessionId: 's-room', players: [{ playerId: 'p', userId: '101', username: 'Ada', isAnonymous: false }],
190
+ send: (id, message) => sent.push(message), broadcast() {},
191
+ hub: { place: 'main', title: room.hub.title, result: null, arrival: () => ({ fromDeckId: 'TOWN' }),
192
+ async readResults() { return { players: {}, boards: {} }; },
193
+ track: (id, event) => { rows.push({ at: sim.timeMs, connected: session.players.some((p) => p.playerId === id), ...event }); return true; } } };
194
+ const server = layer({ server: room.server, hub: room.hub, characterBundle: room.characterBundle }, { ready: (hub) => { ctx = hub; } }, {}, () => true, () => null);
195
+ server.sceneFor(session);
196
+ const sim = { timeMs: 0, scenePath: 'scenes/main.scene', bodies: new Map(),
197
+ players: new Map([['p', { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } }]]) };
198
+ server.ready(sim);
199
+ server.message(session, { playerId: 'p' }, { k: 'hub-hello', avatar: 1, party: 1 });
200
+ const tick = (ms) => { wall += ms; sim.timeMs += ms; server.place(sim); };
201
+ for (let i = 0; i < 5; i++) {tick(20); await new Promise((resolve) => setImmediate(resolve));}
202
+ assert.deepEqual(rows.map((r) => r.kind), [A.EVENTS.arrive]);
203
+ tick(12000);
204
+ ctx.end(['p']);
205
+ assert(sent.some((m) => m.k === 'hub-end'), 'the way back is sent');
206
+ const end = rows.filter((r) => r.kind === A.EVENTS.session_end);
207
+ assert.equal(end.length, 1, 'the end is the session_end');
208
+ assert.deepEqual(end[0], { at: sim.timeMs, connected: true, kind: A.EVENTS.session_end, subject: 0, value: sim.timeMs - rows[0].at, result: A.END.left, flags: 0 });
209
+ assert(end[0].value >= 12000, 'the connected time up to the end');
210
+ // Minutes on the way back with the connection open, then the drop.
211
+ for (let i = 0; i < 180; i++) {tick(1000);}
212
+ session.players = [];
213
+ for (let i = 0; i < 60; i++) {tick(1000);}
214
+ sim.players.delete('p');
215
+ tick(1000);
216
+ return { rows };
217
+ };
218
+ const { rows } = await run();
219
+ assert.equal(rows.filter((r) => r.kind === A.EVENTS.session_end).length, 1, 'the drop after the end reports nothing more');
220
+ // Unit: a stay after the end continues the visit as a new segment.
221
+ const h = { place: { analytics: true }, manifest: {}, sim: { timeMs: 0, players: new Map() }, players: new Map([['p', { arrived: true }]]),
222
+ analytics: A.create(), session: { players: [{ playerId: 'p' }], hub: { track: (id, event) => { stayRows.push(event); return true; } } } };
223
+ const stayRows = [];
224
+ A.arrive(h, [{ playerId: 'p', userId: '101' }]);
225
+ h.sim.timeMs = 5000; A.ended(h, 'p'); A.ended(h, 'p');
226
+ h.sim.timeMs = 6000; A.stayed(h, 'p');
227
+ h.sim.timeMs = 9000; A.leave(h, 'p');
228
+ assert.deepEqual(stayRows.filter((e) => e.kind === A.EVENTS.session_end).map((e) => [e.value, e.result]),
229
+ [[5000, A.END.left], [3000, A.END.continued]], 'one row per segment; a stay continues');
230
+ // A resume that arrives still ended by its door (the visit was let go at
231
+ // the drop) counts nothing until its stay, and that is a continuation.
232
+ stayRows.length = 0;
233
+ h.players.set('p', { arrived: true, ended: true });
234
+ h.sim.timeMs = 20000; A.arrive(h, [{ playerId: 'p', userId: '101' }]);
235
+ h.sim.timeMs = 32000; A.stayed(h, 'p');
236
+ h.sim.timeMs = 35000; A.leave(h, 'p');
237
+ assert.deepEqual(stayRows.filter((e) => e.kind === A.EVENTS.session_end).map((e) => [e.value, e.result]),
238
+ [[3000, A.END.continued]], 'an ended resume reports only what follows its stay');
239
+ stayRows.length = 0;
240
+ h.players.set('p', { arrived: true, ended: true });
241
+ h.sim.timeMs = 40000; A.arrive(h, [{ playerId: 'p', userId: '101' }]);
242
+ h.sim.timeMs = 45000; A.leave(h, 'p');
243
+ assert.equal(stayRows.filter((e) => e.kind === A.EVENTS.session_end).length, 0, 'an ended resume that leaves adds no row');
244
+ } finally {
245
+ Date.now = realNow;
246
+ console.log = realLog;
247
+ }
248
+ console.log('first room: hub.end reports session_end while connected, once: passed');
249
+ }
@@ -97,19 +97,18 @@ export default { ...authored,
97
97
  const a = await connect(`${base}?nonce=${server.mintNonce({userId:'101',username:'Ada',isAnonymous:false})}`);
98
98
  const hello = await a.wait(f => f.t === 'hello');
99
99
  a.send({ k: 'hub-hello', avatar: 0, party: 1 });
100
- await sleep(300);
100
+ await arrived(a);
101
101
  const initial = await query(a, 'state');
102
102
  assert.deepEqual(initial.events, [['arrive', hello.playerId]], 'real hub admitted and arrived');
103
103
  if (resultPlace) assert.equal((await query(a, 'report')).accepted, true);
104
104
  await query(a, 'move');
105
- await sleep(150);
106
- let before = await query(a, 'state');
105
+ let before = await until(a, 'state', {}, s => Math.hypot(s.pose.x - initial.pose.x, s.pose.z - initial.pose.z) > 2);
107
106
  assert.ok(Math.hypot(before.pose.x - initial.pose.x, before.pose.z - initial.pose.z) > 2, 'fixture actually moved away from arrival');
108
107
  const b = await connect(`${base}?nonce=${server.mintNonce({userId:'102',username:'Bo',isAnonymous:false})}`);
109
108
  await b.wait(f => f.t === 'hello');
110
109
  b.send({ k: 'hub-hello', avatar: 0, party: 1 });
111
- await sleep(300);
112
- if (door) { const prep = await query(b, 'prepare', { id: hello.playerId }); if (door === 'fishing') a.send({ k: 'hub-sit', seat: prep.authored.seat }); await sleep(150); before = await query(a, 'state', { id: hello.playerId }); if (door === 'fishing') assert.equal(before.authored.cast, true, 'real seat interaction starts a cast'); }
110
+ await arrived(b);
111
+ if (door) { const prep = await query(b, 'prepare', { id: hello.playerId }); if (door === 'fishing') a.send({ k: 'hub-sit', seat: prep.authored.seat }); before = await until(a, 'state', { id: hello.playerId }, s => door !== 'fishing' || s.authored.cast === true); if (door === 'fishing') assert.equal(before.authored.cast, true, 'real seat interaction starts a cast'); }
113
112
  if (resultPlace) await query(b, 'advance', { ms: 15000 });
114
113
  if (leavingLine) await query(a, 'line');
115
114
  let returned;
@@ -120,8 +119,8 @@ export default { ...authored,
120
119
  a.socket.close();
121
120
  await new Promise(resolve => a.socket.once('close', resolve));
122
121
  }
123
- await sleep(300);
124
- const absent = await query(b, 'state', { id: hello.playerId });
122
+ // The leave reaches the server's child on its own schedule: poll for it.
123
+ const absent = await until(b, 'state', { id: hello.playerId }, s => s.events.some(e => e[0] === 'leave' && e[1] === hello.playerId));
125
124
  assert.equal(absent.events.filter(e => e[0] === 'leave' && e[1] === hello.playerId).length, 1, 'authored immediate leave fires');
126
125
  assert.ok(!absent.departedRoster.includes(hello.playerId), 'authored leave sees only authenticated live roster');
127
126
  if (!fast) assert.ok(!absent.roster.some(p => p.playerId === hello.playerId), 'absent player is not live');
@@ -151,7 +150,7 @@ export default { ...authored,
151
150
  assert.equal((await returned.wait(f => f.t === 'hello')).playerId, hello.playerId);
152
151
  }
153
152
  returned.send({ k: 'hub-hello', avatar: 0, party: 1, ...(plain ? {} : { resume: true }) });
154
- await sleep(300);
153
+ await arrived(returned);
155
154
  const after = await query(returned, 'state');
156
155
  assert.equal(after.events.filter(e => e[0] === 'arrive' && e[1] === hello.playerId).length, 2, 'authored arrive fires again');
157
156
  assert.ok(Math.hypot(after.pose.x - before.pose.x, after.pose.z - before.pose.z) < 0.01, 'pose restored across ordinary leave/arrive');
@@ -170,6 +169,24 @@ export default { ...authored,
170
169
  await server?.shutdown();
171
170
  await rm(dir, { recursive: true, force: true });
172
171
  }
172
+ // The kit's own arrival signal, sent once the place's arrive hook has run and
173
+ // the pose is placed. A fixed sleep raced it under load: a message before the
174
+ // first simulation tick is dropped, one before arrivals() sees no arrive yet.
175
+ // A join that never arrives still fails here, on the frame timeout.
176
+ function arrived(client) {
177
+ return client.wait(f => f.t === 'm' && f.d?.k === 'hub-arrived');
178
+ }
179
+ // Asks again until `done` holds or the deadline passes, then returns the last
180
+ // answer, so the caller's assertion still decides (and fails) on it.
181
+ async function until(client, test, extra, done, ms = 10000) {
182
+ const deadline = Date.now() + ms;
183
+ let answer = await query(client, test, extra);
184
+ while (!done(answer) && Date.now() < deadline) {
185
+ await sleep(50);
186
+ answer = await query(client, test, extra);
187
+ }
188
+ return answer;
189
+ }
173
190
  async function query(client, test, extra = {}) {
174
191
  client.send({ test, ...extra });
175
192
  return (await client.wait(f => f.t === 'm' && f.d?.test === test)).d;
@@ -194,6 +194,15 @@ test('OK and Enter send exact answer once, wipe field/remove listeners and never
194
194
  const count = r.dom.made.length; r.draw(); assert.equal(r.dom.made.length, count); assert(!r.chrome.textAskOpen()); r.chrome.dispose();
195
195
  }
196
196
  });
197
+ test('v1.204: an answer refused while catching up keeps the card and its text', () => {
198
+ const r = rig(); let refuse = true;
199
+ r.chrome.setTextAsk(spec, (id, n, text) => { if (refuse) return false; r.sent.push({ k: 'hub-answer', id, n, text }); return true; }, (open) => r.locks.push(open));
200
+ const input = r.input(); r.type('Rex'); tap(find(r.dom, 'OK'));
201
+ assert.deepEqual(r.sent, []); assert(r.chrome.textAskOpen()); assert.equal(input.value, 'Rex');
202
+ refuse = false; tap(find(r.dom, 'OK'));
203
+ assert.deepEqual(r.sent, [{ k: 'hub-answer', id: spec.id, n: 1, text: 'Rex' }]); assert(!r.chrome.textAskOpen());
204
+ r.chrome.dispose();
205
+ });
197
206
  test('client and server share validation; whitespace, refused characters and oversized raw fields cannot send', () => {
198
207
  const r = rig(); r.draw(); const input = r.input(), ok = find(r.dom, 'OK');
199
208
  const chars = [...Array.from({ length: 32 }, (_, i) => i), ...Array.from({ length: 33 }, (_, i) => 0x7f + i), 0x061c, 0x200b, 0x200c, 0x200d, 0x200e, 0x200f, 0x202a, 0x202b, 0x202c, 0x202d, 0x202e, ...Array.from({ length: 10 }, (_, i) => 0x2060 + i), 0xfeff];
@@ -0,0 +1,188 @@
1
+ // The question card surface (`code/client/askSurface.js`) and its tree
2
+ // (`askTree.js`): the card as the `ask` UI tree root, with no DOM, for a
3
+ // native host. Checks that the trees validate for every kind; that bytes and
4
+ // binding ids do not move across rebuilds with fresh closures; that the
5
+ // words, widths, buttons and heart are the DOM card's (chrome.js drawn into
6
+ // a fake DOM); and that each answer reaches `onAsk` with the card it was
7
+ // drawn for, hides the card until it is given again, and that an away page
8
+ // draws nothing.
9
+ import assert from 'node:assert/strict';
10
+ import { execFileSync } from 'node:child_process';
11
+ import { register } from 'node:module';
12
+ register(`data:text/javascript,${encodeURIComponent(`
13
+ export async function resolve(specifier, context, next) {
14
+ if (specifier === 'castle-web-sdk') return { url: ${JSON.stringify(new URL('./fixtures/sdk-stub.mjs', import.meta.url).href)}, shortCircuit: true };
15
+ return next(specifier, context);
16
+ }
17
+ `)}`);
18
+ const { dispatchUiEvent, resetUiTrees, serialize, setUiTreeSink, validate } = await import('../code/client/uiTree.js');
19
+ const { askWidth, buildAsk } = await import('../code/client/askTree.js');
20
+ const { makeAskSurface } = await import('../code/client/askSurface.js');
21
+
22
+ let passed = 0;
23
+ const test = async (name, fn) => {
24
+ try {await fn();} catch (error) {error.message = `${name}: ${error.message}`; throw error;}
25
+ passed += 1;
26
+ };
27
+
28
+ const ASKS = {
29
+ go: { key: 'go:7', kind: 'go', id: 7, text: 'ada wants to go to Rooftop Race', yes: 'Go', no: 'Stay' },
30
+ invite: { key: 'invite:p2', kind: 'invite', from: 'p2', text: 'bo invites you to a party', yes: 'Join', no: 'No thanks' },
31
+ play: { key: 'play:race', kind: 'play', door: 'race', text: "Let's play Rooftop Race", yes: 'Play', no: 'Not now' },
32
+ again: { key: 'again:race:123', kind: 'again', door: 'race', text: 'Play Rooftop Race again?', yes: 'Again', no: 'Done' },
33
+ yours: { key: 'yours:golf', kind: 'yours', door: 'golf', text: 'Your Mini Golf has 3 new plays and a very long title', line: 'Last played by amy · 2 hearts', yes: 'Go', no: 'Later', heart: false },
34
+ };
35
+ const noop = { answer() {}, heart() {} };
36
+ function find(tree, k) {
37
+ if (!tree) {return null;}
38
+ if (tree.k === k) {return tree;}
39
+ for (const child of tree.c ?? []) {
40
+ const hit = find(child, k);
41
+ if (hit) {return hit;}
42
+ }
43
+ return null;
44
+ }
45
+ const words = (node) => node?.text ?? node?.c?.find((child) => child.t === 'text' && !child.k)?.text;
46
+
47
+ await test('trees validate for every kind, shown and hidden', () => {
48
+ for (const ask of [...Object.values(ASKS), { ...ASKS.yours, heart: true }, { ...ASKS.yours, heart: undefined }, null]) {
49
+ for (const shown of [true, false]) {
50
+ assert.deepEqual(validate(buildAsk({ ask, shown }, noop), 'ask'), []);
51
+ assert.deepEqual(validate(buildAsk({ ask, shown }), 'ask'), []);
52
+ }
53
+ }
54
+ });
55
+
56
+ await test('bytes and binding ids do not move across rebuilds with fresh closures', () => {
57
+ for (const ask of Object.values(ASKS)) {
58
+ const one = serialize(buildAsk({ ask, shown: true }, { answer: () => 1, heart: () => 1 }), 'ask');
59
+ const two = serialize(buildAsk({ ask: structuredClone(ask), shown: true }, { answer: () => 2, heart: () => 2 }), 'ask');
60
+ assert.equal(one.json, two.json);
61
+ assert.deepEqual([...one.handlers.keys()], [...two.handlers.keys()]);
62
+ }
63
+ assert.deepEqual([...serialize(buildAsk({ ask: ASKS.go, shown: true }, noop), 'ask').handlers.keys()], ['ask/card/yes#tap', 'ask/card/no#tap']);
64
+ assert.deepEqual([...serialize(buildAsk({ ask: ASKS.yours, shown: true }, noop), 'ask').handlers.keys()], ['ask/card/heart#tap', 'ask/card/yes#tap', 'ask/card/no#tap']);
65
+ assert.equal(serialize(buildAsk({ ask: null, shown: false }, noop), 'ask').json, '{"t":"stack","k":"ask","s":{"font":"ui","size":15,"weight":600,"lh":1.3,"color":"#fff"}}');
66
+ });
67
+
68
+ await test('the card is the DOM\'s: top-centred under the HUD, its width, words, buttons and heart', async () => {
69
+ for (const ask of Object.values(ASKS)) {
70
+ const card = find(buildAsk({ ask, shown: true }, noop), 'card');
71
+ assert.deepEqual(card.at, { anchor: 'top', top: [92, 80] });
72
+ assert.deepEqual(card.s.w, ask.kind === 'yours' ? [{ vw: 94 }, { px: 420 }] : [{ vw: 86 }, { px: 320 }]);
73
+ assert.deepEqual(card.s.w, askWidth(ask));
74
+ assert.deepEqual([card.s.pad, card.s.gap, card.s.radius, card.s.bg, card.s.size, card.s.hit], [[8, 10], 8, 12, 'rgba(20,16,12,0.9)', 14, 'auto']);
75
+ assert.deepEqual([words(find(card, 'yes')), words(find(card, 'no'))], [ask.yes, ask.no]);
76
+ assert.deepEqual([find(card, 'yes').s.bg, find(card, 'no').s.bg], ['gold', 'transparent'], 'Yes is the primary button');
77
+ assert.deepEqual([find(card, 'yes').fire, find(card, 'no').fire], ['down', 'down'], 'answered on the press, as the DOM');
78
+ assert.equal(find(card, 'text').text, ask.text);
79
+ }
80
+ const yours = find(buildAsk({ ask: ASKS.yours, shown: true }, noop), 'card');
81
+ assert.deepEqual(yours.c.map((c) => c.k), ['words', 'heart', 'yes', 'no']);
82
+ assert.deepEqual([find(yours, 'text').s.lines, find(yours, 'line').s.lines, find(yours, 'line').s.size, find(yours, 'line').text], [1, 1, 11, ASKS.yours.line]);
83
+ assert.deepEqual([find(yours, 'heart').label, find(yours, 'heart').pressed, words(find(yours, 'heart'))], ['Heart this game', false, '♡']);
84
+ const hearted = find(buildAsk({ ask: { ...ASKS.yours, heart: true }, shown: true }, noop), 'heart');
85
+ assert.deepEqual([hearted.label, hearted.pressed, words(hearted)], ['Remove heart', true, '♥']);
86
+ assert.equal(find(buildAsk({ ask: { ...ASKS.yours, heart: undefined }, shown: true }, noop), 'heart'), null);
87
+ assert.equal(find(buildAsk({ ask: { ...ASKS.go, heart: true }, shown: true }, noop), 'heart'), null, 'hearts only on your games');
88
+ // chrome.js's own card, drawn into a fake DOM, has the same words in the
89
+ // same order.
90
+ const dom = await chromeAsk();
91
+ for (const ask of [ASKS.invite, ASKS.yours]) {
92
+ dom.chrome.setAsk(ask);
93
+ const card = find(buildAsk({ ask, shown: true }, noop), 'card');
94
+ const flat = (node) => (node.t === 'text' ? [node.text] : node.c?.length === 1 && node.c[0].t === 'text' && !node.c[0].k ? [node.c[0].text] : (node.c ?? []).flatMap(flat));
95
+ assert.deepEqual(flat(card), dom.texts(), ask.kind);
96
+ assert.equal(dom.card.style.width, ask.kind === 'yours' ? 'min(94vw, 420px)' : 'min(86vw, 320px)');
97
+ }
98
+ dom.chrome.dispose();
99
+ });
100
+
101
+ // chrome.js with a fake DOM: its ask card's words, in order.
102
+ async function chromeAsk() {
103
+ const made = [];
104
+ const node = (tag) => {
105
+ const self = {
106
+ tag, children: [], parent: null, dataset: {}, attrs: {}, textContent: '', innerHTML: '',
107
+ appendChild(child) {child.parent = self; self.children.push(child); return child;},
108
+ insertBefore(child) {child.parent = self; self.children.push(child); return child;},
109
+ remove() {}, contains: () => false, replaceChildren() {self.children = [];},
110
+ addEventListener() {}, removeEventListener() {}, setAttribute(k, v) {self.attrs[k] = String(v);}, getAttribute: (k) => self.attrs[k] ?? null,
111
+ focus() {}, blur() {}, getBoundingClientRect: () => ({ left: 0, right: 0, top: 0, bottom: 0, width: 0, height: 0 }),
112
+ offsetWidth: 100, offsetHeight: 40, offsetLeft: 0, offsetTop: 0, style: {},
113
+ };
114
+ made.push(self);
115
+ return self;
116
+ };
117
+ globalThis.document = { body: node('body'), createElement: node, activeElement: null, visibilityState: 'visible' };
118
+ globalThis.window = { innerWidth: 390, innerHeight: 844 };
119
+ globalThis.requestAnimationFrame ??= () => 0;
120
+ globalThis.cancelAnimationFrame ??= () => {};
121
+ const { makeChrome } = await import('../code/client/chrome.js');
122
+ const chrome = makeChrome({ onBack() {}, onAvatar() {}, avatarCount: 4 });
123
+ const card = made.find((n) => n.style.top === 'max(92px, calc(env(safe-area-inset-top) + 80px))');
124
+ const all = (n) => [n, ...n.children.flatMap(all)];
125
+ return { chrome, card, texts: () => all(card).filter((n) => n !== card && n.textContent && !n.children.length).map((n) => n.textContent) };
126
+ }
127
+
128
+ await test('events: an answer goes to onAsk with the card drawn and hides it until given again; the heart; away', () => {
129
+ resetUiTrees();
130
+ const roots = [];
131
+ setUiTreeSink((name, wire) => roots.push({ name, wire }), { dom: false });
132
+ const calls = [];
133
+ const surface = makeAskSurface({ onAsk: (ask, yes) => calls.push(['ask', ask, yes]), onHeart: (door, ask) => calls.push(['heart', door, ask]) });
134
+ const wire = () => roots.filter((r) => r.name === 'ask').at(-1)?.wire ?? null;
135
+ const tap = (id) => dispatchUiEvent('ask', id, {});
136
+ // Each kind's answer reaches onAsk with the very card it was drawn for.
137
+ for (const [kind, yes] of [['go', true], ['go', false], ['invite', true], ['invite', false], ['play', true], ['again', false], ['yours', true]]) {
138
+ surface.set(ASKS[kind]);
139
+ assert.equal(surface.shown(), true);
140
+ assert.equal(tap(`ask/card/${yes ? 'yes' : 'no'}#tap`), true);
141
+ assert.equal(surface.shown(), false, 'the card hides on the answer');
142
+ assert.equal(wire().c, undefined);
143
+ assert.equal(tap('ask/card/yes#tap'), false, 'a hidden card takes nothing');
144
+ assert.deepEqual(calls.pop(), ['ask', ASKS[kind], yes]);
145
+ }
146
+ // Given again (the driver had not cleared it yet): drawn again.
147
+ surface.set(ASKS.go);
148
+ assert.equal(surface.shown(), true);
149
+ // The heart, with the card it was drawn for.
150
+ surface.set(ASKS.yours);
151
+ tap('ask/card/heart#tap');
152
+ assert.deepEqual(calls.pop(), ['heart', 'golf', ASKS.yours]);
153
+ assert.equal(surface.shown(), true, 'the heart leaves the card up');
154
+ // Away: hidden at once, not showable; back draws it on the next set.
155
+ surface.setAway(true);
156
+ assert.equal(surface.shown(), false);
157
+ assert.equal(surface.showable(), false);
158
+ surface.set(ASKS.yours);
159
+ assert.equal(wire().c, undefined, 'nothing drawn while away');
160
+ surface.setAway(false);
161
+ assert.equal(surface.shown(), false);
162
+ surface.set(ASKS.yours);
163
+ assert.equal(surface.shown(), true);
164
+ surface.set(null);
165
+ assert.equal(wire().c, undefined);
166
+ assert.deepEqual(calls, []);
167
+ surface.dispose();
168
+ assert.equal(wire(), null);
169
+ resetUiTrees();
170
+ });
171
+
172
+ await test('the surface loads and runs in a process that never had a DOM', () => {
173
+ const probe = `
174
+ if (globalThis.document || globalThis.window) throw new Error('a DOM');
175
+ const { setUiTreeSink, dispatchUiEvent } = await import(${JSON.stringify(new URL('../code/client/uiTree.js', import.meta.url).href)});
176
+ const { makeAskSurface } = await import(${JSON.stringify(new URL('../code/client/askSurface.js', import.meta.url).href)});
177
+ const seen = [];
178
+ setUiTreeSink((name, wire) => seen.push(name + ':' + (wire ? (wire.c ?? []).length : null)), { dom: false });
179
+ const surface = makeAskSurface({ onAsk: (ask, yes) => seen.push(ask.key + '=' + yes) });
180
+ surface.set(${JSON.stringify(ASKS.invite)});
181
+ dispatchUiEvent('ask', 'ask/card/no#tap', {});
182
+ surface.dispose();
183
+ console.log(seen.join(' '));
184
+ `;
185
+ assert.equal(execFileSync(process.execPath, ['--input-type=module', '-e', probe], { encoding: 'utf8' }).trim(), 'ask:0 ask:1 ask:0 invite:p2=false ask:null');
186
+ });
187
+
188
+ console.log(`ask surface: ${passed} checks passed`);
@@ -3,7 +3,7 @@
3
3
  // other players' names near the player only. `npm run check` runs this.
4
4
 
5
5
  import assert from 'node:assert/strict';
6
- import { attend, fadeNames, makeAttention, nameOpacity, NAME_SCALE } from '../code/client/attention.js';
6
+ import { attend, behind, fadeNames, makeAttention, nameOpacity, NAME_SCALE } from '../code/client/attention.js';
7
7
 
8
8
  // Fifteen statues round a fountain, the player at the arrival spot 8 m out: none.
9
9
  const ring = Array.from({ length: 15 }, (_, i) => ({ id: `plinth-${i}`, d: 8 + i * 0.3, speech: false }));
@@ -110,3 +110,45 @@ fadeNames(mp, { x: 0, z: 0 }, true, touched);
110
110
  assert.equal(tags.get('p-near').sprite.scale.x, 0.5 * NAME_SCALE);
111
111
 
112
112
  console.log('attention: all passed');
113
+
114
+ // The Weekend Cup statues at yaw 120 (Oct 17, local-proof/yaw120): from the
115
+ // arrival (0, 9) the three stand in a line, so a straight walk to #1 or #3
116
+ // passes the one in front and stops about as near it. The plate passed lies
117
+ // behind the player and gives way to the one walked to.
118
+ {
119
+ const statues = { 'statue-1': [-4.33, 2.5], 'statue-2': [-3.03, 4.752], 'statue-3': [-5.63, 0.248] };
120
+ const walk = (to, steps) => {
121
+ const at = makeAttention();
122
+ const [tx, tz] = statues[to];
123
+ const facing = Math.atan2(tx - 0, tz - 9);
124
+ let picked = null;
125
+ for (let i = 0; i <= steps.length - 1; i++) {
126
+ const from = steps[i];
127
+ const candidates = Object.entries(statues).map(([id, [x, z]]) => ({ id, d: Math.hypot(x - from.x, z - from.z), speech: false, behind: behind(from, facing, x, z) }));
128
+ attend(at, candidates, 1000 + i * 16);
129
+ picked = at.plate;
130
+ }
131
+ return picked;
132
+ };
133
+ const line = (to, stop) => {
134
+ const [tx, tz] = statues[to];
135
+ return Array.from({ length: 40 }, (_, i) => ({ x: (stop.x * i) / 39 + 0 * (1 - i / 39), z: 9 + ((stop.z - 9) * i) / 39 })).filter(({ x, z }) => Math.hypot(tx - x, tz - z) > 0);
136
+ };
137
+ assert.equal(walk('statue-1', line('statue-1', { x: -3.56, z: 3.53 })), 'statue-1', 'arrival to #1 picks #1, not #2 passed on the way');
138
+ assert.equal(walk('statue-3', line('statue-3', { x: -4.87, z: 1.43 })), 'statue-3', 'arrival to #3 picks #3, not #1 passed on the way');
139
+ assert.equal(walk('statue-2', line('statue-2', { x: -2.29, z: 5.8 })), 'statue-2', 'the first statue on the line still shows');
140
+ // No facing (a native host, a missing player), or a plate stood on: no bearing.
141
+ assert.equal(behind({ x: 0, z: 0 }, undefined, 0, -2), false);
142
+ assert.equal(behind({ x: 0, z: 0 }, 0, 0, -0.5), false, 'a plate under the player is not behind');
143
+ assert.equal(behind({ x: 0, z: 0 }, 0, 0, -2), true);
144
+ assert.equal(behind({ x: 0, z: 0 }, 0, 2, 0), false, 'one beside the player is not behind');
145
+ // Two statues side by side, both ahead: the old hysteresis holds.
146
+ const at = makeAttention();
147
+ attend(at, [{ id: 'a', d: 2, speech: false, behind: false }, { id: 'b', d: 2.4, speech: false, behind: false }], 0);
148
+ attend(at, [{ id: 'a', d: 2.3, speech: false, behind: false }, { id: 'b', d: 2.0, speech: false, behind: false }], 16);
149
+ assert.equal(at.plate, 'a', 'a near tie ahead keeps the plate shown');
150
+ // An NPC's line is chosen by distance alone, whichever side it calls from.
151
+ const talk = makeAttention();
152
+ attend(talk, [{ id: 'behind', d: 2, speech: true, behind: true }, { id: 'ahead', d: 5, speech: true, behind: false }], 0);
153
+ assert.equal(talk.speech, 'behind', 'the nearer NPC line shows, even behind the player');
154
+ }
@@ -0,0 +1,71 @@
1
+ // The choice sheet in a real browser at phone portrait sizes: a sheet with
2
+ // more below its fold says so, and picking a face keeps the faces in view.
3
+ import assert from 'node:assert/strict';
4
+ import { readFile } from 'node:fs/promises';
5
+ import { fileURLToPath } from 'node:url';
6
+ import { chromium } from 'playwright-core';
7
+ import { launchChromium, logRenderer } from '../../../experiments/hub-town/qa/launch.mjs';
8
+ const root = new URL('../../../', import.meta.url);
9
+ const lines = JSON.parse(await readFile(new URL('experiments/hub-sneaks/castle.json', root), 'utf8')).hub.ballot.lines;
10
+ const browser = await launchChromium(chromium, { executablePath: process.env.CHROME });
11
+ try {
12
+ for (const [width, height] of [[412, 870], [360, 740]]) {
13
+ const context = await browser.newContext({ viewport: { width, height }, isMobile: true, hasTouch: true });
14
+ const page = await context.newPage();
15
+ await page.route('http://ballot.test/**', async route => {
16
+ const pathname = new URL(route.request().url()).pathname;
17
+ if (pathname === '/') return route.fulfill({ contentType: 'text/html', body: '<meta name="viewport" content="width=device-width"><body style="margin:0"></body>' });
18
+ const url = new URL(`.${pathname}`, root);
19
+ assert(fileURLToPath(url).startsWith(fileURLToPath(root)));
20
+ await route.fulfill({ contentType: 'text/javascript', body: await readFile(url, 'utf8') });
21
+ });
22
+ await page.goto('http://ballot.test/');
23
+ await logRenderer(page, 'ballot sheet');
24
+ const result = await page.evaluate(async (lines) => {
25
+ const { makeBallot } = await import('/kits/hub-game/code/client/ballot.js');
26
+ const ids = Array.from({ length: 8 }, (_, i) => `p${i}`);
27
+ const card = {
28
+ v: 'v1', mode: 'talk', title: 'Meeting · talk', until: 60000, options: [], lines: lines.map(l => l.id),
29
+ text: 'By the well: #2 found #5 tagged out by a Sneak. Tap a face, then a line.',
30
+ faces: ids.map((id, i) => ({ id, note: `#${i + 1}` })),
31
+ who: Object.fromEntries(ids.map((id, i) => [id, { name: `player_${i}`, avatar: i % 6 }])),
32
+ feed: [{ from: 'p1', to: 'p3', line: lines[0].id }, { from: 'p2', line: lines[1].id }],
33
+ };
34
+ const ballot = makeBallot({ send: () => {} });
35
+ ballot.frame(card, lines, 'p0', 0, 0);
36
+ const sheet = ballot.surface();
37
+ const masked = () => getComputedStyle(sheet).maskImage !== 'none';
38
+ const view = sheet.getBoundingClientRect();
39
+ const inView = (node) => { const r = node.getBoundingClientRect(); return r.top >= view.top - 1 && r.bottom <= view.bottom + 1; };
40
+ const scrolls = sheet.scrollHeight > sheet.clientHeight + 8;
41
+ const cueAtTop = masked();
42
+ sheet.scrollTop = sheet.scrollHeight;
43
+ sheet.dispatchEvent(new Event('scroll'));
44
+ const cueAtEnd = masked();
45
+ sheet.scrollTop = 0;
46
+ const faces = [...sheet.querySelectorAll('button[aria-pressed]')];
47
+ faces[2].click();
48
+ ballot.frame(card, lines, 'p0', 0, 0);
49
+ const picked = sheet.querySelector('button[aria-pressed="true"]');
50
+ const chip = [...sheet.querySelectorAll('button:not([aria-pressed])')][0];
51
+ const pickedInView = inView(picked), chipInView = inView(chip);
52
+ sheet.scrollTop = 0;
53
+ ballot.frame(card, lines, 'p0', 0, 0);
54
+ window.turned = () => { ballot.frame(card, lines, 'p0', 0, 0); return getComputedStyle(sheet).maskImage; };
55
+ return { scrolls, cueAtTop, cueAtEnd, pickedInView, chipInView };
56
+ }, lines);
57
+ // Turned on its side, the columns scroll: the sheet keeps no portrait fade.
58
+ await page.setViewportSize({ width: height, height: width });
59
+ result.landscapeMask = await page.evaluate(() => window.turned());
60
+ assert.ok(result.scrolls, `${width}x${height}: the Sneaks card scrolls`);
61
+ assert.ok(result.cueAtTop, `${width}x${height}: more below is cued`);
62
+ assert.ok(!result.cueAtEnd, `${width}x${height}: no cue at the end`);
63
+ assert.ok(result.pickedInView, `${width}x${height}: the picked face stays in view`);
64
+ assert.ok(result.chipInView, `${width}x${height}: the first line chip comes into view`);
65
+ assert.equal(result.landscapeMask, 'none', `${width}x${height}: no portrait fade on the sheet in landscape`);
66
+ await context.close();
67
+ }
68
+ console.log('ballot sheet dom: passed');
69
+ } finally {
70
+ await browser.close();
71
+ }