castle-web-cli 0.4.239 → 0.4.241

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (396) hide show
  1. package/dist/agent.js +5 -1
  2. package/dist/api.d.ts +20 -0
  3. package/dist/api.js +57 -0
  4. package/dist/bundle.d.ts +38 -1
  5. package/dist/bundle.js +309 -13
  6. package/dist/castle-host/host.js +163 -11
  7. package/dist/castleJson.d.ts +10 -0
  8. package/dist/castleJson.js +46 -2
  9. package/dist/check.js +5 -2
  10. package/dist/devSessionServer.js +4 -1
  11. package/dist/devSessionStorage.d.ts +1 -0
  12. package/dist/devSessionStorage.js +32 -7
  13. package/dist/importOrder.d.ts +2 -0
  14. package/dist/importOrder.js +29 -0
  15. package/dist/index.js +6 -3
  16. package/dist/init.js +24 -2
  17. package/dist/multiplayerDoc.d.ts +1 -1
  18. package/dist/multiplayerDoc.js +2 -0
  19. package/dist/platformDoc.js +3 -2
  20. package/dist/playPagePolicy.js +5 -1
  21. package/dist/resetLeaderboards.d.ts +8 -1
  22. package/dist/resetLeaderboards.js +43 -8
  23. package/dist/roomLogs.d.ts +1 -0
  24. package/dist/roomLogs.js +30 -6
  25. package/dist/save-deck.d.ts +32 -2
  26. package/dist/save-deck.js +240 -39
  27. package/kits/base/CLAUDE.md +1 -1
  28. package/kits/base/castle.json +1 -1
  29. package/kits/base/sdk/README.md +174 -6
  30. package/kits/base/sdk/analytics.d.ts +8 -0
  31. package/kits/base/sdk/analytics.js +92 -0
  32. package/kits/base/sdk/castle.d.ts +5 -1
  33. package/kits/base/sdk/castle.js +2 -0
  34. package/kits/base/sdk/commands.d.ts +48 -0
  35. package/kits/base/sdk/commands.js +1 -0
  36. package/kits/base/sdk/debugConsole.d.ts +17 -0
  37. package/kits/base/sdk/debugConsole.js +154 -0
  38. package/kits/base/sdk/experiments.js +24 -1
  39. package/kits/base/sdk/hostRetry.d.ts +7 -0
  40. package/kits/base/sdk/hostRetry.js +57 -0
  41. package/kits/base/sdk/hub.d.ts +20 -2
  42. package/kits/base/sdk/hub.js +99 -13
  43. package/kits/base/sdk/multiplayer.d.ts +2 -0
  44. package/kits/base/sdk/multiplayer.js +168 -26
  45. package/kits/base/sdk/reconnectBudget.d.ts +6 -0
  46. package/kits/base/sdk/reconnectBudget.js +41 -1
  47. package/kits/base/sdk/runtime.js +36 -19
  48. package/kits/base/sdk/server/hub.d.ts +19 -0
  49. package/kits/base/sdk/server/hub.js +12 -0
  50. package/kits/base/sdk/server/platformHandle.d.ts +1 -0
  51. package/kits/base/sdk/server/wrapper.d.ts +1 -1
  52. package/kits/base/sdk/server/wrapper.js +26 -1
  53. package/kits/base/sdk/transport.d.ts +2 -1
  54. package/kits/base/sdk/transport.js +35 -0
  55. package/kits/hub-game/CLAUDE.md +66 -19
  56. package/kits/hub-game/code/client/act.js +9 -6
  57. package/kits/hub-game/code/client/actCore.js +26 -6
  58. package/kits/hub-game/code/client/actGateLog.js +36 -0
  59. package/kits/hub-game/code/client/actionOverflow.js +29 -8
  60. package/kits/hub-game/code/client/actionRailSurface.js +186 -0
  61. package/kits/hub-game/code/client/actionRailTree.js +173 -0
  62. package/kits/hub-game/code/client/askSurface.js +85 -0
  63. package/kits/hub-game/code/client/askTree.js +51 -0
  64. package/kits/hub-game/code/client/attention.js +31 -6
  65. package/kits/hub-game/code/client/ballot.js +42 -5
  66. package/kits/hub-game/code/client/ballotSurface.js +115 -0
  67. package/kits/hub-game/code/client/ballotTree.js +180 -0
  68. package/kits/hub-game/code/client/catchingUp.js +19 -0
  69. package/kits/hub-game/code/client/celebrate.js +66 -0
  70. package/kits/hub-game/code/client/chrome.js +481 -57
  71. package/kits/hub-game/code/client/companion.js +93 -23
  72. package/kits/hub-game/code/client/companionDress.js +1 -1
  73. package/kits/hub-game/code/client/cornerSurface.js +106 -0
  74. package/kits/hub-game/code/client/cornerTree.js +83 -0
  75. package/kits/hub-game/code/client/decor.js +20 -11
  76. package/kits/hub-game/code/client/deviceStorage.js +121 -0
  77. package/kits/hub-game/code/client/disguise.js +23 -0
  78. package/kits/hub-game/code/client/disguiseDraw.js +87 -0
  79. package/kits/hub-game/code/client/dockSurface.js +206 -0
  80. package/kits/hub-game/code/client/dockTree.js +232 -0
  81. package/kits/hub-game/code/client/earned.js +29 -0
  82. package/kits/hub-game/code/client/emoteSurface.js +188 -0
  83. package/kits/hub-game/code/client/emoteTree.js +264 -0
  84. package/kits/hub-game/code/client/farAvatars.js +4 -3
  85. package/kits/hub-game/code/client/fpsTelemetry.js +3 -1
  86. package/kits/hub-game/code/client/grab.js +121 -50
  87. package/kits/hub-game/code/client/holdShow.js +19 -0
  88. package/kits/hub-game/code/client/hookLayer.js +96 -12
  89. package/kits/hub-game/code/client/hubControls.js +7 -1
  90. package/kits/hub-game/code/client/hudSurface.js +11 -3
  91. package/kits/hub-game/code/client/hudTree.js +7 -4
  92. package/kits/hub-game/code/client/idle.js +21 -3
  93. package/kits/hub-game/code/client/invites.js +24 -3
  94. package/kits/hub-game/code/client/keys.js +15 -0
  95. package/kits/hub-game/code/client/labelsNear.js +8 -1
  96. package/kits/hub-game/code/client/layoutCache.js +57 -8
  97. package/kits/hub-game/code/client/loadingCover.js +53 -4
  98. package/kits/hub-game/code/client/menuIcons.js +15 -0
  99. package/kits/hub-game/code/client/menuSurface.js +102 -0
  100. package/kits/hub-game/code/client/menuTree.js +135 -0
  101. package/kits/hub-game/code/client/modelLook.js +41 -0
  102. package/kits/hub-game/code/client/padCues.js +11 -7
  103. package/kits/hub-game/code/client/padReadability.js +3 -3
  104. package/kits/hub-game/code/client/pickerSurface.js +152 -0
  105. package/kits/hub-game/code/client/pickerTree.js +163 -0
  106. package/kits/hub-game/code/client/pushVisit.js +4 -2
  107. package/kits/hub-game/code/client/quality.js +188 -29
  108. package/kits/hub-game/code/client/qualityEntry.js +10 -1
  109. package/kits/hub-game/code/client/quickChatSurface.js +222 -0
  110. package/kits/hub-game/code/client/quickChatTree.js +201 -0
  111. package/kits/hub-game/code/client/rehello.js +75 -0
  112. package/kits/hub-game/code/client/renderVisibility.js +17 -0
  113. package/kits/hub-game/code/client/replay.js +118 -0
  114. package/kits/hub-game/code/client/role.js +3 -0
  115. package/kits/hub-game/code/client/safeLayout.js +441 -56
  116. package/kits/hub-game/code/client/safeStyle.js +13 -10
  117. package/kits/hub-game/code/client/say.js +2 -0
  118. package/kits/hub-game/code/client/soundSurface.js +77 -0
  119. package/kits/hub-game/code/client/soundTree.js +74 -0
  120. package/kits/hub-game/code/client/soundscape.js +12 -9
  121. package/kits/hub-game/code/client/soundscapeCues.js +1 -1
  122. package/kits/hub-game/code/client/state.js +67 -1
  123. package/kits/hub-game/code/client/stuckSurface.js +76 -0
  124. package/kits/hub-game/code/client/stuckTree.js +67 -0
  125. package/kits/hub-game/code/client/talk.js +42 -12
  126. package/kits/hub-game/code/client/talkTree.js +4 -2
  127. package/kits/hub-game/code/client/textAskSurface.js +147 -0
  128. package/kits/hub-game/code/client/textAskTree.js +67 -0
  129. package/kits/hub-game/code/client/tiers.js +252 -27
  130. package/kits/hub-game/code/client/together.js +4 -1
  131. package/kits/hub-game/code/client/uiDom.js +86 -8
  132. package/kits/hub-game/code/client/uiTree.js +33 -4
  133. package/kits/hub-game/code/client/vehicle.js +72 -51
  134. package/kits/hub-game/code/client/weakestTier.js +75 -31
  135. package/kits/hub-game/code/client/wear.js +159 -5
  136. package/kits/hub-game/code/client/worldLabels.js +205 -25
  137. package/kits/hub-game/code/companionSpec.js +4 -2
  138. package/kits/hub-game/code/server/act.js +3 -0
  139. package/kits/hub-game/code/server/actGate.js +83 -0
  140. package/kits/hub-game/code/server/actions.js +71 -15
  141. package/kits/hub-game/code/server/actors.js +20 -5
  142. package/kits/hub-game/code/server/analytics.js +35 -3
  143. package/kits/hub-game/code/server/ask.js +39 -3
  144. package/kits/hub-game/code/server/ballot.js +167 -4
  145. package/kits/hub-game/code/server/celebrate.js +64 -0
  146. package/kits/hub-game/code/server/companion.js +17 -2
  147. package/kits/hub-game/code/server/decor.js +11 -2
  148. package/kits/hub-game/code/server/disguise.js +63 -0
  149. package/kits/hub-game/code/server/earned.js +6 -2
  150. package/kits/hub-game/code/server/friendBests.js +13 -4
  151. package/kits/hub-game/code/server/friendsAmong.js +67 -8
  152. package/kits/hub-game/code/server/grab.js +12 -2
  153. package/kits/hub-game/code/server/heldOffers.js +142 -0
  154. package/kits/hub-game/code/server/holdShow.js +98 -0
  155. package/kits/hub-game/code/server/hub.js +991 -72
  156. package/kits/hub-game/code/server/idle.js +110 -9
  157. package/kits/hub-game/code/server/index.js +9 -0
  158. package/kits/hub-game/code/server/labels.js +13 -3
  159. package/kits/hub-game/code/server/manifest.js +94 -6
  160. package/kits/hub-game/code/server/menu.js +26 -3
  161. package/kits/hub-game/code/server/npcs.js +55 -9
  162. package/kits/hub-game/code/server/observe.js +67 -6
  163. package/kits/hub-game/code/server/players.js +14 -2
  164. package/kits/hub-game/code/server/replay.js +135 -0
  165. package/kits/hub-game/code/server/standing.js +7 -3
  166. package/kits/hub-game/code/server/storageLimit.js +4 -1
  167. package/kits/hub-game/code/server/townDay.js +74 -0
  168. package/kits/hub-game/code/server/vehicle.js +3 -0
  169. package/kits/hub-game/code/server/vis.js +26 -4
  170. package/kits/hub-game/code/server/wallet.js +677 -0
  171. package/kits/hub-game/code/server/wear.js +13 -3
  172. package/kits/hub-game/code/server/writerLease.js +191 -0
  173. package/kits/hub-game/code/shared/act.js +1 -1
  174. package/kits/hub-game/code/shared/expression.js +6 -0
  175. package/kits/hub-game/code/shared/replay.js +37 -0
  176. package/kits/hub-game/code/systems/hub.js +429 -55
  177. package/kits/hub-game/docs/analytics.md +16 -2
  178. package/kits/hub-game/docs/contract.md +956 -101
  179. package/kits/hub-game/docs/home-pieces.md +5 -6
  180. package/kits/hub-game/docs/observed-progress.md +49 -1
  181. package/kits/hub-game/docs/vehicle-preset.md +23 -0
  182. package/kits/hub-game/index.html +1 -0
  183. package/kits/hub-game/models/hats/baker-cap.pxmodel +3 -3
  184. package/kits/hub-game/models/hats/bat-clip.pxmodel +3 -3
  185. package/kits/hub-game/models/hats/beekeeper.pxmodel +3 -3
  186. package/kits/hub-game/models/hats/cap.pxmodel +3 -3
  187. package/kits/hub-game/models/hats/captain.pxmodel +3 -3
  188. package/kits/hub-game/models/hats/chef-toque.pxmodel +3 -3
  189. package/kits/hub-game/models/hats/crooked-top.pxmodel +3 -3
  190. package/kits/hub-game/models/hats/delivery-cap.pxmodel +3 -3
  191. package/kits/hub-game/models/hats/fire-helmet.pxmodel +3 -3
  192. package/kits/hub-game/models/hats/flower-crown.pxmodel +3 -3
  193. package/kits/hub-game/models/hats/foam-crown.pxmodel +3 -3
  194. package/kits/hub-game/models/hats/hard-hat.pxmodel +3 -3
  195. package/kits/hub-game/models/hats/lantern.pxmodel +3 -3
  196. package/kits/hub-game/models/hats/laurel.pxmodel +3 -3
  197. package/kits/hub-game/models/hats/lighthouse.pxmodel +3 -3
  198. package/kits/hub-game/models/hats/nurse-cap.pxmodel +3 -3
  199. package/kits/hub-game/models/hats/police-cap.pxmodel +3 -3
  200. package/kits/hub-game/models/hats/sailor.pxmodel +3 -3
  201. package/kits/hub-game/models/hats/souwester.pxmodel +3 -3
  202. package/kits/hub-game/models/hats/straw.pxmodel +3 -3
  203. package/kits/hub-game/models/hats/sunflower.pxmodel +3 -3
  204. package/kits/hub-game/models/hats/sweatband.pxmodel +3 -3
  205. package/kits/hub-game/models/hats/teacher-beret.pxmodel +3 -3
  206. package/kits/hub-game/models/hats/witch.pxmodel +3 -3
  207. package/kits/hub-game/models/hold-show/daisy.pxmodel +231 -0
  208. package/kits/hub-game/models/hold-show/moonflower.pxmodel +171 -0
  209. package/kits/hub-game/models/hold-show/rose.pxmodel +191 -0
  210. package/kits/hub-game/models/hold-show/square/daisy.pxmodel +233 -0
  211. package/kits/hub-game/models/hold-show/square/moonflower.pxmodel +173 -0
  212. package/kits/hub-game/models/hold-show/square/rose.pxmodel +193 -0
  213. package/kits/hub-game/models/hold-show/square/sunflower.pxmodel +313 -0
  214. package/kits/hub-game/models/hold-show/square/tulip.pxmodel +133 -0
  215. package/kits/hub-game/models/hold-show/sunflower.pxmodel +311 -0
  216. package/kits/hub-game/models/hold-show/tulip.pxmodel +131 -0
  217. package/kits/hub-game/package-lock.json +3 -3
  218. package/kits/hub-game/package.json +4 -3
  219. package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +1 -0
  220. package/kits/hub-game/scripts/fixtures/hud-surface.json +12 -12
  221. package/kits/hub-game/scripts/fixtures/talk-surface.json +8 -8
  222. package/kits/hub-game/scripts/gen-hats.mjs +1 -1
  223. package/kits/hub-game/scripts/gen-hold-show.mjs +27 -0
  224. package/kits/hub-game/scripts/pack.mjs +89 -23
  225. package/kits/hub-game/scripts/test-act-client.mjs +5 -0
  226. package/kits/hub-game/scripts/test-act-core.mjs +32 -0
  227. package/kits/hub-game/scripts/test-act-gate.mjs +186 -0
  228. package/kits/hub-game/scripts/test-action-rail-crowded-dom.mjs +7 -1
  229. package/kits/hub-game/scripts/test-action-rail-default-dom.mjs +102 -0
  230. package/kits/hub-game/scripts/test-action-rail-never-silent-dom.mjs +50 -0
  231. package/kits/hub-game/scripts/test-action-rail-surface.mjs +368 -0
  232. package/kits/hub-game/scripts/test-action-rail-town-jobs-dom.mjs +118 -0
  233. package/kits/hub-game/scripts/test-actions-client.mjs +5 -3
  234. package/kits/hub-game/scripts/test-actions.mjs +24 -0
  235. package/kits/hub-game/scripts/test-actors.mjs +19 -0
  236. package/kits/hub-game/scripts/test-again-corner-dom.mjs +59 -0
  237. package/kits/hub-game/scripts/test-analytics.mjs +79 -0
  238. package/kits/hub-game/scripts/test-arrival-pose-server.mjs +25 -8
  239. package/kits/hub-game/scripts/test-ask-client.mjs +9 -0
  240. package/kits/hub-game/scripts/test-ask-surface.mjs +188 -0
  241. package/kits/hub-game/scripts/test-attention.mjs +43 -1
  242. package/kits/hub-game/scripts/test-ballot-sheet-dom.mjs +71 -0
  243. package/kits/hub-game/scripts/test-ballot-surface.mjs +276 -0
  244. package/kits/hub-game/scripts/test-ballot.mjs +421 -4
  245. package/kits/hub-game/scripts/test-ban-join.mjs +1 -1
  246. package/kits/hub-game/scripts/test-celebrate-client.mjs +62 -0
  247. package/kits/hub-game/scripts/test-celebrate.mjs +116 -0
  248. package/kits/hub-game/scripts/test-chat.mjs +73 -0
  249. package/kits/hub-game/scripts/test-companion-client.mjs +203 -21
  250. package/kits/hub-game/scripts/test-companion.mjs +110 -3
  251. package/kits/hub-game/scripts/test-control-layout-dom.mjs +57 -10
  252. package/kits/hub-game/scripts/test-corner-surface.mjs +268 -0
  253. package/kits/hub-game/scripts/test-decor-client.mjs +59 -3
  254. package/kits/hub-game/scripts/test-decor.mjs +27 -0
  255. package/kits/hub-game/scripts/test-device-class.mjs +4 -1
  256. package/kits/hub-game/scripts/test-disguise-client.mjs +281 -0
  257. package/kits/hub-game/scripts/test-disguise.mjs +176 -0
  258. package/kits/hub-game/scripts/test-dock-surface.mjs +404 -0
  259. package/kits/hub-game/scripts/test-door-stay-client.mjs +602 -0
  260. package/kits/hub-game/scripts/test-door-stay.mjs +613 -0
  261. package/kits/hub-game/scripts/test-earned-client.mjs +119 -0
  262. package/kits/hub-game/scripts/test-emote-surface.mjs +616 -0
  263. package/kits/hub-game/scripts/test-fps-telemetry.mjs +39 -4
  264. package/kits/hub-game/scripts/test-friend-bests.mjs +38 -12
  265. package/kits/hub-game/scripts/test-ghost-click-dom.mjs +75 -0
  266. package/kits/hub-game/scripts/test-grab-client.mjs +29 -2
  267. package/kits/hub-game/scripts/test-grab-orbit.mjs +260 -11
  268. package/kits/hub-game/scripts/test-grab.mjs +10 -1
  269. package/kits/hub-game/scripts/test-hats.mjs +28 -0
  270. package/kits/hub-game/scripts/test-held-offers.mjs +394 -0
  271. package/kits/hub-game/scripts/test-high-only.mjs +3 -3
  272. package/kits/hub-game/scripts/test-hold-show-client.mjs +175 -0
  273. package/kits/hub-game/scripts/test-hold-show.mjs +355 -0
  274. package/kits/hub-game/scripts/test-hub-controls.mjs +3 -1
  275. package/kits/hub-game/scripts/test-hub-idle.mjs +348 -0
  276. package/kits/hub-game/scripts/test-hub-leaving.mjs +21 -0
  277. package/kits/hub-game/scripts/test-hub-ops.mjs +119 -0
  278. package/kits/hub-game/scripts/test-hub-trip.mjs +240 -4
  279. package/kits/hub-game/scripts/test-hud-clear.mjs +83 -0
  280. package/kits/hub-game/scripts/test-hud-rate.mjs +2 -1
  281. package/kits/hub-game/scripts/test-idle.mjs +160 -0
  282. package/kits/hub-game/scripts/test-invites-client.mjs +53 -0
  283. package/kits/hub-game/scripts/test-labels.mjs +11 -0
  284. package/kits/hub-game/scripts/test-landscape-layout.mjs +20 -0
  285. package/kits/hub-game/scripts/test-loading-cover.mjs +67 -1
  286. package/kits/hub-game/scripts/test-manifest.mjs +27 -0
  287. package/kits/hub-game/scripts/test-menu-client.mjs +54 -5
  288. package/kits/hub-game/scripts/test-menu-surface.mjs +236 -0
  289. package/kits/hub-game/scripts/test-npcs.mjs +128 -0
  290. package/kits/hub-game/scripts/test-observed.mjs +171 -3
  291. package/kits/hub-game/scripts/test-pack.mjs +166 -0
  292. package/kits/hub-game/scripts/test-pad-cues.mjs +39 -0
  293. package/kits/hub-game/scripts/test-picker-surface.mjs +321 -0
  294. package/kits/hub-game/scripts/test-placeat-server.mjs +648 -0
  295. package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
  296. package/kits/hub-game/scripts/test-pointer-clear-dom.mjs +82 -0
  297. package/kits/hub-game/scripts/test-progress-reset.mjs +184 -6
  298. package/kits/hub-game/scripts/test-push-visit.mjs +9 -0
  299. package/kits/hub-game/scripts/test-quality.mjs +312 -9
  300. package/kits/hub-game/scripts/test-quick-chat-surface.mjs +511 -0
  301. package/kits/hub-game/scripts/test-rehello.mjs +242 -3
  302. package/kits/hub-game/scripts/test-rejoin-yaw.mjs +138 -0
  303. package/kits/hub-game/scripts/test-relations-among.mjs +13 -7
  304. package/kits/hub-game/scripts/test-relations-refresh.mjs +90 -2
  305. package/kits/hub-game/scripts/test-replay-client.mjs +110 -0
  306. package/kits/hub-game/scripts/test-replay.mjs +178 -0
  307. package/kits/hub-game/scripts/test-resume-held.mjs +13 -0
  308. package/kits/hub-game/scripts/test-resume-pose-server.mjs +43 -5
  309. package/kits/hub-game/scripts/test-role-client.mjs +2 -1
  310. package/kits/hub-game/scripts/test-safe-act.mjs +233 -0
  311. package/kits/hub-game/scripts/test-safe-caption.mjs +364 -0
  312. package/kits/hub-game/scripts/test-safe-layout.mjs +79 -0
  313. package/kits/hub-game/scripts/test-safe-prompt.mjs +163 -0
  314. package/kits/hub-game/scripts/test-sound-surface.mjs +256 -0
  315. package/kits/hub-game/scripts/test-soundscape.mjs +85 -2
  316. package/kits/hub-game/scripts/test-standing.mjs +135 -2
  317. package/kits/hub-game/scripts/test-stuck-surface.mjs +174 -0
  318. package/kits/hub-game/scripts/test-stuck.mjs +36 -1
  319. package/kits/hub-game/scripts/test-talk-surface.mjs +23 -6
  320. package/kits/hub-game/scripts/test-talk-walk-dom.mjs +123 -0
  321. package/kits/hub-game/scripts/test-text-ask-surface.mjs +273 -0
  322. package/kits/hub-game/scripts/test-tiers.mjs +453 -3
  323. package/kits/hub-game/scripts/test-toast-no-row-dom.mjs +71 -0
  324. package/kits/hub-game/scripts/test-together.mjs +11 -0
  325. package/kits/hub-game/scripts/test-town-day.mjs +90 -0
  326. package/kits/hub-game/scripts/test-try-on.mjs +39 -0
  327. package/kits/hub-game/scripts/test-ui-dom-dom.mjs +49 -2
  328. package/kits/hub-game/scripts/test-ui-tree.mjs +28 -0
  329. package/kits/hub-game/scripts/test-vehicle-client.mjs +68 -1
  330. package/kits/hub-game/scripts/test-vis.mjs +145 -0
  331. package/kits/hub-game/scripts/test-wallet.mjs +650 -0
  332. package/kits/hub-game/scripts/test-weakest-tier.mjs +135 -1
  333. package/kits/hub-game/scripts/test-world-labels.mjs +340 -0
  334. package/kits/hub-game/scripts/test-writer-lease-server.mjs +234 -0
  335. package/kits/hub-game/scripts/test-writer-lease.mjs +281 -0
  336. package/kits/hub-game/scripts/writer-storage-fixture.mjs +37 -0
  337. package/kits/hub-game/tools/hubScene/export.mjs +6 -5
  338. package/kits/hub-game/tools/hubScene/hubdata.mjs +10 -0
  339. package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +36 -2
  340. package/kits/hub-game/tools/hubScene/validate-manifest.mjs +10 -2
  341. package/kits/multiplayer-3d/castle.json +5 -5
  342. package/kits/multiplayer-3d/code/client/resumeGate.js +66 -2
  343. package/kits/multiplayer-3d/code/server/ownership.js +25 -6
  344. package/kits/multiplayer-3d/code/server/world.js +19 -4
  345. package/kits/multiplayer-3d/code/systems/multiplayer.js +108 -18
  346. package/kits/multiplayer-3d/package-lock.json +1 -1
  347. package/kits/multiplayer-3d/package.json +2 -1
  348. package/kits/multiplayer-3d/scripts/test-ground-half.mjs +56 -0
  349. package/kits/multiplayer-3d/scripts/test-join-watchdog.mjs +54 -3
  350. package/kits/multiplayer-3d/scripts/test-owned-moves.mjs +190 -0
  351. package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +417 -5
  352. package/kits/multiplayer-3d/scripts/test-resync-reconnect.mjs +68 -0
  353. package/kits/physics-2d/castle.json +2 -2
  354. package/kits/physics-2d/engine/scene.js +10 -2
  355. package/kits/physics-3d/CLAUDE.md +14 -0
  356. package/kits/physics-3d/behaviors/Player.jsx +39 -3
  357. package/kits/physics-3d/castle.json +3 -3
  358. package/kits/physics-3d/docs/engine-model-cache.md +109 -0
  359. package/kits/physics-3d/docs/engine-player.md +76 -0
  360. package/kits/physics-3d/docs/engine-skip-work.md +16 -0
  361. package/kits/physics-3d/docs/pxmodel-format.md +5 -1
  362. package/kits/physics-3d/engine3d/gait.js +16 -8
  363. package/kits/physics-3d/engine3d/groundsize.js +23 -0
  364. package/kits/physics-3d/engine3d/kithooks.js +50 -0
  365. package/kits/physics-3d/engine3d/look.js +110 -17
  366. package/kits/physics-3d/engine3d/lookbake.js +19 -1
  367. package/kits/physics-3d/engine3d/materialpresets.js +3 -2
  368. package/kits/physics-3d/engine3d/modelcache.js +280 -0
  369. package/kits/physics-3d/engine3d/modelcachedigest.js +37 -0
  370. package/kits/physics-3d/engine3d/modelcachegate.js +69 -0
  371. package/kits/physics-3d/engine3d/modelrefs.js +13 -0
  372. package/kits/physics-3d/engine3d/optimize.js +20 -9
  373. package/kits/physics-3d/engine3d/playerRun.js +26 -1
  374. package/kits/physics-3d/engine3d/pxmodel.js +7 -3
  375. package/kits/physics-3d/engine3d/templatecache.js +722 -0
  376. package/kits/physics-3d/engine3d/world3d.js +211 -17
  377. package/kits/physics-3d/package-lock.json +1 -1
  378. package/kits/physics-3d/package.json +2 -1
  379. package/kits/physics-3d/play/behaviors/Player.js +43 -3
  380. package/kits/physics-3d/scripts/render.mjs +56 -8
  381. package/kits/physics-3d/scripts/template-cache-fixtures.mjs +37 -0
  382. package/kits/physics-3d/scripts/template-cache-v1-bytes.json +49 -0
  383. package/kits/physics-3d/scripts/test-coaxial-escape.mjs +176 -0
  384. package/kits/physics-3d/scripts/test-gait.mjs +53 -9
  385. package/kits/physics-3d/scripts/test-ground-half.mjs +120 -0
  386. package/kits/physics-3d/scripts/test-model-cache.mjs +600 -0
  387. package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1 -0
  388. package/kits/physics-3d/scripts/test-sleeping-models.mjs +384 -0
  389. package/kits/physics-3d/scripts/test-template-cache-minified.mjs +106 -0
  390. package/kits/physics-3d/scripts/test-template-cache.mjs +519 -0
  391. package/kits/physics-3d/scripts/test-wall-slide.mjs +272 -0
  392. package/kits/physics-3d/systems/physics3d.js +59 -2
  393. package/kits/real-time/castle.json +2 -2
  394. package/kits/real-time/code/client/connection.js +3 -0
  395. package/package.json +2 -2
  396. package/vendor/three/examples/jsm/libs/fflate.module.js +2672 -0
