castle-web-cli 0.4.231 → 0.4.233

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 (368) hide show
  1. package/dist/agent-failures.d.ts +8 -0
  2. package/dist/agent-failures.js +19 -2
  3. package/dist/agent-prompts.d.ts +1 -1
  4. package/dist/agent-prompts.js +10 -3
  5. package/dist/agent.d.ts +64 -3
  6. package/dist/agent.js +170 -81
  7. package/dist/castle-host/host.d.ts +1 -0
  8. package/dist/castle-host/host.js +51 -3
  9. package/dist/castleJson.d.ts +4 -2
  10. package/dist/castleJson.js +2 -0
  11. package/dist/check.d.ts +3 -1
  12. package/dist/check.js +11 -1
  13. package/dist/devSessionStorage.js +47 -1
  14. package/dist/importPinMismatch.d.ts +22 -0
  15. package/dist/importPinMismatch.js +77 -0
  16. package/dist/importRegression.js +3 -15
  17. package/dist/imports.d.ts +10 -3
  18. package/dist/imports.js +88 -20
  19. package/dist/index.js +5 -4
  20. package/dist/init.js +1 -1
  21. package/dist/platformDoc.js +22 -0
  22. package/dist/routerFences.d.ts +5 -0
  23. package/dist/routerFences.js +12 -2
  24. package/dist/save-deck.d.ts +5 -0
  25. package/dist/save-deck.js +37 -4
  26. package/dist/serve.js +3 -0
  27. package/dist/serverBundle.js +5 -3
  28. package/dist/shell/assets/{index-D2tWM896.js → index-BjOxR-lW.js} +4 -4
  29. package/dist/shell/assets/index-MVLfNYd9.css +1 -0
  30. package/dist/shell/index.html +2 -2
  31. package/dist/taskSteer.d.ts +13 -0
  32. package/dist/taskSteer.js +22 -2
  33. package/kits/base/castle.json +1 -1
  34. package/kits/base/package-lock.json +1 -1
  35. package/kits/base/sdk/README.md +79 -2
  36. package/kits/base/sdk/avatar.d.ts +6 -2
  37. package/kits/base/sdk/avatar.js +12 -4
  38. package/kits/base/sdk/castle.d.ts +1 -1
  39. package/kits/base/sdk/commands.d.ts +14 -0
  40. package/kits/base/sdk/hub.d.ts +6 -2
  41. package/kits/base/sdk/hub.js +13 -0
  42. package/kits/base/sdk/multiplayer.js +17 -1
  43. package/kits/base/sdk/save.js +2 -1
  44. package/kits/base/sdk/server/hub.d.ts +87 -0
  45. package/kits/base/sdk/server/hub.js +70 -0
  46. package/kits/base/sdk/server/platformHandle.d.ts +31 -1
  47. package/kits/base/sdk/server/storage.d.ts +13 -0
  48. package/kits/base/sdk/server/storage.js +46 -0
  49. package/kits/base/sdk/server/wrapper.d.ts +36 -5
  50. package/kits/base/sdk/server/wrapper.js +83 -8
  51. package/kits/hub-game/CLAUDE.md +352 -12
  52. package/kits/hub-game/blueprints/avatar-10.scene +28 -0
  53. package/kits/hub-game/blueprints/avatar-11.scene +28 -0
  54. package/kits/hub-game/blueprints/avatar-12.scene +28 -0
  55. package/kits/hub-game/blueprints/avatar-13.scene +28 -0
  56. package/kits/hub-game/blueprints/avatar-14.scene +28 -0
  57. package/kits/hub-game/blueprints/avatar-15.scene +28 -0
  58. package/kits/hub-game/blueprints/avatar-4.scene +28 -0
  59. package/kits/hub-game/blueprints/avatar-5.scene +28 -0
  60. package/kits/hub-game/blueprints/avatar-6.scene +28 -0
  61. package/kits/hub-game/blueprints/avatar-7.scene +28 -0
  62. package/kits/hub-game/blueprints/avatar-8.scene +28 -0
  63. package/kits/hub-game/blueprints/avatar-9.scene +28 -0
  64. package/kits/hub-game/code/client/actorBudget.js +47 -0
  65. package/kits/hub-game/code/client/attention.js +11 -2
  66. package/kits/hub-game/code/client/avatar.js +345 -32
  67. package/kits/hub-game/code/client/avatarCap.js +228 -0
  68. package/kits/hub-game/code/client/avatarColors.js +70 -0
  69. package/kits/hub-game/code/client/avatarFaces.js +21 -0
  70. package/kits/hub-game/code/client/avatarShare.js +251 -0
  71. package/kits/hub-game/code/client/ballot.js +467 -0
  72. package/kits/hub-game/code/client/build.js +22 -0
  73. package/kits/hub-game/code/client/chat.js +12 -0
  74. package/kits/hub-game/code/client/chrome.js +1334 -50
  75. package/kits/hub-game/code/client/companion.js +716 -0
  76. package/kits/hub-game/code/client/companionDress.js +99 -0
  77. package/kits/hub-game/code/client/decor.js +509 -0
  78. package/kits/hub-game/code/client/earned.js +131 -0
  79. package/kits/hub-game/code/client/emoteBubble.js +75 -0
  80. package/kits/hub-game/code/client/grab.js +363 -20
  81. package/kits/hub-game/code/client/hats.js +26 -0
  82. package/kits/hub-game/code/client/hookLayer.js +328 -15
  83. package/kits/hub-game/code/client/hudClear.js +126 -0
  84. package/kits/hub-game/code/client/idle.js +163 -22
  85. package/kits/hub-game/code/client/interestCap.js +81 -0
  86. package/kits/hub-game/code/client/keys.js +36 -0
  87. package/kits/hub-game/code/client/labelsNear.js +205 -0
  88. package/kits/hub-game/code/client/menuIcons.js +34 -0
  89. package/kits/hub-game/code/client/pack.js +6 -2
  90. package/kits/hub-game/code/client/packFormat.js +3 -3
  91. package/kits/hub-game/code/client/rehello.js +167 -0
  92. package/kits/hub-game/code/client/shot.js +92 -0
  93. package/kits/hub-game/code/client/sound.js +63 -8
  94. package/kits/hub-game/code/client/soundscape.js +1151 -0
  95. package/kits/hub-game/code/client/soundscapeActions.js +99 -0
  96. package/kits/hub-game/code/client/soundscapeAmbience.js +453 -0
  97. package/kits/hub-game/code/client/soundscapeBaked.js +143 -0
  98. package/kits/hub-game/code/client/soundscapeBusker.js +217 -0
  99. package/kits/hub-game/code/client/soundscapeCourt.js +200 -0
  100. package/kits/hub-game/code/client/soundscapeCrowd.js +331 -0
  101. package/kits/hub-game/code/client/soundscapeCues.js +362 -0
  102. package/kits/hub-game/code/client/soundscapeMap.js +181 -0
  103. package/kits/hub-game/code/client/soundscapeMarket.js +176 -0
  104. package/kits/hub-game/code/client/soundscapeMusic.js +126 -0
  105. package/kits/hub-game/code/client/soundscapeMusicEngine.js +460 -0
  106. package/kits/hub-game/code/client/soundscapeSimlish.js +737 -0
  107. package/kits/hub-game/code/client/soundscapeSongs.js +127 -0
  108. package/kits/hub-game/code/client/soundscapeSongsRound3.js +63 -0
  109. package/kits/hub-game/code/client/soundscapeSynthesis.js +168 -0
  110. package/kits/hub-game/code/client/soundscapeUi.js +211 -0
  111. package/kits/hub-game/code/client/soundscapeVoice.js +1209 -0
  112. package/kits/hub-game/code/client/soundscapeWaves.js +206 -0
  113. package/kits/hub-game/code/client/spin.js +101 -0
  114. package/kits/hub-game/code/client/state.js +131 -1
  115. package/kits/hub-game/code/client/stuck.js +259 -0
  116. package/kits/hub-game/code/client/talk.js +538 -47
  117. package/kits/hub-game/code/client/tiers.js +541 -27
  118. package/kits/hub-game/code/client/toastBand.js +37 -0
  119. package/kits/hub-game/code/client/together.js +98 -1
  120. package/kits/hub-game/code/client/visibility.js +43 -0
  121. package/kits/hub-game/code/client/wear.js +470 -97
  122. package/kits/hub-game/code/client/yours.js +199 -0
  123. package/kits/hub-game/code/companionSpec.js +45 -0
  124. package/kits/hub-game/code/privateText.js +7 -0
  125. package/kits/hub-game/code/server/actions.js +133 -0
  126. package/kits/hub-game/code/server/actors.js +14 -1
  127. package/kits/hub-game/code/server/ask.js +155 -0
  128. package/kits/hub-game/code/server/ballot.js +539 -0
  129. package/kits/hub-game/code/server/cells.js +100 -0
  130. package/kits/hub-game/code/server/companion.js +82 -0
  131. package/kits/hub-game/code/server/cues.js +70 -0
  132. package/kits/hub-game/code/server/decor.js +269 -0
  133. package/kits/hub-game/code/server/earned.js +461 -0
  134. package/kits/hub-game/code/server/friendBests.js +166 -0
  135. package/kits/hub-game/code/server/friendsAmong.js +232 -0
  136. package/kits/hub-game/code/server/grab.js +296 -11
  137. package/kits/hub-game/code/server/history.js +5 -0
  138. package/kits/hub-game/code/server/hub.js +1317 -52
  139. package/kits/hub-game/code/server/idle.js +30 -11
  140. package/kits/hub-game/code/server/index.js +2 -2
  141. package/kits/hub-game/code/server/labels.js +28 -2
  142. package/kits/hub-game/code/server/manifest.js +424 -8
  143. package/kits/hub-game/code/server/menu.js +133 -0
  144. package/kits/hub-game/code/server/npcs.js +830 -80
  145. package/kits/hub-game/code/server/party.js +13 -2
  146. package/kits/hub-game/code/server/players.js +22 -0
  147. package/kits/hub-game/code/server/say.js +8 -2
  148. package/kits/hub-game/code/server/shot.js +110 -0
  149. package/kits/hub-game/code/server/standing.js +124 -0
  150. package/kits/hub-game/code/server/vis.js +113 -0
  151. package/kits/hub-game/code/server/wear.js +128 -11
  152. package/kits/hub-game/code/server/yours.js +59 -0
  153. package/kits/hub-game/code/shared/cues.js +9 -0
  154. package/kits/hub-game/code/shared/decor.js +41 -0
  155. package/kits/hub-game/code/shared/shot.js +19 -0
  156. package/kits/hub-game/code/shared/spin.js +57 -0
  157. package/kits/hub-game/code/systems/hub.js +1083 -85
  158. package/kits/hub-game/docs/content-pack.md +1 -1
  159. package/kits/hub-game/docs/contract.md +2440 -61
  160. package/kits/hub-game/docs/home-pieces.md +64 -0
  161. package/kits/hub-game/models/avatar-10.pxmodel +28 -0
  162. package/kits/hub-game/models/avatar-11.pxmodel +28 -0
  163. package/kits/hub-game/models/avatar-12.pxmodel +27 -0
  164. package/kits/hub-game/models/avatar-13.pxmodel +24 -0
  165. package/kits/hub-game/models/avatar-14.pxmodel +29 -0
  166. package/kits/hub-game/models/avatar-15.pxmodel +24 -0
  167. package/kits/hub-game/models/avatar-4.pxmodel +29 -0
  168. package/kits/hub-game/models/avatar-5.pxmodel +27 -0
  169. package/kits/hub-game/models/avatar-6.pxmodel +26 -0
  170. package/kits/hub-game/models/avatar-7.pxmodel +25 -0
  171. package/kits/hub-game/models/avatar-8.pxmodel +24 -0
  172. package/kits/hub-game/models/avatar-9.pxmodel +30 -0
  173. package/kits/hub-game/models/earned/badge-round.pxmodel +100 -0
  174. package/kits/hub-game/models/earned/badge-shield.pxmodel +117 -0
  175. package/kits/hub-game/models/earned/badge-star.pxmodel +87 -0
  176. package/kits/hub-game/models/earned/belt-plain.pxmodel +72 -0
  177. package/kits/hub-game/models/earned/held-ball.pxmodel +43 -0
  178. package/kits/hub-game/models/earned/held-lantern.pxmodel +85 -0
  179. package/kits/hub-game/models/earned/held-net.pxmodel +57 -0
  180. package/kits/hub-game/models/earned/held-trophy.pxmodel +109 -0
  181. package/kits/hub-game/models/earned/pin-round.pxmodel +62 -0
  182. package/kits/hub-game/models/earned/sash-plain.pxmodel +66 -0
  183. package/kits/hub-game/models/earned/square/belt-plain.pxmodel +104 -0
  184. package/kits/hub-game/models/earned/square/sash-plain.pxmodel +98 -0
  185. package/kits/hub-game/models/hats/bat-clip.pxmodel +206 -0
  186. package/kits/hub-game/models/hats/beekeeper.pxmodel +149 -0
  187. package/kits/hub-game/models/hats/cap.pxmodel +162 -0
  188. package/kits/hub-game/models/hats/captain.pxmodel +178 -0
  189. package/kits/hub-game/models/hats/crooked-top.pxmodel +172 -0
  190. package/kits/hub-game/models/hats/flower-crown.pxmodel +451 -0
  191. package/kits/hub-game/models/hats/foam-crown.pxmodel +179 -0
  192. package/kits/hub-game/models/hats/lantern.pxmodel +230 -0
  193. package/kits/hub-game/models/hats/laurel.pxmodel +533 -0
  194. package/kits/hub-game/models/hats/lighthouse.pxmodel +96 -0
  195. package/kits/hub-game/models/hats/sailor.pxmodel +141 -0
  196. package/kits/hub-game/models/hats/souwester.pxmodel +131 -0
  197. package/kits/hub-game/models/hats/straw.pxmodel +139 -0
  198. package/kits/hub-game/models/hats/sunflower.pxmodel +406 -0
  199. package/kits/hub-game/models/hats/sweatband.pxmodel +112 -0
  200. package/kits/hub-game/models/hats/witch.pxmodel +147 -0
  201. package/kits/hub-game/package-lock.json +2 -0
  202. package/kits/hub-game/package.json +2 -1
  203. package/kits/hub-game/scripts/check.mjs +78 -11
  204. package/kits/hub-game/scripts/companion-follower-wire.json +1 -0
  205. package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +121 -0
  206. package/kits/hub-game/scripts/fixtures/decor-keyless.json +293 -0
  207. package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +23 -0
  208. package/kits/hub-game/scripts/fixtures/fake-dom.mjs +107 -0
  209. package/kits/hub-game/scripts/fixtures/interest-legacy.json +385 -0
  210. package/kits/hub-game/scripts/fixtures/npc-notes-v1.77.jsonl +4 -0
  211. package/kits/hub-game/scripts/fixtures/vis-shared-wire.json +1 -0
  212. package/kits/hub-game/scripts/gen-avatars.mjs +933 -16
  213. package/kits/hub-game/scripts/gen-earned.mjs +285 -0
  214. package/kits/hub-game/scripts/gen-hats.mjs +827 -0
  215. package/kits/hub-game/scripts/grab.before-orbit.mjs +400 -0
  216. package/kits/hub-game/scripts/soundscape-wave-analysis.mjs +125 -0
  217. package/kits/hub-game/scripts/test-actions-client.mjs +488 -0
  218. package/kits/hub-game/scripts/test-actions.mjs +298 -0
  219. package/kits/hub-game/scripts/test-actor-budget.mjs +44 -0
  220. package/kits/hub-game/scripts/test-actors.mjs +19 -17
  221. package/kits/hub-game/scripts/test-ask-client.mjs +358 -0
  222. package/kits/hub-game/scripts/test-ask.mjs +269 -0
  223. package/kits/hub-game/scripts/test-attention.mjs +10 -1
  224. package/kits/hub-game/scripts/test-avatar-cap.mjs +379 -0
  225. package/kits/hub-game/scripts/test-avatar-colors.mjs +72 -0
  226. package/kits/hub-game/scripts/test-avatar-models.mjs +181 -0
  227. package/kits/hub-game/scripts/test-avatar-share.mjs +318 -0
  228. package/kits/hub-game/scripts/test-avatar-wire.mjs +753 -0
  229. package/kits/hub-game/scripts/test-avatar.mjs +540 -7
  230. package/kits/hub-game/scripts/test-ballot.mjs +1001 -0
  231. package/kits/hub-game/scripts/test-build.mjs +31 -0
  232. package/kits/hub-game/scripts/test-cells.mjs +71 -0
  233. package/kits/hub-game/scripts/test-chat.mjs +694 -0
  234. package/kits/hub-game/scripts/test-classic.mjs +2 -0
  235. package/kits/hub-game/scripts/test-companion-chat.mjs +198 -0
  236. package/kits/hub-game/scripts/test-companion-client.mjs +1167 -0
  237. package/kits/hub-game/scripts/test-companion.mjs +259 -0
  238. package/kits/hub-game/scripts/test-decor-client.mjs +303 -0
  239. package/kits/hub-game/scripts/test-decor.mjs +457 -0
  240. package/kits/hub-game/scripts/test-earned-client.mjs +459 -0
  241. package/kits/hub-game/scripts/test-earned.mjs +1194 -0
  242. package/kits/hub-game/scripts/test-emote-bubble.mjs +110 -0
  243. package/kits/hub-game/scripts/test-friend-bests.mjs +435 -0
  244. package/kits/hub-game/scripts/test-grab-client.mjs +186 -3
  245. package/kits/hub-game/scripts/test-grab-orbit.mjs +918 -0
  246. package/kits/hub-game/scripts/test-grab.mjs +864 -3
  247. package/kits/hub-game/scripts/test-hats.mjs +483 -0
  248. package/kits/hub-game/scripts/test-hub-leaving.mjs +203 -0
  249. package/kits/hub-game/scripts/test-hub-ops.mjs +439 -2
  250. package/kits/hub-game/scripts/test-hub-trip.mjs +1228 -1
  251. package/kits/hub-game/scripts/test-hud-clear.mjs +1000 -0
  252. package/kits/hub-game/scripts/test-idle.mjs +361 -1
  253. package/kits/hub-game/scripts/test-interest-cap.mjs +36 -0
  254. package/kits/hub-game/scripts/test-interest-cells.mjs +493 -0
  255. package/kits/hub-game/scripts/test-interest-client.mjs +118 -0
  256. package/kits/hub-game/scripts/test-keys.mjs +46 -1
  257. package/kits/hub-game/scripts/test-labels.mjs +596 -0
  258. package/kits/hub-game/scripts/test-manifest.mjs +282 -0
  259. package/kits/hub-game/scripts/test-menu-client.mjs +480 -0
  260. package/kits/hub-game/scripts/test-menu.mjs +296 -0
  261. package/kits/hub-game/scripts/test-npcs.mjs +1718 -12
  262. package/kits/hub-game/scripts/test-object-entry.mjs +76 -0
  263. package/kits/hub-game/scripts/test-pack.mjs +7 -0
  264. package/kits/hub-game/scripts/test-party.mjs +22 -1
  265. package/kits/hub-game/scripts/test-picker.mjs +314 -0
  266. package/kits/hub-game/scripts/test-rehello.mjs +1039 -0
  267. package/kits/hub-game/scripts/test-relations-among.mjs +222 -0
  268. package/kits/hub-game/scripts/test-relations-refresh.mjs +188 -0
  269. package/kits/hub-game/scripts/test-say.mjs +59 -2
  270. package/kits/hub-game/scripts/test-shot.mjs +756 -0
  271. package/kits/hub-game/scripts/test-soundscape.mjs +5432 -0
  272. package/kits/hub-game/scripts/test-spin.mjs +314 -0
  273. package/kits/hub-game/scripts/test-standing.mjs +416 -0
  274. package/kits/hub-game/scripts/test-stuck.mjs +1903 -0
  275. package/kits/hub-game/scripts/test-tier-cells.mjs +706 -0
  276. package/kits/hub-game/scripts/test-tiers-render.mjs +339 -0
  277. package/kits/hub-game/scripts/test-tiers.mjs +666 -3
  278. package/kits/hub-game/scripts/test-toast-band.mjs +61 -0
  279. package/kits/hub-game/scripts/test-try-on.mjs +940 -0
  280. package/kits/hub-game/scripts/test-vis.mjs +343 -0
  281. package/kits/hub-game/scripts/test-visibility.mjs +134 -0
  282. package/kits/hub-game/scripts/test-yours-chrome.mjs +166 -0
  283. package/kits/hub-game/scripts/test-yours.mjs +372 -0
  284. package/kits/multiplayer-3d/CLAUDE.md +50 -0
  285. package/kits/multiplayer-3d/castle.json +5 -5
  286. package/kits/multiplayer-3d/code/client/avatars.js +7 -0
  287. package/kits/multiplayer-3d/code/client/gait.js +65 -0
  288. package/kits/multiplayer-3d/code/client/nameTags.js +59 -4
  289. package/kits/multiplayer-3d/code/options.js +5 -0
  290. package/kits/multiplayer-3d/code/server/ownership.js +10 -2
  291. package/kits/multiplayer-3d/code/server/sceneBodies.js +12 -0
  292. package/kits/multiplayer-3d/code/server/world.js +7 -0
  293. package/kits/multiplayer-3d/code/systems/multiplayer.js +74 -4
  294. package/kits/multiplayer-3d/package.json +2 -1
  295. package/kits/multiplayer-3d/scripts/fixtures/README.md +11 -0
  296. package/kits/multiplayer-3d/scripts/fixtures/ownership-legacy.json +2 -0
  297. package/kits/multiplayer-3d/scripts/ownership-harness.mjs +102 -0
  298. package/kits/multiplayer-3d/scripts/ownership-loader.mjs +46 -0
  299. package/kits/multiplayer-3d/scripts/ownership-worker.mjs +15 -0
  300. package/kits/multiplayer-3d/scripts/record-ownership-session.mjs +98 -0
  301. package/kits/multiplayer-3d/scripts/test-eligible-claims.mjs +167 -0
  302. package/kits/multiplayer-3d/scripts/test-own-name-tag.mjs +247 -0
  303. package/kits/physics-2d/CLAUDE.md +9 -0
  304. package/kits/physics-2d/castle.json +2 -2
  305. package/kits/physics-2d/engine/scene.js +288 -1
  306. package/kits/physics-2d/engine/skyKey.js +129 -0
  307. package/kits/physics-2d/engine/stillClock.js +106 -0
  308. package/kits/physics-2d/engine/updateBudget.js +21 -0
  309. package/kits/physics-2d/scripts/test-skip-unchanged.mjs +370 -1
  310. package/kits/physics-3d/CLAUDE.md +1391 -0
  311. package/kits/physics-3d/behaviors/Player.jsx +921 -3
  312. package/kits/physics-3d/castle.json +3 -3
  313. package/kits/physics-3d/docs/pxmodel-format.md +12 -0
  314. package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +98 -10
  315. package/kits/physics-3d/engine3d/actornode.js +86 -0
  316. package/kits/physics-3d/engine3d/animationBudget.js +23 -0
  317. package/kits/physics-3d/engine3d/editorWorld.js +6 -0
  318. package/kits/physics-3d/engine3d/emptynodes.js +232 -0
  319. package/kits/physics-3d/engine3d/framecap.js +96 -0
  320. package/kits/physics-3d/engine3d/gait.js +118 -0
  321. package/kits/physics-3d/engine3d/kithooks.js +47 -0
  322. package/kits/physics-3d/engine3d/look.js +507 -48
  323. package/kits/physics-3d/engine3d/lookbake.js +208 -0
  324. package/kits/physics-3d/engine3d/materialpresets.js +2 -0
  325. package/kits/physics-3d/engine3d/motion.js +39 -10
  326. package/kits/physics-3d/engine3d/nearshadows.js +37 -19
  327. package/kits/physics-3d/engine3d/optimize.js +58 -5
  328. package/kits/physics-3d/engine3d/orbitinput.js +755 -0
  329. package/kits/physics-3d/engine3d/orbitlens.js +48 -0
  330. package/kits/physics-3d/engine3d/ownmodel.js +213 -0
  331. package/kits/physics-3d/engine3d/pxmodel.js +42 -11
  332. package/kits/physics-3d/engine3d/shadowfade.js +882 -0
  333. package/kits/physics-3d/engine3d/sky.js +547 -0
  334. package/kits/physics-3d/engine3d/skylife.js +306 -0
  335. package/kits/physics-3d/engine3d/unchanged.js +11 -0
  336. package/kits/physics-3d/engine3d/viewrange.js +52 -0
  337. package/kits/physics-3d/engine3d/world3d.js +870 -87
  338. package/kits/physics-3d/main.jsx +5 -0
  339. package/kits/physics-3d/package.json +1 -1
  340. package/kits/physics-3d/scripts/Player.before-orbit.mjs +310 -0
  341. package/kits/physics-3d/scripts/Scene3DPlayer.before-orbit.jsx +337 -0
  342. package/kits/physics-3d/scripts/look-baseline.mjs +155 -0
  343. package/kits/physics-3d/scripts/test-camera-follow.mjs +12 -2
  344. package/kits/physics-3d/scripts/test-camera-orbit.mjs +4588 -0
  345. package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +787 -0
  346. package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +435 -0
  347. package/kits/physics-3d/scripts/test-frame-cap.mjs +452 -0
  348. package/kits/physics-3d/scripts/test-gait.mjs +387 -0
  349. package/kits/physics-3d/scripts/test-look-bake.mjs +1056 -0
  350. package/kits/physics-3d/scripts/test-model-parse-cache.mjs +92 -0
  351. package/kits/physics-3d/scripts/test-near-shadows.mjs +3 -0
  352. package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1920 -0
  353. package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +545 -0
  354. package/kits/physics-3d/scripts/test-orbit-shot.mjs +583 -0
  355. package/kits/physics-3d/scripts/test-orbit-view.mjs +230 -0
  356. package/kits/physics-3d/scripts/test-skip-empty-nodes.mjs +845 -0
  357. package/kits/physics-3d/scripts/test-sky.mjs +2470 -0
  358. package/kits/physics-3d/scripts/test-static-actors.mjs +13 -1
  359. package/kits/physics-3d/scripts/test-static-passes.mjs +1 -1
  360. package/kits/physics-3d/scripts/test-static-scenery.mjs +2171 -0
  361. package/kits/physics-3d/scripts/test-steady-hover.mjs +635 -0
  362. package/kits/physics-3d/scripts/test-view-range.mjs +260 -0
  363. package/kits/physics-3d/systems/physics3d.js +474 -12
  364. package/kits/real-time/castle.json +2 -2
  365. package/kits/real-time/code/server/gameHooks.js +7 -0
  366. package/kits/real-time/code/server/session.js +97 -19
  367. package/package.json +2 -2
  368. package/dist/shell/assets/index-Cf61cNfT.css +0 -1
