castle-web-cli 0.4.237 → 0.4.238

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 (216) hide show
  1. package/dist/bundle.d.ts +24 -0
  2. package/dist/bundle.js +447 -4
  3. package/dist/bundleLatin1.d.ts +6 -0
  4. package/dist/bundleLatin1.js +333 -0
  5. package/dist/castle-host/host.d.ts +10 -1
  6. package/dist/castle-host/host.js +78 -9
  7. package/dist/castleJson.d.ts +2 -0
  8. package/dist/castleJson.js +1 -0
  9. package/dist/deckExports.d.ts +35 -0
  10. package/dist/deckExports.js +365 -0
  11. package/dist/importCheckHook.d.ts +1 -0
  12. package/dist/importCheckHook.js +1 -1
  13. package/dist/index.js +5 -0
  14. package/dist/init.js +2 -1
  15. package/dist/save-deck.js +4 -0
  16. package/kits/base/castle.json +1 -1
  17. package/kits/base/sdk/README.md +47 -0
  18. package/kits/base/sdk/castle.d.ts +3 -1
  19. package/kits/base/sdk/castle.js +1 -0
  20. package/kits/base/sdk/commands.d.ts +25 -1
  21. package/kits/base/sdk/commands.js +29 -1
  22. package/kits/base/sdk/hub.d.ts +17 -0
  23. package/kits/base/sdk/hub.js +33 -9
  24. package/kits/base/sdk/localCache.d.ts +27 -0
  25. package/kits/base/sdk/localCache.js +115 -0
  26. package/kits/base/sdk/localCacheStore.d.ts +15 -0
  27. package/kits/base/sdk/localCacheStore.js +358 -0
  28. package/kits/base/sdk/transport.d.ts +1 -0
  29. package/kits/base/sdk/transport.js +4 -5
  30. package/kits/hub-game/CLAUDE.md +22 -2
  31. package/kits/hub-game/castle.json +4 -1
  32. package/kits/hub-game/code/client/act.js +66 -91
  33. package/kits/hub-game/code/client/actCore.js +134 -0
  34. package/kits/hub-game/code/client/car.js +35 -0
  35. package/kits/hub-game/code/client/chrome.js +207 -381
  36. package/kits/hub-game/code/client/crowdNames.js +2 -2
  37. package/kits/hub-game/code/client/emoteWheel.js +109 -0
  38. package/kits/hub-game/code/client/hats.js +2 -0
  39. package/kits/hub-game/code/client/hookLayer.js +99 -48
  40. package/kits/hub-game/code/client/hostGo.js +77 -0
  41. package/kits/hub-game/code/client/hubControls.js +125 -0
  42. package/kits/hub-game/code/client/hubEntry.js +187 -0
  43. package/kits/hub-game/code/client/hudSurface.js +148 -0
  44. package/kits/hub-game/code/client/hudTree.js +96 -0
  45. package/kits/hub-game/code/client/idle.js +59 -13
  46. package/kits/hub-game/code/client/invites.js +13 -4
  47. package/kits/hub-game/code/client/menuIcons.js +8 -0
  48. package/kits/hub-game/code/client/noTrips.js +38 -0
  49. package/kits/hub-game/code/client/qualityEntry.js +6 -1
  50. package/kits/hub-game/code/client/rehello.js +3 -1
  51. package/kits/hub-game/code/client/riders.js +26 -0
  52. package/kits/hub-game/code/client/role.js +79 -0
  53. package/kits/hub-game/code/client/safeLayout.js +32 -3
  54. package/kits/hub-game/code/client/sound.js +10 -3
  55. package/kits/hub-game/code/client/soundscape.js +2 -2
  56. package/kits/hub-game/code/client/soundscapeAmbience.js +38 -8
  57. package/kits/hub-game/code/client/soundscapeBaked.js +24 -5
  58. package/kits/hub-game/code/client/soundscapeCues.js +2 -1
  59. package/kits/hub-game/code/client/state.js +19 -0
  60. package/kits/hub-game/code/client/stuck.js +2 -1
  61. package/kits/hub-game/code/client/talkSurface.js +178 -0
  62. package/kits/hub-game/code/client/talkTree.js +238 -0
  63. package/kits/hub-game/code/client/tiers.js +8 -5
  64. package/kits/hub-game/code/client/uiDom.js +600 -0
  65. package/kits/hub-game/code/client/uiTree.js +359 -0
  66. package/kits/hub-game/code/client/vehicle.js +154 -0
  67. package/kits/hub-game/code/client/wear.js +27 -5
  68. package/kits/hub-game/code/client/worldLabels.js +3 -2
  69. package/kits/hub-game/code/client/yours.js +10 -3
  70. package/kits/hub-game/code/server/actors.js +4 -3
  71. package/kits/hub-game/code/server/analytics.js +56 -6
  72. package/kits/hub-game/code/server/decor.js +56 -16
  73. package/kits/hub-game/code/server/hub.js +258 -46
  74. package/kits/hub-game/code/server/idle.js +118 -5
  75. package/kits/hub-game/code/server/manifest.js +46 -4
  76. package/kits/hub-game/code/server/npcs.js +4 -2
  77. package/kits/hub-game/code/server/players.js +3 -0
  78. package/kits/hub-game/code/server/role.js +142 -0
  79. package/kits/hub-game/code/server/standing.js +6 -4
  80. package/kits/hub-game/code/server/vehicle.js +126 -0
  81. package/kits/hub-game/code/shared/car.js +52 -0
  82. package/kits/hub-game/code/shared/deckFlags.js +34 -0
  83. package/kits/hub-game/code/shared/deviceClass.js +39 -0
  84. package/kits/hub-game/code/shared/expression.js +9 -0
  85. package/kits/hub-game/code/systems/hub.js +272 -84
  86. package/kits/hub-game/docs/analytics.md +11 -2
  87. package/kits/hub-game/docs/contract.md +352 -14
  88. package/kits/hub-game/docs/vehicle-preset.md +132 -0
  89. package/kits/hub-game/models/hats/baker-cap.pxmodel +89 -0
  90. package/kits/hub-game/models/hats/chef-toque.pxmodel +60 -0
  91. package/kits/hub-game/models/hats/delivery-cap.pxmodel +105 -0
  92. package/kits/hub-game/models/hats/fire-helmet.pxmodel +87 -0
  93. package/kits/hub-game/models/hats/hard-hat.pxmodel +71 -0
  94. package/kits/hub-game/models/hats/nurse-cap.pxmodel +61 -0
  95. package/kits/hub-game/models/hats/police-cap.pxmodel +105 -0
  96. package/kits/hub-game/models/hats/teacher-beret.pxmodel +52 -0
  97. package/kits/hub-game/models/role/square/top-apron.pxmodel +109 -0
  98. package/kits/hub-game/models/role/square/top-cardigan.pxmodel +141 -0
  99. package/kits/hub-game/models/role/square/top-coat.pxmodel +157 -0
  100. package/kits/hub-game/models/role/square/top-scrubs.pxmodel +93 -0
  101. package/kits/hub-game/models/role/square/top-tabard.pxmodel +109 -0
  102. package/kits/hub-game/models/role/square/top-vest.pxmodel +109 -0
  103. package/kits/hub-game/models/role/tool-bag.pxmodel +75 -0
  104. package/kits/hub-game/models/role/tool-bell.pxmodel +71 -0
  105. package/kits/hub-game/models/role/tool-hose.pxmodel +60 -0
  106. package/kits/hub-game/models/role/tool-parcel.pxmodel +61 -0
  107. package/kits/hub-game/models/role/tool-torch.pxmodel +55 -0
  108. package/kits/hub-game/models/role/tool-tray.pxmodel +75 -0
  109. package/kits/hub-game/models/role/top-apron.pxmodel +70 -0
  110. package/kits/hub-game/models/role/top-cardigan.pxmodel +102 -0
  111. package/kits/hub-game/models/role/top-coat.pxmodel +79 -0
  112. package/kits/hub-game/models/role/top-scrubs.pxmodel +54 -0
  113. package/kits/hub-game/models/role/top-tabard.pxmodel +70 -0
  114. package/kits/hub-game/models/role/top-vest.pxmodel +70 -0
  115. package/kits/hub-game/package-lock.json +1 -1
  116. package/kits/hub-game/package.json +1 -1
  117. package/kits/hub-game/scripts/check.mjs +7 -4
  118. package/kits/hub-game/scripts/fixtures/car-vectors.json +279 -0
  119. package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +2 -1
  120. package/kits/hub-game/scripts/fixtures/hud-surface.json +670 -0
  121. package/kits/hub-game/scripts/fixtures/talk-surface.json +3930 -0
  122. package/kits/hub-game/scripts/gen-hats.mjs +46 -2
  123. package/kits/hub-game/scripts/gen-role.mjs +80 -0
  124. package/kits/hub-game/scripts/test-act-core.mjs +167 -0
  125. package/kits/hub-game/scripts/test-actions-client.mjs +34 -0
  126. package/kits/hub-game/scripts/test-actors.mjs +48 -0
  127. package/kits/hub-game/scripts/test-analytics.mjs +99 -5
  128. package/kits/hub-game/scripts/test-apply-deck.mjs +122 -0
  129. package/kits/hub-game/scripts/test-back-visibility.mjs +3 -1
  130. package/kits/hub-game/scripts/test-ballot.mjs +2 -0
  131. package/kits/hub-game/scripts/test-car.mjs +43 -0
  132. package/kits/hub-game/scripts/test-decor-client.mjs +2 -1
  133. package/kits/hub-game/scripts/test-decor.mjs +77 -0
  134. package/kits/hub-game/scripts/test-device-class.mjs +83 -0
  135. package/kits/hub-game/scripts/test-emote-wheel.mjs +374 -0
  136. package/kits/hub-game/scripts/test-hats.mjs +5 -4
  137. package/kits/hub-game/scripts/test-host-go.mjs +265 -0
  138. package/kits/hub-game/scripts/test-hub-controls.mjs +108 -0
  139. package/kits/hub-game/scripts/test-hub-entry.mjs +531 -0
  140. package/kits/hub-game/scripts/test-hub-ops.mjs +75 -0
  141. package/kits/hub-game/scripts/test-hud-clear.mjs +12 -2
  142. package/kits/hub-game/scripts/test-hud-rate.mjs +6 -2
  143. package/kits/hub-game/scripts/test-hud-surface.mjs +272 -0
  144. package/kits/hub-game/scripts/test-idle.mjs +347 -1
  145. package/kits/hub-game/scripts/test-interest-cells.mjs +8 -1
  146. package/kits/hub-game/scripts/test-invites-client.mjs +42 -1
  147. package/kits/hub-game/scripts/test-manifest.mjs +30 -0
  148. package/kits/hub-game/scripts/test-no-trips.mjs +42 -0
  149. package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
  150. package/kits/hub-game/scripts/test-quality.mjs +13 -0
  151. package/kits/hub-game/scripts/test-rehello.mjs +258 -3
  152. package/kits/hub-game/scripts/test-resume-pose-server.mjs +203 -0
  153. package/kits/hub-game/scripts/test-resync.mjs +183 -0
  154. package/kits/hub-game/scripts/test-role-client.mjs +421 -0
  155. package/kits/hub-game/scripts/test-role.mjs +350 -0
  156. package/kits/hub-game/scripts/test-safe-layout.mjs +50 -1
  157. package/kits/hub-game/scripts/test-soundscape.mjs +124 -7
  158. package/kits/hub-game/scripts/test-standing.mjs +15 -1
  159. package/kits/hub-game/scripts/test-talk-surface.mjs +296 -0
  160. package/kits/hub-game/scripts/test-tiers.mjs +13 -0
  161. package/kits/hub-game/scripts/test-ui-dom-dom.mjs +96 -0
  162. package/kits/hub-game/scripts/test-ui-tree.mjs +711 -0
  163. package/kits/hub-game/scripts/test-vehicle-client.mjs +159 -0
  164. package/kits/hub-game/scripts/test-vehicle.mjs +135 -0
  165. package/kits/hub-game/scripts/test-yours.mjs +33 -0
  166. package/kits/hub-game/tools/hubScene/export.mjs +613 -0
  167. package/kits/hub-game/tools/hubScene/hubdata.mjs +921 -0
  168. package/kits/hub-game/tools/hubScene/merge-root.mjs +39 -0
  169. package/kits/hub-game/tools/hubScene/nodeworld.mjs +227 -0
  170. package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +798 -0
  171. package/kits/hub-game/tools/hubScene/test/fixture.json +637 -0
  172. package/kits/hub-game/tools/hubScene/test/paint-export.mjs +40 -0
  173. package/kits/hub-game/tools/hubScene/test/upload.test.mjs +655 -0
  174. package/kits/hub-game/tools/hubScene/upload.mjs +636 -0
  175. package/kits/hub-game/tools/hubScene/validate-manifest.mjs +291 -0
  176. package/kits/multiplayer-3d/castle.json +4 -4
  177. package/kits/multiplayer-3d/code/client/resumeGate.js +30 -2
  178. package/kits/multiplayer-3d/code/client/steer.js +3 -1
  179. package/kits/multiplayer-3d/code/systems/multiplayer.js +30 -2
  180. package/kits/multiplayer-3d/package-lock.json +1 -1
  181. package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +74 -2
  182. package/kits/physics-3d/CLAUDE.md +1 -1
  183. package/kits/physics-3d/behaviors/Player.jsx +37 -27
  184. package/kits/physics-3d/castle.json +2 -2
  185. package/kits/physics-3d/docs/engine-geometry-memory.md +23 -0
  186. package/kits/physics-3d/engine3d/memoryprofile.js +17 -0
  187. package/kits/physics-3d/engine3d/playerRun.js +6 -1
  188. package/kits/physics-3d/engine3d/pxmodel.js +6 -1
  189. package/kits/physics-3d/engine3d/world3d.js +6 -3
  190. package/kits/physics-3d/package.json +1 -1
  191. package/kits/physics-3d/play/behaviors/Player.js +40 -28
  192. package/kits/physics-3d/scripts/test-memory-profile.mjs +237 -0
  193. package/kits/physics-3d/systems/physics3d.js +5 -2
  194. package/kits/real-time/castle.json +2 -2
  195. package/kits/real-time/code/client/messages.js +5 -0
  196. package/kits/real-time/code/server/session.js +28 -1
  197. package/kits/real-time/package-lock.json +1 -1
  198. package/package.json +5 -4
  199. package/vendor/three/LICENSE +21 -0
  200. package/vendor/three/build/three.core.js +58773 -0
  201. package/vendor/three/build/three.module.js +18251 -0
  202. package/vendor/three/examples/jsm/controls/OrbitControls.js +1860 -0
  203. package/vendor/three/examples/jsm/controls/TransformControls.js +1918 -0
  204. package/vendor/three/examples/jsm/exporters/GLTFExporter.js +3595 -0
  205. package/vendor/three/examples/jsm/geometries/RoundedBoxGeometry.js +216 -0
  206. package/vendor/three/examples/jsm/math/MeshSurfaceSampler.js +315 -0
  207. package/vendor/three/examples/jsm/postprocessing/EffectComposer.js +363 -0
  208. package/vendor/three/examples/jsm/postprocessing/MaskPass.js +195 -0
  209. package/vendor/three/examples/jsm/postprocessing/OutputPass.js +139 -0
  210. package/vendor/three/examples/jsm/postprocessing/Pass.js +191 -0
  211. package/vendor/three/examples/jsm/postprocessing/RenderPass.js +183 -0
  212. package/vendor/three/examples/jsm/postprocessing/ShaderPass.js +135 -0
  213. package/vendor/three/examples/jsm/shaders/CopyShader.js +52 -0
  214. package/vendor/three/examples/jsm/shaders/OutputShader.js +103 -0
  215. package/vendor/three/examples/jsm/utils/BufferGeometryUtils.js +1435 -0
  216. package/vendor/three/package.json +134 -0
