castle-web-cli 0.4.236 → 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 (218) hide show
  1. package/dist/api.d.ts +2 -0
  2. package/dist/bundle.d.ts +24 -0
  3. package/dist/bundle.js +447 -4
  4. package/dist/bundleLatin1.d.ts +6 -0
  5. package/dist/bundleLatin1.js +333 -0
  6. package/dist/castle-host/host.d.ts +10 -1
  7. package/dist/castle-host/host.js +78 -9
  8. package/dist/castleJson.d.ts +20 -0
  9. package/dist/castleJson.js +40 -0
  10. package/dist/deckExports.d.ts +35 -0
  11. package/dist/deckExports.js +365 -0
  12. package/dist/importCheckHook.d.ts +1 -0
  13. package/dist/importCheckHook.js +1 -1
  14. package/dist/index.js +5 -0
  15. package/dist/init.js +2 -1
  16. package/dist/save-deck.js +18 -13
  17. package/kits/base/castle.json +1 -1
  18. package/kits/base/sdk/README.md +47 -0
  19. package/kits/base/sdk/castle.d.ts +3 -1
  20. package/kits/base/sdk/castle.js +1 -0
  21. package/kits/base/sdk/commands.d.ts +25 -1
  22. package/kits/base/sdk/commands.js +29 -1
  23. package/kits/base/sdk/hub.d.ts +17 -0
  24. package/kits/base/sdk/hub.js +33 -9
  25. package/kits/base/sdk/localCache.d.ts +27 -0
  26. package/kits/base/sdk/localCache.js +115 -0
  27. package/kits/base/sdk/localCacheStore.d.ts +15 -0
  28. package/kits/base/sdk/localCacheStore.js +358 -0
  29. package/kits/base/sdk/transport.d.ts +1 -0
  30. package/kits/base/sdk/transport.js +4 -5
  31. package/kits/hub-game/CLAUDE.md +22 -2
  32. package/kits/hub-game/castle.json +4 -1
  33. package/kits/hub-game/code/client/act.js +66 -91
  34. package/kits/hub-game/code/client/actCore.js +134 -0
  35. package/kits/hub-game/code/client/car.js +35 -0
  36. package/kits/hub-game/code/client/chrome.js +207 -381
  37. package/kits/hub-game/code/client/crowdNames.js +2 -2
  38. package/kits/hub-game/code/client/emoteWheel.js +109 -0
  39. package/kits/hub-game/code/client/hats.js +2 -0
  40. package/kits/hub-game/code/client/hookLayer.js +99 -48
  41. package/kits/hub-game/code/client/hostGo.js +77 -0
  42. package/kits/hub-game/code/client/hubControls.js +125 -0
  43. package/kits/hub-game/code/client/hubEntry.js +187 -0
  44. package/kits/hub-game/code/client/hudSurface.js +148 -0
  45. package/kits/hub-game/code/client/hudTree.js +96 -0
  46. package/kits/hub-game/code/client/idle.js +59 -13
  47. package/kits/hub-game/code/client/invites.js +13 -4
  48. package/kits/hub-game/code/client/menuIcons.js +8 -0
  49. package/kits/hub-game/code/client/noTrips.js +38 -0
  50. package/kits/hub-game/code/client/qualityEntry.js +6 -1
  51. package/kits/hub-game/code/client/rehello.js +3 -1
  52. package/kits/hub-game/code/client/riders.js +26 -0
  53. package/kits/hub-game/code/client/role.js +79 -0
  54. package/kits/hub-game/code/client/safeLayout.js +32 -3
  55. package/kits/hub-game/code/client/sound.js +10 -3
  56. package/kits/hub-game/code/client/soundscape.js +2 -2
  57. package/kits/hub-game/code/client/soundscapeAmbience.js +38 -8
  58. package/kits/hub-game/code/client/soundscapeBaked.js +24 -5
  59. package/kits/hub-game/code/client/soundscapeCues.js +2 -1
  60. package/kits/hub-game/code/client/state.js +19 -0
  61. package/kits/hub-game/code/client/stuck.js +2 -1
  62. package/kits/hub-game/code/client/talkSurface.js +178 -0
  63. package/kits/hub-game/code/client/talkTree.js +238 -0
  64. package/kits/hub-game/code/client/tiers.js +8 -5
  65. package/kits/hub-game/code/client/uiDom.js +600 -0
  66. package/kits/hub-game/code/client/uiTree.js +359 -0
  67. package/kits/hub-game/code/client/vehicle.js +154 -0
  68. package/kits/hub-game/code/client/wear.js +27 -5
  69. package/kits/hub-game/code/client/worldLabels.js +3 -2
  70. package/kits/hub-game/code/client/yours.js +10 -3
  71. package/kits/hub-game/code/server/actors.js +4 -3
  72. package/kits/hub-game/code/server/analytics.js +56 -6
  73. package/kits/hub-game/code/server/decor.js +56 -16
  74. package/kits/hub-game/code/server/hub.js +258 -46
  75. package/kits/hub-game/code/server/idle.js +118 -5
  76. package/kits/hub-game/code/server/manifest.js +46 -4
  77. package/kits/hub-game/code/server/npcs.js +4 -2
  78. package/kits/hub-game/code/server/players.js +3 -0
  79. package/kits/hub-game/code/server/role.js +142 -0
  80. package/kits/hub-game/code/server/standing.js +6 -4
  81. package/kits/hub-game/code/server/vehicle.js +126 -0
  82. package/kits/hub-game/code/shared/car.js +52 -0
  83. package/kits/hub-game/code/shared/deckFlags.js +34 -0
  84. package/kits/hub-game/code/shared/deviceClass.js +39 -0
  85. package/kits/hub-game/code/shared/expression.js +9 -0
  86. package/kits/hub-game/code/systems/hub.js +300 -85
  87. package/kits/hub-game/docs/analytics.md +11 -2
  88. package/kits/hub-game/docs/contract.md +353 -14
  89. package/kits/hub-game/docs/vehicle-preset.md +132 -0
  90. package/kits/hub-game/models/hats/baker-cap.pxmodel +89 -0
  91. package/kits/hub-game/models/hats/chef-toque.pxmodel +60 -0
  92. package/kits/hub-game/models/hats/delivery-cap.pxmodel +105 -0
  93. package/kits/hub-game/models/hats/fire-helmet.pxmodel +87 -0
  94. package/kits/hub-game/models/hats/hard-hat.pxmodel +71 -0
  95. package/kits/hub-game/models/hats/nurse-cap.pxmodel +61 -0
  96. package/kits/hub-game/models/hats/police-cap.pxmodel +105 -0
  97. package/kits/hub-game/models/hats/teacher-beret.pxmodel +52 -0
  98. package/kits/hub-game/models/role/square/top-apron.pxmodel +109 -0
  99. package/kits/hub-game/models/role/square/top-cardigan.pxmodel +141 -0
  100. package/kits/hub-game/models/role/square/top-coat.pxmodel +157 -0
  101. package/kits/hub-game/models/role/square/top-scrubs.pxmodel +93 -0
  102. package/kits/hub-game/models/role/square/top-tabard.pxmodel +109 -0
  103. package/kits/hub-game/models/role/square/top-vest.pxmodel +109 -0
  104. package/kits/hub-game/models/role/tool-bag.pxmodel +75 -0
  105. package/kits/hub-game/models/role/tool-bell.pxmodel +71 -0
  106. package/kits/hub-game/models/role/tool-hose.pxmodel +60 -0
  107. package/kits/hub-game/models/role/tool-parcel.pxmodel +61 -0
  108. package/kits/hub-game/models/role/tool-torch.pxmodel +55 -0
  109. package/kits/hub-game/models/role/tool-tray.pxmodel +75 -0
  110. package/kits/hub-game/models/role/top-apron.pxmodel +70 -0
  111. package/kits/hub-game/models/role/top-cardigan.pxmodel +102 -0
  112. package/kits/hub-game/models/role/top-coat.pxmodel +79 -0
  113. package/kits/hub-game/models/role/top-scrubs.pxmodel +54 -0
  114. package/kits/hub-game/models/role/top-tabard.pxmodel +70 -0
  115. package/kits/hub-game/models/role/top-vest.pxmodel +70 -0
  116. package/kits/hub-game/package-lock.json +1 -1
  117. package/kits/hub-game/package.json +1 -1
  118. package/kits/hub-game/scripts/check.mjs +7 -4
  119. package/kits/hub-game/scripts/fixtures/car-vectors.json +279 -0
  120. package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +2 -1
  121. package/kits/hub-game/scripts/fixtures/hud-surface.json +670 -0
  122. package/kits/hub-game/scripts/fixtures/talk-surface.json +3930 -0
  123. package/kits/hub-game/scripts/gen-hats.mjs +46 -2
  124. package/kits/hub-game/scripts/gen-role.mjs +80 -0
  125. package/kits/hub-game/scripts/test-act-core.mjs +167 -0
  126. package/kits/hub-game/scripts/test-actions-client.mjs +34 -0
  127. package/kits/hub-game/scripts/test-actors.mjs +48 -0
  128. package/kits/hub-game/scripts/test-analytics.mjs +99 -5
  129. package/kits/hub-game/scripts/test-apply-deck.mjs +122 -0
  130. package/kits/hub-game/scripts/test-back-visibility.mjs +3 -1
  131. package/kits/hub-game/scripts/test-ballot.mjs +2 -0
  132. package/kits/hub-game/scripts/test-car.mjs +43 -0
  133. package/kits/hub-game/scripts/test-decor-client.mjs +2 -1
  134. package/kits/hub-game/scripts/test-decor.mjs +77 -0
  135. package/kits/hub-game/scripts/test-device-class.mjs +83 -0
  136. package/kits/hub-game/scripts/test-emote-wheel.mjs +374 -0
  137. package/kits/hub-game/scripts/test-hats.mjs +5 -4
  138. package/kits/hub-game/scripts/test-host-go.mjs +265 -0
  139. package/kits/hub-game/scripts/test-hub-controls.mjs +108 -0
  140. package/kits/hub-game/scripts/test-hub-entry.mjs +531 -0
  141. package/kits/hub-game/scripts/test-hub-ops.mjs +75 -0
  142. package/kits/hub-game/scripts/test-hub-trip.mjs +85 -0
  143. package/kits/hub-game/scripts/test-hud-clear.mjs +12 -2
  144. package/kits/hub-game/scripts/test-hud-rate.mjs +6 -2
  145. package/kits/hub-game/scripts/test-hud-surface.mjs +272 -0
  146. package/kits/hub-game/scripts/test-idle.mjs +347 -1
  147. package/kits/hub-game/scripts/test-interest-cells.mjs +8 -1
  148. package/kits/hub-game/scripts/test-invites-client.mjs +42 -1
  149. package/kits/hub-game/scripts/test-manifest.mjs +30 -0
  150. package/kits/hub-game/scripts/test-no-trips.mjs +42 -0
  151. package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
  152. package/kits/hub-game/scripts/test-quality.mjs +13 -0
  153. package/kits/hub-game/scripts/test-rehello.mjs +258 -3
  154. package/kits/hub-game/scripts/test-resume-pose-server.mjs +203 -0
  155. package/kits/hub-game/scripts/test-resync.mjs +183 -0
  156. package/kits/hub-game/scripts/test-role-client.mjs +421 -0
  157. package/kits/hub-game/scripts/test-role.mjs +350 -0
  158. package/kits/hub-game/scripts/test-safe-layout.mjs +50 -1
  159. package/kits/hub-game/scripts/test-soundscape.mjs +124 -7
  160. package/kits/hub-game/scripts/test-standing.mjs +15 -1
  161. package/kits/hub-game/scripts/test-talk-surface.mjs +296 -0
  162. package/kits/hub-game/scripts/test-tiers.mjs +13 -0
  163. package/kits/hub-game/scripts/test-ui-dom-dom.mjs +96 -0
  164. package/kits/hub-game/scripts/test-ui-tree.mjs +711 -0
  165. package/kits/hub-game/scripts/test-vehicle-client.mjs +159 -0
  166. package/kits/hub-game/scripts/test-vehicle.mjs +135 -0
  167. package/kits/hub-game/scripts/test-yours.mjs +33 -0
  168. package/kits/hub-game/tools/hubScene/export.mjs +613 -0
  169. package/kits/hub-game/tools/hubScene/hubdata.mjs +921 -0
  170. package/kits/hub-game/tools/hubScene/merge-root.mjs +39 -0
  171. package/kits/hub-game/tools/hubScene/nodeworld.mjs +227 -0
  172. package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +798 -0
  173. package/kits/hub-game/tools/hubScene/test/fixture.json +637 -0
  174. package/kits/hub-game/tools/hubScene/test/paint-export.mjs +40 -0
  175. package/kits/hub-game/tools/hubScene/test/upload.test.mjs +655 -0
  176. package/kits/hub-game/tools/hubScene/upload.mjs +636 -0
  177. package/kits/hub-game/tools/hubScene/validate-manifest.mjs +291 -0
  178. package/kits/multiplayer-3d/castle.json +4 -4
  179. package/kits/multiplayer-3d/code/client/resumeGate.js +30 -2
  180. package/kits/multiplayer-3d/code/client/steer.js +3 -1
  181. package/kits/multiplayer-3d/code/systems/multiplayer.js +30 -2
  182. package/kits/multiplayer-3d/package-lock.json +1 -1
  183. package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +74 -2
  184. package/kits/physics-3d/CLAUDE.md +1 -1
  185. package/kits/physics-3d/behaviors/Player.jsx +37 -27
  186. package/kits/physics-3d/castle.json +2 -2
  187. package/kits/physics-3d/docs/engine-geometry-memory.md +23 -0
  188. package/kits/physics-3d/engine3d/memoryprofile.js +17 -0
  189. package/kits/physics-3d/engine3d/playerRun.js +6 -1
  190. package/kits/physics-3d/engine3d/pxmodel.js +6 -1
  191. package/kits/physics-3d/engine3d/world3d.js +6 -3
  192. package/kits/physics-3d/package.json +1 -1
  193. package/kits/physics-3d/play/behaviors/Player.js +40 -28
  194. package/kits/physics-3d/scripts/test-memory-profile.mjs +237 -0
  195. package/kits/physics-3d/systems/physics3d.js +5 -2
  196. package/kits/real-time/castle.json +2 -2
  197. package/kits/real-time/code/client/messages.js +5 -0
  198. package/kits/real-time/code/server/session.js +28 -1
  199. package/kits/real-time/package-lock.json +1 -1
  200. package/package.json +5 -4
  201. package/vendor/three/LICENSE +21 -0
  202. package/vendor/three/build/three.core.js +58773 -0
  203. package/vendor/three/build/three.module.js +18251 -0
  204. package/vendor/three/examples/jsm/controls/OrbitControls.js +1860 -0
  205. package/vendor/three/examples/jsm/controls/TransformControls.js +1918 -0
  206. package/vendor/three/examples/jsm/exporters/GLTFExporter.js +3595 -0
  207. package/vendor/three/examples/jsm/geometries/RoundedBoxGeometry.js +216 -0
  208. package/vendor/three/examples/jsm/math/MeshSurfaceSampler.js +315 -0
  209. package/vendor/three/examples/jsm/postprocessing/EffectComposer.js +363 -0
  210. package/vendor/three/examples/jsm/postprocessing/MaskPass.js +195 -0
  211. package/vendor/three/examples/jsm/postprocessing/OutputPass.js +139 -0
  212. package/vendor/three/examples/jsm/postprocessing/Pass.js +191 -0
  213. package/vendor/three/examples/jsm/postprocessing/RenderPass.js +183 -0
  214. package/vendor/three/examples/jsm/postprocessing/ShaderPass.js +135 -0
  215. package/vendor/three/examples/jsm/shaders/CopyShader.js +52 -0
  216. package/vendor/three/examples/jsm/shaders/OutputShader.js +103 -0
  217. package/vendor/three/examples/jsm/utils/BufferGeometryUtils.js +1435 -0
  218. package/vendor/three/package.json +134 -0
