castle-web-cli 0.4.237 → 0.4.239

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 (239) 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 +133 -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 +21 -0
  14. package/dist/init.js +2 -1
  15. package/dist/multiplayerDoc.d.ts +1 -1
  16. package/dist/multiplayerDoc.js +9 -0
  17. package/dist/platformDoc.js +2 -1
  18. package/dist/playPagePolicy.d.ts +1 -0
  19. package/dist/playPagePolicy.js +8 -3
  20. package/dist/roomLogs.d.ts +39 -0
  21. package/dist/roomLogs.js +166 -0
  22. package/dist/save-deck.js +4 -0
  23. package/kits/base/CLAUDE.md +1 -0
  24. package/kits/base/castle.json +1 -1
  25. package/kits/base/sdk/README.md +113 -2
  26. package/kits/base/sdk/castle.d.ts +6 -2
  27. package/kits/base/sdk/castle.js +2 -0
  28. package/kits/base/sdk/commands.d.ts +56 -1
  29. package/kits/base/sdk/commands.js +29 -1
  30. package/kits/base/sdk/hub.d.ts +17 -0
  31. package/kits/base/sdk/hub.js +33 -9
  32. package/kits/base/sdk/localCache.d.ts +27 -0
  33. package/kits/base/sdk/localCache.js +115 -0
  34. package/kits/base/sdk/localCacheStore.d.ts +15 -0
  35. package/kits/base/sdk/localCacheStore.js +358 -0
  36. package/kits/base/sdk/multiplayer.js +30 -0
  37. package/kits/base/sdk/rooms.d.ts +11 -0
  38. package/kits/base/sdk/rooms.js +22 -0
  39. package/kits/base/sdk/store.d.ts +8 -2
  40. package/kits/base/sdk/store.js +5 -1
  41. package/kits/base/sdk/transport.d.ts +1 -0
  42. package/kits/base/sdk/transport.js +4 -5
  43. package/kits/hub-game/CLAUDE.md +22 -2
  44. package/kits/hub-game/castle.json +8 -5
  45. package/kits/hub-game/code/client/act.js +66 -91
  46. package/kits/hub-game/code/client/actCore.js +134 -0
  47. package/kits/hub-game/code/client/car.js +35 -0
  48. package/kits/hub-game/code/client/chrome.js +208 -381
  49. package/kits/hub-game/code/client/crowdNames.js +2 -2
  50. package/kits/hub-game/code/client/emoteWheel.js +109 -0
  51. package/kits/hub-game/code/client/hats.js +2 -0
  52. package/kits/hub-game/code/client/hookLayer.js +99 -48
  53. package/kits/hub-game/code/client/hostGo.js +77 -0
  54. package/kits/hub-game/code/client/hubControls.js +125 -0
  55. package/kits/hub-game/code/client/hubEntry.js +187 -0
  56. package/kits/hub-game/code/client/hudSurface.js +148 -0
  57. package/kits/hub-game/code/client/hudTree.js +96 -0
  58. package/kits/hub-game/code/client/idle.js +59 -13
  59. package/kits/hub-game/code/client/invites.js +13 -4
  60. package/kits/hub-game/code/client/menuIcons.js +8 -0
  61. package/kits/hub-game/code/client/menuRows.js +8 -2
  62. package/kits/hub-game/code/client/noTrips.js +38 -0
  63. package/kits/hub-game/code/client/qualityEntry.js +6 -1
  64. package/kits/hub-game/code/client/rehello.js +3 -1
  65. package/kits/hub-game/code/client/riders.js +26 -0
  66. package/kits/hub-game/code/client/role.js +79 -0
  67. package/kits/hub-game/code/client/safeLayout.js +32 -3
  68. package/kits/hub-game/code/client/sound.js +10 -3
  69. package/kits/hub-game/code/client/soundscape.js +2 -2
  70. package/kits/hub-game/code/client/soundscapeAmbience.js +38 -8
  71. package/kits/hub-game/code/client/soundscapeBaked.js +24 -5
  72. package/kits/hub-game/code/client/soundscapeCues.js +2 -1
  73. package/kits/hub-game/code/client/state.js +19 -0
  74. package/kits/hub-game/code/client/stuck.js +2 -1
  75. package/kits/hub-game/code/client/talkSurface.js +178 -0
  76. package/kits/hub-game/code/client/talkTree.js +238 -0
  77. package/kits/hub-game/code/client/tiers.js +8 -5
  78. package/kits/hub-game/code/client/uiDom.js +600 -0
  79. package/kits/hub-game/code/client/uiTree.js +359 -0
  80. package/kits/hub-game/code/client/vehicle.js +156 -0
  81. package/kits/hub-game/code/client/wear.js +27 -5
  82. package/kits/hub-game/code/client/worldLabels.js +13 -3
  83. package/kits/hub-game/code/client/yours.js +10 -3
  84. package/kits/hub-game/code/server/actors.js +4 -3
  85. package/kits/hub-game/code/server/analytics.js +61 -18
  86. package/kits/hub-game/code/server/decor.js +56 -16
  87. package/kits/hub-game/code/server/doorAnalytics.js +2 -5
  88. package/kits/hub-game/code/server/hub.js +261 -46
  89. package/kits/hub-game/code/server/idle.js +118 -5
  90. package/kits/hub-game/code/server/loadAbandon.js +2 -5
  91. package/kits/hub-game/code/server/manifest.js +46 -4
  92. package/kits/hub-game/code/server/npcs.js +4 -2
  93. package/kits/hub-game/code/server/players.js +3 -0
  94. package/kits/hub-game/code/server/role.js +142 -0
  95. package/kits/hub-game/code/server/standing.js +6 -4
  96. package/kits/hub-game/code/server/trackQueue.js +29 -0
  97. package/kits/hub-game/code/server/vehicle.js +126 -0
  98. package/kits/hub-game/code/shared/car.js +52 -0
  99. package/kits/hub-game/code/shared/deckFlags.js +34 -0
  100. package/kits/hub-game/code/shared/deviceClass.js +39 -0
  101. package/kits/hub-game/code/shared/expression.js +9 -0
  102. package/kits/hub-game/code/systems/hub.js +281 -86
  103. package/kits/hub-game/docs/analytics.md +15 -3
  104. package/kits/hub-game/docs/contract.md +352 -14
  105. package/kits/hub-game/docs/vehicle-preset.md +132 -0
  106. package/kits/hub-game/models/hats/baker-cap.pxmodel +89 -0
  107. package/kits/hub-game/models/hats/chef-toque.pxmodel +60 -0
  108. package/kits/hub-game/models/hats/delivery-cap.pxmodel +105 -0
  109. package/kits/hub-game/models/hats/fire-helmet.pxmodel +87 -0
  110. package/kits/hub-game/models/hats/hard-hat.pxmodel +71 -0
  111. package/kits/hub-game/models/hats/nurse-cap.pxmodel +61 -0
  112. package/kits/hub-game/models/hats/police-cap.pxmodel +105 -0
  113. package/kits/hub-game/models/hats/teacher-beret.pxmodel +52 -0
  114. package/kits/hub-game/models/role/square/top-apron.pxmodel +109 -0
  115. package/kits/hub-game/models/role/square/top-cardigan.pxmodel +141 -0
  116. package/kits/hub-game/models/role/square/top-coat.pxmodel +157 -0
  117. package/kits/hub-game/models/role/square/top-scrubs.pxmodel +93 -0
  118. package/kits/hub-game/models/role/square/top-tabard.pxmodel +109 -0
  119. package/kits/hub-game/models/role/square/top-vest.pxmodel +109 -0
  120. package/kits/hub-game/models/role/tool-bag.pxmodel +75 -0
  121. package/kits/hub-game/models/role/tool-bell.pxmodel +71 -0
  122. package/kits/hub-game/models/role/tool-hose.pxmodel +60 -0
  123. package/kits/hub-game/models/role/tool-parcel.pxmodel +61 -0
  124. package/kits/hub-game/models/role/tool-torch.pxmodel +55 -0
  125. package/kits/hub-game/models/role/tool-tray.pxmodel +75 -0
  126. package/kits/hub-game/models/role/top-apron.pxmodel +70 -0
  127. package/kits/hub-game/models/role/top-cardigan.pxmodel +102 -0
  128. package/kits/hub-game/models/role/top-coat.pxmodel +79 -0
  129. package/kits/hub-game/models/role/top-scrubs.pxmodel +54 -0
  130. package/kits/hub-game/models/role/top-tabard.pxmodel +70 -0
  131. package/kits/hub-game/models/role/top-vest.pxmodel +70 -0
  132. package/kits/hub-game/package-lock.json +1 -1
  133. package/kits/hub-game/package.json +1 -1
  134. package/kits/hub-game/scripts/check.mjs +7 -4
  135. package/kits/hub-game/scripts/fixtures/car-vectors.json +279 -0
  136. package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +2 -1
  137. package/kits/hub-game/scripts/fixtures/hud-surface.json +670 -0
  138. package/kits/hub-game/scripts/fixtures/talk-surface.json +3930 -0
  139. package/kits/hub-game/scripts/gen-hats.mjs +46 -2
  140. package/kits/hub-game/scripts/gen-role.mjs +80 -0
  141. package/kits/hub-game/scripts/test-act-core.mjs +167 -0
  142. package/kits/hub-game/scripts/test-actions-client.mjs +34 -0
  143. package/kits/hub-game/scripts/test-actors.mjs +48 -0
  144. package/kits/hub-game/scripts/test-analytics.mjs +100 -6
  145. package/kits/hub-game/scripts/test-apply-deck.mjs +122 -0
  146. package/kits/hub-game/scripts/test-back-visibility.mjs +3 -1
  147. package/kits/hub-game/scripts/test-ballot.mjs +2 -0
  148. package/kits/hub-game/scripts/test-car.mjs +43 -0
  149. package/kits/hub-game/scripts/test-decor-client.mjs +2 -1
  150. package/kits/hub-game/scripts/test-decor.mjs +77 -0
  151. package/kits/hub-game/scripts/test-device-class.mjs +83 -0
  152. package/kits/hub-game/scripts/test-door-analytics.mjs +1 -1
  153. package/kits/hub-game/scripts/test-emote-wheel.mjs +374 -0
  154. package/kits/hub-game/scripts/test-hats.mjs +5 -4
  155. package/kits/hub-game/scripts/test-host-go.mjs +265 -0
  156. package/kits/hub-game/scripts/test-hub-controls.mjs +108 -0
  157. package/kits/hub-game/scripts/test-hub-entry.mjs +531 -0
  158. package/kits/hub-game/scripts/test-hub-ops.mjs +103 -0
  159. package/kits/hub-game/scripts/test-hub-trip.mjs +20 -1
  160. package/kits/hub-game/scripts/test-hud-clear.mjs +12 -2
  161. package/kits/hub-game/scripts/test-hud-rate.mjs +6 -2
  162. package/kits/hub-game/scripts/test-hud-surface.mjs +272 -0
  163. package/kits/hub-game/scripts/test-idle.mjs +347 -1
  164. package/kits/hub-game/scripts/test-interest-cells.mjs +8 -1
  165. package/kits/hub-game/scripts/test-invites-client.mjs +42 -1
  166. package/kits/hub-game/scripts/test-load-abandon.mjs +2 -2
  167. package/kits/hub-game/scripts/test-manifest.mjs +30 -0
  168. package/kits/hub-game/scripts/test-menu-client.mjs +1 -1
  169. package/kits/hub-game/scripts/test-no-trips.mjs +42 -0
  170. package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
  171. package/kits/hub-game/scripts/test-quality.mjs +13 -0
  172. package/kits/hub-game/scripts/test-rehello.mjs +258 -3
  173. package/kits/hub-game/scripts/test-resume-pose-server.mjs +203 -0
  174. package/kits/hub-game/scripts/test-resync.mjs +196 -0
  175. package/kits/hub-game/scripts/test-role-client.mjs +427 -0
  176. package/kits/hub-game/scripts/test-role.mjs +350 -0
  177. package/kits/hub-game/scripts/test-safe-layout.mjs +50 -1
  178. package/kits/hub-game/scripts/test-soundscape.mjs +124 -7
  179. package/kits/hub-game/scripts/test-standing.mjs +15 -1
  180. package/kits/hub-game/scripts/test-talk-surface.mjs +296 -0
  181. package/kits/hub-game/scripts/test-tiers.mjs +13 -0
  182. package/kits/hub-game/scripts/test-track-queue.mjs +64 -0
  183. package/kits/hub-game/scripts/test-ui-dom-dom.mjs +96 -0
  184. package/kits/hub-game/scripts/test-ui-tree.mjs +711 -0
  185. package/kits/hub-game/scripts/test-vehicle-client.mjs +168 -0
  186. package/kits/hub-game/scripts/test-vehicle.mjs +135 -0
  187. package/kits/hub-game/scripts/test-world-labels.mjs +40 -0
  188. package/kits/hub-game/scripts/test-yours.mjs +33 -0
  189. package/kits/hub-game/tools/hubScene/export.mjs +613 -0
  190. package/kits/hub-game/tools/hubScene/hubdata.mjs +921 -0
  191. package/kits/hub-game/tools/hubScene/merge-root.mjs +39 -0
  192. package/kits/hub-game/tools/hubScene/nodeworld.mjs +227 -0
  193. package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +810 -0
  194. package/kits/hub-game/tools/hubScene/test/fixture.json +637 -0
  195. package/kits/hub-game/tools/hubScene/test/paint-export.mjs +40 -0
  196. package/kits/hub-game/tools/hubScene/test/upload.test.mjs +655 -0
  197. package/kits/hub-game/tools/hubScene/upload.mjs +636 -0
  198. package/kits/hub-game/tools/hubScene/validate-manifest.mjs +301 -0
  199. package/kits/multiplayer-3d/castle.json +4 -4
  200. package/kits/multiplayer-3d/code/client/resumeGate.js +30 -2
  201. package/kits/multiplayer-3d/code/client/steer.js +3 -1
  202. package/kits/multiplayer-3d/code/systems/multiplayer.js +30 -2
  203. package/kits/multiplayer-3d/package-lock.json +1 -1
  204. package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +74 -2
  205. package/kits/physics-3d/CLAUDE.md +1 -1
  206. package/kits/physics-3d/behaviors/Player.jsx +37 -27
  207. package/kits/physics-3d/castle.json +2 -2
  208. package/kits/physics-3d/docs/engine-geometry-memory.md +23 -0
  209. package/kits/physics-3d/engine3d/memoryprofile.js +17 -0
  210. package/kits/physics-3d/engine3d/playerRun.js +6 -1
  211. package/kits/physics-3d/engine3d/pxmodel.js +6 -1
  212. package/kits/physics-3d/engine3d/world3d.js +6 -3
  213. package/kits/physics-3d/package.json +1 -1
  214. package/kits/physics-3d/play/behaviors/Player.js +40 -28
  215. package/kits/physics-3d/scripts/test-memory-profile.mjs +237 -0
  216. package/kits/physics-3d/systems/physics3d.js +5 -2
  217. package/kits/real-time/castle.json +2 -2
  218. package/kits/real-time/code/client/messages.js +5 -0
  219. package/kits/real-time/code/server/session.js +28 -1
  220. package/kits/real-time/package-lock.json +1 -1
  221. package/package.json +5 -4
  222. package/vendor/three/LICENSE +21 -0
  223. package/vendor/three/build/three.core.js +58773 -0
  224. package/vendor/three/build/three.module.js +18251 -0
  225. package/vendor/three/examples/jsm/controls/OrbitControls.js +1860 -0
  226. package/vendor/three/examples/jsm/controls/TransformControls.js +1918 -0
  227. package/vendor/three/examples/jsm/exporters/GLTFExporter.js +3595 -0
  228. package/vendor/three/examples/jsm/geometries/RoundedBoxGeometry.js +216 -0
  229. package/vendor/three/examples/jsm/math/MeshSurfaceSampler.js +315 -0
  230. package/vendor/three/examples/jsm/postprocessing/EffectComposer.js +363 -0
  231. package/vendor/three/examples/jsm/postprocessing/MaskPass.js +195 -0
  232. package/vendor/three/examples/jsm/postprocessing/OutputPass.js +139 -0
  233. package/vendor/three/examples/jsm/postprocessing/Pass.js +191 -0
  234. package/vendor/three/examples/jsm/postprocessing/RenderPass.js +183 -0
  235. package/vendor/three/examples/jsm/postprocessing/ShaderPass.js +135 -0
  236. package/vendor/three/examples/jsm/shaders/CopyShader.js +52 -0
  237. package/vendor/three/examples/jsm/shaders/OutputShader.js +103 -0
  238. package/vendor/three/examples/jsm/utils/BufferGeometryUtils.js +1435 -0
  239. package/vendor/three/package.json +134 -0
