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
@@ -429,8 +429,49 @@ for (const options of [{ enabled: false }, { gpu: 'Mali-G52 MC3' }]) {
429
429
  assert.equal(h.ratio(), 1.25);
430
430
  assert.equal(h.scene.three.composer._pixelRatio, 1.75);
431
431
  }
432
+ // A game through a door wakes the town and returns its files, but keeps the
433
+ // profile's buffers until High or the town again.
434
+ {
435
+ const h = middleFixture();
436
+ h.frame();
437
+ assert.equal(h.ratio(), 1);
438
+ h.scene.content = {};
439
+ h.frame(1);
440
+ assert.equal(h.system.weakestTier.active, false);
441
+ assert.equal(h.system.weakestTier.capped, true);
442
+ assert.equal(h.ratio(), 1, 'the door game keeps Middle\'s halved buffers');
443
+ assert.equal(h.scene.three.composer._pixelRatio, 1);
444
+ assert.equal(h.scene.getActors().length, h.scene.actors.size);
445
+ assert.equal(h.scene.files, h.files);
446
+ h.frame(2);
447
+ assert.equal(h.ratio(), 1, 'repeated door frames never halve again');
448
+ h.system.tiers.set('high');
449
+ h.frame(3);
450
+ assert.equal(h.system.weakestTier.capped, false);
451
+ assert.equal(h.ratio(), 2, 'High in a door game puts the buffers back');
452
+ assert.equal(h.scene.three.composer._pixelRatio, 2);
453
+ h.system.tiers.set('auto');
454
+ h.frame(4);
455
+ assert.equal(h.ratio(), 1, 'Low again in the door game caps again');
456
+ delete h.scene.content;
457
+ h.frame(5);
458
+ assert.equal(h.ratio(), 1, 'back in the town the district cap holds');
459
+ assert.equal(h.scene.isActorSleeping(h.right), true);
460
+ h.system.weakestTier.restore();
461
+ assert.equal(h.ratio(), 2);
462
+ }
463
+ {
464
+ const h = middleFixture({ gpu: 'PowerVR Rogue GE8320', composerRatio: 1.75 });
465
+ h.setRatio(1.75);
466
+ h.scene.content = {};
467
+ h.frame();
468
+ assert.equal(h.system.tiers.weakest(), true);
469
+ assert.equal(h.ratio(), 0.5, 'a door game entered first still gets the Weakest cap');
470
+ assert.equal(h.scene.three.composer._pixelRatio, 0.5);
471
+ h.system.weakestTier.restore();
472
+ assert.equal(h.ratio(), 1.75);
473
+ }
432
474
  for (const leave of [
433
- (h) => { h.scene.content = {}; },
434
475
  (h) => { h.scene.requestedScene = 'scenes/door.scene'; },
435
476
  (h) => { h.player.components.Transform.x = 40; },
436
477
  (h) => { h.scene.data = { ...h.scene.data, weakestDistricts: { version: 99 } }; },
@@ -468,6 +509,39 @@ for (const profile of ['middle', 'weakest']) {
468
509
  assert.equal(h.scene.getActors().length, h.scene.actors.size);
469
510
  }
470
511
 
512
+ // A walking resident across the line stays drawn within 20 m and holds to
513
+ // 22 m once awake; one at its authored spot, or a moved prop, follows the
514
+ // district rule. The player stands at x -10 in 'left'.
515
+ for (const profile of ['middle', 'weakest']) {
516
+ const h = fixture(), controller = makeWeakestTier({ profile });
517
+ h.scene.data.weakestDistricts = { ...spec, actors: [...spec.actors] };
518
+ // The stander's authored spot is 19 m away across the line.
519
+ for (const [id, components, x] of [['walker', { HubNpc: {} }, 15], ['stander', { HubNpc: {} }, 9], ['prop', {}, 15]]) {
520
+ h.scene.spawnActor({ id, components: { Transform: { x, y: 0, z: 0 }, ...components } });
521
+ h.scene.data.weakestDistricts.actors.push({ id, districts: ['right'], origin: [x, 0], bounds: [x, 0, x, 0] });
522
+ }
523
+ const at = (id, x) => { h.scene.getActor(id).components.Transform.x = x; };
524
+ const asleep = (id) => h.scene.isActorSleeping(h.scene.getActor(id));
525
+ at('walker', 9.9); at('prop', 9.9);
526
+ controller.frame(h.scene, true, 0);
527
+ assert.equal(asleep('walker'), false, `${profile}: walker 19.9 m away across the line`);
528
+ assert.equal(asleep('stander'), true, `${profile}: resident at its spot follows the district`);
529
+ assert.equal(asleep('prop'), true, `${profile}: a moved non-resident follows the district`);
530
+ at('walker', 11.9);
531
+ controller.frame(h.scene, true, 200);
532
+ assert.equal(asleep('walker'), false, `${profile}: awake walker holds to 22 m`);
533
+ at('walker', 12.1);
534
+ controller.frame(h.scene, true, 400);
535
+ assert.equal(asleep('walker'), true, `${profile}: walker past 22 m sleeps`);
536
+ at('walker', 10.1);
537
+ controller.frame(h.scene, true, 600);
538
+ assert.equal(asleep('walker'), true, `${profile}: asleep walker wakes only inside 20 m`);
539
+ at('walker', 9.9);
540
+ controller.frame(h.scene, true, 800);
541
+ assert.equal(asleep('walker'), false, `${profile}: walker back inside 20 m wakes`);
542
+ controller.restore();
543
+ }
544
+
471
545
  // Run the actual goal/label collection and chrome.setPointers pass. Current
472
546
  // target NPCs wake even when a new label arrives inside the 100 ms sleep tick.
473
547
  const labelStart = hubSource.indexOf(' for (const [id, label] of Object.entries');
@@ -922,3 +996,63 @@ console.log('bounded Weakest look: self/accessory/distance ordering, real drain
922
996
  assert.equal(calls, 2);
923
997
  }
924
998
  }
999
+
1000
+ // Both profiles prepare sleeping templates after the join grace period, even
1001
+ // between district checks; completion stays idle until sleepers/assets change.
1002
+ for (const profile of ['middle', 'weakest']) {
1003
+ const h = fixture(), controller = makeWeakestTier({ profile });
1004
+ const text = JSON.stringify({ format: 'pxmodel', parts: [
1005
+ { id: 'box', kind: 'box', size: [1, 1, 1], color: '#778899' },
1006
+ ] });
1007
+ h.scene.files['models/prewarm.pxmodel'] = text;
1008
+ h.right.components.Model = { file: 'models/prewarm.pxmodel' };
1009
+ const engine = await import('@imports/castle.physics-3d/engine3d/world3d');
1010
+ h.scene.three = { models: new Map(), camera: { position: { x: -10, z: 0 } },
1011
+ prewarmSleepingModels(runtime, options) { return engine.prewarmSleepingModels(this, runtime, options); },
1012
+ needsSleepingModelPrewarm(runtime) { return engine.needsSleepingModelPrewarm(this, runtime); } };
1013
+ controller.frame(h.scene, true, 0);
1014
+ assert.equal(h.scene.isActorSleeping(h.right), true);
1015
+ controller.frame(h.scene, true, 14999);
1016
+ assert.equal(h.scene.three.models.size, 0, `${profile}: join grace period`);
1017
+ controller.frame(h.scene, true, 15000);
1018
+ assert.equal(h.scene.three.models.size, 1, `${profile}: prewarm between district checks`);
1019
+ const state = h.scene.three.sleepingModelPrewarm;
1020
+ const template = [...h.scene.three.models.values()][0];
1021
+ assert.equal(template.users, 0);
1022
+ // A build may consume the first slice before the remaining non-model
1023
+ // sleeper is visited; an active queue takes its next slice one step later.
1024
+ controller.frame(h.scene, true, 15100);
1025
+ assert.equal(state.done, true, `${profile}: active queue finishes on the next step`);
1026
+ const getActor = h.scene.getActor.bind(h.scene);
1027
+ let lookups = 0;
1028
+ h.scene.getActor = (id) => { lookups++; return getActor(id); };
1029
+ h.scene.files['models/prewarm.pxmodel'] += '\n';
1030
+ // Weakest's single build finished on the first step (idle check due at 15250),
1031
+ // Middle's on the second (15350): frames before either scan nothing.
1032
+ for (let at = 15101; at < 15250; at++) controller.frame(h.scene, true, at);
1033
+ assert.equal(lookups, 0, `${profile}: completed frames skip sleeper scans until the idle check`);
1034
+ assert.equal(h.scene.three.sleepingModelPrewarm, state, `${profile}: done state stays idle`);
1035
+ controller.frame(h.scene, true, 15351);
1036
+ assert.equal(h.scene.three.models.size, 2, `${profile}: asset edit resumes and defers pruning until renderer sync`);
1037
+ assert.ok([...h.scene.three.models.values()].some(entry => entry !== template));
1038
+ const refreshed = h.scene.three.sleepingModelPrewarm;
1039
+ h.left.components.Model = { file: 'models/prewarm.pxmodel' };
1040
+ h.player.components.Transform.x = 12;
1041
+ controller.frame(h.scene, true, 15400);
1042
+ assert.equal(h.scene.isActorSleeping(h.left), true);
1043
+ controller.frame(h.scene, true, 15601);
1044
+ assert.notEqual(h.scene.three.sleepingModelPrewarm, refreshed, `${profile}: sleep-set change resumes within 250 ms`);
1045
+ controller.restore();
1046
+ assert.equal(h.scene.sleepingActorCount, 0);
1047
+ }
1048
+ {
1049
+ const h = fixture(), controller = makeWeakestTier({ profile: 'middle' });
1050
+ h.right.components.Model = { file: 'models/prewarm.pxmodel' };
1051
+ h.scene.files['models/prewarm.pxmodel'] = JSON.stringify({ format: 'pxmodel', parts: [{ id: 'box', kind: 'box', size: [1, 1, 1] }] });
1052
+ h.scene.three = { models: new Map(), camera: { position: { x: -10, z: 0 } } };
1053
+ controller.frame(h.scene, true, 0);
1054
+ for (let at = 15000; at < 15500; at += 50) controller.frame(h.scene, true, at);
1055
+ assert.equal(h.scene.three.models.size, 0, 'an engine without the prewarm methods builds nothing');
1056
+ controller.restore();
1057
+ }
1058
+ console.log('sleeping model prewarm: Middle/Weakest 15 s grace period, 100 ms step cadence, 250 ms idle checks, asset/sleep invalidation and an older engine passed');
@@ -155,6 +155,111 @@ console.log('world labels: bounded nearest tags, objective precedence, HUD/colum
155
155
  console.log('world labels: snapshot caption reflow, shift/hide retention, repeated flush and restored-width clearance passed');
156
156
  }
157
157
 
158
+ // An unchanged caption keeps its reflow across frames: no style writes but
159
+ // its own shift, no late reads, and every frame (and every reader between
160
+ // the frame-start reset and the flush) matches the restore-and-search path.
161
+ {
162
+ const scene = { w: 844, h: 390, text: 'x'.repeat(60), left: box(0, 0, 324, 390), right: box(520, 0, 324, 390), menu: false, layer: 'wide' };
163
+ // Stand-ins for CSS outside the caption: its layer's class and a sheet's rules.
164
+ const natural = () => scene.layer === 'narrow' || globalThis.document?.styleSheets?.[0]?.cssRules.length > 1 ? 700 : scene.w;
165
+ const view = () => ({ w: scene.w, h: scene.h });
166
+ const at = (geometry) => ({ style: {}, getBoundingClientRect: () => ({ ...geometry(), width: geometry().right - geometry().left, height: geometry().bottom - geometry().top }) });
167
+ const build = (keep) => {
168
+ const counts = { reads: 0, writes: [] };
169
+ const style = new Proxy({ width: '', right: '0', translate: '' }, { set(target, key, value) {counts.writes.push(key); target[key] = value; return true;} });
170
+ const parent = { style: {}, get className() {return scene.layer;}, getAttributeNames: () => ['class'], getAttribute: () => scene.layer };
171
+ const caption = { style, parentElement: parent, textContent: scene.text, getBoundingClientRect() {
172
+ counts.reads++;
173
+ const width = Number.parseFloat(style.width) || natural();
174
+ const height = Math.min(Math.ceil(caption.textContent.length * 8 / width) * 21, Number.parseFloat(style.maxHeight) || Infinity);
175
+ const [dx, dy] = (style.translate || '0 0').split(' ').map(Number.parseFloat);
176
+ return { ...box((Number.parseFloat(style.left) || 0) + dx, 340 + dy, width, height), width, height };
177
+ } };
178
+ const labels = [node(box(200, 350, 60, 20)), node(box(380, 200, 60, 20)), node(box(400, 120, 60, 20))];
179
+ const menu = at(() => box(330, 10, 180, 40));
180
+ const surfaces = () => [{ id: 'hud-prompt', kind: 'text', node: caption },
181
+ { kind: 'control', node: at(() => scene.left) }, { kind: 'control', node: at(() => scene.right) },
182
+ ...(scene.menu ? [{ id: 'menu', kind: 'card', node: menu }] : []), ...labels.map((label) => ({ kind: 'label', node: label }))];
183
+ const geometry = makeLayoutCache();
184
+ const pass = makeWorldLayout(surfaces, view, () => [], geometry);
185
+ return { caption, counts, labels, geometry, pass, surfaces, frame(between = () => {}, late = false) {
186
+ geometry.beginFrame(surfaces().map((entry) => entry.node));
187
+ counts.reads = 0; counts.writes = [];
188
+ pass.begin(keep);
189
+ between(caption);
190
+ const reader = geometry.rect(caption);
191
+ pass.flush();
192
+ if (late) {pass.flush();}
193
+ geometry.endFrame();
194
+ return { reader: { left: reader.left, right: reader.right, top: reader.top, bottom: reader.bottom },
195
+ caption: JSON.stringify(caption.style), labels: labels.map((label) => [label.style.visibility, label.style.translate]) };
196
+ } };
197
+ };
198
+ const kept = build(true), today = build(false);
199
+ const frame = (label, between, late) => {
200
+ const result = kept.frame(between, late);
201
+ assert.deepEqual(result, today.frame(between, late), `${label}: matches the restore-and-search path`);
202
+ return result;
203
+ };
204
+ const first = frame('first frame');
205
+ assert.equal(kept.caption.style.width, '180px', 'caption reflows into the gap');
206
+ assert(kept.caption.style.translate, 'and shifts into its slot');
207
+ for (let i = 0; i < 3; i++) {
208
+ assert.deepEqual(frame(`steady frame ${i}`), first, 'nothing changed, nothing moves');
209
+ assert.equal(kept.counts.reads, 0, 'no late caption reads while nothing changed');
210
+ assert.deepEqual(kept.counts.writes, ['translate', 'translate'], 'only the shift is reset and rewritten');
211
+ assert(today.counts.reads > 0 && today.counts.writes.includes('width'), 'the restore path re-runs the search');
212
+ }
213
+ const full = (label) => {
214
+ assert(kept.counts.reads > 0 && kept.counts.writes.includes('width'), `${label}: runs the full search`);
215
+ frame(`${label}, settled`);
216
+ assert.equal(kept.counts.reads, 0, `${label}: kept again once settled`);
217
+ };
218
+ scene.text = 'x'.repeat(30); kept.caption.textContent = today.caption.textContent = scene.text;
219
+ frame('caption text'); full('caption text');
220
+ scene.right = box(540, 0, 304, 390); frame('a control moves'); full('a control moves');
221
+ scene.w = 900; frame('viewport size'); full('viewport size');
222
+ scene.menu = true; frame('a menu appears'); full('a menu appears');
223
+ scene.menu = false; frame('the menu closes'); full('the menu closes');
224
+ kept.caption.style.width = today.caption.style.width = '260px';
225
+ frame('another writer sets the width'); full('another writer sets the width');
226
+ // Copy changed between the reset and the flush: the reader already sees
227
+ // the restored caption, exactly as after a restore.
228
+ frame('copy changed mid-frame', (caption) => {caption.textContent = 'x'.repeat(90);});
229
+ full('copy changed mid-frame');
230
+ // A late flush in the same frame (crowd names) keeps it too.
231
+ assert.deepEqual(frame('late flush', undefined, true), frame('after a late flush'));
232
+ frame('late flush again', undefined, true);
233
+ assert.equal(kept.counts.reads, 0, 'a late flush keeps the unchanged reflow');
234
+ // A frame-start reset with no flush before the frame ends leaves the
235
+ // caption restored, as the plain reset does.
236
+ for (const twin of [kept, today]) {
237
+ twin.geometry.beginFrame(twin.surfaces().map((entry) => entry.node));
238
+ twin.pass.begin(twin === kept);
239
+ twin.geometry.endFrame();
240
+ }
241
+ assert.equal(JSON.stringify(kept.caption.style), JSON.stringify(today.caption.style), 'reset without a flush restores the caption');
242
+ assert.equal(kept.caption.style.width, '', 'to its own width');
243
+ frame('after a reset without a flush'); full('after a reset without a flush');
244
+ // CSS outside the caption can resize its natural box while its reflowed
245
+ // box stays put: an ancestor's class, before the frame or mid-frame.
246
+ scene.layer = 'narrow'; assert.equal(frame('layer class').reader.right, 700); full('layer class');
247
+ frame('layer class mid-frame', () => {scene.layer = 'wide';}); full('layer class mid-frame');
248
+ // A style sheet gaining rules.
249
+ const sheet = { cssRules: { length: 1 } };
250
+ globalThis.document.styleSheets = [sheet];
251
+ frame('style sheet added'); full('style sheet added');
252
+ sheet.cssRules.length = 2; assert.equal(frame('style sheet rules').reader.right, 700); full('style sheet rules');
253
+ delete globalThis.document.styleSheets;
254
+ frame('style sheet removed'); full('style sheet removed');
255
+ // Another writer's styles set after the frame-start reset survive the
256
+ // hold's release, as they survive the plain reset.
257
+ frame('width and left set mid-frame', (caption) => {Object.assign(caption.style, { width: '100px', left: '351px' });});
258
+ assert.equal(kept.caption.style.translate, today.caption.style.translate);
259
+ full('width and left set mid-frame');
260
+ console.log('world labels: unchanged caption reflow kept across frames; each changed input re-fits identically passed');
261
+ }
262
+
158
263
  // A caption measured wholly off-screen (the Life RP repro: "2 here" at y
159
264
  // 11702 in a 574x246 frame) is not slotted into a band labels must clear.
160
265
  // An on-screen caption still takes its band and collapses a label under it.
@@ -342,6 +447,38 @@ for (const focused of [true, false]) {
342
447
  chrome.flushWorldLabels(); assert.equal(summit.style.translate, shifted, 'avatar avoidance does not drift');
343
448
  chrome.setWorldAvatar(null); chrome.flushWorldLabels();
344
449
  assert.equal(summit.style.translate, '', 'pointer restores its anchor when avatar is absent');
450
+ // An NPC's line (Chirp's from the viewer's shoulder, which always crosses
451
+ // the viewer's own body box) is drawn over the viewer's body, as a role
452
+ // chip or mark is. A player's own speech still yields to the avatar.
453
+ chrome.setPointers([]);
454
+ chrome.setLabels([
455
+ { id: 'companion:line', x: 422, y: 200, text: 'Fish with me on the pier?', speech: true, npc: true },
456
+ { id: 'rowan', x: 460, y: 260, text: 'Rowan: hello', speech: true, npc: true },
457
+ { id: 'said:p2', x: 300, y: 300, text: 'hi all', speech: true },
458
+ ]);
459
+ const chirp = dom.made.find((element) => element.textContent === 'Fish with me on the pier?');
460
+ const rowan = dom.made.find((element) => element.textContent === 'Rowan: hello');
461
+ const said = dom.made.find((element) => element.textContent === 'hi all');
462
+ rowan.rect = box(400, 234, 120, 26);
463
+ said.rect = box(340, 274, 60, 26);
464
+ // Chirp's bubble and the viewer's body box as the Town projects them at
465
+ // orbit 6, 12 and 16 m, with the shortest and tallest avatars.
466
+ for (const [bubble, body] of [
467
+ [{ left: 225, top: 177, right: 546, bottom: 203 }, { left: 363, top: 153, right: 481, bottom: 321 }],
468
+ [{ left: 244, top: 177, right: 565, bottom: 203 }, { left: 390, top: 167, right: 454, bottom: 253 }],
469
+ [{ left: 248, top: 175, right: 569, bottom: 201 }, { left: 396, top: 166, right: 448, bottom: 239 }],
470
+ ]) {
471
+ chirp.rect = { ...bubble, x: bubble.left, y: bubble.top, width: bubble.right - bubble.left, height: bubble.bottom - bubble.top };
472
+ chrome.setWorldAvatar(body);
473
+ chrome.flushWorldLabels();
474
+ assert.equal(chirp.style.visibility, '', "Chirp's line is drawn over the viewer's own body");
475
+ }
476
+ chrome.setWorldAvatar(box(380, 160, 90, 120));
477
+ chrome.flushWorldLabels();
478
+ assert.equal(rowan.style.visibility, '', "an NPC's line is drawn over the viewer's own body");
479
+ assert.equal(said.style.visibility, 'hidden', "a player's speech over the body still yields");
480
+ chrome.setWorldAvatar(null); chrome.flushWorldLabels();
481
+ assert.equal(said.style.visibility, '', 'that speech returns when the avatar is absent');
345
482
  chrome.dispose();
346
483
  }
347
484
 
@@ -405,3 +542,206 @@ for (const focused of [true, false]) {
405
542
  globalThis.getComputedStyle = previous;
406
543
  }
407
544
  }