@@ -2,7 +2,7 @@
2
2
 
3
3
  A game behind a door in the Cauldron hub town. A hub game is a
4
4
  `castle.multiplayer-3d` deck that meets the **hub contract**
5
- (`docs/contract.md`, latest version 1.136; manifest `hub.contract: 1`): the kit
5
+ (`docs/contract.md`, latest version 1.158; manifest `hub.contract: 1`): the kit
6
6
  draws every player as their platform avatar, brings them in at the arrival
7
7
  together and sends them back out
8
8
  through the door they came in by, and draws the HUD, labels and Back control
@@ -39,6 +39,15 @@ notes messages and the client's refill behavior stay exactly as before.
39
39
  `fall(hub, playerId)` (below the place's `fallY`; every place catches at
40
40
  -20 by default, including past the edge of the finite implicit ground).
41
41
  `server.main` stays `imports/castle.hub-game/code/server/index.js`.
42
+ - **Cars (v1.160).** Server-only `hub.drive(playerId, { look, color?, seats?,
43
+ speed?, reverse?, accel?, brake?, turn?, length?, width?, camDistance?,
44
+ camHeight?, horn? })` selects a predicted car on the player's capsule;
45
+ `look` is a scene Model template. At most 24 cars and four seats each.
46
+ `hub.ride(playerId, driverId, seat)` seats a nearby unheld walker (seat 1
47
+ onward), held and drawn from the driver's pose. `hub.vehicle(playerId)`
48
+ reads the role. `drive(id, null, at?)` gets everyone out; `ride(id, null)`
49
+ gets one rider out. Holds stop drivers, walk tune returns on exit; retained
50
+ reconnect keeps cars. Horn must be listed in `idle.sounds`. See contract §6.
42
51
  - **A player's progress between visits** goes in `hub.session.storage.deck`
