castle-web-cli 0.4.233 → 0.4.235

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 (383) hide show
  1. package/dist/api.d.ts +11 -0
  2. package/dist/api.js +43 -0
  3. package/dist/bundle.d.ts +64 -0
  4. package/dist/bundle.js +558 -2
  5. package/dist/castle-host/host.d.ts +17 -2
  6. package/dist/castle-host/host.js +793 -36
  7. package/dist/castleJson.d.ts +20 -1
  8. package/dist/castleJson.js +44 -2
  9. package/dist/check.js +9 -2
  10. package/dist/chunkLoader.d.ts +3 -0
  11. package/dist/chunkLoader.js +111 -0
  12. package/dist/devParty.d.ts +26 -0
  13. package/dist/devParty.js +231 -0
  14. package/dist/devSaveStorage.js +4 -0
  15. package/dist/devSessionStorage.js +3 -1
  16. package/dist/devSocial.d.ts +24 -0
  17. package/dist/devSocial.js +70 -0
  18. package/dist/ide.d.ts +2 -0
  19. package/dist/ide.js +119 -15
  20. package/dist/index.js +8 -2
  21. package/dist/init.js +1 -1
  22. package/dist/save-deck.d.ts +20 -1
  23. package/dist/save-deck.js +141 -5
  24. package/dist/serve.js +29 -11
  25. package/dist/shell/assets/{index-BjOxR-lW.js → index-DulbYIJm.js} +97 -97
  26. package/dist/shell/index.html +1 -1
  27. package/dist/vitePlugins.d.ts +2 -1
  28. package/dist/vitePlugins.js +13 -0
  29. package/kits/base/castle.json +1 -1
  30. package/kits/base/sdk/README.md +266 -3
  31. package/kits/base/sdk/castle.d.ts +7 -3
  32. package/kits/base/sdk/castle.js +2 -0
  33. package/kits/base/sdk/commands.d.ts +162 -1
  34. package/kits/base/sdk/commands.js +3 -0
  35. package/kits/base/sdk/display.d.ts +3 -0
  36. package/kits/base/sdk/display.js +9 -3
  37. package/kits/base/sdk/hub.d.ts +33 -6
  38. package/kits/base/sdk/hub.js +68 -5
  39. package/kits/base/sdk/hubRejoin.d.ts +4 -0
  40. package/kits/base/sdk/hubRejoin.js +15 -0
  41. package/kits/base/sdk/multiplayer.d.ts +7 -1
  42. package/kits/base/sdk/multiplayer.js +147 -40
  43. package/kits/base/sdk/multiplayerProtocol.d.ts +2 -0
  44. package/kits/base/sdk/party.d.ts +23 -0
  45. package/kits/base/sdk/party.js +91 -0
  46. package/kits/base/sdk/reconnectBudget.d.ts +23 -0
  47. package/kits/base/sdk/reconnectBudget.js +96 -0
  48. package/kits/base/sdk/save.d.ts +38 -1
  49. package/kits/base/sdk/save.js +79 -6
  50. package/kits/base/sdk/server/hub.d.ts +31 -1
  51. package/kits/base/sdk/server/hub.js +50 -3
  52. package/kits/base/sdk/server/platformHandle.d.ts +13 -1
  53. package/kits/base/sdk/server/storage.d.ts +4 -0
  54. package/kits/base/sdk/server/storage.js +19 -3
  55. package/kits/base/sdk/server/wrapper.d.ts +7 -1
  56. package/kits/base/sdk/server/wrapper.js +10 -1
  57. package/kits/base/sdk/social.d.ts +9 -0
  58. package/kits/base/sdk/social.js +5 -0
  59. package/kits/hub-game/CLAUDE.md +123 -3
  60. package/kits/hub-game/README.md +63 -0
  61. package/kits/hub-game/castle.json +5 -5
  62. package/kits/hub-game/code/client/act.js +312 -0
  63. package/kits/hub-game/code/client/actionLayout.js +147 -0
  64. package/kits/hub-game/code/client/actionOverflow.js +556 -0
  65. package/kits/hub-game/code/client/arrivalCamera.js +50 -0
  66. package/kits/hub-game/code/client/askSlot.js +117 -0
  67. package/kits/hub-game/code/client/avatar.js +4 -2
  68. package/kits/hub-game/code/client/avatarShare.js +2 -0
  69. package/kits/hub-game/code/client/backVisibility.js +13 -0
  70. package/kits/hub-game/code/client/ballot.js +15 -10
  71. package/kits/hub-game/code/client/build.js +16 -0
  72. package/kits/hub-game/code/client/chat.js +41 -5
  73. package/kits/hub-game/code/client/chatModeration.js +5 -0
  74. package/kits/hub-game/code/client/chrome.js +1148 -258
  75. package/kits/hub-game/code/client/crowdNames.js +241 -0
  76. package/kits/hub-game/code/client/decor.js +10 -4
  77. package/kits/hub-game/code/client/defaultEnvironment.js +194 -0
  78. package/kits/hub-game/code/client/doorErrors.js +39 -0
  79. package/kits/hub-game/code/client/fall.js +18 -0
  80. package/kits/hub-game/code/client/farAvatars.js +233 -0
  81. package/kits/hub-game/code/client/firstJoin.js +9 -2
  82. package/kits/hub-game/code/client/fpsTelemetry.js +50 -0
  83. package/kits/hub-game/code/client/frameBatch.js +5 -0
  84. package/kits/hub-game/code/client/grab.js +31 -11
  85. package/kits/hub-game/code/client/hookLayer.js +87 -8
  86. package/kits/hub-game/code/client/hudCopy.js +51 -0
  87. package/kits/hub-game/code/client/hudRate.js +20 -0
  88. package/kits/hub-game/code/client/idle.js +14 -2
  89. package/kits/hub-game/code/client/invites.js +231 -0
  90. package/kits/hub-game/code/client/joinError.js +9 -0
  91. package/kits/hub-game/code/client/labelsNear.js +31 -2
  92. package/kits/hub-game/code/client/landscapeLayout.js +17 -0
  93. package/kits/hub-game/code/client/layoutCache.js +264 -0
  94. package/kits/hub-game/code/client/loadTelemetry.js +20 -0
  95. package/kits/hub-game/code/client/loadingCover.js +148 -0
  96. package/kits/hub-game/code/client/loadingEntry.js +8 -0
  97. package/kits/hub-game/code/client/menuRows.js +43 -0
  98. package/kits/hub-game/code/client/modelReady.js +7 -0
  99. package/kits/hub-game/code/client/padCueArrival.js +23 -0
  100. package/kits/hub-game/code/client/padCues.js +112 -0
  101. package/kits/hub-game/code/client/padOccupancy.js +88 -0
  102. package/kits/hub-game/code/client/padReadability.js +26 -0
  103. package/kits/hub-game/code/client/padRings.js +69 -0
  104. package/kits/hub-game/code/client/pushVisit.js +14 -0
  105. package/kits/hub-game/code/client/quality.js +205 -0
  106. package/kits/hub-game/code/client/qualityEntry.js +55 -0
  107. package/kits/hub-game/code/client/safeLayout.js +338 -0
  108. package/kits/hub-game/code/client/safeStyle.js +42 -0
  109. package/kits/hub-game/code/client/say.js +12 -3
  110. package/kits/hub-game/code/client/shot.js +64 -10
  111. package/kits/hub-game/code/client/shotFit.js +56 -0
  112. package/kits/hub-game/code/client/signIn.js +28 -0
  113. package/kits/hub-game/code/client/state.js +53 -0
  114. package/kits/hub-game/code/client/talk.js +209 -45
  115. package/kits/hub-game/code/client/tiers.js +68 -66
  116. package/kits/hub-game/code/client/together.js +7 -2
  117. package/kits/hub-game/code/client/weakestLookBake.js +92 -0
  118. package/kits/hub-game/code/client/weakestTier.js +295 -0
  119. package/kits/hub-game/code/client/worldLabels.js +241 -0
  120. package/kits/hub-game/code/client/yours.js +10 -9
  121. package/kits/hub-game/code/npcDisplayText.js +55 -0
  122. package/kits/hub-game/code/server/act.js +124 -0
  123. package/kits/hub-game/code/server/actions.js +6 -1
  124. package/kits/hub-game/code/server/actors.js +2 -1
  125. package/kits/hub-game/code/server/analytics.js +83 -0
  126. package/kits/hub-game/code/server/anonymousEntry.js +49 -0
  127. package/kits/hub-game/code/server/arrivalPose.js +36 -0
  128. package/kits/hub-game/code/server/companion.js +28 -3
  129. package/kits/hub-game/code/server/doorAnalytics.js +52 -0
  130. package/kits/hub-game/code/server/earned.js +22 -5
  131. package/kits/hub-game/code/server/frameBatch.js +183 -0
  132. package/kits/hub-game/code/server/friendsAmong.js +49 -9
  133. package/kits/hub-game/code/server/history.js +2 -0
  134. package/kits/hub-game/code/server/hub.js +1306 -95
  135. package/kits/hub-game/code/server/idle.js +30 -1
  136. package/kits/hub-game/code/server/index.js +26 -4
  137. package/kits/hub-game/code/server/invites.js +19 -0
  138. package/kits/hub-game/code/server/labels.js +9 -1
  139. package/kits/hub-game/code/server/loadAbandon.js +106 -0
  140. package/kits/hub-game/code/server/manifest.js +211 -3
  141. package/kits/hub-game/code/server/menu.js +31 -3
  142. package/kits/hub-game/code/server/npcs.js +226 -64
  143. package/kits/hub-game/code/server/observe.js +408 -0
  144. package/kits/hub-game/code/server/padOccupancy.js +85 -0
  145. package/kits/hub-game/code/server/players.js +9 -1
  146. package/kits/hub-game/code/server/resumePose.js +152 -0
  147. package/kits/hub-game/code/server/say.js +1 -1
  148. package/kits/hub-game/code/server/standing.js +4 -5
  149. package/kits/hub-game/code/server/storageLimit.js +187 -0
  150. package/kits/hub-game/code/server/vis.js +67 -5
  151. package/kits/hub-game/code/shared/act.js +35 -0
  152. package/kits/hub-game/code/shared/danceIdle.js +28 -0
  153. package/kits/hub-game/code/shared/loadStages.js +12 -0
  154. package/kits/hub-game/code/shared/quality.js +74 -0
  155. package/kits/hub-game/code/shared/say.js +2 -0
  156. package/kits/hub-game/code/shared/shot.js +35 -1
  157. package/kits/hub-game/code/systems/hub.js +970 -169
  158. package/kits/hub-game/docs/analytics.md +279 -0
  159. package/kits/hub-game/docs/contract.md +1259 -42
  160. package/kits/hub-game/docs/home-pieces.md +9 -2
  161. package/kits/hub-game/docs/observed-progress.md +252 -0
  162. package/kits/hub-game/main.jsx +2 -0
  163. package/kits/hub-game/package-lock.json +10 -3
  164. package/kits/hub-game/package.json +6 -3
  165. package/kits/hub-game/play/player.js +142 -0
  166. package/kits/hub-game/play/registry.js +47 -0
  167. package/kits/hub-game/play.jsx +37 -0
  168. package/kits/hub-game/scripts/check.mjs +39 -5
  169. package/kits/hub-game/scripts/companion-follower-wire.json +1 -1
  170. package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +11 -0
  171. package/kits/hub-game/scripts/fixtures/decor-keyless.json +5 -5
  172. package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +3 -0
  173. package/kits/hub-game/scripts/fixtures/fake-dom.mjs +19 -3
  174. package/kits/hub-game/scripts/fixtures/interest-legacy.json +3 -3
  175. package/kits/hub-game/scripts/fixtures/vis-shared-wire.json +1 -1
  176. package/kits/hub-game/scripts/pose-storage-fixture.mjs +46 -0
  177. package/kits/hub-game/scripts/test-act-client.mjs +186 -0
  178. package/kits/hub-game/scripts/test-act.mjs +171 -0
  179. package/kits/hub-game/scripts/test-action-layout.mjs +80 -0
  180. package/kits/hub-game/scripts/test-action-observers.mjs +46 -0
  181. package/kits/hub-game/scripts/test-actions-client.mjs +367 -2
  182. package/kits/hub-game/scripts/test-actors.mjs +20 -7
  183. package/kits/hub-game/scripts/test-analytics.mjs +76 -0
  184. package/kits/hub-game/scripts/test-anonymous-entry.mjs +28 -0
  185. package/kits/hub-game/scripts/test-arrival-pose-server.mjs +196 -0
  186. package/kits/hub-game/scripts/test-arrival-pose.mjs +24 -0
  187. package/kits/hub-game/scripts/test-ask-slot.mjs +85 -0
  188. package/kits/hub-game/scripts/test-avatar-wire.mjs +49 -10
  189. package/kits/hub-game/scripts/test-avatar.mjs +44 -0
  190. package/kits/hub-game/scripts/test-back-visibility.mjs +82 -0
  191. package/kits/hub-game/scripts/test-ballot.mjs +11 -4
  192. package/kits/hub-game/scripts/test-ban-join.mjs +121 -13
  193. package/kits/hub-game/scripts/test-build.mjs +20 -2
  194. package/kits/hub-game/scripts/test-chat.mjs +206 -5
  195. package/kits/hub-game/scripts/test-companion-chat.mjs +20 -2
  196. package/kits/hub-game/scripts/test-control-layout-dom.mjs +120 -0
  197. package/kits/hub-game/scripts/test-crowd-names.mjs +205 -0
  198. package/kits/hub-game/scripts/test-decor-client.mjs +45 -4
  199. package/kits/hub-game/scripts/test-decor.mjs +7 -0
  200. package/kits/hub-game/scripts/test-default-environment-root.mjs +95 -0
  201. package/kits/hub-game/scripts/test-default-environment.mjs +267 -0
  202. package/kits/hub-game/scripts/test-door-analytics.mjs +58 -0
  203. package/kits/hub-game/scripts/test-door-jump.mjs +100 -0
  204. package/kits/hub-game/scripts/test-earned.mjs +33 -3
  205. package/kits/hub-game/scripts/test-far-avatars.mjs +340 -0
  206. package/kits/hub-game/scripts/test-fps-telemetry.mjs +112 -0
  207. package/kits/hub-game/scripts/test-frame-batch.mjs +252 -0
  208. package/kits/hub-game/scripts/test-fresh-friends.mjs +118 -0
  209. package/kits/hub-game/scripts/test-grab-orbit.mjs +47 -4
  210. package/kits/hub-game/scripts/test-high-only.mjs +170 -0
  211. package/kits/hub-game/scripts/test-hub-ops.mjs +321 -2
  212. package/kits/hub-game/scripts/test-hub-trip.mjs +879 -11
  213. package/kits/hub-game/scripts/test-hud-clear.mjs +162 -59
  214. package/kits/hub-game/scripts/test-hud-defects-dom.mjs +100 -0
  215. package/kits/hub-game/scripts/test-hud-rate.mjs +224 -0
  216. package/kits/hub-game/scripts/test-hud-safe-visibility-dom.mjs +83 -0
  217. package/kits/hub-game/scripts/test-idle.mjs +66 -0
  218. package/kits/hub-game/scripts/test-interest-cells.mjs +20 -0
  219. package/kits/hub-game/scripts/test-interest.mjs +15 -0
  220. package/kits/hub-game/scripts/test-invites-client.mjs +430 -0
  221. package/kits/hub-game/scripts/test-invites.mjs +109 -0
  222. package/kits/hub-game/scripts/test-labels.mjs +71 -3
  223. package/kits/hub-game/scripts/test-landscape-layout.mjs +194 -0
  224. package/kits/hub-game/scripts/test-list-scroll-dom.mjs +49 -0
  225. package/kits/hub-game/scripts/test-load-abandon.mjs +246 -0
  226. package/kits/hub-game/scripts/test-loading-cover.mjs +162 -0
  227. package/kits/hub-game/scripts/test-manifest.mjs +265 -0
  228. package/kits/hub-game/scripts/test-menu-client.mjs +105 -0
  229. package/kits/hub-game/scripts/test-menu.mjs +23 -0
  230. package/kits/hub-game/scripts/test-npcs.mjs +917 -10
  231. package/kits/hub-game/scripts/test-observed.mjs +745 -0
  232. package/kits/hub-game/scripts/test-pad-cues.mjs +304 -0
  233. package/kits/hub-game/scripts/test-pad-occupancy.mjs +177 -0
  234. package/kits/hub-game/scripts/test-picker.mjs +234 -7
  235. package/kits/hub-game/scripts/test-placement-cache.mjs +690 -0
  236. package/kits/hub-game/scripts/test-progress-reset.mjs +559 -0
  237. package/kits/hub-game/scripts/test-push-visit.mjs +26 -0
  238. package/kits/hub-game/scripts/test-quality.mjs +385 -0
  239. package/kits/hub-game/scripts/test-rehello.mjs +699 -5
  240. package/kits/hub-game/scripts/test-resume-action-order.mjs +598 -0
  241. package/kits/hub-game/scripts/test-resume-held.mjs +239 -0
  242. package/kits/hub-game/scripts/test-resume-pose.mjs +142 -0
  243. package/kits/hub-game/scripts/test-safe-events-dom.mjs +116 -0
  244. package/kits/hub-game/scripts/test-safe-layout.mjs +330 -0
  245. package/kits/hub-game/scripts/test-say.mjs +1 -1
  246. package/kits/hub-game/scripts/test-shot.mjs +145 -0
  247. package/kits/hub-game/scripts/test-signin-client.mjs +45 -0
  248. package/kits/hub-game/scripts/test-soundscape.mjs +22 -17
  249. package/kits/hub-game/scripts/test-standing.mjs +35 -2
  250. package/kits/hub-game/scripts/test-storage-limit.mjs +333 -0
  251. package/kits/hub-game/scripts/test-stuck.mjs +5 -4
  252. package/kits/hub-game/scripts/test-talk-overlay-dom.mjs +130 -0
  253. package/kits/hub-game/scripts/test-tiers-render.mjs +86 -13
  254. package/kits/hub-game/scripts/test-tiers.mjs +7 -8
  255. package/kits/hub-game/scripts/test-vis.mjs +433 -6
  256. package/kits/hub-game/scripts/test-weakest-tier.mjs +924 -0
  257. package/kits/hub-game/scripts/test-world-labels.mjs +367 -0
  258. package/kits/hub-game/scripts/test-yours-chrome.mjs +50 -6
  259. package/kits/hub-game/scripts/test-yours.mjs +39 -8
  260. package/kits/multiplayer-3d/castle.json +5 -5
  261. package/kits/multiplayer-3d/code/client/joinFailure.js +27 -0
  262. package/kits/multiplayer-3d/code/client/resumeGate.js +139 -0
  263. package/kits/multiplayer-3d/code/systems/multiplayer.js +369 -30
  264. package/kits/multiplayer-3d/package-lock.json +8 -1
  265. package/kits/multiplayer-3d/package.json +2 -1
  266. package/kits/multiplayer-3d/scripts/test-join-watchdog.mjs +436 -0
  267. package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +624 -0
  268. package/kits/physics-2d/CLAUDE.md +10 -1
  269. package/kits/physics-2d/castle.json +2 -2
  270. package/kits/physics-2d/engine/frozenActors.js +233 -0
  271. package/kits/physics-2d/engine/scene.js +87 -5
  272. package/kits/physics-2d/eslint.config.js +1 -1
  273. package/kits/physics-2d/play/behaviors/AnalogStick.js +198 -0
  274. package/kits/physics-2d/play/behaviors/Camera.js +40 -0
  275. package/kits/physics-2d/play/behaviors/Collider.js +122 -0
  276. package/kits/physics-2d/play/behaviors/Draggable.js +115 -0
  277. package/kits/physics-2d/play/behaviors/Goal.js +46 -0
  278. package/kits/physics-2d/play/behaviors/Joints.js +126 -0
  279. package/kits/physics-2d/play/behaviors/Layout.js +71 -0
  280. package/kits/physics-2d/play/behaviors/RigidBody.js +57 -0
  281. package/kits/physics-2d/play/behaviors/Slingshot.js +142 -0
  282. package/kits/physics-2d/play/behaviors/SoundPlayer.js +263 -0
  283. package/kits/physics-2d/play/behaviors/Sprite.js +406 -0
  284. package/kits/physics-2d/play/behaviors/Style.js +209 -0
  285. package/kits/physics-2d/play/behaviors/Text.js +85 -0
  286. package/kits/physics-2d/play/behaviors/Video.js +93 -0
  287. package/kits/physics-3d/CLAUDE.md +25 -1651
  288. package/kits/physics-3d/behaviors/Body.jsx +3 -0
  289. package/kits/physics-3d/behaviors/Model.jsx +3 -0
  290. package/kits/physics-3d/behaviors/Player.jsx +35 -18
  291. package/kits/physics-3d/behaviors/Shape.jsx +3 -0
  292. package/kits/physics-3d/behaviors/Solid.jsx +3 -0
  293. package/kits/physics-3d/behaviors/Transform.jsx +3 -0
  294. package/kits/physics-3d/castle.json +3 -3
  295. package/kits/physics-3d/docs/engine-camera.md +542 -0
  296. package/kits/physics-3d/docs/engine-frame-cap.md +136 -0
  297. package/kits/physics-3d/docs/engine-load.md +149 -0
  298. package/kits/physics-3d/docs/engine-look.md +114 -0
  299. package/kits/physics-3d/docs/engine-shadows.md +372 -0
  300. package/kits/physics-3d/docs/engine-skip-work.md +187 -0
  301. package/kits/physics-3d/docs/engine-sky.md +198 -0
  302. package/kits/physics-3d/docs/engine-static-actors.md +226 -0
  303. package/kits/physics-3d/docs/engine-view.md +37 -0
  304. package/kits/physics-3d/docs/pxmodel-format.md +1 -1
  305. package/kits/physics-3d/engine3d/PlayOnly3D.jsx +5 -1
  306. package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +19 -333
  307. package/kits/physics-3d/engine3d/actornode.js +1 -0
  308. package/kits/physics-3d/engine3d/branches.js +3 -13
  309. package/kits/physics-3d/engine3d/cage.js +2 -7
  310. package/kits/physics-3d/engine3d/cageops.js +2 -17
  311. package/kits/physics-3d/engine3d/dataBehaviors.js +12 -0
  312. package/kits/physics-3d/engine3d/framecap.js +4 -1
  313. package/kits/physics-3d/engine3d/frozenphysics.js +140 -0
  314. package/kits/physics-3d/engine3d/frozenstatics.js +273 -0
  315. package/kits/physics-3d/engine3d/gait.js +8 -0
  316. package/kits/physics-3d/engine3d/initialModelFiles.js +18 -0
  317. package/kits/physics-3d/engine3d/look.js +7 -0
  318. package/kits/physics-3d/engine3d/modelFiles.js +3 -17
  319. package/kits/physics-3d/engine3d/modelMath.js +49 -0
  320. package/kits/physics-3d/engine3d/modelready.js +16 -0
  321. package/kits/physics-3d/engine3d/motion.js +3 -3
  322. package/kits/physics-3d/engine3d/nearshadows.js +77 -10
  323. package/kits/physics-3d/engine3d/orbitinput.js +59 -25
  324. package/kits/physics-3d/engine3d/partgeometry.js +1 -16
  325. package/kits/physics-3d/engine3d/paths.js +1 -9
  326. package/kits/physics-3d/engine3d/playTimings.js +50 -0
  327. package/kits/physics-3d/engine3d/playerRun.js +372 -0
  328. package/kits/physics-3d/engine3d/pxmodel.js +3 -3
  329. package/kits/physics-3d/engine3d/rapier.js +27 -0
  330. package/kits/physics-3d/engine3d/scatter.js +1 -11
  331. package/kits/physics-3d/engine3d/shadowfade.js +23 -15
  332. package/kits/physics-3d/engine3d/sky.js +1 -1
  333. package/kits/physics-3d/engine3d/squarefirst.js +177 -0
  334. package/kits/physics-3d/engine3d/stillshadows.js +399 -0
  335. package/kits/physics-3d/engine3d/sweep.js +1 -25
  336. package/kits/physics-3d/engine3d/world3d.js +468 -18
  337. package/kits/physics-3d/eslint.config.js +2 -1
  338. package/kits/physics-3d/main.jsx +6 -3
  339. package/kits/physics-3d/package-lock.json +7 -0
  340. package/kits/physics-3d/package.json +5 -1
  341. package/kits/physics-3d/play/behaviors/Body.js +31 -0
  342. package/kits/physics-3d/play/behaviors/Door.js +37 -0
  343. package/kits/physics-3d/play/behaviors/Lookable.js +16 -0
  344. package/kits/physics-3d/play/behaviors/Model.js +23 -0
  345. package/kits/physics-3d/play/behaviors/Pickup.js +46 -0
  346. package/kits/physics-3d/play/behaviors/Player.js +1204 -0
  347. package/kits/physics-3d/play/behaviors/Shape.js +47 -0
  348. package/kits/physics-3d/play/behaviors/Solid.js +16 -0
  349. package/kits/physics-3d/play/behaviors/Transform.js +29 -0
  350. package/kits/physics-3d/pnpm-lock.yaml +8 -0
  351. package/kits/physics-3d/scripts/bench-shadow-fade.mjs +37 -0
  352. package/kits/physics-3d/scripts/build-rapier-gz.mjs +56 -0
  353. package/kits/physics-3d/scripts/frozen-statics-fixture.mjs +141 -0
  354. package/kits/physics-3d/scripts/test-camera-follow.mjs +5 -1
  355. package/kits/physics-3d/scripts/test-camera-orbit.mjs +52 -4
  356. package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +1 -1
  357. package/kits/physics-3d/scripts/test-empty-gait-hints.mjs +89 -0
  358. package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +6 -3
  359. package/kits/physics-3d/scripts/test-frame-cap.mjs +1 -1
  360. package/kits/physics-3d/scripts/test-frozen-nested.mjs +49 -0
  361. package/kits/physics-3d/scripts/test-frozen-statics-legacy-physics2d.mjs +123 -0
  362. package/kits/physics-3d/scripts/test-frozen-statics.mjs +434 -0
  363. package/kits/physics-3d/scripts/test-look-bake.mjs +1 -1
  364. package/kits/physics-3d/scripts/test-near-shadows.mjs +2 -2
  365. package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +88 -7
  366. package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +40 -3
  367. package/kits/physics-3d/scripts/test-orbit-shot.mjs +75 -1
  368. package/kits/physics-3d/scripts/test-rapier-gz.mjs +106 -0
  369. package/kits/physics-3d/scripts/test-sky.mjs +1 -1
  370. package/kits/physics-3d/scripts/test-square-first.mjs +921 -0
  371. package/kits/physics-3d/scripts/test-static-actors.mjs +3 -1
  372. package/kits/physics-3d/scripts/test-static-physics.mjs +4 -1
  373. package/kits/physics-3d/scripts/test-static-scenery.mjs +5 -2
  374. package/kits/physics-3d/scripts/test-steady-hover.mjs +5 -2
  375. package/kits/physics-3d/scripts/test-still-shadows.mjs +477 -0
  376. package/kits/physics-3d/systems/physics3d.js +37 -4
  377. package/kits/real-time/castle.json +2 -2
  378. package/kits/real-time/code/client/connection.js +33 -10
  379. package/kits/real-time/code/client/gameHooks.js +2 -0
  380. package/kits/real-time/code/client/joinOverlay.js +9 -4
  381. package/kits/real-time/code/server/session.js +6 -4
  382. package/kits/real-time/package-lock.json +1 -1
  383. package/package.json +2 -2
