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
@@ -35,8 +35,8 @@ export function arrive(h, group) {
35
35
  if (key) {a.departed.delete(key);}
36
36
  a.visits.set(p.playerId, { at: now, userId: key });
37
37
  if (back) {track(h, p.playerId, 'reconnect', { subject: h.manifest.house ? SUBJECTS.house : SUBJECTS.town });}
38
- else if (h.firstVisit && !h.manifest.house) {a.visits.get(p.playerId).arrival = { subject: SUBJECTS.town, result: p.from ? 2 : 1 };}
39
- else {track(h, p.playerId, h.manifest.house ? 'house_visit' : 'arrive', { subject: h.manifest.house ? SUBJECTS.house : SUBJECTS.town, result: p.from ? 2 : 1 });}
38
+ else if (h.firstVisit && !h.manifest.house) {a.visits.get(p.playerId).arrival = { subject: SUBJECTS.town, value: p.device ?? 0, result: p.from ? 2 : 1 };}
39
+ else {track(h, p.playerId, h.manifest.house ? 'house_visit' : 'arrive', { subject: h.manifest.house ? SUBJECTS.house : SUBJECTS.town, value: p.device ?? 0, result: p.from ? 2 : 1 });}
40
40
  }
41
41
  }
42
42
  // Resolve the existing arrival once storage has answered, without duplicating it.
@@ -48,13 +48,63 @@ export function firstVisitArrived(h, playerId, flags) {
48
48
  if (accepted) {delete visit.arrival;}
49
49
  return accepted;
50
50
  }
51
+ // Terminal rows carry how their segment ended in `result` (Ghost owns flags):
52
+ // 0 the visit ended here, 1 its connection dropped and never came back in
53
+ // time, 2 a segment that continued the visit after a late resume. Rows with
54
+ // result 0 or 1 count each real visit once; summing `value` gives its
55
+ // connected time.
56
+ export const END = Object.freeze({ left: 0, dropped: 1, continued: 2 });
57
+ // The host resolves a departed player for under a minute, while a place may
58
+ // hold the visit for five. A drop still away this long is reported now.
59
+ export const DROP_REPORT_MS = 40000;
60
+ function end(h, playerId, visit, value, result) {
61
+ if (visit.arrival) {firstVisitArrived(h, playerId, 0);}
62
+ value = Math.max(0, Math.min(2147483647, Math.round(value)));
63
+ track(h, playerId, 'session_end', { value, result });
64
+ if (h.manifest.house) {track(h, playerId, 'house_time', { subject: SUBJECTS.house, value, result });}
65
+ }
66
+ // Every reconcile, after the place forgot whom it lets go. Presence is the
67
+ // session roster, whatever the place still retains: a stale body or a resume
68
+ // hold must not move the report deadline. A new body under the same id means
69
+ // the connection came back between two ticks; the time between is away.
70
+ export function observe(h) {
71
+ const now = h.sim.timeMs;
72
+ for (const [playerId, visit] of h.analytics.visits) {
73
+ const body = h.sim.players.get(playerId);
74
+ if (h.session?.players.some((p) => p.playerId === playerId)) {
75
+ if (visit.droppedAt !== undefined) {resume(h, visit, now);}
76
+ else if (body && visit.body && body !== visit.body && visit.seen !== undefined) {visit.at += now - visit.seen;}
77
+ if (body) {visit.body = body;}
78
+ visit.seen = now;
79
+ } else if (!h.resumeDeparting?.has(playerId)) {
80
+ if (visit.droppedAt === undefined) {
81
+ visit.droppedAt = visit.seen ?? now;
82
+ visit.droppedWall = Date.now();
83
+ }
84
+ if (!visit.reported && Date.now() - visit.droppedWall >= DROP_REPORT_MS) {
85
+ end(h, playerId, visit, visit.droppedAt - visit.at, visit.continued ? END.continued : END.dropped);
86
+ visit.reported = true;
87
+ }
88
+ }
89
+ }
90
+ }
91
+ // A quick return is the same segment, without the time away. One after its
92
+ // drop was reported starts a continuation.
93
+ function resume(h, visit, now) {
94
+ if (visit.reported) {
95
+ visit.continued = true;
96
+ visit.at = now;
97
+ } else {visit.at += now - visit.droppedAt;}
98
+ delete visit.droppedAt;
99
+ delete visit.droppedWall;
100
+ delete visit.reported;
101
+ }
51
102
  export function leave(h, playerId) {
52
103
  const a = h.analytics, visit = a.visits.get(playerId);
53
104
  if (!visit) {return;}
54
- if (visit.arrival) {firstVisitArrived(h, playerId, 0);}
55
- const value = Math.max(0, Math.min(2147483647, Math.round(h.sim.timeMs - visit.at)));
56
- track(h, playerId, 'session_end', { value, result: 0 });
57
- if (h.manifest.house) {track(h, playerId, 'house_time', { subject: SUBJECTS.house, value });}
105
+ if (visit.droppedAt !== undefined) {
106
+ if (!visit.reported) {end(h, playerId, visit, visit.droppedAt - visit.at, visit.continued ? END.continued : END.dropped);}
107
+ } else {end(h, playerId, visit, h.sim.timeMs - visit.at, visit.continued ? END.continued : END.left);}
58
108
  a.visits.delete(playerId);
59
109
  if (visit.userId) {a.departed.set(visit.userId, h.sim.timeMs);}
60
110
  }
