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
@@ -1,4 +1,4 @@
1
- // `node scripts/gen-hats.mjs`: writes the sixteen hats a player can wear
1
+ // `node scripts/gen-hats.mjs`: writes the hats a player can wear
2
2
  // (contract §11, `code/client/hats.js`) to `models/hats/<id>.pxmodel`.
3
3
  //
4
4
  // A hat is modelled about its seat: y = 0 is the ring of the head its band or
@@ -39,6 +39,14 @@ export const MAIN = {
39
39
  souwester: '#f0c419',
40
40
  captain: '#22335a',
41
41
  lighthouse: '#d1453b',
42
+ 'police-cap': '#22335a',
43
+ 'nurse-cap': '#f4f6fa',
44
+ 'fire-helmet': '#e5484d',
45
+ 'chef-toque': '#f4f6fa',
46
+ 'delivery-cap': '#f0a12b',
47
+ 'teacher-beret': '#5a4a8a',
48
+ 'hard-hat': '#f0c419',
49
+ 'baker-cap': '#e8c96a',
42
50
  };
43
51
  export const PERCHED = ['lantern', 'lighthouse'];
44
52
 
@@ -811,8 +819,44 @@ const HATS = {
811
819
  ],
812
820
  };
813
821
 
822
+ // Role hats (v1.157) use the same seat and fit as the existing hats.
823
+ const roleCap = (id) => [
824
+ { id: 'crown', kind: 'cylinder', radius: 0.21, height: 0.12, position: [0, 0.06, 0], color: MAIN[id], segments: 16 },
825
+ { id: 'band', kind: 'cylinder', radius: 0.215, height: 0.025, position: [0, 0.012, 0], color: INK, segments: 16 },
826
+ peak('visor', visor(0.19, 0.3), 0.015, INK),
827
+ ];
828
+ const ROLE_HATS = {
829
+ 'police-cap': () => [...roleCap('police-cap'), { id: 'badge', kind: 'box', size: [0.06, 0.06, 0.018], position: [0, 0.07, 0.212], color: '#e3c35a' }],
830
+ 'nurse-cap': () => [
831
+ { id: 'cap', kind: 'box', size: [0.4, 0.13, 0.3], position: [0, 0.065, 0], color: MAIN['nurse-cap'] },
832
+ { id: 'crossV', kind: 'box', size: [0.025, 0.08, 0.015], position: [0, 0.07, 0.16], color: '#e5484d' },
833
+ { id: 'crossH', kind: 'box', size: [0.08, 0.025, 0.015], position: [0, 0.07, 0.16], color: '#e5484d' },
834
+ ],
835
+ 'fire-helmet': () => [
836
+ brim('brim', 0.16, 0.3, 0, MAIN['fire-helmet'], { segments: 16 }),
837
+ { id: 'crown', kind: 'lathe', profile: [[0.21, 0], [0.21, 0.1], [0.16, 0.22], [0, 0.26]], color: MAIN['fire-helmet'], segments: 16 },
838
+ { id: 'badge', kind: 'box', size: [0.07, 0.09, 0.02], position: [0, 0.1, 0.215], color: '#e3c35a' },
839
+ ],
840
+ 'chef-toque': () => [
841
+ { id: 'band', kind: 'cylinder', radius: 0.2, height: 0.12, position: [0, 0.06, 0], color: INK, segments: 16 },
842
+ { id: 'toque', kind: 'lathe', profile: [[0.2, 0.025], [0.2, 0.16], [0.25, 0.2], [0.25, 0.33], [0.18, 0.37], [0, 0.37]], color: MAIN['chef-toque'], segments: 16 },
843
+ ],
844
+ 'delivery-cap': () => [...roleCap('delivery-cap'), { id: 'patch', kind: 'box', size: [0.09, 0.04, 0.015], position: [0, 0.075, 0.212], color: '#f4f6fa' }],
845
+ 'teacher-beret': () => [
846
+ { id: 'band', kind: 'cylinder', radius: 0.2, height: 0.025, position: [0, 0.012, 0], color: INK, segments: 16 },
847
+ { id: 'beret', kind: 'lathe', profile: [[0.2, 0.02], [0.27, 0.07], [0.22, 0.14], [0, 0.16]], color: MAIN['teacher-beret'], segments: 16 },
848
+ ],
849
+ 'hard-hat': () => [
850
+ brim('brim', 0.16, 0.26, 0, INK, { segments: 16 }),
851
+ { id: 'crown', kind: 'lathe', profile: [[0.21, 0], [0.2, 0.14], [0.12, 0.23], [0, 0.25]], color: MAIN['hard-hat'], segments: 16 },
852
+ ],
853
+ 'baker-cap': () => roleCap('baker-cap'),
854
+ };
855
+ Object.assign(HATS, ROLE_HATS);
856
+
814
857
  export function hatModel(id) {
815
- const parts = HATS[id]();
858
+ // A common flat material lets role trims merge within four draw calls.
859
+ const parts = HATS[id]().map((part) => Object.hasOwn(ROLE_HATS, id) ? { ...part, flat: true } : part);
816
860
  return { format: 'pxmodel', name: id, triangles: 900, look: LOOK, parts };
817
861
  }
818
862
 