@@ -1,3 +1,4 @@
1
+ import { disguiseBody } from './disguise.js';
1
2
  import { ensureActorModel } from './modelReady.js';
2
3
  // Idle play (contract §6, v1.6), the client's half: the emote picker and Sit /
3
4
  // Stand in the hub chrome, and drawing what the place says -- each player's
@@ -16,7 +17,7 @@ import { hub, simNow } from './state.js';
16
17
  import { allActors } from './quality.js';
17
18
  import { vehicleOf } from '../shared/car.js';
18
19
  import { danceIdlePose } from '../shared/danceIdle.js';
19
- import { EXPRESSION_EMOTES } from '../shared/expression.js';
20
+ import { EXPRESSION_EMOTES, PLACE_EMOTES } from '../shared/expression.js';
20
21
 
21
22
  // The kit's emotes, in the picker's order, with the emoji drawn over the head.
22
23
  // The server holds the same ids and durations (`EMOTES` in server/idle.js).
@@ -30,8 +31,12 @@ export const EMOTES = [
30
31
  const EMOJI = Object.fromEntries(EMOTES);
31
32
  export function emoteDefinition(id) {
32
33
  if (Object.hasOwn(EMOJI, id)) { return { emoji: EMOJI[id], motion: id }; }
33
- if (!hub.place?.idle?.expression) { return null; }
34
- return (Object.hasOwn(EXPRESSION_EMOTES, id) ? { ...EXPRESSION_EMOTES[id], motion: id } : hub.place.idle.expression.roleEmotes.find((role) => role.id === id)) ?? null;
34
+ const expression = hub.place?.idle?.expression
35
+ ? (Object.hasOwn(EXPRESSION_EMOTES, id) ? { ...EXPRESSION_EMOTES[id], motion: id } : hub.place.idle.expression.roleEmotes.find((role) => role.id === id))
36
+ : null;
37
+ // v1.174: a place-only kit emote, drawn wherever it is played; a declared
38
+ // role of the same id keeps its own definition.
39
+ return expression ?? (Object.hasOwn(PLACE_EMOTES, id) ? { ...PLACE_EMOTES[id], motion: id } : null);
35
40
  }
36
41
 
37
42
  export function expressionChoices(expression, grants) {
@@ -100,6 +105,18 @@ export function emotePose(id, u, s) {
100
105
  return { y: Math.abs(Math.sin(s * TAU * 2.4)) * 0.12 * e, rx: (-0.2 + Math.sin(s * TAU * 2.4) * 0.1) * e, ry: 0, rz: 0 };
101
106
  case 'point':
102
107
  return { y: 0, rx: 0.24 * e, ry: 0.2 * e, rz: 0 };
108
+ case 'yawn': {
109
+ // v1.174: stretch up with the head back (the yawn), then sag and droop
110
+ // forward and to one side with a slow nod (dozing), then settle back.
111
+ const stretch = Math.sin(Math.PI * Math.min(1, u / 0.45));
112
+ const doze = Math.sin(Math.PI * Math.min(1, Math.max(0, (u - 0.35) / 0.65)));
113
+ return {
114
+ y: (0.07 * stretch - 0.1 * doze) * e,
115
+ rx: (-0.3 * stretch + (0.22 + Math.sin(s * TAU * 0.5) * 0.05) * doze) * e,
116
+ ry: 0,
117
+ rz: 0.14 * doze * e,
118
+ };
119
+ }
103
120
  case 'spin':
104
121
  return { y: Math.sin(Math.PI * u) * 0.2, rx: 0, ry: TAU * smooth(u), rz: 0 };
105
122
  default:
@@ -410,6 +427,7 @@ function labels(scene, local, cam, view, project) {
410
427
  const out = [];
411
428
  const now = simNow();
412
429
  for (const [id, actorId, e] of emoteActors(scene, local)) {
430
+ if (id.startsWith('emote:') && disguiseBody(scene.multiplayer?.net?.selfId?.(), id.slice(6))) {continue;}
413
431
  const span = e.until - e.at;
414
432
  const u = span > 0 ? (now - e.at) / span : 1;
415
433
  const emoji = emoteDefinition(e.id)?.emoji;
@@ -24,7 +24,7 @@ export function makeInvites(api, target, route, now = () => Date.now(), notify =
24
24
  let root = null, connection = null, done = null, pending = false, disposed = false;
25
25
  let epoch = 0, attempts = 0, retryAt = 0;
26
26
  let carriedInvite = false;
27
- let identity = null;
27
+ let identity = null, availability = null;
28
28
  let destination = null, landed = false, routing = false, routeDoor = null, pointerUntil = 0, pointerSince = null;
29
29
  function close() { root?.remove(); root = null; onLayout?.(null); }
30
30
  function askHost(read) {
@@ -158,6 +158,27 @@ export function makeInvites(api, target, route, now = () => Date.now(), notify =
158
158
  const own = identity.hostUser === null ? identity.user : identity.hostUser === String(userId);
159
159
  return own && identity.host;
160
160
  },
161
+ // v1.188 Character-only read: one attempt per scene, socket and identity.
162
+ // Other invite entry points keep the canInvite/share behavior above.
163
+ inviteAvailable(scene, net, active = () => true) {
164
+ if (scene.data?.engine?.hubInviteRail !== true) {return false;}
165
+ const playerId = net?.selfId?.(), userId = net?.userId?.(playerId), data = scene.data;
166
+ const current = () => !disposed && active() && scene.data === data && scene.multiplayer?.net === net &&
167
+ !net?.closed?.() && net?.selfId?.() === playerId && net?.userId?.(playerId) === userId;
168
+ if (!current() || !/^[1-9]\d{0,9}$/.test(String(userId ?? ''))) {availability = null; return false;}
169
+ if (availability?.scene !== scene || availability.data !== data || availability.net !== net ||
170
+ availability.playerId !== playerId || availability.userId !== userId) {
171
+ const read = availability = { scene, data, net, playerId, userId, available: false };
172
+ Promise.resolve().then(() => {
173
+ if (availability !== read || !current() || scene.data.engine.hubInviteRail !== true) {return;}
174
+ return api.inviteAvailable?.();
175
+ }).then((answer) => {
176
+ if (availability !== read || !current() || scene.data.engine.hubInviteRail !== true) {return;}
177
+ read.available = answer?.status === 'ok' && answer.available === true;
178
+ }).catch(() => {});
179
+ }
180
+ return availability.available;
181
+ },
161
182
  open() { void createShare(); },
162
183
  frame(net, beforeHello = false) {
163
184
  if (disposed || !net?.selfId?.()) {return;}
@@ -234,7 +255,7 @@ export function makeInvites(api, target, route, now = () => Date.now(), notify =
234
255
  }
235
256
  return null;
236
257
  },
237
- reset() { identity = null; epoch++; connection = null; done = null; pending = false; attempts = 0; retryAt = 0; destination = null; routing = false; carriedInvite = false; close(); },
238
- dispose() { identity = null; epoch++; disposed = true; unwatchViewport(); close(); },
258
+ reset() { identity = null; availability = null; epoch++; connection = null; done = null; pending = false; attempts = 0; retryAt = 0; destination = null; routing = false; carriedInvite = false; close(); },
259
+ dispose() { identity = null; availability = null; epoch++; disposed = true; unwatchViewport(); close(); },
239
260
  };
240
261
  }
@@ -36,6 +36,21 @@ export function swallowsScroll(event) {
36
36
  );
37
37
  }
38
38
 
39
+ // The keys an untouched talk field lets through to the game (`chrome.js`): the
40
+ // ones that walk and jump, pressed alone. Shift with a letter is a capital, and
41
+ // the field's.
42
+ const WALK_KEYS = new Set(['KeyW', 'KeyA', 'KeyS', 'KeyD', 'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'Space']);
43
+
44
+ export function walkKey(event) {
45
+ return WALK_KEYS.has(event.code) && !event.isComposing && event.keyCode !== 229 &&
46
+ !(event.altKey || event.ctrlKey || event.metaKey || event.shiftKey);
47
+ }
48
+
49
+ // A walk key's release always goes on: it may have been pressed before the
50
+ // field took focus, and a release the game never sees leaves the avatar
51
+ // walking. A release only ever lets go.
52
+ export const walkRelease = (event) => event.type === 'keyup' && WALK_KEYS.has(event.code);
53
+
39
54
  // Installs the guard on `win`; returns its removal.
40
55
  export function guardScrollKeys(win = globalThis) {
41
56
  const onKey = (event) => {
@@ -228,7 +228,14 @@ export function chromeItem(id, text, speech, npc, box, opacity) {
228
228
  }
229
229
 
230
230
  // A private goal can project a server-supplied point without moving any actor.
231
- export function goalAt(label, actorAt) {
231
+ // v1.201: `at: "self"` projects this player's own avatar (`selfAt`, its
232
+ // predicted Transform), `rise` metres up; with no avatar it is not drawn.
233
+ export function goalAt(label, actorAt, selfAt) {
234
+ if (label.style === 'goal' && label.at === 'self') {
235
+ const rise = Number.isFinite(label.rise) ? Math.min(Math.max(label.rise, 0), 4) : 0;
236
+ return selfAt && ['x', 'y', 'z'].every((key) => Number.isFinite(selfAt[key]))
237
+ ? { x: selfAt.x, y: selfAt.y + rise, z: selfAt.z } : null;
238
+ }
232
239
  return label.style === 'goal' && label.at && ['x', 'y', 'z'].every((key) => Number.isFinite(label.at[key]))
233
240
  ? label.at : actorAt;
234
241
  }
@@ -105,11 +105,21 @@ function layoutChanged(node, previous) {
105
105
  // observer saw: inherited changes above a source and late font metrics.
106
106
  const REFRESH_FRAMES = 30;
107
107
 
108
+ // Everything inline a node's own layout can come from, for a stand-in sample
109
+ // that must end the moment anything touches the node.
110
+ export const surfacePrint = (node) => {
111
+ const style = node.style ?? {};
112
+ return [node.textContent, node.className, 'cssText' in style ? style.cssText : JSON.stringify(style)].join('\u0001');
113
+ };
114
+
108
115
  export function makeLayoutCache() {
109
116
  const sources = new Map(), snapshot = new Map(), dirty = new Set(), descendants = new Set(), structural = new Set();
110
117
  // Sources mutated since their stored layoutState; only a fresh sample clears it.
111
118
  const unsampled = new Set();
112
- let active = false, viewport, frame = 0, reconnect = false;
119
+ // Stand-in samples, until the node changes or the frame ends. One with a
120
+ // release callback stands for a DOM state its owner must restore first.
121
+ const held = new Map();
122
+ let active = false, viewport, frame = 0, reconnect = false, fontEpoch = 0;
113
123
  function changedChildren(node) {
114
124
  for (const child of node.children ?? []) {
115
125
  if (sources.has(child)) {descendants.add(child);}
@@ -145,7 +155,7 @@ export function makeLayoutCache() {
145
155
  reconnect = false;
146
156
  }
147
157
  const fonts = globalThis.document?.fonts;
148
- const fontsLoaded = () => snapshot.clear();
158
+ const fontsLoaded = () => {snapshot.clear(); fontEpoch += 1;};
149
159
  fonts?.addEventListener?.('loadingdone', fontsLoaded);
150
160
  const view = () => active ? viewport : { w: globalThis.window?.innerWidth, h: globalThis.window?.innerHeight };
151
161
  function register(node, options = {}) {
@@ -158,7 +168,7 @@ export function makeLayoutCache() {
158
168
  }
159
169
  function forget(node) {
160
170
  if (sources.delete(node)) {reconnect = true;}
161
- snapshot.delete(node); dirty.delete(node); descendants.delete(node); structural.delete(node); unsampled.delete(node);
171
+ snapshot.delete(node); dirty.delete(node); descendants.delete(node); structural.delete(node); unsampled.delete(node); held.delete(node);
162
172
  for (const child of node.children ?? []) {forget(child);}
163
173
  }
164
174
  // Release observer membership as soon as a surface leaves, once per call.
@@ -169,13 +179,13 @@ export function makeLayoutCache() {
169
179
  }
170
180
  // An observed source with no mutation since its last layout sample keeps
171
181
  // that sample's copy and inline styles; only geometry is read again.
172
- function measure(node, previous) {
182
+ function measure(node, previous, aside = false) {
173
183
  const shown = displayed(node);
174
184
  const box = shown ? node.getBoundingClientRect() : { left: 0, right: 0, top: 0, bottom: 0, width: 0, height: 0 };
175
185
  const options = sources.get(node);
176
186
  const style = node.style ?? {};
177
187
  const reuse = shown && observer && previous?.layout && !unsampled.has(node);
178
- if (shown && !reuse) {unsampled.delete(node);}
188
+ if (shown && !reuse && !aside) {unsampled.delete(node);}
179
189
  const measured = {
180
190
  rect: { left: box.left, right: box.right, top: box.top, bottom: box.bottom, width: box.width, height: box.height },
181
191
  size: { w: shown ? node.offsetWidth : 0, h: shown ? node.offsetHeight : 0 },
@@ -192,6 +202,25 @@ export function makeLayoutCache() {
192
202
  }
193
203
  return measured;
194
204
  }
205
+ function letGo(node) {
206
+ const entry = held.get(node);
207
+ held.delete(node);
208
+ if (entry?.release) {snapshot.delete(node); entry.release();}
209
+ }
210
+ function holding(node) {
211
+ const entry = held.get(node);
212
+ if (!entry) {return false;}
213
+ if (snapshot.has(node) && displayed(node) && surfacePrint(node) === entry.print) {
214
+ // `check` runs once, at the first read, where a restore's fresh sample
215
+ // would have been taken.
216
+ const check = entry.check;
217
+ entry.check = null;
218
+ if (!check || check()) {return true;}
219
+ }
220
+ letGo(node);
221
+ return false;
222
+ }
223
+ const letAllGo = () => {for (const node of [...held.keys()]) {letGo(node);}};
195
224
  function used(node) {
196
225
  if (!sources.has(node)) {register(node);}
197
226
  sources.get(node).readFrame = frame;
@@ -199,6 +228,7 @@ export function makeLayoutCache() {
199
228
  }
200
229
  function read(node) {
201
230
  used(node); changes();
231
+ if (holding(node)) {dirty.delete(node); structural.delete(node); return snapshot.get(node);}
202
232
  const options = sources.get(node);
203
233
  let measured = snapshot.get(node);
204
234
  const shown = displayed(node);
@@ -213,8 +243,27 @@ export function makeLayoutCache() {
213
243
  return measured;
214
244
  }
215
245
  return {
216
- register, unregister, invalidate: (node) => snapshot.delete(node), view, active: () => active,
246
+ register, unregister, invalidate: (node) => {snapshot.delete(node); held.delete(node);}, view, active: () => active,
247
+ // Serve `measured` for an unpositioned node until the node changes or
248
+ // `check` fails; `release` (when given) runs before it is measured again.
249
+ hold(node, measured, release, check) {
250
+ if (!active || !measured || sources.get(used(node))?.positioned) {return false;}
251
+ snapshot.set(node, { ...measured, frame, layout: layoutState(node) });
252
+ held.set(node, { release, check, print: surfacePrint(node) });
253
+ return true;
254
+ },
255
+ // A sample of the node as it is now, leaving the snapshot as it was.
256
+ fresh: (node) => active ? measure(used(node), undefined, true) : undefined,
257
+ fontEpoch: () => fontEpoch,
258
+ held: (node) => holding(node),
259
+ // This frame's sample when nothing inline has changed since it was taken.
260
+ sample(node) {
261
+ const measured = snapshot.get(node), now = active && measured?.frame === frame && measured.layout ? layoutState(node) : null;
262
+ return now && ['text', 'className', 'css', 'left', 'right'].every((key) => now[key] === measured.layout[key])
263
+ && JSON.stringify(now.styles) === JSON.stringify(measured.layout.styles) ? measured : undefined;
264
+ },
217
265
  beginFrame(nodes = []) {
266
+ letAllGo();
218
267
  for (const node of nodes) {register(node);}
219
268
  changes();
220
269
  const next = { w: globalThis.window?.innerWidth, h: globalThis.window?.innerHeight };
@@ -235,7 +284,7 @@ export function makeLayoutCache() {
235
284
  }
236
285
  dirty.clear(); descendants.clear(); structural.clear();
237
286
  },
238
- endFrame() {active = false;},
287
+ endFrame() {letAllGo(); active = false;},
239
288
  rect(node) {
240
289
  if (!active) {return used(node).getBoundingClientRect();}
241
290
  const measured = read(node);
@@ -259,6 +308,6 @@ export function makeLayoutCache() {
259
308
  const style = globalThis.getComputedStyle?.(node) ?? node.style;
260
309
  return Object.fromEntries(['Left', 'Right', 'Top', 'Bottom'].map((edge) => [edge.toLowerCase(), Number.parseFloat(style[`padding${edge}`]) || 0]));
261
310
  })(),
262
- dispose() {active = false; observer?.disconnect(); fonts?.removeEventListener?.('loadingdone', fontsLoaded); structural.clear(); unsampled.clear(); sources.clear(); snapshot.clear(); dirty.clear(); descendants.clear(); viewport = null;},
311
+ dispose() {active = false; observer?.disconnect(); fonts?.removeEventListener?.('loadingdone', fontsLoaded); structural.clear(); unsampled.clear(); held.clear(); sources.clear(); snapshot.clear(); dirty.clear(); descendants.clear(); viewport = null;},
263
312
  };
264
313
  }
@@ -1,5 +1,13 @@
1
1
  // v1.126: page-owned chrome, released only by a completed world draw.
2
2
  export let loadingCover = null;
3
+ // A fresh player id's arrival (a progress read, then the restored pose) may
4
+ // follow its placement by the server's 5 s progress wait; past this the cover
5
+ // lifts without it, so a place that never sends one is not kept covered.
6
+ export const ARRIVAL_WAIT_MS = 6000;
7
+ // A return's cover (any cover raised after the first load lifted) shows no
8
+ // words and no spinner while hidden and for this long after the page shows
9
+ // again, then says it is reconnecting: most returns are back sooner.
10
+ export const QUIET_RETURN_MS = 2500;
3
11
  export function startLoadingCover(options) {
4
12
  loadingCover?.dispose();
5
13
  loadingCover = makeLoadingCover(options);
@@ -20,6 +28,7 @@ export function makeLoadingCover({ enabled, title, document: doc = globalThis.do
20
28
  [data-hub-loading-cover] i { width: 36px; height: 36px; box-sizing: border-box;
21
29
  border: 3px solid #ffffff40; border-top-color: #fff; border-radius: 50%;
22
30
  animation: hub-loading-spin .8s linear infinite; }
31
+ [data-hub-loading-cover] i[hidden] { display: none; }
23
32
  @keyframes hub-loading-spin { to { transform: rotate(360deg); } }
24
33
  `;
25
34
  doc.head.append(css);
@@ -30,9 +39,17 @@ export function makeLoadingCover({ enabled, title, document: doc = globalThis.do
30
39
  cover.setAttribute('aria-label', `Loading ${title || 'deck'}`);
31
40
  const text = doc.createElement('span');
32
41
  text.textContent = title || 'Loading…';
33
- cover.append(text, doc.createElement('i'));
42
+ const spinner = doc.createElement('i');
43
+ cover.append(text, spinner);
34
44
  let covered = false, failed = false, binding = null, sceneNow = null;
45
+ // Whether the first load's cover has lifted, and since when a return's
46
+ // cover has been quiet (`QUIET_RETURN_MS`).
47
+ let lifted = false, returnAt = null;
35
48
  let hiddenAt = null;
49
+ // Whether the caller still waits for this session's arrival (`sync`), held
50
+ // one frame past it while its clamp reaches the body, and since when a
51
+ // settled draw has waited on it.
52
+ let arriving = false, wasArriving = false, arrivalSince = null;
36
53
  const now = () => doc.defaultView?.performance?.now?.() ?? performance.now();
37
54
  const connected = () => sceneNow?.multiplayer?.net?.status?.()?.state === 'connected';
38
55
  // The default player catches update/sync errors before reaching the
@@ -43,7 +60,17 @@ export function makeLoadingCover({ enabled, title, document: doc = globalThis.do
43
60
  if (changes.some((change) => [...change.addedNodes].some((node) => node.nodeType === 1 &&
44
61
  (node.style?.zIndex === '2147483000' || node.querySelector?.('[style*="z-index: 2147483000"]'))))) { fail(); }
45
62
  }) : null;
63
+ // A return's cover: quiet at first, then 'Reconnecting…'.
64
+ function label() {
65
+ if (returnAt === null) { return; }
66
+ const quiet = doc.hidden || now() - returnAt < QUIET_RETURN_MS;
67
+ text.textContent = quiet ? '' : 'Reconnecting…';
68
+ if (quiet) { spinner.setAttribute('hidden', ''); } else { spinner.removeAttribute('hidden'); }
69
+ cover.setAttribute('aria-label', 'Reconnecting');
70
+ }
46
71
  function show() {
72
+ if (lifted) { returnAt ??= now(); }
73
+ label();
47
74
  covered = true;
48
75
  doc.documentElement.setAttribute('data-hub-loading', '');
49
76
  // Outside #root: either entry can replace its children during startup.
@@ -52,6 +79,9 @@ export function makeLoadingCover({ enabled, title, document: doc = globalThis.do
52
79
  }
53
80
  function hide() {
54
81
  covered = false;
82
+ lifted = true;
83
+ returnAt = null;
84
+ arrivalSince = null;
55
85
  cover.remove();
56
86
  doc.documentElement.removeAttribute('data-hub-loading');
57
87
  recovery?.disconnect();
@@ -62,7 +92,12 @@ export function makeLoadingCover({ enabled, title, document: doc = globalThis.do
62
92
  // A short connected app switch needs no extra black hub cover. The
63
93
  // engine's independent room-current gate still protects stale poses.
64
94
  if (!connected()) {show();}
95
+ // A return's cover already up goes quiet with the page.
96
+ label();
65
97
  } else {
98
+ // The quiet starts again from the page showing, words and all, before
99
+ // the next frame.
100
+ if (returnAt !== null) { returnAt = now(); label(); }
66
101
  if (hiddenAt !== null && (now() - hiddenAt >= 30_000 || !connected())) {show();}
67
102
  hiddenAt = null;
68
103
  }
@@ -86,11 +121,18 @@ export function makeLoadingCover({ enabled, title, document: doc = globalThis.do
86
121
  doc.defaultView?.addEventListener('error', fail);
87
122
  show();
88
123
  return {
89
- sync(scene) {
124
+ // `arriving`: a fresh player id the hub has not yet seen placed by its
125
+ // arrival. It never raises the cover; it only keeps a raised one up.
126
+ sync(scene, { arriving: pending = false } = {}) {
90
127
  sceneNow = scene;
128
+ arriving = pending === true || wasArriving;
129
+ wasArriving = pending === true;
130
+ if (!arriving) { arrivalSince = null; }
91
131
  if (failed) { failed = false; show(); }
92
132
  const mp = scene.multiplayer;
93
- if (!mp?.joined && mp?.coverText) {
133
+ if (returnAt !== null) {
134
+ label();
135
+ } else if (!mp?.joined && mp?.coverText) {
94
136
  text.textContent = mp.coverText();
95
137
  cover.setAttribute('aria-label', text.textContent);
96
138
  }
@@ -128,7 +170,14 @@ export function makeLoadingCover({ enabled, title, document: doc = globalThis.do
128
170
  const stopped = mp?.joinError || mp?.joinFailed || mp?.net?.status?.()?.state === 'closed';
129
171
  // Placement also keeps initial acquisition under the cover: otherwise
130
172
  // a pre-join draw would uncover, then the next joining frame re-cover.
131
- if (covered && drawn && !doc.hidden && (settled || stopped)) { hide(); }
173
+ // A fresh rejoin's spawn is not where the player stands: its restored
174
+ // pose and HUD come with the arrival, which waits ARRIVAL_WAIT_MS at most.
175
+ let held = false;
176
+ if (covered && drawn && !doc.hidden && settled && !stopped && arriving) {
177
+ arrivalSince ??= now();
178
+ held = now() - arrivalSince < ARRIVAL_WAIT_MS;
179
+ }
180
+ if (covered && drawn && !doc.hidden && (settled || stopped) && !held) { hide(); }
132
181
  return result;
133
182
  };
134
183
  composer.render = wrapper;
@@ -36,6 +36,21 @@ const PATHS = {
36
36
  'hard-hat': 'M4 15a8 8 0 0 1 16 0zM1 15h22v3H1zM11 7h2v4h-2z',
37
37
  'baker-cap': 'M4 10a8 5 0 0 1 16 0v4H4zM3 14h18v3H3z',
38
38
  };
39
+ // The same paths for a build script and a native icon registry: each a
40
+ // 24x24 single path, drawn `fill-rule="evenodd"` in the tile's tint.
41
+ export const MENU_ICON_PATHS = Object.freeze({ ...PATHS });
42
+ // Kit icons a UI tree names that are not menu silhouettes: their own view
43
+ // box and fills (not tinted). `companion` is the dock's companion badge,
44
+ // the SVG `chrome.js` draws.
45
+ export const KIT_ICONS = Object.freeze({
46
+ companion: Object.freeze({
47
+ viewBox: '0 0 28 28',
48
+ paths: Object.freeze([
49
+ Object.freeze({ d: 'M3 6l11 5L24 3l-5 13-7 6-2-8z', fill: '#fff6e6' }),
50
+ Object.freeze({ d: 'M14 11l5 5-7 6 2-11zM19 16l7 1-6 3z', fill: '#e8743b' }),
51
+ ]),
52
+ }),
53
+ });
39
54
  export function menuIcon(icon) {
40
55
  const path = PATHS[icon];
41
56
  return path ? `url("data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="black" fill-rule="evenodd" d="${path}"/></svg>`)}")` : null;
@@ -0,0 +1,102 @@
1
+ // The place menu surface: the menu sheet (`menuTree.js`) with the behaviour
2
+ // `chrome.js` `setMenu` gives it in the DOM -- one sheet per offer, a newer
3
+ // offer replacing it, an older one ignored, Close / Esc / Back telling the
4
+ // place `close` -- published as the `menu` UI tree root. No DOM and no
5
+ // window: a native host gives it the place's offers as the chrome is given
6
+ // them and draws the root from the UI tree sink. The web chrome does not use
7
+ // it yet.
8
+ //
9
+ // makeMenuSurface({ view, draw }):
10
+ // view() the stage: { landscape, w } in CSS px;
11
+ // draw(tree) called with each root built (only when it changed).
12
+ import { publishUiRoot } from './uiTree.js';
13
+ import { buildMenu, menuCovers } from './menuTree.js';
14
+
15
+ export function makeMenuSurface({ view = () => ({}), draw = null } = {}) {
16
+ // `n` the last offer taken; `spec` the open sheet's, or null.
17
+ let menu = null;
18
+ let key = '';
19
+ let disposed = false;
20
+
21
+ const on = {
22
+ pick: (id) => {
23
+ if (menu?.spec) {menu.handler(id, menu.n);}
24
+ },
25
+ close: () => cancel(),
26
+ };
27
+
28
+ function render() {
29
+ if (disposed) {return;}
30
+ const stage = view() ?? {};
31
+ const state = { view: { landscape: Boolean(stage.landscape), w: Number(stage.w) || 0 }, spec: menu?.spec ?? null };
32
+ const next = JSON.stringify(state);
33
+ if (next === key) {return;}
34
+ key = next;
35
+ const tree = buildMenu(state, on);
36
+ publishUiRoot('menu', tree);
37
+ draw?.(tree);
38
+ }
39
+
40
+ function close() {
41
+ if (!menu?.spec) {return false;}
42
+ const onOpen = menu.onOpen;
43
+ menu.spec = null;
44
+ menu.onOpen = null;
45
+ render();
46
+ onOpen?.(false);
47
+ return true;
48
+ }
49
+ // Close / Esc / Back: the sheet shuts and the place is told `close`.
50
+ function cancel() {
51
+ if (!menu?.spec) {return false;}
52
+ const { handler, n } = menu;
53
+ close();
54
+ handler('close', n);
55
+ return true;
56
+ }
57
+
58
+ render();
59
+ return {
60
+ // chrome `setMenu`: `offer` { n, spec } (null shuts the sheet without
61
+ // telling the place), `handler(id, n)` for a pick or `close`, and
62
+ // `onOpen(open)` as the sheet opens and shuts. An offer no newer than the
63
+ // last one taken is ignored.
64
+ set(offer, handler, onOpen) {
65
+ if (!offer) {
66
+ close();
67
+ return;
68
+ }
69
+ if (menu && offer.n <= menu.n) {return;}
70
+ close();
71
+ menu = { n: offer.n, spec: null, handler: handler ?? (() => {}), onOpen: null };
72
+ if (!offer.spec) {
73
+ render();
74
+ return;
75
+ }
76
+ menu.spec = offer.spec;
77
+ menu.onOpen = onOpen ?? null;
78
+ render();
79
+ onOpen?.(true);
80
+ },
81
+ // chrome `clearMenu`: shut and forget the last offer taken.
82
+ clear() {
83
+ close();
84
+ menu = null;
85
+ render();
86
+ },
87
+ // A turned or resized stage.
88
+ render,
89
+ cancel,
90
+ isOpen: () => Boolean(menu?.spec),
91
+ // A row sheet that reaches near the top: the host hides the HUD (any row
92
+ // sheet) and the controls under it (`covers`) while it is open.
93
+ rows: () => menu?.spec?.presentation === 'rows',
94
+ covers: () => menuCovers(menu?.spec),
95
+ dispose() {
96
+ if (disposed) {return;}
97
+ close();
98
+ disposed = true;
99
+ publishUiRoot('menu', null);
100
+ },
101
+ };
102
+ }
@@ -0,0 +1,135 @@
1
+ // The place menu (v1.79 `hub-menu` offers) as a UI tree (schema v0): the
2
+ // bottom sheet `chrome.js` `setMenu` draws -- the title and Close, a note,
3
+ // then tiles in sections (an icon or colour swatch over a label, a tick on
4
+ // the ones that are on) or, for `presentation: 'rows'`, text rows of one
5
+ // label or three columns (`menuRows.js`) with an optional footer of buttons.
6
+ // The same words, labels and states. Pure: no DOM, no window; the web chrome
7
+ // still draws its own DOM. Tile icons are `icon` nodes named by the
8
+ // `menuIcons.js` ids (`MENU_ICON_PATHS`), tinted as the DOM's mask is.
9
+ //
10
+ // state = {
11
+ // view: { landscape, w } (CSS px);
12
+ // spec: the offer's spec, or null (no sheet): { title, note?, readOnly?,
13
+ // presentation?: 'rows', face?, sections: [{ title, items }],
14
+ // footer?: [{ id, label }] }; a tile item { id, label, icon?,
15
+ // color?, on? }, a row item { id, label, columns?: [3 strings],
16
+ // readOnly? };
17
+ // }
18
+ // on = { pick(id), close() }: a tile, row or footer button pressed; Close or
19
+ // Back.
20
+ import { h } from './uiTree.js';
21
+
22
+ const TILE_LINE = 'rgba(255,255,255,.4)';
23
+ const TILE_BG = 'rgba(255,255,255,.1)';
24
+ const ROW_LINE = 'rgba(255,255,255,.25)';
25
+ // On a short view (an embedded 574x246 frame) 55% or 40% of the height left
26
+ // the list a sliver under the title and note: the sheet takes at least this
27
+ // much, short of the whole view, so a row of choices always shows.
28
+ export const SHORT_PX = 220, SHORT_FACE_PX = 150;
29
+
30
+ // Whether the sheet is a row sheet that reaches to near the top of the view
31
+ // (the controls under it are hidden while it is open).
32
+ export const menuCovers = (spec) => Boolean(spec) && spec.presentation === 'rows' && !Object.hasOwn(spec, 'face');
33
+
34
+ // The tile grid's columns: the DOM's auto-fill of 64 px tiles, four on a
35
+ // view up to 600 px wide, three up to 340.
36
+ export const tileCols = (w) => (w > 0 && w <= 340 ? 3 : w > 0 && w <= 600 ? 4 : { min: 64 });
37
+
38
+ function tile(item, readOnly, on) {
39
+ const color = item.color ?? '#fff';
40
+ return h('button', {
41
+ key: `t:${item.id}`, label: item.label, pressed: item.on === true, disabled: readOnly, press: 'scale',
42
+ data: { id: String(item.id) },
43
+ style: { box: 'border', minW: 64, minH: 64, aspect: 1, pad: 0, radius: 8, border: { w: item.on ? 2 : 1, c: item.on ? '#fff' : TILE_LINE }, bg: TILE_BG, clip: true },
44
+ on: { tap: () => {if (!readOnly) {on.pick?.(item.id);}} },
45
+ },
46
+ h('stack', { key: 'cell', style: { w: 'fill', h: 'fill' } },
47
+ h('column', { key: 'body', style: { w: 'fill', h: 'fill', box: 'border', minH: 62, pad: 6, align: 'center', justify: 'center', gap: 4, hit: 'none' } },
48
+ item.icon
49
+ ? h('icon', { key: 'swatch', name: String(item.icon), tint: color, style: { w: 28, h: 28, flex: '0 0 auto' } })
50
+ : h('spacer', { key: 'swatch', style: { w: 28, h: 28, radius: 6, bg: color, flex: '0 0 auto' } }),
51
+ h('text', { key: 'label', text: String(item.label ?? ''), style: { size: 12, lh: 1.15, lines: 2, ellipsis: false, talign: 'center', wrap: 'anywhere' } })),
52
+ item.on ? h('text', { key: 'tick', text: '✓', at: { anchor: 'topRight', top: 2, right: 4 }, style: { size: 12 } }) : null));
53
+ }
54
+
55
+ function textRow(item, specReadOnly, on) {
56
+ const readOnly = specReadOnly || item.readOnly === true;
57
+ const columns = Array.isArray(item.columns) ? item.columns : null;
58
+ const texts = (columns ?? [item.label]).map((text, index) => h('text', {
59
+ key: `c${index}`, text: String(text ?? ''),
60
+ style: columns
61
+ // A steady left column, the middle taking the rest and wrapping
62
+ // anywhere, the right one its own width, right aligned.
63
+ ? index === 0 ? { flex: '0 1 90px', minW: 0 } : index === 1 ? { flex: '1 1 0', minW: 60, wrap: 'anywhere' } : { flex: '0 1 auto', minW: 0, talign: 'end' }
64
+ : { flex: 1, minW: 0, wrap: 'anywhere' },
65
+ }));
66
+ const body = [
67
+ h('row', { key: 'cols', style: { align: 'center', gap: 8, minH: 31, pad: [6, 8], box: 'border' } }, texts),
68
+ h('spacer', { key: 'rule', style: { h: 1, bg: ROW_LINE } }),
69
+ ];
70
+ const style = { w: 'fill', talign: 'start', lh: 1.3333 };
71
+ return readOnly
72
+ ? h('column', { key: `r:${item.id}`, data: { id: String(item.id) }, style }, body)
73
+ : h('button', {
74
+ key: `r:${item.id}`, label: (columns ?? [item.label]).join(' · '), data: { id: String(item.id) },
75
+ style: { ...style, pad: 0, border: 'none', bg: 'transparent' },
76
+ on: { tap: () => on.pick?.(item.id) },
77
+ }, body);
78
+ }
79
+
80
+ export function buildMenu(state, on = {}) {
81
+ const spec = state.spec;
82
+ const root = { key: 'menu', style: { font: 'ui', size: 15, weight: 600, lh: 1.3, color: '#fff' } };
83
+ if (!spec) {return h('stack', root);}
84
+ const view = state.view ?? {};
85
+ const rows = spec.presentation === 'rows';
86
+ const face = Object.hasOwn(spec, 'face');
87
+ const readOnly = spec.readOnly === true;
88
+ const width = rows
89
+ ? [{ vw: 100, px: -24 }, { px: 720 }]
90
+ : view.landscape ? [{ vw: 56 }, { max: [220, { vw: 100, px: -344 }] }, { px: 560 }] : [{ vw: 100 }, { px: 720 }];
91
+
92
+ let list;
93
+ if (rows) {
94
+ list = spec.sections.flatMap((section, s) => [
95
+ h('text', { key: `s${s}`, text: String(section.title ?? ''), style: { size: 13, pad: [4, 0], wrap: 'anywhere' } }),
96
+ ...section.items.map((item) => textRow(item, readOnly, on)),
97
+ ]);
98
+ } else {
99
+ list = spec.sections.flatMap((section, s) => [
100
+ h('text', { key: `s${s}`, text: String(section.title ?? ''), style: { size: 13, pad: [8, 0] } }),
101
+ h('grid', { key: `g${s}`, cols: tileCols(view.w), style: { gap: 8 } }, section.items.map((item) => tile(item, readOnly, on))),
102
+ ]);
103
+ }
104
+ const footer = rows && spec.footer?.length
105
+ ? h('row', { key: 'footer', style: { gap: 8, pad: [6, 0, 0, 0] } }, spec.footer.map((item) => h('button', {
106
+ key: `b:${item.id}`, disabled: readOnly, data: { id: String(item.id) },
107
+ style: { flex: '1 1 0', minW: 0, minH: 44, pad: 8, box: 'border', radius: 8, border: { w: 1, c: TILE_LINE }, bg: TILE_BG, wrap: ['word', 'anywhere'] },
108
+ on: { tap: () => {if (!readOnly) {on.pick?.(item.id);}} },
109
+ }, item.label)))
110
+ : null;
111
+
112
+ return h('stack', {
113
+ ...root,
114
+ // Esc / Back closes the sheet (and tells the place).
115
+ on: { cancel: on.close },
116
+ },
117
+ h('column', {
118
+ key: 'sheet', hub: 'menu', role: 'dialog', label: String(spec.title ?? ''),
119
+ at: { anchor: 'bottom', bottom: 0, z: 9 },
120
+ style: {
121
+ w: width, maxH: rows && !face ? [{ dvh: 100, px: -24 }] : [{ max: [{ dvh: face ? 40 : 55 }, face ? SHORT_FACE_PX : SHORT_PX] }, { dvh: 100, px: -24 }], box: 'border', clip: true,
122
+ gap: 6, pad: [12, 12, [12, 0], 12], radius: [12, 12, 0, 0], bg: 'card', shadow: 'card', hit: 'auto',
123
+ },
124
+ },
125
+ h('row', { key: 'head', style: { align: 'center', gap: 8 } },
126
+ h('text', { key: 'title', text: String(spec.title ?? ''), style: { flex: 1, minW: 0, wrap: 'anywhere' } }),
127
+ h('button', {
128
+ key: 'close', label: 'Close',
129
+ style: { minW: 44, minH: 44, pad: [5, 12], radius: 12, border: { w: 1, c: 'line35' }, bg: 'transparent', color: '#fff', size: 13, weight: 700, lh: 'normal' },
130
+ on: { tap: on.close },
131
+ }, '×')),
132
+ spec.note ? h('text', { key: 'note', text: String(spec.note), style: { size: 13, wrap: 'anywhere' } }) : null,
133
+ h('scroll', { key: 'list', axis: 'y', style: { minH: 0, ...(rows ? { flex: '1 1 auto' } : {}) } }, list),
134
+ footer));
135
+ }