@@ -6,6 +6,7 @@ import { DECOR_ID, footprint } from '../shared/decor.js';
6
6
  export const MAX_ITEMS = 64;
7
7
  export const MAX_PLACED = 64;
8
8
  export const MAX_SWATCHES = 24;
9
+ const SPEC = ['title', 'grid', 'tabs', 'items', 'swatches', 'placed'];
9
10
  const COLOR = /^#[0-9a-fA-F]{6}$/;
10
11
  const ACTOR = (value) => typeof value === 'string' && value.trim().length > 0 && value.length <= 128;
11
12
  const object = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
@@ -25,24 +26,45 @@ function id(value, where) {
25
26
  need(typeof value === 'string' && DECOR_ID.test(value), `${where} must be a short id`);
26
27
  }
27
28
 
29
+ function readGrid(value, where) {
30
+ keys(value, ['origin', 'w', 'd', 'cell'], where);
31
+ const { origin, w, d, cell } = value;
32
+ need(ACTOR(origin), `${where}.origin must name an actor`);
33
+ need(int(w, 1, 16) && int(d, 1, 16), `${where} w and d must be integers in 1..16`);
34
+ need(Number.isFinite(cell) && cell >= 0.5 && cell <= 2, `${where}.cell must be 0.5..2 metres`);
35
+ return { origin, w, d, cell };
36
+ }
37
+
28
38
  // The manifest and the publish check share this reader. Absence adds no key.