@@ -0,0 +1,80 @@
1
+ // Role outfits and carried tools (contract §11, v1.157). Tops wrap a 0.2 m
2
+ // waist ring and rise 0.2 m; roleLook fits them to the drawn avatar. Tools
3
+ // have their grip at the origin, +z forward. MAIN alone is recoloured.
4
+ import fs from 'node:fs';
5
+ import { fileURLToPath } from 'node:url';
6
+ import { ROLE_MAIN as MAIN, ROLE_TOPS, ROLE_TOOLS, roleFile } from '../code/client/role.js';
7
+
8
+ const LOOK = { outline: 0.012, outlineColor: '#241a2e', rim: 0.3, ao: 0.4 };
9
+ const INK = '#2b2b33', WHITE = '#f4f6fa', SILVER = '#c9ccd6', GOLD = '#e3c35a';
10
+ const box = (id, size, position, color) => ({ id, kind: 'box', size, position, color });
11
+ const cyl = (id, radius, height, position, color) => ({ id, kind: 'cylinder', radius, height, position, color, segments: 12 });
12
+ const band = (id, bottom, high, color, square) => square ? [
13
+ box(`${id}F`, [0.432, high, 0.016], [0, bottom + high / 2, 0.208], color),
14
+ box(`${id}B`, [0.432, high, 0.016], [0, bottom + high / 2, -0.208], color),
15
+ box(`${id}L`, [0.016, high, 0.4], [0.208, bottom + high / 2, 0], color),
16
+ box(`${id}R`, [0.016, high, 0.4], [-0.208, bottom + high / 2, 0], color),
17
+ ] : [{ id, kind: 'lathe', segments: 20, profile: [[0.2, bottom], [0.216, bottom], [0.216, bottom + high], [0.2, bottom + high]], color }];
18
+
19
+ function top(id, square) {
20
+ const parts = band('body', 0, 0.2, MAIN, square);
21
+ const front = 0.224;
22
+ if (id === 'vest') {
23
+ parts.push(box('zip', [0.018, 0.19, 0.012], [0, 0.1, front], INK), box('badge', [0.065, 0.065, 0.016], [0.09, 0.145, front], GOLD));
24
+ } else if (id === 'scrubs') {
25
+ parts.push(box('pocket', [0.09, 0.07, 0.018], [0.085, 0.08, front], WHITE));
26
+ } else if (id === 'coat') {
27
+ parts.push(...band('reflect', 0.04, 0.025, SILVER, square), box('zip', [0.018, 0.2, 0.012], [0, 0.1, front], INK));
28
+ } else if (id === 'apron') {
29
+ parts.push(box('bib', [0.26, 0.19, 0.02], [0, 0.105, front], MAIN), box('pocket', [0.14, 0.065, 0.018], [0, 0.06, front + 0.014], WHITE));
30
+ } else if (id === 'cardigan') {
31
+ parts.push(box('placket', [0.035, 0.2, 0.012], [0, 0.1, front], WHITE));
32
+ for (let i = 0; i < 3; i += 1) { parts.push(box(`button${i}`, [0.05, 0.05, 0.012], [0, 0.04 + i * 0.06, front + 0.01], GOLD)); }
33
+
34
+ } else if (id === 'tabard') {
35
+ parts.push(box('panel', [0.3, 0.2, 0.02], [0, 0.1, front], MAIN), box('stripe', [0.28, 0.035, 0.016], [0, 0.14, front + 0.014], WHITE));
36
+ }
37
+ return parts;
38
+ }
39
+ const TOOLS = {
40
+ torch: () => [cyl('grip', 0.035, 0.19, [0, -0.03, 0.04], INK), cyl('head', 0.065, 0.07, [0, 0.1, 0.04], MAIN), cyl('light', 0.055, 0.012, [0, 0.14, 0.04], '#ffe9a3')],
41
+ bag: () => [
42
+ box('bag', [0.24, 0.17, 0.14], [0, -0.17, 0.05], MAIN),
43
+ { id: 'handle', kind: 'torus', radius: 0.055, tube: 0.012, position: [0, -0.035, 0.05], color: INK, segments: 10 },
44
+ box('crossV', [0.025, 0.08, 0.012], [0, -0.17, 0.127], WHITE), box('crossH', [0.08, 0.025, 0.012], [0, -0.17, 0.127], WHITE),
45
+ ],
46
+ hose: () => [
47
+ cyl('grip', 0.035, 0.15, [0, 0, 0.04], MAIN),
48
+ { ...cyl('nozzle', 0.045, 0.18, [0, 0.09, 0.1], SILVER), rotation: [70, 0, 0] },
49
+ { id: 'coil', kind: 'torus', radius: 0.095, tube: 0.022, position: [0, -0.14, 0.04], color: INK, segments: 12 },
50
+ ],
51
+ tray: () => [
52
+ cyl('tray', 0.17, 0.018, [0, -0.015, 0.13], MAIN),
53
+ { id: 'cloche', kind: 'lathe', segments: 16, profile: [[0.15, 0], [0.14, 0.06], [0.1, 0.115], [0.035, 0.14], [0, 0.14]], position: [0, 0, 0.13], color: SILVER },
54
+ cyl('knob', 0.04, 0.025, [0, 0.15, 0.13], INK),
55
+ ],
56
+ bell: () => [
57
+ cyl('handle', 0.023, 0.16, [0, -0.02, 0.04], INK),
58
+ { id: 'bell', kind: 'lathe', segments: 16, profile: [[0.09, -0.2], [0.065, -0.18], [0.045, -0.1], [0, -0.09]], position: [0, 0, 0.04], color: MAIN },
59
+ cyl('lip', 0.09, 0.014, [0, -0.2, 0.04], GOLD),
60
+ ],
61
+ parcel: () => [box('parcel', [0.22, 0.19, 0.2], [0, -0.055, 0.12], MAIN), box('tape', [0.035, 0.195, 0.205], [0, -0.055, 0.12], '#e8c96a'), box('label', [0.085, 0.055, 0.012], [0.055, -0.035, 0.227], WHITE)],
62
+ };
63
+
64
+ export function roleModel(kind, id, square = false) {
65
+ if (!(kind === 'top' ? ROLE_TOPS : ROLE_TOOLS).includes(id)) { throw new Error(`Unknown role piece ${id}`); }
66
+ return { format: 'pxmodel', name: `${kind}-${id}${square ? '-square' : ''}`, triangles: 900, look: LOOK, parts: (kind === 'top' ? top(id, square) : TOOLS[id]()).map((part) => ({ ...part, flat: true })) };
67
+ }
68
+
69
+ if (process.argv[1] === fileURLToPath(import.meta.url)) {
70
+ for (const [kind, ids] of [['top', ROLE_TOPS], ['tool', ROLE_TOOLS]]) {
71
+ for (const id of ids) {
72
+ for (const square of kind === 'top' ? [false, true] : [false]) {
73
+ const file = new URL(`../${roleFile(kind, id, square)}`, import.meta.url);
74
+ fs.mkdirSync(new URL('.', file), { recursive: true });
75
+ fs.writeFileSync(file, `${JSON.stringify(roleModel(kind, id, square), null, 1)}\n`);
76
+ }
77
+ }
78
+ }
79
+ console.log('wrote 18 role models');
80
+ }
@@ -0,0 +1,167 @@
1
+ // actCore.js: Act's selection, presses and Jump with no DOM, over a fake
2
+ // scene facade, clock and send -- the way a native host drives it.
3
+ import assert from 'node:assert/strict';
4
+ import { makeActCore, actItems, HOLD_MS } from '../code/client/actCore.js';
5
+
6
+ const state = { place: { id: 'main', act: true, grab: true }, prompts: [], held: new Set(), seated: {}, spawned: {}, hidden: new Set() };
7
+ const actors = [
8
+ { id: 'buy', components: { HubAct: { id: 'buy-hat', verb: 'Buy', reach: 4, hold: true }, Transform: { x: 3, y: 1, z: 0 } } },
9
+ { id: 'play', components: { HubAct: { id: 'play', verb: 'Play', reach: 2, hold: false }, Transform: { x: 1.5, y: 1, z: 0 } } },
10
+ { id: 'clem', components: { HubNpc: { name: 'Clem' }, Transform: { x: 0.5, y: 1, z: 0 } } },
11
+ { id: 'ball', components: { Body: { type: 'dynamic' }, Transform: { x: 0.2, y: 1, z: 0 } } },
12
+ { id: 'bench', components: { HubSeat: {}, Shape: { kind: 'box', width: 4, depth: 1 }, Transform: { x: 0, y: 0.5, z: -1.4 } } },
13
+ { id: 'far', components: { HubAct: { id: 'far', verb: 'Far', reach: 1, hold: false }, Transform: { x: 9, y: 1, z: 0 } } },
14
+ ];
15
+ const offer = (id, verb, hold = false) => ({ id, verb, hold });
16
+ state.prompts = [offer('buy-hat', 'Buy', true), offer('play', 'Play'), offer('clem', 'Talk to Clem'), offer('ball', 'Grab'), offer('bench', 'Sit'), offer('far', 'Far'), offer('ghost', 'Gone')];
17
+
18
+ const net = { id: 'net' }, link = { net };
19
+ const player = { x: 0, y: 1, z: 0 };
20
+ const facade = (over = {}) => ({ scene: 'scene', link, self: 'p1', player, online: true,
21
+ actors: () => actors, getActor: id => actors.find(a => a.id === id), ...over });
22
+
23
+ let now = 0;
24
+ const sent = [], effects = [];
25
+ const core = makeActCore({
26
+ now: () => now, state, seq: 100,
27
+ send: (message, l) => sent.push({ ...message, via: l.net.id }),
28
+ effects: {
29
+ throw: (item, f, done) => effects.push(['throw', item.actor, f.self, done]),
30
+ grab: (item, f) => effects.push(['grab', item.actor, f.self]),
31
+ talk: (item, f) => effects.push(['talk', item.actor, f.self]),
32
+ },
33
+ });
34
+
35
+ // Before any frame: nothing shown, nothing pressable, Jump not taken.
36
+ assert.deepEqual(core.pairState(), { show: false, enabled: false });
37
+ core.start({ id: 'play', hold: false }, 'KeyE'); assert.equal(sent.length, 0, 'no press before a frame');
38
+ assert.equal(core.consumeJump(() => true), undefined, 'no context, no Jump');
39
+
40
+ // Selection: authored verbs outrank Talk and Grab; nearest within a rank;
41
+ // out of reach and unknown offers drop; the seat measures its footprint.
42
+ assert.equal(core.frame(facade(), true), false, 'first frame is not a change');
43
+ assert.deepEqual(core.items().map(i => i.id), ['bench', 'play', 'buy-hat', 'ball', 'clem']);
44
+ assert.equal(core.current().id, 'bench');
45
+ assert(Math.abs(core.items().find(i => i.id === 'bench').d - 0.9) < 1e-9, 'a seat measures to its footprint');
46
+ assert.deepEqual(core.pairState(), { show: true, enabled: true });
47
+ assert.equal(actItems(facade(), state, false).length, 0, 'nothing offered while acting is not allowed');
48
+
49
+ // Hidden actors and server states: Stand on a seat, Throw of a held body.
50
+ state.hidden.add('bench');
51
+ state.prompts[3] = offer('ball', 'Throw');
52
+ core.frame(facade(), true);
53
+ // A held body's Throw ranks with the authored verbs, ahead of the rest.
54
+ assert.deepEqual(core.items().map(i => [i.id, i.op]), [['ball', 'throw'], ['play', 'custom'], ['buy-hat', 'custom'], ['clem', 'talk']]);
55
+ assert.equal(core.items().find(i => i.id === 'ball').d, 0, 'a held body is always in reach');
56
+ state.hidden.clear(); state.prompts[4] = offer('bench', 'Stand');
57
+ core.frame(facade(), true);
58
+ assert.equal(core.items().find(i => i.id === 'bench').op, 'stand');
59
+ state.prompts[4] = offer('bench', 'Sit'); state.prompts[3] = offer('ball', 'Grab');
60
+
61
+ // A tap performs at once with a fresh nonce and the item's effect.
62
+ const pick = id => core.items().find(i => i.id === id);
63
+ core.frame(facade(), true);
64
+ core.start(pick('play'), 'KeyE');
65
+ assert.deepEqual(sent.at(-1), { k: 'hub-act', id: 'play', n: 101, via: 'net' });
66
+ core.start(pick('clem'), 'pointer:1');
67
+ assert.deepEqual(effects.at(-1), ['talk', 'clem', 'p1']); assert.equal(sent.at(-1).id, 'clem');
68
+ core.start(pick('ball'), 'pointer:1');
69
+ assert.deepEqual(effects.at(-1), ['grab', 'ball', 'p1']); assert.equal(sent.at(-1).id, 'ball');
70
+ // Throw sends only when the prediction path says so.
71
+ state.prompts[3] = offer('ball', 'Throw'); core.frame(facade(), true);
72
+ const before = sent.length; core.start(pick('ball'), 'KeyE');
73
+ assert.equal(sent.length, before); effects.at(-1)[3]();
74
+ assert.deepEqual(sent.at(-1), { k: 'hub-act', id: 'ball', n: 104, via: 'net' });
75
+ state.prompts[3] = offer('ball', 'Grab'); core.frame(facade(), true);
76
+
77
+ // A hold: down, progress, an early release cancels and never buys.
78
+ core.start(pick('buy-hat'), 'Space');
79
+ assert.deepEqual(sent.at(-1), { k: 'hub-act-hold', id: 'buy-hat', n: 105, down: true, via: 'net' });
80
+ assert.equal(core.pressSource(), 'Space');
81
+ core.start(pick('play'), 'KeyE'); assert.equal(sent.at(-1).n, 105, 'one press at a time');
82
+ now = HOLD_MS / 2; assert.equal(core.progress('buy-hat'), 0.5); assert.equal(core.progress('play'), 0);
83
+ core.release();
84
+ assert.deepEqual(sent.at(-1), { k: 'hub-act-hold', id: 'buy-hat', n: 105, down: false, via: 'net' });
85
+ assert.equal(core.pressSource(), null);
86
+ // Completed by release once held long enough.
87
+ core.start(pick('buy-hat'), 'Space'); now += HOLD_MS; core.release();
88
+ assert.deepEqual(sent.at(-1), { k: 'hub-act', id: 'buy-hat', n: 106, via: 'net' });
89
+ // Completed by the frame, and only once.
90
+ core.start(pick('buy-hat'), 'pointer:2'); now += HOLD_MS - 1; core.frame(facade(), true);
91
+ assert.equal(sent.at(-1).k, 'hub-act-hold');
92
+ now += 1; core.frame(facade(), true);
93
+ assert.deepEqual(sent.at(-1), { k: 'hub-act', id: 'buy-hat', n: 107, via: 'net' });
94
+ const count = sent.length; now += 5000; core.frame(facade(), true); core.release();
95
+ assert.equal(sent.length, count, 'a completed hold does not repeat');
96
+
97
+ // A press ends when its offer changes, acting is barred or the context moves.
98
+ core.start(pick('buy-hat'), 'Space');
99
+ state.prompts[0] = offer('buy-hat', 'Buy', false); core.frame(facade(), true);
100
+ assert.equal(sent.at(-1).down, false, 'a changed offer cancels the hold');
101
+ state.prompts[0] = offer('buy-hat', 'Buy', true); core.frame(facade(), true);
102
+ core.start(pick('buy-hat'), 'Space'); core.frame(facade(), false);
103
+ assert.equal(sent.at(-1).down, false, 'a barred frame cancels');
104
+ assert.deepEqual(core.pairState(), { show: false, enabled: false });
105
+ core.frame(facade(), true); core.start(pick('buy-hat'), 'Space');
106
+ core.frame(facade({ online: false }), true);
107
+ assert.equal(sent.at(-1).down, false, 'a lost connection cancels');
108
+ core.frame(facade(), true); core.start(pick('buy-hat'), 'Space');
109
+ const other = { link: { net: { id: 'other' } } };
110
+ assert.equal(core.frame(facade(other), true), true, 'another connection is a change');
111
+ assert.deepEqual(sent.at(-1), { k: 'hub-act-hold', id: 'buy-hat', n: 111, down: false, via: 'net' }, 'cancelled on the old connection');
112
+ assert.equal(core.frame(facade(other), true), false);
113
+ assert.equal(core.frame(facade({ ...other, scene: 'scene2' }), true), true, 'another scene is a change');
114
+ state.place = { ...state.place, id: 'door' };
115
+ assert.equal(core.frame(facade({ ...other, scene: 'scene2' }), true), true, 'another place is a change');
116
+ core.start(pick('play'), 'KeyE'); assert.equal(sent.at(-1).via, 'other');
117
+
118
+ // As on the web, a net replaced inside the same link is no change, and sends
119
+ // follow the link's current net.
120
+ {
121
+ const same = { net: { id: 'a' } }, f = facade({ link: same });
122
+ core.frame(f, true); core.start(pick('buy-hat'), 'Space');
123
+ same.net = { id: 'b' };
124
+ assert.equal(core.frame(facade({ link: same }), true), false);
125
+ core.release(); assert.deepEqual(sent.at(-1), { k: 'hub-act-hold', id: 'buy-hat', n: 113, down: false, via: 'b' }, 'the hold survives and its release goes on the new net');
126
+ // A host reusing one facade object still has its scene change seen.
127
+ core.frame(f, true); core.queueJump(); f.scene = 'scene-reused';
128
+ assert.equal(core.frame(f, true), true, 'a reused facade object still shows the change');
129
+ assert.equal(core.consumeJump(() => false), false);
130
+ core.frame(facade({ ...other, scene: 'scene2' }), true);
131
+ }
132
+
133
+ // Held still by the place: no Act, unless seated.
134
+ state.held.add('p1'); core.frame(facade({ ...other, scene: 'scene2' }), true);
135
+ assert.equal(core.can(), false); assert.equal(core.items().length, 0);
136
+ state.seated.p1 = 'bench'; core.frame(facade({ ...other, scene: 'scene2' }), true);
137
+ assert.equal(core.can(), true);
138
+ state.held.clear(); state.seated = {};
139
+ assert.equal(core.frame(facade({ ...other, scene: 'scene2', player: null }), true), false);
140
+ assert.equal(core.can(), false, 'no local player, no Act');
141
+
142
+ // Jump: queued only while allowed, consumed once, ORed with the original.
143
+ core.frame(facade(), true);
144
+ core.queueJump();
145
+ assert.equal(core.consumeJump(() => false), true); assert.equal(core.consumeJump(() => false), false);
146
+ assert.equal(core.consumeJump(() => true), true, 'the movement input\'s own Jump still counts');
147
+ core.frame(facade(), false); core.queueJump();
148
+ assert.equal(core.consumeJump(() => true), false, 'no Jump while barred');
149
+ core.frame(facade(), true); core.queueJump(); core.frame(facade({ scene: 'scene3' }), true);
150
+ assert.equal(core.consumeJump(() => false), false, 'a context change drops a queued Jump');
151
+
152
+ // Nothing in reach: shown, Act disabled.
153
+ const saved = state.prompts; state.prompts = []; core.frame(facade(), true);
154
+ assert.deepEqual(core.pairState(), { show: true, enabled: false }); assert.equal(core.current(), null);
155
+ state.prompts = saved; core.frame(facade(), true);
156
+
157
+ // Dispose cancels a live hold.
158
+ core.start(pick('buy-hat'), 'Space'); core.dispose();
159
+ assert.equal(sent.at(-1).down, false); assert.equal(core.pressSource(), null);
160
+ // A host with no Throw effect still sends Throw.
161
+ {
162
+ const bare = [], plain = makeActCore({ now: () => now, state, seq: 0, send: (m) => bare.push(m) });
163
+ state.prompts[3] = offer('ball', 'Throw'); plain.frame(facade(), true);
164
+ plain.start(plain.items().find(i => i.id === 'ball'), 'KeyE');
165
+ assert.deepEqual(bare, [{ k: 'hub-act', id: 'ball', n: 1 }]);
166
+ }
167
+ console.log('Act core: rank and reach, Stand/Throw, taps and effects, holds, cancels, context changes, held/seated, pair state and Jump passed');
@@ -660,6 +660,40 @@ test('frame wiring only draws in opted-in places and clears once on keyless trav
660
660
  assert.equal(calls.filter(([name]) => name === 'clearActions').length, 1);
661
661
  assert(!Object.hasOwn(system, 'actionsDrawn'));
662
662
  });
