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
@@ -0,0 +1,359 @@
1
+ // Hub UI tree, schema v0: the screen UI described as plain data. A builder is
2
+ // a pure function (state) -> node; two renderers draw the same node: on web
3
+ // `uiDom.js` (keyed DOM, the same inline styles the chrome always wrote), on
4
+ // native the host's renderer, which gets each root's tree through the sink
5
+ // (`setUiTreeSink`). Nothing here touches `window` or `document`, so the
6
+ // native JS host can import it before any DOM exists.
7
+ //
8
+ // A node is { t, k?, s?, at?, on?, c?, ...type fields }:
9
+ // t the type: column row stack scroll grid text button field image icon
10
+ // activity spacer;
11
+ // k its key, unique among its siblings (default `#<index>`); the keys from
12
+ // the root down, joined with '/', are its path ('%' and '/' in a key are
13
+ // written %25 and %2F there, so a key 'a/b' is never the path of 'b'
14
+ // inside 'a');
15
+ // s its style, the closed subset in STYLE_KEYS (text keys inherit);
16
+ // at its placement in a stack (anchor, edges, z, ime, avoid, rail);
17
+ // on { event: function } in a builder; the serializer swaps each function
18
+ // for a binding id, `<path>#<event>`, and keeps the newest closure.
19
+ //
20
+ // Additions to the schema-v0 draft, each needed to draw today's chrome
21
+ // exactly (they are presentation only; a native renderer may treat them as
22
+ // the nearest v0 value):
23
+ // s.box 'border' | 'content' box-sizing (the portrait talk panel's width
24
+ // is a content-box width today);
25
+ // s.lh 'normal' a `font` shorthand's line height;
26
+ // s.flex '1 1 auto' a flex string as well as a grow number;
27
+ // s.mt n space above a node, outside its paint (the
28
+ // HUD's big line keeps 4 px under the title
29
+ // even with no title);
30
+ // s.clip false explicitly not clipped (overflow visible);
31
+ // s.wrap ['word', 'anywhere'] both text wrap rules written (the HUD copy
32
+ // pills reset white-space as well);
33
+ // Len terms { dvh }, { max: [terms] } and { sub: { l: 16, r: 16 } }
34
+ // (dynamic viewport units, a floor, and
35
+ // minus `max(16px, env(inset))`);
36
+ // data { hubAct: 'act' } web-only data-* attributes (QA hooks);
37
+ // button.keepFocus a press does not move focus (a chip
38
+ // keeps the talk field's keyboard up);
39
+ // scroll.follow as a list, with mode 'stick' (scroll to the end when the
40
+ // key appears and the viewer was at the end)
41
+ // and scroll.refollow (a counter: re-apply the
42
+ // last alignment if the viewer has not moved).
43
+
44
+ export const TYPES = new Set(['column', 'row', 'stack', 'scroll', 'grid', 'text', 'button', 'field', 'image', 'icon', 'activity', 'spacer']);
45
+ const CONTAINERS = new Set(['column', 'row', 'stack', 'scroll', 'grid', 'button']);
46
+ export const EVENTS = new Set(['tap', 'press', 'release', 'cancel', 'input', 'submit', 'focus', 'blur']);
47
+
48
+ // The closed style subset. Text keys inherit down the tree, as in CSS.
49
+ export const STYLE_KEYS = new Set([
50
+ 'w', 'h', 'minW', 'minH', 'maxW', 'maxH', 'pad', 'mt', 'gap', 'flex', 'basis', 'align', 'justify', 'wrap', 'self', 'box',
51
+ 'bg', 'radius', 'border', 'shadow', 'opacity', 'gray', 'clip', 'gone', 'hidden', 'hit',
52
+ 'color', 'font', 'size', 'weight', 'lh', 'ls', 'italic', 'upper', 'tabular', 'talign', 'lines', 'ellipsis', 'tshadow', 'fit',
53
+ ]);
54
+ export const AT_KEYS = new Set(['anchor', 'top', 'right', 'bottom', 'left', 'z', 'ime', 'avoid', 'avoidHide', 'rail']);
55
+ const NODE_KEYS = new Set(['t', 'k', 's', 'at', 'on', 'c', 'report', 'label', 'role', 'pressed', 'hub', 'data']);
56
+ const TYPE_FIELDS = {
57
+ scroll: ['axis', 'follow', 'refollow', 'reveal', 'snap', 'lazy'],
58
+ grid: ['cols'],
59
+ text: ['text', 'clock'],
60
+ button: ['fire', 'disabled', 'press', 'keepFocus'],
61
+ field: ['value', 'ver', 'ph', 'max', 'maxUnit', 'enter', 'cap', 'spell', 'correct', 'disabled', 'focus', 'name'],
62
+ image: ['src', 'fit'],
63
+ icon: ['name', 'tint'],
64
+ activity: ['kind'],
65
+ };
66
+
67
+ // Theme tokens: today's literals, byte for byte (schema §4).
68
+ export const TOKENS = {
69
+ chip: 'rgba(20,16,12,0.72)',
70
+ copy: 'rgba(20,16,12,0.78)',
71
+ toast: 'rgba(20,16,12,0.8)',
72
+ card: 'rgba(20,16,12,0.88)',
73
+ sheet: 'rgba(20,16,12,0.96)',
74
+ line35: 'rgba(255,255,255,0.35)',
75
+ line40: 'rgba(255,255,255,0.4)',
76
+ line45: 'rgba(255,255,255,0.45)',
77
+ field: 'rgba(255,255,255,0.1)',
78
+ fieldLine: 'rgba(255,255,255,0.3)',
79
+ gold: '#e9c48f',
80
+ onGold: '#2b2118',
81
+ goldSoft: 'rgba(233,196,143,0.25)',
82
+ askChip: 'rgba(233,196,143,0.14)',
83
+ askLine: 'rgba(233,196,143,0.7)',
84
+ askText: '#f5dfbd',
85
+ cream: 'rgba(255,250,240,0.94)',
86
+ inkText: '#2b2118',
87
+ select: '#f2c94c',
88
+ action: '#f4c66c',
89
+ onAction: '#26222b',
90
+ };
91
+
92
+ // White text drawn straight over the world (the HUD, the feed): an outline
93
+ // close around each letter as well as the soft drop shadow, so it reads over a
94
+ // pale sky as it does over a dark street.
95
+ export const BARE_TEXT_SHADOW = '0 0 2px rgba(0,0,0,0.95), 0 0 2px rgba(0,0,0,0.95), 0 1px 4px rgba(0,0,0,0.75), 0 0 10px rgba(0,0,0,0.45)';
96
+ export const SHADOWS = { card: '0 4px 14px rgba(0,0,0,0.45)', sheet: '0 -4px 18px rgba(0,0,0,0.45)', lift: '0 2px 6px rgba(0,0,0,0.4)', none: 'none' };
97
+ export const TEXT_SHADOWS = { outline: BARE_TEXT_SHADOW, soft: '0 2px 4px rgba(0,0,0,0.5)', none: 'none' };
98
+ export const FONTS = { ui: 'system-ui, sans-serif', mono: 'ui-monospace, monospace' };
99
+
100
+ export const color = (value) => (typeof value === 'string' && Object.hasOwn(TOKENS, value) ? TOKENS[value] : value);
101
+
102
+ // h(type, props, ...children): props.key becomes k; props.style becomes s;
103
+ // everything else is copied. Children are flattened; null, undefined and
104
+ // false are dropped, and strings and numbers become text nodes.
105
+ export function h(t, props = null, ...children) {
106
+ const node = { t };
107
+ if (props) {
108
+ for (const [name, value] of Object.entries(props)) {
109
+ if (value === undefined) {continue;}
110
+ if (name === 'key') {node.k = String(value);}
111
+ else if (name === 'style') {node.s = value;}
112
+ else if (name === 'on') {
113
+ // Only events with a handler: a builder may pass what it was given.
114
+ const on = Object.fromEntries(Object.entries(value ?? {}).filter(([, fn]) => fn !== undefined && fn !== null));
115
+ if (Object.keys(on).length) {node.on = on;}
116
+ }
117
+ else {node[name] = value;}
118
+ }
119
+ }
120
+ const kids = [];
121
+ (function add(list) {
122
+ for (const child of list) {
123
+ if (Array.isArray(child)) {add(child);}
124
+ else if (child !== null && child !== undefined && child !== false) {
125
+ kids.push(typeof child === 'object' ? child : { t: 'text', text: String(child) });
126
+ }
127
+ }
128
+ })(children);
129
+ if (kids.length) {node.c = kids;}
130
+ return node;
131
+ }
132
+ // Shorthands for the common nodes.
133
+ export const text = (value, props = null) => h('text', { ...props, text: String(value ?? '') });
134
+ export const spacer = (props = null) => h('spacer', props);
135
+
136
+ export const keyOf = (node, index) => (node?.k !== undefined && node?.k !== null ? String(node.k) : `#${index}`);
137
+ // A key as one path segment: '%' and '/' escaped, so two different nodes
138
+ // never share a path (or a binding id: an event name has no '#', so the last
139
+ // '#' of an id always ends its path).
140
+ export const segment = (key) => (/[%/]/.test(key) ? key.replace(/%/g, '%25').replace(/\//g, '%2F') : key);
141
+ export const childPath = (path, node, index) => `${path}/${segment(keyOf(node, index))}`;
142
+
143
+ // Builder tree -> wire tree: functions in `on` become binding ids, stored in
144
+ // `handlers` (id -> function). Anything that is not data is dropped, so the
145
+ // wire bytes of a tree rebuilt with fresh closures never change.
146
+ export function serialize(tree, rootName = null) {
147
+ const handlers = new Map();
148
+ const wire = tree ? encode(tree, rootName ?? segment(keyOf(tree, 0)), handlers) : null;
149
+ return { wire, handlers, json: JSON.stringify(wire) };
150
+ }
151
+ function encode(node, path, handlers) {
152
+ const out = {};
153
+ for (const [name, value] of Object.entries(node)) {
154
+ if (name === 'c' || value === undefined) {continue;}
155
+ if (name === 'on') {
156
+ const on = {};
157
+ for (const [event, fn] of Object.entries(value ?? {})) {
158
+ if (typeof fn !== 'function') {continue;}
159
+ const id = `${path}#${event}`;
160
+ handlers.set(id, fn);
161
+ on[event] = id;
162
+ }
163
+ if (Object.keys(on).length) {out.on = on;}
164
+ continue;
165
+ }
166
+ const data = clean(value);
167
+ if (data !== undefined) {out[name] = data;}
168
+ }
169
+ if (Array.isArray(node.c) && node.c.length) {
170
+ out.c = node.c.map((child, i) => encode(child, childPath(path, child, i), handlers));
171
+ }
172
+ return out;
173
+ }
174
+ function clean(value) {
175
+ if (value === null || typeof value === 'string' || typeof value === 'boolean') {return value;}
176
+ if (typeof value === 'number') {return Number.isFinite(value) ? value : undefined;}
177
+ if (Array.isArray(value)) {return value.map((item) => clean(item) ?? null);}
178
+ if (typeof value === 'object') {
179
+ const out = {};
180
+ for (const [name, item] of Object.entries(value)) {
181
+ const data = clean(item);
182
+ if (data !== undefined) {out[name] = data;}
183
+ }
184
+ return out;
185
+ }
186
+ return undefined;
187
+ }
188
+
189
+ // A text's `clock` (schema §4.2, made absolute): { gen, t0, v0, rate, fmt,
190
+ // min?, warn?: { below, s } }. Its value at `now` is
191
+ // v0 + rate × (now − t0), clamped at `min`,
192
+ // where `t0` and `now` are seconds in the hub's shared simulation time
193
+ // (`Hub.simNow() / 1000`), never a renderer's receipt time. Every field is
194
+ // fixed for a generation: `gen` changes only when the timer itself does (a
195
+ // start, a stop, its since/until, its rate). So every send of a clock (the
196
+ // first, a rebuild for something else, a replay to a sink attached later)
197
+ // carries the same bytes, and every renderer shows the same value at the same
198
+ // instant. A server time correction moves the time base, not the clock.
199
+ // `fmt` is 's.1' (12.4, the HUD timer, `toFixed(1)`) or 'm:ss' (the ballot
200
+ // countdown, whole seconds rounded up). Below `warn.below` the `warn.s`
201
+ // style is laid over the node's own.
202
+ export function formatClock(seconds, fmt) {
203
+ if (fmt === 'm:ss') {
204
+ const s = Math.max(0, Math.ceil(seconds));
205
+ return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, '0')}`;
206
+ }
207
+ return seconds.toFixed(1);
208
+ }
209
+ // The clock's value and words at `now` (simulation seconds).
210
+ export function readClock(clock, now) {
211
+ let value = Number(clock.v0 ?? 0) + Number(clock.rate ?? 0) * (now - Number(clock.t0 ?? 0));
212
+ if (Number.isFinite(clock.min)) {value = Math.max(clock.min, value);}
213
+ const warn = Boolean(clock.warn && Number.isFinite(clock.warn.below) && value < clock.warn.below);
214
+ return { value, text: formatClock(value, clock.fmt), warn };
215
+ }
216
+
217
+ // Dev check of the closed schema: a list of problems, empty when the tree is
218
+ // valid. Release builds skip it (unknown keys are then dropped by renderers).
219
+ export function validate(tree, rootName = null) {
220
+ const problems = [];
221
+ (function walk(node, path) {
222
+ if (!node || typeof node !== 'object') {problems.push(`${path}: not a node`); return;}
223
+ if (!TYPES.has(node.t)) {problems.push(`${path}: unknown type ${node.t}`);}
224
+ const fields = new Set(TYPE_FIELDS[node.t] ?? []);
225
+ for (const name of Object.keys(node)) {
226
+ if (!NODE_KEYS.has(name) && !fields.has(name)) {problems.push(`${path}: unknown field ${name}`);}
227
+ }
228
+ for (const name of Object.keys(node.s ?? {})) {
229
+ if (!STYLE_KEYS.has(name)) {problems.push(`${path}: unknown style ${name}`);}
230
+ }
231
+ for (const name of Object.keys(node.at ?? {})) {
232
+ if (!AT_KEYS.has(name)) {problems.push(`${path}: unknown placement ${name}`);}
233
+ }
234
+ for (const [event, fn] of Object.entries(node.on ?? {})) {
235
+ if (!EVENTS.has(event)) {problems.push(`${path}: unknown event ${event}`);}
236
+ if (typeof fn !== 'function' && typeof fn !== 'string') {problems.push(`${path}: ${event} is not a handler`);}
237
+ }
238
+ if (node.c && !CONTAINERS.has(node.t)) {problems.push(`${path}: ${node.t} has children`);}
239
+ const seen = new Set();
240
+ (node.c ?? []).forEach((child, i) => {
241
+ const key = keyOf(child, i);
242
+ if (seen.has(key)) {problems.push(`${path}: duplicate key ${key}`);}
243
+ seen.add(key);
244
+ walk(child, `${path}/${segment(key)}`);
245
+ });
246
+ })(tree, rootName ?? segment(keyOf(tree, 0)));
247
+ return problems;
248
+ }
249
+
250
+ // The sink seam: a host (the native engine) that draws the trees itself
251
+ // receives every changed root as (rootName, wireTree, handlers, info), where
252
+ // `handlers` is that root's live table (id -> newest closure) and `info` is
253
+ // { rev, json, simNow }. `simNow` is the simulation time at this send, in
254
+ // seconds (`Hub.simNow() / 1000`, from `setUiTreeTime`; null without one):
255
+ // the host keeps its offset from its own monotonic clock and reads every
256
+ // `clock` against that. `{ dom: false }` asks the web renderer to stand down
257
+ // for the roots the sink takes (it draws nothing; state still flows to the
258
+ // sink).
259
+ //
260
+ // Time sync with no root change: `{ onTime(simNow) }`, given with the sink,
261
+ // is called with the simulation time in seconds when the sink attaches and
262
+ // whenever the simulation clock's offset from this page's monotonic clock
263
+ // (`performance.now()`) has moved more than TIME_SYNC_S since the host was
264
+ // last told the time (by a root post or an `onTime`): a server correction
265
+ // with nothing else changed. `syncUiTreeTime()`, said each frame by the hub
266
+ // system, checks it. A host treats `onTime(simNow)` exactly as the `simNow`
267
+ // of a root post.
268
+ export const TIME_SYNC_S = 0.05;
269
+ let sink = null;
270
+ let sinkDom = true;
271
+ let onTime = null;
272
+ let timeSource = null;
273
+ // The offset (sim − monotonic, seconds) as of the last time the host was told.
274
+ let toldOffset = null;
275
+ const roots = new Map(); // name -> { json, wire, rev, handlers }
276
+ // The simulation clock, in seconds, sent with every root.
277
+ export function setUiTreeTime(fn) {
278
+ timeSource = typeof fn === 'function' ? fn : null;
279
+ }
280
+ const monoSeconds = () => (globalThis.performance?.now?.() ?? Date.now()) / 1000;
281
+ // The sim time now, noted as told to the host (each post carries it).
282
+ const simNowSeconds = () => {
283
+ const now = timeSource?.();
284
+ if (!Number.isFinite(now)) {return null;}
285
+ if (sink) {toldOffset = now - monoSeconds();}
286
+ return now;
287
+ };
288
+ export function setUiTreeSink(fn, { dom = true, onTime: timeFn = null } = {}) {
289
+ sink = typeof fn === 'function' ? fn : null;
290
+ sinkDom = sink ? dom !== false : true;
291
+ onTime = sink && typeof timeFn === 'function' ? timeFn : null;
292
+ toldOffset = null;
293
+ // A new sink gets the time, then every live root again, as it was sent:
294
+ // there are no actions, the tree is all state, and clocks are absolute.
295
+ if (sink) {
296
+ const simNow = simNowSeconds();
297
+ if (simNow !== null) {onTime?.(simNow);}
298
+ for (const [name, root] of roots) {sink(name, root.wire, root.handlers, { rev: root.rev, json: root.json, simNow });}
299
+ }
300
+ }
301
+ // Said each frame: tells the host the time (`onTime`) when the simulation
302
+ // clock has moved against the monotonic one since it was last told.
303
+ // Returns whether it told.
304
+ export function syncUiTreeTime() {
305
+ if (!sink || !onTime) {return false;}
306
+ const now = timeSource?.();
307
+ if (!Number.isFinite(now)) {return false;}
308
+ const offset = now - monoSeconds();
309
+ if (toldOffset !== null && Math.abs(offset - toldOffset) <= TIME_SYNC_S) {return false;}
310
+ toldOffset = offset;
311
+ onTime(now);
312
+ return true;
313
+ }
314
+ export const uiTreeSink = () => sink;
315
+ // Whether the web renderer draws the roots (true without a sink, or with a
316
+ // sink that keeps the DOM).
317
+ export const uiTreeDomEnabled = () => sinkDom;
318
+ // Called by a surface each time it has built a root: serializes it, keeps the
319
+ // newest closures, and hands the sink the tree only when its bytes changed.
320
+ // `null` drops the root. Returns true when the sink was sent the root.
321
+ export function publishUiRoot(name, tree) {
322
+ const previous = roots.get(name);
323
+ if (!tree) {
324
+ if (!previous) {return false;}
325
+ roots.delete(name);
326
+ sink?.(name, null, new Map(), { rev: previous.rev + 1, json: 'null', simNow: simNowSeconds() });
327
+ return Boolean(sink);
328
+ }
329
+ const { wire, handlers, json } = serialize(tree, name);
330
+ if (previous && previous.json === json) {
331
+ // Newest closure wins, without a resend.
332
+ previous.handlers.clear();
333
+ for (const [id, fn] of handlers) {previous.handlers.set(id, fn);}
334
+ return false;
335
+ }
336
+ const root = { json, wire, rev: (previous?.rev ?? 0) + 1, handlers: previous?.handlers ?? new Map() };
337
+ root.handlers.clear();
338
+ for (const [id, fn] of handlers) {root.handlers.set(id, fn);}
339
+ roots.set(name, root);
340
+ sink?.(name, wire, root.handlers, { rev: root.rev, json, simNow: simNowSeconds() });
341
+ return Boolean(sink);
342
+ }
343
+ // Native -> JS: an event on a root's binding. An id no longer in the table
344
+ // (its node is gone) is dropped; returns whether a handler ran.
345
+ export function dispatchUiEvent(rootName, id, payload) {
346
+ const fn = roots.get(rootName)?.handlers.get(id);
347
+ if (!fn) {return false;}
348
+ fn(payload);
349
+ return true;
350
+ }
351
+ // Tests and hot reload: forget every root and the sink.
352
+ export function resetUiTrees() {
353
+ roots.clear();
354
+ sink = null;
355
+ onTime = null;
356
+ timeSource = null;
357
+ toldOffset = null;
358
+ sinkDom = true;
359
+ }
@@ -0,0 +1,154 @@
1
+ // Vehicle preset, contract v1.160. The driver's existing capsule is the car.
2
+ import { Group } from 'three';
3
+ import { buildModelNode, parseModelCached } from '@imports/castle.physics-3d/engine3d/pxmodel';
4
+ import { copyModel, takeModel, releaseModel } from '@imports/castle.physics-3d/engine3d/optimize';
5
+ import { vehicleOf } from '../shared/car.js';
6
+ import { actorFor, pinRiders } from './riders.js';
7
+ import { bumperBlocked, carInput, stepCar } from './car.js';
8
+ import { hub } from './state.js';
9
+
10
+ const DEG = Math.PI / 180;
11
+ const buildsOf = new WeakMap();
12
+ export { actorFor, pinRiders };
13
+
14
+ export function tintPaint(text, color) {
15
+ if (!color) {return text;}
16
+ const data = JSON.parse(text);
17
+ const visit = (part) => {
18
+ if (!part || typeof part !== 'object') {return;}
19
+ if (part.id === 'paint' || part.name === 'paint' || part.material === 'paint') {part.color = color; part.materialColor = color;}
20
+ for (const child of part.parts ?? []) {visit(child);}
21
+ };
22
+ for (const part of data.parts ?? []) {visit(part);}
23
+ return JSON.stringify(data);
24
+ }
25
+ function disposeTree(root) {
26
+ const freed = new Set();
27
+ root.traverse(o => {
28
+ for (const v of [o.geometry, ...[o.material].flat()]) {
29
+ if (v && !freed.has(v)) {freed.add(v); v.dispose();}
30
+ }
31
+ });
32
+ }
33
+ export function carLook(scene, car) {
34
+ const model = scene.getActor?.(car.look)?.components.Model;
35
+ const text = model && scene.files?.[model.file];
36
+ if (typeof text !== 'string' || !scene.three) {return null;}
37
+ const tinted = tintPaint(text, car.color), parsed = parseModelCached(tinted);
38
+ if (!parsed) {return null;}
39
+ let builds = buildsOf.get(scene.three);
40
+ if (!builds) {builds = new Map(); buildsOf.set(scene.three, builds);}
41
+ const key = `${model.file}:${tinted}`;
42
+ const template = takeModel(builds, key, () => buildModelNode(parsed, scene.sprites, scene.files, model.file, [model.file], { optimize: true }));
43
+ const group = new Group(), copy = copyModel(template);
44
+ group.name = 'hub:car';
45
+ copy.scale.setScalar(model.scale ?? 1);
46
+ copy.position.y = model.yOffset ?? 0;
47
+ group.position.set(...car.seats[0].map(v => -v));
48
+ group.add(copy);
49
+ return { group, release: () => {group.removeFromParent(); releaseModel(builds, key, disposeTree);} };
50
+ }
51
+
52
+ // What a drawn look depends on: riders getting in or out do not rebuild it.
53
+ // Each hubCars message makes new car objects, so the key is kept per object
54
+ // and nothing is serialised on a frame that brought no change.
55
+ const lookKeys = new WeakMap();
56
+ function lookKey(car) {
57
+ let key = lookKeys.get(car);
58
+ if (key === undefined) {
59
+ key = JSON.stringify([car.look, car.color ?? null, car.seats[0]]);
60
+ lookKeys.set(car, key);
61
+ }
62
+ return key;
63
+ }
64
+
65
+ export function makeVehicle() {
66
+ const drawn = new Map();
67
+ let installed = null, saved = null, carState = null, lastCar = null;
68
+ function clearDrive() {
69
+ if (installed) {
70
+ const { scene, seam, previous, player, camera } = installed;
71
+ if (scene.playerDrive === seam) {
72
+ if (previous === undefined) {delete scene.playerDrive;} else {scene.playerDrive = previous;}
73
+ }
74
+ if (player) {player.camDistance = camera.distance; player.camHeight = camera.height;}
75
+ }
76
+ installed = null; saved = null; carState = null; lastCar = null;
77
+ }
78
+ const api = {
79
+ frame(scene, local, cars, on = true) {
80
+ const id = scene.multiplayer?.net?.selfId?.(), mine = vehicleOf(cars, id);
81
+ if (!on || !mine || !local?.components.Player) {clearDrive(); return mine;}
82
+ const car = mine.driver ? cars[id] : cars[mine.of];
83
+ const player = local.components.Player;
84
+ if (installed?.scene !== scene || installed?.player !== player) {
85
+ clearDrive();
86
+ saved = { distance: player.camDistance ?? 9, height: player.camHeight ?? 7 };
87
+ const seam = { step(actor, phys, input, dt) {
88
+ const current = vehicleOf(hub.cars ?? {}, id);
89
+ input.stick?.consumeJump?.();
90
+ actor.runtime.jumpBuffer = 0;
91
+ if (!current) {carState = null; return;}
92
+ if (!current.driver) {pinRiders(scene, actor, hub.cars); return;}
93
+ const spec = hub.cars[id], t = actor.components.Transform;
94
+ const controls = carInput(input.keys, input.stick);
95
+ const stopped = hub.held.has(id);
96
+ const jumped = carState && Math.hypot(t.x - carState.x, t.z - carState.z) > 3;
97
+ const before = { speed: stopped || jumped ? 0 : carState?.speed ?? 0, heading: (t.rotationY ?? 0) * DEG };
98
+ const direction = { x: Math.sin(before.heading), y: 0, z: Math.cos(before.heading) };
99
+ // Players do not stop a car, but what stands behind one does: the
100
+ // ray passes over every avatar's collider (physics-3d's `skip`).
101
+ const avatars = new Set(scene.multiplayer?.avatars?.actors?.values?.() ?? []);
102
+ const isAvatar = (actorId) => avatars.has(actorId) || Boolean(scene.getActor?.(actorId)?.components.Player);
103
+ const ray = (sign) => phys.castRay({ x: t.x, y: t.y, z: t.z }, { x: direction.x * sign, y: 0, z: direction.z * sign }, spec.length / 2, actor, isAvatar)?.distance;
104
+ const front = ray(1), back = ray(-1);
105
+ const next = stepCar(before, { ...controls, ...(stopped ? { forward: 0, steer: 0 } : {}), front, back }, spec, dt);
106
+ if (stopped) {next.speed = 0;}
107
+ carState = { ...next, x: t.x, z: t.z };
108
+ actor.runtime.facing = next.heading;
109
+ t.rotationY = next.heading / DEG;
110
+ (scene.persistent ??= {}).camAngle = Math.PI - next.heading;
111
+ const velocity = phys.getVelocity(actor), factor = Math.min(1, dt * 14) * (input.grounded ? 1 : 0.3), mass = phys.mass(actor);
112
+ if (stopped || (next.speed === 0 && bumperBlocked(before.speed, controls.forward, front, back, spec.length))) {
113
+ phys.setVelocity(actor, { x: 0, y: velocity.y, z: 0 });
114
+ return;
115
+ }
116
+ phys.applyImpulse(actor, { x: (Math.sin(next.heading) * next.speed - velocity.x) * mass * factor, y: 0, z: (Math.cos(next.heading) * next.speed - velocity.z) * mass * factor });
117
+ } };
118
+ installed = { scene, seam, previous: scene.playerDrive, player, camera: saved };
119
+ scene.playerDrive = seam;
120
+ }
121
+ const signature = JSON.stringify({ ...car, riders: undefined });
122
+ if (lastCar !== signature) {carState = null; lastCar = signature;}
123
+ player.camDistance = car.cam?.distance ?? saved.distance * 1.4;
124
+ player.camHeight = car.cam?.height ?? saved.height * 1.4;
125
+ return mine;
126
+ },
127
+ draw(scene, local, cars) {
128
+ pinRiders(scene, local, cars);
129
+ for (const [id, entry] of drawn) {
130
+ const actor = actorFor(scene, local, id), node = scene.three?.nodes?.get(actor?.id)?.node;
131
+ if (!cars[id] || entry.world !== scene.three || entry.node !== node || entry.key !== lookKey(cars[id])) {entry.release(); drawn.delete(id);}
132
+ }
133
+ for (const [id, car] of Object.entries(cars)) {
134
+ const actor = actorFor(scene, local, id), node = scene.three?.nodes?.get(actor?.id)?.node;
135
+ if (!node || drawn.has(id)) {continue;}
136
+ const look = carLook(scene, car);
137
+ if (look) {node.add(look.group); drawn.set(id, { ...look, node, world: scene.three, key: lookKey(car) });}
138
+ }
139
+ },
140
+ // A local rider follows the driver's drawn centre, at this car's camera
141
+ // distance/height. Run after multiplayer has placed the driver's avatar.
142
+ camera(scene, local, cars) {
143
+ const id = scene.multiplayer?.net?.selfId?.(), mine = vehicleOf(cars, id);
144
+ if (!mine || mine.driver) {return;}
145
+ const t = actorFor(scene, local, mine.of)?.components.Transform, cam = scene.three?.camera, player = local?.components.Player;
146
+ if (!t || !cam || !player) {return;}
147
+ const a = (t.rotationY ?? 0) * DEG;
148
+ cam.position.set(t.x - Math.sin(a) * player.camDistance, t.y + player.camHeight, t.z - Math.cos(a) * player.camDistance);
149
+ cam.lookAt(t.x, t.y + 0.5, t.z);
150
+ },
151
+ clear() {clearDrive(); for (const entry of drawn.values()) {entry.release();} drawn.clear();},
152
+ };
153
+ return api;
154
+ }
@@ -30,6 +30,7 @@ import { buildModelNode, parseModelCached } from '@imports/castle.physics-3d/eng
30
30
  import { copyModel, releaseModel, takeModel } from '@imports/castle.physics-3d/engine3d/optimize';
31
31
  import { hatId } from './hats.js';
32
32
  import { earnedLook, tinted } from './earned.js';
33
+ import { ROLE_MAIN, roleLook, rolePieces } from './role.js';
33
34
 
34
35
  // Heights from the avatar's origin, the capsule's centre: the model's feet,
35
36
  // which stand on the ground, are this far under it.
@@ -290,14 +291,15 @@ function takeShared(world, files, file, text, label) {
290
291
 
291
292
  // An earned item's object (v1.53, `earned.js`): its shape's model in its
292
293
  // colour, where its fit puts it, or null when these files lack the model.
293
- function buildEarned(spec, world, files) {
294
+ function buildEarned(spec, world, files, prefix = 'earned') {
294
295
  const file = ROOTS.map((root) => `${root}${spec.file}`).find((f) => typeof files?.[f] === 'string');
295
- const taken = file ? takeShared(world, files, file, tinted(files[file], spec.color), 'earned') : null;
296
+ const text = file ? (prefix === 'role' ? files[file].split(JSON.stringify(ROLE_MAIN)).join(JSON.stringify(spec.color)) : tinted(files[file], spec.color)) : null;
297
+ const taken = file ? takeShared(world, files, file, text, prefix) : null;
296
298
  if (!taken) {
297
299
  return null;
298
300
  }
299
301
  const group = new THREE.Group();
300
- group.name = `earned:${spec.shape}`;
302
+ group.name = `${prefix}:${spec.shape}`;
301
303
  group.userData.hatKey = taken.key;
302
304
  group.userData.hatBuilds = taken.builds;
303
305
  // Scaled, then tilted about z and turned about y (Euler XYZ applies z
@@ -449,6 +451,26 @@ export function makeWear() {
449
451
  // shape, color }` and `fitOf(playerId)` that player's avatar's earned fit
450
452
  // (`avatar.js`). Nothing at all is done while nobody shows one.
451
453
  export function makeEarned() {
454
+ return makeItems(earnedLook, 'earned');
455
+ }
456
+
457
+ // Role pieces share the earned renderer and its per-world build lifecycle.
458
+ export function makeRole() {
459
+ const top = makeItems(roleLook, 'role');
460
+ const tool = makeItems(roleLook, 'role');
461
+ return {
462
+ get size() { return top.size + tool.size; },
463
+ frame(scene, local, roles, fitOf) {
464
+ if (!roles.size && !this.size) { return; }
465
+ top.frame(scene, local, rolePieces(roles, 'top'), fitOf);
466
+ tool.frame(scene, local, rolePieces(roles, 'tool'), fitOf);
467
+ },
468
+ clear() { top.clear(); tool.clear(); },
469
+ forget() { top.forget(); tool.forget(); },
470
+ };
471
+ }
472
+
473
+ function makeItems(lookOf, prefix) {
452
474
  // playerId -> { json, group, node, world }
453
475
  const drawn = new Map();
454
476
  function remove(playerId) {
@@ -494,8 +516,8 @@ export function makeEarned() {
494
516
  if (entry?.json !== json || entry.world !== scene.three) {
495
517
  // The new one is made before the old is taken down, so the same
496
518
  // item refitted keeps its share of the build.
497
- const spec = earnedLook(item, fit);
498
- const group = spec ? buildEarned(spec, scene.three, scene.files) : null;
519
+ const spec = lookOf(item, fit);
520
+ const group = spec ? buildEarned(spec, scene.three, scene.files, prefix) : null;
499
521
  remove(playerId);
500
522
  entry = { json, group, node: null, world: scene.three };
501
523
  drawn.set(playerId, entry);
@@ -52,7 +52,7 @@ export function worldPlacement(pointers, labels, controls, view) {
52
52
  });
53
53
  const labelBoxes = labels.map((box) => {
54
54
  const fits = box.left >= bounds.left && box.right <= bounds.right && box.top >= bounds.top && box.bottom <= bounds.bottom;
55
- if (!fits || taken.some((other) => overlaps(box, other))) {return null;}
55
+ if (!fits || taken.some((other) => other !== box.ignoreObstacle && overlaps(box, other))) {return null;}
56
56
  taken.push(box);
57
57
  return box;
58
58
  });
@@ -225,7 +225,8 @@ export function makeWorldLayout(entries, view, obstacles = () => [], geometry =
225
225
  .sort((a, b) => Number(b.id?.startsWith('pointer:goal:') === true) - Number(a.id?.startsWith('pointer:goal:') === true));
226
226
  const labels = measured.filter((entry) => entry.kind === 'label');
227
227
  const controls = measured.filter((entry) => (entry.kind !== 'pointer' || entry.id === 'stuck') && entry.kind !== 'label').map((entry) => entry.box);
228
- const placements = worldPlacement(pointers.map((entry) => entry.box), labels.map((entry) => entry.box), [...controls, ...obstacles()], view());
228
+ const placements = worldPlacement(pointers.map((entry) => entry.box), labels.map(({ box, ignoreObstacle }) => ignoreObstacle
229
+ ? { left: box.left, right: box.right, top: box.top, bottom: box.bottom, ignoreObstacle } : box), [...controls, ...obstacles()], view());
229
230
  for (const [items, boxes] of [[pointers, placements.pointers], [labels, placements.labels]]) {
230
231
  items.forEach(({ node, box }, index) => {
231
232
  const placed = boxes[index];
@@ -36,6 +36,7 @@ export function makeYours(api, user, toast, clock = () => performance.now()) {
36
36
  let offered = false;
37
37
  let returning = null;
38
38
  let returnLine = '';
39
+ let left = null;
39
40
  let dismissed = false;
40
41
  const hearts = () => pending.reduce((ids, door) => toggleHeart(ids, door), confirmed);
41
42
 
@@ -94,12 +95,18 @@ export function makeYours(api, user, toast, clock = () => performance.now()) {
94
95
  started = signed = available = saving = offered = dismissed = arrived = false;
95
96
  confirmed = [];
96
97
  pending = [];
97
- latestHearts = returning = null;
98
+ latestHearts = returning = left = null;
98
99
  authoritativeUntil = 0;
99
100
  returnLine = '';
100
101
  waitUntil = 0;
101
102
  },
102
- returned(door, result = null) {
103
+ returned(door, result = null, home = false) {
104
+ // Out of a House is not out of a game: Go would only undo the exit, so
105
+ // that door is not offered this visit, and there is no return offer.
106
+ if (home) {
107
+ left = door;
108
+ return;
109
+ }
103
110
  offerKey = `yours:${visit}:return:${++occurrence}`;
104
111
  returning = door;
105
112
  const last = Number.isFinite(result?.score) ? `Last ${result.score}${['ms', 's', 'points'].includes(result.unit) ? ` ${result.unit}` : ''}` : result?.outcome ?? '';
@@ -179,7 +186,7 @@ export function makeYours(api, user, toast, clock = () => performance.now()) {
179
186
  const row = returning ? rows.find((r) => r.door === returning) ?? (() => {
180
187
  const door = doors.find((d) => d.id === returning);
181
188
  return door ? { door: door.id, title: door.title, line: '' } : null;
182
- })() : rows[0];
189
+ })() : rows.find((r) => r.door !== left);
183
190
  if (!row) {
184
191
  return null;
185
192
  }
@@ -309,7 +309,7 @@ export function marksOf(h) {
309
309
  // A copy is an actor like its template: move, tint, hide and label it. The
310
310
  // template may be hidden (a prototype nobody sees). Not a template with a
311
311
  // dynamic Body (its ownership is the multiplayer kit's), nor a player, door or
312
- // NPC. Bounded: MAX_SPAWNED copies alive, SPAWN_RATE spawns a second with
312
+ // NPC. Bounded: MAX_SPAWNED copies alive (a deck's hub.spawnCap, v1.161), SPAWN_RATE spawns a second with
313
313
  // bursts of SPAWN_BURST, so the snapshot and every client's actor count stay
314
314
  // small.
315
315
  export const MAX_SPAWNED = 96;
@@ -341,8 +341,9 @@ export function spawn(h, fromId, at, engine) {
341
341
  warnOnce(h, 'spawn:bounds', 'hub.spawn: that point is outside the world');
342
342
  return null;
343
343
  }
344
- if (h.spawned.size >= MAX_SPAWNED) {
345
- warnOnce(h, 'spawn:max', `hub.spawn: at most ${MAX_SPAWNED} copies at once`);
344
+ const cap = h.manifest.spawnCap ?? MAX_SPAWNED;
345
+ if (h.spawned.size >= cap) {
346
+ warnOnce(h, 'spawn:max', `hub.spawn: at most ${cap} copies at once`);
346
347
  return null;
347
348
  }
348
349
  const budget = h.spawnBudget;