29
39
  export function readDecor(value, where, errors) {
30
40
  if (value === undefined) {
31
41
  return null;
32
42
  }
33
43
  try {
34
- keys(value, ['grid', 'layers'], where);
35
- keys(value.grid, ['origin', 'w', 'd', 'cell'], `${where}.grid`);
36
- const { origin, w, d, cell } = value.grid;
37
- need(ACTOR(origin), `${where}.grid.origin must name an actor`);
38
- need(int(w, 1, 16) && int(d, 1, 16), `${where}.grid w and d must be integers in 1..16`);
39
- need(Number.isFinite(cell) && cell >= 0.5 && cell <= 2, `${where}.grid.cell must be 0.5..2 metres`);
44
+ keys(value, ['grid', 'grids', 'layers'], where);
45
+ need(value.grid !== undefined || value.grids !== undefined, `${where} needs grid or grids`);
46
+ const out = {};
47
+ if (value.grid !== undefined) {
48
+ out.grid = readGrid(value.grid, `${where}.grid`);
49
+ }
50
+ // v1.159: named grids a spec picks by id, e.g. one per house lot.
51
+ if (value.grids !== undefined) {
52
+ need(object(value.grids), `${where}.grids must be an object`);
53
+ const ids = Object.keys(value.grids);
54
+ need(ids.length >= 1 && ids.length <= 16, `${where}.grids must hold 1..16 grids`);
55
+ out.grids = {};
56
+ for (const gridId of ids) {
57
+ id(gridId, `${where}.grids key`);
58
+ out.grids[gridId] = readGrid(value.grids[gridId], `${where}.grids.${gridId}`);
59
+ }
60
+ }
40
61
  need(Array.isArray(value.layers) && value.layers.length >= 1 && value.layers.length <= 3, `${where}.layers must contain 1..3 ids`);
41
62
  for (const layer of value.layers) {
42
63
  id(layer, `${where}.layers`);
43
64
  }
44
65
  need(new Set(value.layers).size === value.layers.length, `${where}.layers must be unique`);
45
- return { grid: { origin, w, d, cell }, layers: [...value.layers] };
66
+ out.layers = [...value.layers];
67
+ return out;
46
68
  } catch (error) {
47
69
  errors.push(error.message);
48
70
  return null;
@@ -56,9 +78,21 @@ function unique(values, where) {
56
78
  need(new Set(values).size === values.length, `${where} must be unique`);
57
79
  }
58
80
 
81
+ // The declared grid a spec decorates: its named one, else the place's own.
82
+ function declared(h, spec) {
83
+ const decor = h.place.decor;
84
+ if (spec?.grid === undefined) {
85
+ need(decor.grid, 'spec.grid must name one of the place\'s decor grids');
86
+ return decor.grid;
87
+ }
88
+ need(typeof spec.grid === 'string' && decor.grids && Object.hasOwn(decor.grids, spec.grid), 'spec.grid must name one of the place\'s decor grids');
89
+ return decor.grids[spec.grid];
90
+ }
91
+
59
92
  export function checkSpec(h, value) {
60
- keys(value, ['title', 'tabs', 'items', 'swatches', 'placed'], 'spec');
61
- const out = {};
93
+ keys(value, SPEC, 'spec');
94
+ const grid = declared(h, value);
95
+ const out = value.grid === undefined ? {} : { grid: value.grid };
62
96
  if (value.title !== undefined) {
63
97
  need(typeof value.title === 'string' && value.title.length <= 40, 'title must be at most 40 characters');
64
98
  out.title = value.title;
@@ -111,7 +145,7 @@ export function checkSpec(h, value) {
111
145
  const item = out.items.find((i) => i.id === piece.item);
112
146
  need(item && item.layer === piece.layer, 'placed item and layer must match the catalogue');
113
147
  need(int(piece.rot, 0, 3), 'placed.rot must be 0..3');
114
- const size = footprint(item, piece.rot), grid = h.place.decor.grid;
148
+ const size = footprint(item, piece.rot);
115
149
  need(int(piece.x, 0, grid.w - size.w) && int(piece.z, 0, grid.d - size.d), 'placed piece must fit in the grid');
116
150
  return { key: piece.key, item: piece.item, x: piece.x, z: piece.z, rot: piece.rot, layer: piece.layer };
117
151
  });
@@ -126,8 +160,8 @@ function player(h, playerId) {
126
160
  need(h.place.decor, 'this place does not declare decor');
127
161
  need(present(h, playerId), 'playerId must name a player here');
128
162
  }
129
- function gridOf(h) {
130
- const grid = h.place.decor.grid;
163
+ function gridOf(h, spec) {
164
+ const grid = declared(h, spec);
131
165
  const t = h.actors.find((actor) => actor.id === grid.origin)?.components.Transform;
132
166
  need(t && ['x', 'y', 'z'].every((key) => t[key] === undefined || Number.isFinite(t[key])), 'grid.origin must have a finite Transform');
133
167
  return { x: t.x ?? 0, y: t.y ?? 0, z: t.z ?? 0, w: grid.w, d: grid.d, cell: grid.cell };
@@ -138,7 +172,12 @@ function current(h, playerId) {
138
172
  function send(h, playerId, state) {
139
173
  const wire = { k: 'hub-decor', ...state };
140
174
  if (state.spec) {
141
- wire.grid = gridOf(h);
175
+ // The chosen grid's id stays off the wire: its resolved bounds follow.
176
+ if (state.spec.grid !== undefined) {
177
+ wire.spec = { ...state.spec };
178
+ delete wire.spec.grid;
179
+ }
180
+ wire.grid = gridOf(h, state.spec);
142
181
  }
143
182
  h.session?.send(playerId, wire);
144
183
  }
@@ -161,7 +200,7 @@ export function api(h) {
161
200
  open(playerId, spec) {
162
201
  player(h, playerId);
163
202
  const checked = checkSpec(h, spec);
164
- gridOf(h);
203
+ gridOf(h, checked);
165
204
  set(h, playerId, { ...current(h, playerId), spec: checked });
166
205
  },
167
206
  close(playerId) {
@@ -172,8 +211,9 @@ export function api(h) {
172
211
  player(h, playerId);
173
212
  const state = current(h, playerId);
174
213
  need(state.spec, 'update needs an open catalogue');
175
- keys(partial, ['title', 'tabs', 'items', 'swatches', 'placed'], 'partial spec');
214
+ keys(partial, SPEC, 'partial spec');
176
215
  const checked = checkSpec(h, { ...state.spec, ...partial });
216
+ gridOf(h, checked);
177
217
  set(h, playerId, { ...state, spec: checked });
178
218
  },
179
219
  });
@@ -200,7 +240,7 @@ export function message(h, playerId, data) {
200
240
  case 'place':
201
241
  case 'move': {
202
242
  keys(data, ['k', 'op', data.op === 'place' ? 'item' : 'key', 'x', 'z', 'rot'], 'placement op');
203
- const grid = h.place.decor.grid;
243
+ const grid = declared(h, spec);
204
244
  need(int(data.x, 0, grid.w - 1) && int(data.z, 0, grid.d - 1) && int(data.rot, 0, 3), 'invalid cells or rotation');
205
245
  if (data.op === 'place') {
206
246
  const item = spec.items.find((i) => i.id === data.item);