castle-web-cli 0.4.232 → 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 (355) 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/shell/assets/{index-D2tWM896.js → index-BjOxR-lW.js} +4 -4
  28. package/dist/shell/assets/index-MVLfNYd9.css +1 -0
  29. package/dist/shell/index.html +2 -2
  30. package/dist/taskSteer.d.ts +13 -0
  31. package/dist/taskSteer.js +22 -2
  32. package/kits/base/castle.json +1 -1
  33. package/kits/base/package-lock.json +1 -1
  34. package/kits/base/sdk/README.md +79 -2
  35. package/kits/base/sdk/avatar.d.ts +6 -2
  36. package/kits/base/sdk/avatar.js +12 -4
  37. package/kits/base/sdk/castle.d.ts +1 -1
  38. package/kits/base/sdk/commands.d.ts +14 -0
  39. package/kits/base/sdk/hub.d.ts +6 -2
  40. package/kits/base/sdk/hub.js +13 -0
  41. package/kits/base/sdk/multiplayer.js +17 -1
  42. package/kits/base/sdk/save.js +2 -1
  43. package/kits/base/sdk/server/hub.d.ts +87 -0
  44. package/kits/base/sdk/server/hub.js +70 -0
  45. package/kits/base/sdk/server/platformHandle.d.ts +31 -1
  46. package/kits/base/sdk/server/storage.d.ts +13 -0
  47. package/kits/base/sdk/server/storage.js +46 -0
  48. package/kits/base/sdk/server/wrapper.d.ts +36 -5
  49. package/kits/base/sdk/server/wrapper.js +83 -8
  50. package/kits/hub-game/CLAUDE.md +329 -11
  51. package/kits/hub-game/blueprints/avatar-10.scene +28 -0
  52. package/kits/hub-game/blueprints/avatar-11.scene +28 -0
  53. package/kits/hub-game/blueprints/avatar-12.scene +28 -0
  54. package/kits/hub-game/blueprints/avatar-13.scene +28 -0
  55. package/kits/hub-game/blueprints/avatar-14.scene +28 -0
  56. package/kits/hub-game/blueprints/avatar-15.scene +28 -0
  57. package/kits/hub-game/blueprints/avatar-4.scene +28 -0
  58. package/kits/hub-game/blueprints/avatar-5.scene +28 -0
  59. package/kits/hub-game/blueprints/avatar-6.scene +28 -0
  60. package/kits/hub-game/blueprints/avatar-7.scene +28 -0
  61. package/kits/hub-game/blueprints/avatar-8.scene +28 -0
  62. package/kits/hub-game/blueprints/avatar-9.scene +28 -0
  63. package/kits/hub-game/code/client/actorBudget.js +47 -0
  64. package/kits/hub-game/code/client/attention.js +11 -2
  65. package/kits/hub-game/code/client/avatar.js +309 -35
  66. package/kits/hub-game/code/client/avatarCap.js +228 -0
  67. package/kits/hub-game/code/client/avatarColors.js +70 -0
  68. package/kits/hub-game/code/client/avatarFaces.js +21 -0
  69. package/kits/hub-game/code/client/avatarShare.js +251 -0
  70. package/kits/hub-game/code/client/ballot.js +467 -0
  71. package/kits/hub-game/code/client/build.js +22 -0
  72. package/kits/hub-game/code/client/chrome.js +1144 -50
  73. package/kits/hub-game/code/client/companion.js +716 -0
  74. package/kits/hub-game/code/client/companionDress.js +99 -0
  75. package/kits/hub-game/code/client/decor.js +509 -0
  76. package/kits/hub-game/code/client/earned.js +131 -0
  77. package/kits/hub-game/code/client/emoteBubble.js +75 -0
  78. package/kits/hub-game/code/client/grab.js +339 -20
  79. package/kits/hub-game/code/client/hookLayer.js +299 -13
  80. package/kits/hub-game/code/client/idle.js +163 -22
  81. package/kits/hub-game/code/client/interestCap.js +81 -0
  82. package/kits/hub-game/code/client/keys.js +36 -0
  83. package/kits/hub-game/code/client/labelsNear.js +205 -0
  84. package/kits/hub-game/code/client/menuIcons.js +34 -0
  85. package/kits/hub-game/code/client/pack.js +6 -2
  86. package/kits/hub-game/code/client/packFormat.js +3 -3
  87. package/kits/hub-game/code/client/rehello.js +167 -0
  88. package/kits/hub-game/code/client/shot.js +92 -0
  89. package/kits/hub-game/code/client/sound.js +63 -8
  90. package/kits/hub-game/code/client/soundscape.js +1151 -0
  91. package/kits/hub-game/code/client/soundscapeActions.js +99 -0
  92. package/kits/hub-game/code/client/soundscapeAmbience.js +453 -0
  93. package/kits/hub-game/code/client/soundscapeBaked.js +143 -0
  94. package/kits/hub-game/code/client/soundscapeBusker.js +217 -0
  95. package/kits/hub-game/code/client/soundscapeCourt.js +200 -0
  96. package/kits/hub-game/code/client/soundscapeCrowd.js +331 -0
  97. package/kits/hub-game/code/client/soundscapeCues.js +362 -0
  98. package/kits/hub-game/code/client/soundscapeMap.js +181 -0
  99. package/kits/hub-game/code/client/soundscapeMarket.js +176 -0
  100. package/kits/hub-game/code/client/soundscapeMusic.js +126 -0
  101. package/kits/hub-game/code/client/soundscapeMusicEngine.js +460 -0
  102. package/kits/hub-game/code/client/soundscapeSimlish.js +737 -0
  103. package/kits/hub-game/code/client/soundscapeSongs.js +127 -0
  104. package/kits/hub-game/code/client/soundscapeSongsRound3.js +63 -0
  105. package/kits/hub-game/code/client/soundscapeSynthesis.js +168 -0
  106. package/kits/hub-game/code/client/soundscapeUi.js +211 -0
  107. package/kits/hub-game/code/client/soundscapeVoice.js +1209 -0
  108. package/kits/hub-game/code/client/soundscapeWaves.js +206 -0
  109. package/kits/hub-game/code/client/spin.js +101 -0
  110. package/kits/hub-game/code/client/state.js +109 -1
  111. package/kits/hub-game/code/client/stuck.js +259 -0
  112. package/kits/hub-game/code/client/talk.js +538 -47
  113. package/kits/hub-game/code/client/tiers.js +516 -27
  114. package/kits/hub-game/code/client/toastBand.js +37 -0
  115. package/kits/hub-game/code/client/together.js +32 -0
  116. package/kits/hub-game/code/client/visibility.js +43 -0
  117. package/kits/hub-game/code/client/wear.js +461 -170
  118. package/kits/hub-game/code/client/yours.js +199 -0
  119. package/kits/hub-game/code/companionSpec.js +45 -0
  120. package/kits/hub-game/code/privateText.js +7 -0
  121. package/kits/hub-game/code/server/actions.js +133 -0
  122. package/kits/hub-game/code/server/actors.js +9 -1
  123. package/kits/hub-game/code/server/ask.js +155 -0
  124. package/kits/hub-game/code/server/ballot.js +539 -0
  125. package/kits/hub-game/code/server/cells.js +100 -0
  126. package/kits/hub-game/code/server/companion.js +82 -0
  127. package/kits/hub-game/code/server/cues.js +70 -0
  128. package/kits/hub-game/code/server/decor.js +269 -0
  129. package/kits/hub-game/code/server/earned.js +461 -0
  130. package/kits/hub-game/code/server/friendBests.js +166 -0
  131. package/kits/hub-game/code/server/friendsAmong.js +232 -0
  132. package/kits/hub-game/code/server/history.js +5 -0
  133. package/kits/hub-game/code/server/hub.js +1254 -50
  134. package/kits/hub-game/code/server/idle.js +30 -11
  135. package/kits/hub-game/code/server/index.js +2 -2
  136. package/kits/hub-game/code/server/labels.js +28 -2
  137. package/kits/hub-game/code/server/manifest.js +378 -7
  138. package/kits/hub-game/code/server/menu.js +133 -0
  139. package/kits/hub-game/code/server/npcs.js +830 -80
  140. package/kits/hub-game/code/server/party.js +2 -2
  141. package/kits/hub-game/code/server/players.js +22 -0
  142. package/kits/hub-game/code/server/shot.js +110 -0
  143. package/kits/hub-game/code/server/standing.js +124 -0
  144. package/kits/hub-game/code/server/vis.js +113 -0
  145. package/kits/hub-game/code/server/wear.js +12 -0
  146. package/kits/hub-game/code/server/yours.js +59 -0
  147. package/kits/hub-game/code/shared/cues.js +9 -0
  148. package/kits/hub-game/code/shared/decor.js +41 -0
  149. package/kits/hub-game/code/shared/shot.js +19 -0
  150. package/kits/hub-game/code/shared/spin.js +57 -0
  151. package/kits/hub-game/code/systems/hub.js +845 -95
  152. package/kits/hub-game/docs/content-pack.md +1 -1
  153. package/kits/hub-game/docs/contract.md +2244 -61
  154. package/kits/hub-game/docs/home-pieces.md +64 -0
  155. package/kits/hub-game/models/avatar-10.pxmodel +28 -0
  156. package/kits/hub-game/models/avatar-11.pxmodel +28 -0
  157. package/kits/hub-game/models/avatar-12.pxmodel +27 -0
  158. package/kits/hub-game/models/avatar-13.pxmodel +24 -0
  159. package/kits/hub-game/models/avatar-14.pxmodel +29 -0
  160. package/kits/hub-game/models/avatar-15.pxmodel +24 -0
  161. package/kits/hub-game/models/avatar-4.pxmodel +29 -0
  162. package/kits/hub-game/models/avatar-5.pxmodel +27 -0
  163. package/kits/hub-game/models/avatar-6.pxmodel +26 -0
  164. package/kits/hub-game/models/avatar-7.pxmodel +25 -0
  165. package/kits/hub-game/models/avatar-8.pxmodel +24 -0
  166. package/kits/hub-game/models/avatar-9.pxmodel +30 -0
  167. package/kits/hub-game/models/earned/badge-round.pxmodel +100 -0
  168. package/kits/hub-game/models/earned/badge-shield.pxmodel +117 -0
  169. package/kits/hub-game/models/earned/badge-star.pxmodel +87 -0
  170. package/kits/hub-game/models/earned/belt-plain.pxmodel +72 -0
  171. package/kits/hub-game/models/earned/held-ball.pxmodel +43 -0
  172. package/kits/hub-game/models/earned/held-lantern.pxmodel +85 -0
  173. package/kits/hub-game/models/earned/held-net.pxmodel +57 -0
  174. package/kits/hub-game/models/earned/held-trophy.pxmodel +109 -0
  175. package/kits/hub-game/models/earned/pin-round.pxmodel +62 -0
  176. package/kits/hub-game/models/earned/sash-plain.pxmodel +66 -0
  177. package/kits/hub-game/models/earned/square/belt-plain.pxmodel +104 -0
  178. package/kits/hub-game/models/earned/square/sash-plain.pxmodel +98 -0
  179. package/kits/hub-game/models/hats/bat-clip.pxmodel +206 -0
  180. package/kits/hub-game/models/hats/beekeeper.pxmodel +149 -0
  181. package/kits/hub-game/models/hats/cap.pxmodel +162 -0
  182. package/kits/hub-game/models/hats/captain.pxmodel +178 -0
  183. package/kits/hub-game/models/hats/crooked-top.pxmodel +172 -0
  184. package/kits/hub-game/models/hats/flower-crown.pxmodel +451 -0
  185. package/kits/hub-game/models/hats/foam-crown.pxmodel +179 -0
  186. package/kits/hub-game/models/hats/lantern.pxmodel +230 -0
  187. package/kits/hub-game/models/hats/laurel.pxmodel +533 -0
  188. package/kits/hub-game/models/hats/lighthouse.pxmodel +96 -0
  189. package/kits/hub-game/models/hats/sailor.pxmodel +141 -0
  190. package/kits/hub-game/models/hats/souwester.pxmodel +131 -0
  191. package/kits/hub-game/models/hats/straw.pxmodel +139 -0
  192. package/kits/hub-game/models/hats/sunflower.pxmodel +406 -0
  193. package/kits/hub-game/models/hats/sweatband.pxmodel +112 -0
  194. package/kits/hub-game/models/hats/witch.pxmodel +147 -0
  195. package/kits/hub-game/package-lock.json +2 -0
  196. package/kits/hub-game/package.json +2 -1
  197. package/kits/hub-game/scripts/check.mjs +78 -11
  198. package/kits/hub-game/scripts/companion-follower-wire.json +1 -0
  199. package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +121 -0
  200. package/kits/hub-game/scripts/fixtures/decor-keyless.json +293 -0
  201. package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +23 -0
  202. package/kits/hub-game/scripts/fixtures/fake-dom.mjs +107 -0
  203. package/kits/hub-game/scripts/fixtures/interest-legacy.json +385 -0
  204. package/kits/hub-game/scripts/fixtures/npc-notes-v1.77.jsonl +4 -0
  205. package/kits/hub-game/scripts/fixtures/vis-shared-wire.json +1 -0
  206. package/kits/hub-game/scripts/gen-avatars.mjs +933 -16
  207. package/kits/hub-game/scripts/gen-earned.mjs +285 -0
  208. package/kits/hub-game/scripts/gen-hats.mjs +827 -0
  209. package/kits/hub-game/scripts/grab.before-orbit.mjs +400 -0
  210. package/kits/hub-game/scripts/soundscape-wave-analysis.mjs +125 -0
  211. package/kits/hub-game/scripts/test-actions-client.mjs +488 -0
  212. package/kits/hub-game/scripts/test-actions.mjs +298 -0
  213. package/kits/hub-game/scripts/test-actor-budget.mjs +44 -0
  214. package/kits/hub-game/scripts/test-actors.mjs +19 -17
  215. package/kits/hub-game/scripts/test-ask-client.mjs +358 -0
  216. package/kits/hub-game/scripts/test-ask.mjs +269 -0
  217. package/kits/hub-game/scripts/test-attention.mjs +10 -1
  218. package/kits/hub-game/scripts/test-avatar-cap.mjs +379 -0
  219. package/kits/hub-game/scripts/test-avatar-colors.mjs +72 -0
  220. package/kits/hub-game/scripts/test-avatar-models.mjs +181 -0
  221. package/kits/hub-game/scripts/test-avatar-share.mjs +318 -0
  222. package/kits/hub-game/scripts/test-avatar-wire.mjs +753 -0
  223. package/kits/hub-game/scripts/test-avatar.mjs +540 -7
  224. package/kits/hub-game/scripts/test-ballot.mjs +1001 -0
  225. package/kits/hub-game/scripts/test-build.mjs +31 -0
  226. package/kits/hub-game/scripts/test-cells.mjs +71 -0
  227. package/kits/hub-game/scripts/test-chat.mjs +662 -0
  228. package/kits/hub-game/scripts/test-classic.mjs +2 -0
  229. package/kits/hub-game/scripts/test-companion-chat.mjs +198 -0
  230. package/kits/hub-game/scripts/test-companion-client.mjs +1167 -0
  231. package/kits/hub-game/scripts/test-companion.mjs +259 -0
  232. package/kits/hub-game/scripts/test-decor-client.mjs +303 -0
  233. package/kits/hub-game/scripts/test-decor.mjs +457 -0
  234. package/kits/hub-game/scripts/test-earned-client.mjs +459 -0
  235. package/kits/hub-game/scripts/test-earned.mjs +1194 -0
  236. package/kits/hub-game/scripts/test-emote-bubble.mjs +110 -0
  237. package/kits/hub-game/scripts/test-friend-bests.mjs +435 -0
  238. package/kits/hub-game/scripts/test-grab-orbit.mjs +918 -0
  239. package/kits/hub-game/scripts/test-grab.mjs +7 -0
  240. package/kits/hub-game/scripts/test-hats.mjs +422 -168
  241. package/kits/hub-game/scripts/test-hub-leaving.mjs +203 -0
  242. package/kits/hub-game/scripts/test-hub-ops.mjs +439 -2
  243. package/kits/hub-game/scripts/test-hub-trip.mjs +716 -2
  244. package/kits/hub-game/scripts/test-hud-clear.mjs +328 -4
  245. package/kits/hub-game/scripts/test-idle.mjs +361 -1
  246. package/kits/hub-game/scripts/test-interest-cap.mjs +36 -0
  247. package/kits/hub-game/scripts/test-interest-cells.mjs +493 -0
  248. package/kits/hub-game/scripts/test-interest-client.mjs +118 -0
  249. package/kits/hub-game/scripts/test-keys.mjs +46 -1
  250. package/kits/hub-game/scripts/test-labels.mjs +596 -0
  251. package/kits/hub-game/scripts/test-manifest.mjs +207 -0
  252. package/kits/hub-game/scripts/test-menu-client.mjs +480 -0
  253. package/kits/hub-game/scripts/test-menu.mjs +296 -0
  254. package/kits/hub-game/scripts/test-npcs.mjs +1718 -12
  255. package/kits/hub-game/scripts/test-object-entry.mjs +76 -0
  256. package/kits/hub-game/scripts/test-pack.mjs +7 -0
  257. package/kits/hub-game/scripts/test-picker.mjs +314 -0
  258. package/kits/hub-game/scripts/test-rehello.mjs +1039 -0
  259. package/kits/hub-game/scripts/test-relations-among.mjs +222 -0
  260. package/kits/hub-game/scripts/test-relations-refresh.mjs +188 -0
  261. package/kits/hub-game/scripts/test-shot.mjs +756 -0
  262. package/kits/hub-game/scripts/test-soundscape.mjs +5432 -0
  263. package/kits/hub-game/scripts/test-spin.mjs +314 -0
  264. package/kits/hub-game/scripts/test-standing.mjs +416 -0
  265. package/kits/hub-game/scripts/test-stuck.mjs +1903 -0
  266. package/kits/hub-game/scripts/test-tier-cells.mjs +706 -0
  267. package/kits/hub-game/scripts/test-tiers-render.mjs +339 -0
  268. package/kits/hub-game/scripts/test-tiers.mjs +477 -2
  269. package/kits/hub-game/scripts/test-toast-band.mjs +61 -0
  270. package/kits/hub-game/scripts/test-try-on.mjs +22 -22
  271. package/kits/hub-game/scripts/test-vis.mjs +343 -0
  272. package/kits/hub-game/scripts/test-visibility.mjs +134 -0
  273. package/kits/hub-game/scripts/test-yours-chrome.mjs +166 -0
  274. package/kits/hub-game/scripts/test-yours.mjs +372 -0
  275. package/kits/multiplayer-3d/CLAUDE.md +50 -0
  276. package/kits/multiplayer-3d/castle.json +5 -5
  277. package/kits/multiplayer-3d/code/client/avatars.js +7 -0
  278. package/kits/multiplayer-3d/code/client/gait.js +65 -0
  279. package/kits/multiplayer-3d/code/client/nameTags.js +59 -4
  280. package/kits/multiplayer-3d/code/options.js +5 -0
  281. package/kits/multiplayer-3d/code/server/ownership.js +10 -2
  282. package/kits/multiplayer-3d/code/server/sceneBodies.js +12 -0
  283. package/kits/multiplayer-3d/code/server/world.js +7 -0
  284. package/kits/multiplayer-3d/code/systems/multiplayer.js +74 -4
  285. package/kits/multiplayer-3d/package.json +2 -1
  286. package/kits/multiplayer-3d/scripts/fixtures/README.md +11 -0
  287. package/kits/multiplayer-3d/scripts/fixtures/ownership-legacy.json +2 -0
  288. package/kits/multiplayer-3d/scripts/ownership-harness.mjs +102 -0
  289. package/kits/multiplayer-3d/scripts/ownership-loader.mjs +46 -0
  290. package/kits/multiplayer-3d/scripts/ownership-worker.mjs +15 -0
  291. package/kits/multiplayer-3d/scripts/record-ownership-session.mjs +98 -0
  292. package/kits/multiplayer-3d/scripts/test-eligible-claims.mjs +167 -0
  293. package/kits/multiplayer-3d/scripts/test-own-name-tag.mjs +247 -0
  294. package/kits/physics-2d/CLAUDE.md +9 -0
  295. package/kits/physics-2d/castle.json +2 -2
  296. package/kits/physics-2d/engine/scene.js +253 -1
  297. package/kits/physics-2d/engine/skyKey.js +129 -0
  298. package/kits/physics-2d/engine/stillClock.js +106 -0
  299. package/kits/physics-2d/engine/updateBudget.js +21 -0
  300. package/kits/physics-2d/scripts/test-skip-unchanged.mjs +326 -1
  301. package/kits/physics-3d/CLAUDE.md +1169 -30
  302. package/kits/physics-3d/behaviors/Player.jsx +629 -72
  303. package/kits/physics-3d/castle.json +3 -3
  304. package/kits/physics-3d/docs/pxmodel-format.md +8 -0
  305. package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +69 -13
  306. package/kits/physics-3d/engine3d/actornode.js +86 -0
  307. package/kits/physics-3d/engine3d/animationBudget.js +23 -0
  308. package/kits/physics-3d/engine3d/editorWorld.js +6 -0
  309. package/kits/physics-3d/engine3d/emptynodes.js +232 -0
  310. package/kits/physics-3d/engine3d/framecap.js +96 -0
  311. package/kits/physics-3d/engine3d/gait.js +118 -0
  312. package/kits/physics-3d/engine3d/kithooks.js +47 -0
  313. package/kits/physics-3d/engine3d/look.js +507 -48
  314. package/kits/physics-3d/engine3d/lookbake.js +208 -0
  315. package/kits/physics-3d/engine3d/materialpresets.js +2 -0
  316. package/kits/physics-3d/engine3d/motion.js +39 -10
  317. package/kits/physics-3d/engine3d/nearshadows.js +37 -19
  318. package/kits/physics-3d/engine3d/optimize.js +9 -5
  319. package/kits/physics-3d/engine3d/orbitinput.js +487 -9
  320. package/kits/physics-3d/engine3d/orbitlens.js +48 -0
  321. package/kits/physics-3d/engine3d/ownmodel.js +213 -0
  322. package/kits/physics-3d/engine3d/pxmodel.js +42 -11
  323. package/kits/physics-3d/engine3d/shadowfade.js +882 -0
  324. package/kits/physics-3d/engine3d/sky.js +547 -0
  325. package/kits/physics-3d/engine3d/skylife.js +306 -0
  326. package/kits/physics-3d/engine3d/unchanged.js +11 -0
  327. package/kits/physics-3d/engine3d/viewrange.js +52 -0
  328. package/kits/physics-3d/engine3d/world3d.js +796 -69
  329. package/kits/physics-3d/main.jsx +5 -0
  330. package/kits/physics-3d/package.json +1 -1
  331. package/kits/physics-3d/scripts/look-baseline.mjs +155 -0
  332. package/kits/physics-3d/scripts/test-camera-orbit.mjs +2563 -80
  333. package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +1 -1
  334. package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +435 -0
  335. package/kits/physics-3d/scripts/test-frame-cap.mjs +452 -0
  336. package/kits/physics-3d/scripts/test-gait.mjs +387 -0
  337. package/kits/physics-3d/scripts/test-look-bake.mjs +1056 -0
  338. package/kits/physics-3d/scripts/test-model-parse-cache.mjs +92 -0
  339. package/kits/physics-3d/scripts/test-near-shadows.mjs +3 -0
  340. package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1920 -0
  341. package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +545 -0
  342. package/kits/physics-3d/scripts/test-orbit-shot.mjs +583 -0
  343. package/kits/physics-3d/scripts/test-orbit-view.mjs +230 -0
  344. package/kits/physics-3d/scripts/test-skip-empty-nodes.mjs +845 -0
  345. package/kits/physics-3d/scripts/test-sky.mjs +2470 -0
  346. package/kits/physics-3d/scripts/test-static-actors.mjs +8 -1
  347. package/kits/physics-3d/scripts/test-static-scenery.mjs +2171 -0
  348. package/kits/physics-3d/scripts/test-steady-hover.mjs +2 -0
  349. package/kits/physics-3d/scripts/test-view-range.mjs +260 -0
  350. package/kits/physics-3d/systems/physics3d.js +383 -6
  351. package/kits/real-time/castle.json +2 -2
  352. package/kits/real-time/code/server/gameHooks.js +7 -0
  353. package/kits/real-time/code/server/session.js +97 -19
  354. package/package.json +2 -2
  355. package/dist/shell/assets/index-Cf61cNfT.css +0 -1
