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
@@ -10,6 +10,7 @@
10
10
  // rig, a child of the node the Transform places): never the Transform, the
11
11
  // body or the network pose, so nothing anyone simulates changes.
12
12
 
13
+ import { Box3, Matrix4, Vector3 } from 'three';
13
14
  import { hub, simNow } from './state.js';
14
15
 
15
16
  // The kit's emotes, in the picker's order, with the emoji drawn over the head.
@@ -28,6 +29,9 @@ export const SIT_OFFER_M = 1.5;
28
29
  // A sitter's model drops this far and tips back this much (radians).
29
30
  export const SEAT_DROP_M = 0.45;
30
31
  const SEAT_TILT = -0.1;
32
+ // Lying uses a feet-origin model, centred lengthwise and face up.
33
+ const LIE_DROP_M = 0.6;
34
+ const LIE_OFFSET_M = 0.7;
31
35
  // Input that gets a sitter up.
32
36
  const MOVE_KEYS = ['KeyW', 'KeyA', 'KeyS', 'KeyD', 'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'Space'];
33
37
  // A request is not sent again sooner than this.
@@ -35,6 +39,12 @@ const RESEND_MS = 400;
35
39
  // The emoji rises this far over the head as the emote plays.
36
40
  const EMOJI_Y = 2.25;
37
41
  const EMOJI_RISE = 0.35;
42
+ // Where the model is drawn, the emoji is put on its head instead
43
+ // (`emoteBubble.js`): the head is the top HEAD_SHARE of the model's box, and
44
+ // the emoji rises RISE_PX over it as the emote plays.
45
+ const HEAD_SHARE = 0.4;
46
+ const RISE_PX = 6;
47
+ const box = new Box3();
38
48
 
39
49
  const TAU = Math.PI * 2;
40
50
  const smooth = (t) => t * t * (3 - 2 * t);
@@ -48,20 +58,20 @@ export function emotePose(id, u, s) {
48
58
  const e = envelope(u);
49
59
  switch (id) {
50
60
  case 'wave':
51
- return { y: 0, rx: 0, ry: 0, rz: Math.sin(s * TAU * 1.6) * 0.16 * e };
61
+ return { y: Math.abs(Math.sin(s * TAU * 1.6)) * 0.08 * e, rx: 0, ry: 0, rz: Math.sin(s * TAU * 1.6) * 0.3 * e };
52
62
  case 'dance':
53
63
  return {
54
- y: Math.abs(Math.sin(s * Math.PI * 2.4)) * 0.16 * e,
64
+ y: Math.abs(Math.sin(s * Math.PI * 2.4)) * 0.24 * e,
55
65
  rx: 0,
56
- ry: Math.sin(s * TAU * 0.6) * 0.6 * e,
57
- rz: Math.sin(s * TAU * 1.2) * 0.14 * e,
66
+ ry: Math.sin(s * TAU * 0.6) * 0.8 * e,
67
+ rz: Math.sin(s * TAU * 1.2) * 0.22 * e,
58
68
  };
59
69
  case 'cheer':
60
- return { y: Math.abs(Math.sin(Math.PI * u * 3)) * 0.45, rx: -0.12 * e, ry: 0, rz: 0 };
70
+ return { y: Math.abs(Math.sin(Math.PI * u * 3)) * 0.55, rx: -0.18 * e, ry: 0, rz: 0 };
61
71
  case 'bow':
62
- return { y: 0, rx: Math.sin(Math.PI * u) * 0.6, ry: 0, rz: 0 };
72
+ return { y: 0, rx: Math.sin(Math.PI * u) * 0.8, ry: 0, rz: 0 };
63
73
  case 'spin':
64
- return { y: Math.sin(Math.PI * u) * 0.12, rx: 0, ry: TAU * smooth(u), rz: 0 };
74
+ return { y: Math.sin(Math.PI * u) * 0.2, rx: 0, ry: TAU * smooth(u), rz: 0 };
65
75
  default:
66
76
  return null;
67
77
  }
@@ -140,7 +150,7 @@ function frame(t, scene, mp, local, canAct, sceneKey) {
140
150
  t.sitPressed = false;
141
151
  // A player the place holds still cannot sit.
142
152
  const seat = hub.held.has(self) ? null : nearestSeat(t, scene, local, self, sceneKey);
143
- t.chrome.sitPrompt?.(seat ? 'Sit' : null);
153
+ t.chrome.sitPrompt?.(seat ? (scene.getActor(seat)?.components.HubSeat?.pose === 'lie' ? 'Lie down' : 'Sit') : null);
144
154
  if (seat && pressed && now - t.sentAt >= RESEND_MS) {
145
155
  t.sentAt = now;
146
156
  net.send({ k: 'hub-sit', seat });
@@ -179,7 +189,7 @@ function moving(scene) {
179
189
 
180
190
  // The nearest free, shown seat within SIT_OFFER_M of the player, or null.
181
191
  function nearestSeat(t, scene, local, self, sceneKey) {
182
- if (t.seatsFor !== sceneKey) {
192
+ if (t.seatsFor !== sceneKey || hub.place?.decor) {
183
193
  t.seatsFor = sceneKey;
184
194
  t.seats = scene
185
195
  .getActors()
@@ -195,8 +205,8 @@ function nearestSeat(t, scene, local, self, sceneKey) {
195
205
  for (const id of t.seats) {
196
206
  const actor = hub.hidden.has(id) || taken.has(id) ? null : scene.getActor(id);
197
207
  const type = actor?.components.Body?.type;
198
- if (type === 'dynamic' || type === 'kinematic') {
199
- // The server refuses a seat that can move (server/idle.js `seatOf`).
208
+ if (type === 'dynamic' || (type === 'kinematic' && !(hub.place?.decor && Object.hasOwn(hub.spawned, id)))) {
209
+ // Only a decor copy may be a moving seat (server/idle.js `seatOf`).
200
210
  continue;
201
211
  }
202
212
  const d = actor?.components.Transform ? footprintDistance(actor, me) : Infinity;
@@ -232,6 +242,16 @@ function actorOf(scene, local, playerId) {
232
242
  return playerId === self ? (local?.id ?? null) : (mp?.avatars?.actors?.get(playerId) ?? null);
233
243
  }
234
244
 
245
+ // v1.47: bodies use the same motion and emoji, with actor ids of their own.
246
+ function* emoteActors(scene, local) {
247
+ for (const [playerId, e] of Object.entries(hub.emotes)) {
248
+ yield [`emote:${playerId}`, actorOf(scene, local, playerId), e];
249
+ }
250
+ for (const [actorId, e] of Object.entries(hub.npcEmotes)) {
251
+ yield [`npc-emote:${actorId}`, actorId, e];
252
+ }
253
+ }
254
+
235
255
  // The model inside an actor's drawn node: physics-3d's model rig, the node's
236
256
  // child the Transform does not write. Null until the node is built.
237
257
  function rigOf(scene, actorId) {
@@ -248,13 +268,15 @@ function draw(t, scene, local) {
248
268
  const now = simNow();
249
269
  const add = (actorId, p) => {
250
270
  const was = poses.get(actorId) ?? { y: 0, rx: 0, ry: 0, rz: 0 };
251
- poses.set(actorId, { y: was.y + p.y, rx: was.rx + p.rx, ry: was.ry + p.ry, rz: was.rz + p.rz });
271
+ poses.set(actorId, {
272
+ y: was.y + p.y, rx: was.rx + p.rx, ry: was.ry + p.ry, rz: was.rz + p.rz,
273
+ ...(p.lie ? { lie: true, z: LIE_OFFSET_M } : {}),
274
+ });
252
275
  };
253
- for (const [playerId, e] of Object.entries(hub.emotes)) {
276
+ for (const [, actorId, e] of emoteActors(scene, local)) {
254
277
  const span = e.until - e.at;
255
278
  const u = span > 0 ? (now - e.at) / span : 1;
256
- const actorId = u >= 0 && u < 1 ? actorOf(scene, local, playerId) : null;
257
- const pose = actorId ? emotePose(e.id, u, (now - e.at) / 1000) : null;
279
+ const pose = actorId && u >= 0 && u < 1 ? emotePose(e.id, u, (now - e.at) / 1000) : null;
258
280
  if (pose) {
259
281
  add(actorId, pose);
260
282
  }
@@ -262,7 +284,14 @@ function draw(t, scene, local) {
262
284
  for (const playerId of Object.keys(hub.seated)) {
263
285
  const actorId = actorOf(scene, local, playerId);
264
286
  if (actorId) {
265
- add(actorId, { y: -SEAT_DROP_M, rx: SEAT_TILT, ry: 0, rz: 0 });
287
+ const lie = scene.getActor(hub.seated[playerId])?.components.HubSeat?.pose === 'lie';
288
+ // Front is +Z: -90 degrees puts the face up and head behind the seat.
289
+ // Feet-origin models are about 1.4 m tall; +0.7 Z centres that length.
290
+ // Cancel the standing rig's yOffset below: the back rests near the top
291
+ // of the house bed (held centre 1.36, rig origin 0.76, back about 0.56).
292
+ add(actorId, lie
293
+ ? { lie: true, y: -LIE_DROP_M, rx: -Math.PI / 2, ry: 0, rz: 0 }
294
+ : { y: -SEAT_DROP_M, rx: SEAT_TILT, ry: 0, rz: 0 });
266
295
  }
267
296
  }
268
297
  for (const [actorId, rig] of [...t.touched]) {
@@ -283,7 +312,14 @@ function draw(t, scene, local) {
283
312
  ry: rig.rotation.y,
284
313
  rz: rig.rotation.z,
285
314
  });
286
- rig.position.y = base.y + p.y;
315
+ if (p.lie && !Object.hasOwn(base, 'z')) {
316
+ base.z = rig.position.z;
317
+ }
318
+ if (Object.hasOwn(base, 'z')) {
319
+ rig.position.z = base.z + (p.z ?? 0);
320
+ }
321
+ rig.userData.hubIdleLie = Boolean(p.lie);
322
+ rig.position.y = (p.lie ? 0 : base.y) + p.y;
287
323
  rig.rotation.set(base.rx + p.rx, base.ry + p.ry, base.rz + p.rz);
288
324
  t.touched.set(actorId, rig);
289
325
  }
@@ -295,7 +331,11 @@ function restore(rig) {
295
331
  return;
296
332
  }
297
333
  rig.position.y = base.y;
334
+ if (Object.hasOwn(base, 'z')) {
335
+ rig.position.z = base.z;
336
+ }
298
337
  rig.rotation.set(base.rx, base.ry, base.rz);
338
+ delete rig.userData.hubIdleLie;
299
339
  delete rig.userData.hubIdleBase;
300
340
  }
301
341
 
@@ -311,16 +351,117 @@ function release(t) {
311
351
  function labels(scene, local, cam, view, project) {
312
352
  const out = [];
313
353
  const now = simNow();
314
- for (const [playerId, e] of Object.entries(hub.emotes)) {
354
+ for (const [id, actorId, e] of emoteActors(scene, local)) {
315
355
  const span = e.until - e.at;
316
356
  const u = span > 0 ? (now - e.at) / span : 1;
317
357
  const emoji = EMOJI[e.id];
318
- const actorId = emoji && u >= 0 && u < 1 ? actorOf(scene, local, playerId) : null;
319
- const at = actorId ? scene.getActor(actorId)?.components.Transform : null;
320
- const screen = at ? project(cam, at.x, at.y + EMOJI_Y + EMOJI_RISE * u, at.z, view) : null;
358
+ const at = actorId && emoji && u >= 0 && u < 1 ? scene.getActor(actorId)?.components.Transform : null;
359
+ if (!at) {
360
+ continue;
361
+ }
362
+ const opacity = Math.min(1, (1 - u) * 4);
363
+ // The drawn head first: a close camera looking down can have the head in
364
+ // view while a fixed height over the body is behind it.
365
+ const head = headRect(scene, actorId, cam, view, project);
366
+ if (head) {
367
+ out.push({ id, x: (head.left + head.right) / 2, y: head.top, text: emoji, emote: true, opacity, head, lift: RISE_PX * u });
368
+ continue;
369
+ }
370
+ const screen = finitePoint(project(cam, at.x, at.y + EMOJI_Y + EMOJI_RISE * u, at.z, view));
321
371
  if (screen) {
322
- out.push({ id: `emote:${playerId}`, x: screen.x, y: screen.y, text: emoji, emote: true, opacity: Math.min(1, (1 - u) * 4) });
372
+ out.push({ id, x: screen.x, y: screen.y, text: emoji, emote: true, opacity });
323
373
  }
324
374
  }
325
375
  return out;
326
376
  }
377
+
378
+ // A projected point with finite coordinates, or null.
379
+ function finitePoint(p) {
380
+ return p && Number.isFinite(p.x) && Number.isFinite(p.y) ? p : null;
381
+ }
382
+
383
+ // The head of an actor's drawn model on screen: the top HEAD_SHARE of the
384
+ // model's world box, its eight corners projected for its sides and bottom.
385
+ // Null with no model drawn, bounds that are not finite, or any corner behind
386
+ // the camera or projected to no finite point.
387
+ function headRect(scene, actorId, cam, view, project) {
388
+ const rig = rigOf(scene, actorId);
389
+ if (typeof rig?.updateWorldMatrix !== 'function') {
390
+ return null;
391
+ }
392
+ if (rig.userData.hubIdleLie) {
393
+ return lyingHeadRect(rig, cam, view, project);
394
+ }
395
+ box.setFromObject(rig);
396
+ if (box.isEmpty() || ![box.min.x, box.min.y, box.min.z, box.max.x, box.max.y, box.max.z].every(Number.isFinite)) {
397
+ return null;
398
+ }
399
+ const lo = box.max.y - (box.max.y - box.min.y) * HEAD_SHARE;
400
+ let r = null;
401
+ for (const x of [box.min.x, box.max.x]) {
402
+ for (const y of [lo, box.max.y]) {
403
+ for (const z of [box.min.z, box.max.z]) {
404
+ const p = finitePoint(project(cam, x, y, z, view));
405
+ if (!p) {
406
+ return null;
407
+ }
408
+ r = r ? { left: Math.min(r.left, p.x), right: Math.max(r.right, p.x), top: Math.min(r.top, p.y), bottom: Math.max(r.bottom, p.y) } : { left: p.x, right: p.x, top: p.y, bottom: p.y };
409
+ }
410
+ }
411
+ }
412
+ // The top is the middle of the box's top, not its far corners: a camera
413
+ // looking down sees those well above the head it draws.
414
+ const top = finitePoint(project(cam, (box.min.x + box.max.x) / 2, box.max.y, (box.min.z + box.max.z) / 2, view));
415
+ if (!top) {
416
+ return null;
417
+ }
418
+ r.top = Math.min(top.y, r.bottom);
419
+ return r;
420
+ }
421
+
422
+ // A lying model's head is still its local +Y end, even when world Y spans
423
+ // only its thickness. Gather each mesh's bounds in the rig's own frame.
424
+ function lyingHeadRect(rig, cam, view, project) {
425
+ rig.updateWorldMatrix(true, true);
426
+ const inverse = new Matrix4().copy(rig.matrixWorld).invert();
427
+ const relative = new Matrix4();
428
+ const part = new Box3();
429
+ box.makeEmpty();
430
+ rig.traverse((node) => {
431
+ if (!node.geometry) {
432
+ return;
433
+ }
434
+ if (!node.geometry.boundingBox) {
435
+ node.geometry.computeBoundingBox();
436
+ }
437
+ relative.multiplyMatrices(inverse, node.matrixWorld);
438
+ box.union(part.copy(node.geometry.boundingBox).applyMatrix4(relative));
439
+ });
440
+ if (box.isEmpty() || ![box.min.x, box.min.y, box.min.z, box.max.x, box.max.y, box.max.z].every(Number.isFinite)) {
441
+ return null;
442
+ }
443
+ const lo = box.max.y - (box.max.y - box.min.y) * HEAD_SHARE;
444
+ const point = new Vector3();
445
+ const projected = (x, y, z) => {
446
+ point.set(x, y, z).applyMatrix4(rig.matrixWorld);
447
+ return finitePoint(project(cam, point.x, point.y, point.z, view));
448
+ };
449
+ let r = null;
450
+ for (const x of [box.min.x, box.max.x]) {
451
+ for (const y of [lo, box.max.y]) {
452
+ for (const z of [box.min.z, box.max.z]) {
453
+ const p = projected(x, y, z);
454
+ if (!p) {
455
+ return null;
456
+ }
457
+ r = r ? { left: Math.min(r.left, p.x), right: Math.max(r.right, p.x), top: Math.min(r.top, p.y), bottom: Math.max(r.bottom, p.y) } : { left: p.x, right: p.x, top: p.y, bottom: p.y };
458
+ }
459
+ }
460
+ }
461
+ const top = projected((box.min.x + box.max.x) / 2, box.max.y, (box.min.z + box.max.z) / 2);
462
+ if (!top) {
463
+ return null;
464
+ }
465
+ r.top = Math.min(top.y, r.bottom);
466
+ return r;
467
+ }
@@ -0,0 +1,81 @@
1
+ // Pure frame-time policy for the optional cell-interest client cap. The hub
2
+ // system supplies frame timestamps and sends returned caps over its transport.
3
+ export const LOW_CAP = 16;
4
+ const WINDOW_MS = 3000;
5
+ const CHANGE_MS = 10000;
6
+ const RECOVER_MS = 20000;
7
+
8
+ export function makeInterestCap(full = 1000) {
9
+ let tier = null;
10
+ let limited = false;
11
+ let changedAt = -Infinity;
12
+ let goodAt = null;
13
+ let last = null;
14
+ let start = null;
15
+ let frames = [];
16
+ return {
17
+ frame(now, nextTier, counts = true) {
18
+ const dt = last === null ? 0 : now - last;
19
+ last = now;
20
+ if (!counts || dt < 0 || dt > 1000) {
21
+ frames = [];
22
+ start = null;
23
+ goodAt = null;
24
+ } else {
25
+ start ??= now;
26
+ if (dt > 0) {
27
+ frames.push([now, dt]);
28
+ }
29
+ frames = frames.filter(([at]) => now - at <= WINDOW_MS);
30
+ }
31
+ if (tier !== nextTier) {
32
+ if (tier !== null) {
33
+ changedAt = now;
34
+ }
35
+ tier = nextTier;
36
+ limited = tier === 'low';
37
+ goodAt = null;
38
+ frames = [];
39
+ start = null;
40
+ return limited ? LOW_CAP : full;
41
+ }
42
+ if (tier === 'low' || start === null || now - start < WINDOW_MS || !frames.length) {
43
+ return null;
44
+ }
45
+ const sorted = frames.map(([, ms]) => ms).sort((a, b) => a - b);
46
+ const p95 = sorted[Math.ceil(sorted.length * 0.95) - 1];
47
+ if (limited) {
48
+ goodAt = p95 < 28 ? (goodAt ?? now) : null;
49
+ if (goodAt !== null && now - goodAt >= RECOVER_MS && now - changedAt >= CHANGE_MS) {
50
+ limited = false;
51
+ changedAt = now;
52
+ goodAt = null;
53
+ return full;
54
+ }
55
+ } else if (p95 > 40 && now - changedAt >= CHANGE_MS) {
56
+ limited = true;
57
+ changedAt = now;
58
+ goodAt = null;
59
+ return LOW_CAP;
60
+ }
61
+ return null;
62
+ },
63
+ };
64
+ }
65
+
66
+ export function mergeDictionary(current, delta) {
67
+ const next = { ...current };
68
+ for (const [id, value] of Object.entries(delta)) {
69
+ if (value === null) {
70
+ delete next[id];
71
+ } else {
72
+ Object.defineProperty(next, id, {
73
+ value,
74
+ enumerable: true,
75
+ configurable: true,
76
+ writable: true,
77
+ });
78
+ }
79
+ }
80
+ return next;
81
+ }
@@ -46,3 +46,39 @@ export function guardScrollKeys(win = globalThis) {
46
46
  win.addEventListener?.('keydown', onKey);
47
47
  return () => win.removeEventListener?.('keydown', onKey);
48
48
  }
49
+
50
+ // Whether this frame should ask for the keyboard as the place starts. A deck
51
+ // page gives its frame no focus until a click, so on a desktop WASD and the
52
+ // arrows went to the page around it. Only where a keyboard is how the place
53
+ // is played and nothing else is likely to want it: Castle's web player (not
54
+ // the editor, the CLI or the app), the deck's own page (the frame's parent is
55
+ // the top page: not an embed on another site, not a Discord activity), and a
56
+ // mouse (a phone or tablet is left alone).
57
+ export function wantsKeys(win = globalThis) {
58
+ const embed = win.CastleEmbed;
59
+ if (embed?.host !== 'web' || embed.edit) {
60
+ return false;
61
+ }
62
+ if (!win.parent || win.parent === win || win.parent !== win.top) {
63
+ return false;
64
+ }
65
+ if (win.matchMedia?.('(pointer: fine)')?.matches !== true) {
66
+ return false;
67
+ }
68
+ return win.document?.hasFocus?.() !== true;
69
+ }
70
+
71
+ // Takes the keyboard where `wantsKeys` says so; returns whether it asked.
72
+ // Chrome and Firefox grant a frame's own `focus()` without a click; Safari
73
+ // ignores it, and there the first click still does it.
74
+ export function takeKeys(win = globalThis) {
75
+ if (!wantsKeys(win)) {
76
+ return false;
77
+ }
78
+ try {
79
+ win.focus();
80
+ } catch {
81
+ return false;
82
+ }
83
+ return true;
84
+ }
@@ -0,0 +1,205 @@
1
+ // A town's labels kept near and apart (contract v1.43, the deck's
2
+ // `hub.labels: "near"`), with no DOM in it so `scripts/test-labels.mjs` can
3
+ // hold it. The hub system calls in here only in a deck that asks, and only in
4
+ // a place that is not a game; without the key nothing here runs.
5
+ //
6
+ // The world labels are what `hub.label` puts over scene actors as a plate
7
+ // (plain or `"tag"`), an NPC's line (`"speech"`) or a `"sign"`. The attention
8
+ // rule (`attention.js`) already picks the one plate and the one line a player
9
+ // stands by. This adds, for a world too wide for signs seen from anywhere:
10
+ // - a sign is drawn only near the player: from SIGN_NEAR_M, until SIGN_FAR_M;
11
+ // - no two world labels overlap: the more important one is drawn;
12
+ // - at most MAX are drawn at once.
13
+ // Goal and friend pointers, players' own bubbles, emotes and marks, name tags,
14
+ // a cabinet's card, the ribbon and the "Stuck?" chip are not world labels:
15
+ // they are never given to this, never counted and never hidden by it.
16
+
17
+ // A sign comes on this near the player (on the ground, not from the camera:
18
+ // zooming out brings nothing in) and is kept until this far.
19
+ export const SIGN_NEAR_M = 12;
20
+ export const SIGN_FAR_M = 14;
21
+ // Over the last of the way out it thins, so nothing is drawn past SIGN_FAR_M.
22
+ const SIGN_THIN_M = 1;
23
+ export const MAX = 3;
24
+ // A label drawn counts as this much nearer, so two equally near do not swap.
25
+ export const STICK_M = 0.75;
26
+ // A label taken down for another (or for being one too many) comes back only
27
+ // when it clears the others by this much, and no sooner than this after it
28
+ // went: no label goes and comes and goes inside HIDE_MS, whatever passes in
29
+ // front of it. While it waits it keeps its place among the MAX, so the next
30
+ // one down the order does not flash up in it for that moment.
31
+ export const CLEAR_PX = 8;
32
+ export const HIDE_MS = 2000;
33
+ // Coming or going by distance, a label fades over this long.
34
+ const FADE_MS = 250;
35
+
36
+ import { pushBelow } from './hudClear.js';
37
+
38
+ const RANK = { plate: 0, speech: 1, sign: 2 };
39
+
40
+ export function makeNear() {
41
+ return {
42
+ // id -> opacity of every label drawn or fading
43
+ alpha: new Map(),
44
+ // the signs in reach, and the labels chosen on the last frame
45
+ reach: new Set(),
46
+ chosen: new Set(),
47
+ // id -> when it was last taken down for another label or the cap
48
+ downAt: new Map(),
49
+ at: 0,
50
+ };
51
+ }
52
+
53
+ // The rule's state belongs to one visit: one loaded scene, on one connection,
54
+ // in one place as the server last said it. `holder` keeps the state and what
55
+ // it was made for; anything else and it starts again, so nothing held, in
56
+ // reach or half faded is carried into another scene, across a reconnect or
57
+ // past the hub's state being cleared. `scope` is
58
+ // `{ scene, data, net, place }`: the scene's key (another scene: the hub
59
+ // system's `enterScene`), the loaded scene's data (a new object on every
60
+ // load, the same scene loaded again included: the engine's `reset`), the
61
+ // connection (a new one on every join), and the place's manifest (`state.js`
62
+ // `clear()` drops it, and each join is told a new one).
63
+ export function nearFor(holder, scope) {
64
+ const was = holder.scope;
65
+ if (!holder.state || !was || was.scene !== scope.scene || was.data !== scope.data || was.net !== scope.net || was.place !== scope.place) {
66
+ holder.state = makeNear();
67
+ holder.scope = { scene: scope.scene, data: scope.data, net: scope.net, place: scope.place };
68
+ }
69
+ return holder.state;
70
+ }
71
+
72
+ const touch = (a, b, pad) => a.left - pad < b.right && b.left - pad < a.right && a.top - pad < b.bottom && b.top - pad < a.bottom;
73
+ const inView = (box, view) => box.right > 0 && box.left < view.w && box.bottom > 0 && box.top < view.h;
74
+
75
+ // `items` is every world label the place has up for this player that may be
76
+ // drawn: `{ id, kind, pick, d, mine, box }`. `kind` is 'plate', 'speech' or
77
+ // 'sign'; `pick` whether a plate or a line is the attention rule's own for
78
+ // this frame (one that is not may only finish fading); `d` its actor's
79
+ // distance from the player on the ground; `mine`
80
+ // whether it was said to this player alone; `box` where its label would lie,
81
+ // `{ left, right, top, bottom }` in CSS pixels, or null when its actor is not
82
+ // in front of the camera. `view` is `{ w, h }`. Returns the labels to draw,
83
+ // id -> opacity.
84
+ export function near(s, items, view, now) {
85
+ const dt = s.at ? Math.min(100, Math.max(0, now - s.at)) : FADE_MS;
86
+ s.at = now;
87
+ const live = new Map();
88
+ const want = [];
89
+ for (const item of items) {
90
+ live.set(item.id, item);
91
+ if (item.kind === 'sign') {
92
+ if (item.d <= (s.reach.has(item.id) ? SIGN_FAR_M : SIGN_NEAR_M)) {
93
+ s.reach.add(item.id);
94
+ } else {
95
+ s.reach.delete(item.id);
96
+ continue;
97
+ }
98
+ }
99
+ if (item.box && inView(item.box, view) && (item.kind === 'sign' || item.pick)) {
100
+ want.push(item);
101
+ }
102
+ }
103
+ for (const id of s.reach) {
104
+ if (!live.has(id)) {
105
+ s.reach.delete(id);
106
+ }
107
+ }
108
+ // The more important first: the plate stood by, the NPC's line, then signs
109
+ // by how near; one said to this player before one said to everyone.
110
+ const felt = (item) => item.d - (s.chosen.has(item.id) ? STICK_M : 0);
111
+ const order = (a, b) => RANK[a.kind] - RANK[b.kind] || felt(a) - felt(b) || Number(b.mine === true) - Number(a.mine === true) || (a.id < b.id ? -1 : 1);
112
+ want.sort(order);
113
+ const chosen = [];
114
+ let places = 0;
115
+ for (const item of want) {
116
+ const was = s.chosen.has(item.id);
117
+ // One not drawn waits out its time down, and for clear air.
118
+ const waits = !was && now - (s.downAt.get(item.id) ?? -Infinity) < HIDE_MS;
119
+ const pad = was ? 0 : CLEAR_PX;
120
+ if (places < MAX && !waits && !chosen.some((c) => touch(item.box, c.box, pad))) {
121
+ chosen.push(item);
122
+ places += 1;
123
+ } else if (was || waits) {
124
+ if (was) {
125
+ s.downAt.set(item.id, now);
126
+ }
127
+ places += 1;
128
+ }
129
+ }
130
+ s.chosen = new Set(chosen.map((c) => c.id));
131
+ const shown = new Map();
132
+ const step = dt / FADE_MS;
133
+ for (const item of chosen) {
134
+ const alpha = Math.min(1, (s.alpha.get(item.id) ?? 0) + step);
135
+ s.alpha.set(item.id, alpha);
136
+ if (alpha * thin(item) > 0) {
137
+ shown.set(item.id, alpha * thin(item));
138
+ }
139
+ }
140
+ // What was drawn and is not chosen fades out where it lies -- but every box
141
+ // drawn this frame, at any opacity, is held to the one rule: no two touch.
142
+ // The fading are taken in the same order of importance after the chosen;
143
+ // one whose box touches a box already taken (a chosen label's, or an
144
+ // earlier fading one's), or that would be one too many, is gone at once.
145
+ const fading = [];
146
+ for (const [id, was] of s.alpha) {
147
+ const item = live.get(id);
148
+ if (s.chosen.has(id)) {
149
+ continue;
150
+ }
151
+ if (item?.box && inView(item.box, view) && (was - step) * thin(item) > 0) {
152
+ fading.push(item);
153
+ } else {
154
+ s.alpha.delete(id);
155
+ }
156
+ }
157
+ fading.sort(order);
158
+ const taken = chosen.map((c) => c.box);
159
+ for (const item of fading) {
160
+ if (taken.length < MAX && !taken.some((box) => touch(item.box, box, 0))) {
161
+ const alpha = s.alpha.get(item.id) - step;
162
+ taken.push(item.box);
163
+ s.alpha.set(item.id, alpha);
164
+ shown.set(item.id, alpha * thin(item));
165
+ } else {
166
+ s.alpha.delete(item.id);
167
+ }
168
+ }
169
+ for (const id of s.downAt.keys()) {
170
+ if (!live.has(id)) {
171
+ s.downAt.delete(id);
172
+ }
173
+ }
174
+ return shown;
175
+ }
176
+
177
+ // A sign's share of its opacity by distance: whole to within SIGN_THIN_M of
178
+ // SIGN_FAR_M, nothing at it.
179
+ function thin(item) {
180
+ return item.kind === 'sign' ? Math.max(0, Math.min(1, (SIGN_FAR_M - item.d) / SIGN_THIN_M)) : 1;
181
+ }
182
+
183
+ // Where a label of `size` (`{ w, h }`) will lie when the frame is drawn, for
184
+ // the screen point (x, y) it hangs over: centred on it with its bottom edge
185
+ // there, an NPC's line kept on the screen sideways (`chrome.js` `setLabels`),
186
+ // and then, in a place with a clear HUD (v1.26), moved down from under the
187
+ // HUD's box exactly as the chrome's flush will move it (`hudClear.js`
188
+ // `pushBelow`; `hud` is that box, or null where there is none to clear).
189
+ // The rule judges these boxes, so they must be the final ones.
190
+ export function labelBox(x, y, size, npc, view, hud = null) {
191
+ const half = size.w / 2;
192
+ const cx = npc ? Math.min(Math.max(x, half + 6), view.w - half - 6) : x;
193
+ const box = { left: cx - half, right: cx + half, top: y - size.h, bottom: y };
194
+ const down = pushBelow(box, hud, undefined, view.h);
195
+ return down > 0 ? { left: box.left, right: box.right, top: box.top + down, bottom: box.bottom + down } : box;
196
+ }
197
+
198
+ // What the chrome is given for a world label the rule chose (`setLabels`):
199
+ // its words, its `box` -- the one the rule judged, which the chrome draws it
200
+ // in -- and an id for its node. The chrome styles a node once, as a plate or
201
+ // as a line, so a label that turns from one into the other gets another node:
202
+ // the one drawn is always styled as the one that was measured.
203
+ export function chromeItem(id, text, speech, npc, box, opacity) {
204
+ return { id: speech ? `${id}\u0000${npc ? 'npc' : 'speech'}` : id, x: (box.left + box.right) / 2, y: box.bottom, text, speech, npc, box, opacity };
205
+ }
@@ -0,0 +1,34 @@
1
+ // Small monochrome silhouettes of the kit's earned shapes and hat ids.
2
+ // IDs are validated against earned.js/HATS on the server, never a new catalogue.
3
+ const PATHS = {
4
+ 'badge-round': 'M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18',
5
+ 'badge-star': 'm12 2 3 6 7 1-5 5 1 7-6-3-6 3 1-7-5-5 7-1z',
6
+ 'badge-shield': 'M3 4 12 2 21 4v8c0 5-9 10-9 10S3 17 3 12z',
7
+ 'pin-round': 'M12 3a7 7 0 1 0 0 14a7 7 0 1 0 0-14M11 17h2v5h-2z',
8
+ 'belt-plain': 'M2 8h20v8H2zM9 7v10h6V7z',
9
+ 'sash-plain': 'm3 2 19 17-3 3L2 5z',
10
+ 'held-lantern': 'M8 2h8v4h-2V4h-4v2H8zM6 6h12l2 14H4z',
11
+ 'held-trophy': 'M7 3h10v9l-4 4v4h5v2H6v-2h5v-4l-4-4zM2 4h4v3H4v3l3 2v3l-5-4zM18 4h4v7l-5 4v-3l3-2V7h-2z',
12
+ 'held-net': 'M5 2h14v11H5zM11 13h2v9h-2zM7 4v7h10V4z',
13
+ 'held-ball': 'M12 2a10 10 0 1 0 0 20a10 10 0 1 0 0-20',
14
+ sweatband: 'M2 9h20v6H2z',
15
+ cap: 'M4 14V9a8 8 0 0 1 16 0v5H4M4 14h19v3H4z',
16
+ 'foam-crown': 'm3 18-1-12 6 5 4-8 4 8 6-5-1 12z',
17
+ laurel: 'M11 21C1 18 0 6 7 2l2 3C4 8 5 16 11 18zM13 21v-3c6-2 7-10 2-13l2-3c7 4 6 16-4 19',
18
+ 'bat-clip': 'm1 5 7 4 4-3 4 3 7-4-2 10-5-2-4 5-4-5-5 2z',
19
+ witch: 'm12 2 7 15H5zM1 17h22v4H1z',
20
+ lantern: 'M8 2h8v4H8zM6 6h12l2 14H4z',
21
+ 'crooked-top': 'm7 4 11-2-2 6 3 10H5zM1 18h22v4H1z',
22
+ straw: 'M6 7h12l2 9H4zM1 16h22v4H1z',
23
+ 'flower-crown': 'M2 9h20v6H2zM3 5h5v5H3zM10 3h5v7h-5zM17 5h5v5h-5z',
24
+ beekeeper: 'M6 3h12l2 6H4zM2 9h20v3H2zM4 12h16v10H4z',
25
+ sunflower: 'm12 1 3 5 6-1-1 6 3 3-5 3 1 6-6-1-3 3-3-5-6 1 1-6-3-3 5-3-1-6 6 1z',
26
+ sailor: 'M3 7h18l-3 10H6zM4 17h16v4H4z',
27
+ souwester: 'M5 5h14l2 10 2 4H1l2-4z',
28
+ captain: 'M3 6h18l-2 8H5zM4 14h16v4H4zM8 18h14v3H8z',
29
+ lighthouse: 'M9 2h6v4H9zM7 6h10l3 16H4z',
30
+ };
31
+ export function menuIcon(icon) {
32
+ const path = PATHS[icon];
33
+ return path ? `url("data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="black" fill-rule="evenodd" d="${path}"/></svg>`)}")` : null;
34
+ }
@@ -22,7 +22,11 @@ const RESOLVE_TIMEOUT_MS = 12000;
22
22
  // The engine's own files laid over every pack: the kit's avatar blueprints and
23
23
  // everything they draw (models, art, from whichever import holds them) are the
24
24
  // town's, whatever a game was built with (contract §11, HUB.md decision 4).
25
+ // So are the hats a player wears (v1.41, `wear.js`), drawn from the kit's models.
25
26
  const AVATAR_BLUEPRINT = /^(imports\/castle\.hub-game\/)?blueprints\/((blocky|bean|pixel)\/)?avatar-\d+\.scene$/;
27
+ const HAT_MODEL = /^(imports\/castle\.hub-game\/)?models\/hats\/[a-z-]+\.pxmodel$/;
28
+ // And the earned items (v1.53, `earned.js`).
29
+ const EARNED_MODEL = /^(imports\/castle\.hub-game\/)?models\/earned\/(square\/)?[a-z0-9-]+\.pxmodel$/;
26
30
 
27
31
  const cache = new Map();
28
32
 
@@ -170,7 +174,7 @@ function buildContent(sha256, pack, baseFiles) {
170
174
  };
171
175
  }
172
176
 
173
- // The avatar blueprints and every file they reach, the way the exporter
177
+ // The avatar blueprints, hat and earned models, and every file they reach, the way the exporter
174
178
  // follows a place's scene (scripts/pack.mjs): a string naming a file the
175
179
  // engine has is a reference, as written or inside the referencing import.
176
180
  // Computed once per page: the engine's files do not change under it.
@@ -181,7 +185,7 @@ function avatarClosure(baseFiles) {
181
185
  }
182
186
  const has = (path) => typeof baseFiles[path] === 'string' || Boolean(initialMedia[path]);
183
187
  const seen = new Set();
184
- const queue = Object.keys(baseFiles).filter((path) => AVATAR_BLUEPRINT.test(path));
188
+ const queue = Object.keys(baseFiles).filter((path) => AVATAR_BLUEPRINT.test(path) || HAT_MODEL.test(path) || EARNED_MODEL.test(path));
185
189
  while (queue.length) {
186
190
  const path = queue.shift();
187
191
  if (seen.has(path)) {