@@ -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;
@@ -1,4 +1,5 @@
1
1
  // v1.93: server only. A place without analytics creates no state or messages.
2
+ import { send } from './trackQueue.js';
2
3
  export const EVENTS = Object.freeze({ arrive: 1, door_enter: 2, door_exit: 3, game_result: 4,
3
4
  activity_start: 5, activity_end: 6, outcome: 7, first_play: 8, pointer_stage: 9,
4
5
  reconnect: 10, session_end: 11, furniture_placed: 12, furniture_moved: 13,
@@ -19,11 +20,7 @@ export function track(h, playerId, name, props = {}) {
19
20
  if (!Number.isSafeInteger(n) || n < 0 || n > max) {return false;}
20
21
  event[key] = n;
21
22
  }
22
- try {
23
- const pending = h.session?.hub?.track?.(playerId, event);
24
- if (pending && typeof pending.catch === 'function') {pending.catch(() => {});}
25
- return pending !== undefined && pending !== false;
26
- } catch { return false; }
23
+ return send(h.session, playerId, event);
27
24
  }
28
25
  export function arrive(h, group) {
29
26
  const a = h.analytics, now = h.sim.timeMs;
@@ -35,8 +32,8 @@ export function arrive(h, group) {
35
32
  if (key) {a.departed.delete(key);}
36
33
  a.visits.set(p.playerId, { at: now, userId: key });
37
34
  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 });}