43
52
  under `'<name>:<userId>'`, never user scope, which their own client can
44
53
  write (contract §14).
@@ -79,6 +88,11 @@ notes messages and the client's refill behavior stay exactly as before.
79
88
  `result(playerId, { outcome, score, stats })`, `results(playerId)` (ghost's
80
89
  recent results and records of a player), `end(playerIds?)`,
81
90
  `go(door, playerIds)`, `send`, `broadcast`, `session`, `sim`, `place`.
91
+ - **Visit roles** (v1.157): `hub.role(playerId, { id, label, color, hat?, top?, tool? } | null)`
92
+ dresses a player for this visit; `hub.roleOf(playerId)` returns a copy or null.
93
+ Role hat > try-on > owned Look. Tops hide earned belt/sash; tools hide earned
94
+ held items. The coloured label sits below the name. Nothing goes to ghost;
95
+ retained reconnect keeps it, leave/end/account change clears it. Contract §11.
82
96
  - **Place menu** (v1.79): only with `menu: true`,
83
97
  `hub.menu(playerId, { title, note?, readOnly?, face?, sections: [{ title, items:
84
98
  [{ id, label, color?, icon?, on? }] }] } | null)` offers that player a
@@ -289,7 +303,7 @@ notes messages and the client's refill behavior stay exactly as before.
289
303
  and on a phone on its side the text keeps to two lines. Without it the HUD
290
304
  and labels are drawn as they always were.
291
305
  - **Idle play** (contract v1.6): `"idle": true` in the `hub` block (or
292
- `{ emotes, seats, sounds: ["sounds/x.mp3"] }`) gives players an emote picker
306
+ `{ emotes, seats, sounds: ["sounds/x.mp3"], expression }`) gives players an emote picker
293
307
  (wave, dance, cheer, bow, spin, drawn on their avatar) and Sit on scene
294
308
  actors carrying `HubSeat` (`{ face, height, pose }`, all optional; v1.82 `pose: "lie"` offers Lie down and draws a back-lying player, absent/`"sit"` keeps Sit); a seat is a hold, so the
295
309
  place's `hub.release` stands a sitter. Hooks `emote(hub, playerId, id)` and