663
+ test('invite actions are drawn and sent only while the host makes links for this player', () => {
664
+ State.clear(); fakeDom({ viewW: 360, viewH: 780 });
665
+ let system; installSystem({ registerSystem(value) { system = value; } });
666
+ const calls = [], sent = [];
667
+ system.chrome = new Proxy({ peopleOpen: () => false, chatFocused: () => false, padOccupancyControls: () => [] }, { get(target, name) { return target[name] ?? ((...args) => calls.push([name, ...args])); } });
668
+ system.talk = { frame() {}, talking: () => false, typing: () => false, talkingWith: () => null };
669
+ system.idle = { frame() {}, draw() {}, labels: () => [] };
670
+ system.grab = { frame() {} }; system.sound = { frame() {} }; system.sayHooked = true;
671
+ system.together.frame = () => {};
672
+ for (const method of ['keepResident', 'wearAvatar', 'applyTune', 'watchSession', 'sayHello', 'followPlace', 'holdFall', 'turnSpinners', 'applySpawns', 'applyTints', 'registerInterest', 'applyVisibility', 'applyWear', 'adoptLate', 'runCommands', 'askFriends', 'stepEnd', 'faceArrival', 'measure']) system[method] = () => {};
673
+ system.sceneKey = 'main';
674
+ let allowed = false;
675
+ system.invites = { frame() {}, canInvite: () => allowed, dispose() {} };
676
+ const scene = { sceneKey: 'main', currentScenePath: 'scenes/main.scene', multiplayer: { net: { selfId: () => 'p1', send: (msg) => sent.push(msg) } }, actorWith: () => null, persistent: { hubTickets: [], hubAvatar: 0 }, getActors: () => [] };
677
+ const offered = [{ id: 'invite-friend', label: 'Invite a friend' }, { id: 'market-looks', label: 'Market looks' }, { id: 'share-win', label: 'Share' }, { id: 'share-town', label: 'Share' }];
678
+ hook.state({}, { hubPlace: { id: 'main', title: 'Town', scene: 'scenes/main.scene', result: null } });
679
+ State.hub.place.actions = true; State.hub.place.invite = true; State.hub.actions = { items: offered, n: 3 };
680
+ const drawn = () => calls.findLast(([name]) => name === 'setActions');
681
+ system.afterBehaviors(scene, 0.05);
682
+ assert.deepEqual(drawn()[1].map((item) => item.id), ['market-looks'], 'a refused host hides every invite action');
683
+ drawn()[2]('invite-friend', 3); drawn()[2]('share-win', 3);
684
+ assert.deepEqual(sent, [], 'a stale invite pick is not sent while the host refuses');
685
+ drawn()[2]('market-looks', 3);
686
+ assert.deepEqual(sent, [{ k: 'hub-action', id: 'market-looks', n: 3 }], 'other actions are sent as before');
687
+ allowed = true; sent.length = 0;
688
+ system.afterBehaviors(scene, 0.05);
689
+ assert.deepEqual(drawn()[1], offered, 'an allowing host draws the offer unchanged');
690
+ drawn()[2]('share-town', 3);
691
+ assert.deepEqual(sent, [{ k: 'hub-action', id: 'share-town', n: 3 }]);
692
+ State.hub.place.invite = false; sent.length = 0;
693
+ system.afterBehaviors(scene, 0.05);
694
+ assert.deepEqual(drawn()[1].map((item) => item.id), ['market-looks'], 'a place without invites never draws them');
695
+ drawn()[2]('invite-friend', 3); assert.deepEqual(sent, []);
696
+ });
663
697
  test('opted-in late crowd pass uses current renderer eligibility and restores OFF', () => {
664
698
  State.clear();
665
699
  State.hub.place = { id: 'main', result: null };
@@ -5,6 +5,9 @@
5
5
  // needs nothing installed.
6
6
 
7
7
  import assert from 'node:assert/strict';
8
+ import fs from 'node:fs';
9
+ import os from 'node:os';
10
+ import path from 'node:path';
8
11
  import { register } from 'node:module';
9
12
 
10
13
  const sceneStub = 'export const readScene = () => globalThis.__hubTestActors ?? [];';
@@ -22,6 +25,7 @@ register(
22
25
  );
23
26
  const { layer } = await import('../code/server/hub.js');
24
27
  const Actors = await import('../code/server/actors.js');
28
+ const { readManifest } = await import('../code/server/manifest.js');
25
29
  const { look } = await import('../code/client/wear.js');
26
30
  const Wear = await import('../code/server/wear.js');
27
31
 
@@ -393,6 +397,34 @@ test('spawn copies a scene actor for everyone, under its caps; despawn removes i
393
397
  assert.equal(Object.keys(h.join().spawned).length, Actors.MAX_SPAWNED);
394
398
  });
395
399
 
400
+ test('v1.161 a deck may raise the spawn cap to 192; absent keeps 96 and the same manifest bytes', () => {
401
+ const engine = { createBody: () => body(), removeActor: (sim, id) => { sim.bodies.delete(id); sim.objects.delete(id); } };
402
+ const filled = (hubKeys) => {
403
+ let hub = null;
404
+ const h = layer({ ...castleJson, hub: { ...castleJson.hub, ...hubKeys } }, { ready: (x) => (hub = x) }, {}, sceneExists, () => null, null, engine);
405
+ h.sceneFor({ sessionId: 's-1', players: [], hub: null, send() {}, broadcast() {} });
406
+ const world = { timeMs: 0, players: new Map(), bodies: new Map(), objects: new Map(), scenePath: 'scenes/main.scene' };
407
+ h.ready(world);
408
+ for (let i = 0; i < 40; i += 1) {
409
+ world.timeMs += 10000;
410
+ while (hub.spawn('wall', {})) {}
411
+ }
412
+ return Object.keys(h.join().spawned).length;
413
+ };
414
+ assert.equal(filled({}), 96);
415
+ assert.equal(filled({ spawnCap: 96 }), 96);
416
+ assert.equal(filled({ spawnCap: 150 }), 150);
417
+ assert.equal(filled({ spawnCap: 192 }), 192);
418
+ const plain = readManifest(castleJson, sceneExists).manifest;
419
+ assert.equal(Object.hasOwn(plain, 'spawnCap'), false);
420
+ assert.equal(readManifest({ ...castleJson, hub: { ...castleJson.hub, spawnCap: 192 } }, sceneExists).manifest.spawnCap, 192);
421
+ for (const spawnCap of [95, 193, 120.5, '150', null, true]) {
422
+ assert.equal(readManifest({ ...castleJson, hub: { ...castleJson.hub, spawnCap } }, sceneExists).manifest, null, String(spawnCap));
423
+ }
424
+ const placed = { ...castleJson, hub: { ...castleJson.hub, places: { room: { title: 'Room', scene: 'scenes/room.scene', spawnCap: 150 } } } };
425
+ assert.equal(readManifest(placed, sceneExists).manifest, null, 'root only');
426
+ });
427
+
396
428
  test("tune sets one player's controller within bounds, and the server clamp follows it", () => {
397
429
  const sent = [];
398
430
  let hub = null;
@@ -677,5 +709,21 @@ test('wear: a block hides a wearable as it hides the avatar, sent alone to who m
677
709
  assert.deepEqual(sent, []);
678
710
  });
679
711
 
712
+ // The publish check refuses a spawn cap outside 96..192 (v1.161).
713
+ const check = (await import('./check.mjs')).default;
714
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'hub-spawn-cap-'));
715
+ try {
716
+ fs.mkdirSync(path.join(dir, 'scenes'));
717
+ fs.writeFileSync(path.join(dir, 'scenes/main.scene'), JSON.stringify({ actors: globalThis.__hubTestActors }));
718
+ const deck = (spawnCap) => fs.writeFileSync(path.join(dir, 'castle.json'), JSON.stringify({ server: { main: 'code/server/index.js', maxPlayers: 8 }, hub: { ...castleJson.hub, spawnCap } }));
719
+ deck(192);
720
+ assert.ok(!(await check({ deckDir: dir, self: true })).errors.some((e) => e.includes('spawnCap')));
721
+ deck(193);
722
+ assert.ok((await check({ deckDir: dir, self: true })).errors.includes('hub.spawnCap must be an integer 96..192.'));
723
+ n += 1;
724
+ } finally {
725
+ fs.rmSync(dir, { recursive: true, force: true });
726
+ }
727
+
680
728
  console.warn = warn;