@@ -0,0 +1,1000 @@
1
+ // Tests over a clear HUD (contract v1.26, a place's `hud: { clear: true }`):
2
+ // the sizes and geometry (`code/client/hudClear.js`), and the chrome that
3
+ // draws by them (`code/client/chrome.js`) over a small stand-in for the DOM.
4
+ // A place that does not ask is written to exactly as it was: the same styles,
5
+ // positions and order of writes, whether the chrome was never told, told no,
6
+ // or told no after a place that asked. `npm run check` runs it.
7
+
8
+ import assert from 'node:assert/strict';
9
+ import {
10
+ BIG_MIN_PX,
11
+ BIG_PX,
12
+ BIG_WITH_TEXT_PX,
13
+ BIG_WITH_TEXT_SHORT_PX,
14
+ bigEms,
15
+ boxAt,
16
+ fitPx,
17
+ HUD_GAP,
18
+ hudLayout,
19
+ pushBelow,
20
+ SHORT_HUD_SHARE,
21
+ } from '../code/client/hudClear.js';
22
+
23
+ let n = 0;
24
+ function test(name, fn) {
25
+ fn();
26
+ n += 1;
27
+ }
28
+
29
+ // --- the sizes ---------------------------------------------------------
30
+
31
+ const PHONE = { viewW: 360, viewH: 740 };
32
+ const SIDEWAYS = { viewW: 740, viewH: 360 };
33
+
34
+ test('a big line alone keeps 56 px, on any view', () => {
35
+ for (const view of [PHONE, SIDEWAYS, { viewW: 1280, viewH: 800 }]) {
36
+ for (const text of [undefined, '', null]) {
37
+ const layout = hudLayout({ big: 'FINISH', text, ...view });
38
+ assert.equal(layout.bigPx, BIG_PX);
39
+ assert.equal(layout.bigOneLine, false);
40
+ assert.equal(layout.bigMaxWidth, null);
41
+ }
42
+ }
43
+ assert.equal(BIG_PX, 56);
44
+ });
45
+
46
+ test('a big line over a text line is clearly smaller: 32 px, 28 on a short view', () => {
47
+ const tall = hudLayout({ big: '3', text: 'get ready', ...PHONE });
48
+ assert.equal(tall.bigPx, BIG_WITH_TEXT_PX);
49
+ assert.ok(tall.bigPx >= 30 && tall.bigPx <= 34);
50
+ assert.equal(tall.bigOneLine, true);
51
+ assert.equal(tall.textLines, null);
52
+ assert.equal(tall.maxHeight, null);
53
+ const short = hudLayout({ big: '3', text: 'get ready', ...SIDEWAYS });
54
+ assert.equal(short.bigPx, BIG_WITH_TEXT_SHORT_PX);
55
+ // The words every playtest game puts there fit at the full smaller size.
56
+ for (const big of ['12.3', '1:23.4', 'YOU WIN', 'YOU LOSE', 'WINNER', 'FINISH', 'GOAL!', 'TIME', '3 / 5', 'OUT']) {
57
+ assert.equal(hudLayout({ big, text: 'x', ...PHONE }).bigPx, BIG_WITH_TEXT_PX, big);
58
+ }
59
+ });
60
+
61
+ test('a long big line shrinks to one line at 360 px, never below the least, and is never wrapped', () => {
62
+ // The contract cuts `big` at 12 characters.
63
+ for (const big of ['LOCKED OUT W', 'WWWWWWWWWWWW', 'MMMMMMMMMMMM', '000000000000', 'SHOW OVER NOW', 'iiiiiiiiiiii']) {
64
+ for (const reserve of [0, 98]) {
65
+ const layout = hudLayout({ big, text: 'find the lantern', ...PHONE, reserve });
66
+ assert.equal(layout.bigOneLine, true);
67
+ assert.ok(layout.bigPx >= BIG_MIN_PX && layout.bigPx <= BIG_WITH_TEXT_PX, `${big}: ${layout.bigPx}`);
68
+ // Never wider than the HUD's own widest (70vw), never narrower than the
69
+ // box hangs (half the view).
70
+ assert.ok(layout.bigMaxWidth <= 252 && layout.bigMaxWidth >= 180);
71
+ // It fits by the estimate, or is at the least and cut with an ellipsis.
72
+ assert.ok(bigEms(big) * layout.bigPx <= layout.bigMaxWidth || layout.bigPx === BIG_MIN_PX, big);
73
+ }
74
+ }
75
+ const wide = hudLayout({ big: 'LOCKED OUT W', text: 'x', ...PHONE });
76
+ assert.ok(wide.bigPx < BIG_WITH_TEXT_PX, 'twelve capitals are shrunk');
77
+ // Beside a Back button the row is narrower, so the same words are smaller.
78
+ assert.ok(hudLayout({ big: 'LOCKED OUT W', text: 'x', ...PHONE, reserve: 98 }).bigPx <= wide.bigPx);
79
+ assert.equal(hudLayout({ big: 'LOCKED OUT W', text: 'x', ...PHONE, reserve: 98 }).bigMaxWidth, 180);
80
+ // On a wide view nothing of twelve characters needs shrinking.
81
+ assert.equal(hudLayout({ big: 'WWWWWWWWWWWW', text: 'x', viewW: 1280, viewH: 800 }).bigPx, BIG_WITH_TEXT_PX);
82
+ });
83
+
84
+ test('the drawn line is measured after: one still too wide shrinks to fit, to the least', () => {
85
+ assert.equal(fitPx(32, 252, 252), 32);
86
+ assert.equal(fitPx(32, 252, 200), 32);
87
+ assert.equal(fitPx(32, 252, 336), 24);
88
+ assert.equal(fitPx(32, 252, 5000), BIG_MIN_PX);
89
+ assert.equal(fitPx(32, 0, 100), 32, 'nothing measured: left alone');
90
+ assert.equal(fitPx(32, 252, undefined), 32);
91
+ });
92
+
93
+ test('a short view: the text keeps to two lines and the box to a share of the height', () => {
94
+ for (const spec of [{ big: '3', text: 'a long line' }, { big: '', text: 'a long line' }, { big: 'FINISH', text: '' }]) {
95
+ const layout = hudLayout({ ...spec, ...SIDEWAYS });
96
+ assert.equal(layout.textLines, 2);
97
+ assert.equal(layout.maxHeight, Math.round(360 * SHORT_HUD_SHARE));
98
+ assert.ok(layout.maxHeight <= 360 * 0.45);
99
+ }
100
+ // Title 17 px, the smaller big line, two lines of text: inside the share.
101
+ const layout = hudLayout({ big: '3', text: 'x', ...SIDEWAYS });
102
+ assert.ok(13 * 1.3 + layout.bigPx * 1.05 + 2 * 14 * 1.3 <= layout.maxHeight);
103
+ // A portrait view is never short, however small: the web player's card on a 360 px phone.
104
+ const card = hudLayout({ big: '3', text: 'x', viewW: 352, viewH: 475 });
105
+ assert.equal(card.textLines, null);
106
+ assert.equal(card.maxHeight, null);
107
+ assert.equal(card.bigPx, hudLayout({ big: '3', text: 'x', ...PHONE }).bigPx);
108
+ // A tall view has neither limit.
109
+ assert.equal(hudLayout({ big: '3', text: 'x', ...PHONE }).textLines, null);
110
+ assert.equal(hudLayout({ big: '3', text: 'x', ...PHONE }).maxHeight, null);
111
+ });
112
+
113
+ // --- the geometry --------------------------------------------------------
114
+
115
+ const HUD = { left: 90, right: 270, top: 12, bottom: 100 };
116
+
117
+ test('boxAt: a label hangs over its point, an edge chip is centred on it', () => {
118
+ assert.deepEqual(boxAt(180, 90, 100, 24), { left: 130, right: 230, top: 66, bottom: 90 });
119
+ assert.deepEqual(boxAt(180, 90, 100, 24, 'center'), { left: 130, right: 230, top: 78, bottom: 102 });
120
+ });
121
+
122
+ test('pushBelow: what lies over the HUD goes just under it; the rest stays', () => {
123
+ // Over it: moved so its top is the gap under the HUD's bottom.
124
+ const over = boxAt(180, 90, 100, 24);
125
+ assert.equal(pushBelow(over, HUD), HUD.bottom + HUD_GAP - over.top);
126
+ assert.equal(over.top + pushBelow(over, HUD), 106);
127
+ // Only its bottom edge under the HUD's: still moved whole.
128
+ assert.equal(boxAt(180, 110, 100, 24).top + pushBelow(boxAt(180, 110, 100, 24), HUD), 106);
129
+ // In the gap: moved the little that clears it.
130
+ assert.equal(pushBelow(boxAt(180, 127, 100, 24), HUD), 3);
131
+ // Already under, beside it, or above it: not moved.
132
+ assert.equal(pushBelow(boxAt(180, 130, 100, 24), HUD), 0);
133
+ assert.equal(pushBelow(boxAt(180, 400, 100, 24), HUD), 0);
134
+ assert.equal(pushBelow(boxAt(40, 90, 100, 24), HUD), 0, 'its right edge touches the HUD');
135
+ assert.equal(pushBelow(boxAt(320, 90, 100, 24), HUD), 0);
136
+ assert.equal(pushBelow(boxAt(180, 12, 100, 24), HUD), 0, 'above the HUD');
137
+ // A corner over it is over it.
138
+ assert.ok(pushBelow(boxAt(60, 90, 100, 24), HUD) > 0);
139
+ // No HUD drawn: nothing moves.
140
+ assert.equal(pushBelow(over, null), 0);
141
+ // Never up: a push is zero or down.
142
+ for (let y = -50; y < 400; y += 7) {
143
+ assert.ok(pushBelow(boxAt(180, y, 100, 24), HUD) >= 0);
144
+ }
145
+ });
146
+
147
+ // --- the chrome, over a stand-in DOM -------------------------------------
148
+
149
+ // Every write (a style, the text, a child added or removed) is logged in
150
+ // order, so two runs can be held to the same writes, not only the same end.
151
+ function fakeDom(view) {
152
+ const log = [];
153
+ let ids = 0;
154
+ const made = [];
155
+ function node(tag) {
156
+ const id = `${tag}#${(ids += 1)}`;
157
+ const styles = {};
158
+ let text = '';
159
+ const self = {
160
+ id,
161
+ tag,
162
+ children: [],
163
+ parent: null,
164
+ dataset: {},
165
+ attrs: {},
166
+ rect: null,
167
+ size: null,
168
+ style: new Proxy(styles, {
169
+ get: (target, key) => target[key] ?? '',
170
+ set(target, key, value) {
171
+ target[key] = String(value);
172
+ log.push(`${id} style.${String(key)}=${value}`);
173
+ return true;
174
+ },
175
+ }),
176
+ styles,
177
+ get textContent() {
178
+ return text;
179
+ },
180
+ set textContent(value) {
181
+ text = String(value);
182
+ log.push(`${id} text=${text}`);
183
+ },
184
+ appendChild(child) {
185
+ child.parent = self;
186
+ self.children.push(child);
187
+ log.push(`${id} +${child.id}`);
188
+ return child;
189
+ },
190
+ append(...kids) {
191
+ kids.forEach((kid) => self.appendChild(kid));
192
+ },
193
+ insertBefore(child, before) {
194
+ if (child.parent) {
195
+ child.parent.children = child.parent.children.filter((c) => c !== child);
196
+ }
197
+ child.parent = self;
198
+ const at = self.children.indexOf(before);
199
+ self.children.splice(at < 0 ? self.children.length : at, 0, child);
200
+ return child;
201
+ },
202
+ remove() {
203
+ if (self.parent) {
204
+ self.parent.children = self.parent.children.filter((c) => c !== self);
205
+ log.push(`${id} removed`);
206
+ }
207
+ },
208
+ replaceChildren(...kids) {
209
+ self.children = [];
210
+ log.push(`${id} emptied`);
211
+ kids.forEach((kid) => self.appendChild(kid));
212
+ },
213
+ addEventListener() {},
214
+ removeEventListener() {},
215
+ setAttribute(key, value) {
216
+ self.attrs[key] = String(value);
217
+ },
218
+ getAttribute: (key) => self.attrs[key] ?? null,
219
+ focus() {},
220
+ blur() {},
221
+ // A stand-in layout: 7 px a character and 20 of padding, one 24 px line.
222
+ get offsetWidth() {
223
+ log.push(`${id} read`);
224
+ return (typeof self.size === 'function' ? self.size(self) : self.size)?.w ?? text.length * 7 + 20;
225
+ },
226
+ get offsetHeight() {
227
+ log.push(`${id} read`);
228
+ return (typeof self.size === 'function' ? self.size(self) : self.size)?.h ?? 24;
229
+ },
230
+ get offsetLeft() {
231
+ return parseFloat(styles.left) || 0;
232
+ },
233
+ get clientWidth() {
234
+ return self.client ?? self.offsetWidth;
235
+ },
236
+ get scrollWidth() {
237
+ return self.scroll ?? self.offsetWidth;
238
+ },
239
+ getBoundingClientRect() {
240
+ const r = self.rect ?? { left: 0, right: 0, top: 0, bottom: 0 };
241
+ return { ...r, width: r.right - r.left, height: r.bottom - r.top };
242
+ },
243
+ };
244
+ made.push(self);
245
+ return self;
246
+ }
247
+ const body = node('body');
248
+ globalThis.document = { body, createElement: node, activeElement: null };
249
+ globalThis.window = { innerWidth: view.viewW, innerHeight: view.viewH };
250
+ globalThis.innerWidth = view.viewW;
251
+ return { log, body, made };
252
+ }
253
+
254
+ const { makeChrome } = await import(process.env.HUB_TEST_CHROME ?? '../code/client/chrome.js');
255
+
256
+ function rig(view = PHONE) {
257
+ const dom = fakeDom(view);
258
+ const chrome = makeChrome({ onBack() {}, onAvatar() {}, avatarCount: 4 });
259
+ const root = dom.body.children[0];
260
+ const hud = root.children.find((c) => c.styles.maxWidth === '70vw');
261
+ const [hudTitle, hudBig, hudText] = hud.children;
262
+ // v1.38: the pointers' layer is under the labels' (a speech bubble is read over a chip).
263
+ const pointers = root.children[root.children.indexOf(hud) + 1];
264
+ const labels = root.children[root.children.indexOf(hud) + 2];
265
+ const cabinet = dom.made.find((c) => c.dataset.hub === 'cabinet');
266
+ return { ...dom, chrome, root, hud, hudTitle, hudBig, hudText, labels, pointers, cabinet };
267
+ }
268
+
269
+ test('v1.52: the cover line is smaller, centred and phone-wrappable, and absent without text', () => {
270
+ const r = rig();
271
+ const cover = r.root.children[0];
272
+ const [title] = cover.children;
273
+ r.chrome.setCover(1, 'Town');
274
+ assert.equal(title.textContent, 'Town');
275
+ assert.equal(cover.children.length, 1, 'no second line until a place asks');
276
+ assert.equal(cover.styles.flexDirection, undefined, 'original cover layout');
277
+ r.chrome.setCover(1, 'Town', 'Your lantern will be waiting by the well');
278
+ const line = cover.children[1];
279
+ assert.equal(line.textContent, 'Your lantern will be waiting by the well');
280
+ assert.equal(line.styles.display, 'block');
281
+ assert.ok(parseFloat(line.styles.fontSize) < parseFloat(title.styles.fontSize));
282
+ assert.equal(line.styles.textAlign, 'center');
283
+ assert.equal(line.styles.overflowWrap, 'anywhere');
284
+ assert.equal(line.styles.width, 'min(84vw, 420px)');
285
+ assert.equal(line.styles.fontFamily, undefined, 'both lines inherit the chrome font');
286
+ r.chrome.setCover(0);
287
+ assert.equal(line.textContent, '');
288
+ assert.equal(line.styles.display, 'none');
289
+ r.chrome.setCover(1, 'Another place');
290
+ assert.equal(line.styles.display, 'none', 'no old line on the next cover');
291
+ });
292
+
293
+ test('v1.52: leaving toasts wrap a 120-character unbroken line and restore the ordinary toast styles', () => {
294
+ for (const view of [PHONE, SIDEWAYS, { viewW: 1280, viewH: 800 }]) {
295
+ const r = rig(view);
296
+ const toast = r.root.children.find((c) => c.dataset.hub === 'toast');
297
+ r.chrome.setToast('Ordinary feedback');
298
+ const original = { ...toast.styles, display: 'none' };
299
+ assert.equal(toast.styles.width, 'max-content');
300
+ assert.equal(toast.styles.maxWidth, 'calc(100vw - 24px)');
301
+ assert.equal(toast.styles.textAlign, 'center');
302
+ r.log.length = 0;
303
+ r.chrome.setToast('Ordinary feedback');
304
+ assert.equal(r.log.some((entry) => entry.startsWith(`${toast.id} style.`)), false, 'an unchanged toast writes no styles');
305
+ const line = 'x'.repeat(120);
306
+ r.chrome.setToast(line, { wrap: true });
307
+ assert.equal(toast.textContent, line);
308
+ assert.equal(toast.styles.maxWidth, 'min(90vw, 480px)');
309
+ assert.equal(toast.styles.overflowWrap, 'anywhere');
310
+ assert.equal(toast.styles.textAlign, 'center');
311
+ r.chrome.setToast(`Back from Foot Race · ${line}`, { wrap: true });
312
+ assert.equal(toast.styles.maxWidth, 'min(90vw, 480px)');
313
+ r.chrome.setToast('Invited Ada to your party');
314
+ const reset = { maxWidth: original.maxWidth, overflowWrap: '', textAlign: original.textAlign };
315
+ assert.deepEqual(toast.styles, { ...original, ...reset, display: 'block' });
316
+ // Restore actual prior inline values, not just the current empty defaults.
317
+ const prior = { maxWidth: '240px', overflowWrap: 'normal', textAlign: 'left' };
318
+ Object.assign(toast.style, prior);
319
+ r.chrome.setToast(line, { wrap: true });
320
+ r.chrome.setToast('');
321
+ assert.deepEqual(toast.styles, { ...original, ...prior });
322
+ // Even a wrap option on an empty toast must restore the old styles.
323
+ r.chrome.setToast(line, { wrap: true });
324
+ r.chrome.setToast('', { wrap: true });
325
+ assert.deepEqual(toast.styles, { ...original, ...prior });
326
+ }
327
+ });
328
+
329
+ const SPEC = { title: 'Lantern Run', big: '12.3', text: 'find the lantern and bring it home' };
330
+ const LABELS = [
331
+ { id: 'sign', x: 180, y: 90, text: 'Start here', speech: false, npc: false, opacity: 1 },
332
+ { id: 'npc', x: 170, y: 60, text: 'Take the lantern to the well.', speech: true, npc: true, opacity: 1 },
333
+ { id: 'mark', x: 30, y: 80, text: 'IT', color: '#ff0000' },
334
+ { id: 'far', x: 180, y: 400, text: 'Well', speech: false, npc: false, opacity: 0.5 },
335
+ { id: 'wave', x: 200, y: 70, text: '👋', emote: true },
336
+ ];
337
+ const POINTERS = [
338
+ { id: 'goal:well', x: 180, y: 84, text: 'The well · 22 m', angle: -1.57 },
339
+ { id: 'to:p2', x: 200, y: 95, text: 'bo · 31 m', angle: null },
340
+ { id: 'goal:gate', x: 180, y: 500, text: 'Gate', angle: null },
341
+ ];
342
+
343
+ // A visit's frames, as the hub system draws them (`drawChrome`): the flag
344
+ // when `tell` gives one, then the HUD, the pointers, the labels, the ribbon.
345
+ function frames(r, tell, specs = [SPEC, { ...SPEC, big: '12.4' }, { title: 'Lantern Run', big: 'FINISH' }, null, { text: 'only words' }, SPEC]) {
346
+ for (const spec of specs) {
347
+ const on = tell();
348
+ if (on !== undefined) {
349
+ r.chrome.setHudClear(on);
350
+ }
351
+ r.chrome.setHud(spec, null);
352
+ r.chrome.setPointers(POINTERS);
353
+ r.chrome.setLabels(LABELS);
354
+ r.chrome.setRibbon({ x: 180, y: 96 }, '🏅 12.3 s');
355
+ // The frame's end. The hub system says it only in a place that asks; said
356
+ // here in every run, it must do nothing at all in one that does not.
357
+ r.chrome.flushHudClear?.();
358
+ }
359
+ }
360
+
361
+ // A style set to '' is one not set, as in a browser.
362
+ const styleOf = (node) => Object.fromEntries(Object.entries(node.styles).filter(([, value]) => value !== ''));
363
+ const tree = (node) => ({ id: node.id, text: node.children.length ? undefined : node.textContent, style: styleOf(node), kids: node.children.map(tree) });
364
+
365
+ // The HUD as it is today, written here so a change to the default shows.
366
+ const TODAY = {
367
+ hud: { position: 'absolute', top: 'max(12px, env(safe-area-inset-top))', left: '50%', transform: 'translateX(-50%)', textAlign: 'center', textShadow: '0 0 2px rgba(0,0,0,0.95), 0 0 2px rgba(0,0,0,0.95), 0 1px 4px rgba(0,0,0,0.75), 0 0 10px rgba(0,0,0,0.45)', display: 'block', maxWidth: '70vw' },
368
+ title: { fontSize: '13px', opacity: '0.85', letterSpacing: '0.06em', textTransform: 'uppercase' },
369
+ big: { fontSize: '56px', fontWeight: '800', lineHeight: '1.05', display: 'block' },
370
+ text: { fontSize: '14px', fontWeight: '500' },
371
+ };
372
+
373
+ test('never told: the HUD, labels and pointers are styled and placed as today', () => {
374
+ const r = rig();
375
+ r.hud.rect = { left: 90, right: 270, top: 12, bottom: 106 };
376
+ frames(r, () => undefined);
377
+ assert.deepEqual(styleOf(r.hud), TODAY.hud);
378
+ assert.deepEqual(styleOf(r.hudTitle), TODAY.title);
379
+ assert.deepEqual(styleOf(r.hudBig), TODAY.big);
380
+ assert.deepEqual(styleOf(r.hudText), TODAY.text);
381
+ // Each label is where it was asked to be, under the HUD or not -- except
382
+ // an emote's emoji, which is drawn just under the HUD's box (106 px, an 8 px
383
+ // gap, its own height to its anchored bottom: `emoteBubble.js`).
384
+ const top = Object.fromEntries(r.labels.children.map((c) => [c.textContent, c.styles.top]));
385
+ assert.deepEqual(top, { 'Start here': '90px', 'Take the lantern to the well.': '60px', IT: '80px', Well: '400px', '👋': '138px' });
386
+ assert.deepEqual(r.pointers.children.map((c) => c.styles.top), ['84px', '95px', '500px']);
387
+ // Nothing of a clear HUD was written anywhere.
388
+ for (const node of [r.hud, r.hudBig, r.hudText]) {
389
+ assert.ok(!r.log.some((line) => line.startsWith(`${node.id} `) && /overflow|maxHeight|webkit|textOverflow|margin|whiteSpace/.test(line)), node.id);
390
+ }
391
+ });
392
+
393
+ test('told no: the same writes in the same order as never told', () => {
394
+ const never = rig();
395
+ never.hud.rect = { left: 90, right: 270, top: 12, bottom: 106 };
396
+ const base = never.log.length;
397
+ frames(never, () => undefined);
398
+ const no = rig();
399
+ no.hud.rect = { left: 90, right: 270, top: 12, bottom: 106 };
400
+ assert.equal(no.log.length, base, 'the chrome is built the same');
401
+ frames(no, () => false);
402
+ assert.deepEqual(no.log, never.log);
403
+ assert.deepEqual(tree(no.root), tree(never.root));
404
+ });
405
+
406
+ test('asked: a big line over text is 32 px on one line; alone it is 56 px again', () => {
407
+ const r = rig();
408
+ r.hud.rect = { left: 90, right: 270, top: 12, bottom: 82 };
409
+ r.chrome.setHudClear(true);
410
+ r.chrome.setHud(SPEC, null);
411
+ assert.equal(r.hudBig.styles.fontSize, '32px');
412
+ assert.equal(r.hudBig.styles.whiteSpace, 'nowrap');
413
+ assert.equal(r.hudBig.styles.overflow, 'hidden');
414
+ assert.equal(r.hudBig.styles.textOverflow, 'ellipsis');
415
+ assert.equal(r.hudBig.styles.maxWidth, '252px');
416
+ assert.equal(r.hudText.styles.webkitLineClamp ?? '', '', 'a tall view does not cut the text');
417
+ assert.equal(r.hud.styles.maxHeight ?? '', '');
418
+ // The timer is the big line when the place gives none.
419
+ r.chrome.setHud({ title: 'Lantern Run', text: 'go', timer: { since: 0 } }, 4.26);
420
+ assert.equal(r.hudBig.textContent, '4.3');
421
+ assert.equal(r.hudBig.styles.fontSize, '32px');
422
+ // Alone: the 56 px of always, free to be as it was.
423
+ r.chrome.setHud({ title: 'Lantern Run', big: 'FINISH' }, null);
424
+ assert.equal(r.hudBig.styles.fontSize, '56px');
425
+ assert.equal(r.hudBig.styles.whiteSpace, '');
426
+ assert.equal(r.hudBig.styles.overflow, '');
427
+ assert.equal(r.hudBig.styles.maxWidth, '');
428
+ // The drawn line is wider than its box: shrunk again by what was measured.
429
+ r.hudBig.client = 252;
430
+ r.hudBig.scroll = 336;
431
+ r.chrome.setHud({ big: 'LANTERN', text: 'x' }, null);
432
+ assert.equal(r.hudBig.styles.fontSize, '24px');
433
+ });
434
+
435
+ test('asked: beside a Back button the big line keeps to its own part of the row', () => {
436
+ const r = rig();
437
+ r.hud.rect = { left: 90, right: 270, top: 12, bottom: 82 };
438
+ // The Back button as a phone draws it: 12 px in, about 78 wide.
439
+ r.root.children.find((c) => c.tag === 'button' && c.styles.left === '12px').size = { w: 78, h: 38 };
440
+ r.chrome.showBack(true, 'Town');
441
+ r.chrome.setHudClear(true);
442
+ r.chrome.setHud({ big: 'LOCKED OUT W', text: 'x' }, null);
443
+ assert.equal(r.hudBig.styles.maxWidth, '180px');
444
+ assert.ok(parseFloat(r.hudBig.styles.fontSize) < 32 && parseFloat(r.hudBig.styles.fontSize) >= BIG_MIN_PX);
445
+ });
446
+
447
+ test('asked, a phone on its side: two lines of text and a box no taller than its share', () => {
448
+ const r = rig(SIDEWAYS);
449
+ r.hud.rect = { left: 190, right: 550, top: 12, bottom: 96 };
450
+ r.chrome.setHudClear(true);
451
+ r.chrome.setHud(SPEC, null);
452
+ assert.equal(r.hudBig.styles.fontSize, '28px');
453
+ assert.equal(r.hudText.styles.display, '-webkit-box');
454
+ assert.equal(r.hudText.styles.webkitLineClamp, '2');
455
+ assert.equal(r.hudText.styles.webkitBoxOrient, 'vertical');
456
+ assert.equal(r.hudText.styles.overflow, 'hidden');
457
+ assert.equal(r.hud.styles.maxHeight, '144px');
458
+ assert.equal(r.hud.styles.overflow, 'hidden');
459
+ });
460
+
461
+ test('emote bubbles: sizes are read once per emoji, never between this frame\'s writes', () => {
462
+ const r = rig();
463
+ const heads = Array.from({ length: 30 }, (_, i) => ({ id: `e${i}`, x: 0, y: 0, text: i % 2 ? '👋' : '💃', emote: true, head: { left: 20 + i * 10, right: 50 + i * 10, top: 400, bottom: 430 }, lift: 0 }));
464
+ r.chrome.setLabels(heads);
465
+ const reads = (from) => r.log.slice(from).filter((line) => line.endsWith(' read'));
466
+ assert.equal(reads(0).length, 4, 'two emoji, each read once (width and height)');
467
+ for (let frame = 0; frame < 3; frame += 1) {
468
+ const from = r.log.length;
469
+ r.chrome.setLabels(heads.map((h) => ({ ...h, head: { ...h.head, top: h.head.top + frame } })));
470
+ assert.deepEqual(reads(from), [], 'no read in a later frame');
471
+ }
472
+ });
473
+
474
+ test('emote bubbles: one hidden for a head off the view is shown again on any later placement', () => {
475
+ const r = rig();
476
+ const off = { id: 'w', x: 0, y: 0, text: '👋', emote: true, head: { left: 400, right: 440, top: 300, bottom: 330 }, lift: 0 };
477
+ r.chrome.setLabels([off]);
478
+ const node = r.labels.children.find((c) => c.textContent === '👋');
479
+ assert.equal(node.styles.visibility, 'hidden');
480
+ // Its head back in the view.
481
+ r.chrome.setLabels([{ ...off, head: { left: 150, right: 190, top: 300, bottom: 330 } }]);
482
+ assert.equal(node.styles.visibility, '');
483
+ r.chrome.setLabels([off]);
484
+ assert.equal(node.styles.visibility, 'hidden');
485
+ // No head this frame (the old point): shown again.
486
+ r.chrome.setLabels([{ id: 'w', x: 180, y: 400, text: '👋', emote: true }]);
487
+ assert.equal(node.styles.visibility, '');
488
+ assert.equal(node.styles.left, '180px');
489
+ });
490
+
491
+ test('asked: labels, speech, marks, emotes, pointers and the ribbon over the HUD go just under it', () => {
492
+ const r = rig();
493
+ r.hud.rect = { left: 90, right: 270, top: 12, bottom: 106 };
494
+ frames(r, () => true, [SPEC]);
495
+ const node = (text) => r.labels.children.find((c) => c.textContent === text);
496
+ // Each is 24 px tall here, hung by its bottom edge: clear is top 112, so 136.
497
+ assert.equal(node('Start here').styles.top, '136px');
498
+ assert.equal(node('Take the lantern to the well.').styles.top, '136px');
499
+ assert.equal(node('👋').styles.top, '136px');
500
+ // Beside the HUD (its box ends left of 90) and far below it: where they were.
501
+ assert.equal(node('IT').styles.top, '80px');
502
+ assert.equal(node('Well').styles.top, '400px');
503
+ // Never hidden, never moved sideways.
504
+ for (const c of r.labels.children) {
505
+ assert.notEqual(c.styles.display, 'none');
506
+ }
507
+ assert.equal(node('Start here').styles.left, '180px');
508
+ // An edge chip is centred on its point (top 112 is y 124); one over a friend hangs.
509
+ assert.deepEqual(r.pointers.children.map((c) => c.styles.top), ['124px', '136px', '500px']);
510
+ const ribbon = r.made.find((c) => c.textContent === '🏅 12.3 s');
511
+ assert.equal(ribbon.styles.top, '136px');
512
+ // Nothing drawn: nothing to keep clear of.
513
+ frames(r, () => true, [null]);
514
+ assert.equal(node('Start here').styles.top, '90px');
515
+ assert.deepEqual(r.pointers.children.map((c) => c.styles.top), ['84px', '95px', '500px']);
516
+ // A taller HUD pushes farther: the box is measured again when it changes.
517
+ r.hud.rect = { left: 90, right: 270, top: 12, bottom: 140 };
518
+ frames(r, () => true, [{ ...SPEC, text: 'a much longer line of words that wraps' }]);
519
+ assert.equal(node('Start here').styles.top, '170px');
520
+ });
521
+
522
+ test('asked: a cabinet card over the HUD goes under it too', () => {
523
+ const r = rig();
524
+ r.hud.rect = { left: 90, right: 270, top: 12, bottom: 106 };
525
+ r.chrome.setHudClear(true);
526
+ r.chrome.setHud(SPEC, null);
527
+ r.cabinet.size = { w: 120, h: 30 };
528
+ const item = { id: 'cab', rev: 1, card: { title: 'Arcade', top: [{ username: 'bo', score: 12 }] }, x: 180, y: 90, opacity: 1 };
529
+ r.chrome.setCabinet(item, () => null);
530
+ r.chrome.flushHudClear?.();
531
+ assert.equal(r.cabinet.styles.display, 'block');
532
+ // 30 px tall, hung by its bottom edge: clear is top 112, so 142.
533
+ assert.equal(r.cabinet.styles.top, '142px');
534
+ const off = rig();
535
+ off.hud.rect = r.hud.rect;
536
+ off.chrome.setHud(SPEC, null);
537
+ off.cabinet.size = { w: 120, h: 30 };
538
+ off.chrome.setCabinet(item, () => null);
539
+ off.chrome.flushHudClear?.();
540
+ assert.equal(off.cabinet.styles.display, 'block');
541
+ assert.equal(off.cabinet.styles.top, '90px');
542
+ });
543
+
544
+ test('after a place that asked, a place that does not is drawn as never told', () => {
545
+ for (const view of [PHONE, SIDEWAYS]) {
546
+ const never = rig(view);
547
+ never.hud.rect = { left: 90, right: 270, top: 12, bottom: 106 };
548
+ frames(never, () => undefined);
549
+ const after = rig(view);
550
+ after.hud.rect = { left: 90, right: 270, top: 12, bottom: 106 };
551
+ after.chrome.showBack(true, 'Town');
552
+ frames(after, () => true);
553
+ after.chrome.showBack(false);
554
+ const mark = after.log.length;
555
+ frames(after, () => false);
556
+ // Same styles and positions on every node the two runs share.
557
+ const strip = (t) => JSON.stringify(t).replace(/"id":"[^"]*",?/g, '');
558
+ const hudOf = (r) => strip(tree(r.hud));
559
+ assert.equal(hudOf(after), hudOf(never));
560
+ assert.equal(strip(tree(after.labels)), strip(tree(never.labels)));
561
+ assert.equal(strip(tree(after.pointers)), strip(tree(never.pointers)));
562
+ assert.deepEqual(styleOf(after.hudBig), TODAY.big);
563
+ assert.deepEqual(styleOf(after.hudText), TODAY.text);
564
+ assert.deepEqual(styleOf(after.hud), TODAY.hud);
565
+ // And after the one frame that put it back, nothing of it is written.
566
+ const putBack = after.log.slice(mark).filter((line) => /maxHeight|webkit|textOverflow/.test(line));
567
+ assert.equal(putBack.length, 4, 'put back once, in the first frame');
568
+ }
569
+ });
570
+
571
+ test('asked: a bubble that wraps by where it is is measured again when it moves', () => {
572
+ const r = rig();
573
+ r.hud.rect = { left: 90, right: 270, top: 12, bottom: 106 };
574
+ r.chrome.setHudClear(true);
575
+ r.chrome.setHud(SPEC, null);
576
+ // A player's chat bubble: its width is what is left of the view to its
577
+ // right, so nearer the right edge it is narrower and taller.
578
+ const bubble = (x) => [{ id: 'say:p2', x, y: 136, text: 'meet me by the well when the bell rings', speech: true, npc: false, opacity: 1 }];
579
+ let reads = 0;
580
+ r.chrome.setLabels(bubble(100));
581
+ r.chrome.flushHudClear?.();
582
+ const node = r.labels.children[0];
583
+ node.size = (self) => ((reads += 1), parseFloat(self.styles.left) > 200 ? { w: 150, h: 58 } : { w: 220, h: 24 });
584
+ r.chrome.setLabels(bubble(100));
585
+ r.chrome.flushHudClear?.();
586
+ assert.equal(node.styles.top, '136px', 'one line: its top is 112, clear');
587
+ // Moved right with the same words: three lines now, so its top would be 78.
588
+ r.chrome.setLabels(bubble(210));
589
+ r.chrome.flushHudClear?.();
590
+ assert.equal(node.styles.top, '170px', 'its top is 112 again');
591
+ // Standing still it is not measured every frame.
592
+ const before = reads;
593
+ for (let i = 0; i < 10; i += 1) {
594
+ r.chrome.setLabels(bubble(210));
595
+ r.chrome.flushHudClear?.();
596
+ }
597
+ assert.equal(reads, before);
598
+ // A label that never wraps is measured once, wherever it goes.
599
+ const sign = (x) => [{ id: 'sign', x, y: 90, text: 'Start here', speech: false, npc: false, opacity: 1 }];
600
+ r.chrome.setLabels(sign(100));
601
+ r.chrome.flushHudClear?.();
602
+ let signReads = 0;
603
+ r.labels.children[0].size = () => ((signReads += 1), { w: 90, h: 24 });
604
+ for (let x = 100; x < 260; x += 10) {
605
+ r.chrome.setLabels(sign(x));
606
+ r.chrome.flushHudClear?.();
607
+ }
608
+ assert.ok(signReads <= 2, `${signReads} reads`);
609
+ });
610
+
611
+ test('asked: a frame is all measured, then all moved -- no layout read after its first push, across pointers, labels, the card and the ribbon', () => {
612
+ const r = rig();
613
+ r.hud.rect = { left: 60, right: 300, top: 12, bottom: 106 };
614
+ // Four chat bubbles and two pointers drifting sideways under the HUD: each
615
+ // bubble's size is read again every frame (it wraps by where it is), and
616
+ // each pointer's words change with its distance.
617
+ const bubbles = (dx) => [0, 1, 2, 3].map((i) => ({ id: `say:p${i}`, x: 100 + i * 40 + dx, y: 60 + i * 10, text: `bubble ${i} has a few words in it`, speech: true, npc: false, opacity: 1 }));
618
+ const chips = (dx) => [0, 1].map((i) => ({ id: `to:p${i}`, x: 150 + i * 60 + dx, y: 90, text: `friend ${i} · ${20 + dx} m`, angle: null }));
619
+ const card = { id: 'cab', rev: 1, card: { title: 'Arcade', top: [{ username: 'bo', score: 12 }] }, x: 180, y: 90, opacity: 1 };
620
+ // The hub system's own order (`drawChrome`).
621
+ const frame = (dx) => {
622
+ r.chrome.setHudClear(true);
623
+ r.chrome.setHud(SPEC, null);
624
+ r.chrome.setPointers(chips(dx));
625
+ r.chrome.setLabels(bubbles(dx));
626
+ r.chrome.setCabinet(card, () => null);
627
+ r.chrome.setRibbon({ x: 180 + dx, y: 96 }, `🏅 ${dx} s`);
628
+ r.chrome.setToast('');
629
+ r.chrome.flushHudClear();
630
+ };
631
+ for (let dx = 0; dx < 8; dx += 1) {
632
+ const mark = r.log.length;
633
+ frame(dx);
634
+ const lines = r.log.slice(mark);
635
+ // A push is the second write of `top` to a node in the frame.
636
+ const tops = new Set();
637
+ const firstPush = lines.findIndex((line) => {
638
+ const m = /^(\S+) style\.top=/.exec(line);
639
+ if (!m) {
640
+ return false;
641
+ }
642
+ if (tops.has(m[1])) {
643
+ return true;
644
+ }
645
+ tops.add(m[1]);
646
+ return false;
647
+ });
648
+ assert.ok(firstPush > 0, 'something was pushed');
649
+ const before = lines.slice(0, firstPush);
650
+ const after = lines.slice(firstPush);
651
+ // Measured this frame: the four moving bubbles, the two pointers, the ribbon.
652
+ const measured = new Set(before.filter((line) => line.endsWith(' read')).map((line) => line.split(' ')[0]));
653
+ for (const node of [...r.labels.children, ...r.pointers.children]) {
654
+ assert.ok(measured.has(node.id), `${node.id} was measured`);
655
+ }
656
+ assert.ok(!after.some((line) => line.endsWith(' read')), `frame ${dx}: no read after the first push`);
657
+ assert.ok(after.every((line) => / style\.top=/.test(line)), 'only pushes after it');
658
+ // Eight pushes: four bubbles, two pointers, the card, the ribbon.
659
+ assert.equal(after.length, 8);
660
+ }
661
+ // And each is clear: 24 px tall, top 112.
662
+ assert.deepEqual(r.labels.children.map((c) => c.styles.top), ['136px', '136px', '136px', '136px']);
663
+ assert.deepEqual(r.pointers.children.map((c) => c.styles.top), ['136px', '136px']);
664
+ assert.equal(r.cabinet.styles.top, '136px');
665
+ assert.equal(r.made.find((c) => c.textContent === '🏅 7 s').styles.top, '136px');
666
+ });
667
+
668
+ test('never asked: the end of a frame reads and writes nothing', () => {
669
+ const r = rig();
670
+ r.hud.rect = { left: 90, right: 270, top: 12, bottom: 106 };
671
+ frames(r, () => undefined, [SPEC]);
672
+ const mark = r.log.length;
673
+ r.chrome.flushHudClear();
674
+ r.chrome.flushHudClear();
675
+ assert.equal(r.log.length, mark);
676
+ // Nor after a place that asked has been left.
677
+ frames(r, () => true, [SPEC]);
678
+ r.chrome.setHudClear(false);
679
+ r.chrome.setLabels(LABELS);
680
+ const quiet = r.log.length;
681
+ r.chrome.flushHudClear();
682
+ assert.equal(r.log.length, quiet);
683
+ });
684
+
685
+ test('pushBelow: nothing is pushed off the bottom of the view', () => {
686
+ const hud = { left: 90, right: 270, top: 12, bottom: 94 };
687
+ // It fits under the HUD and in the view: moved clear, as without a view.
688
+ assert.equal(pushBelow(boxAt(180, 90, 100, 24), hud, HUD_GAP, 360), pushBelow(boxAt(180, 90, 100, 24), hud));
689
+ // A 276 px board on a 360 px view cannot be both: moved only as far as
690
+ // keeps it whole on screen, the HUD over its top.
691
+ const board = boxAt(180, 320, 204, 276);
692
+ assert.equal(pushBelow(board, hud), 56);
693
+ assert.equal(pushBelow(board, hud, HUD_GAP, 360), 40);
694
+ assert.equal(board.bottom + pushBelow(board, hud, HUD_GAP, 360), 360);
695
+ // Already at or past the bottom: left where it is, never moved up.
696
+ assert.equal(pushBelow(boxAt(180, 360, 204, 300), hud, HUD_GAP, 360), 0);
697
+ assert.equal(pushBelow(boxAt(180, 380, 204, 330), hud, HUD_GAP, 360), 0);
698
+ });
699
+
700
+ test('asked: an open cabinet board on a short view stays whole on screen', () => {
701
+ const r = rig(SIDEWAYS);
702
+ r.hud.rect = { left: 190, right: 550, top: 12, bottom: 94 };
703
+ r.chrome.setHudClear(true);
704
+ r.chrome.setHud(SPEC, null);
705
+ r.cabinet.size = { w: 204, h: 276 };
706
+ r.chrome.setCabinet({ id: 'cab', rev: 1, card: { title: 'Arcade', top: [{ username: 'bo', score: 12 }] }, x: 370, y: 320, opacity: 1 }, () => null);
707
+ r.chrome.flushHudClear?.();
708
+ assert.equal(r.cabinet.styles.display, 'block');
709
+ // Its bottom is its `top` style: never past the view's 360.
710
+ assert.equal(r.cabinet.styles.top, '360px');
711
+ // A small label there still goes clear under the HUD.
712
+ r.chrome.setLabels([{ id: 'sign', x: 370, y: 90, text: 'Start here', speech: false, npc: false, opacity: 1 }]);
713
+ r.chrome.flushHudClear?.();
714
+ assert.equal(r.labels.children[0].styles.top, '124px');
715
+ });
716
+
717
+ test('asked, then not, with no HUD drawn: put back at once, and written to as never told', () => {
718
+ for (const view of [PHONE, SIDEWAYS]) {
719
+ const later = [null, null, SPEC, { title: 'Lantern Run', big: 'FINISH' }, null];
720
+ const never = rig(view);
721
+ never.hud.rect = { left: 90, right: 270, top: 12, bottom: 106 };
722
+ frames(never, () => undefined);
723
+ const neverMark = never.log.length;
724
+ frames(never, () => undefined, later);
725
+ const after = rig(view);
726
+ after.hud.rect = { left: 90, right: 270, top: 12, bottom: 106 };
727
+ frames(after, () => true);
728
+ assert.notDeepEqual(styleOf(after.hudBig), TODAY.big);
729
+ // The place is left for one with no HUD: the option goes, then no HUD.
730
+ after.chrome.setHudClear(false);
731
+ for (const [node, today] of [[after.hud, TODAY.hud], [after.hudTitle, TODAY.title], [after.hudBig, TODAY.big], [after.hudText, TODAY.text]]) {
732
+ assert.deepEqual(styleOf(node), today, 'put back before any HUD is drawn');
733
+ }
734
+ const mark = after.log.length;
735
+ after.chrome.setHud(null, null);
736
+ assert.deepEqual(styleOf(after.hud), { ...TODAY.hud, display: 'none' });
737
+ assert.deepEqual(styleOf(after.hudBig), TODAY.big);
738
+ assert.deepEqual(styleOf(after.hudText), TODAY.text);
739
+ after.log.length = mark;
740
+ // From then on: the same writes, in the same order, as a client never told.
741
+ frames(after, () => undefined, later);
742
+ assert.deepEqual(after.log.slice(mark), never.log.slice(neverMark));
743
+ const strip = (t) => JSON.stringify(t).replace(/"id":"[^"]*",?/g, '');
744
+ assert.equal(strip(tree(after.root)), strip(tree(never.root)));
745
+ // Told no again and again: nothing more is written for it.
746
+ const quiet = after.log.length;
747
+ after.chrome.setHudClear(false);
748
+ after.chrome.setHudClear(false);
749
+ assert.equal(after.log.length, quiet);
750
+ }
751
+ });
752
+
753
+ // A setter called with no flush after it (outside the hub system's frame) is
754
+ // still moved, before the browser would paint: all read, then all written.
755
+ {
756
+ const r = rig();
757
+ r.hud.rect = { left: 90, right: 270, top: 12, bottom: 106 };
758
+ r.chrome.setHudClear(true);
759
+ r.chrome.setHud(SPEC, null);
760
+ const mark = r.log.length;
761
+ r.chrome.setPointers(POINTERS);
762
+ r.chrome.setLabels(LABELS);
763
+ assert.equal(r.labels.children[0].styles.top, '90px', 'not moved as it is asked');
764
+ await Promise.resolve();
765
+ assert.equal(r.labels.children[0].styles.top, '136px');
766
+ assert.deepEqual(r.pointers.children.map((c) => c.styles.top), ['124px', '136px', '500px']);
767
+ const lines = r.log.slice(mark);
768
+ const lastRead = lines.findLastIndex((line) => line.endsWith(' read'));
769
+ assert.ok(lines.slice(lastRead + 1).every((line) => / style\.top=/.test(line)), 'reads, then only pushes');
770
+ // Flushed once: the frame's own flush after it finds nothing left.
771
+ const quiet = r.log.length;
772
+ r.chrome.flushHudClear();
773
+ await Promise.resolve();
774
+ assert.equal(r.log.length, quiet);
775
+ n += 1;
776
+ }
777
+
778
+ // v1.34: pointers (friends, a place's goals) are under every panel and card:
779
+ // their layer is made with the labels', before anything that opens over the
780
+ // world, so a goal's arrow is never drawn on the NPC words being read.
781
+ {
782
+ const r = rig();
783
+ const order = r.root.children;
784
+ const at = order.indexOf(r.pointers);
785
+ // v1.38: and under the labels' layer, so an NPC's speech bubble is read over a chip.
786
+ assert.equal(at, order.indexOf(r.labels) - 1, 'the pointers layer is just under the labels layer');
787
+ const over = order.filter((c) => c.tag === 'button' || (c.styles.width ?? '').startsWith('min(') || c.styles.borderRadius);
788
+ // (Back and the toast are made before both layers, as they always were.)
789
+ const early = order.slice(0, at).filter((c) => over.includes(c));
790
+ assert.ok(early.length <= 3 && over.length - early.length >= 8, `made before the pointers: ${early.length} of ${over.length}`);
791
+ assert.ok(over.filter((c) => !early.includes(c)).every((c) => order.indexOf(c) > order.indexOf(r.labels)), 'everything that opens over the world is over the pointers and the labels');
792
+ assert.ok(order.filter((c, i) => i > at && (c.styles.width ?? '').startsWith('min(')).length >= 1, 'the talk panel among them');
793
+ n += 1;
794
+ }
795
+
796
+ // v1.38: a chip at the screen's edge is kept beside the round buttons there
797
+ // (quick chat, emotes, grab), never under one: half its words were covered.
798
+ {
799
+ const r = rig();
800
+ const say = r.made.find((c) => c.attrs['aria-label'] === 'Quick chat');
801
+ r.chrome.setSay({ reactions: ['👋'], phrases: [] });
802
+ say.rect = { left: window.innerWidth - 72, right: window.innerWidth - 20, top: 600, bottom: 652 };
803
+ const chipOf = (text) => r.pointers.children.find((c) => c.children[1].textContent === text);
804
+ const edgeX = window.innerWidth - 4;
805
+ r.chrome.setPointers([
806
+ { id: 'a', x: edgeX, y: 626, text: 'lantern', angle: 0 },
807
+ { id: 'b', x: edgeX, y: 300, text: 'lantern b', angle: 0 },
808
+ { id: 'c', x: edgeX - 40, y: 626, text: 'amy', angle: null },
809
+ ]);
810
+ // (the stand-in layout measures a chip by its own text, none: 20 px wide)
811
+ const half = () => 10;
812
+ assert.equal(parseFloat(chipOf('lantern').styles.left), say.rect.left - 6 - half('lantern'), 'beside the button, not under it');
813
+ assert.equal(parseFloat(chipOf('lantern b').styles.left), window.innerWidth - half('lantern b') - 6, 'an edge chip clear of the button stays at the edge');
814
+ assert.equal(parseFloat(chipOf('amy').styles.left), Math.min(edgeX - 40, window.innerWidth - half('amy') - 6), 'a chip over a friend is not moved');
815
+ // A chip too wide to stand beside the button goes over it (under it with no room over).
816
+ const wide = chipOf('lantern');
817
+ wide.size = { w: 300, h: 20 };
818
+ r.chrome.setPointers([{ id: 'a', x: edgeX, y: 626, text: 'lantern', angle: 0 }]);
819
+ assert.equal(parseFloat(wide.styles.left), window.innerWidth - 150 - 6);
820
+ assert.equal(parseFloat(wide.styles.top), say.rect.top - 6 - 10, 'over the button');
821
+ say.rect = { ...say.rect, top: 10, bottom: 62 };
822
+ r.chrome.setPointers([{ id: 'a', x: edgeX, y: 30, text: 'lantern', angle: 0 }]);
823
+ assert.equal(parseFloat(wide.styles.top), 62 + 6 + 10, 'under it where there is no room over');
824
+ // With two buttons up, a move away from one never lands on the other.
825
+ const emote = r.made.find((c) => c.tag === 'button' && c.styles.right === '20px' && c.styles.width === '52px' && c !== say);
826
+ say.rect = { ...say.rect, top: 600, bottom: 652 };
827
+ emote.styles.display = 'block';
828
+ emote.style.display = 'block';
829
+ emote.rect = { left: say.rect.left, right: say.rect.right, top: 542, bottom: 594 };
830
+ r.chrome.setPointers([{ id: 'a', x: edgeX, y: 626, text: 'lantern', angle: 0 }]);
831
+ assert.equal(parseFloat(wide.styles.top), 542 - 6 - 10, 'over the whole column');
832
+ wide.size = undefined;
833
+ r.chrome.setPointers([{ id: 'a', x: edgeX, y: 626, text: 'lantern', angle: 0 }]);
834
+ assert.equal(parseFloat(wide.styles.left), say.rect.left - 6 - 10, 'a narrow chip goes left of the column');
835
+ emote.styles.display = 'none';
836
+ emote.style.display = 'none';
837
+ say.rect = { ...say.rect, top: 600, bottom: 652 };
838
+ // With the button hidden, the chip is at the edge as before.
839
+ r.chrome.setSay(null);
840
+ r.chrome.setPointers([{ id: 'a', x: edgeX, y: 626, text: 'lantern', angle: 0 }]);
841
+ assert.equal(parseFloat(chipOf('lantern').styles.left), window.innerWidth - half('lantern') - 6);
842
+ n += 1;
843
+ }
844
+
845
+ // v1.35: the NPC talk panel. A reply is scrolled to its first word, the
846
+ // player's own line to the end of the log, and a player who has scrolled up to
847
+ // read is left where they are. The log has no layout here, so its numbers are
848
+ // set by hand: each line lies where the last one ended.
849
+ {
850
+ const r = rig();
851
+ const logNode = r.dom?.made?.find?.((c) => c.styles.maxHeight === '28vh') ?? r.made.find((c) => c.styles.maxHeight === '28vh' && c.styles.overflowY === 'auto');
852
+ assert.ok(logNode, 'the talk log');
853
+ Object.assign(logNode, { offsetTop: 40, clientHeight: 100, scrollTop: 0, scrollHeight: 0 });
854
+ // Adds a line `height` tall as the browser would lay it out.
855
+ const add = (who, height) => {
856
+ const before = logNode.children.length;
857
+ const top = 40 + logNode.scrollHeight;
858
+ const made = logNode.appendChild;
859
+ logNode.appendChild = (child) => {
860
+ child.offsetTop = top;
861
+ logNode.scrollHeight += height;
862
+ return made.call(logNode, child);
863
+ };
864
+ r.chrome.talkLine(who, 'words');
865
+ logNode.appendChild = made;
866
+ assert.equal(logNode.children.length, before + 1);
867
+ return top - 40;
868
+ };
869
+ r.chrome.openTalk('Mabel');
870
+ add('me', 30);
871
+ assert.equal(logNode.scrollTop, 30, 'my own line: the end of the log');
872
+ logNode.scrollTop = 0; // the browser stops at the end: 30 tall in 100
873
+ // A long reply: its first word at the top of what shows, not its last.
874
+ const reply = add('them', 400);
875
+ assert.equal(reply, 30);
876
+ assert.equal(logNode.scrollTop, 30, 'a long reply starts at the top of the view');
877
+ // The player reads to its end, then another reply: again from its start.
878
+ logNode.scrollTop = logNode.scrollHeight - logNode.clientHeight;
879
+ const next = add('them', 300);
880
+ assert.equal(logNode.scrollTop, next);
881
+ // Scrolled up to read something earlier: a reply does not move the view...
882
+ logNode.scrollTop = 10;
883
+ add('them', 200);
884
+ assert.equal(logNode.scrollTop, 10, 'a player who scrolled up is left there');
885
+ // ...and their own next line does.
886
+ add('me', 30);
887
+ assert.equal(logNode.scrollTop, logNode.scrollHeight);
888
+ n += 1;
889
+ }
890
+
891
+ // v1.37: what to ask an NPC, as chips in the talk panel between the log and
892
+ // the field: none made until a place gives some, a tap hands back the
893
+ // question, an empty list or closing the panel takes them away.
894
+ {
895
+ const r = rig();
896
+ const panel = r.made.find((c) => (c.styles.width ?? '').startsWith('min(92vw'));
897
+ const kids = () => panel.children.length;
898
+ const before = kids();
899
+ r.chrome.openTalk('Mabel');
900
+ r.chrome.talkAsks([], null);
901
+ assert.equal(kids(), before, 'no chips row until there are chips');
902
+ const taps = [];
903
+ r.chrome.talkAsks(['What can I do here?', 'Where is the inn?', 'Who are you?', 'A fourth'], (ask) => taps.push(ask));
904
+ assert.equal(kids(), before + 1);
905
+ const row = panel.children.at(-2);
906
+ assert.equal(panel.children.at(-1).children.some((c) => c.tag === 'input'), true, 'the row sits just above the field');
907
+ assert.deepEqual([row.styles.display, row.children.map((c) => c.textContent)], ['flex', ['What can I do here?', 'Where is the inn?', 'Who are you?']]);
908
+ r.chrome.talkAsks([], null);
909
+ assert.equal(kids(), before, 'an empty list takes the row out again');
910
+ r.chrome.talkAsks(['Again?'], (ask) => taps.push(ask));
911
+ assert.equal(kids(), before + 1);
912
+ r.chrome.closeTalk();
913
+ assert.equal(kids(), before, 'closing the panel takes it out');
914
+ r.chrome.talkAsks(['Once more?'], (ask) => taps.push(ask));
915
+ r.chrome.openTalk('Rowan');
916
+ assert.equal(kids(), before, 'and the next conversation starts with the panel it always had');
917
+ n += 1;
918
+ }
919
+
920
+ // --- a goal pointer's distance (v1.39) --------------------------------------
921
+
922
+ const { goalPointers, goalText, pointerAt } = await import('../code/client/together.js');
923
+
924
+ // A vector stand-in with identity camera matrices: x/y are NDC and z says
925
+ // whether a destination is in front. Exercise the real pointer projection.
926
+ class PointerVector {
927
+ clone() { return new PointerVector().set(this.x, this.y, this.z); }
928
+ set(x, y, z) { Object.assign(this, { x, y, z }); return this; }
929
+ applyMatrix4() { return this; }
930
+ project() { return this; }
931
+ }
932
+
933
+ test('v1.81: hints draw only on screen and hidden hints never consume the nearest-goal cap', () => {
934
+ const cam = { position: new PointerVector() };
935
+ const view = { w: 400, h: 800 };
936
+ const make = (id, d, at, edge) => ({ id, d, at, label: { text: id, ...(edge === undefined ? {} : { edge }) } });
937
+ const on = { x: 0, y: 0, z: -1 };
938
+ const off = { x: 2, y: 0, z: -1 };
939
+ const behind = { x: 0, y: 0, z: 1 };
940
+ const pointer = (g) => pointerAt(cam, view, g.at, `goal:${g.id}`, goalText(g.label, g.d, 6));
941
+ const visible = make('visible hint', 10, on, false);
942
+ const side = make('edge goal', 20, off);
943
+ const back = make('behind goal', 30, behind);
944
+ const hidden = [make('off hint', 1, off, false), make('behind hint', 2, behind, false)];
945
+ assert.deepEqual(goalPointers(hidden, 2, pointer), []);
946
+ assert.deepEqual(goalPointers([back, ...hidden, side, visible], 2, pointer), [pointer(visible), pointer(side)]);
947
+ assert.equal(pointer(visible).angle, null);
948
+ assert.equal(pointer(visible).text, 'visible hint · 10 m');
949
+ assert.notEqual(pointer(side).angle, null);
950
+ assert.deepEqual(goalPointers([...hidden, back, side], 2, pointer), [pointer(side), pointer(back)]);
951
+ assert.deepEqual(goalPointers([back, side, visible], 2, pointer), [pointer(visible), pointer(side)], 'absent-key selection is unchanged');
952
+ assert.deepEqual(goalPointers([make('near hint', 3, on, false)], 2, pointer)[0].text, 'near hint');
953
+ for (const edge of [true, null, 0, 'false']) {
954
+ const g = make('legacy', 10, behind, edge);
955
+ assert.deepEqual(goalPointers([g], 2, pointer), [pointer(g)]);
956
+ }
957
+ });
958
+
959
+ test("a goal pointer's words: the measured distance as before, the place's number, or none", () => {
960
+ const NEAR = 6;
961
+ // Without the option: the straight line to the actor, beyond 6 m, as it always was.
962
+ assert.equal(goalText({ text: 'Mill', style: 'goal' }, 22.4, NEAR), 'Mill · 22 m');
963
+ assert.equal(goalText({ text: 'Mill', style: 'goal' }, 6, NEAR), 'Mill');
964
+ assert.equal(goalText({ text: 'Mill', style: 'goal' }, 6.2, NEAR), 'Mill · 6 m');
965
+ // `distanceM`: that number, whatever the pointer's own actor is from the player.
966
+ assert.equal(goalText({ text: 'Mill', style: 'goal', distanceM: 84 }, 3, NEAR), 'Mill · 84 m', 'the corner is 3 m off, the walk 84');
967
+ assert.equal(goalText({ text: 'Mill', style: 'goal', distanceM: 84 }, 300, NEAR), 'Mill · 84 m');
968
+ assert.equal(goalText({ text: 'Mill', style: 'goal', distanceM: 4 }, 300, NEAR), 'Mill', 'nearly there: no number, as for a near actor');
969
+ assert.equal(goalText({ text: 'Mill', style: 'goal', distanceM: 0 }, 300, NEAR), 'Mill');
970
+ // `distance: false`: none, however far.
971
+ assert.equal(goalText({ text: 'Mill', style: 'goal', distance: false }, 300, NEAR), 'Mill');
972
+ assert.equal(goalText({ text: 'Mill', style: 'goal', distance: false, distanceM: 84 }, 300, NEAR), 'Mill');
973
+ // Anything else is not there: measured.
974
+ for (const junk of [{ distanceM: -1 }, { distanceM: NaN }, { distanceM: Infinity }, { distanceM: '40' }, { distanceM: null }, { distance: true }, { distance: 0 }]) {
975
+ assert.equal(goalText({ text: 'Mill', style: 'goal', ...junk }, 22.4, NEAR), 'Mill · 22 m', JSON.stringify(junk));
976
+ }
977
+ });
978
+
979
+ test('a new distance alone rewrites the chip\'s words: the same node, nothing else written', () => {
980
+ const r = rig();
981
+ const at = (text) => [{ id: 'goal:corner', x: 180, y: 300, text, angle: -1.57 }];
982
+ r.chrome.setPointers(at(goalText({ text: 'Mill', distanceM: 84 }, 3, 6)));
983
+ const chip = r.pointers.children[0];
984
+ const made = r.made.length;
985
+ r.log.length = 0;
986
+ // The place sends the label again a second later with one metre less.
987
+ r.chrome.setPointers(at(goalText({ text: 'Mill', distanceM: 83 }, 3, 6)));
988
+ assert.equal(r.pointers.children.length, 1);
989
+ assert.equal(r.pointers.children[0], chip, 'the same chip');
990
+ assert.equal(r.made.length, made, 'nothing built');
991
+ const words = chip.children[1];
992
+ assert.equal(words.textContent, 'Mill · 83 m');
993
+ assert.deepEqual(r.log.filter((line) => / text=| removed| emptied| \+/.test(line)), [`${words.id} text=Mill · 83 m`], 'one write of words: no node made, moved or taken away');
994
+ // The same number again: no words written at all.
995
+ r.log.length = 0;
996
+ r.chrome.setPointers(at('Mill · 83 m'));
997
+ assert.equal(r.log.some((line) => / text=/.test(line)), false);
998
+ });
999
+
1000
+ console.log(`hub-game hud-clear: ${n} tests passed`);