35
+ 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 };}
36
+ 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
37
  }
41
38
  }
42
39
  // Resolve the existing arrival once storage has answered, without duplicating it.
@@ -48,13 +45,63 @@ export function firstVisitArrived(h, playerId, flags) {
48
45
  if (accepted) {delete visit.arrival;}
49
46
  return accepted;
50
47
  }
48
+ // Terminal rows carry how their segment ended in `result` (Ghost owns flags):
49
+ // 0 the visit ended here, 1 its connection dropped and never came back in
50
+ // time, 2 a segment that continued the visit after a late resume. Rows with
51
+ // result 0 or 1 count each real visit once; summing `value` gives its
52
+ // connected time.
53
+ export const END = Object.freeze({ left: 0, dropped: 1, continued: 2 });
54
+ // The host resolves a departed player for under a minute, while a place may
55
+ // hold the visit for five. A drop still away this long is reported now.
56
+ export const DROP_REPORT_MS = 40000;
57
+ function end(h, playerId, visit, value, result) {
58
+ if (visit.arrival) {firstVisitArrived(h, playerId, 0);}
59
+ value = Math.max(0, Math.min(2147483647, Math.round(value)));
60
+ track(h, playerId, 'session_end', { value, result });
61
+ if (h.manifest.house) {track(h, playerId, 'house_time', { subject: SUBJECTS.house, value, result });}
62
+ }
63
+ // Every reconcile, after the place forgot whom it lets go. Presence is the
64
+ // session roster, whatever the place still retains: a stale body or a resume
65
+ // hold must not move the report deadline. A new body under the same id means
66
+ // the connection came back between two ticks; the time between is away.
67
+ export function observe(h) {
68
+ const now = h.sim.timeMs;
69
+ for (const [playerId, visit] of h.analytics.visits) {
70
+ const body = h.sim.players.get(playerId);
71
+ if (h.session?.players.some((p) => p.playerId === playerId)) {
72
+ if (visit.droppedAt !== undefined) {resume(h, visit, now);}
73
+ else if (body && visit.body && body !== visit.body && visit.seen !== undefined) {visit.at += now - visit.seen;}
74
+ if (body) {visit.body = body;}
75
+ visit.seen = now;
76
+ } else if (!h.resumeDeparting?.has(playerId)) {
77
+ if (visit.droppedAt === undefined) {
78
+ visit.droppedAt = visit.seen ?? now;
79
+ visit.droppedWall = Date.now();
80
+ }
81
+ if (!visit.reported && Date.now() - visit.droppedWall >= DROP_REPORT_MS) {
82
+ end(h, playerId, visit, visit.droppedAt - visit.at, visit.continued ? END.continued : END.dropped);
83
+ visit.reported = true;
84
+ }
85
+ }
86
+ }
87
+ }
88
+ // A quick return is the same segment, without the time away. One after its
89
+ // drop was reported starts a continuation.
90
+ function resume(h, visit, now) {
91
+ if (visit.reported) {
92
+ visit.continued = true;
93
+ visit.at = now;
94
+ } else {visit.at += now - visit.droppedAt;}
95
+ delete visit.droppedAt;
96
+ delete visit.droppedWall;
97
+ delete visit.reported;
98
+ }
51
99
  export function leave(h, playerId) {
52
100
  const a = h.analytics, visit = a.visits.get(playerId);
53
101
  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 });}
