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
@@ -28,9 +28,11 @@ import {
28
28
  makeLevers,
29
29
  makeTiers,
30
30
  median,
31
+ primeTiers,
31
32
  readMode,
32
33
  weakGpu,
33
34
  } from '../code/client/tiers.js';
35
+ import { CACHE_PREFIX, deviceStorage, makeCachedStorage, usableLocalStorage } from '../code/client/deviceStorage.js';
34
36
 
35
37
  let n = 0;
36
38
  function test(name, fn) {
@@ -43,6 +45,16 @@ function test(name, fn) {
43
45
  n += 1;
44
46
  }
45
47
 
48
+ async function asyncTest(name, fn) {
49
+ try {
50
+ await fn();
51
+ } catch (err) {
52
+ console.error(`not ok: ${name}`);
53
+ throw err;
54
+ }
55
+ n += 1;
56
+ }
57
+
46
58
  function memoryStorage(init = {}) {
47
59
  const map = new Map(Object.entries(init));
48
60
  return {
@@ -511,8 +523,9 @@ test('levers: high again restores node parents and lights exactly', () => {
511
523
 
512
524
  test('Low keeps the full render resolution: the pixel ratio is never read or set, across Low/High switches', () => {
513
525
  // Measured on phones, a render scale of 1 bought 2-9% and made Low jagged
514
- // on 2x screens, so Low leaves the renderer and composer alone. The only
515
- // read of the renderer is the GPU hint, once.
526
+ // on 2x screens, so Low leaves the renderer and composer alone unless a Low
527
+ // window is still slow (the resolution step, below). The only read of the
528
+ // renderer is the GPU hint, once.
516
529
  const { world, scene, touched } = fakeWorld(TOWN);
517
530
  const t = makeTiers({ storage: memoryStorage(), deviceMemory: 1, levers: makeLevers({ boundsOf: bounds(0) }) });
518
531
  const s = { ...scene, three: world };
@@ -540,6 +553,226 @@ test('Low keeps the full render resolution: the pixel ratio is never read or set
540
553
  assert.deepEqual(touched, ['renderer.getContext'], 'only the GPU hint, read once');
541
554
  });
542
555
 
556
+ // Auto Low's resolution step, on a fake renderer and composer.
557
+ function ratioWorld(ratio = 2) {
558
+ const renderer = { ratio, sets: [], getPixelRatio: () => renderer.ratio, setPixelRatio: (x) => { renderer.ratio = x; renderer.sets.push(x); } };
559
+ const composer = { _pixelRatio: ratio, sets: [], setPixelRatio: (x) => { composer._pixelRatio = x; composer.sets.push(x); } };
560
+ return { renderer, composer };
561
+ }
562
+ // Frames of `ms` each through `t.frame` from `now` for `seconds`; returns the time after.
563
+ function frames(t, scene, now, ms, seconds, counts = true) {
564
+ for (const end = now + seconds * 1000; now < end; now += ms) {
565
+ t.frame(scene, counts, now);
566
+ }
567
+ return now;
568
+ }
569
+ // A device the judge drops to Low within the first window (60 ms frames).
570
+ function slowLow({ storage = memoryStorage(), clock = () => 5000, world = ratioWorld(), weakest = false } = {}) {
571
+ const t = makeTiers({ storage, clock, deviceMemory: 8, levers: fakeLevers(), weakest });
572
+ const scene = { three: world };
573
+ const now = frames(t, scene, 0, 60, 6);
574
+ assert.equal(t.handle.current, 'low');
575
+ return { t, scene, world, storage, now };
576
+ }
577
+
578
+ test('scale: a fill-bound device keeps half the ratio and remembers it', () => {
579
+ const { t, scene, world, storage, now: start } = slowLow();
580
+ assert.equal(t.handle.scale.state, 'baseline');
581
+ assert.deepEqual(world.renderer.sets, [], 'nothing changes before a slow Low window');
582
+ let now = frames(t, scene, start, 60, 11);
583
+ assert.deepEqual([t.handle.scale.state, t.handle.scale.ratio, t.handle.scale.baseline], ['trial', 1, 60]);
584
+ assert.deepEqual([world.renderer.ratio, world.composer._pixelRatio], [1, 1]);
585
+ now = frames(t, scene, now, 40, 11);
586
+ assert.deepEqual(t.handle.scale, { state: 'kept', ratio: 1, baseline: 60, trial: 40 });
587
+ assert.deepEqual(JSON.parse(storage.map.get(TIER_KEY)), { tier: 'low', at: 5000, scale: 'kept' });
588
+ // It stays put.
589
+ frames(t, scene, now, 60, 30);
590
+ assert.equal(t.handle.scale.state, 'kept');
591
+ assert.deepEqual([world.renderer.sets, world.composer.sets], [[1], [1]]);
592
+ });
593
+
594
+ test('scale: a CPU-bound device is refused, put back, remembered, never retried', () => {
595
+ const { t, scene, world, storage, now: start } = slowLow();
596
+ let now = frames(t, scene, start, 60, 11);
597
+ now = frames(t, scene, now, 52, 11);
598
+ assert.deepEqual(t.handle.scale, { state: 'refused', ratio: null, baseline: 60, trial: 52 });
599
+ assert.deepEqual([world.renderer.ratio, world.composer._pixelRatio], [2, 2]);
600
+ assert.deepEqual(JSON.parse(storage.map.get(TIER_KEY)), { tier: 'low', at: 5000, scale: 'refused' });
601
+ frames(t, scene, now, 80, 60);
602
+ assert.equal(t.handle.scale.state, 'refused');
603
+ assert.deepEqual([world.renderer.sets, world.composer.sets], [[1, 2], [1, 2]]);
604
+ });
605
+
606
+ test('scale: a remembered kept applies at once; a remembered refused never tries', () => {
607
+ const at = 10 * REMEMBER_MS;
608
+ const kept = memoryStorage({ [TIER_KEY]: JSON.stringify({ tier: 'low', at, scale: 'kept' }) });
609
+ const t = makeTiers({ storage: kept, clock: () => at + 1000, deviceMemory: 8, levers: fakeLevers() });
610
+ const world = ratioWorld(3);
611
+ t.frame({ three: world }, true, 0);
612
+ assert.deepEqual([t.handle.reason, t.handle.scale.state, world.renderer.ratio, world.composer._pixelRatio], ['remembered', 'kept', 1.5, 1.5]);
613
+ // Outside the week the mark and its scale are forgotten.
614
+ const old = makeTiers({ storage: kept, clock: () => at + REMEMBER_MS + 1, deviceMemory: 8, levers: fakeLevers() });
615
+ const fresh = ratioWorld();
616
+ old.frame({ three: fresh }, true, 0);
617
+ assert.deepEqual([old.handle.current, old.handle.scale.state, fresh.renderer.sets], ['high', 'none', []]);
618
+
619
+ const refused = memoryStorage({ [TIER_KEY]: JSON.stringify({ tier: 'low', at, scale: 'refused' }) });
620
+ const r = makeTiers({ storage: refused, clock: () => at + 1000, deviceMemory: 8, levers: fakeLevers() });
621
+ const w = ratioWorld();
622
+ frames(r, { three: w }, 0, 80, 60);
623
+ assert.deepEqual([r.handle.current, r.handle.scale.state, w.renderer.sets, w.composer.sets], ['low', 'refused', [], []]);
624
+ // A stored mark without a scale still starts low and measures as today.
625
+ assert.deepEqual(initialTier({ storage: refused, now: at + 1000 }), { tier: 'low', reason: 'remembered' });
626
+ });
627
+
628
+ test('scale: a manual High puts the ratios back; manual Low never steps', () => {
629
+ const { t, scene, world, now: start } = slowLow();
630
+ let now = frames(t, scene, start, 60, 11);
631
+ now = frames(t, scene, now, 40, 11);
632
+ assert.equal(t.handle.scale.state, 'kept');
633
+ t.handle.set('high');
634
+ now = frames(t, scene, now, 16, 1);
635
+ assert.deepEqual([world.renderer.ratio, world.composer._pixelRatio, t.handle.scale.ratio], [2, 2, null]);
636
+ t.handle.set('low');
637
+ now = frames(t, scene, now, 80, 30);
638
+ assert.deepEqual([world.renderer.ratio, world.composer._pixelRatio], [2, 2], 'manual Low leaves the ratio alone');
639
+ // Auto again: the kept step applies at once.
640
+ t.handle.set('auto');
641
+ frames(t, scene, now, 16, 1);
642
+ assert.deepEqual([t.handle.scale.state, world.renderer.ratio, world.composer._pixelRatio], ['kept', 1, 1]);
643
+
644
+ // Manual Low from the start never measures.
645
+ const storage = memoryStorage({ [MODE_KEY]: '"low"' });
646
+ const m = makeTiers({ storage, deviceMemory: 8, levers: fakeLevers() });
647
+ const w = ratioWorld();
648
+ frames(m, { three: w }, 0, 80, 60);
649
+ assert.deepEqual([m.handle.current, m.handle.scale.state, w.renderer.sets], ['low', 'none', []]);
650
+ });
651
+
652
+ test('scale: a manual pick mid-trial puts the ratio back and measures again from the start', () => {
653
+ const { t, scene, world, now: start } = slowLow();
654
+ let now = frames(t, scene, start, 60, 11);
655
+ assert.equal(t.handle.scale.state, 'trial');
656
+ t.handle.set('high');
657
+ now = frames(t, scene, now, 16, 1);
658
+ assert.deepEqual([t.handle.scale.state, world.renderer.ratio], ['baseline', 2]);
659
+ t.handle.set('auto');
660
+ now = frames(t, scene, now, 60, 11);
661
+ assert.deepEqual([t.handle.scale.state, world.renderer.ratio], ['trial', 1]);
662
+ });
663
+
664
+ test('scale: a weakest-tier deck never touches the ratios', () => {
665
+ const { t, scene, world } = slowLow({ weakest: true });
666
+ frames(t, scene, 6000, 80, 60);
667
+ assert.deepEqual([t.handle.scale.state, world.renderer.sets, world.composer.sets], ['none', [], []]);
668
+ });
669
+
670
+ test('scale: a ratio of 1 or less, or a renderer it cannot read, does nothing and never throws', () => {
671
+ for (const world of [
672
+ ratioWorld(1),
673
+ ratioWorld(0.75),
674
+ { renderer: { getPixelRatio: () => 2, setPixelRatio() {} } },
675
+ { renderer: { getPixelRatio: () => 2, setPixelRatio() {} }, composer: { _pixelRatio: NaN, setPixelRatio() {} } },
676
+ { renderer: { getPixelRatio: () => NaN, setPixelRatio() {} }, composer: { _pixelRatio: 2, setPixelRatio() {} } },
677
+ { renderer: { getPixelRatio() { throw new Error('lost'); }, setPixelRatio() {} }, composer: { _pixelRatio: 2, setPixelRatio() {} } },
678
+ { renderer: {} },
679
+ ]) {
680
+ const { t, scene, now } = slowLow({ world });
681
+ frames(t, scene, now, 80, 30);
682
+ assert.deepEqual([t.handle.scale.state, t.handle.scale.ratio], ['settled', null]);
683
+ assert.deepEqual(world.renderer.sets ?? [], []);
684
+ }
685
+ // A remembered kept on a 1x screen settles too.
686
+ const at = 10 * REMEMBER_MS;
687
+ const t = makeTiers({ storage: memoryStorage({ [TIER_KEY]: JSON.stringify({ tier: 'low', at, scale: 'kept' }) }), clock: () => at, deviceMemory: 8, levers: fakeLevers() });
688
+ const w = ratioWorld(1);
689
+ t.frame({ three: w }, true, 0);
690
+ assert.deepEqual([t.handle.scale.state, w.renderer.sets], ['settled', []]);
691
+ });
692
+
693
+ test('scale: a hidden page and frames that do not count do not advance its windows', () => {
694
+ const { t, scene, world, now: start } = slowLow();
695
+ let now = frames(t, scene, start, 80, 30, false);
696
+ assert.equal(t.handle.scale.state, 'baseline');
697
+ globalThis.document = { hidden: true };
698
+ try {
699
+ now = frames(t, scene, now, 80, 30);
700
+ } finally {
701
+ delete globalThis.document;
702
+ }
703
+ assert.deepEqual([t.handle.scale.state, world.renderer.sets], ['baseline', []]);
704
+ // Gaps cut a window short too.
705
+ for (let i = 0; i < 20; i += 1) {
706
+ now = frames(t, scene, now + 2000, 80, 5);
707
+ }
708
+ assert.deepEqual([t.handle.scale.state, world.renderer.sets], ['baseline', []]);
709
+ frames(t, scene, now, 80, 11);
710
+ assert.equal(t.handle.scale.state, 'trial');
711
+ });
712
+
713
+ test('scale: putting back leaves a ratio someone else changed alone; a new world inherits nothing', () => {
714
+ const { t, scene, world, now: start } = slowLow();
715
+ let now = frames(t, scene, start, 60, 11);
716
+ now = frames(t, scene, now, 40, 11);
717
+ assert.equal(t.handle.scale.state, 'kept');
718
+ // Someone else picks the renderer's ratio; the composer still holds ours.
719
+ world.renderer.setPixelRatio(1.25);
720
+ t.handle.set('high');
721
+ now = frames(t, scene, now, 16, 1);
722
+ assert.deepEqual([world.renderer.ratio, world.composer._pixelRatio], [1.25, 2]);
723
+
724
+ // A new world mid-trial: the old one is put back, the new one measured from the start.
725
+ const s = slowLow();
726
+ let n = frames(s.t, s.scene, s.now, 60, 11);
727
+ assert.equal(s.t.handle.scale.state, 'trial');
728
+ const next = ratioWorld(2);
729
+ s.scene.three = next;
730
+ n = frames(s.t, s.scene, n, 60, 1);
731
+ assert.deepEqual([s.world.renderer.ratio, s.world.composer._pixelRatio], [2, 2]);
732
+ assert.deepEqual([s.t.handle.scale.state, next.renderer.sets], ['baseline', []]);
733
+ frames(s.t, s.scene, n, 60, 11);
734
+ assert.deepEqual([s.t.handle.scale.state, next.renderer.ratio, s.world.renderer.ratio], ['trial', 1, 2]);
735
+ });
736
+
737
+ test('scale: a trip or another place mid-trial drops the trial; a cheaper place never reads as kept (review P2)', () => {
738
+ // The trip's frames do not count: the trial is dropped and the ratio put back.
739
+ const { t, scene, world, storage, now: start } = slowLow();
740
+ scene.data = { path: 'town' };
741
+ let now = frames(t, scene, start, 60, 11);
742
+ assert.equal(t.handle.scale.state, 'trial');
743
+ now = frames(t, scene, now, 60, 2, false);
744
+ assert.deepEqual([t.handle.scale.state, t.handle.scale.baseline, world.renderer.ratio, world.composer._pixelRatio], ['baseline', null, 2, 2]);
745
+ // A cheap game behind the door is measured on its own and is never slow.
746
+ scene.data = { path: 'game' };
747
+ now = frames(t, scene, now, 20, 40);
748
+ assert.deepEqual([t.handle.scale.state, world.renderer.ratio], ['baseline', 2]);
749
+ assert.equal(JSON.parse(storage.map.get(TIER_KEY)).scale, undefined, 'nothing remembered');
750
+
751
+ // A scene swapped in mid-trial with every frame counting: dropped the same way.
752
+ const s = slowLow();
753
+ s.scene.data = { path: 'town' };
754
+ let n = frames(s.t, s.scene, s.now, 60, 11);
755
+ assert.equal(s.t.handle.scale.state, 'trial');
756
+ n = frames(s.t, s.scene, n, 20, 5);
757
+ s.scene.data = { path: 'game' };
758
+ frames(s.t, s.scene, n, 20, 6);
759
+ assert.deepEqual([s.t.handle.scale.state, s.world.renderer.ratio], ['baseline', 2]);
760
+ });
761
+
762
+ test('scale: a new world mid-trial starts its window afresh (review P2)', () => {
763
+ const { t, scene, now: start } = slowLow();
764
+ let now = frames(t, scene, start, 60, 11);
765
+ assert.equal(t.handle.scale.state, 'trial');
766
+ // Half a trial window on the old world, then a new one: those frames are not its.
767
+ now = frames(t, scene, now, 60, 5);
768
+ const next = ratioWorld(2);
769
+ scene.three = next;
770
+ now = frames(t, scene, now, 60, 6);
771
+ assert.deepEqual([t.handle.scale.state, next.renderer.sets], ['baseline', []]);
772
+ frames(t, scene, now, 60, 5);
773
+ assert.deepEqual([t.handle.scale.state, next.renderer.ratio], ['trial', 1]);
774
+ });
775
+
543
776
  test('levers: a Shape that says solid blocks, so it is scenery, not decor (review P1)', () => {
544
777
  assert.equal(classify({ Transform: {}, Shape: { solid: true } }), 'static');
545
778
  assert.equal(classify({ Transform: {}, Shape: { solid: true }, Model: {} }), 'static');
@@ -1030,6 +1263,173 @@ test('low: keyless, unmarked scenes have the previous graph and no world flag',
1030
1263
  assert.equal(Object.hasOwn(s, 'sky'), false, 'and the runtime is as it was');
1031
1264
  });
1032
1265
 
1266
+ // A frame without localStorage (castle.xyz's sandboxed player frame): the
1267
+ // tier mark and the Graphics pick live in memory and are written through to
1268
+ // LocalCache (`code/client/deviceStorage.js`), here a stand-in that keeps its
1269
+ // entries across "reloads" (a new storage over the same cache) and counts
1270
+ // every call. `hold` keeps its reads waiting until `release`.
1271
+ function fakeCache(entries = {}) {
1272
+ const kept = new Map(Object.entries(entries).map(([k, v]) => [CACHE_PREFIX + k, v]));
1273
+ const calls = [];
1274
+ const waiting = [];
1275
+ const cache = {
1276
+ kept,
1277
+ calls,
1278
+ hold: false,
1279
+ release: () => {
1280
+ cache.hold = false;
1281
+ waiting.splice(0).forEach((go) => go());
1282
+ },
1283
+ async getText(key) {
1284
+ calls.push(['getText', key]);
1285
+ if (cache.hold) {
1286
+ await new Promise((go) => waiting.push(go));
1287
+ }
1288
+ return kept.has(key) ? kept.get(key) : null;
1289
+ },
1290
+ async set(key, value) {
1291
+ calls.push(['set', key]);
1292
+ kept.set(key, value);
1293
+ },
1294
+ async remove(key) {
1295
+ calls.push(['remove', key]);
1296
+ kept.delete(key);
1297
+ },
1298
+ };
1299
+ return cache;
1300
+ }
1301
+ const settle = () => new Promise((go) => setTimeout(go, 0));
1302
+
1303
+ test('device storage: localStorage is used only when a set and a remove work', () => {
1304
+ const page = memoryStorage();
1305
+ page.removeItem = (k) => page.map.delete(k);
1306
+ assert.equal(usableLocalStorage({ localStorage: page }), page);
1307
+ assert.equal(page.map.size, 0, 'the probe leaves nothing behind');
1308
+ assert.equal(usableLocalStorage({ get localStorage() { throw new Error('SecurityError'); } }), null, 'a sandboxed frame');
1309
+ assert.equal(usableLocalStorage({ localStorage: { ...throwing, removeItem() {} } }), null, 'a Storage whose writes throw');
1310
+ assert.equal(usableLocalStorage({}), null);
1311
+ });
1312
+
1313
+ await asyncTest('device storage: no localStorage, the pick and the low mark (with its scale) come back after a reload through LocalCache', async () => {
1314
+ const cache = fakeCache();
1315
+ const at = 10 * REMEMBER_MS;
1316
+ // First visit: the judge finds the device slow, the resolution step keeps
1317
+ // half the ratio, and the player picks Low by hand.
1318
+ const first = makeCachedStorage(() => cache);
1319
+ const { t, scene, now: start } = slowLow({ storage: first, clock: () => at });
1320
+ let now = frames(t, scene, start, 60, 11);
1321
+ frames(t, scene, now, 40, 11);
1322
+ assert.equal(t.handle.scale.state, 'kept');
1323
+ t.set('low');
1324
+ await settle();
1325
+ assert.deepEqual(JSON.parse(cache.kept.get(CACHE_PREFIX + TIER_KEY)), { tier: 'low', at, scale: 'kept' });
1326
+ assert.equal(cache.kept.get(CACHE_PREFIX + MODE_KEY), '"low"');
1327
+ // The reload: a new storage over the same cache, primed before the tiers
1328
+ // are made (the quality entry's wait).
1329
+ const second = makeCachedStorage(() => cache);
1330
+ assert.equal(second.getItem(MODE_KEY), null, 'nothing before the prime');
1331
+ assert.deepEqual([...(await primeTiers({ storage: second }))].sort(), [MODE_KEY, TIER_KEY].sort());
1332
+ const again = makeTiers({ storage: second, clock: () => at + 60000, deviceMemory: 8, levers: fakeLevers() });
1333
+ assert.equal(again.handle.mode, 'low');
1334
+ // And the remembered mark with its outcome, seen in auto.
1335
+ again.set('auto');
1336
+ const world = ratioWorld(2);
1337
+ again.frame({ three: world }, true, 0);
1338
+ assert.deepEqual([again.handle.current, again.handle.reason, again.handle.scale.state, world.renderer.ratio], ['low', 'remembered', 'kept', 1]);
1339
+ });
1340
+
1341
+ await asyncTest('device storage: values that arrive after the tiers picked are adopted, the scale step included', async () => {
1342
+ const at = 10 * REMEMBER_MS;
1343
+ const cache = fakeCache({ [TIER_KEY]: JSON.stringify({ tier: 'low', at, scale: 'kept' }) });
1344
+ cache.hold = true;
1345
+ const storage = makeCachedStorage(() => cache);
1346
+ const t = makeTiers({ storage, clock: () => at + 1000, deviceMemory: 8, levers: fakeLevers() });
1347
+ const world = ratioWorld(2);
1348
+ const scene = { three: world };
1349
+ t.frame(scene, false, 0);
1350
+ await settle();
1351
+ assert.deepEqual([t.handle.current, t.handle.reason], ['high', 'auto'], 'High by its hints while the mark is on its way');
1352
+ cache.release();
1353
+ await settle();
1354
+ assert.deepEqual([t.handle.current, t.handle.reason], ['low', 'remembered']);
1355
+ t.frame(scene, true, 16);
1356
+ assert.deepEqual([t.handle.scale.state, world.renderer.ratio], ['kept', 1], 'the kept ratio at once, as on a load with it');
1357
+ });
1358
+
1359
+ await asyncTest('device storage: a pick made before the stored values arrive wins over them', async () => {
1360
+ const cache = fakeCache({ [MODE_KEY]: '"low"' });
1361
+ cache.hold = true;
1362
+ const storage = makeCachedStorage(() => cache);
1363
+ const t = makeTiers({ storage, deviceMemory: 8, levers: fakeLevers() });
1364
+ await settle();
1365
+ t.set('high');
1366
+ cache.release();
1367
+ await settle();
1368
+ assert.equal(t.handle.mode, 'high');
1369
+ assert.equal(storage.getItem(MODE_KEY), '"high"');
1370
+ assert.equal(cache.kept.get(CACHE_PREFIX + MODE_KEY), '"high"', 'and it is the one kept for the next visit');
1371
+ assert.deepEqual(await storage.prime([MODE_KEY]), new Set(), 'asked again, the stored value is still not adopted');
1372
+ });
1373
+
1374
+ await asyncTest('device storage: quick picks reach LocalCache in order, even when its writes finish out of order', async () => {
1375
+ const kept = new Map();
1376
+ // The first write takes longer than the second: unchained, the older pick
1377
+ // would land last.
1378
+ let delay = 20;
1379
+ const cache = {
1380
+ async getText() { return null; },
1381
+ async set(key, value) {
1382
+ const wait = delay;
1383
+ delay = 0;
1384
+ await new Promise((go) => setTimeout(go, wait));
1385
+ kept.set(key, value);
1386
+ },
1387
+ async remove(key) { kept.delete(key); },
1388
+ };
1389
+ const storage = makeCachedStorage(() => cache);
1390
+ storage.setItem(MODE_KEY, '"low"');
1391
+ storage.setItem(MODE_KEY, '"high"');
1392
+ await new Promise((go) => setTimeout(go, 40));
1393
+ assert.equal(kept.get(CACHE_PREFIX + MODE_KEY), '"high"');
1394
+ });
1395
+
1396
+ await asyncTest('device storage: a working localStorage is used as it was, and LocalCache is never asked', async () => {
1397
+ const previous = Object.getOwnPropertyDescriptor(globalThis, 'localStorage');
1398
+ const page = memoryStorage();
1399
+ page.removeItem = (k) => page.map.delete(k);
1400
+ Object.defineProperty(globalThis, 'localStorage', { configurable: true, value: page });
1401
+ try {
1402
+ assert.equal(deviceStorage(), page);
1403
+ assert.equal(primeTiers(), null, 'nothing to wait for');
1404
+ const t = makeTiers({ deviceMemory: 8, levers: fakeLevers() });
1405
+ assert.equal('prime' in page, false);
1406
+ t.set('low');
1407
+ assert.equal(page.map.get(MODE_KEY), '"low"');
1408
+ assert.deepEqual([...page.map.keys()], [MODE_KEY], 'only what tiers wrote, the probe gone');
1409
+ } finally {
1410
+ if (previous) {
1411
+ Object.defineProperty(globalThis, 'localStorage', previous);
1412
+ } else {
1413
+ delete globalThis.localStorage;
1414
+ }
1415
+ }
1416
+ });
1417
+
1418
+ await asyncTest('device storage: without a LocalCache the fallback keeps values for the visit and never throws', async () => {
1419
+ const storage = makeCachedStorage(() => undefined);
1420
+ storage.setItem(MODE_KEY, '"low"');
1421
+ assert.equal(storage.getItem(MODE_KEY), '"low"');
1422
+ assert.deepEqual(await storage.prime([TIER_KEY]), new Set());
1423
+ const broken = makeCachedStorage(() => Promise.reject(new Error('no sdk')));
1424
+ broken.setItem(MODE_KEY, '"high"');
1425
+ broken.removeItem(MODE_KEY);
1426
+ assert.equal(broken.getItem(MODE_KEY), null);
1427
+ assert.deepEqual(await broken.prime([MODE_KEY]), new Set());
1428
+ // A host that never answers costs the wait's cap, no more.
1429
+ const never = { prime: () => new Promise(() => {}) };
1430
+ assert.deepEqual(await primeTiers({ storage: never, waitMs: 5 }), new Set());
1431
+ });
1432
+
1033
1433
  // The hub system with `hub.tiers` absent: never a call into tiers.js, never a
1034
1434
  // storage read, no harness handle. tiers.js is stubbed for hub.js so any call
1035
1435
  // is counted.
@@ -1039,7 +1439,7 @@ const mediaStub = 'export const initialMedia = {}; export const playMedia = () =
1039
1439
  const tiersStub = `
1040
1440
  export function makeTiers() {
1041
1441
  globalThis.__tiersMade = (globalThis.__tiersMade ?? 0) + 1;
1042
- return { mode: 'auto', set() {}, frame() { globalThis.__tiersFrames = (globalThis.__tiersFrames ?? 0) + 1; }, handle: { stub: true } };
1442
+ return (globalThis.__tiersObj = { mode: 'auto', set() {}, frame() { globalThis.__tiersFrames = (globalThis.__tiersFrames ?? 0) + 1; }, handle: { stub: true } });
1043
1443
  }`;
1044
1444
  const url = (src) => 'data:text/javascript,' + encodeURIComponent(src);
1045
1445
  register(
@@ -1256,6 +1656,51 @@ visibilityTest('place hidden: instanced actor roots go out and back, otherwise r
1256
1656
  assert.equal(drawn(world, 'trophy'), true, 'back while far, as before');
1257
1657
  });
1258
1658
 
1659
+ // v1.184 review: a solid private hide and the tier lever each save and
1660
+ // restore visibility; neither may capture and later restore the other's.
1661
+ for (const solidFirst of [true, false]) {
1662
+ visibilityTest(`solid hide and the tier lever on an instanced low actor (${solidFirst ? 'hide on High, clear, then Low' : 'hide on Low, High, clear, then Low'})`, () => {
1663
+ const actor = { ...hiddenActor('wall', {}, [5, 2, 0]), tier: LOW };
1664
+ const { world, tiers, frame } = visibilityWorld([actor], solidFirst ? 'high' : 'low');
1665
+ const entry = world.nodes.get('wall');
1666
+ entry.node.visible = true;
1667
+ entry.instancedRig = Object.assign(new Obj('instance-rig'), { visible: true });
1668
+ entry.node.add(entry.instancedRig);
1669
+ const solidHide = (on) => {
1670
+ hub.hiddenMe = new Set(on ? ['wall'] : []);
1671
+ hub.solidMe = new Set(on ? ['wall'] : []);
1672
+ mergeHidden();
1673
+ };
1674
+ let now = 0;
1675
+ const step = () => frame((now += 16));
1676
+ // On High the hide lands before the tier lever first looks at the root.
1677
+ if (!solidFirst) {
1678
+ step();
1679
+ }
1680
+ solidHide(true);
1681
+ step();
1682
+ assert.equal(actor.components.Transform.y, 2, 'a solid hide keeps the actor in place');
1683
+ assert.equal(entry.instancedRig.visible, false, 'its rig is drawn hidden');
1684
+ if (solidFirst) {
1685
+ solidHide(false);
1686
+ step();
1687
+ tiers.set('low');
1688
+ step();
1689
+ } else {
1690
+ tiers.set('high');
1691
+ step();
1692
+ assert.equal(entry.node.visible, false, 'High takes the low-marked instanced root out');
1693
+ solidHide(false);
1694
+ step();
1695
+ tiers.set('low');
1696
+ step();
1697
+ }
1698
+ assert.equal(drawn(world, 'wall'), true);
1699
+ assert.equal(entry.node.visible, true, 'the tier lever restores the authored root flag');
1700
+ assert.equal(entry.instancedRig.visible, true, 'the solid hide restored its rig');
1701
+ });
1702
+ }
1703
+
1259
1704
  visibilityTest('place hidden: a game through a door keeps only the place hide and shadow levers', () => {
1260
1705
  const { world, scene, frame } = visibilityWorld([hiddenActor('trophy')]);
1261
1706
  scene.content = {};
@@ -1320,6 +1765,11 @@ visibilityTest('place hidden: a game through a door keeps only the place hide an
1320
1765
  assert.equal(globalThis.__tiersFrames, 2);
1321
1766
  assert.equal(graphics, 1);
1322
1767
  assert.deepEqual(globalThis.__hub.tier, { stub: true });
1768
+ // A stored pick that arrives later (deviceStorage.js) redraws the row once.
1769
+ globalThis.__tiersObj.mode = 'low';
1770
+ late[1].afterBehaviors({ ...scene, multiplayer: mp });
1771
+ late[1].afterBehaviors({ ...scene, multiplayer: mp });
1772
+ assert.equal(graphics, 2);
1323
1773
  deck.tiers = false;
1324
1774
  });
1325
1775
  delete globalThis.localStorage;
@@ -0,0 +1,71 @@
1
+ // The toast is drawn only in a row clear of every control, else not drawn
2
+ // (the caption lanes' rule): at 509x218 with the town's offers there is no
3
+ // such row; at 844x390 there is, and the toast shows there.
4
+ import assert from 'node:assert/strict';
5
+ import { readFile } from 'node:fs/promises';
6
+ import { fileURLToPath } from 'node:url';
7
+ import { chromium } from 'playwright-core';
8
+ import { launchChromium, logRenderer } from '../../../experiments/hub-town/qa/launch.mjs';
9
+ const root = new URL('../../../', import.meta.url);
10
+ const browser = await launchChromium(chromium, { executablePath: process.env.CHROME });
11
+ try {
12
+ for (const [width, height, expectShown] of [[509, 218, false], [844, 390, true]]) {
13
+ for (const safeInsets of [false, true]) {
14
+ const context = await browser.newContext({ viewport: { width, height }, isMobile: true, hasTouch: true });
15
+ const page = await context.newPage();
16
+ await page.route('http://toast.test/**', async route => {
17
+ const pathname = new URL(route.request().url()).pathname;
18
+ if (pathname === '/') return route.fulfill({ contentType: 'text/html', body: '<meta name="viewport" content="width=device-width,initial-scale=1"><body style="margin:0"></body>' });
19
+ const url = new URL(`.${pathname}`, root);
20
+ assert(fileURLToPath(url).startsWith(fileURLToPath(root)));
21
+ await route.fulfill({ contentType: 'text/javascript', body: await readFile(url, 'utf8') });
22
+ });
23
+ await page.goto('http://toast.test/');
24
+ await logRenderer(page, 'toast no row');
25
+ const result = await page.evaluate(async (safeInsets) => {
26
+ const { makeChrome } = await import('/kits/hub-game/code/client/chrome.js');
27
+ const chrome = makeChrome({ avatarCount: 4, onBack() {}, onAvatar() {}, safeInsets });
28
+ chrome.setWorldLabelFocus(false);
29
+ chrome.showBack(true, 'Back');
30
+ chrome.soundControl(true, { volume: 0.7, muted: false }, { onMuted() {}, onVolume() {} });
31
+ chrome.showPicker(true, 0, undefined, { onPick() {} });
32
+ chrome.setEmotes([['wave', '👋']]);
33
+ chrome.setSay({ reactions: [], phrases: [] });
34
+ chrome.setDoors([{ id: 'color', title: 'Color Call' }]);
35
+ chrome.setCompanionBadge(true, 'Chirp', () => {});
36
+ chrome.talkPrompt('Chirp', true);
37
+ chrome.setActions([{ id: 'invite-friend', label: 'Invite a friend' }, { id: 'market-looks', label: 'Market looks' }], () => {}, true, 1, !(innerWidth > innerHeight));
38
+ chrome.setHud({ title: 'Castle Town', text: 'Find your house' }, null);
39
+ const raf = () => new Promise(resolve => requestAnimationFrame(() => resolve()));
40
+ for (let round = 0; round < 3; round++) {
41
+ for (let i = 0; i < 3; i++) {
42
+ chrome.beginLayoutFrame(); chrome.beginWorldLabels();
43
+ chrome.setToast('Welcome back to Castle Town');
44
+ chrome.flushWorldLabels(); chrome.endLayoutFrame();
45
+ await raf();
46
+ }
47
+ await new Promise(resolve => setTimeout(resolve, safeInsets ? 550 : 0));
48
+ }
49
+ const shown = n => {
50
+ if (!n?.isConnected) {return false;}
51
+ for (let p = n; p; p = p.parentElement) {const s = getComputedStyle(p); if (s.display === 'none' || s.visibility === 'hidden') {return false;}}
52
+ const r = n.getBoundingClientRect(); return r.width > 0 && r.height > 0;
53
+ };
54
+ const toast = document.querySelector('[data-hub="toast"]');
55
+ const box = toast.getBoundingClientRect();
56
+ const hits = [...document.querySelectorAll('button')].filter(n => shown(n) && n.textContent.trim() && n !== chrome.companionTalkButton)
57
+ .filter(n => { const r = n.getBoundingClientRect(); return r.left < box.right && r.right > box.left && r.top < box.bottom && r.bottom > box.top; })
58
+ .map(n => n.textContent.trim());
59
+ const toastShown = shown(toast);
60
+ chrome.dispose();
61
+ return { toastShown, hits: toastShown ? hits : [] };
62
+ }, safeInsets);
63
+ const label = `${width}x${height} safeInsets=${safeInsets}`;
64
+ assert.deepEqual(result.hits, [], `${label}: a drawn toast covers no control`);
65
+ if (expectShown) {assert.ok(result.toastShown, `${label}: with a clear row the toast shows`);}
66
+ if (!expectShown && !safeInsets) {assert.equal(result.toastShown, false, `${label}: with no clear row the toast is not drawn`);}
67
+ console.log(`${label}: toast ${result.toastShown ? 'shown, clear' : 'not drawn'}`);
68
+ await context.close();
69
+ }
70
+ }
71
+ } finally { await browser.close(); }
@@ -200,6 +200,17 @@ let n = 0;
200
200
  n += 1;
201
201
  }
202
202
 
203
+ // A player whose connection has dropped (kept for its reconnect window) is
204
+ // not told: nobody is there to read it.
205
+ {
206
+ const b = boot();
207
+ b.session.players = PLAYERS.filter((p) => p.playerId !== 'p3');
208
+ b.ctx().go('race', ['p1']);
209
+ const went = b.sent.filter(([, msg]) => msg.k === 'hub-went');
210
+ assert.deepEqual(went, [['p2', { k: 'hub-went', players: ['p1'], door: 'race' }]]);
211
+ n += 1;
212
+ }
213
+
203
214
  // A game answers neither.
204
215
  {
205
216
  const b = boot({ sessionId: 'dev:hub.race.abc123' });