@@ -0,0 +1,99 @@
1
+ // v1.78: folded paper additions; the undressed songbird stays in companion.js.
2
+ import * as THREE from 'three';
3
+ const TINTS = { rose: '#ee91ad', mint: '#87d8b0', midnight: '#39436b', gold: '#eab94e' };
4
+ const PAPER = { owl: '#98704b', parrot: '#4caf68', hummingbird: '#45bba1' };
5
+
6
+ export function paperSpecies(group, species, mesh, triangle) {
7
+ group.scale.setScalar(2.2);
8
+ group.userData.flutter = species === 'hummingbird' ? 22 : 4;
9
+ group.add(mesh(new THREE.OctahedronGeometry(0.06), '#ffd27a', true));
10
+ const body = mesh(new THREE.OctahedronGeometry(species === 'hummingbird' ? 0.037 : 0.052), PAPER[species]);
11
+ body.scale.set(species === 'owl' ? 0.95 : 0.7, species === 'owl' ? 1.05 : 0.85, 1.05);
12
+ body.userData.paper = true;
13
+ const head = mesh(new THREE.TetrahedronGeometry(species === 'owl' ? 0.041 : 0.029), species === 'owl' ? '#ead9b0' : PAPER[species]);
14
+ head.position.set(0, 0.032, 0.04);
15
+ head.userData.paper = species !== 'owl';
16
+ group.add(body, head);
17
+ for (const side of [-1, 1]) {
18
+ const wing = triangle([0, 0.015, 0.025, side * 0.11, 0.032, -0.035, side * 0.015, 0, -0.055], species === 'hummingbird' ? (side > 0 ? '#70d6bc' : '#359b9c') : PAPER[species]);
19
+ wing.userData.wing = side;
20
+ wing.userData.paper = true;
21
+ group.add(wing);
22
+ const eye = mesh(new THREE.CircleGeometry(species === 'owl' ? 0.017 : 0.006, species === 'owl' ? 6 : 3), species === 'owl' ? '#fff0c9' : '#242538');
23
+ eye.material.side = THREE.DoubleSide;
24
+ eye.position.set(side * (species === 'owl' ? 0.02 : 0.014), 0.035, 0.065);
25
+ group.add(eye);
26
+ if (species === 'owl') {
27
+ const pupil = triangle([side * 0.02 - 0.004, 0.03, 0.066, side * 0.02 + 0.004, 0.03, 0.066, side * 0.02, 0.041, 0.066], '#242538');
28
+ const tuft = triangle([side * 0.012, 0.057, 0.025, side * 0.036, 0.081, 0.025, side * 0.036, 0.046, 0.025], PAPER.owl);
29
+ tuft.userData.paper = true;
30
+ group.add(pupil, tuft);
31
+ }
32
+ }
33
+ const tail = species === 'parrot' ? -0.13 : -0.085;
34
+ group.add(triangle([0, 0.008, -0.033, -0.026, -0.01, tail, 0.026, -0.01, tail], species === 'parrot' ? '#e65b53' : PAPER[species]));
35
+ const tip = species === 'hummingbird' ? 0.135 : 0.09;
36
+ group.add(triangle([0, 0.027, tip, -0.009, 0.022, 0.055, 0.009, 0.022, 0.055], species === 'hummingbird' ? '#344650' : '#eab94e'));
37
+ if (species === 'parrot') {
38
+ group.add(triangle([0, 0.027, tip, 0, 0.005, 0.087, 0.008, 0.022, 0.065], '#eab94e'));
39
+ }
40
+ }
41
+
42
+ export function dressBird(group, dress, mesh, triangle) {
43
+ const species = dress?.species ?? 'songbird';
44
+ // Fold dimensions, tetrahedron head widths, and head/neck attachment points.
45
+ const rig = {
46
+ songbird: { head: [0, 0.022, 0.05], neck: [0, 0.003, 0.063], width: 0.05, length: 0.13 },
47
+ owl: { head: [0, 0.057, 0.04], neck: [0, 0.016, 0.058], width: 0.041 * 2 / Math.sqrt(3), length: 0.1092 },
48
+ parrot: { head: [0, 0.05, 0.04], neck: [0, 0.014, 0.058], width: 0.029 * 2 / Math.sqrt(3), length: 0.1092 },
49
+ hummingbird: { head: [0, 0.05, 0.04], neck: [0, 0.014, 0.058], width: 0.029 * 2 / Math.sqrt(3), length: 0.0777 },
50
+ }[species];
51
+ const anchor = new THREE.Group();
52
+ anchor.name = 'companion:hat-anchor';
53
+ anchor.position.set(...rig.head);
54
+ group.add(anchor);
55
+ group.userData.hatAnchor = anchor;
56
+ if (dress?.tint) {
57
+ group.traverse((node) => {
58
+ if (node.userData.paper || node.material?.color?.getHexString() === 'fff6e6') {
59
+ node.material.color.set(TINTS[dress.tint]);
60
+ }
61
+ });
62
+ }
63
+ if (!dress?.wear) { return; }
64
+ const worn = new THREE.Group();
65
+ worn.name = `companion:wear:${dress.wear}`;
66
+ group.userData.worn = worn;
67
+ if (['bow', 'scarf'].includes(dress.wear)) {
68
+ worn.position.set(...rig.neck);
69
+ worn.scale.setScalar(rig.width / 0.076);
70
+ group.add(worn);
71
+ worn.add(triangle([-0.038, 0.016, 0, 0, 0, 0.008, -0.033, -0.012, 0, 0.038, 0.016, 0, 0.033, -0.012, 0, 0, 0, 0.008], '#d6607d'));
72
+ if (dress.wear === 'scarf') {
73
+ worn.add(triangle([0, 0, 0.008, -0.01, -0.055, 0, 0.016, -0.045, 0], '#d6607d'));
74
+ }
75
+ } else {
76
+ anchor.add(worn);
77
+ if (dress.wear === 'flowercrown') {
78
+ worn.scale.setScalar(rig.width / 0.074);
79
+ const ring = mesh(new THREE.RingGeometry(0.025, 0.037, 6), '#76ac70');
80
+ ring.rotation.x = -Math.PI / 2;
81
+ ring.material.side = THREE.DoubleSide;
82
+ worn.add(ring);
83
+ for (let i = 0; i < 5; i++) {
84
+ const flower = mesh(new THREE.TetrahedronGeometry(0.012), i % 2 ? '#efb85c' : '#ec91b6');
85
+ flower.position.set(Math.cos(i * Math.PI * 0.4) * 0.032, 0.007, Math.sin(i * Math.PI * 0.4) * 0.032);
86
+ worn.add(flower);
87
+ }
88
+ } else {
89
+ const color = { tophat: '#53426d', sunhat: '#e5c777', stampcap: '#83a9c1' }[dress.wear];
90
+ const brimRadius = rig.width * (dress.wear === 'sunhat' ? 0.6 : 0.55);
91
+ const brimHeight = 0.003;
92
+ const height = dress.wear === 'tophat' ? rig.length / 3 : rig.length / 7;
93
+ const brim = mesh(new THREE.CylinderGeometry(brimRadius, brimRadius, brimHeight, 6), color);
94
+ const crown = mesh(new THREE.CylinderGeometry(rig.width * 0.35, rig.width * 0.4, height - brimHeight, 6), color);
95
+ crown.position.y = height / 2;
96
+ worn.add(brim, crown);
97
+ }
98
+ }
99
+ }
@@ -0,0 +1,509 @@
1
+ // Decorating (v1.67): private chrome and local previews. No actor or body is
2
+ // changed: the deck's server hook decides every edit and sends the catalogue
3
+ // back. Made only in a place with `decor`, under the existing chrome root.
4
+ import * as THREE from 'three';
5
+ import { hub } from './state.js';
6
+ import { fits, footprint, freeCell } from '../shared/decor.js';
7
+
8
+ const PAINT = { panel: 'rgba(29,26,35,0.96)', tile: '#55515f', gold: '#f4c66c', green: '#59df8b' };
9
+ const FONT = '600 14px/1.2 system-ui, sans-serif';
10
+
11
+ function el(tag, style, parent, text) {
12
+ const node = document.createElement(tag);
13
+ Object.assign(node.style, style);
14
+ if (text !== undefined) {
15
+ node.textContent = text;
16
+ }
17
+ parent.appendChild(node);
18
+ return node;
19
+ }
20
+
21
+ export function makeDecor(chrome, { renderer = () => new THREE.WebGLRenderer({ alpha: true, antialias: true, preserveDrawingBuffer: true }) } = {}) {
22
+ const listeners = new AbortController();
23
+ function button(parent, label, action, style = {}) {
24
+ const node = el('button', { border: '0', borderRadius: '22px', minHeight: '44px', padding: '10px 14px', font: FONT, color: '#26222b', background: '#fff', cursor: 'pointer', touchAction: 'manipulation', ...style }, parent, label);
25
+ node.type = 'button';
26
+ node.addEventListener('click', (event) => {
27
+ event.stopPropagation();
28
+ action();
29
+ }, { signal: listeners.signal });
30
+ return node;
31
+ }
32
+ const root = el('div', { position: 'absolute', inset: '0', pointerEvents: 'none', zIndex: '3', display: 'none', color: '#fff', font: FONT }, chrome.decorRoot());
33
+ const enter = button(root, '', () => send({ op: 'button' }), { position: 'absolute', right: '12px', bottom: 'max(76px, calc(env(safe-area-inset-bottom) + 66px))', background: PAINT.gold, pointerEvents: 'auto', fontSize: '16px', padding: '12px 20px' });
34
+ const header = el('div', { position: 'absolute', top: 'max(14px, env(safe-area-inset-top))', left: '50%', transform: 'translateX(-50%)', borderRadius: '24px', padding: '9px 14px', background: PAINT.panel, maxWidth: 'calc(100% - 28px)', boxSizing: 'border-box', textAlign: 'center', pointerEvents: 'auto' }, root);
35
+ el('div', { fontSize: '20px', fontWeight: '700', whiteSpace: 'nowrap' }, header, 'Decorating');
36
+ const subtitle = el('div', { fontSize: '13px', opacity: '0.78', maxWidth: '260px', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, header);
37
+ const world = el('div', { position: 'absolute', inset: '0', touchAction: 'none', pointerEvents: 'auto' }, root);
38
+ // The header and tray are above the world input surface, so scrolling a
39
+ // row never places a piece. All world gestures belong to the preview.
40
+ header.style.zIndex = '1';
41
+ const tray = el('div', { position: 'absolute', left: '0', right: '0', bottom: '0', borderRadius: '18px 18px 0 0', padding: '6px 8px max(8px, env(safe-area-inset-bottom))', background: PAINT.panel, pointerEvents: 'auto', zIndex: '1', boxSizing: 'border-box' }, root);
42
+ const tabRow = el('div', { display: 'flex', gap: '4px', overflowX: 'auto', alignItems: 'center', marginBottom: '4px', touchAction: 'pan-x', overscrollBehavior: 'contain' }, tray);
43
+ const tiles = el('div', { display: 'flex', gap: '7px', overflowX: 'auto', touchAction: 'pan-x', overscrollBehavior: 'contain', paddingBottom: '2px' }, tray);
44
+ const actions = el('div', { position: 'absolute', display: 'flex', gap: '6px', pointerEvents: 'auto', transform: 'translate(-50%, -100%)', zIndex: '2', whiteSpace: 'nowrap' }, root);
45
+ const rotate = button(actions, '⟳ Rotate', () => {
46
+ if (t.lift) {
47
+ t.lift.rot = (t.lift.rot + 1) % 4;
48
+ }
49
+ });
50
+ const stash = button(actions, 'Put away', () => {
51
+ if (t.lift?.key) {
52
+ send({ op: 'stash', key: t.lift.key });
53
+ } else {
54
+ dropGhost();
55
+ }
56
+ });
57
+ const confirm = button(actions, '✓', () => {
58
+ if (!t.lift) {
59
+ send({ op: 'close' });
60
+ } else if (fits(t.grid, t.spec.items, t.spec.placed, t.lift)) {
61
+ const { key, item, x, z, rot } = t.lift;
62
+ send(key ? { op: 'move', key, x, z, rot } : { op: 'place', item, x, z, rot });
63
+ }
64
+ }, { background: PAINT.green, minWidth: '44px' });
65
+ confirm.setAttribute('aria-label', 'Confirm placement');
66
+ const t = { root, scene: null, net: null, spec: null, grid: null, tab: null, lift: null, ghost: null, group: null, world: null, selected: null, thumbnails: new Map(), images: new Map(), renderer: null, rendererFailed: false, thumbScene: null, state: null, open: false, drag: null, sceneKey: null, wasLive: false };
67
+ const ray = new THREE.Raycaster(), point = new THREE.Vector3();
68
+ const plane = new THREE.Plane(new THREE.Vector3(0, 1, 0), 0);
69
+
70
+ function send(op) {
71
+ if (t.net) {
72
+ t.net.send({ k: 'decor', ...op });
73
+ }
74
+ }
75
+ function dropGhost() {
76
+ if (t.selected) {
77
+ t.selected.node.visible = t.selected.visible;
78
+ if (t.selected.instances) {
79
+ t.selected.instances.rigs.add(t.selected.rig);
80
+ }
81
+ t.selected = null;
82
+ }
83
+ if (t.ghost) {
84
+ t.ghost.removeFromParent();
85
+ const disposed = new Set();
86
+ t.ghost.traverse((node) => {
87
+ for (const material of (Array.isArray(node.material) ? node.material : [node.material])) {
88
+ if (material && !disposed.has(material)) {
89
+ disposed.add(material);
90
+ material.dispose();
91
+ }
92
+ }
93
+ });
94
+ }
95
+ t.ghost = null;
96
+ t.lift = null;
97
+ t.drag = null;
98
+ }
99
+ function clearWorld() {
100
+ dropGhost();
101
+ if (t.group) {
102
+ t.group.removeFromParent();
103
+ t.group.traverse((node) => {
104
+ node.geometry?.dispose();
105
+ node.material?.dispose();
106
+ });
107
+ }
108
+ t.group = null;
109
+ t.world = null;
110
+ }
111
+ function clear() {
112
+ clearWorld();
113
+ t.spec = null;
114
+ t.state = null;
115
+ t.open = false;
116
+ t.images.clear();
117
+ t.thumbnails.clear();
118
+ root.style.display = 'none';
119
+ chrome.setDecorating(false);
120
+ }
121
+ function cloneActor(id) {
122
+ const entry = t.scene?.three?.nodes.get(id);
123
+ if (!entry) {
124
+ return null;
125
+ }
126
+ const copy = entry.node.clone(true);
127
+ // An instanced actor's own node has an empty rig. Its shared model is
128
+ // what a thumbnail and a ghost draw, at the rig's authored scale.
129
+ if (entry.instancedRig) {
130
+ const model = t.scene.three.models.get(entry.modelKey)?.template;
131
+ if (!model) {
132
+ return null;
133
+ }
134
+ copy.clear();
135
+ const rig = model.clone(true);
136
+ rig.position.copy(entry.instancedRig.position);
137
+ rig.scale.copy(entry.instancedRig.scale);
138
+ copy.add(rig);
139
+ }
140
+ copy.visible = true;
141
+ copy.position.set(0, 0, 0);
142
+ copy.rotation.y = 0;
143
+ copy.updateMatrixWorld(true);
144
+ return copy;
145
+ }
146
+ function lift(piece) {
147
+ dropGhost();
148
+ t.lift = { ...piece };
149
+ drawGhost();
150
+ }
151
+ function drawGhost() {
152
+ if (!t.lift || !t.group) {
153
+ return;
154
+ }
155
+ const item = t.spec.items.find((i) => i.id === t.lift.item);
156
+ if (!t.ghost) {
157
+ const copy = cloneActor(t.lift.key ?? item.template);
158
+ if (!copy) {
159
+ return;
160
+ }
161
+ const materials = new Map();
162
+ copy.traverse((node) => {
163
+ if (node.material) {
164
+ const clone = (material) => {
165
+ if (!materials.has(material)) {
166
+ const m = material.clone();
167
+ m.transparent = true;
168
+ m.opacity = 0.8;
169
+ m.depthWrite = false;
170
+ materials.set(material, m);
171
+ }
172
+ return materials.get(material);
173
+ };
174
+ node.material = Array.isArray(node.material) ? node.material.map(clone) : clone(node.material);
175
+ }
176
+ });
177
+ t.ghost = copy;
178
+ // The ghost shares geometry with the actor, but owns its preview
179
+ // materials. Only those materials are released when the lift ends.
180
+ t.world.scene.add(copy);
181
+ if (t.lift.key) {
182
+ const entry = t.scene.three.nodes.get(t.lift.key);
183
+ const instances = entry.instancedRig ? t.scene.three.instances.get(entry.modelKey) : null;
184
+ t.selected = { node: entry.node, visible: entry.node.visible, instances, rig: entry.instancedRig };
185
+ entry.node.visible = false;
186
+ instances?.rigs.delete(entry.instancedRig);
187
+ }
188
+ }
189
+ const { w, d } = footprint(item, t.lift.rot);
190
+ t.ghost.position.set(0, 0, 0);
191
+ t.ghost.rotation.y = t.lift.rot * Math.PI / 2;
192
+ t.ghost.updateMatrixWorld(true);
193
+ const bounds = new THREE.Box3().setFromObject(t.ghost);
194
+ const middle = bounds.getCenter(new THREE.Vector3());
195
+ t.ghost.position.set(t.grid.x + (t.lift.x + w / 2) * t.grid.cell - middle.x, t.grid.y + 0.14 - bounds.min.y, t.grid.z + (t.lift.z + d / 2) * t.grid.cell - middle.z);
196
+ const valid = fits(t.grid, t.spec.items, t.spec.placed, t.lift);
197
+ t.highlight.material.color.set(valid ? PAINT.green : '#ef6471');
198
+ t.highlight.scale.set(w * t.grid.cell, d * t.grid.cell, 1);
199
+ t.highlight.position.set(t.grid.x + (t.lift.x + w / 2) * t.grid.cell, t.grid.y + 0.035, t.grid.z + (t.lift.z + d / 2) * t.grid.cell);
200
+ t.highlight.visible = true;
201
+ confirm.disabled = !valid;
202
+ confirm.style.opacity = valid ? '1' : '0.5';
203
+ }
204
+ function drawGrid() {
205
+ if (t.group && t.world === t.scene.three) {
206
+ return;
207
+ }
208
+ clearWorld();
209
+ t.world = t.scene.three;
210
+ t.group = new THREE.Group();
211
+ const g = t.grid, vertices = [];
212
+ for (let x = 0; x <= g.w; x += 1) {
213
+ vertices.push(g.x + x * g.cell, g.y + 0.025, g.z, g.x + x * g.cell, g.y + 0.025, g.z + g.d * g.cell);
214
+ }
215
+ for (let z = 0; z <= g.d; z += 1) {
216
+ vertices.push(g.x, g.y + 0.025, g.z + z * g.cell, g.x + g.w * g.cell, g.y + 0.025, g.z + z * g.cell);
217
+ }
218
+ const geometry = new THREE.BufferGeometry();
219
+ geometry.setAttribute('position', new THREE.Float32BufferAttribute(vertices, 3));
220
+ t.group.add(new THREE.LineSegments(geometry, new THREE.LineBasicMaterial({ color: '#fff3dc', transparent: true, opacity: 0.55, depthWrite: false })));
221
+ t.highlight = new THREE.Mesh(new THREE.PlaneGeometry(1, 1), new THREE.MeshBasicMaterial({ color: PAINT.green, transparent: true, opacity: 0.4, depthWrite: false, side: THREE.DoubleSide }));
222
+ t.highlight.rotation.x = -Math.PI / 2;
223
+ t.highlight.visible = false;
224
+ t.group.add(t.highlight);
225
+ t.world.scene.add(t.group);
226
+ }
227
+ function cachedThumbnail(template) {
228
+ const cached = t.thumbnails.get(template), entry = t.scene?.three?.nodes.get(template);
229
+ if (cached && cached.node === entry?.node && cached.sig === entry?.sig) {
230
+ return cached.url;
231
+ }
232
+ t.thumbnails.delete(template);
233
+ return null;
234
+ }
235
+ function thumbnail(template) {
236
+ const cached = cachedThumbnail(template);
237
+ if (cached) {
238
+ return cached;
239
+ }
240
+ if (t.scene.three.bakesLookLater && t.scene.three.lookBake?.shown === false) {
241
+ return null;
242
+ }
243
+ if (t.rendererFailed) {
244
+ return null;
245
+ }
246
+ const copy = cloneActor(template);
247
+ if (!copy) {
248
+ return null;
249
+ }
250
+ const bounds = new THREE.Box3().setFromObject(copy);
251
+ if (bounds.isEmpty()) {
252
+ return null;
253
+ }
254
+ try {
255
+ if (!t.renderer) {
256
+ t.renderer = renderer();
257
+ t.renderer.setPixelRatio(1);
258
+ t.renderer.setSize(112, 88, false);
259
+ t.renderer.setClearColor(0x000000, 0);
260
+ t.thumbScene = new THREE.Scene();
261
+ t.thumbScene.add(new THREE.HemisphereLight(0xffffff, 0x7c6c83, 2.5));
262
+ const light = new THREE.DirectionalLight(0xffffff, 3);
263
+ light.position.set(4, 6, 5);
264
+ t.thumbScene.add(light);
265
+ }
266
+ const center = bounds.getCenter(new THREE.Vector3()), size = bounds.getSize(new THREE.Vector3());
267
+ copy.position.sub(center);
268
+ const radius = Math.max(size.length() / 2, 0.1) * 1.15;
269
+ const camera = new THREE.OrthographicCamera(-radius * 112 / 88, radius * 112 / 88, radius, -radius, 0.01, radius * 12);
270
+ camera.position.set(radius * 3, radius * 2.5, radius * 3);
271
+ camera.lookAt(0, 0, 0);
272
+ t.thumbScene.add(copy);
273
+ t.renderer.render(t.thumbScene, camera);
274
+ const url = t.renderer.domElement.toDataURL('image/png');
275
+ copy.removeFromParent();
276
+ const entry = t.scene.three.nodes.get(template);
277
+ t.thumbnails.set(template, { node: entry.node, sig: entry.sig, url });
278
+ return url;
279
+ } catch {
280
+ copy.removeFromParent();
281
+ t.rendererFailed = true;
282
+ t.renderer?.dispose();
283
+ t.renderer = null;
284
+ return null;
285
+ }
286
+ }
287
+ function catalogue() {
288
+ tabRow.replaceChildren();
289
+ tiles.replaceChildren();
290
+ t.images.clear();
291
+ if (!t.spec.tabs.some((tab) => tab.id === t.tab)) {
292
+ t.tab = t.spec.tabs[0].id;
293
+ }
294
+ for (const tab of t.spec.tabs) {
295
+ const node = button(tabRow, tab.label, () => {
296
+ t.tab = tab.id;
297
+ catalogue();
298
+ }, { background: t.tab === tab.id ? PAINT.gold : '#403c49', color: t.tab === tab.id ? '#26222b' : '#ddd', minHeight: '28px', padding: '5px 6px', fontSize: '11px', whiteSpace: 'nowrap', flex: 'none', touchAction: 'pan-x' });
299
+ node.setAttribute('aria-pressed', String(t.tab === tab.id));
300
+ }
301
+ button(tabRow, 'Done ✓', () => send({ op: 'close' }), { background: PAINT.green, flex: 'none', minHeight: '28px', padding: '5px 6px', fontSize: '11px', whiteSpace: 'nowrap', touchAction: 'pan-x' });
302
+ const tile = (label, action) => button(tiles, '', action, { position: 'relative', flex: '0 0 64px', width: '64px', height: '80px', boxSizing: 'border-box', padding: '0', overflow: 'hidden', borderRadius: '10px', background: PAINT.tile, color: '#fff', display: 'flex', flexDirection: 'column', alignItems: 'stretch', touchAction: 'pan-x', fontSize: '12px' });
303
+ for (const item of t.spec.items.filter((i) => i.tab === t.tab)) {
304
+ const node = tile(item.label, () => {
305
+ if (item.locked || item.count === 0) {
306
+ return;
307
+ }
308
+ const at = t.scene.actorWith('Player')?.components.Transform ?? {};
309
+ const near = { x: ((at.x ?? t.grid.x) - t.grid.x) / t.grid.cell, z: ((at.z ?? t.grid.z) - t.grid.z) / t.grid.cell };
310
+ const cell = freeCell(t.grid, t.spec.items, t.spec.placed, item, near);
311
+ // A full layer still lets the owner preview a red footprint.
312
+ lift({ item: item.id, x: cell?.x ?? 0, z: cell?.z ?? 0, rot: 0, layer: item.layer });
313
+ });
314
+ node.setAttribute('aria-label', `${item.label}${item.locked ? ` · Locked · ${item.locked.price}` : ` · ${item.count} spare`}`);
315
+ node.disabled = Boolean(item.locked || item.count === 0);
316
+ node.style.opacity = item.locked || item.count === 0 ? '0.65' : '1';
317
+ const image = el('img', { width: '64px', height: '54px', flex: 'none', objectFit: 'contain', pointerEvents: 'none' }, node);
318
+ image.alt = '';
319
+ t.images.set(image, item.template);
320
+ if (!item.locked && item.count >= 2) {
321
+ el('span', { position: 'absolute', top: '4px', left: '4px', background: PAINT.green, color: '#17241b', borderRadius: '9px', padding: '1px 5px', fontSize: '11px' }, node, `×${item.count}`);
322
+ }
323
+ if (item.locked) {
324
+ el('span', { position: 'absolute', right: '4px', top: '4px', fontSize: '13px' }, node, '🔒');
325
+ }
326
+ el('div', { padding: item.locked ? '0 3px' : '5px 3px', lineHeight: item.locked ? '14px' : '16px', flex: 'none', background: 'rgba(0,0,0,0.15)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, node, item.label);
327
+ if (item.locked) {
328
+ el('div', { padding: '0 3px', flex: 'none', color: PAINT.gold, fontSize: '11px', lineHeight: '12px', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, node, item.locked.price);
329
+ }
330
+ }
331
+ for (const swatch of (t.spec.swatches ?? []).filter((s) => s.tab === t.tab)) {
332
+ const node = tile(swatch.label, () => send({ op: 'swatch', swatch: swatch.id }));
333
+ node.setAttribute('aria-label', swatch.label);
334
+ el('div', { background: swatch.color, borderRadius: '50%', width: '40px', height: '40px', flex: 'none', margin: '7px auto' }, node);
335
+ el('div', { padding: '5px 3px', lineHeight: '16px', flex: 'none', background: 'rgba(0,0,0,0.15)' }, node, swatch.label);
336
+ }
337
+ }
338
+ function cellAt(event) {
339
+ const camera = t.scene?.three?.camera;
340
+ if (!camera || !t.grid) {
341
+ return null;
342
+ }
343
+ const rect = root.getBoundingClientRect();
344
+ ray.setFromCamera(new THREE.Vector2((event.clientX - rect.left) / rect.width * 2 - 1, 1 - (event.clientY - rect.top) / rect.height * 2), camera);
345
+ plane.constant = -t.grid.y;
346
+ if (!ray.ray.intersectPlane(plane, point)) {
347
+ return null;
348
+ }
349
+ return { x: Math.floor((point.x - t.grid.x) / t.grid.cell), z: Math.floor((point.z - t.grid.z) / t.grid.cell) };
350
+ }
351
+ function pick(cell) {
352
+ // Mesh hits pick tall pieces at their drawn location. Instanced pieces
353
+ // have no meshes in their node: the floor footprint is their fallback.
354
+ const nodes = t.spec.placed.map((p) => t.scene.three.nodes.get(p.key)?.node).filter(Boolean);
355
+ const hits = ray.intersectObjects(nodes, true);
356
+ for (const hit of hits) {
357
+ let node = hit.object;
358
+ while (node && !nodes.includes(node)) {
359
+ node = node.parent;
360
+ }
361
+ const piece = t.spec.placed.find((p) => t.scene.three.nodes.get(p.key)?.node === node);
362
+ if (piece) {
363
+ return piece;
364
+ }
365
+ }
366
+ return [...t.spec.placed].reverse().find((piece) => {
367
+ const item = t.spec.items.find((i) => i.id === piece.item), size = footprint(item, piece.rot);
368
+ return cell.x >= piece.x && cell.z >= piece.z && cell.x < piece.x + size.w && cell.z < piece.z + size.d;
369
+ });
370
+ }
371
+ world.addEventListener('pointerdown', (event) => {
372
+ if (!t.open || (event.button !== undefined && event.button !== 0)) {
373
+ return;
374
+ }
375
+ event.preventDefault();
376
+ event.stopPropagation();
377
+ const cell = cellAt(event);
378
+ if (!cell) {
379
+ return;
380
+ }
381
+ if (!t.lift) {
382
+ const piece = pick(cell);
383
+ if (piece) {
384
+ lift(piece);
385
+ t.drag = { id: event.pointerId, dx: cell.x - piece.x, dz: cell.z - piece.z };
386
+ }
387
+ } else {
388
+ t.lift.x = cell.x;
389
+ t.lift.z = cell.z;
390
+ t.drag = { id: event.pointerId, dx: 0, dz: 0 };
391
+ }
392
+ world.setPointerCapture?.(event.pointerId);
393
+ }, { signal: listeners.signal });
394
+ world.addEventListener('pointermove', (event) => {
395
+ if (!t.lift || t.drag?.id !== event.pointerId) {
396
+ return;
397
+ }
398
+ event.preventDefault();
399
+ event.stopPropagation();
400
+ const cell = cellAt(event);
401
+ if (cell) {
402
+ t.lift.x = cell.x - t.drag.dx;
403
+ t.lift.z = cell.z - t.drag.dz;
404
+ }
405
+ }, { signal: listeners.signal });
406
+ const up = (event) => {
407
+ if (t.drag?.id === event.pointerId) {
408
+ t.drag = null;
409
+ }
410
+ };
411
+ world.addEventListener('pointerup', up, { signal: listeners.signal });
412
+ world.addEventListener('pointercancel', up, { signal: listeners.signal });
413
+ root.addEventListener('pointerdown', (event) => event.stopPropagation(), { signal: listeners.signal });
414
+
415
+ return {
416
+ opened: () => t.open,
417
+ clear,
418
+ frame(scene, mp, local, canAct) {
419
+ const state = hub.decor;
420
+ const live = Boolean(hub.place?.decor && mp.net && (mp.joinState?.() ?? 'joined') === 'joined');
421
+ if (!live || !canAct || !scene.three) {
422
+ if (t.open) {
423
+ clearWorld();
424
+ }
425
+ t.open = false;
426
+ root.style.display = 'none';
427
+ chrome.setDecorating(false);
428
+ if (!live && t.wasLive) {
429
+ delete hub.decor;
430
+ t.state = null;
431
+ }
432
+ t.wasLive = live;
433
+ return;
434
+ }
435
+ t.wasLive = true;
436
+ const key = scene.sceneKey ?? scene.currentScenePath;
437
+ if (key !== t.sceneKey) {
438
+ clear();
439
+ t.sceneKey = key;
440
+ }
441
+ t.scene = scene;
442
+ t.net = mp.net;
443
+ t.open = Boolean(state?.spec && state.grid);
444
+ root.style.display = state && (state.button || t.open) ? 'block' : 'none';
445
+ enter.style.display = state?.button && !t.open ? 'block' : 'none';
446
+ enter.textContent = state?.button ?? '';
447
+ world.style.display = header.style.display = tray.style.display = t.open ? 'block' : 'none';
448
+ chrome.setDecorating(t.open);
449
+ if (!t.open) {
450
+ clearWorld();
451
+ actions.style.display = 'none';
452
+ t.state = state;
453
+ return;
454
+ }
455
+ if (state !== t.state) {
456
+ dropGhost();
457
+ if (JSON.stringify(state.grid) !== JSON.stringify(t.grid)) {
458
+ clearWorld();
459
+ }
460
+ t.spec = state.spec;
461
+ t.grid = state.grid;
462
+ t.state = state;
463
+ subtitle.textContent = t.spec.title ?? '';
464
+ subtitle.style.display = t.spec.title ? 'block' : 'none';
465
+ catalogue();
466
+ }
467
+ drawGrid();
468
+ // At most one new offscreen render per frame; cached thumbnails can
469
+ // fill the rest immediately. Hidden templates are still renderable.
470
+ let rendered = false;
471
+ for (const [image, template] of t.images) {
472
+ const cached = cachedThumbnail(template);
473
+ if (!cached && rendered) {
474
+ continue;
475
+ }
476
+ const url = cached ?? thumbnail(template);
477
+ rendered ||= !cached && Boolean(url);
478
+ if (url && image.src !== url) {
479
+ image.src = url;
480
+ }
481
+ }
482
+ t.highlight.visible = false;
483
+ actions.style.display = t.lift ? 'flex' : 'none';
484
+ if (t.lift) {
485
+ drawGhost();
486
+ rotate.disabled = false;
487
+ stash.textContent = t.lift.key ? 'Put away' : 'Cancel';
488
+ const p = t.ghost?.position.clone().project(scene.three.camera);
489
+ const rect = root.getBoundingClientRect();
490
+ const trayTop = tray.getBoundingClientRect().top - rect.top;
491
+ const x = p && p.z < 1 && p.z > -1 ? (p.x + 1) * rect.width / 2 : rect.width / 2;
492
+ const y = p && p.z < 1 && p.z > -1 ? (1 - p.y) * rect.height / 2 - 42 : trayTop - 16;
493
+ actions.style.left = `${Math.max(145, Math.min(rect.width - 145, x))}px`;
494
+ actions.style.top = `${Math.max(header.offsetHeight + 82, Math.min(trayTop - 12, y))}px`;
495
+ }
496
+ },
497
+ dispose() {
498
+ listeners.abort();
499
+ clear();
500
+ t.renderer?.dispose();
501
+ t.renderer?.forceContextLoss?.();
502
+ t.renderer = null;
503
+ t.thumbScene = null;
504
+ t.scene = null;
505
+ t.net = null;
506
+ root.remove();
507
+ },
508
+ };
509
+ }