102
+ if (visit.droppedAt !== undefined) {
103
+ if (!visit.reported) {end(h, playerId, visit, visit.droppedAt - visit.at, visit.continued ? END.continued : END.dropped);}
104
+ } else {end(h, playerId, visit, h.sim.timeMs - visit.at, visit.continued ? END.continued : END.left);}
58
105
  a.visits.delete(playerId);
59
106
  if (visit.userId) {a.departed.set(visit.userId, h.sim.timeMs);}
60
107
  }
@@ -73,11 +120,7 @@ export function fps(h, session, player, data) {
73
120
  const field = data.final ? 'fpsFinalAt' : 'fpsAt';
74
121
  if (entry[field] !== undefined && now - entry[field] < 60000) {return false;}
75
122
  entry[field] = now;
76
- try {
77
- const pending = h.session?.hub?.track?.(player.playerId, {
78
- kind: 26, subject: data.tier, value: data.median * 4096 + data.p10, result: data.avatars, flags: 0,
79
- });
80
- pending?.catch?.(() => {});
81
- return pending !== undefined && pending !== false;
82
- } catch { return false; }
123
+ return send(h.session, player.playerId, {
124
+ kind: 26, subject: data.tier, value: data.median * 4096 + data.p10, result: data.avatars, flags: 0,
125
+ });
83
126
  }
@@ -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);
@@ -1,14 +1,11 @@
1
+ import { send } from './trackQueue.js';
1
2
  // Numeric door telemetry. Ghost stamps the subject from the committed trip;
2
3
  // the client's door id and the authored server's subject are never trusted.
3
4
  export const EVENTS = Object.freeze({ round_start: 28, round_end: 29, door_progress: 30, door_error: 31 });
4
5
  export const ERROR_INTERVAL_MS = 10000;
5
6
  function emit(h, playerId, name, value, result) {
6
7
  if (!h.players.get(playerId)?.arrived) {return false;}
7
- try {
8
- const pending = h.session?.hub?.track?.(playerId, { kind: EVENTS[name], value, result });
9
- pending?.catch?.(() => {});
10
- return pending !== undefined && pending !== false;
11
- } catch {return false;}
8
+ return send(h.session, playerId, { kind: EVENTS[name], value, result });
12
9
  }
13
10
  export function track(h, playerId, name, props = {}) {
14
11
  const entry = h.players.get(playerId);