@@ -298,6 +312,11 @@ notes messages and the client's refill behavior stay exactly as before.
298
312
  radius })` / `hub.sound(actorId, null)` for a listed sound file of the deck
299
313
  (carried in its content pack's `audio`, so a game behind a door sounds too;
300
314
  silent only on a town whose engine predates that).
315
+ v1.158 `expression: true` (requires `emotes: true`) replaces the picker with
316
+ an RP wheel and sit-anywhere (`hub.seat` returns `'ground'`, sit hook gets
317
+ null). `{ roleEmotes: [{ id, emoji, label, motion, ms }] }` declares up to
318
+ 12 role emotes; `hub.emotesFor(playerId, ids | null)` grants them for the
319
+ visit, privately. Absent expression keeps existing UI and wire bytes (§6).
301
320
  - **The soundscape** (contract v1.42, v1.49, v1.50, v1.56, v1.60): `"soundscape": true` in the `hub`
302
321
  block (or `{ babble, steps }`, each on unless `false`; the deck's, not a
303
322
  place's) has the kit make its own sounds, synthesised in the client and
@@ -494,6 +513,7 @@ notes messages and the client's refill behavior stay exactly as before.
494
513
  | `scripts/check.mjs` | the publish check (`onCheck`) |
495
514
  | `scripts/pack.mjs` | the content pack exporter (`onPack`): the deck's client half as data, for another deck's engine (`docs/content-pack.md`) |
496
515
  | `code/client/pack.js`, `packFormat.js`, `sha256.js` | mounting a pack: fetch, verify, validate, build content |
516
+ | `tools/hubScene/` | the save-time HubSceneManifest exporter (castle.json `exports.hubScene`, run by `castle-web export`, and by `save-deck` under `CASTLE_SAVE_EXPORTS=1`): the deck's world built in Node with the CLI's own shipped kits (the loader refuses any other module; a deck's imports/ is read as data only), written into a stage the CLI then moves to `.castle/exports/hubScene/`; glbs are content-addressed in `~/.castle/export-cache/hubScene/shared/` (created exclusively, never overwritten; no GC yet), and the last manifest is reused while its key (CLI version, the shipped kit trees, three, every data file read) holds; `validate-manifest.mjs` checks it, `merge-root.mjs` merges decks into one root for the native host, `test/export-fixture.mjs` is its test. Manifest v1.4 adds `deck` (the hub block's client flags, `code/shared/deckFlags.js`) and `interactables` (HubNpc, HubAct and HubSeat actors as `{ id, components }` with their Transform, and, when the scene opts in to chat Report & block, the component-only `{ id: 'hub-chat-moderation', components: { HubChatModeration: { v: 1 } } }`) for the DOM-less native kit, which applies `deck` with `hookLayer.applyDeck` (`scripts/test-apply-deck.mjs`). v1.6 (`format` and `version` unchanged) adds the deck's sound: each file the hub block's root and places' `idle.sounds` name, read as the page's initialMedia holds it (the deck's own .mp3/.wav/.m4a; others are left out with a source note), is a content-addressed asset mapped by its castle.json path in `audio`; `deck` keeps `soundscape` and the root and places' `idle` at their keys; `interactables` adds the `jukebox` actor (Shape, Lookable, Transform) and every actor carrying a component the soundscape names (`zones`, `steps.paths`, `ambience.spots` keys), whole, with its Transform. v1.7 (`format` and `version` still unchanged) always adds `avatarFits` (16 entries per style after `Avatar.drawn` fallback, earned fit arrays verbatim, `hat` and `top`), `wearModels` (untinted content-addressed glb asset records for every hat, earned and role model, including square variants, also registered in `assets`) and `wearPieces` (anchors, constant scales, main colours to tint and fit-dependent placement notes). Fits are over feet; placement shifts to the avatar origin as in `wear.js`. Ring `scale` is the unchanged height scale; horizontal stretch and all top scaling depend on the fit. Hats retain authored colours; lantern/lighthouse perch on the crown (`wear.js`), while other hats sit at the seat. The shipped client avatar/role/earned/hats modules and model files are already covered by the kits hash. Upload rewrites the embedded wear asset URIs too. Earlier fields match castle-client's live-page exporter (`nativetown/hubscene/tools/export-hub.mjs`) |
497
517
  | `scripts/test-manifest.mjs`, `test-pack.mjs`, `test-actors.mjs`, `test-idle.mjs`, `test-classic.mjs` | tests over the manifest, results, place resolution, the pack, moved and painted actors, idle play, and cabinets |
498
518
  | `scripts/test-avatar.mjs`, `test-avatar-models.mjs`, `test-picker.mjs` | the avatar seam; the toon models held to the generator and to 1,500 triangles and 8 draw calls (the engine's own count); the character picker |
499
519
  | `code/client/avatarCap.js`, `scripts/test-avatar-cap.mjs` | a limit on different characters drawn at once, by default all sixteen (no stand-ins); with `?hubAvDistinct=N`, at most N (the local player's included): the farthest players past that are drawn as their stand-in (`avatar % 4`), never anyone within 8 m, with hysteresis, respawned through the hook layer's avatar-change path; client display only. `?hubAvDistinct=N` sets the limit (absent or 0 the default) |
@@ -92,5 +92,8 @@
92
92
  }
93
93
  },
94
94
  "onCheck": "scripts/check.mjs",
95
- "onPack": "scripts/pack.mjs"
95
+ "onPack": "scripts/pack.mjs",
96
+ "exports": {
97
+ "hubScene": "tools/hubScene/export.mjs"
98
+ }
96
99
  }
@@ -1,10 +1,10 @@
1
1
  // Shared Act/Jump controls, allocated only by hub.act. All text comes from
2
2
  // the server's current private offer; scene data supplies its world anchor.
3
3
  import { makeLayoutCache } from './layoutCache.js';
4
- import { hub } from './state.js';
5
- import { footprintDistance } from './idle.js';
6
4
  import { clearBox } from './padOccupancy.js';
7
- import { interaction } from '../shared/act.js';
5
+ import { mountUiTree } from './uiDom.js';
6
+ import { buildActPair } from './hudTree.js';
7
+ import { makeActCore } from './actCore.js';
8
8
 
9
9
  const intersects = (a, b) => a.left < b.right && a.right > b.left && a.top < b.bottom && a.bottom > b.top;
10
10
  export function placeBox(w, h, preferred, bounds, obstacles) {
@@ -21,9 +21,6 @@ export function placeBox(w, h, preferred, bounds, obstacles) {
21
21
  return null;
22
22
  }
23
23
  const textEntry = event => event.target?.isContentEditable || ['INPUT', 'TEXTAREA', 'SELECT'].includes(event.target?.tagName);
24
- // Authored counter verbs (Trade, Stamp, Buy, Play, Sit...) take focus over a
25
- // nearby loose body or keeper; distance decides only within a rank.
26
- const rank = item => item.op === 'talk' || item.op === 'grab' ? 1 : 0;
27
24
  const typing = event => textEntry(event) || event.target?.tagName === 'BUTTON';
28
25
  // Break only at spaces, keeping any omission after a complete word. Explicit
29
26
  // line breaks avoid browser line-clamp ellipses in the middle of a name.
@@ -64,53 +61,54 @@ export function makeAct(chrome, grab, talk) {
64
61
  const root = document.createElement('div');
65
62
  Object.assign(root.style, { position: 'absolute', inset: '0', pointerEvents: 'none', zIndex: '2' });
66
63
  chrome.interactionRoot().appendChild(root);
67
- const pair = document.createElement('div');
68
- Object.assign(pair.style, { position: 'absolute', width: '134px', height: '48px', pointerEvents: 'none', display: 'none' });
69
- root.appendChild(pair);
70
- const act = el(pair, 'act', 'Act'), jump = el(pair, 'jump', 'Jump');
71
- Object.assign(act.style, { left: '70px', top: '0', height: '48px', padding: '8px', whiteSpace: 'nowrap' });
72
- Object.assign(jump.style, { left: '0', top: '0', height: '48px', padding: '8px', whiteSpace: 'nowrap' });
64
+ // The Act/Jump pair is the HUD root's `actpair` node (`hudTree.js`): drawn
65
+ // here, in this layer, by the UI tree's DOM renderer, and handed to the
66
+ // chrome so a native host's HUD tree carries it too. Its presses come back
67
+ // as the tree's events. Selection, presses and Jump are `actCore.js`'s.
68
+ const core = makeActCore({
69
+ now: () => performance.now(),
70
+ send: (message, mp) => mp.net?.send(message),
71
+ effects: {
72
+ throw: (item, f, done) => grab.perform(item.actor, f.scene, f.mp, f.local, item.op, done),
73
+ grab: (item, f) => grab.perform(item.actor, f.scene, f.mp, f.local, item.op),
74
+ talk: item => talk.prepare(item.actor),
75
+ },
76
+ });
77
+ const pairState = { show: false, enabled: false, on: {
78
+ press: ({ pointerId } = {}) => {keyboardInput = false; core.start(core.current(), `pointer:${pointerId}`);},
79
+ release: ({ pointerId } = {}) => {if (core.pressSource() === `pointer:${pointerId}`) {core.release();}},
80
+ cancel: ({ pointerId } = {}) => {if (core.pressSource() === `pointer:${pointerId}`) {core.cancel();}},
81
+ jump: () => {keyboardInput = false; core.queueJump();},
82
+ } };
83
+ const pairDom = mountUiTree(root);
84
+ let pairKey = '';
85
+ function drawPair() {
86
+ const key = `${pairState.show}:${pairState.enabled}`;
87
+ if (key === pairKey) {return;}
88
+ pairKey = key;
89
+ pairDom.render({ t: 'stack', k: 'act', c: [buildActPair(pairState)] });
90
+ chrome.setActPair?.(pairState);
91
+ }
92
+ drawPair();
93
+ const pair = pairDom.nodeFor('act/actpair');
94
+ const act = pairDom.nodeFor('act/actpair/act'), jump = pairDom.nodeFor('act/actpair/jump');
73
95
  chrome.interactionRail(pair, act, jump);
74
- act.style.width = jump.style.width = '64px';
75
96
  const probe = document.createElement('div');
76
97
  Object.assign(probe.style, { position: 'absolute', visibility: 'hidden', pointerEvents: 'none', padding: 'env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left)' });
77
98
  root.appendChild(probe);
78
99
  geometry.register(probe, { padding: true });
79
100
  for (const node of [pair, act, jump]) {geometry.register(node);}
80
101
  const nodes = new Map(), listeners = new AbortController(), signal = listeners.signal;
81
- let current = null, context = null, press = null, seq = Date.now() * 1000, queuedJump = false, input = null, originalJump = null;
102
+ let input = null, originalJump = null;
82
103
  let keyboardInput = false;
83
104
  let textMeasure;
84
105
  chrome.setActMode(true);
85
- function cancel() {
86
- if (press) {context?.mp.net?.send({ k: 'hub-act-hold', id: press.id, n: press.n, down: false });}
87
- press = null;
88
- }
89
- function perform(item, n) {
90
- const c = context;
91
- if (!c?.can || !item) {return;}
92
- // The existing client prediction/denial paths carry grabs and NPC panels.
93
- if (item.op === 'throw') {
94
- grab.perform(item.actor, c.scene, c.mp, c.local, item.op, () => c.mp.net.send({ k: 'hub-act', id: item.id, n }));
95
- return;
96
- }
97
- if (item.op === 'grab') {grab.perform(item.actor, c.scene, c.mp, c.local, item.op);}
98
- if (item.op === 'talk') {talk.prepare(item.actor);}
99
- c.mp.net.send({ k: 'hub-act', id: item.id, n });
100
- }
101
- function release() {
102
- if (!press || performance.now() - press.at < 500) {cancel(); return;}
103
- const done = press; press = null; perform(done.item, done.n);
104
- }
105
- function start(item, source) {
106
- if (!context?.can || !item || press) {return;}
107
- const n = ++seq;
108
- if (item.hold) {
109
- press = { id: item.id, n, at: performance.now(), source, item };
110
- context.mp.net.send({ k: 'hub-act-hold', id: item.id, n, down: true });
111
- } else {perform(item, n);}
112
- }
106
+ const start = (item, source) => core.start(item, source);
113
107
  function bind(node, item) {
108
+ bindPointer(node, item);
109
+ bindKeys(node, item);
110
+ }
111
+ function bindPointer(node, item) {
114
112
  node.addEventListener('pointerdown', event => {
115
113
  keyboardInput = false;
116
114
  event.preventDefault(); event.stopPropagation();
@@ -120,11 +118,13 @@ export function makeAct(chrome, grab, talk) {
120
118
  for (const type of ['pointerup', 'pointercancel', 'lostpointercapture']) {
121
119
  node.addEventListener(type, event => {
122
120
  event.preventDefault(); event.stopPropagation();
123
- if (press?.source === `pointer:${event.pointerId}`) {
124
- if (type === 'pointerup') {release();} else {cancel();}
121
+ if (core.pressSource() === `pointer:${event.pointerId}`) {
122
+ if (type === 'pointerup') {core.release();} else {core.cancel();}
125
123
  }
126
124
  }, { signal });
127
125
  }
126
+ }
127
+ function bindKeys(node, item) {
128
128
  node.addEventListener('keydown', event => {
129
129
  if (event.code === 'Space' || event.code === 'Enter') {
130
130
  keyboardInput = true;
@@ -140,7 +140,7 @@ export function makeAct(chrome, grab, talk) {
140
140
  }, { signal });
141
141
  node.addEventListener('keyup', event => {
142
142
  if (['Space', 'Enter'].includes(event.code)) {event.stopPropagation();}
143
- if (press?.source === event.code) {event.preventDefault(); release();}
143
+ if (core.pressSource() === event.code) {event.preventDefault(); core.release();}
144
144
  }, { signal });
145
145
  // Synthesized activation has no hold duration. It can activate ordinary
146
146
  // actions; spending still requires sustained pointer or keyboard input.
@@ -151,64 +151,42 @@ export function makeAct(chrome, grab, talk) {
151
151
  if (chosen && !chosen.hold) {start(chosen, 'click');}
152
152
  }, { signal });
153
153
  }
154
- bind(act, () => current);
155
- jump.addEventListener('pointerdown', event => {keyboardInput = false; event.preventDefault(); event.stopPropagation(); if (context?.can) {queuedJump = true;}}, { signal });
154
+ bindKeys(act, () => core.current());
156
155
  jump.addEventListener('keydown', event => {
157
- if (['Space', 'Enter'].includes(event.code)) {keyboardInput = true; event.preventDefault(); event.stopPropagation(); if (!event.repeat && context?.can) {queuedJump = true;}}
156
+ if (['Space', 'Enter'].includes(event.code)) {keyboardInput = true; event.preventDefault(); event.stopPropagation(); if (!event.repeat) {core.queueJump();}}
158
157
  }, { signal });
159
- jump.addEventListener('click', event => {if (event.detail === 0 && context?.can) {queuedJump = true;}}, { signal });
158
+ jump.addEventListener('click', event => {if (event.detail === 0) {core.queueJump();}}, { signal });
160
159
  globalThis.addEventListener?.('pointerdown', () => {keyboardInput = false;}, { capture: true, signal });
161
160
  globalThis.addEventListener?.('keydown', event => {
162
161
  // Pointer capability does not establish a hardware-keyboard input.
163
162
  // Observe game/navigation keys outside editable or composing text instead.
164
163
  if (!textEntry(event) && !event.isComposing && !event.altKey && !event.ctrlKey && !event.metaKey &&
165
164
  /^(Key[WASDEF]|Arrow(Up|Down|Left|Right)|Space|Enter|Tab)$/.test(event.code)) {keyboardInput = true;}
166
- if (typing(event) || event.altKey || event.ctrlKey || event.metaKey || !context?.can) {return;}
165
+ if (typing(event) || event.altKey || event.ctrlKey || event.metaKey || !core.can()) {return;}
166
+ const current = core.current();
167
167
  if (event.code === 'KeyE' || (event.code === 'Space' && current)) {
168
168
  event.preventDefault(); event.stopImmediatePropagation();
169
- if (event.code === 'Space') {context.scene.keys?.delete?.('Space');}
169
+ if (event.code === 'Space') {core.facade().scene.keys?.delete?.('Space');}
170
170
  if (!event.repeat) {start(current, event.code);}
171
171
  }
172
172
  }, { capture: true, signal });
173
173
  globalThis.addEventListener?.('keyup', event => {
174
- if (press?.source === event.code) {release();}
175
- if (event.code === 'Space') {context?.scene.keys?.delete?.('Space');}
174
+ if (core.pressSource() === event.code) {core.release();}
175
+ if (event.code === 'Space') {core.facade()?.scene.keys?.delete?.('Space');}
176
176
  }, { capture: true, signal });
177
- globalThis.addEventListener?.('blur', cancel, { signal });
178
- document.addEventListener('visibilitychange', () => {if (document.hidden) {cancel();}}, { signal });
177
+ globalThis.addEventListener?.('blur', core.cancel, { signal });
178
+ document.addEventListener('visibilitychange', () => {if (document.hidden) {core.cancel();}}, { signal });
179
179
  function frame(scene, mp, local, can) {
180
- const self = mp.net?.selfId?.();
181
- can = can && (!hub.held.has(self) || Object.hasOwn(hub.seated, self));
182
180
  const status = mp.net?.status?.();
183
- const connected = mp.net && self && local?.components.Transform && (!status || status.state === 'connected');
184
- const changed = context && (context.scene !== scene || context.mp.net !== mp.net || context.self !== self || context.place !== hub.place?.id);
185
- if (changed || !can || !connected) {cancel(); queuedJump = false;}
181
+ const changed = core.frame({ scene, link: mp, self: mp.net?.selfId?.(), player: local?.components.Transform,
182
+ online: !status || status.state === 'connected', actors: () => scene.getActors(), getActor: id => scene.getActor(id), mp, local }, can);
186
183
  if (changed) {keyboardInput = false;}
187
- context = { scene, mp, local, can: Boolean(can && connected), self, place: hub.place?.id };
188
184
  if (scene.moveInput && input !== scene.moveInput) {
189
185
  if (input?.consumeJump === consumeJump) {input.consumeJump = originalJump;}
190
186
  input = scene.moveInput; originalJump = input.consumeJump;
191
187
  input.consumeJump = consumeJump;
192
188
  }
193
- const actors = scene.getActors(), authored = new Map();
194
- for (const actor of actors) {
195
- const item = interaction(actor, hub.place ?? {}, Object.hasOwn(hub.spawned, actor.id));
196
- if (item) {authored.set(item.id, item);}
197
- }
198
- const me = local?.components.Transform;
199
- const items = (context.can ? hub.prompts ?? [] : []).flatMap(item => {
200
- const base = authored.get(item.id), actor = base && scene.getActor(base.actor), t = actor?.components.Transform;
201
- if (!base || !t || hub.hidden.has(actor.id)) {return [];}
202
- // Stand and Throw are server-selected states of the same actor.
203
- const op = item.verb === 'Stand' && base.op === 'sit' ? 'stand' : item.verb === 'Throw' && base.op === 'grab' ? 'throw' : base.op;
204
- const d = op === 'throw' ? 0 : base.op === 'sit' ? footprintDistance(actor, me) : Math.hypot(t.x - me.x, t.y - me.y, t.z - me.z);
205
- return d <= base.reach ? [{ ...base, ...item, op, t, d }] : [];
206
- }).sort((a, b) => rank(a) - rank(b) || a.d - b.d || a.id.localeCompare(b.id));
207
- current = items[0] ?? null;
208
- if (press && !items.some(item => item.id === press.id && item.verb === press.item.verb && item.hold === press.item.hold)) {cancel();}
209
- if (press && performance.now() - press.at >= 500) {
210
- const done = press; press = null; perform(done.item, done.n);
211
- }
189
+ const items = core.items(), current = core.current();
212
190
  const visible = new Set(items.map(item => item.id));
213
191
  for (const [id, node] of nodes) {if (!visible.has(id)) {chrome.safeSurface?.(`act-prompt:${id}`, null); geometry.unregister(node); node.remove(); nodes.delete(id);}}
214
192
  for (const item of items) {
@@ -217,7 +195,7 @@ export function makeAct(chrome, grab, talk) {
217
195
  node = el(root, 'prompt', ''); nodes.set(item.id, node);
218
196
  geometry.register(node, { positioned: true });
219
197
  chrome.safeSurface?.(`act-prompt:${item.id}`, node, 'control', { transient: true });
220
- bind(node, () => context?.can ? node._actItem : null);
198
+ bind(node, () => core.can() ? node._actItem : null);
221
199
  }
222
200
  node._actItem = item;
223
201
  const label = `${item.verb}${keyboardInput ? ' · E' : ''}`;
@@ -226,20 +204,16 @@ export function makeAct(chrome, grab, talk) {
226
204
  if (node.title !== item.verb) {node.title = item.verb;}
227
205
  node.style.opacity = item.id === current?.id ? '1' : '.55';
228
206
  node.style.borderColor = item.id === current?.id ? '#f2c94c' : 'rgba(255,255,255,.55)';
229
- const progress = press?.id === item.id ? Math.min(1, (performance.now() - press.at) / 500) : 0;
207
+ const progress = core.progress(item.id);
230
208
  node.style.background = progress ? `linear-gradient(90deg, #806521 ${progress * 100}%, rgba(20,16,12,.88) ${progress * 100}%)` : 'rgba(20,16,12,.88)';
231
209
  }