681
729
  console.log(`test-actors: ${n} passed`);
@@ -1,5 +1,8 @@
1
1
  import assert from 'node:assert/strict';
2
+ import { register } from 'node:module';
2
3
  import * as A from '../code/server/analytics.js';
4
+ import * as DoorAnalytics from '../code/server/doorAnalytics.js';
5
+ import { encodeDeviceClass } from '../code/shared/deviceClass.js';
3
6
  import { readManifest, publicPlace } from '../code/server/manifest.js';
4
7
  import * as Town from '../../../experiments/hub-town/code/server/analytics.js';
5
8
  const castle = (hub = {}) => ({ hub: { contract: 1, title: 'Town', ...hub } });
@@ -15,22 +18,27 @@ assert.deepEqual(publicPlace('main', v111), publicPlace('main', old), 'v1.111 an
15
18
  assert(readManifest(castle({ analyticsV111: true })).errors.some((e) => e.includes('requires analytics')));
16
19
  for (const analyticsV111 of [false, 1, 'true', {}, null]) assert(readManifest(castle({ analytics: true, analyticsV111 })).errors.some((e) => e.includes('.analyticsV111')));
17
20
  const calls = [];
21
+ const device = encodeDeviceClass({ lowMemory: true, cores: 4, dpr: 2, width: 360, height: 800, deviceMemory: 2 });
18
22
  const h = { place: { analytics: true }, manifest: {}, sim: { timeMs: 0 }, players: new Map([['p', { arrived: true }]]),
19
23
  session: { hub: { track: (id, event) => { calls.push([id, event]); return Promise.resolve(true); } } }, analytics: A.create() };
20
24
  A.arrive(h, [{ playerId: 'p', userId: '42' }]);
21
25
  assert.equal(calls.at(-1)[1].kind, A.EVENTS.arrive);
26
+ assert.equal(calls.at(-1)[1].value, 0, 'missing device records unknown');
22
27
  for (const props of [{ text: 'private words' }, { subject: 'another user' }, { value: null }, { value: -1 }, { value: NaN }]) assert.equal(A.track(h, 'p', 'outcome', props), false);
23
28
  for (const event of ['invite_sent', 'invite_opened', 'invite_joined', 'arrival_source', 'join_failed']) assert.equal(A.track(h, 'p', event), false, `${event} is platform-owned`);
24
29
  assert.equal(A.track(h, 'stranger', 'outcome'), false);
25
30
  h.sim.timeMs = 1000; A.leave(h, 'p'); A.leave(h, 'p');
26
31
  assert.equal(calls.filter(([, e]) => e.kind === A.EVENTS.session_end).length, 1);
27
- h.sim.timeMs = 31000; A.arrive(h, [{ playerId: 'p', userId: '42' }]);
32
+ h.sim.timeMs = 31000; A.arrive(h, [{ playerId: 'p', userId: '42', device }]);
28
33
  assert.equal(calls.at(-1)[1].kind, A.EVENTS.reconnect);
34
+ assert.equal(calls.at(-1)[1].value, 0, 'reconnect does not carry device');
29
35
  h.sim.timeMs = 32000; A.leave(h, 'p');
30
- A.arrive(h, [{ playerId: 'p', userId: '42', from: 'race' }]);
36
+ A.arrive(h, [{ playerId: 'p', userId: '42', from: 'race', device }]);
31
37
  assert.equal(calls.at(-1)[1].kind, A.EVENTS.arrive, 'door returns are town arrivals');
32
- h.manifest.house = {}; A.arrive(h, [{ playerId: 'p', userId: '43' }]);
38
+ assert.equal(calls.at(-1)[1].value, device, 'track accepts packed device on arrival');
39
+ h.manifest.house = {}; A.arrive(h, [{ playerId: 'p', userId: '43', device }]);
33
40
  assert.equal(calls.at(-1)[1].kind, A.EVENTS.house_visit, 'house entry must not be a town arrival');
41
+ assert.equal(calls.at(-1)[1].value, device, 'house entry carries device');
34
42
  const before = calls.length; h.place.analytics = undefined;
35
43
  assert.equal(A.track(h, 'p', 'arrive'), false); assert.equal(calls.length, before);
36
44
  // Town spans start only on accepted interactions; durations exclude the inactivity tail.
@@ -40,6 +48,36 @@ town.now = 35001; Town.tick(town);
40
48
  assert.deepEqual(events.map(([, event]) => event), ['activity_start', 'outcome', 'outcome', 'activity_end']);
41
49
  assert.equal(events.at(-1)[2].value, 5000);
42
50
  Town.leave(town, 'p'); assert.equal(events.length, 4);
51
+ {
52
+ // A drop reports at its deadline once; a quick return is the same segment.
53
+ const rows = [], realNow = Date.now;
54
+ let wall = 0;
55
+ Date.now = () => wall;
56
+ try {
57
+ const body = {};
58
+ const h = { place: { analytics: true }, manifest: { house: {} }, sim: { timeMs: 0, players: new Map([['p', body]]) },
59
+ players: new Map([['p', { arrived: true }]]), analytics: A.create(),
60
+ session: { players: [{ playerId: 'p' }], hub: { track: (id, event) => { rows.push(event); return true; } } } };
61
+ const ends = () => rows.filter((e) => e.kind === 11 || e.kind === 17).map((e) => [e.kind, e.value, e.result]);
62
+ const at = (ms, present) => { wall += ms - h.sim.timeMs; h.sim.timeMs = ms; h.session.players = present ? [{ playerId: 'p' }] : []; A.observe(h); };
63
+ A.arrive(h, [{ playerId: 'p', userId: '42' }]);
64
+ at(1000, true); at(1050, false); at(20000, false); at(20050, true);
65
+ at(22000, true); at(22050, false); at(62000, false);
66
+ assert.deepEqual(ends(), [], 'reported 40 s after the drop is first seen');
67
+ at(62050, false); at(90000, false);
68
+ assert.deepEqual(ends(), [[11, 2950, 1], [17, 2950, 1]], 'time away is excluded; a report is once');
69
+ at(100000, true); at(105000, true); A.leave(h, 'p');
70
+ assert.deepEqual(ends().slice(2), [[11, 5000, 2], [17, 5000, 2]], 'a late resume reports its continuation');
71
+ rows.length = 0; A.arrive(h, [{ playerId: 'p', userId: '43' }]);
72
+ at(106000, true); at(106050, false); at(110000, false); A.leave(h, 'p'); A.leave(h, 'p');
73
+ assert.deepEqual(ends(), [[11, 1000, 1], [17, 1000, 1]], 'an early expiry reports the drop');
74
+ rows.length = 0; A.arrive(h, [{ playerId: 'p', userId: '44' }]);
75
+ at(111000, true); h.sim.players.set('p', {}); at(291000, true); at(292000, true); A.leave(h, 'p');
76
+ assert.deepEqual(ends(), [[11, 2000, 0], [17, 2000, 0]], 'a body replaced between ticks was away in between');
77
+ h.session.players = []; A.observe(h);
78
+ assert.equal(ends().length, 2, 'a forgotten visit is not observed');
79
+ } finally { Date.now = realNow; }
80
+ }
43
81
  console.log('hub analytics opt-in, privacy, lifecycle and engagement spans: passed');
44
82
 
45
83
  const casts = [], fisher = { now: 0, track: (id, event) => casts.push(event) };
@@ -62,15 +100,71 @@ assert(readManifest(castle({ fpsTelemetry: fpsConfig })).errors.some((e) => e.in
62
100
  const h = { firstVisit: { live: ['home', 'door'] }, place: { analytics: true }, manifest: {}, sim: { timeMs: 0 },
63
101
  players: new Map([['p', { arrived: true }]]), analytics: A.create(),
64
102
  session: { hub: { track: (id, event) => { events.push(event); return true; } } } };
65
- A.arrive(h, [{ playerId: 'p', userId: '42' }]);
103
+ A.arrive(h, [{ playerId: 'p', userId: '42', device }]);
66
104
  assert.equal(events.length, 0, 'arrival waits for storage assignment');
105
+ assert.equal(h.analytics.visits.get('p').arrival.value, device, 'deferred arrival retains device');
67
106
  assert.equal(A.firstVisitArrived(h, 'p', 4), false);
68
107
  assert.equal(A.firstVisitArrived(h, 'p', 2), true);
69
108
  assert.equal(A.firstVisitArrived(h, 'p', 1), false, 'arrival emits once');
70
- assert.deepEqual(events, [{ kind: 1, subject: 0, value: 0, result: 1, flags: 2 }]);
109
+ assert.deepEqual(events, [{ kind: 1, subject: 0, value: device, result: 1, flags: 2 }]);
71
110
  A.arrive(h, [{ playerId: 'p', userId: '42', from: 'game' }]);
72
111
  A.firstVisitArrived(h, 'p', 2);
73
112
  assert.equal(events.at(-1).flags, 2, 'door return carries sticky variant');
113
+ assert.equal(events.at(-1).value, 0, 'deferred old-client arrival stays unknown');
74
114
  A.leave(h, 'p'); A.arrive(h, [{ playerId: 'p', userId: '42' }]);
75
115
  assert.equal(events.at(-1).kind, 10, 'short reconnect stays reconnect');
76
116
  }
117
+
118
+ // Real hello -> player entry -> arrival group -> analytics, including old clients.
119
+ const sceneStub = 'export const readScene = () => [{ id: "spawn", components: { Player: {}, Transform: { x: 0, y: 1, z: 0 } } }];';
120
+ register(`data:text/javascript,${encodeURIComponent(`
121
+ export async function resolve(specifier, context, next) {
122
+ if (specifier === '@imports/castle.multiplayer-3d/code/server/sceneBodies.js') {
123
+ return { url: 'data:text/javascript,${encodeURIComponent(sceneStub)}', shortCircuit: true };
124
+ }
125
+ return next(specifier, context);
126
+ }
127
+ `)}`);
128
+ const { layer } = await import('../code/server/hub.js');
129
+ async function helloArrival(hellos) {
130
+ const events = [], groups = [], sent = [];
131
+ const session = { sessionId: 's-device', players: [{ playerId: 'p', userId: '101', username: 'Ada', isAnonymous: false }],
132
+ send: (id, message) => sent.push(message), broadcast() {},
133
+ hub: { place: 'main', title: 'Town', result: null, arrival: () => null,
134
+ async readResults() { return { players: {}, boards: {} }; },
135
+ track: (id, event) => { events.push(event); return true; } } };
136
+ const server = layer({ server: { maxPlayers: 8 }, hub: { contract: 1, title: 'Town', analytics: true } },
137
+ { arrive: (_hub, group) => groups.push(group) }, {}, () => true, () => null);
138
+ server.sceneFor(session);
139
+ const sim = { timeMs: 0, scenePath: 'scenes/main.scene', bodies: new Map(),
140
+ players: new Map([['p', { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } }]]) };
141
+ server.ready(sim);
142
+ const hello = (extra) => server.message(session, { playerId: 'p' }, { k: 'hub-hello', avatar: 1, party: 1, ...extra });
143
+ for (const extra of hellos) {hello(extra);}
144
+ for (let i = 0; i < 5; i++) {server.place(sim); await new Promise((resolve) => setImmediate(resolve));}
145
+ assert(sent.some((message) => message.k === 'hub-arrived'), 'hello still arrives');
146
+ assert.equal(groups.length, 1, 'repeated hello arrives once');
147
+ assert.equal(events.length, 1);
148
+ assert.equal(events[0].kind, A.EVENTS.arrive);
149
+ assert.equal(groups[0][0].device, events[0].value, 'arrival group carries the validated entry value');
150
+ hello({ device: device + 1 });
151
+ server.place(sim);
152
+ assert.equal(events.length, 1, 'later hello does not duplicate arrival analytics');
153
+ return events[0].value;
154
+ }
155
+ assert.equal(await helloArrival([{ device }]), device);
156
+ for (const invalid of [undefined, null, 0, -1, 0.5, NaN, Infinity, 2 ** 29, Number.MAX_SAFE_INTEGER, String(device), {}, true]) {
157
+ assert.equal(await helloArrival([invalid === undefined ? {} : { device: invalid }]), 0, 'missing/invalid device arrives as unknown');
158
+ }
159
+ assert.equal(await helloArrival([{}, { device: -1 }, { device }]), device, 'later valid hello corrects unknown');
160
+ assert.equal(await helloArrival([{ device }, {}, { device: -1 }, { device: 2 ** 29 }]), device, 'missing/invalid hello preserves known class');
161
+ assert.equal(await helloArrival([{ device }, { device: device + 1 }]), device + 1, 'later valid hello can correct known class');
162
+ for (const boundary of [1, 2 ** 29 - 1]) {
163
+ assert.equal(await helloArrival([{ device: boundary }]), boundary, 'server accepts the specified positive wire range');
164
+ }
165
+
166
+ const doorEvents = [];
167
+ DoorAnalytics.arrive({ place: { result: {} }, players: new Map([['p', { arrived: true }]]), sim: { timeMs: 0 },
168
+ session: { hub: { track: (id, event) => { doorEvents.push(event); return true; } } } }, [{ playerId: 'p', device }]);
169
+ assert.deepEqual(doorEvents, [{ kind: DoorAnalytics.EVENTS.round_start, value: 1, result: 0 }], 'door round value remains group size');
170
+ console.log('arrival device values, deferred first visits, hello validation and old clients: passed');