castle-web-cli 0.4.238 → 0.4.240

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (404) hide show
  1. package/dist/agent.js +5 -1
  2. package/dist/api.d.ts +20 -0
  3. package/dist/api.js +57 -0
  4. package/dist/bundle.d.ts +38 -1
  5. package/dist/bundle.js +309 -13
  6. package/dist/castle-host/host.js +218 -11
  7. package/dist/castleJson.d.ts +10 -0
  8. package/dist/castleJson.js +46 -2
  9. package/dist/check.js +5 -2
  10. package/dist/devSessionServer.js +4 -1
  11. package/dist/devSessionStorage.d.ts +1 -0
  12. package/dist/devSessionStorage.js +32 -7
  13. package/dist/importOrder.d.ts +2 -0
  14. package/dist/importOrder.js +29 -0
  15. package/dist/index.js +22 -3
  16. package/dist/init.js +24 -2
  17. package/dist/multiplayerDoc.d.ts +1 -1
  18. package/dist/multiplayerDoc.js +9 -0
  19. package/dist/platformDoc.js +4 -2
  20. package/dist/playPagePolicy.d.ts +1 -0
  21. package/dist/playPagePolicy.js +12 -3
  22. package/dist/resetLeaderboards.d.ts +8 -1
  23. package/dist/resetLeaderboards.js +43 -8
  24. package/dist/roomLogs.d.ts +39 -0
  25. package/dist/roomLogs.js +166 -0
  26. package/dist/save-deck.d.ts +32 -2
  27. package/dist/save-deck.js +240 -39
  28. package/kits/base/CLAUDE.md +2 -1
  29. package/kits/base/castle.json +1 -1
  30. package/kits/base/sdk/README.md +240 -8
  31. package/kits/base/sdk/analytics.d.ts +8 -0
  32. package/kits/base/sdk/analytics.js +92 -0
  33. package/kits/base/sdk/castle.d.ts +8 -2
  34. package/kits/base/sdk/castle.js +3 -0
  35. package/kits/base/sdk/commands.d.ts +79 -0
  36. package/kits/base/sdk/commands.js +1 -0
  37. package/kits/base/sdk/debugConsole.d.ts +17 -0
  38. package/kits/base/sdk/debugConsole.js +154 -0
  39. package/kits/base/sdk/experiments.js +24 -1
  40. package/kits/base/sdk/hostRetry.d.ts +7 -0
  41. package/kits/base/sdk/hostRetry.js +57 -0
  42. package/kits/base/sdk/hub.d.ts +20 -2
  43. package/kits/base/sdk/hub.js +99 -13
  44. package/kits/base/sdk/multiplayer.d.ts +2 -0
  45. package/kits/base/sdk/multiplayer.js +198 -26
  46. package/kits/base/sdk/reconnectBudget.d.ts +6 -0
  47. package/kits/base/sdk/reconnectBudget.js +41 -1
  48. package/kits/base/sdk/rooms.d.ts +11 -0
  49. package/kits/base/sdk/rooms.js +22 -0
  50. package/kits/base/sdk/runtime.js +36 -19
  51. package/kits/base/sdk/server/hub.d.ts +19 -0
  52. package/kits/base/sdk/server/hub.js +12 -0
  53. package/kits/base/sdk/server/platformHandle.d.ts +1 -0
  54. package/kits/base/sdk/server/wrapper.d.ts +1 -1
  55. package/kits/base/sdk/server/wrapper.js +26 -1
  56. package/kits/base/sdk/store.d.ts +8 -2
  57. package/kits/base/sdk/store.js +5 -1
  58. package/kits/base/sdk/transport.d.ts +2 -1
  59. package/kits/base/sdk/transport.js +35 -0
  60. package/kits/hub-game/CLAUDE.md +66 -19
  61. package/kits/hub-game/castle.json +4 -4
  62. package/kits/hub-game/code/client/act.js +9 -6
  63. package/kits/hub-game/code/client/actCore.js +26 -6
  64. package/kits/hub-game/code/client/actGateLog.js +36 -0
  65. package/kits/hub-game/code/client/actionOverflow.js +29 -8
  66. package/kits/hub-game/code/client/actionRailSurface.js +186 -0
  67. package/kits/hub-game/code/client/actionRailTree.js +173 -0
  68. package/kits/hub-game/code/client/askSurface.js +85 -0
  69. package/kits/hub-game/code/client/askTree.js +51 -0
  70. package/kits/hub-game/code/client/attention.js +31 -6
  71. package/kits/hub-game/code/client/ballot.js +42 -5
  72. package/kits/hub-game/code/client/ballotSurface.js +115 -0
  73. package/kits/hub-game/code/client/ballotTree.js +180 -0
  74. package/kits/hub-game/code/client/catchingUp.js +19 -0
  75. package/kits/hub-game/code/client/celebrate.js +66 -0
  76. package/kits/hub-game/code/client/chrome.js +474 -53
  77. package/kits/hub-game/code/client/companion.js +93 -23
  78. package/kits/hub-game/code/client/companionDress.js +1 -1
  79. package/kits/hub-game/code/client/cornerSurface.js +106 -0
  80. package/kits/hub-game/code/client/cornerTree.js +83 -0
  81. package/kits/hub-game/code/client/decor.js +20 -11
  82. package/kits/hub-game/code/client/deviceStorage.js +121 -0
  83. package/kits/hub-game/code/client/disguise.js +23 -0
  84. package/kits/hub-game/code/client/disguiseDraw.js +87 -0
  85. package/kits/hub-game/code/client/dockSurface.js +206 -0
  86. package/kits/hub-game/code/client/dockTree.js +232 -0
  87. package/kits/hub-game/code/client/earned.js +29 -0
  88. package/kits/hub-game/code/client/emoteSurface.js +188 -0
  89. package/kits/hub-game/code/client/emoteTree.js +264 -0
  90. package/kits/hub-game/code/client/farAvatars.js +4 -3
  91. package/kits/hub-game/code/client/fpsTelemetry.js +3 -1
  92. package/kits/hub-game/code/client/grab.js +121 -50
  93. package/kits/hub-game/code/client/holdShow.js +19 -0
  94. package/kits/hub-game/code/client/hookLayer.js +96 -12
  95. package/kits/hub-game/code/client/hubControls.js +7 -1
  96. package/kits/hub-game/code/client/hudSurface.js +11 -3
  97. package/kits/hub-game/code/client/hudTree.js +7 -4
  98. package/kits/hub-game/code/client/idle.js +21 -3
  99. package/kits/hub-game/code/client/invites.js +24 -3
  100. package/kits/hub-game/code/client/keys.js +15 -0
  101. package/kits/hub-game/code/client/labelsNear.js +8 -1
  102. package/kits/hub-game/code/client/layoutCache.js +57 -8
  103. package/kits/hub-game/code/client/loadingCover.js +53 -4
  104. package/kits/hub-game/code/client/menuIcons.js +15 -0
  105. package/kits/hub-game/code/client/menuRows.js +8 -2
  106. package/kits/hub-game/code/client/menuSurface.js +102 -0
  107. package/kits/hub-game/code/client/menuTree.js +135 -0
  108. package/kits/hub-game/code/client/modelLook.js +41 -0
  109. package/kits/hub-game/code/client/pickerSurface.js +152 -0
  110. package/kits/hub-game/code/client/pickerTree.js +163 -0
  111. package/kits/hub-game/code/client/pushVisit.js +4 -2
  112. package/kits/hub-game/code/client/quality.js +188 -29
  113. package/kits/hub-game/code/client/qualityEntry.js +10 -1
  114. package/kits/hub-game/code/client/quickChatSurface.js +222 -0
  115. package/kits/hub-game/code/client/quickChatTree.js +201 -0
  116. package/kits/hub-game/code/client/rehello.js +75 -0
  117. package/kits/hub-game/code/client/renderVisibility.js +17 -0
  118. package/kits/hub-game/code/client/replay.js +118 -0
  119. package/kits/hub-game/code/client/role.js +3 -0
  120. package/kits/hub-game/code/client/safeLayout.js +441 -56
  121. package/kits/hub-game/code/client/safeStyle.js +13 -10
  122. package/kits/hub-game/code/client/say.js +2 -0
  123. package/kits/hub-game/code/client/soundSurface.js +77 -0
  124. package/kits/hub-game/code/client/soundTree.js +74 -0
  125. package/kits/hub-game/code/client/soundscape.js +12 -9
  126. package/kits/hub-game/code/client/soundscapeCues.js +1 -1
  127. package/kits/hub-game/code/client/state.js +67 -1
  128. package/kits/hub-game/code/client/stuckSurface.js +76 -0
  129. package/kits/hub-game/code/client/stuckTree.js +67 -0
  130. package/kits/hub-game/code/client/talk.js +42 -12
  131. package/kits/hub-game/code/client/talkTree.js +4 -2
  132. package/kits/hub-game/code/client/textAskSurface.js +147 -0
  133. package/kits/hub-game/code/client/textAskTree.js +67 -0
  134. package/kits/hub-game/code/client/tiers.js +252 -27
  135. package/kits/hub-game/code/client/together.js +4 -1
  136. package/kits/hub-game/code/client/uiDom.js +86 -8
  137. package/kits/hub-game/code/client/uiTree.js +33 -4
  138. package/kits/hub-game/code/client/vehicle.js +75 -52
  139. package/kits/hub-game/code/client/weakestTier.js +75 -31
  140. package/kits/hub-game/code/client/wear.js +159 -5
  141. package/kits/hub-game/code/client/worldLabels.js +215 -26
  142. package/kits/hub-game/code/companionSpec.js +4 -2
  143. package/kits/hub-game/code/server/act.js +3 -0
  144. package/kits/hub-game/code/server/actGate.js +83 -0
  145. package/kits/hub-game/code/server/actions.js +71 -15
  146. package/kits/hub-game/code/server/actors.js +20 -5
  147. package/kits/hub-game/code/server/analytics.js +40 -15
  148. package/kits/hub-game/code/server/ask.js +39 -3
  149. package/kits/hub-game/code/server/ballot.js +167 -4
  150. package/kits/hub-game/code/server/celebrate.js +64 -0
  151. package/kits/hub-game/code/server/companion.js +17 -2
  152. package/kits/hub-game/code/server/decor.js +11 -2
  153. package/kits/hub-game/code/server/disguise.js +63 -0
  154. package/kits/hub-game/code/server/doorAnalytics.js +2 -5
  155. package/kits/hub-game/code/server/earned.js +6 -2
  156. package/kits/hub-game/code/server/friendBests.js +13 -4
  157. package/kits/hub-game/code/server/friendsAmong.js +67 -8
  158. package/kits/hub-game/code/server/grab.js +12 -2
  159. package/kits/hub-game/code/server/heldOffers.js +142 -0
  160. package/kits/hub-game/code/server/holdShow.js +98 -0
  161. package/kits/hub-game/code/server/hub.js +854 -45
  162. package/kits/hub-game/code/server/idle.js +110 -9
  163. package/kits/hub-game/code/server/index.js +9 -0
  164. package/kits/hub-game/code/server/labels.js +13 -3
  165. package/kits/hub-game/code/server/loadAbandon.js +2 -5
  166. package/kits/hub-game/code/server/manifest.js +94 -6
  167. package/kits/hub-game/code/server/menu.js +26 -3
  168. package/kits/hub-game/code/server/npcs.js +55 -9
  169. package/kits/hub-game/code/server/observe.js +67 -6
  170. package/kits/hub-game/code/server/players.js +8 -1
  171. package/kits/hub-game/code/server/replay.js +135 -0
  172. package/kits/hub-game/code/server/storageLimit.js +4 -1
  173. package/kits/hub-game/code/server/townDay.js +74 -0
  174. package/kits/hub-game/code/server/trackQueue.js +29 -0
  175. package/kits/hub-game/code/server/vehicle.js +3 -0
  176. package/kits/hub-game/code/server/vis.js +26 -4
  177. package/kits/hub-game/code/server/wallet.js +677 -0
  178. package/kits/hub-game/code/server/wear.js +13 -3
  179. package/kits/hub-game/code/server/writerLease.js +191 -0
  180. package/kits/hub-game/code/shared/act.js +1 -1
  181. package/kits/hub-game/code/shared/expression.js +6 -0
  182. package/kits/hub-game/code/shared/replay.js +37 -0
  183. package/kits/hub-game/code/systems/hub.js +437 -57
  184. package/kits/hub-game/docs/analytics.md +20 -3
  185. package/kits/hub-game/docs/contract.md +942 -99
  186. package/kits/hub-game/docs/home-pieces.md +5 -6
  187. package/kits/hub-game/docs/observed-progress.md +49 -1
  188. package/kits/hub-game/docs/vehicle-preset.md +23 -0
  189. package/kits/hub-game/index.html +1 -0
  190. package/kits/hub-game/models/hats/baker-cap.pxmodel +3 -3
  191. package/kits/hub-game/models/hats/bat-clip.pxmodel +3 -3
  192. package/kits/hub-game/models/hats/beekeeper.pxmodel +3 -3
  193. package/kits/hub-game/models/hats/cap.pxmodel +3 -3
  194. package/kits/hub-game/models/hats/captain.pxmodel +3 -3
  195. package/kits/hub-game/models/hats/chef-toque.pxmodel +3 -3
  196. package/kits/hub-game/models/hats/crooked-top.pxmodel +3 -3
  197. package/kits/hub-game/models/hats/delivery-cap.pxmodel +3 -3
  198. package/kits/hub-game/models/hats/fire-helmet.pxmodel +3 -3
  199. package/kits/hub-game/models/hats/flower-crown.pxmodel +3 -3
  200. package/kits/hub-game/models/hats/foam-crown.pxmodel +3 -3
  201. package/kits/hub-game/models/hats/hard-hat.pxmodel +3 -3
  202. package/kits/hub-game/models/hats/lantern.pxmodel +3 -3
  203. package/kits/hub-game/models/hats/laurel.pxmodel +3 -3
  204. package/kits/hub-game/models/hats/lighthouse.pxmodel +3 -3
  205. package/kits/hub-game/models/hats/nurse-cap.pxmodel +3 -3
  206. package/kits/hub-game/models/hats/police-cap.pxmodel +3 -3
  207. package/kits/hub-game/models/hats/sailor.pxmodel +3 -3
  208. package/kits/hub-game/models/hats/souwester.pxmodel +3 -3
  209. package/kits/hub-game/models/hats/straw.pxmodel +3 -3
  210. package/kits/hub-game/models/hats/sunflower.pxmodel +3 -3
  211. package/kits/hub-game/models/hats/sweatband.pxmodel +3 -3
  212. package/kits/hub-game/models/hats/teacher-beret.pxmodel +3 -3
  213. package/kits/hub-game/models/hats/witch.pxmodel +3 -3
  214. package/kits/hub-game/models/hold-show/daisy.pxmodel +231 -0
  215. package/kits/hub-game/models/hold-show/moonflower.pxmodel +171 -0
  216. package/kits/hub-game/models/hold-show/rose.pxmodel +191 -0
  217. package/kits/hub-game/models/hold-show/square/daisy.pxmodel +233 -0
  218. package/kits/hub-game/models/hold-show/square/moonflower.pxmodel +173 -0
  219. package/kits/hub-game/models/hold-show/square/rose.pxmodel +193 -0
  220. package/kits/hub-game/models/hold-show/square/sunflower.pxmodel +313 -0
  221. package/kits/hub-game/models/hold-show/square/tulip.pxmodel +133 -0
  222. package/kits/hub-game/models/hold-show/sunflower.pxmodel +311 -0
  223. package/kits/hub-game/models/hold-show/tulip.pxmodel +131 -0
  224. package/kits/hub-game/package-lock.json +3 -3
  225. package/kits/hub-game/package.json +4 -3
  226. package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +1 -0
  227. package/kits/hub-game/scripts/fixtures/hud-surface.json +12 -12
  228. package/kits/hub-game/scripts/fixtures/talk-surface.json +8 -8
  229. package/kits/hub-game/scripts/gen-hats.mjs +1 -1
  230. package/kits/hub-game/scripts/gen-hold-show.mjs +27 -0
  231. package/kits/hub-game/scripts/pack.mjs +89 -23
  232. package/kits/hub-game/scripts/test-act-client.mjs +5 -0
  233. package/kits/hub-game/scripts/test-act-core.mjs +32 -0
  234. package/kits/hub-game/scripts/test-act-gate.mjs +186 -0
  235. package/kits/hub-game/scripts/test-action-rail-crowded-dom.mjs +7 -1
  236. package/kits/hub-game/scripts/test-action-rail-default-dom.mjs +102 -0
  237. package/kits/hub-game/scripts/test-action-rail-never-silent-dom.mjs +50 -0
  238. package/kits/hub-game/scripts/test-action-rail-surface.mjs +368 -0
  239. package/kits/hub-game/scripts/test-action-rail-town-jobs-dom.mjs +118 -0
  240. package/kits/hub-game/scripts/test-actions-client.mjs +5 -3
  241. package/kits/hub-game/scripts/test-actions.mjs +24 -0
  242. package/kits/hub-game/scripts/test-actors.mjs +19 -0
  243. package/kits/hub-game/scripts/test-again-corner-dom.mjs +59 -0
  244. package/kits/hub-game/scripts/test-analytics.mjs +80 -1
  245. package/kits/hub-game/scripts/test-arrival-pose-server.mjs +25 -8
  246. package/kits/hub-game/scripts/test-ask-client.mjs +9 -0
  247. package/kits/hub-game/scripts/test-ask-surface.mjs +188 -0
  248. package/kits/hub-game/scripts/test-attention.mjs +43 -1
  249. package/kits/hub-game/scripts/test-ballot-sheet-dom.mjs +71 -0
  250. package/kits/hub-game/scripts/test-ballot-surface.mjs +276 -0
  251. package/kits/hub-game/scripts/test-ballot.mjs +420 -3
  252. package/kits/hub-game/scripts/test-ban-join.mjs +1 -1
  253. package/kits/hub-game/scripts/test-celebrate-client.mjs +62 -0
  254. package/kits/hub-game/scripts/test-celebrate.mjs +116 -0
  255. package/kits/hub-game/scripts/test-chat.mjs +73 -0
  256. package/kits/hub-game/scripts/test-companion-client.mjs +203 -21
  257. package/kits/hub-game/scripts/test-companion.mjs +110 -3
  258. package/kits/hub-game/scripts/test-control-layout-dom.mjs +57 -10
  259. package/kits/hub-game/scripts/test-corner-surface.mjs +268 -0
  260. package/kits/hub-game/scripts/test-decor-client.mjs +59 -3
  261. package/kits/hub-game/scripts/test-decor.mjs +27 -0
  262. package/kits/hub-game/scripts/test-device-class.mjs +4 -1
  263. package/kits/hub-game/scripts/test-disguise-client.mjs +281 -0
  264. package/kits/hub-game/scripts/test-disguise.mjs +176 -0
  265. package/kits/hub-game/scripts/test-dock-surface.mjs +404 -0
  266. package/kits/hub-game/scripts/test-door-analytics.mjs +1 -1
  267. package/kits/hub-game/scripts/test-door-stay-client.mjs +602 -0
  268. package/kits/hub-game/scripts/test-door-stay.mjs +613 -0
  269. package/kits/hub-game/scripts/test-earned-client.mjs +119 -0
  270. package/kits/hub-game/scripts/test-emote-surface.mjs +616 -0
  271. package/kits/hub-game/scripts/test-fps-telemetry.mjs +39 -4
  272. package/kits/hub-game/scripts/test-friend-bests.mjs +38 -12
  273. package/kits/hub-game/scripts/test-ghost-click-dom.mjs +75 -0
  274. package/kits/hub-game/scripts/test-grab-client.mjs +29 -2
  275. package/kits/hub-game/scripts/test-grab-orbit.mjs +260 -11
  276. package/kits/hub-game/scripts/test-grab.mjs +10 -1
  277. package/kits/hub-game/scripts/test-hats.mjs +28 -0
  278. package/kits/hub-game/scripts/test-held-offers.mjs +394 -0
  279. package/kits/hub-game/scripts/test-high-only.mjs +3 -3
  280. package/kits/hub-game/scripts/test-hold-show-client.mjs +175 -0
  281. package/kits/hub-game/scripts/test-hold-show.mjs +355 -0
  282. package/kits/hub-game/scripts/test-hub-controls.mjs +3 -1
  283. package/kits/hub-game/scripts/test-hub-idle.mjs +348 -0
  284. package/kits/hub-game/scripts/test-hub-leaving.mjs +21 -0
  285. package/kits/hub-game/scripts/test-hub-ops.mjs +147 -0
  286. package/kits/hub-game/scripts/test-hub-trip.mjs +260 -5
  287. package/kits/hub-game/scripts/test-hud-clear.mjs +83 -0
  288. package/kits/hub-game/scripts/test-hud-rate.mjs +2 -1
  289. package/kits/hub-game/scripts/test-idle.mjs +160 -0
  290. package/kits/hub-game/scripts/test-invites-client.mjs +53 -0
  291. package/kits/hub-game/scripts/test-labels.mjs +11 -0
  292. package/kits/hub-game/scripts/test-landscape-layout.mjs +20 -0
  293. package/kits/hub-game/scripts/test-load-abandon.mjs +2 -2
  294. package/kits/hub-game/scripts/test-loading-cover.mjs +67 -1
  295. package/kits/hub-game/scripts/test-manifest.mjs +27 -0
  296. package/kits/hub-game/scripts/test-menu-client.mjs +55 -6
  297. package/kits/hub-game/scripts/test-menu-surface.mjs +236 -0
  298. package/kits/hub-game/scripts/test-npcs.mjs +128 -0
  299. package/kits/hub-game/scripts/test-observed.mjs +171 -3
  300. package/kits/hub-game/scripts/test-pack.mjs +166 -0
  301. package/kits/hub-game/scripts/test-picker-surface.mjs +321 -0
  302. package/kits/hub-game/scripts/test-placeat-server.mjs +395 -0
  303. package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
  304. package/kits/hub-game/scripts/test-pointer-clear-dom.mjs +82 -0
  305. package/kits/hub-game/scripts/test-progress-reset.mjs +184 -6
  306. package/kits/hub-game/scripts/test-push-visit.mjs +9 -0
  307. package/kits/hub-game/scripts/test-quality.mjs +312 -9
  308. package/kits/hub-game/scripts/test-quick-chat-surface.mjs +511 -0
  309. package/kits/hub-game/scripts/test-rehello.mjs +237 -0
  310. package/kits/hub-game/scripts/test-rejoin-yaw.mjs +138 -0
  311. package/kits/hub-game/scripts/test-relations-among.mjs +13 -7
  312. package/kits/hub-game/scripts/test-relations-refresh.mjs +90 -2
  313. package/kits/hub-game/scripts/test-replay-client.mjs +110 -0
  314. package/kits/hub-game/scripts/test-replay.mjs +178 -0
  315. package/kits/hub-game/scripts/test-resume-held.mjs +13 -0
  316. package/kits/hub-game/scripts/test-resume-pose-server.mjs +43 -5
  317. package/kits/hub-game/scripts/test-resync.mjs +13 -0
  318. package/kits/hub-game/scripts/test-role-client.mjs +10 -3
  319. package/kits/hub-game/scripts/test-safe-act.mjs +233 -0
  320. package/kits/hub-game/scripts/test-safe-caption.mjs +364 -0
  321. package/kits/hub-game/scripts/test-safe-layout.mjs +79 -0
  322. package/kits/hub-game/scripts/test-safe-prompt.mjs +163 -0
  323. package/kits/hub-game/scripts/test-sound-surface.mjs +256 -0
  324. package/kits/hub-game/scripts/test-soundscape.mjs +85 -2
  325. package/kits/hub-game/scripts/test-stuck-surface.mjs +174 -0
  326. package/kits/hub-game/scripts/test-stuck.mjs +31 -0
  327. package/kits/hub-game/scripts/test-talk-surface.mjs +23 -6
  328. package/kits/hub-game/scripts/test-talk-walk-dom.mjs +123 -0
  329. package/kits/hub-game/scripts/test-text-ask-surface.mjs +273 -0
  330. package/kits/hub-game/scripts/test-tiers.mjs +453 -3
  331. package/kits/hub-game/scripts/test-toast-no-row-dom.mjs +71 -0
  332. package/kits/hub-game/scripts/test-together.mjs +11 -0
  333. package/kits/hub-game/scripts/test-town-day.mjs +90 -0
  334. package/kits/hub-game/scripts/test-track-queue.mjs +64 -0
  335. package/kits/hub-game/scripts/test-try-on.mjs +39 -0
  336. package/kits/hub-game/scripts/test-ui-dom-dom.mjs +49 -2
  337. package/kits/hub-game/scripts/test-ui-tree.mjs +28 -0
  338. package/kits/hub-game/scripts/test-vehicle-client.mjs +77 -1
  339. package/kits/hub-game/scripts/test-vis.mjs +145 -0
  340. package/kits/hub-game/scripts/test-wallet.mjs +650 -0
  341. package/kits/hub-game/scripts/test-weakest-tier.mjs +135 -1
  342. package/kits/hub-game/scripts/test-world-labels.mjs +380 -0
  343. package/kits/hub-game/scripts/test-writer-lease-server.mjs +234 -0
  344. package/kits/hub-game/scripts/test-writer-lease.mjs +281 -0
  345. package/kits/hub-game/scripts/writer-storage-fixture.mjs +37 -0
  346. package/kits/hub-game/tools/hubScene/export.mjs +6 -5
  347. package/kits/hub-game/tools/hubScene/hubdata.mjs +10 -0
  348. package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +48 -2
  349. package/kits/hub-game/tools/hubScene/validate-manifest.mjs +21 -3
  350. package/kits/multiplayer-3d/castle.json +5 -5
  351. package/kits/multiplayer-3d/code/client/resumeGate.js +49 -2
  352. package/kits/multiplayer-3d/code/server/ownership.js +25 -6
  353. package/kits/multiplayer-3d/code/server/world.js +19 -4
  354. package/kits/multiplayer-3d/code/systems/multiplayer.js +67 -11
  355. package/kits/multiplayer-3d/package-lock.json +1 -1
  356. package/kits/multiplayer-3d/package.json +2 -1
  357. package/kits/multiplayer-3d/scripts/test-ground-half.mjs +56 -0
  358. package/kits/multiplayer-3d/scripts/test-join-watchdog.mjs +54 -3
  359. package/kits/multiplayer-3d/scripts/test-owned-moves.mjs +190 -0
  360. package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +191 -5
  361. package/kits/multiplayer-3d/scripts/test-resync-reconnect.mjs +68 -0
  362. package/kits/physics-2d/castle.json +2 -2
  363. package/kits/physics-2d/engine/scene.js +10 -2
  364. package/kits/physics-3d/CLAUDE.md +14 -0
  365. package/kits/physics-3d/behaviors/Player.jsx +39 -3
  366. package/kits/physics-3d/castle.json +3 -3
  367. package/kits/physics-3d/docs/engine-model-cache.md +109 -0
  368. package/kits/physics-3d/docs/engine-player.md +76 -0
  369. package/kits/physics-3d/docs/engine-skip-work.md +16 -0
  370. package/kits/physics-3d/docs/pxmodel-format.md +5 -1
  371. package/kits/physics-3d/engine3d/gait.js +16 -8
  372. package/kits/physics-3d/engine3d/groundsize.js +23 -0
  373. package/kits/physics-3d/engine3d/kithooks.js +50 -0
  374. package/kits/physics-3d/engine3d/look.js +110 -17
  375. package/kits/physics-3d/engine3d/lookbake.js +19 -1
  376. package/kits/physics-3d/engine3d/materialpresets.js +3 -2
  377. package/kits/physics-3d/engine3d/modelcache.js +280 -0
  378. package/kits/physics-3d/engine3d/modelcachedigest.js +37 -0
  379. package/kits/physics-3d/engine3d/modelcachegate.js +69 -0
  380. package/kits/physics-3d/engine3d/modelrefs.js +13 -0
  381. package/kits/physics-3d/engine3d/optimize.js +20 -9
  382. package/kits/physics-3d/engine3d/playerRun.js +26 -1
  383. package/kits/physics-3d/engine3d/pxmodel.js +7 -3
  384. package/kits/physics-3d/engine3d/templatecache.js +722 -0
  385. package/kits/physics-3d/engine3d/world3d.js +211 -17
  386. package/kits/physics-3d/package-lock.json +1 -1
  387. package/kits/physics-3d/package.json +2 -1
  388. package/kits/physics-3d/play/behaviors/Player.js +43 -3
  389. package/kits/physics-3d/scripts/render.mjs +56 -8
  390. package/kits/physics-3d/scripts/template-cache-fixtures.mjs +37 -0
  391. package/kits/physics-3d/scripts/template-cache-v1-bytes.json +49 -0
  392. package/kits/physics-3d/scripts/test-gait.mjs +53 -9
  393. package/kits/physics-3d/scripts/test-ground-half.mjs +120 -0
  394. package/kits/physics-3d/scripts/test-model-cache.mjs +600 -0
  395. package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1 -0
  396. package/kits/physics-3d/scripts/test-sleeping-models.mjs +384 -0
  397. package/kits/physics-3d/scripts/test-template-cache-minified.mjs +106 -0
  398. package/kits/physics-3d/scripts/test-template-cache.mjs +519 -0
  399. package/kits/physics-3d/scripts/test-wall-slide.mjs +272 -0
  400. package/kits/physics-3d/systems/physics3d.js +51 -2
  401. package/kits/real-time/castle.json +2 -2
  402. package/kits/real-time/code/client/connection.js +3 -0
  403. package/package.json +2 -2
  404. package/vendor/three/examples/jsm/libs/fflate.module.js +2672 -0