@@ -1108,6 +1108,81 @@ await test('a door that stayed shut is not fired again for that player until the
1108
1108
  assert.deepEqual(fires().at(-1)[1].memberUserIds, ['101']);
1109
1109
  });
1110
1110
 
1111
+ await test('a player whose app has no door trips is left out of pads and go, and alone told so', async () => {
1112
+ const p = platformHub();
1113
+ const s = session({ hub: p.hub });
1114
+ const { h, world, ctx } = boot(s);
1115
+ const hub = ctx();
1116
+ const gathered = () => p.calls.filter((c) => c[0] === 'pad').map((c) => c[1]);
1117
+ const fires = () => gathered().filter((c) => c.fire);
1118
+ const labelsOf = (id) => s.sent.filter(([to, d]) => to === id && d.k === 'hub-labels').at(-1)?.[1].labels;
1119
+ // Only a connected player's own word counts, and only for themselves.
1120
+ h.message(s.session, { playerId: 'ghost' }, { k: 'hub-no-trips' });
1121
+ assert.equal(hub.noTrips('ghost'), false);
1122
+ assert.equal(hub.noTrips('p1'), false);
1123
+ h.message(s.session, { playerId: 'p1' }, { k: 'hub-no-trips' });
1124
+ assert.equal(hub.noTrips('p1'), true);
1125
+ assert.equal(hub.noTrips('p2'), false);
1126
+ // p1 stands on the pad with p2: ghost gathers p2 alone.
1127
+ hub.pad('race', ['p1', 'p2']);
1128
+ await flush();
1129
+ assert.deepEqual(gathered().at(-1).memberUserIds, ['102']);
1130
+ h.step(world);
1131
+ assert.equal(labelsOf('p1')?.['race-door']?.text, 'Update Castle to play');
1132
+ assert.equal(labelsOf('p2'), undefined, 'nobody else sees it');
1133
+ // A fire takes p2 through, never p1; p1 alone fires nothing.
1134
+ assert.ok(hub.go('race', ['p1', 'p2']));
1135
+ await flush();
1136
+ assert.deepEqual(fires().at(-1).memberUserIds, ['102']);
1137
+ const fired = fires().length;
1138
+ hub.pad('race', ['p1']);
1139
+ assert.equal(hub.go('race', ['p1']), null);
1140
+ await flush();
1141
+ assert.equal(fires().length, fired);
1142
+ // Stepping off clears the label; the mark stays for the visit.
1143
+ hub.pad('race', []);
1144
+ h.step(world);
1145
+ assert.equal(labelsOf('p1')['race-door'], undefined);
1146
+ assert.equal(hub.noTrips('p1'), true);
1147
+ hub.pad('race', ['p1']);
1148
+ h.step(world);
1149
+ assert.equal(labelsOf('p1')?.['race-door']?.text, 'Update Castle to play');
1150
+ });
1151
+
1152
+ await test('a mark that arrives while a fire is pending keeps that player from going', async () => {
1153
+ const p = platformHub();
1154
+ let answer = null;
1155
+ p.hub.updatePad = (input) => {
1156
+ p.calls.push(['pad', input]);
1157
+ return input.fire ? new Promise((resolve) => { answer = () => resolve({ status: 'fired', members: [...input.memberUserIds] }); }) : Promise.resolve({ status: 'gathering', members: [] });
1158
+ };
1159
+ const s = session({ hub: p.hub });
1160
+ const { h, ctx } = boot(s);
1161
+ const hub = ctx();
1162
+ hub.pad('race', ['p1', 'p2']);
1163
+ assert.ok(hub.go('race', ['p1', 'p2']));
1164
+ h.message(s.session, { playerId: 'p1' }, { k: 'hub-no-trips' });
1165
+ answer();
1166
+ await flush();
1167
+ const goes = s.sent.filter(([, d]) => d.k === 'hub-go').map(([id]) => id);
1168
+ assert.deepEqual(goes, ['p2']);
1169
+ });
1170
+
1171
+ await test('players whose app has door trips gather and go exactly as before', async () => {
1172
+ const p = platformHub();
1173
+ const s = session({ hub: p.hub });
1174
+ const { h, world, ctx } = boot(s);
1175
+ const hub = ctx();
1176
+ hub.pad('race', ['p1', 'p2']);
1177
+ await flush();
1178
+ h.step(world);
1179
+ assert.deepEqual(p.calls.filter((c) => c[0] === 'pad').at(-1)[1].memberUserIds, ['101', '102']);
1180
+ assert.ok(hub.go('race', ['p1', 'p2']));
1181
+ await flush();
1182
+ assert.deepEqual(p.calls.filter((c) => c[0] === 'pad' && c[1].fire).at(-1)[1].memberUserIds, ['101', '102']);
1183
+ assert.ok(!s.sent.some(([, d]) => d.k === 'hub-labels'), 'no pad label is sent');
1184
+ });
1185
+
1111
1186
  await test('a door that stays shut after the player already stepped off holds nothing', async () => {
1112
1187
  const p = platformHub();
1113
1188
  const s = session({ hub: p.hub });
@@ -514,6 +514,91 @@ await test('an acquisition that lands after the trip gave up is given back', asy
514
514
  }
515
515
  });