232
- act.disabled = !current;
233
- act.style.opacity = current ? '1' : '.5';
234
- pair.style.display = context.can ? 'block' : 'none';
235
- act.style.display = jump.style.display = context.can ? 'block' : 'none';
210
+ Object.assign(pairState, core.pairState());
211
+ drawPair();
236
212
  chrome.layoutInteractionRail();
237
213
  layout(scene, items);
238
214
  }
239
215
  function consumeJump(...args) {
240
- const own = queuedJump; queuedJump = false;
241
- const had = originalJump?.apply(this, args);
242
- return context?.can && (own || had);
216
+ return core.consumeJump(() => originalJump?.apply(this, args));
243
217
  }
244
218
  function layout(scene, items) {
245
219
  const { w, h } = geometry.view(), inset = geometry.padding(probe);
@@ -284,7 +258,7 @@ export function makeAct(chrome, grab, talk) {
284
258
  const at = { left, right: left + r.width, top, bottom: top + r.height };
285
259
  // A secondary prompt with nowhere clear yields rather than cover the
286
260
  // player; the focused one keeps its projected place.
287
- box = clearBox(at, placed, { w, h, bounds }, avatar) ?? (item === current ? at : null);
261
+ box = clearBox(at, placed, { w, h, bounds }, avatar) ?? (item === core.current() ? at : null);
288
262
  } else {box = placeBox(r.width, r.height, preferred, bounds, obstacles);}
289
263
  if (box) {
290
264
  Object.assign(node.style, { left: `${box.left}px`, top: `${box.top}px` }); obstacles.push(box);
@@ -301,9 +275,10 @@ export function makeAct(chrome, grab, talk) {
301
275
  },
302
276
  endLayoutFrame() {if (!sharedGeometry) {geometry.endFrame();}},
303
277
  dispose() {
304
- cancel(); listeners.abort(); geometry.unregister(root);
278
+ core.dispose(); listeners.abort(); geometry.unregister(root);
305
279
  if (!sharedGeometry) {geometry.dispose();}
306
280
  chrome.interactionRail(null);
281
+ chrome.setActPair?.(null);
307
282
  for (const [id] of nodes) {chrome.safeSurface?.(`act-prompt:${id}`, null);}
308
283
  root.remove(); chrome.setActMode(false);
309
284
  if (input?.consumeJump === consumeJump) {input.consumeJump = originalJump;}
@@ -0,0 +1,134 @@
1
+ // The DOM-less half of Act (v1.127): which of the server's private offers the
2
+ // player can act on and which one Act takes, press/hold/release/perform, what
3
+ // the Act/Jump pair shows and the queued Jump. `act.js` draws it on the web
4
+ // (prompt chips, keys, layout); a native host drives the same core over its
5
+ // own scene facade.
6
+ //
7
+ // makeActCore({ now, send, state, effects, seq }):
8
+ // now() a millisecond clock (the web passes performance.now)
9
+ // send(message, link) sends `hub-act` / `hub-act-hold` on `link.net`, the
10
+ // link of the frame the press was made in
11
+ // state the hub client state (`state.js` `hub`): place, prompts,
12
+ // held, seated, spawned, hidden
13
+ // effects optional { throw(item, facade, done), grab(item, facade),
14
+ // talk(item, facade) }: the client prediction and panel paths
15
+ // run as an item is performed. A Throw sends when its effect
16
+ // calls `done`, or at once without one.
17
+ // seq the first press nonce (Date.now() * 1000)
18
+ //
19
+ // frame(facade, can), once per frame, with the scene facade:
20
+ // { scene, link, self, player, online, actors(), getActor(id) }
21
+ // scene an identity: another scene cancels any press and queued Jump
22
+ // link the connection's holder, whose `net` (with `send`) is read
23
+ // live, as the web reads its multiplayer object's: another
24
+ // `link.net` is a change too, but a net replaced inside the
25
+ // same link is the link's own business
26
+ // self the local player id
27
+ // player the local player's Transform ({ x, y, z }), or null
28
+ // online the connection is up
29
+ // actors() the scene's actors ({ id, components }); interaction()
30
+ // reads HubAct, HubSeat, HubNpc and a dynamic Body
31
+ // getActor(id) one actor by id, with its Transform
32
+ // Any other facade field is the host's own, handed back to `effects`; the
33
+ // core keeps its own copy of the identities, so a host may reuse one facade.
34
+ import { hub as hubState } from './state.js';
35
+ import { footprintDistance } from './idle.js';
36
+ import { interaction } from '../shared/act.js';
37
+
38
+ export const HOLD_MS = 500;
39
+ // Authored counter verbs (Trade, Stamp, Buy, Play, Sit...) take focus over a
40
+ // nearby loose body or keeper; distance decides only within a rank.
41
+ export const rank = item => item.op === 'talk' || item.op === 'grab' ? 1 : 0;
42
+
43
+ // The offers in reach, focused first: `state.prompts` joined with the scene's
44
+ // authored interactions, nearest within a rank, then by id.
45
+ export function actItems(facade, state, can) {
46
+ const authored = new Map();
47
+ for (const actor of facade.actors()) {
48
+ const item = interaction(actor, state.place ?? {}, Object.hasOwn(state.spawned, actor.id));
49
+ if (item) {authored.set(item.id, item);}
50
+ }
51
+ const me = facade.player;
52
+ return (can ? state.prompts ?? [] : []).flatMap(item => {
53
+ const base = authored.get(item.id), actor = base && facade.getActor(base.actor), t = actor?.components.Transform;
54
+ if (!base || !t || state.hidden.has(actor.id)) {return [];}
55
+ // Stand and Throw are server-selected states of the same actor.
56
+ const op = item.verb === 'Stand' && base.op === 'sit' ? 'stand' : item.verb === 'Throw' && base.op === 'grab' ? 'throw' : base.op;
57
+ const d = op === 'throw' ? 0 : base.op === 'sit' ? footprintDistance(actor, me) : Math.hypot(t.x - me.x, t.y - me.y, t.z - me.z);
58
+ return d <= base.reach ? [{ ...base, ...item, op, t, d }] : [];
59
+ }).sort((a, b) => rank(a) - rank(b) || a.d - b.d || a.id.localeCompare(b.id));
60
+ }
61
+
62
+ export function makeActCore({ now, send, state = hubState, effects = {}, seq = Date.now() * 1000 }) {
63
+ let current = null, context = null, press = null, queuedJump = false, items = [];
64
+ function cancel() {
65
+ if (press) {send({ k: 'hub-act-hold', id: press.id, n: press.n, down: false }, context.link);}
66
+ press = null;
67
+ }
68
+ function perform(item, n) {
69
+ const c = context;
70
+ if (!c?.can || !item) {return;}
71
+ // The existing client prediction/denial paths carry grabs and NPC panels.
72
+ if (item.op === 'throw') {
73
+ const done = () => send({ k: 'hub-act', id: item.id, n }, c.link);
74
+ if (effects.throw) {effects.throw(item, c.facade, done);} else {done();}
75
+ return;
76
+ }
77
+ if (item.op === 'grab') {effects.grab?.(item, c.facade);}
78
+ if (item.op === 'talk') {effects.talk?.(item, c.facade);}
79
+ send({ k: 'hub-act', id: item.id, n }, c.link);
80
+ }
81
+ function release() {
82
+ if (!press || now() - press.at < HOLD_MS) {cancel(); return;}
83
+ const done = press; press = null; perform(done.item, done.n);
84
+ }
85
+ function start(item, source) {
86
+ if (!context?.can || !item || press) {return;}
87
+ const n = ++seq;
88
+ if (item.hold) {
89
+ press = { id: item.id, n, at: now(), source, item };
90
+ send({ k: 'hub-act-hold', id: item.id, n, down: true }, context.link);
91
+ } else {perform(item, n);}
92
+ }
93
+ // Returns whether the context changed (another scene, connection, player or
94
+ // place), which also drops a host's keyboard-hint state.
95
+ function frame(facade, can) {
96
+ const self = facade.self;
97
+ can = can && (!state.held.has(self) || Object.hasOwn(state.seated, self));
98
+ const { scene, link } = facade;
99
+ const connected = link.net && self && facade.player && facade.online;
100
+ const changed = Boolean(context && (context.scene !== scene || context.link.net !== link.net ||
101
+ context.self !== self || context.place !== state.place?.id));
102
+ if (changed || !can || !connected) {cancel(); queuedJump = false;}
103
+ context = { facade, scene, link, can: Boolean(can && connected), self, place: state.place?.id };
104
+ items = actItems(facade, state, context.can);
105
+ current = items[0] ?? null;
106
+ if (press && !items.some(item => item.id === press.id && item.verb === press.item.verb && item.hold === press.item.hold)) {cancel();}
107
+ if (press && now() - press.at >= HOLD_MS) {
108
+ const done = press; press = null; perform(done.item, done.n);
109
+ }
110
+ return changed;
111
+ }
112
+ return {
113
+ frame, start, release, cancel,
114
+ items: () => items,
115
+ current: () => current,
116
+ can: () => Boolean(context?.can),
117
+ facade: () => context?.facade ?? null,
118
+ // The source ('pointer:<id>', a key code, 'click') of the press in progress.
119
+ pressSource: () => press?.source ?? null,
120
+ // 0..1 of the hold on this item, 0 when it is not being held.
121
+ progress: id => press?.id === id ? Math.min(1, (now() - press.at) / HOLD_MS) : 0,
122
+ // What the Act/Jump pair shows: shown while acting is allowed, Act
123
+ // enabled while something is in reach.
124
+ pairState: () => ({ show: Boolean(context?.can), enabled: Boolean(current) }),
125
+ queueJump() {if (context?.can) {queuedJump = true;}},
126
+ // The movement input's Jump: this pair's queued Jump or the original's.
127
+ consumeJump(original) {
128
+ const own = queuedJump; queuedJump = false;
129
+ const had = original?.();
130
+ return context?.can && (own || had);
131
+ },
132
+ dispose: cancel,
133
+ };
134
+ }
@@ -0,0 +1,35 @@
1
+ // Pure car dynamics, contract v1.160. Heading in radians, signed speed in m/s.
2
+ const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
3
+ const toward = (v, target, amount) => v + clamp(target - v, -amount, amount);
4
+ export function carInput(keys, stick) {
5
+ const held = (...codes) => codes.some(code => keys?.has?.(code));
6
+ let forward = Number(held('KeyW', 'ArrowUp')) - Number(held('KeyS', 'ArrowDown'));
7
+ let steer = Number(held('KeyD', 'ArrowRight')) - Number(held('KeyA', 'ArrowLeft'));
8
+ if (!forward && !steer && stick?.active && Math.hypot(stick.x, stick.y) >= 0.15) {
9
+ forward = -stick.y;
10
+ steer = stick.x;
11
+ }
12
+ return { forward: clamp(forward, -1, 1), steer: clamp(steer, -1, 1) };
13
+ }
14
+ export function bumperBlocked(speed, forward, front, back, length) {
15
+ const direction = Math.sign(speed) || Math.sign(forward);
16
+ const hit = direction > 0 ? front : direction < 0 ? back : null;
17
+ return Number.isFinite(hit) && hit >= 0 && hit <= length / 2;
18
+ }
19
+ export function stepCar(state, input, car, dt) {
20
+ dt = Number.isFinite(dt) ? Math.max(0, dt) : 0;
21
+ const forward = clamp(input.forward || 0, -1, 1), steer = clamp(input.steer || 0, -1, 1);
22
+ let speed = clamp(state.speed || 0, -car.reverse, car.speed);
23
+ const target = forward * (forward < 0 ? car.reverse : car.speed);
24
+ if (!forward) {speed = toward(speed, 0, 2 * dt);}
25
+ else if (speed * forward < 0) {
26
+ const braking = Math.min(dt, Math.abs(speed) / car.brake);
27
+ speed = toward(speed, 0, car.brake * braking);
28
+ speed = toward(speed, target, car.accel * (dt - braking));
29
+ } else {speed = toward(speed, target, car.accel * dt);}
30
+ if (bumperBlocked(speed, forward, input.front, input.back, car.length)) {speed = 0;}
31
+ // Steering right lowers the heading, as the walk's right turn lowers its
32
+ // facing: heading 0 runs along +Z, and a right turn swings toward -X.
33
+ const heading = (state.heading || 0) - car.turn * steer * Math.min(1, Math.abs(speed) / 4) * Math.sign(speed) * dt;
34
+ return { ...state, speed, heading };
35
+ }