@@ -1,6 +1,6 @@
1
1
  // The default world view: goals already become pointers, other actor labels
2
2
  // use the existing three-slot distance/hysteresis rule in games as well.
3
- import { makeLayoutCache } from './layoutCache.js';
3
+ import { makeLayoutCache, surfacePrint } from './layoutCache.js';
4
4
  import { near } from './labelsNear.js';
5
5
  import { clearBox } from './padOccupancy.js';
6
6
  import { overlaps, reservedCorners } from './safeLayout.js';
@@ -27,7 +27,15 @@ export function relevantLabels(state, items, view, now) {
27
27
  // Pointers keep their words before ordinary labels. Labels retain their world
28
28
  // anchor: when there is no clear air there, they collapse instead of becoming
29
29
  // a second row of HUD. Speech/emotes/marks participate in clearance too.
30
- export function worldPlacement(pointers, labels, controls, view) {
30
+ // A plate or a sign (`clamp`) whose anchor is on screen slides onto it rather
31
+ // than being dropped at the edge, and one over the player's own avatar (one
32
+ // of `around`) steps just above or beside it; a control still drops it.
33
+ // An NPC's line (`edge`) is pinned to the screen edge by its caller, so a
34
+ // sub-pixel past the margin, or under a tighter world bound, it slides on.
35
+ // Over its own Talk prompt, a reserved corner or any card or control it
36
+ // steps to the nearest clear slot (`edgeSlot`) instead of being hidden; it
37
+ // never steps around the avatar, which it is already drawn over.
38
+ export function worldPlacement(pointers, labels, controls, view, around = []) {
31
39
  const insets = view.insets ?? { top: 0, right: 0, bottom: 0, left: 0 };
32
40
  const world = view.world;
33
41
  const bounds = {
@@ -50,15 +58,73 @@ export function worldPlacement(pointers, labels, controls, view) {
50
58
  if (placed) {taken.push(placed);}
51
59
  return placed;
52
60
  });
61
+ const inside = (box) => box.left >= bounds.left && box.right <= bounds.right && box.top >= bounds.top && box.bottom <= bounds.bottom;
62
+ const clear = (box, ignore) => !taken.some((other) => other !== ignore && overlaps(box, other));
53
63
  const labelBoxes = labels.map((box) => {
54
- const fits = box.left >= bounds.left && box.right <= bounds.right && box.top >= bounds.top && box.bottom <= bounds.bottom;
55
- if (!fits || taken.some((other) => other !== box.ignoreObstacle && overlaps(box, other))) {return null;}
56
- taken.push(box);
57
- return box;
64
+ let placed = inside(box) && clear(box, box.ignoreObstacle) ? box : null;
65
+ if (!placed && box.clamp) {
66
+ const at = clampTo(box, bounds);
67
+ const w = box.right - box.left, h = box.bottom - box.top;
68
+ const moves = at ? [at, ...around.filter((o) => overlaps(at, o)).flatMap((o) => [
69
+ { left: at.left, right: at.right, top: o.top - 8 - h, bottom: o.top - 8 },
70
+ { left: o.left - 8 - w, right: o.left - 8, top: at.top, bottom: at.bottom },
71
+ { left: o.right + 8, right: o.right + 8 + w, top: at.top, bottom: at.bottom },
72
+ ])] : [];
73
+ placed = moves.filter((move) => inside(move) && clear(move, box.ignoreObstacle))
74
+ .sort((a, b) => Math.hypot(a.left - box.left, a.top - box.top) - Math.hypot(b.left - box.left, b.top - box.top))[0] ?? null;
75
+ } else if (!placed && box.edge) {
76
+ placed = edgeSlot(box, bounds, taken, inside, clear);
77
+ }
78
+ if (placed) {taken.push(placed);}
79
+ return placed;
58
80
  });
59
81
  return { pointers: pointerBoxes, labels: labelBoxes };
60
82
  }
61
83
 
84
+ // Where an NPC's line goes when its slid box is covered: the nearest clear
85
+ // slot higher up (above its own Talk prompt, beside a reserved corner as
86
+ // well if need be), then the nearest clear slot beside or below, then the same search
87
+ // for its first line alone (`box.line` tall; the result carries `line: true`
88
+ // and the chrome clips the rest). Slots stand 8 px off what they step around
89
+ // and stay within a label's width, and twice its height, of where it was
90
+ // slid to. Null when the anchor is off `bounds` or nothing is clear.
91
+ function edgeSlot(box, bounds, taken, inside, clear) {
92
+ const at = clampTo(box, bounds);
93
+ if (!at) {return null;}
94
+ if (inside(at) && clear(at, box.ignoreObstacle)) {return at;}
95
+ const w = at.right - at.left, h = at.bottom - at.top;
96
+ const reach = { left: at.left - w - 8, right: at.right + w + 8, top: at.top - 2 * h - 16, bottom: at.bottom + 2 * h + 16 };
97
+ const near = taken.filter((other) => other !== box.ignoreObstacle && overlaps(other, reach));
98
+ const lefts = [...new Set([at.left, bounds.left, bounds.right - w, ...near.flatMap((other) => [other.left - 8 - w, other.right + 8])])]
99
+ .filter((left) => Math.abs(left - at.left) <= w + 8);
100
+ const slot = (height) => {
101
+ const tops = [...new Set([at.top, at.bottom - height, bounds.top, bounds.bottom - height,
102
+ ...near.flatMap((other) => [other.top - 8 - height, other.bottom + 8])])]
103
+ .filter((top) => top >= reach.top && top + height <= reach.bottom);
104
+ const rank = (move) => [move.bottom < at.bottom - 0.5 ? 0 : 1, Math.hypot(move.left - at.left, move.bottom - at.bottom)];
105
+ return tops.flatMap((top) => lefts.map((left) => ({ left, right: left + w, top, bottom: top + height })))
106
+ .filter((move) => inside(move) && clear(move, box.ignoreObstacle))
107
+ .map((move) => ({ move, key: rank(move) }))
108
+ .sort((a, b) => a.key[0] - b.key[0] || a.key[1] - b.key[1])[0]?.move ?? null;
109
+ };
110
+ const whole = slot(h);
111
+ if (whole || !(box.line > 0 && box.line < h - 0.5)) {return whole;}
112
+ const first = slot(box.line);
113
+ return first && { ...first, line: true };
114
+ }
115
+
116
+ // A label slid inside `bounds`, or null when its anchor (the middle of its
117
+ // bottom edge) is off them or it is wider or taller than they are.
118
+ function clampTo(box, bounds) {
119
+ const w = box.right - box.left, h = box.bottom - box.top;
120
+ const x = (box.left + box.right) / 2;
121
+ if (x < bounds.left || x > bounds.right || box.bottom < bounds.top || box.bottom > bounds.bottom
122
+ || w > bounds.right - bounds.left || h > bounds.bottom - bounds.top) {return null;}
123
+ const left = Math.min(Math.max(box.left, bounds.left), bounds.right - w);
124
+ const top = Math.min(Math.max(box.top, bounds.top), bounds.bottom - h);
125
+ return { left, right: left + w, top, bottom: top + h };
126
+ }
127
+
62
128
  // Try whole-width vertical bands first; the DOM pass can reflow on failure.
63
129
  export function captionBand(box, controls, view) {
64
130
  const height = box.bottom - box.top;
@@ -117,28 +183,91 @@ function captionSlot(box, controls, view) {
117
183
  return null;
118
184
  }
119
185
 
120
- export function makeWorldLayout(entries, view, obstacles = () => [], geometry = makeLayoutCache()) {
186
+ const reflowKeys = ['width', 'maxWidth', 'left', 'right', 'boxSizing', 'whiteSpace', 'maxHeight', 'overflowY', 'pointerEvents'];
187
+
188
+ // Everything outside a caption's own text and inline style that can resize
189
+ // it unseen under its reflow: the attributes of it and every ancestor, the
190
+ // style sheets and their rule counts, loaded fonts and the pixel ratio.
191
+ const sheetIds = new WeakMap();
192
+ let sheets = 0;
193
+ function surroundings(node, geometry) {
194
+ const parts = [geometry.fontEpoch?.(), globalThis.devicePixelRatio];
195
+ for (let at = node; at; at = at.parentElement ?? at.parent) {
196
+ parts.push('/', at.className);
197
+ for (const name of at.getAttributeNames?.() ?? []) {
198
+ if (at !== node || name !== 'style') {parts.push(name, at.getAttribute(name));}
199
+ }
200
+ }
201
+ const doc = globalThis.document;
202
+ for (const sheet of [...(doc?.styleSheets ?? []), ...(doc?.adoptedStyleSheets ?? [])]) {
203
+ if (!sheetIds.has(sheet)) {sheetIds.set(sheet, sheets += 1);}
204
+ let rules = null;
205
+ try {rules = sheet.cssRules?.length;} catch {/* A cross-origin sheet's rules are unreadable. */}
206
+ parts.push(sheetIds.get(sheet), rules, sheet.disabled, sheet.media?.mediaText);
207
+ }
208
+ return parts.join('\u0001');
209
+ }
210
+
211
+ // `held(node)` is the box a control held before safe layout moved or hid it
212
+ // (an act prompt): labels and pointers make way for that box, as before.
213
+ export function makeWorldLayout(entries, view, obstacles = () => [], geometry = makeLayoutCache(), held = () => null) {
121
214
  const hidden = new Set();
122
215
  const shifted = new Map();
123
216
  const reflowed = new Map();
124
- function restoreReflowed() {
125
- for (const [node, styles] of reflowed) {
126
- Object.assign(node.style, styles);
127
- // The snapshot may contain the narrower caption from the last flush.
128
- geometry.invalidate(node);
129
- }
130
- reflowed.clear();
217
+ // A caption's last reflow and everything it was fitted to. While none of
218
+ // it changes, the reflowed styles stay written and the natural sample
219
+ // stands in for the restored caption's box.
220
+ const kept = new Map();
221
+ // Captions held with their natural sample, as if restored at frame start.
222
+ const restoredEarly = new Set();
223
+ // `early`: the plain reset would have restored this caption already, so
224
+ // a style another writer set since then is theirs to keep.
225
+ function restore(node, early = false) {
226
+ const styles = reflowed.get(node), written = kept.get(node)?.written;
227
+ if (!styles) {return;}
228
+ Object.assign(node.style, early ? Object.fromEntries(Object.entries(styles).filter(([key]) => node.style[key] === written[key])) : styles);
229
+ // The snapshot may contain the narrower caption from the last flush.
230
+ geometry.invalidate(node);
231
+ reflowed.delete(node); kept.delete(node); restoredEarly.delete(node);
131
232
  }
132
- function begin() {
233
+ const hold = (node) => {
234
+ const record = kept.get(node);
235
+ if (geometry.hold?.(node, record?.natural, () => restore(node, true), () => surroundings(node, geometry) === record.surroundings) !== true) {return false;}
236
+ restoredEarly.add(node);
237
+ return true;
238
+ };
239
+ // At a frame's start the caption must still be drawn where it was fitted
240
+ // in the same viewport, with nothing inline changed since (layout moves
241
+ // in 1/64px units).
242
+ const drawnAsKept = (node) => {
243
+ const record = kept.get(node);
244
+ if (!record || !geometry.active?.() || surfacePrint(node) !== record.print || JSON.stringify(view()) !== record.viewport) {return false;}
245
+ const box = geometry.rect(node);
246
+ return ['left', 'right', 'top', 'bottom'].every((side) => Math.abs(box[side] - record.box[side]) < 0.005);
247
+ };
248
+ // NPC lines drawn as their first line alone: node -> its own clip-path.
249
+ const clipped = new Map();
250
+ function unplace() {
133
251
  for (const node of hidden) {node.style.visibility = '';}
134
252
  for (const [node, value] of shifted) {node.style.translate = value;}
135
- restoreReflowed();
136
- hidden.clear(); shifted.clear();
253
+ for (const [node, value] of clipped) {node.style.clipPath = value;}
254
+ hidden.clear(); shifted.clear(); clipped.clear();
255
+ }
256
+ // `keep` is the frame-start reset: an unchanged reflow waits for the flush.
257
+ function begin(keep = false) {
258
+ unplace();
259
+ for (const node of [...reflowed.keys()]) {
260
+ if (!keep || !drawnAsKept(node) || !hold(node)) {restore(node);}
261
+ }
137
262
  }
138
263
  function flush() {
139
264
  // Width restoration changes wrapping, so only those captions need a fresh
140
- // DOM read. Ordinary surfaces keep using the frame-start snapshot.
141
- restoreReflowed();
265
+ // DOM read. Ordinary surfaces keep using the frame-start snapshot. A
266
+ // reflow held unchanged since then keeps its styles until compared below;
267
+ // one held only since the last flush stands for a restore made here.
268
+ for (const node of [...reflowed.keys()]) {
269
+ if (!geometry.held?.(node) || (!restoredEarly.has(node) && !hold(node))) {restore(node);}
270
+ }
142
271
  const surfaces = entries();
143
272
  const styleHides = (style) => style?.display === 'none' || style?.visibility === 'hidden' || style?.opacity === '0';
144
273
  // Surfaces share their layers, so each ancestor's style is read once per
@@ -155,6 +284,9 @@ export function makeWorldLayout(entries, view, obstacles = () => [], geometry =
155
284
  for (const parent of walked) {ancestorHidden.set(parent, result);}
156
285
  return result;
157
286
  };
287
+ // Safe layout's `!important` translate outranks the inline one written
288
+ // here, so its rect is already where the node is drawn.
289
+ const safeMoved = (node) => node.hasAttribute?.('data-hub-safe-translate') === true;
158
290
  const visible = ({ node }) => {
159
291
  if (!node || node.isConnected === false) {return null;}
160
292
  // The node's own last-pass hide is ignored; an ancestor's is not.
@@ -162,7 +294,7 @@ export function makeWorldLayout(entries, view, obstacles = () => [], geometry =
162
294
  if (own?.display === 'none' || (own?.visibility === 'hidden' && !hidden.has(node)) || own?.opacity === '0') {return null;}
163
295
  if (chainHidden(node.parentElement ?? node.parent)) {return null;}
164
296
  let box = geometry.rect(node);
165
- if (shifted.has(node)) {
297
+ if (shifted.has(node) && !safeMoved(node)) {
166
298
  const [dx, dy] = node.style.translate.split(' ').map(Number.parseFloat);
167
299
  const original = shifted.get(node) || '0 0';
168
300
  const [ox, oy = '0'] = original.split(' ');
@@ -175,21 +307,46 @@ export function makeWorldLayout(entries, view, obstacles = () => [], geometry =
175
307
  const measured = surfaces.map((entry) => ({ ...entry, box: visible(entry) })).filter((entry) => entry.box);
176
308
  // Restore the previous pass after reading its unshifted boxes, before the
177
309
  // caption pass records this flush's shifts, hides and reflowed styles.
178
- begin();
310
+ unplace();
179
311
  // Text bands yield to navigation, but never escape the viewport while
180
312
  // doing so. Dense lanes reflow into a narrower gap before world labels.
181
313
  const viewport = view();
182
314
  const captions = ['hud-prompt', 'engine-look'].flatMap((id) => measured.filter((entry) => entry.id === id));
315
+ const menu = measured.some((entry) => entry.id === 'menu' || entry.node.dataset?.hub === 'action-sheet');
316
+ const fitted = new Set();
183
317
  for (const caption of captions) {
318
+ // A caption safe layout already placed keeps that place and is cleared
319
+ // where it is drawn. One laid out wholly off-screen (a parked engine
320
+ // node) is not on show; pulling it into a band would only make world
321
+ // labels clear it.
322
+ const { box: at } = caption;
323
+ if (safeMoved(caption.node) || at.bottom <= 0 || at.top >= viewport.h || at.right <= 0 || at.left >= viewport.w) {continue;}
184
324
  const controls = measured.filter((entry) => entry !== caption &&
185
325
  entry.kind !== 'label' && entry.kind !== 'pointer').map((entry) => entry.box)
186
326
  .concat(reservedCorners({ ...viewport, insets: viewport.insets ?? { top: 0, right: 0, bottom: 0, left: 0 } })
187
327
  .map(({ x, y, w, h }) => ({ left: x, right: x + w, top: y, bottom: y + h })));
188
328
  let box = caption.box;
189
329
  let placed = captionBand(box, controls, viewport);
330
+ const record = kept.get(caption.node);
331
+ let natural = null, around = null;
332
+ // The width search reads only the DOM and these inputs, so an
333
+ // unchanged caption would find the same width and slot again.
334
+ if (!placed && reflowed.has(caption.node) && record?.menu === menu
335
+ && record.viewport === JSON.stringify(viewport) && record.controls === JSON.stringify(controls)) {
336
+ ({ box, placed } = record);
337
+ fitted.add(caption.node);
338
+ } else if (reflowed.has(caption.node)) {
339
+ // Otherwise a held caption is restored and measured afresh.
340
+ restore(caption.node, restoredEarly.has(caption.node));
341
+ box = caption.box = geometry.rect(caption.node);
342
+ placed = captionBand(box, controls, viewport);
343
+ }
190
344
  if (!placed) {
345
+ natural = geometry.fresh?.(caption.node);
346
+ around = natural && surroundings(caption.node, geometry);
191
347
  const style = caption.node.style;
192
- reflowed.set(caption.node, Object.fromEntries(['width', 'maxWidth', 'left', 'right', 'boxSizing', 'whiteSpace', 'maxHeight', 'overflowY', 'pointerEvents'].map((key) => [key, style[key]])));
348
+ reflowed.set(caption.node, Object.fromEntries(reflowKeys.map((key) => [key, style[key]])));
349
+ fitted.add(caption.node);
193
350
  for (const width of captionWidths(controls, viewport)) {
194
351
  Object.assign(style, { width: `${width}px`, maxWidth: `${width}px`, left: `${(viewport.w - width) / 2}px`, right: 'auto', boxSizing: 'border-box', whiteSpace: 'normal' });
195
352
  box = geometry.rect(caption.node);
@@ -201,7 +358,6 @@ export function makeWorldLayout(entries, view, obstacles = () => [], geometry =
201
358
  // A menu owns its reading surface until it closes. Outside a menu,
202
359
  // make a one-line scrollable caption in a measured gap, preserving
203
360
  // access to the full words even when the complete paragraph won't fit.
204
- const menu = measured.some((entry) => entry.id === 'menu' || entry.node.dataset?.hub === 'action-sheet');
205
361
  if (!menu) {
206
362
  for (const width of captionWidths(controls, viewport)) {
207
363
  Object.assign(caption.node.style, { width: `${width}px`, maxWidth: `${width}px`, left: `${(viewport.w - width) / 2}px`, right: 'auto', maxHeight: '21px', overflowY: 'auto', pointerEvents: 'auto' });
@@ -215,21 +371,54 @@ export function makeWorldLayout(entries, view, obstacles = () => [], geometry =
215
371
  continue;
216
372
  }
217
373
  }
374
+ const sample = natural && geometry.sample(caption.node);
375
+ if (sample) {
376
+ kept.set(caption.node, { natural, sample, box, placed, menu, print: surfacePrint(caption.node), surroundings: around,
377
+ written: Object.fromEntries(reflowKeys.map((key) => [key, caption.node.style[key]])),
378
+ viewport: JSON.stringify(viewport), controls: JSON.stringify(controls) });
379
+ }
218
380
  if (placed.left !== box.left || placed.top !== box.top) {
219
381
  shifted.set(caption.node, caption.node.style.translate);
220
382
  caption.node.style.translate = `${placed.left - box.left}px ${placed.top - box.top}px`;
221
383
  }
384
+ // Later reads this frame see the reflowed sample, as after a search.
385
+ if (fitted.has(caption.node) && kept.has(caption.node)) {
386
+ geometry.hold(caption.node, kept.get(caption.node).sample);
387
+ restoredEarly.delete(caption.node);
388
+ }
222
389
  caption.box = { left: placed.left, right: placed.right, top: placed.top, bottom: placed.top + box.bottom - box.top };
223
390
  }
391
+ for (const node of [...reflowed.keys()]) {
392
+ if (!fitted.has(node)) {restore(node, restoredEarly.has(node));}
393
+ }
224
394
  const pointers = measured.filter((entry) => entry.kind === 'pointer' && entry.id !== 'stuck')
225
395
  .sort((a, b) => Number(b.id?.startsWith('pointer:goal:') === true) - Number(a.id?.startsWith('pointer:goal:') === true));
226
396
  const labels = measured.filter((entry) => entry.kind === 'label');
227
- const controls = measured.filter((entry) => (entry.kind !== 'pointer' || entry.id === 'stuck') && entry.kind !== 'label').map((entry) => entry.box);
228
- const placements = worldPlacement(pointers.map((entry) => entry.box), labels.map(({ box, ignoreObstacle }) => ignoreObstacle
229
- ? { left: box.left, right: box.right, top: box.top, bottom: box.bottom, ignoreObstacle } : box), [...controls, ...obstacles()], view());
397
+ const controls = measured.filter((entry) => (entry.kind !== 'pointer' || entry.id === 'stuck') && entry.kind !== 'label' && !held(entry.node)).map((entry) => entry.box)
398
+ .concat(surfaces.map((entry) => held(entry.node)).filter(Boolean));
399
+ const around = obstacles();
400
+ // An NPC line's one-line form: the slot is its line box and both
401
+ // paddings; what stays drawn ends at its first line's foot (`firstLine`),
402
+ // since the second line starts there and its glyphs would show through
403
+ // the bottom padding.
404
+ const firstLine = new Map();
405
+ const lineOf = (node) => {
406
+ const style = globalThis.getComputedStyle?.(node) ?? node.style;
407
+ const line = Number.parseFloat(style?.lineHeight);
408
+ if (!Number.isFinite(line)) {return null;}
409
+ const top = Number.parseFloat(style.paddingTop) || 0;
410
+ firstLine.set(node, top + line);
411
+ return top + line + (Number.parseFloat(style.paddingBottom) || 0);
412
+ };
413
+ const placements = worldPlacement(pointers.map((entry) => entry.box), labels.map(({ node, box, ignoreObstacle, clamp, edge }) => ignoreObstacle || clamp || edge
414
+ ? { left: box.left, right: box.right, top: box.top, bottom: box.bottom, ignoreObstacle, clamp, edge, ...(edge ? { line: lineOf(node) } : {}) } : box), [...controls, ...around], view(), around);
230
415
  for (const [items, boxes] of [[pointers, placements.pointers], [labels, placements.labels]]) {
231
416
  items.forEach(({ node, box }, index) => {
232
417
  const placed = boxes[index];
418
+ if (placed?.line) {
419
+ clipped.set(node, node.style.clipPath);
420
+ node.style.clipPath = `inset(0 0 ${Number((box.bottom - box.top - firstLine.get(node)).toFixed(3))}px 0 round 12px)`;
421
+ }
233
422
  if (!placed) {node.style.visibility = 'hidden'; hidden.add(node);}
234
423
  else if (placed.left !== box.left || placed.top !== box.top) {
235
424
  shifted.set(node, node.style.translate);
@@ -28,7 +28,7 @@ export function check(spec) {
28
28
  return null;
29
29
  }
30
30
  need(object(spec), 'spec must be a plain object or null');
31
- need(Reflect.ownKeys(spec).every((key) => ['look', 'say', 'at', 'dress', 'pose'].includes(key)), 'spec has an unknown key');
31
+ need(Reflect.ownKeys(spec).every((key) => ['look', 'say', 'at', 'dress', 'pose', 'shown'].includes(key)), 'spec has an unknown key');
32
32
  need(Object.hasOwn(spec, 'look'), 'look must be an own property');
33
33
  const look = spec.look;
34
34
  const hasSay = Object.hasOwn(spec, 'say'), hasAt = Object.hasOwn(spec, 'at');
@@ -41,5 +41,7 @@ export function check(spec) {
41
41
  const dress = hasDress ? checkDress(spec.dress) : undefined;
42
42
  const hasPose = Object.hasOwn(spec, 'pose'), pose = hasPose ? spec.pose : undefined;
43
43
  need(!hasPose || (look === 'bird' && pose === 'show'), 'pose must be show and requires bird');
44
- return { look, ...(hasSay ? { say } : {}), ...(hasAt ? { at } : {}), ...(dress ? { dress } : {}), ...(hasPose ? { pose } : {}) };
44
+ const hasShown = Object.hasOwn(spec, 'shown'), shown = hasShown ? spec.shown : undefined;
45
+ need(!hasShown || (look === 'bird' && shown === true), 'shown must be true and requires bird');
46
+ return { look, ...(hasSay ? { say } : {}), ...(hasAt ? { at } : {}), ...(dress ? { dress } : {}), ...(hasPose ? { pose } : {}), ...(hasShown ? { shown } : {}) };
45
47
  }
@@ -118,7 +118,10 @@ export function message(h, player, data, placeAt) {
118
118
  else if (item.op === 'grab' || item.op === 'throw') {Grab.message(h, id, { actor: item.actor, op: item.op });}
119
119
  else if (item.op === 'talk') {h.npcs.message(player, { k: 'hub-npc-open', npc: item.actor });}
120
120
  else {
121
+ // v1.169: an end this press makes is the player's own door (`hub.end`).
122
+ h.acting = { playerId: id, id: item.id };
121
123
  try {h.hooks.message?.(h.ctx, player, { k: 'hub-act', id: item.id, n: data.n });}
122
124
  catch {console.warn('[hub] Act message hook failed');}
125
+ finally {h.acting = null;}
123
126
  }
124
127
  }
@@ -0,0 +1,83 @@
1
+ // Act-gate log (v1.203, `hub.actGateLog`): a client in an opted-in place
2
+ // reports when its Act/Jump pair is hidden or shown again and why
3
+ // (`client/actGateLog.js`), and the server prints one stdout line per
4
+ // accepted change, so a hidden pair in production can be read from the logs.
5
+ //
6
+ // Advisory only: the report changes no game state. Reasons are a fixed list
7
+ // of short tokens, never text from the client. Lines are capped per player
8
+ // per minute, then per player for the life of this server.
9
+
10
+ export const GATE_REASONS = new Set(['hold', 'card', 'menu', 'ask', 'action', 'talk', 'trip', 'end', 'decor', 'nobody']);
11
+ export const MAX_REASONS = 8;
12
+ export const PER_MINUTE = 20;
13
+ export const PER_SERVER = 400;
14
+ const MINUTE_MS = 60000;
15
+ const KEYS = new Set(['k', 'show', 'reasons']);
16
+
17
+ // Reasons as the client gave them, cleaned: known tokens only, each once, at
18
+ // most MAX_REASONS. Null for a report that is not a report.
19
+ export function readReport(data) {
20
+ if (!data || typeof data !== 'object' || typeof data.show !== 'boolean' || !Array.isArray(data.reasons) ||
21
+ Object.keys(data).some(key => !KEYS.has(key))) {return null;}
22
+ const reasons = [];
23
+ for (const reason of data.reasons.slice(0, 32)) {
24
+ if (typeof reason === 'string' && reason.length <= 12 && GATE_REASONS.has(reason) && !reasons.includes(reason)) {reasons.push(reason);}
25
+ if (reasons.length === MAX_REASONS) {break;}
26
+ }
27
+ return { show: data.show, reasons: data.show ? [] : reasons };
28
+ }
29
+
30
+ const label = show => show === null ? '-' : show ? 'shown' : 'hidden';
31
+
32
+ // One line against `key`'s budget; past PER_SERVER, one muted line and then
33
+ // nothing more from that key.
34
+ function emit(budget, key, line, now, log) {
35
+ if (budget.muted) {return;}
36
+ if (budget.lines >= PER_SERVER) {
37
+ budget.muted = true;
38
+ log(`[hub] act-gate ${key} muted after ${PER_SERVER} lines t=${now}`);
39
+ return;
40
+ }
41
+ budget.lines++;
42
+ log(line);
43
+ }
44
+
45
+ // `who` is the account id, or null for a guest (printed 'guest', budgeted by
46
+ // player id). An account's per-server budget holds across rejoins; the last
47
+ // state is a visit's, dropped by `forget`.
48
+ export function message(h, player, data, who, now = Date.now(), log = console.log) {
49
+ const report = readReport(data);
50
+ const playerId = player?.playerId;
51
+ if (!report || !h.session?.players.some(p => p.playerId === playerId)) {return;}
52
+ h.actGate ??= { players: new Map(), budgets: new Map() };
53
+ const last = h.actGate.players.get(playerId) ?? { show: null, reasons: [] };
54
+ if (last.show === report.show && last.reasons.join(',') === report.reasons.join(',')) {return;}
55
+ h.actGate.players.set(playerId, report);
56
+ const key = who ?? 'guest';
57
+ const budgetKey = who ?? `guest:${playerId}`;
58
+ let budget = h.actGate.budgets.get(budgetKey);
59
+ if (!budget) {
60
+ budget = { windowAt: now, count: 0, suppressed: 0, lines: 0, muted: false, flushedAt: null };
61
+ h.actGate.budgets.set(budgetKey, budget);
62
+ }
63
+ if (now - budget.windowAt >= MINUTE_MS) {
64
+ // One summary a window: none if a leave already printed this one's.
65
+ if (budget.suppressed > 0 && budget.flushedAt !== budget.windowAt) {emit(budget, key, `[hub] act-gate ${key} suppressed=${budget.suppressed} t=${now}`, now, log);}
66
+ budget.windowAt = now; budget.count = 0; budget.suppressed = 0;
67
+ }
68
+ if (budget.count >= PER_MINUTE) {budget.suppressed++; return;}
69
+ budget.count++;
70
+ emit(budget, key, `[hub] act-gate ${key} ${label(last.show)}->${label(report.show)} reasons=${report.reasons.join(',') || '-'} t=${now}`, now, log);
71
+ }
72
+
73
+ // A visit's end also prints the count its minute held back, once a minute:
74
+ // leaving and rejoining does not buy more lines.
75
+ export function forget(h, playerId, who, now = Date.now(), log = console.log) {
76
+ if (!h.actGate?.players.delete(playerId)) {return;}
77
+ const key = who ?? 'guest';
78
+ const budget = h.actGate.budgets.get(who ?? `guest:${playerId}`);
79
+ if (!budget?.suppressed || budget.flushedAt === budget.windowAt) {return;}
80
+ budget.flushedAt = budget.windowAt;
81
+ emit(budget, key, `[hub] act-gate ${key} suppressed=${budget.suppressed} t=${now}`, now, log);
82
+ budget.suppressed = 0;
83
+ }
@@ -1,32 +1,38 @@
1
1
  // Action chips (contract v1.74): private offers; the place's hook alone
2
2
  // decides what a press does. No state exists in a place without `actions`.
3
3
  import { REFUSED_TEXT as DIRECTIONS } from '../privateText.js';
4
+ import { warnOnce } from './actors.js';
5
+ import * as Held from './heldOffers.js';
4
6
 
5
7
  const ID = /^[a-z][a-z0-9_-]{0,23}$/;
6
8
  const SEND_EVERY_MS = 250;
7
9
  const object = (value) => value !== null && typeof value === 'object' && [Object.prototype, null].includes(Object.getPrototypeOf(value));
8
10
  const id = (value) => typeof value === 'string' && ID.exec(value)?.[0] === value;
9
11
 
10
- function need(condition, message) {
12
+ function need(condition, message, at = '') {
11
13
  if (!condition) {
12
- throw new TypeError(`hub.actions: ${message}`);
14
+ throw Object.assign(new TypeError(`hub.actions: ${message}`), { rule: message, at });
13
15
  }
14
16
  }
17
+ // Where in the list a rule failed, for the log: an item's id as it was read
18
+ // (never read again: a getter runs once), or its place when it has none yet.
19
+ const shown = (value) => typeof value === 'string' ? JSON.stringify(value.slice(0, 32)) : typeof value;
15
20
  function check(items) {
16
21
  if (items === null) {
17
22
  return null;
18
23
  }
19
24
  need(Array.isArray(items) && items.length <= 3, 'items must be null or an array of 0..3 items');
20
- const out = Array.from(items, (item) => {
21
- need(object(item), 'item must be a plain object');
22
- need(Reflect.ownKeys(item).every((key) => ['id', 'label'].includes(key)), 'item has an unknown key');
23
- need(Object.hasOwn(item, 'id') && Object.hasOwn(item, 'label'), 'id and label must be own properties');
25
+ const out = Array.from(items, (item, i) => {
26
+ need(object(item), 'item must be a plain object', `item ${i}`);
27
+ need(Reflect.ownKeys(item).every((key) => ['id', 'label'].includes(key)), 'item has an unknown key', `item ${i}`);
28
+ need(Object.hasOwn(item, 'id') && Object.hasOwn(item, 'label'), 'id and label must be own properties', `item ${i}`);
24
29
  const itemId = item.id, label = item.label;
25
- need(id(itemId), 'id must be a short id');
26
- need(typeof label === 'string' && label.length <= 32 && label.trim().length > 0 && Array.from(label).length <= 16 && !DIRECTIONS.test(label), 'label must be 1..16 characters (code points), no control, direction or zero-width characters');
30
+ need(id(itemId), 'id must be a short id', `id ${shown(itemId)}`);
31
+ need(typeof label === 'string' && label.length <= 32 && label.trim().length > 0 && Array.from(label).length <= 16 && !DIRECTIONS.test(label), 'label must be 1..16 characters (code points), no control, direction or zero-width characters', `id ${shown(itemId)}`);
27
32
  return { id: itemId, label };
28
33
  });
29
- need(new Set(out.map((item) => item.id)).size === out.length, 'ids must be unique');
34
+ const repeated = out.find((item, i) => out.findIndex((other) => other.id === item.id) !== i);
35
+ need(!repeated, 'ids must be unique', `id ${shown(repeated?.id)}`);
30
36
  return out.length ? out : null;
31
37
  }
32
38
  function present(h, playerId) {
@@ -57,22 +63,38 @@ function version(h) {
57
63
  return h.actionsSeq;
58
64
  }
59
65
 
66
+ // A refused list still throws, as it always did; the place's log also says
67
+ // once which rule refused it and at what, as a deck that catches the throw
68
+ // would otherwise refuse every player's list with no word.
60
69
  export function set(h, playerId, items) {
61
- need(h.place.actions === true, 'this place does not declare actions');
62
- need(typeof playerId === 'string', 'playerId must be a string');
63
- const checked = check(items);
64
- if (!arrived(h, playerId)) {
70
+ let checked;
71
+ try {
72
+ need(h.place.actions === true, 'this place does not declare actions');
73
+ need(typeof playerId === 'string', 'playerId must be a string');
74
+ checked = check(items);
75
+ } catch (error) {
76
+ if (error?.rule) {
77
+ warnOnce(h, `actions:refused:${error.rule}`, `hub.actions refused a list: ${error.rule}${error.at ? ` (${error.at})` : ''}`);
78
+ }
79
+ throw error;
80
+ }
81
+ // v1.180: a held visit away takes the call, recorded unsent.
82
+ const held = Held.on(h) ? Held.take(h, playerId) : null;
83
+ if (held === 'block' || (!held?.away && !arrived(h, playerId))) {
65
84
  return false;
66
85
  }
86
+ if (held && Held.gate(h, playerId, h.actionsMe?.get(playerId)) === 'drop') {
87
+ h.actionsMe.delete(playerId);
88
+ }
67
89
  const state = current(h, playerId), json = JSON.stringify(checked);
68
- if (state.json === json) {
90
+ if (state.json === json && state.hold === held?.hold) {
69
91
  return true;
70
92
  }
71
93
  // Record every changed list; the tick sends only the latest, at most 4/s.
72
94
  // Back to the list the player was last sent, with nothing sent since: that
73
95
  // offer and its version stand (the client never heard of the ones between).
74
96
  const n = json === state.sentJson ? state.sentN : version(h);
75
- (h.actionsMe ??= new Map()).set(playerId, { ...state, items: checked, json, n });
97
+ (h.actionsMe ??= new Map()).set(playerId, { ...state, items: checked, json, n, ...(held ? { hold: held.hold } : {}) });
76
98
  return true;
77
99
  }
78
100
 
@@ -95,6 +117,16 @@ export function message(h, playerId, data) {
95
117
  return;
96
118
  }
97
119
  const actionId = data.id, n = data.n, state = current(h, playerId);
120
+ // v1.180: a held offer is pressed only by its own account, back on the
121
+ // visit's body and replayed to by a fresh hello.
122
+ const held = Held.on(h) ? Held.gate(h, playerId, h.actionsMe?.get(playerId)) : null;
123
+ if (held === 'drop' || held === 'block') {
124
+ h.actionsMe?.delete(playerId);
125
+ return;
126
+ }
127
+ if (held === 'away') {
128
+ return;
129
+ }
98
130
  // The offer in force is the one this player was sent: a list recorded and
99
131
  // not yet sent cannot be pressed, however its version was guessed.
100
132
  if (!id(actionId) || !Number.isSafeInteger(n) || n !== state.n || n !== state.sentN || !state.items?.some((item) => item.id === actionId)) {
@@ -106,14 +138,29 @@ export function message(h, playerId, data) {
106
138
  console.warn(`[hub] action hook failed: ${error?.message ?? error}`);
107
139
  }
108
140
  };
141
+ // v1.169: an end the hook makes before it returns is the player's own door.
142
+ h.acting = { playerId, id: actionId };
109
143
  try {
110
144
  Promise.resolve(h.hooks.action?.(h.ctx, playerId, actionId)).catch(failed);
111
145
  } catch (error) {
112
146
  failed(error);
147
+ } finally {
148
+ h.acting = null;
113
149
  }
114
150
  }
115
151
 
116
152
  export function joinedAfresh(h, playerId) {
153
+ if (Held.on(h)) {
154
+ const held = Held.gate(h, playerId, h.actionsMe?.get(playerId));
155
+ if (held === 'drop' || held === 'block') {
156
+ h.actionsMe?.delete(playerId);
157
+ } else if (held === 'away') {
158
+ return;
159
+ } else if (held === 'here' && h.actionsMe?.has(playerId)) {
160
+ // v1.180: a replay is a new offer; presses on the old version are refused.
161
+ h.actionsMe.get(playerId).n = version(h);
162
+ }
163
+ }
117
164
  const state = current(h, playerId);
118
165
  (h.actionsMe ??= new Map()).set(playerId, state);
119
166
  send(h, playerId, state);
@@ -124,6 +171,15 @@ export function forget(h, playerId) {
124
171
  }
125
172
  export function prune(h) {
126
173
  for (const playerId of new Set([...(h.actionsMe?.keys() ?? []), ...(h.actionsBudget?.keys() ?? [])])) {
174
+ const held = Held.on(h) ? Held.gate(h, playerId, h.actionsMe?.get(playerId)) : null;
175
+ if (held === 'drop' || held === 'block') {
176
+ forget(h, playerId);
177
+ continue;
178
+ }
179
+ if (held === 'away') {
180
+ h.actionsBudget?.delete(playerId);
181
+ continue;
182
+ }
127
183
  if (!present(h, playerId)) {
128
184
  forget(h, playerId);
129
185
  continue;