545
+
546
+ // Town frames at 844x390 from Oct 14 (before the Town placed labels with
547
+ // this rule): a returning greeting running off the left edge over People
548
+ // and Chat, a barker line over the same dock, and the benches chip under
549
+ // Invite a friend. Each line is collapsed and the chip moved clear.
550
+ {
551
+ const view = { w: 844, h: 390, insets: { top: 0, right: 0, bottom: 0, left: 0 } };
552
+ const rect = (left, top, right, bottom) => ({ left, top, right, bottom });
553
+ const dock = [rect(10, 74.5, 110.3, 112), rect(116.3, 68, 160.3, 112)];
554
+ const invite = rect(688.6, 86.5, 832, 130.5);
555
+ const greeting = rect(-68.8, 71.4, 330.2, 96.3);
556
+ const barker = rect(82.6, 77.3, 530.4, 102.2);
557
+ const benches = rect(650.8, 113.2, 766, 131.5);
558
+ const { pointers, labels } = worldPlacement([benches], [greeting, barker], [...dock, invite], view);
559
+ assert.deepEqual(labels, [null, null], 'speech under the dock, or off the view, is not drawn');
560
+ assert(pointers[0], 'the route chip is still shown');
561
+ for (const control of [...dock, invite]) {
562
+ assert(!(pointers[0].left < control.right && pointers[0].right > control.left && pointers[0].top < control.bottom && pointers[0].bottom > control.top), 'the route chip is clear of the controls');
563
+ }
564
+ assert(pointers[0].left >= 6 && pointers[0].right <= view.w - 6, 'the route chip stays on screen');
565
+ // The greeting's left end off the view, with no control under it.
566
+ const offView = rect(-68.8, 200, 330.2, 224.9);
567
+ assert.deepEqual(worldPlacement([], [offView], [], view).labels, [null], 'a line running off the left edge is not drawn');
568
+ assert.deepEqual(worldPlacement([], [rect(10, 200, 408, 224.9)], [], view).labels, [rect(10, 200, 408, 224.9)], 'the same line on screen is');
569
+ }
570
+
571
+ // A plate or a sign (`clamp`) is slid onto the screen while its anchor is on
572
+ // it, and steps off the player's own avatar, rather than being dropped
573
+ // (Weekend Cup statues, Oct 17: `#2` over the avatar drew nothing). A control
574
+ // under it still drops it, and a speech line keeps the old rule.
575
+ {
576
+ const view = { w: 412, h: 870, insets: { top: 0, right: 0, bottom: 0, left: 0 } };
577
+ const rect = (left, top, right, bottom, extra = {}) => ({ left, top, right, bottom, ...extra });
578
+ const avatar = rect(170, 300, 250, 420);
579
+ const plate = rect(140, 314, 300, 340, { clamp: true });
580
+ const [over] = worldPlacement([], [plate], [avatar], view, [avatar]).labels;
581
+ assert(over, 'a plate over the avatar is drawn');
582
+ assert(!(over.left < avatar.right && over.right > avatar.left && over.top < avatar.bottom && over.bottom > avatar.top), 'clear of the avatar');
583
+ assert.deepEqual([over.right - over.left, over.bottom - over.top], [160, 26], 'at its own size');
584
+ assert.equal(over.bottom, avatar.top - 8, 'just above the avatar, the nearest clear place');
585
+ assert.deepEqual(worldPlacement([], [rect(140, 314, 300, 340)], [avatar], view, [avatar]).labels, [null], 'a label without clamp is dropped as before');
586
+ const edge = rect(-40, 200, 120, 226, { clamp: true });
587
+ const [slid] = worldPlacement([], [edge], [], view).labels;
588
+ assert.deepEqual([slid.left, slid.top, slid.right], [6, 200, 166], 'a plate at the left edge slides on screen');
589
+ assert.deepEqual(worldPlacement([], [rect(-140, 200, 2, 226, { clamp: true })], [], view).labels, [null], 'one whose anchor is off screen is not drawn');
590
+ const control = rect(0, 180, 100, 240);
591
+ const [beside] = worldPlacement([], [edge], [control], view).labels;
592
+ assert(!beside || !(beside.left < control.right && beside.right > control.left && beside.top < control.bottom && beside.bottom > control.top), 'a slid plate never lands on a control');
593
+ assert.deepEqual(worldPlacement([], [rect(20, 190, 180, 216, { clamp: true })], [control], view).labels, [null], 'a plate under a control is still dropped');
594
+ }
595
+
596
+ // The moto e22 in the Castle app (build 213, Oct 14, 800x360 CSS): two edge
597
+ // chips for players off to the left were drawn on each other and over the
598
+ // Doors pill. Each is moved clear of the dock (People, the companion, Doors)
599
+ // and of the other, and stays on screen.
600
+ {
601
+ const view = { w: 800, h: 360, insets: { top: 0, right: 0, bottom: 0, left: 0 } };
602
+ const rect = (left, top, right, bottom) => ({ left, top, right, bottom });
603
+ const dock = rect(10, 60, 136, 132);
604
+ const right = [rect(669, 183, 789, 221), rect(752, 233, 788, 268), rect(752, 276, 788, 312), rect(707, 320, 788, 350)];
605
+ const { pointers } = worldPlacement([rect(5, 110, 106, 122), rect(5, 122, 139, 136)], [], [dock, ...right], view);
606
+ const hit = (a, b) => a.left < b.right && a.right > b.left && a.top < b.bottom && a.bottom > b.top;
607
+ assert(pointers.every(Boolean), 'both chips are shown');
608
+ for (const chip of pointers) {
609
+ assert(![dock, ...right].some((control) => hit(chip, control)), 'a chip is clear of the dock and the controls');
610
+ assert(chip.left >= 6 && chip.right <= view.w - 6 && chip.top >= 6 && chip.bottom <= view.h - 6, 'a chip stays on screen');
611
+ }
612
+ assert(!hit(pointers[0], pointers[1]), 'the two chips do not stack');
613
+ const [house] = worldPlacement([rect(5, 100, 120, 124)], [], [dock, ...right], view).pointers;
614
+ assert(house && !hit(house, dock), "'your house' clears the Doors pill");
615
+ }
616
+
617
+ // Chirp's line pinned to the screen edge (QA build, Oct 30, 404 px wide: hidden
618
+ // at l6 and at r398, drawn once it moved in). setLabels pins an NPC's line 6 px
619
+ // from the edge, so a sub-pixel past it, or under a tighter world canvas, it is
620
+ // slid on rather than dropped. An NPC line under a control steps clear of it
621
+ // (never around the avatar), a player's own line at the edge is still
622
+ // dropped, and a pointer chip is placed as before.
623
+ {
624
+ const { fakeDom } = await import('./fixtures/fake-dom.mjs');
625
+ const { makeChrome } = await import('../code/client/chrome.js');
626
+ const dom = fakeDom({ viewW: 404, viewH: 870 });
627
+ const chrome = makeChrome({ avatarCount: 4, onBack() {}, onAvatar() {}, worldLabelsDefault: true });
628
+ chrome.setLabels([
629
+ { id: 'companion:line', x: 160, y: 346, text: 'Fish with me on the pier?', speech: true, npc: true },
630
+ { id: 'said:p1', x: 300, y: 600, text: 'hi all', speech: true },
631
+ ]);
632
+ const chirp = dom.made.find((element) => element.textContent === 'Fish with me on the pier?');
633
+ const said = dom.made.find((element) => element.textContent === 'hi all');
634
+ const at = (node, left) => {node.rect = box(left, node === chirp ? 320 : 580, node === chirp ? 300 : 60);};
635
+ const drawn = (node) => {
636
+ const [dx = 0] = (node.style.translate || '0px').split(' ').map(Number.parseFloat);
637
+ return node.style.visibility === 'hidden' ? null : node.rect.left + dx;
638
+ };
639
+ chrome.setWorldAvatar(box(150, 300, 100, 150));
640
+ for (const [left, want] of [[5.6, 6], [404 - 6 + 0.4 - 300, 404 - 6 - 300]]) {
641
+ at(chirp, left); at(said, 200); chrome.flushWorldLabels();
642
+ assert.equal(drawn(chirp), want, "Chirp's line pinned a sub-pixel past the edge is slid on and drawn");
643
+ }
644
+ chrome.setWorldViewport({ left: 20, right: 384, top: 0, bottom: 870, width: 364, height: 870 });
645
+ for (const [left, want] of [[6, 20], [404 - 6 - 300, 384 - 300]]) {
646
+ at(chirp, left); chrome.flushWorldLabels();
647
+ assert.equal(drawn(chirp), want, 'and inside a narrower world canvas');
648
+ }
649
+ chrome.setWorldViewport(null);
650
+ at(said, 5.6); chrome.flushWorldLabels();
651
+ assert.equal(said.style.visibility, 'hidden', "a player's own line past the edge is still dropped");
652
+ const control = document.createElement('div');
653
+ control.rect = box(0, 310, 60, 50);
654
+ chrome.safeSurface('edge-control', control, 'control');
655
+ for (const left of [5.6, 40]) {
656
+ at(chirp, left); chrome.flushWorldLabels();
657
+ const [dx, dy] = chirp.style.translate.split(' ').map(Number.parseFloat);
658
+ assert.notEqual(chirp.style.visibility, 'hidden', "an NPC's line under a control is drawn");
659
+ assert.deepEqual([chirp.rect.left + dx, chirp.rect.bottom + dy], [Math.max(6, left), 302], 'just above the control, not beside the avatar');
660
+ }
661
+ // Walled in above and below, it is drawn as its first line alone, clipped,
662
+ // and whole again once there is room.
663
+ chirp.style.lineHeight = '16.9px'; chirp.style.paddingTop = '4px'; chirp.style.paddingBottom = '4px';
664
+ at(chirp, 5.6); chirp.rect = { ...chirp.rect, top: 300, bottom: 346 };
665
+ const roof = document.createElement('div'), floor = document.createElement('div');
666
+ roof.rect = box(0, 0, 404, 312); floor.rect = box(0, 346, 404, 524);
667
+ chrome.safeSurface('edge-roof', roof, 'card'); chrome.safeSurface('edge-floor', floor, 'card');
668
+ chrome.safeSurface('edge-control', null);
669
+ chrome.flushWorldLabels();
670
+ assert.notEqual(chirp.style.visibility, 'hidden', 'drawn in the one-line form');
671
+ assert.equal(chirp.style.clipPath, 'inset(0 0 25.1px 0 round 12px)', 'clipped at its first line\'s foot, so no second line shows');
672
+ const [, dy1] = chirp.style.translate.split(' ').map(Number.parseFloat);
673
+ assert.deepEqual([chirp.rect.top + dy1], [320], 'the line sits in the gap, 8 px under the card');
674
+ chrome.safeSurface('edge-roof', null); chrome.safeSurface('edge-floor', null);
675
+ chrome.flushWorldLabels();
676
+ assert.equal(chirp.style.clipPath, '', 'whole again when there is room');
677
+ chrome.dispose();
678
+ const view = { w: 404, h: 870, insets: { top: 0, right: 0, bottom: 0, left: 0 } };
679
+ const chip = box(5, 500);
680
+ const line = { ...box(5.6, 320, 300), edge: true };
681
+ assert.deepEqual(worldPlacement([chip], [line], [], view).pointers, worldPlacement([chip], [], [], view).pointers, 'a pointer chip is placed as before');
682
+ assert.deepEqual(worldPlacement([], [{ ...line, edge: false }], [], view).labels, [null], 'a line without edge keeps the old rule');
683
+ }
684
+
685
+ // Rowan's line in the Run 3 frame (#4726's offline harness, SAVE 28, 404x721):
686
+ // the edge slide puts it at 6,65.6-276.5,124.2, 20.7 px into his own "Talk to
687
+ // Rowan" prompt (8,104-216,148), and in landscape into the reserved back
688
+ // corner. It steps to the nearest clear slot instead of being hidden: above
689
+ // the prompt first, beside the corner, then below, then its first line alone.
690
+ {
691
+ const view = { w: 404, h: 721, insets: { top: 0, right: 0, bottom: 0, left: 0 } };
692
+ const rect = (left, top, right, bottom, extra = {}) => ({ left, top, right, bottom, ...extra });
693
+ const hit = (a, b) => a.left < b.right && a.right > b.left && a.top < b.bottom && a.bottom > b.top;
694
+ const talk = rect(8, 104, 216, 148);
695
+ const sign = rect(8, 152, 112, 178);
696
+ const sound = rect(352, 64, 392, 100);
697
+ const chips = rect(120, 172, 396, 216);
698
+ const corners = [rect(0, 0, 64, 56), rect(340, 0, 404, 56)];
699
+ const rowan = rect(5.77, 65.6, 276.24, 124.2, { edge: true, line: 24.9 });
700
+ const w = rowan.right - rowan.left, h = rowan.bottom - rowan.top;
701
+ // In a wider view the slot above the prompt, beside the back corner, is free.
702
+ const [above] = worldPlacement([], [rowan], [talk], { ...view, w: 500 }).labels;
703
+ assert(above && !above.line, "Rowan's line over his own Talk prompt is drawn whole");
704
+ assert.deepEqual([above.left, above.bottom], [64 + 8, talk.top - 8], 'above the prompt, beside the back corner');
705
+ assert.deepEqual([above.right - above.left, above.bottom - above.top], [w, h], 'at its own size');
706
+ // At 404 the two reserved corners leave no room above, so it goes below the prompt.
707
+ const [below] = worldPlacement([], [rowan], [talk], view).labels;
708
+ assert(below && !below.line && below.top === talk.bottom + 8, 'below the prompt when there is no room above');
709
+ for (const other of [talk, ...corners]) {assert(!hit(below, other), 'clear of the prompt and the corners');}
710
+ // The whole Run 3 frame (the Harbour sign, Sound, the Invite and Market
711
+ // chips): its first line alone, above the prompt.
712
+ const [first] = worldPlacement([], [rowan], [talk, sign, sound, chips], view).labels;
713
+ assert(first?.line, 'the one-line form');
714
+ assert.deepEqual([first.left, first.top, first.bottom], [6, talk.top - 8 - 24.9, talk.top - 8], 'one line tall, above the prompt');
715
+ for (const other of [talk, sign, sound, chips, ...corners]) {assert(!hit(first, other), 'one line clear of everything');}
716
+ assert.deepEqual(worldPlacement([], [{ ...rowan, line: null }], [talk, sign, sound, chips], view).labels, [null], 'no line height, no one-line form: hidden');
717
+ assert.deepEqual(worldPlacement([], [rowan], [rect(0, 0, 404, 721)], view).labels, [null], 'nothing clear: hidden');
718
+ // A control still hides a label without `edge`, and an anchor off the view still hides it.
719
+ assert.deepEqual(worldPlacement([], [rect(20, 65.6, 290, 124.2)], [talk], view).labels, [null], 'a sign under a control is still dropped');
720
+ assert.deepEqual(worldPlacement([], [rect(-300, 65.6, -30, 124.2, { edge: true })], [], view).labels, [null], 'an anchor off the view is the accepted limit');
721
+ // Landscape (TECNO 806x360, inset left 36): the slid line lands in the back corner (36,0-100,56).
722
+ const land = { w: 806, h: 360, insets: { top: 0, right: 0, bottom: 0, left: 36 } };
723
+ const line = rect(6.14, 20.3, 525.9, 62, { edge: true, line: 24.9 });
724
+ const [clearOfCorner] = worldPlacement([], [line], [], land).labels;
725
+ assert(clearOfCorner && !hit(clearOfCorner, rect(36, 0, 100, 56)), 'clear of the reserved back corner in landscape');
726
+ assert(clearOfCorner.left >= 36, 'inside the inset');
727
+ }
728
+
729
+ // The drawn width: a label's measure is its fractional box, not the
730
+ // whole-pixel offsetWidth, so labelBox's 6 px pin is where it is drawn.
731
+ {
732
+ const { fakeDom } = await import('./fixtures/fake-dom.mjs');
733
+ const { makeChrome } = await import('../code/client/chrome.js');
734
+ const { labelBox } = await import('../code/client/labelsNear.js');
735
+ const dom = fakeDom({ viewW: 404, viewH: 721 });
736
+ const chrome = makeChrome({ avatarCount: 4, onBack() {}, onAvatar() {}, worldLabelsDefault: true });
737
+ const text = 'Rowan, the greeter: welcome back to the harbour';
738
+ chrome.measureLabel(text, true, true);
739
+ const probe = dom.made.find((node) => node.textContent === text && node.style.left === '-10000px');
740
+ probe.size = { w: 270, h: 59 };
741
+ probe.rect = { left: 0, right: 270.47, top: 0, bottom: 58.6 };
742
+ const size = chrome.measureLabel(text, true, true);
743
+ assert.deepEqual([size.w, size.h], [270.47, 58.6], 'measured at the drawn, fractional size');
744
+ const placed = labelBox(-330, 124.2, size, true, { w: 404, h: 721 });
745
+ assert(Math.abs(placed.left - 6) < 1e-9 && Math.abs(placed.right - 276.47) < 1e-9, 'pinned at 6 px as drawn (not 5.765)');
746
+ chrome.dispose();
747
+ }