@@ -0,0 +1,241 @@
1
+ // A scene may opt its existing multiplayer name sprites into a bounded crowd
2
+ // pass (`engine.hubCrowdNames`). The caller supplies only tags the avatar
3
+ // renderer already authorized and drew; this module never discovers players.
4
+
5
+ export const ENTER_M = 1;
6
+ export const LEAVE_M = 1.25;
7
+ export const HOLD_MS = 500;
8
+ export const RESTORE_MS = 250;
9
+ export const RESTORE_PX = 8;
10
+ export const MAX_CANDIDATES = 24;
11
+ export const MIN_FONT_PX = 15;
12
+
13
+ const TAG_FONT_PX = 44;
14
+ const TAG_CANVAS_H = 68;
15
+
16
+ const inView = (box, view) => box && box.left >= 8 && box.top >= 8 && box.right <= view.w - 8 && box.bottom <= view.h - 8;
17
+ const touches = (a, b, gap = 0) => a.left - gap < b.right && b.left - gap < a.right && a.top - gap < b.bottom && b.top - gap < a.bottom;
18
+ const pairKey = (a, b) => JSON.stringify(a < b ? [a, b] : [b, a]);
19
+ const distanceBucket = (d) => Math.floor(Math.max(0, d) * 4);
20
+
21
+ export function makeCrowdNames() {
22
+ return {
23
+ nearPairs: new Set(),
24
+ chosen: new Set(),
25
+ chosenAt: new Map(),
26
+ friends: new Map(),
27
+ suppressed: new Set(),
28
+ clearSince: new Map(),
29
+ };
30
+ }
31
+
32
+ // State belongs to one loaded scene on one live connection. In particular, a
33
+ // reconnect cannot carry a retained slot into a newly authorized roster.
34
+ export function crowdNamesFor(holder, scope) {
35
+ const was = holder.scope;
36
+ if (!holder.state || !was || was.scene !== scope.scene || was.data !== scope.data || was.net !== scope.net || was.place !== scope.place || was.visit !== scope.visit) {
37
+ holder.state = makeCrowdNames();
38
+ holder.scope = { ...scope };
39
+ }
40
+ return holder.state;
41
+ }
42
+
43
+ function rank(state, now, a, b) {
44
+ const aHeld = state.chosen.has(a.id) && now - (state.chosenAt.get(a.id) ?? -Infinity) < HOLD_MS;
45
+ const bHeld = state.chosen.has(b.id) && now - (state.chosenAt.get(b.id) ?? -Infinity) < HOLD_MS;
46
+ return Number(Boolean(b.friend)) - Number(Boolean(a.friend)) ||
47
+ Number(bHeld) - Number(aHeld) ||
48
+ distanceBucket(a.distance) - distanceBucket(b.distance) ||
49
+ (a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
50
+ }
51
+
52
+ function groupsOf(items, state) {
53
+ const parent = new Map(items.map((item) => [item.id, item.id]));
54
+ const find = (id) => {
55
+ let root = id;
56
+ while (parent.get(root) !== root) {root = parent.get(root);}
57
+ while (parent.get(id) !== id) {
58
+ const next = parent.get(id);
59
+ parent.set(id, root);
60
+ id = next;
61
+ }
62
+ return root;
63
+ };
64
+ const join = (a, b) => {
65
+ const ar = find(a), br = find(b);
66
+ if (ar !== br) {parent.set(br, ar);}
67
+ };
68
+ let pairTests = 0;
69
+ const livePairs = new Set();
70
+ for (let i = 0; i < items.length; i += 1) {
71
+ for (let j = i + 1; j < items.length; j += 1) {
72
+ pairTests += 1;
73
+ const a = items[i], b = items[j];
74
+ const key = pairKey(a.id, b.id);
75
+ const near = Math.hypot(a.at.x - b.at.x, a.at.z - b.at.z) <= (state.nearPairs.has(key) ? LEAVE_M : ENTER_M);
76
+ if (near) {livePairs.add(key);}
77
+ if (near || touches(a.box, b.box)) {join(a.id, b.id);}
78
+ }
79
+ }
80
+ state.nearPairs = livePairs;
81
+ const groups = new Map();
82
+ for (const item of items) {
83
+ const root = find(item.id);
84
+ const group = groups.get(root) ?? [];
85
+ group.push(item);
86
+ groups.set(root, group);
87
+ }
88
+ return { groups: [...groups.values()], pairTests };
89
+ }
90
+
91
+ // Returns stable player ids whose existing sprites remain visible, plus an
92
+ // anonymous summary request. `candidates` are current authorized, baseline-
93
+ // visible tags: `{ id, friend, distance, at:{x,z}, box }`.
94
+ export function layoutCrowdNames(state, candidates, { now, view, obstacles = [] }) {
95
+ const live = new Set(candidates.map((candidate) => candidate.id));
96
+ // Losing friend priority is effective in this frame; it cannot borrow the
97
+ // old priority's retained-slot hold.
98
+ let friendRevoked = false;
99
+ for (const candidate of candidates) {
100
+ if (state.friends.get(candidate.id) === true && candidate.friend !== true) {
101
+ state.chosen.delete(candidate.id);
102
+ state.chosenAt.delete(candidate.id);
103
+ friendRevoked = true;
104
+ }
105
+ state.friends.set(candidate.id, candidate.friend === true);
106
+ }
107
+ if (friendRevoked) {
108
+ state.suppressed.clear();
109
+ state.clearSince.clear();
110
+ }
111
+ for (const id of state.chosen) {
112
+ if (!live.has(id)) {
113
+ state.chosen.delete(id);
114
+ state.chosenAt.delete(id);
115
+ }
116
+ }
117
+ for (const id of state.suppressed) {
118
+ if (!live.has(id)) {
119
+ state.suppressed.delete(id);
120
+ state.clearSince.delete(id);
121
+ }
122
+ }
123
+ for (const id of state.friends.keys()) {
124
+ if (!live.has(id)) {state.friends.delete(id);}
125
+ }
126
+
127
+ const drawable = candidates.filter((candidate) => inView(candidate.box, view));
128
+ drawable.sort((a, b) => rank(state, now, a, b));
129
+ const bounded = drawable.slice(0, MAX_CANDIDATES);
130
+ const overflow = drawable.slice(MAX_CANDIDATES);
131
+ const { groups, pairTests } = groupsOf(bounded, state);
132
+ const tiny = view.w <= 509 && view.h <= 218;
133
+ const chosen = new Set();
134
+ const chosenBoxes = [];
135
+ const summary = [];
136
+
137
+ for (const group of groups) {
138
+ const dense = group.length > 1;
139
+ group.sort((a, b) => rank(state, now, a, b));
140
+ const limit = tiny ? 0 : dense ? 2 : 1;
141
+ let used = 0;
142
+ for (const candidate of group) {
143
+ const blocked = obstacles.some((box) => touches(candidate.box, box));
144
+ const conflicts = chosenBoxes.some((box) => touches(candidate.box, box));
145
+ let allowed = used < limit && !blocked && !conflicts;
146
+ let waiting = false;
147
+ if (allowed && state.suppressed.has(candidate.id)) {
148
+ const separated = !obstacles.some((box) => touches(candidate.box, box, RESTORE_PX)) &&
149
+ !chosenBoxes.some((box) => touches(candidate.box, box, RESTORE_PX));
150
+ if (!separated) {
151
+ state.clearSince.delete(candidate.id);
152
+ allowed = false;
153
+ } else {
154
+ const since = state.clearSince.get(candidate.id);
155
+ if (since === undefined) {
156
+ state.clearSince.set(candidate.id, now);
157
+ allowed = false;
158
+ waiting = true;
159
+ } else if (now - since < RESTORE_MS) {
160
+ allowed = false;
161
+ waiting = true;
162
+ }
163
+ }
164
+ }
165
+ if (allowed) {
166
+ chosen.add(candidate.id);
167
+ chosenBoxes.push(candidate.box);
168
+ used += 1;
169
+ } else {
170
+ if (!waiting) {state.clearSince.delete(candidate.id);}
171
+ if (dense || tiny) {summary.push(candidate);}
172
+ }
173
+ }
174
+ }
175
+ summary.push(...overflow);
176
+
177
+ const previous = state.chosen;
178
+ state.chosen = chosen;
179
+ state.suppressed = new Set(drawable.filter((candidate) => !chosen.has(candidate.id)).map((candidate) => candidate.id));
180
+ for (const id of chosen) {
181
+ if (!previous.has(id)) {state.chosenAt.set(id, now);}
182
+ }
183
+ for (const id of [...state.chosenAt.keys()]) {
184
+ if (!chosen.has(id)) {state.chosenAt.delete(id);}
185
+ }
186
+
187
+ let summaryAt = null;
188
+ if (summary.length) {
189
+ summaryAt = {
190
+ x: summary.reduce((sum, candidate) => sum + (candidate.box.left + candidate.box.right) / 2, 0) / summary.length,
191
+ y: Math.min(...summary.map((candidate) => candidate.box.top)) - 6,
192
+ count: summary.length,
193
+ tiny,
194
+ };
195
+ }
196
+ return { visible: chosen, summary: summaryAt, pairTests, considered: bounded.length };
197
+ }
198
+
199
+ // The multiplayer tag is a camera-facing sprite. Project its current camera
200
+ // right/up extents so collisions use the final CSS-pixel rectangle rather than
201
+ // stale texture or unscaled text dimensions.
202
+ export function spriteBox(sprite, cam, view, project) {
203
+ const at = sprite?.position;
204
+ const matrix = cam?.matrixWorld?.elements;
205
+ if (!at || !matrix) {return null;}
206
+ const right = { x: matrix[0], y: matrix[1], z: matrix[2] };
207
+ const up = { x: matrix[4], y: matrix[5], z: matrix[6] };
208
+ const halfW = Math.abs(sprite.scale?.x ?? 0) / 2;
209
+ const halfH = Math.abs(sprite.scale?.y ?? 0) / 2;
210
+ const left = project(cam, at.x - right.x * halfW, at.y - right.y * halfW, at.z - right.z * halfW, view);
211
+ const rightAt = project(cam, at.x + right.x * halfW, at.y + right.y * halfW, at.z + right.z * halfW, view);
212
+ const top = project(cam, at.x + up.x * halfH, at.y + up.y * halfH, at.z + up.z * halfH, view);
213
+ const bottom = project(cam, at.x - up.x * halfH, at.y - up.y * halfH, at.z - up.z * halfH, view);
214
+ if (!left || !rightAt || !top || !bottom) {return null;}
215
+ return {
216
+ left: Math.min(left.x, rightAt.x),
217
+ right: Math.max(left.x, rightAt.x),
218
+ top: Math.min(top.y, bottom.y),
219
+ bottom: Math.max(top.y, bottom.y),
220
+ };
221
+ }
222
+
223
+ // E may enlarge an already-rendered multiplayer plate just enough for its
224
+ // 44px canvas font to read at 15 CSS pixels. The returned box is projected
225
+ // again after the scale write, so collision uses the current camera result.
226
+ export function readableSpriteBox(sprite, cam, view, project) {
227
+ let box = spriteBox(sprite, cam, view, project);
228
+ if (!box) {return { box: null, resized: null };}
229
+ const fontPx = (box.bottom - box.top) * TAG_FONT_PX / TAG_CANVAS_H;
230
+ if (!(fontPx > 0) || fontPx >= MIN_FONT_PX) {
231
+ return { box, resized: null };
232
+ }
233
+ const x = sprite.scale.x;
234
+ const y = sprite.scale.y;
235
+ const factor = MIN_FONT_PX / fontPx;
236
+ sprite.scale.x = x * factor;
237
+ sprite.scale.y = y * factor;
238
+ const resized = { x, y, scaledX: sprite.scale.x, scaledY: sprite.scale.y };
239
+ box = spriteBox(sprite, cam, view, project);
240
+ return { box, resized };
241
+ }
@@ -1,3 +1,4 @@
1
+ import { ensureActorModel } from './modelReady.js';
1
2
  // Decorating (v1.67): private chrome and local previews. No actor or body is
2
3
  // changed: the deck's server hook decides every edit and sends the catalogue
3
4
  // back. Made only in a place with `decor`, under the existing chrome root.
@@ -19,6 +20,7 @@ function el(tag, style, parent, text) {
19
20
  }
20
21
 
21
22
  export function makeDecor(chrome, { renderer = () => new THREE.WebGLRenderer({ alpha: true, antialias: true, preserveDrawingBuffer: true }) } = {}) {
23
+ const geometry = chrome.layoutGeometry?.();
22
24
  const listeners = new AbortController();
23
25
  function button(parent, label, action, style = {}) {
24
26
  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);
@@ -119,6 +121,7 @@ export function makeDecor(chrome, { renderer = () => new THREE.WebGLRenderer({ a
119
121
  chrome.setDecorating(false);
120
122
  }
121
123
  function cloneActor(id) {
124
+ ensureActorModel(t.scene?.three, id);
122
125
  const entry = t.scene?.three?.nodes.get(id);
123
126
  if (!entry) {
124
127
  return null;
@@ -340,7 +343,7 @@ export function makeDecor(chrome, { renderer = () => new THREE.WebGLRenderer({ a
340
343
  if (!camera || !t.grid) {
341
344
  return null;
342
345
  }
343
- const rect = root.getBoundingClientRect();
346
+ const rect = geometry?.rect(root) ?? root.getBoundingClientRect();
344
347
  ray.setFromCamera(new THREE.Vector2((event.clientX - rect.left) / rect.width * 2 - 1, 1 - (event.clientY - rect.top) / rect.height * 2), camera);
345
348
  plane.constant = -t.grid.y;
346
349
  if (!ray.ray.intersectPlane(plane, point)) {
@@ -412,6 +415,8 @@ export function makeDecor(chrome, { renderer = () => new THREE.WebGLRenderer({ a
412
415
  world.addEventListener('pointercancel', up, { signal: listeners.signal });
413
416
  root.addEventListener('pointerdown', (event) => event.stopPropagation(), { signal: listeners.signal });
414
417
 
418
+ for (const node of [root, enter, header, tray, actions]) {geometry?.register(node);}
419
+
415
420
  return {
416
421
  opened: () => t.open,
417
422
  clear,
@@ -486,12 +491,12 @@ export function makeDecor(chrome, { renderer = () => new THREE.WebGLRenderer({ a
486
491
  rotate.disabled = false;
487
492
  stash.textContent = t.lift.key ? 'Put away' : 'Cancel';
488
493
  const p = t.ghost?.position.clone().project(scene.three.camera);
489
- const rect = root.getBoundingClientRect();
490
- const trayTop = tray.getBoundingClientRect().top - rect.top;
494
+ const rect = geometry?.rect(root) ?? root.getBoundingClientRect();
495
+ const trayTop = (geometry?.rect(tray) ?? tray.getBoundingClientRect()).top - rect.top;
491
496
  const x = p && p.z < 1 && p.z > -1 ? (p.x + 1) * rect.width / 2 : rect.width / 2;
492
497
  const y = p && p.z < 1 && p.z > -1 ? (1 - p.y) * rect.height / 2 - 42 : trayTop - 16;
493
498
  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`;
499
+ actions.style.top = `${Math.max((geometry?.size(header).h ?? header.offsetHeight) + 82, Math.min(trayTop - 12, y))}px`;
495
500
  }
496
501
  },
497
502
  dispose() {
@@ -503,6 +508,7 @@ export function makeDecor(chrome, { renderer = () => new THREE.WebGLRenderer({ a
503
508
  t.thumbScene = null;
504
509
  t.scene = null;
505
510
  t.net = null;
511
+ geometry?.unregister(root);
506
512
  root.remove();
507
513
  },
508
514
  };
@@ -0,0 +1,194 @@
1
+ import { Color, Fog } from 'three';
2
+
3
+ // A hub game's fallback picture. It is deliberately only a clear colour and
4
+ // Three's built-in linear fog: no mesh, texture, shader or render pass. The
5
+ // fog begins before the engine's 60 m ground reaches its edge, while leaving
6
+ // enough distance for an ordinary door game's whole yard.
7
+ export const DEFAULT_SKY_COLOR = '#bfe3f2';
8
+ export const DEFAULT_FOG_NEAR = 18;
9
+ export const DEFAULT_FOG_FAR = 60;
10
+ export const FALL_FADE_BELOW_M = 1;
11
+ export const FALL_RETURN_S = 0.45;
12
+
13
+ const hexColor = (value) => typeof value === 'string' && /^#[\da-f]{6}$/i.test(value);
14
+ const clamp01 = (value) => Math.max(0, Math.min(1, value));
15
+
16
+ // Presence is intentional here. A malformed/newer authored key keeps the
17
+ // picture it had before rather than silently becoming the hub fallback, and a
18
+ // tier may shadow the parsed `scene.sky` getter with an own null without
19
+ // making the authored scene keyless.
20
+ export function hasAuthoredEnvironment(data) {
21
+ const engine = data?.engine;
22
+ return Boolean(
23
+ (data && Object.hasOwn(data, 'background')) ||
24
+ (engine && (Object.hasOwn(engine, 'sky') || Object.hasOwn(engine, 'view')))
25
+ );
26
+ }
27
+
28
+ function colorEquals(a, b) {
29
+ return Boolean(a?.isColor && b?.isColor && a.equals(b));
30
+ }
31
+
32
+ function rendererColor(renderer) {
33
+ if (typeof renderer?.getClearColor !== 'function') {return null;}
34
+ return renderer.getClearColor(new Color()).clone();
35
+ }
36
+
37
+ function clearAlpha(renderer) {
38
+ return typeof renderer?.getClearAlpha === 'function' ? renderer.getClearAlpha() : 1;
39
+ }
40
+
41
+ function zoneColor(scene) {
42
+ const data = scene?.data;
43
+ const viewColor = data?.engine?.view?.fogColor;
44
+ if (hexColor(viewColor)) {return new Color(viewColor);}
45
+ const fogColor = scene?.three?.scene?.fog?.color;
46
+ if (fogColor?.isColor) {return fogColor.clone();}
47
+
48
+ const zones = data?.engine?.sky?.zones;
49
+ if (Array.isArray(zones) && zones.length) {
50
+ const state = scene.skyZone;
51
+ const byId = new Map(zones.filter((zone) => hexColor(zone?.color)).map((zone) => [zone.id, zone.color]));
52
+ const home = zones.find((zone) => zone?.box === undefined && hexColor(zone?.color));
53
+ const from = byId.get(state?.from) ?? byId.get(state?.id) ?? home?.color ?? zones.find((zone) => hexColor(zone?.color))?.color;
54
+ if (from) {
55
+ const color = new Color(from);
56
+ const to = byId.get(state?.to);
57
+ if (to && state?.blend > 0) {color.lerp(new Color(to), clamp01(state.blend));}
58
+ return color;
59
+ }
60
+ }
61
+ const background = scene?.three?.scene?.background;
62
+ if (background?.isColor) {return background.clone();}
63
+ if (hexColor(data?.background)) {return new Color(data.background);}
64
+ return new Color(DEFAULT_SKY_COLOR);
65
+ }
66
+
67
+ function cssColor(color) {
68
+ return `#${color.getHexString()}`;
69
+ }
70
+
71
+ // The default environment is scene-local and owns only the exact values it
72
+ // writes. `frame` also supplies the fall transition for authored scenes: the
73
+ // WebGL canvas fades over its parent's sky/fog colour, which covers materials
74
+ // that opt out of fog without another render pass. Chrome remains readable.
75
+ export function makeDefaultEnvironment() {
76
+ const state = {
77
+ scene: null,
78
+ data: null,
79
+ world: null,
80
+ fog: null,
81
+ fogBefore: null,
82
+ clearBefore: null,
83
+ clearAlpha: 1,
84
+ clearWritten: null,
85
+ fade: 0,
86
+ canvas: null,
87
+ parent: null,
88
+ opacityBefore: '',
89
+ backgroundBefore: '',
90
+ opacityWritten: null,
91
+ backgroundWritten: null,
92
+ };
93
+
94
+ const restorePicture = () => {
95
+ const world = state.world;
96
+ if (world?.scene?.fog === state.fog) {world.scene.fog = state.fogBefore;}
97
+ const renderer = world?.renderer;
98
+ const current = rendererColor(renderer);
99
+ if (state.clearWritten && colorEquals(current, state.clearWritten) && clearAlpha(renderer) === state.clearAlpha) {
100
+ renderer.setClearColor(state.clearBefore, state.clearAlpha);
101
+ }
102
+ state.fog = null;
103
+ state.fogBefore = null;
104
+ state.clearBefore = null;
105
+ state.clearWritten = null;
106
+ };
107
+
108
+ const restoreFade = () => {
109
+ if (state.canvas && state.opacityWritten !== null && state.canvas.style.opacity === state.opacityWritten) {
110
+ state.canvas.style.opacity = state.opacityBefore;
111
+ }
112
+ if (state.parent && state.backgroundWritten !== null && state.parent.style.background === state.backgroundWritten) {
113
+ state.parent.style.background = state.backgroundBefore;
114
+ }
115
+ state.fade = 0;
116
+ state.canvas = null;
117
+ state.parent = null;
118
+ state.opacityBefore = '';
119
+ state.backgroundBefore = '';
120
+ state.opacityWritten = null;
121
+ state.backgroundWritten = null;
122
+ };
123
+
124
+ const restore = () => {
125
+ restoreFade();
126
+ restorePicture();
127
+ state.scene = null;
128
+ state.data = null;
129
+ state.world = null;
130
+ };
131
+
132
+ const adopt = (scene) => {
133
+ const world = scene?.three;
134
+ if (state.scene === scene && state.data === scene?.data && state.world === world) {return;}
135
+ restore();
136
+ if (!world) {return;}
137
+ state.scene = scene;
138
+ state.data = scene.data;
139
+ state.world = world;
140
+ if (hasAuthoredEnvironment(scene.data) || world.scene?.background || world.scene?.fog) {return;}
141
+ const renderer = world.renderer;
142
+ const before = rendererColor(renderer);
143
+ if (!before || typeof renderer.setClearColor !== 'function') {return;}
144
+ state.fogBefore = world.scene.fog;
145
+ state.fog = new Fog(DEFAULT_SKY_COLOR, DEFAULT_FOG_NEAR, DEFAULT_FOG_FAR);
146
+ world.scene.fog = state.fog;
147
+ state.clearBefore = before;
148
+ state.clearAlpha = clearAlpha(renderer);
149
+ state.clearWritten = new Color(DEFAULT_SKY_COLOR);
150
+ renderer.setClearColor(state.clearWritten, state.clearAlpha);
151
+ };
152
+
153
+ const drawFade = (scene, amount) => {
154
+ const canvas = scene?.three?.renderer?.domElement;
155
+ const parent = canvas?.parentElement;
156
+ if (!canvas?.style || !parent?.style) {return;}
157
+ if (state.canvas !== canvas || state.parent !== parent) {
158
+ const fade = state.fade;
159
+ restoreFade();
160
+ state.fade = fade;
161
+ state.canvas = canvas;
162
+ state.parent = parent;
163
+ state.opacityBefore = canvas.style.opacity;
164
+ state.backgroundBefore = parent.style.background;
165
+ }
166
+ const color = cssColor(zoneColor(scene));
167
+ const opacity = String(1 - amount);
168
+ canvas.style.opacity = opacity;
169
+ parent.style.background = color;
170
+ // CSSOM normalizes colours (usually to rgb(...)) and sometimes numbers.
171
+ // Remember what the browser retained, not what was assigned.
172
+ state.opacityWritten = canvas.style.opacity;
173
+ state.backgroundWritten = parent.style.background;
174
+ };
175
+
176
+ const frame = (scene, local, fallY, dt = 0, enabled = true) => {
177
+ if (enabled === false) {
178
+ restore();
179
+ return;
180
+ }
181
+ adopt(scene);
182
+ const y = local?.components?.Transform?.y;
183
+ let target = 0;
184
+ if (typeof fallY === 'number' && Number.isFinite(y)) {
185
+ target = clamp01((fallY - y) / FALL_FADE_BELOW_M);
186
+ }
187
+ if (target > state.fade) {state.fade = target;}
188
+ else {state.fade = Math.max(target, state.fade - Math.max(0, dt) / FALL_RETURN_S);}
189
+ if (state.fade > 0) {drawFade(scene, state.fade);}
190
+ else if (state.canvas) {restoreFade();}
191
+ };
192
+
193
+ return { frame, restore };
194
+ }
@@ -0,0 +1,39 @@
1
+ // Report only a fixed category to the current server. Never inspect error text.
2
+ export function makeDoorErrors(win = globalThis.window, doc = globalThis.document) {
3
+ let target = null, listening = false, last = null, next = 0;
4
+ const report = result => {
5
+ if (!target || doc?.visibilityState === 'hidden' || target.closed?.() ||
6
+ (target.status && target.status().state !== 'connected')) {return;}
7
+ const now = Date.now();
8
+ if (now < next) {return;}
9
+ next = now + 10000;
10
+ try {target.send({ k: 'hub-door-error', result });} catch { /* Best effort. */ }
11
+ };
12
+ const exception = () => report(2);
13
+ const visibility = () => {last = null;};
14
+ return {
15
+ sync(net, enabled, now) {
16
+ if (!enabled || target !== net) {last = null;}
17
+ target = enabled ? net : null;
18
+ if (Boolean(target) !== listening && win?.addEventListener) {
19
+ for (const name of ['error', 'unhandledrejection']) {
20
+ if (target) {win.addEventListener(name, exception);}
21
+ else {win.removeEventListener(name, exception);}
22
+ }
23
+ if (target) {doc?.addEventListener?.('visibilitychange', visibility);}
24
+ else {doc?.removeEventListener?.('visibilitychange', visibility);}
25
+ listening = Boolean(target);
26
+ }
27
+ // A visible render gap >= 2 seconds. Hidden tabs do not count as stalls.
28
+ if (target && doc?.visibilityState !== 'hidden' && last !== null && now - last >= 2000) {report(1);}
29
+ last = target && doc?.visibilityState !== 'hidden' ? now : null;
30
+ },
31
+ dispose() {
32
+ if (listening) {
33
+ for (const name of ['error', 'unhandledrejection']) {win.removeEventListener(name, exception);}
34
+ }
35
+ doc?.removeEventListener?.('visibilitychange', visibility);
36
+ target = null; listening = false; last = null;
37
+ },
38
+ };
39
+ }
@@ -0,0 +1,18 @@
1
+ // The server does not catch a player while the place holds them. Keep the
2
+ // client-side floor guard and fall fade on that same condition: otherwise a
3
+ // legitimate low hold fights the server's pose and can leave the view faded.
4
+ // Travel suppresses both too, because the previous place remains in client
5
+ // state until the trip installs its destination.
6
+ export function activeFallY(fallY, held, travelling) {
7
+ return typeof fallY === 'number' && !held && !travelling ? fallY : null;
8
+ }
9
+
10
+ export function holdFallenPlayer(scene, local, fallY) {
11
+ const t = local?.components.Transform;
12
+ if (typeof fallY !== 'number' || !t || t.y >= fallY - 1) {
13
+ return;
14
+ }
15
+ t.y = fallY - 1;
16
+ scene.physics3d?.bodyOf?.(local)?.setTranslation({ x: t.x, y: t.y, z: t.z }, true);
17
+ scene.physics3d?.setVelocity?.(local, { x: 0, y: 0, z: 0 });
18
+ }