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
@@ -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 });
@@ -1575,6 +1650,34 @@ await test('authored visit results/end do not finish an interrupted competitive
1575
1650
  world.players.delete('p1'); s.session.players = s.session.players.filter(p=>p.playerId!=='p1'); h.place(world);
1576
1651
  assert.deepEqual(events.filter(([,e])=>e.kind===29).map(([,e])=>e.result),[3],'disconnect closes interrupted round');
1577
1652
  });
1653
+ await test('a stored resume pose is not restored for an arrival ghost placed through a door', async () => {
1654
+ const { store } = await import('../code/server/resumePose.js');
1655
+ const { poseStorage } = await import('./pose-storage-fixture.mjs');
1656
+ const p = platformHub();
1657
+ const s = session({ hub: p.hub });
1658
+ s.session.storage = { deck: poseStorage() };
1659
+ const cold = { at: { x: -7, y: 1, z: 9 }, facing: 0.5 };
1660
+ // Both accounts left the Town earlier and each has a stored pose.
1661
+ for (const userId of ['101', '102']) {
1662
+ const earlier = store(s.session, 'main');
1663
+ await earlier.take(userId);
1664
+ await earlier.end(userId, cold);
1665
+ }
1666
+ const json = { ...castleJson, hub: { ...castleJson.hub, resumePose: true } };
1667
+ const { h, world, arrived } = boot(s, {}, json);
1668
+ // p1 comes back through the race door (ghost's arrival); p2 rejoins with none.
1669
+ hello(h, s, 'p1');
1670
+ hello(h, s, 'p2');
1671
+ for (let i = 0; i < 10 && arrived.length < 2; i++) {
1672
+ await flush();
1673
+ h.place(world);
1674
+ }
1675
+ assert.equal(arrived.length, 2);
1676
+ const at = (id) => world.players.get(id).at;
1677
+ assert.ok(Math.hypot(at('p1').x - cold.at.x, at('p1').z - cold.at.z) > 1, `door arrival left at the stored pose ${JSON.stringify(at('p1'))}`);
1678
+ assert.ok(Math.hypot(at('p2').x - cold.at.x, at('p2').z - cold.at.z) < 0.01, `rejoin without a door keeps its stored pose ${JSON.stringify(at('p2'))}`);
1679
+ });
1680
+
1578
1681
  console.log(`hub ops: ${n} tests passed`);
1579
1682
 
1580
1683
  // Opt-in exists after actual layer construction, before authored hooks run.
@@ -3663,7 +3663,7 @@ await test('early proxy not_running retries the same door once with a fresh acqu
3663
3663
  mp.state = 'joined'; system.stepTrip(scene, mp, null, 4002);
3664
3664
  assert.equal(scene.persistent.hubDepth, 1);
3665
3665
  });
3666
- for (const [code, age, retried] of [[4401, 1000, false], [1013, 1000, false], [4404, 5001, false], [4404, 1000, true]]) {
3666
+ for (const [code, age, retried] of [[4401, 1000, false], [1013, 1000, false], [4404, 10001, false], [4404, 1000, true]]) {
3667
3667
  await test(`door retry limit: close ${code}, age ${age}, already retried ${retried}`, async () => {
3668
3668
  const { system, scene } = setup(); const mp = mpStub(scene);
3669
3669
  answers.go = handoff(); system.goHub(scene, { door: 'race' }); await toSwitch(system, scene, mp);
@@ -3674,6 +3674,25 @@ for (const [code, age, retried] of [[4401, 1000, false], [1013, 1000, false], [4
3674
3674
  assert.equal(calls.filter(c => c[0] === 'go').length, 1);
3675
3675
  });
3676
3676
  }
3677
+ await test('early proxy not_running still retries a door 8 s after its handoff (the SDK tried its nonce meanwhile)', async () => {
3678
+ const { system, scene } = setup(); const mp = mpStub(scene);
3679
+ answers.go = handoff(); system.goHub(scene, { door: 'race' }); await toSwitch(system, scene, mp);
3680
+ system.trip.target.acquiredAt = 0;
3681
+ mp.state = 'failed'; mp.joinFailure = { code: 'MULTIPLAYER_CONNECTION_FAILED', closeCode: 4404 };
3682
+ system.stepTrip(scene, mp, null, 8000);
3683
+ assert.equal(system.trip.phase, 'retrying-door');
3684
+ });
3685
+ await test("a host's Go is never acquired again from this session after an early not_running", async () => {
3686
+ const { system, scene } = setup(); const mp = mpStub(scene);
3687
+ answers.go = handoff(); system.goHub(scene, { door: 'race', title: 'Foot Race', host: true });
3688
+ await toSwitch(system, scene, mp);
3689
+ const trip = system.trip; trip.target.acquiredAt = 0;
3690
+ mp.state = 'failed'; mp.joinFailure = { code: 'MULTIPLAYER_CONNECTION_FAILED', closeCode: 4404 };
3691
+ system.stepTrip(scene, mp, null, 1500);
3692
+ assert.notEqual(system.trip?.phase, 'retrying-door');
3693
+ system.stepTrip(scene, mp, null, 5000); await flush();
3694
+ assert.equal(calls.filter(c => c[0] === 'go').length, 1);
3695
+ });
3677
3696
  console.log(`hub trips with retry: ${n} tests passed`);
3678
3697
 
3679
3698
  for (const failure of ['refused', 'pack', 'timeout']) {
@@ -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
+ }