516
516
 
517
+ // v1.154: ghost's roster lags an arrival by up to 15 s, and the SDK asks a door
518
+ // again through its `forbidden` for 16 s after the arrival. The kit's limit
519
+ // counts from the end of that window, not from the trip's start.
520
+ async function rosterTrip({ arrivedAt, placed = true, startedAt = 1000 }) {
521
+ const { system, scene } = setup();
522
+ let release;
523
+ const go = globalThis.__tripHub.go;
524
+ globalThis.__tripHub.go = (doorId) => {
525
+ calls.push(['go', doorId]);
526
+ return new Promise((resolve) => (release = resolve));
527
+ };
528
+ try {
529
+ system.arrivedAt = arrivedAt;
530
+ system.placedLast = placed;
531
+ system.goHub(scene, { door: 'race', key: null, title: 'Foot Race' });
532
+ await flush();
533
+ } finally {
534
+ globalThis.__tripHub.go = go;
535
+ }
536
+ system.trip.startedAt = startedAt;
537
+ return { system, scene, trip: system.trip, release: (v) => release(v) };
538
+ }
539
+
540
+ await test('v1.154: a door used 1 s after arriving, forbidden for 14 s and then ok, goes through', async () => {
541
+ const { system, scene, trip, release } = await rosterTrip({ arrivedAt: 0 });
542
+ // 15.5 s after the trip began: the old limit's "it took too long".
543
+ assert.equal(system.contentReady(scene, trip, 16_500), false);
544
+ assert.equal(trip.shut, undefined);
545
+ // The SDK's retry gets its ok (14 s of `forbidden`), and the pack loads.
546
+ release(handoff());
547
+ await flush();
548
+ assert.equal(system.contentReady(scene, trip, 17_000), true);
549
+ assert.equal(trip.shut, undefined);
550
+ assert.deepEqual(calls, [['go', 'race'], ['loadPack', 'abc', 'https://cdn/abc.json']]);
551
+ });
552
+
553
+ await test('v1.154: a door that never answers after an arrival still shuts, by 31 s', async () => {
554
+ const { system, scene, trip, release } = await rosterTrip({ arrivedAt: 0 });
555
+ // Asked at 1 s: the window ends at 16 s, the limit 15 s after that.
556
+ assert.equal(system.contentReady(scene, trip, 30_999), false);
557
+ assert.equal(trip.shut, undefined);
558
+ assert.equal(system.contentReady(scene, trip, 31_001), false);
559
+ assert.equal(trip.shut, 'it took too long');
560
+ release(handoff());
561
+ await flush();
562
+ await flush();
563
+ assert.deepEqual(calls.at(-1), ['cancel']);
564
+ });
565
+
566
+ await test('v1.154: a player not placed (reconnecting) gets the window, capped at 16 s', async () => {
567
+ const { system, scene, trip } = await rosterTrip({ arrivedAt: 0, placed: false });
568
+ assert.equal(system.contentReady(scene, trip, 1000 + 30_999), false);
569
+ assert.equal(trip.shut, undefined);
570
+ assert.equal(system.contentReady(scene, trip, 1000 + 31_001), false);
571
+ assert.equal(trip.shut, 'it took too long');
572
+ });
573
+
574
+ await test('v1.154: a door used long after the arrival keeps the 15 s limit', async () => {
575
+ const { system, scene, trip } = await rosterTrip({ arrivedAt: -60_000 });
576
+ assert.equal(system.contentReady(scene, trip, 1000 + 14_999), false);
577
+ assert.equal(trip.shut, undefined);
578
+ assert.equal(system.contentReady(scene, trip, 1000 + 15_001), false);
579
+ assert.equal(trip.shut, 'it took too long');
580
+ });
581
+
582
+ await test('v1.154: an arrival is placed() rising; unplaced reads as arriving now', async () => {
583
+ const { system } = setup();
584
+ let placed = false;
585
+ const mp = { placed: () => placed };
586
+ system.noteArrival(mp, 0);
587
+ assert.equal(system.arrivedAt, undefined);
588
+ placed = true;
589
+ system.noteArrival(mp, 500);
590
+ system.noteArrival(mp, 900);
591
+ assert.equal(system.arrivedAt, 500);
592
+ assert.equal(system.contentDeadline({ target: {}, startedAt: 2000 }, 2000), 2000 + 15_000 + 14_500);
593
+ placed = false;
594
+ system.noteArrival(mp, 40_000);
595
+ assert.equal(system.contentDeadline({ target: {}, startedAt: 40_000 }, 40_000), 40_000 + 15_000 + 16_000);
596
+ // A runtime without placed() never extends the limit.
597
+ const bare = setup().system;
598
+ bare.noteArrival({}, 0);
599
+ assert.equal(bare.contentDeadline({ target: {}, startedAt: 0 }, 0), 15_000);
600
+ });
601
+
517
602
  await test('the way back from a hub trip is Hub.back', async () => {
518
603
  const { system, scene } = setup();
519
604
  const ticket = { hub: true, scene: 'scenes/main.scene', content: null, join: { mode: 'public' }, door: 'race', title: 'Town' };
@@ -739,9 +739,19 @@ test('asked, then not, with no HUD drawn: put back at once, and written to as ne
739
739
  assert.deepEqual(styleOf(after.hudBig), TODAY.big);
740
740
  assert.deepEqual(styleOf(after.hudText), { ...TODAY.text, display: 'none' });
741
741
  after.log.length = mark;
742
- // From then on: the same writes, in the same order, as a client never told.
742
+ // From then on: the same writes, in the same order, as a client never
743
+ // told, less the ones that would write a value already there (the HUD
744
+ // root is drawn by a renderer that skips them, and the client never told
745
+ // still had a HUD up when its later frames began).
743
746
  frames(after, () => undefined, later);
744
- assert.deepEqual(after.log.slice(mark), never.log.slice(neverMark));
747
+ const told = after.log.slice(mark), untold = never.log.slice(neverMark);
748
+ let at = 0;
749
+ for (const line of told) {
750
+ at = untold.indexOf(line, at);
751
+ assert(at >= 0, `an extra write: ${line}`);
752
+ at += 1;
753
+ }
754
+ assert(told.length < untold.length, 'only the writes of values already there are skipped');
745
755
  const strip = (t) => JSON.stringify(t).replace(/"id":"[^"]*",?/g, '');
746
756
  assert.equal(strip(tree(after.root)), strip(tree(never.root)));
747
757
  // Told no again and again: nothing more is written for it.
@@ -15,6 +15,10 @@ import { makeSay, REACTIONS } from '../code/client/say.js';
15
15
  import { chatModerationEnabled } from '../code/client/chatModeration.js';
16
16
  import { joinErrorText } from '../code/client/joinError.js';
17
17
  import { padCuesEnabled } from '../code/client/padCues.js';
18
+ import { syncUiTreeTime } from '../code/client/uiTree.js';
19
+ import { hudInputs } from '../code/client/hudSurface.js';
20
+ import { backControl } from '../code/client/hubControls.js';
21
+ import { roleItems } from '../code/client/role.js';
18
22
 
19
23
  const inputEvents = ['pointerdown', 'pointerup', 'touchstart', 'touchend', 'keydown', 'keyup'];
20
24
  function inputTarget() {
@@ -79,8 +83,8 @@ const dependencies = { Hub, makeHudRate, askPadsAt, attend, goalAt, worldLabelFo
79
83
  bodyBox, goalPointers, goalText, pointerAt, REACTIONS, chatModerationEnabled, joinErrorText, padCuesEnabled,
80
84
  Avatar: { current: scene => scene.persistent.avatar, colorsAvailable: () => false, style: () => 'toon',
81
85
  currentColor: () => 0, top: () => 1.5, drawn: () => 0 },
82
- Cabinets: { nearest: () => null }, kitBackNeeded: () => false,
83
- loadingCover: null, clearShot() {},
86
+ Cabinets: { nearest: () => null }, kitBackNeeded: () => false, backControl,
87
+ loadingCover: null, clearShot() {}, syncUiTreeTime, hudInputs, roleItems,
84
88
  };
85
89
  const Harness = new Function(...Object.keys(dependencies), `${constants}\n${project}
86
90
  return class { ${['drawChrome', 'drawPanelControls', 'drawNearPrompt', 'dispose'].map(method).join('\n')} };`
@@ -0,0 +1,272 @@
1
+ // The HUD surface (`code/client/hudSurface.js`): the HUD root's state and
2
+ // builder, with no DOM, for the web chrome and a native host alike. Each
3
+ // scripted sequence below is played through the web chrome on the stand-in
4
+ // DOM and recorded: every `hud` root the sink is sent (its bytes, rev and sim
5
+ // time), every time sync, every event handled, and a digest of every DOM
6
+ // write. The recording in `fixtures/hud-surface.json` was made from the
7
+ // chrome as it was before the HUD state moved out of it; the chrome must
8
+ // still produce it byte for byte, and the surface alone (no DOM at all) must
9
+ // send the host the same roots. `RECORD=1` writes the recording anew.
10
+ import assert from 'node:assert/strict';
11
+ import { createHash } from 'node:crypto';
12
+ import { readFileSync, writeFileSync } from 'node:fs';
13
+ import { fakeDom } from './fixtures/fake-dom.mjs';
14
+ import { dispatchUiEvent, resetUiTrees, setUiTreeSink, setUiTreeTime, syncUiTreeTime } from '../code/client/uiTree.js';
15
+
16
+ const RECORD = process.env.RECORD === '1';
17
+ const FIXTURE = new URL('./fixtures/hud-surface.json', import.meta.url);
18
+
19
+ // The timer the hub system gives `setHud` (systems/hub.js before `hudInputs`).
20
+ const timerOf = (spec, sim) => {
21
+ if (spec?.timer?.since !== undefined) {return Math.max(0, (sim - spec.timer.since) / 1000);}
22
+ if (spec?.timer?.until !== undefined) {return Math.max(0, (spec.timer.until - sim) / 1000);}
23
+ return null;
24
+ };
25
+
26
+ // A recorder: a sink and a time sync that note what the host is told, and a
27
+ // page monotonic clock (`mono`, ms) plus a server offset: sim time is their sum.
28
+ function makeRig() {
29
+ const rig = {
30
+ mono: 1_000,
31
+ offset: 1_700_000_000_000,
32
+ get sim() {return this.mono + this.offset;},
33
+ record: [],
34
+ };
35
+ rig.sink = (name, wire, handlers, info) => {
36
+ if (name === 'hud') {rig.record.push(['root', info.json, info.rev, info.simNow, [...handlers.keys()]]);}
37
+ };
38
+ rig.onTime = (simNow) => rig.record.push(['time', simNow]);
39
+ rig.attach = () => setUiTreeSink(rig.sink, { onTime: rig.onTime });
40
+ rig.advance = (ms) => {rig.mono += ms;};
41
+ rig.correct = (ms) => {rig.offset += ms;};
42
+ rig.event = (id, payload) => rig.record.push(['event', id, dispatchUiEvent('hud', id, payload)]);
43
+ return rig;
44
+ }
45
+
46
+ const pairOn = (rig) => ({
47
+ press: () => rig.record.push(['handler', 'press']),
48
+ release: () => rig.record.push(['handler', 'release']),
49
+ cancel: () => rig.record.push(['handler', 'cancel']),
50
+ jump: () => rig.record.push(['handler', 'jump']),
51
+ });
52
+
53
+ // The scripted sequences. `api` is the HUD API under test plus
54
+ // `blockPrompt(on)` (the chrome: a talk panel with questions over the
55
+ // prompt) and `frame(spec)` (one hub frame: setHud at the sim time, then the
56
+ // time sync).
57
+ const SEQUENCES = {
58
+ portrait: { view: { viewW: 390, viewH: 844 }, play(api, rig) {
59
+ rig.attach();
60
+ api.showBack(true, 'Town');
61
+ for (let i = 0; i < 3; i++) {api.frame({ title: 'Fishing', text: 'Cast. Then reel.' });}
62
+ rig.event('hud/back#tap');
63
+ api.setToast('Bo is here');
64
+ api.setToast('Bo is here');
65
+ api.setToast('');
66
+ api.setToast('A long line about the visit that has to wrap over two lines', { wrap: true });
67
+ api.setToast(null);
68
+ api.showBack(false);
69
+ api.showBack(true);
70
+ api.setActPair({ show: true, enabled: false, on: pairOn(rig) });
71
+ api.setActPair({ show: true, enabled: true, on: pairOn(rig) });
72
+ rig.event('hud/actpair/act#press', { pointerId: 1 });
73
+ rig.event('hud/actpair/act#release', { pointerId: 1 });
74
+ rig.event('hud/actpair/jump#tap');
75
+ api.setActPair({ show: false, enabled: true, on: pairOn(rig) });
76
+ api.setActPair(null);
77
+ rig.event('hud/actpair/jump#tap');
78
+ api.frame({ title: 'Garden', text: 'Water the beds. Then rest.' });
79
+ api.blockPrompt(true);
80
+ api.frame({ title: 'Garden', text: 'Water the beds. Then rest.' });
81
+ api.blockPrompt(false);
82
+ api.frame(null);
83
+ api.frame({ title: 'Score', big: '3 fish' });
84
+ api.frame({ big: 7 });
85
+ api.frame({ title: '', text: '' });
86
+ api.frame(null);
87
+ } },
88
+ timer: { view: { viewW: 390, viewH: 844 }, play(api, rig) {
89
+ rig.attach();
90
+ const until = rig.sim + 30_000;
91
+ const race = { title: 'Race', text: 'Run. Fast.', timer: { until } };
92
+ api.frame(race);
93
+ for (let i = 0; i < 40; i++) {rig.advance(100); api.frame(race);}
94
+ // Jitter, then a server correction of 180 ms.
95
+ rig.correct(20); api.frame(race);
96
+ rig.correct(-20); api.frame(race);
97
+ rig.correct(180); api.frame(race);
98
+ api.setToast('Bo is here');
99
+ rig.advance(1_000); api.frame(race);
100
+ // Restarted at the value it started at.
101
+ const again = { ...race, timer: { until: rig.sim + 30_000 } };
102
+ api.frame(again);
103
+ rig.advance(500); api.frame(again);
104
+ // A since timer, then big over a timer, then no timer.
105
+ const since = { title: 'Fishing', timer: { since: rig.sim - 2_000 } };
106
+ api.frame(since);
107
+ rig.advance(250); api.frame(since);
108
+ api.frame({ title: 'Fishing', big: '3 fish', timer: { until } });
109
+ api.frame({ title: 'Fishing', text: 'Cast. Then reel.' });
110
+ // A timer with no sim time to read it at: words, not a clock.
111
+ api.setHud(race, 12.34, undefined);
112
+ api.setHud(race, 12.34, Number.NaN);
113
+ api.frame(race);
114
+ // Past the end: never below 0.
115
+ rig.advance(60_000); api.frame(race);
116
+ api.frame(null);
117
+ } },
118
+ landscape: { view: { viewW: 844, viewH: 390 }, play(api, rig) {
119
+ rig.attach();
120
+ api.showBack(true, 'Again');
121
+ api.frame({ title: 'Cove', text: 'Swim to the buoy. Then back.' });
122
+ api.setToast('Ada is here');
123
+ api.setToast('Ada left the cove and went back to the town square', { wrap: true });
124
+ api.setActPair({ show: true, enabled: true, on: pairOn(rig) });
125
+ rig.event('hud/actpair/act#cancel');
126
+ api.frame({ title: 'Cove', big: '2' });
127
+ api.frame(null);
128
+ } },
129
+ safe: { view: { viewW: 390, viewH: 844 }, safeInsets: true, play(api, rig) {
130
+ rig.attach();
131
+ api.showBack(true, 'Town');
132
+ api.setActPair({ show: true, enabled: false, on: pairOn(rig) });
133
+ api.frame({ title: 'Plot', text: 'Plant. Then wait.' });
134
+ api.setToast('Planted');
135
+ rig.event('hud/back#tap');
136
+ } },
137
+ safeLandscape: { view: { viewW: 932, viewH: 430 }, safeInsets: true, play(api, rig) {
138
+ rig.attach();
139
+ api.showBack(true, 'Back');
140
+ api.setActPair({ show: true, enabled: true, on: pairOn(rig) });
141
+ api.frame({ title: 'Runway', timer: { since: rig.sim } });
142
+ rig.advance(1_500); api.frame({ title: 'Runway', timer: { since: rig.sim - 1_500 } });
143
+ } },
144
+ lateSink: { view: { viewW: 390, viewH: 844 }, play(api, rig) {
145
+ const race = { title: 'Race', timer: { until: rig.sim + 30_000 } };
146
+ api.frame(race);
147
+ for (let i = 0; i < 50; i++) {rig.advance(100); api.frame(race);}
148
+ api.setToast('Bo is here');
149
+ rig.advance(1_000); api.frame(race);
150
+ rig.attach();
151
+ rig.advance(1_000); api.frame(race);
152
+ api.setToast('Ada is here');
153
+ api.showBack(true, 'Town');
154
+ } },
155
+ };
156
+
157
+ const digest = (lines) => createHash('sha256').update(lines.join('\n')).digest('hex');
158
+
159
+ // One sequence through the web chrome on the stand-in DOM.
160
+ async function viaChrome(name) {
161
+ const { view, safeInsets = false, play } = SEQUENCES[name];
162
+ resetUiTrees();
163
+ const dom = fakeDom(view);
164
+ globalThis.matchMedia = () => ({ matches: false });
165
+ const realNow = performance.now;
166
+ const rig = makeRig();
167
+ performance.now = () => rig.mono;
168
+ setUiTreeTime(() => rig.sim / 1000);
169
+ const { makeChrome } = await import('../code/client/chrome.js');
170
+ const chrome = makeChrome({ avatarCount: 4, safeInsets, onBack: () => rig.record.push(['handler', 'back']), onAvatar() {} });
171
+ chrome.onTalk({ open() {}, send() {}, end() {} });
172
+ const api = {
173
+ showBack: (...args) => chrome.showBack(...args),
174
+ setHud: (...args) => chrome.setHud(...args),
175
+ setToast: (...args) => chrome.setToast(...args),
176
+ setActPair: (...args) => chrome.setActPair(...args),
177
+ blockPrompt(on) {
178
+ if (on) {
179
+ chrome.openTalk('Mabel', { mind: false });
180
+ chrome.talkAsks(['Where?'], () => {});
181
+ } else {
182
+ chrome.closeTalk();
183
+ }
184
+ },
185
+ frame(spec) {
186
+ chrome.setHud(spec, timerOf(spec, rig.sim), rig.sim);
187
+ syncUiTreeTime();
188
+ },
189
+ };
190
+ try {
191
+ play(api, rig);
192
+ chrome.dispose();
193
+ } finally {
194
+ performance.now = realNow;
195
+ resetUiTrees();
196
+ }
197
+ return { record: rig.record, dom: digest(dom.log), writes: dom.log.length };
198
+ }
199
+
200
+ // The same sequence through the surface alone: no DOM, no window.
201
+ async function viaSurface(name) {
202
+ const { view, safeInsets = false, play } = SEQUENCES[name];
203
+ resetUiTrees();
204
+ delete globalThis.document;
205
+ delete globalThis.window;
206
+ const realNow = performance.now;
207
+ const rig = makeRig();
208
+ performance.now = () => rig.mono;
209
+ setUiTreeTime(() => rig.sim / 1000);
210
+ const { makeHudSurface, hudInputs } = await import('../code/client/hudSurface.js');
211
+ let blocked = false;
212
+ const hud = makeHudSurface({ landscape: view.viewW > view.viewH, safeInsets, onBack: () => rig.record.push(['handler', 'back']), promptBlocked: () => blocked });
213
+ const api = {
214
+ showBack: (...args) => hud.showBack(...args),
215
+ setHud: (...args) => hud.setHud(...args),
216
+ setToast: (...args) => hud.setToast(...args),
217
+ setActPair: (...args) => hud.setActPair(...args),
218
+ blockPrompt(on) {
219
+ blocked = on;
220
+ hud.syncPrompt();
221
+ },
222
+ frame(spec) {
223
+ const inputs = hudInputs({ hud: spec }, rig.sim);
224
+ assert.equal(inputs.spec, spec);
225
+ assert.equal(inputs.timer, timerOf(spec, rig.sim));
226
+ hud.setHud(spec, inputs.timer, rig.sim);
227
+ syncUiTreeTime();
228
+ },
229
+ };
230
+ try {
231
+ play(api, rig);
232
+ hud.dispose();
233
+ } finally {
234
+ performance.now = realNow;
235
+ resetUiTrees();
236
+ }
237
+ return { record: rig.record };
238
+ }
239
+
240
+ let passed = 0;
241
+ if (RECORD) {
242
+ const out = {};
243
+ for (const name of Object.keys(SEQUENCES)) {out[name] = await viaChrome(name);}
244
+ writeFileSync(FIXTURE, `${JSON.stringify(out, null, 1)}\n`);
245
+ console.log(`hud surface: recorded ${Object.keys(out).length} sequences`);
246
+ } else {
247
+ const fixture = JSON.parse(readFileSync(FIXTURE, 'utf8'));
248
+ assert.deepEqual(Object.keys(fixture), Object.keys(SEQUENCES));
249
+ for (const name of Object.keys(SEQUENCES)) {
250
+ const want = fixture[name];
251
+ const chrome = await viaChrome(name);
252
+ assert.deepEqual(chrome.record, want.record, `${name}: the chrome sends the recorded roots`);
253
+ assert.equal(chrome.writes, want.writes, `${name}: the chrome makes the recorded DOM writes`);
254
+ assert.equal(chrome.dom, want.dom, `${name}: the chrome's DOM writes are the recorded bytes`);
255
+ passed += 1;
256
+ const surface = await viaSurface(name);
257
+ assert.deepEqual(surface.record, want.record, `${name}: the surface alone sends the recorded roots`);
258
+ passed += 1;
259
+ }
260
+ // hudInputs: the player's own HUD over the place's; the timer from the
261
+ // sim time, never below 0.
262
+ const { hudInputs } = await import('../code/client/hudSurface.js');
263
+ const place = { title: 'Place' }, mine = { title: 'Mine', timer: { since: 1_000 } };
264
+ assert.deepEqual(hudInputs({ hud: place, hudMe: null }, 5_000), { spec: place, timer: null });
265
+ assert.deepEqual(hudInputs({ hud: place, hudMe: mine }, 5_000), { spec: mine, timer: 4 });
266
+ assert.deepEqual(hudInputs({ hud: { timer: { until: 2_000 } } }, 5_000).timer, 0);
267
+ assert.deepEqual(hudInputs({ hud: { timer: { until: 9_500 } } }, 5_000).timer, 4.5);
268
+ assert.deepEqual(hudInputs({ hud: null, hudMe: undefined }, 5_000), { spec: null, timer: null });
269
+ assert.deepEqual(hudInputs({}, 5_000), { spec: undefined, timer: null });
270
+ passed += 1;
271
+ console.log(`hud surface: ${passed} checks passed`);
272
+ }