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
@@ -0,0 +1,159 @@
1
+ // Vehicle preset v1.160: real model build, controller seam, seats and cleanup.
2
+ import assert from 'node:assert/strict';
3
+ import fs from 'node:fs';
4
+ import { register } from 'node:module';
5
+ import { Group, PerspectiveCamera } from 'three';
6
+ const root = new URL('../../', import.meta.url).href;
7
+ register(`data:text/javascript,${encodeURIComponent(`
8
+ export async function resolve(specifier, context, next) {
9
+ if (specifier === '@imports/castle.physics-2d/engine/art') return { url: 'data:text/javascript,export const renderArtFrame=()=>null;export const artReady=()=>false;export const artFrameCount=()=>0;', shortCircuit: true };
10
+ if (specifier.startsWith('@imports/')) {
11
+ const file = specifier.replace('@imports/castle.', '');
12
+ return { url: ${JSON.stringify(root)} + file + (file.endsWith('.js') ? '' : '.js'), shortCircuit: true };
13
+ }
14
+ try {return await next(specifier, context);} catch(e) {
15
+ if (specifier.startsWith('.') && !specifier.endsWith('.js')) return next(specifier + '.js', context);
16
+ throw e;
17
+ }
18
+ }
19
+ `)}`);
20
+ const { makeVehicle, pinRiders, tintPaint } = await import('../code/client/vehicle.js');
21
+ const { parseCar, vehicleOf } = await import('../code/shared/car.js');
22
+ const { hub, clear } = await import('../code/client/state.js');
23
+ const { makeIdle, SEAT_DROP_M } = await import('../code/client/idle.js');
24
+ const Stuck = await import('../code/client/stuck.js');
25
+ const { stuckText } = Stuck;
26
+ const playerSource = fs.readFileSync(new URL('../../physics-3d/behaviors/Player.jsx', import.meta.url), 'utf8');
27
+ const { Player } = await import('data:text/javascript,' + encodeURIComponent(playerSource));
28
+ const model = JSON.stringify({ format: 'pxmodel', look: { outline: 0, ao: 0, rim: 0 }, parts: [
29
+ { id: 'paint', kind: 'box', width: 2, height: 0.5, depth: 4, color: '#00ff00' },
30
+ { id: 'glass', kind: 'box', width: 1, height: 0.3, depth: 1, color: '#111111' },
31
+ ] });
32
+ function boot() {
33
+ clear();
34
+ const local = { id: 'local', components: { Player: { ...Player.defaultProps }, Transform: { x: 1, y: 1, z: 2, rotationY: 0 } }, runtime: {} };
35
+ const driver = { id: 'other', components: { Transform: { x: 10, y: 2, z: 20, rotationY: 90 } }, runtime: {} };
36
+ const look = { id: 'car', components: { Model: { file: 'car.pxmodel', scale: 2 } } };
37
+ const nodes = new Map();
38
+ for (const actor of [local, driver]) {
39
+ const node = new Group(), rig = new Group(); rig.userData.modelParts = new Map(); node.userData.modelParts = rig.userData.modelParts; rig.position.y = -0.7; node.add(rig); nodes.set(actor.id, { node });
40
+ }
41
+ const actors = new Map([local, driver, look].map(a => [a.id, a]));
42
+ const impulses = [], placements = [], velocity = { x: 0, y: 0, z: 0 };
43
+ const scene = {
44
+ files: { 'car.pxmodel': model }, keys: new Set(['KeyW', 'Space']), moveInput: { consumeJump: () => true },
45
+ persistent: {}, getActor: id => actors.get(id), getActors: () => [],
46
+ three: { nodes, camera: new PerspectiveCamera() },
47
+ multiplayer: { net: { selfId: () => 'me' }, avatars: { actors: new Map([['driver', 'other']]) }, players: new Map([['driver', { samples: [{ pose: [999, 999, 999, 0] }] }]]) },
48
+ physics3d: { ready: () => true, mass: () => 1, getVelocity: () => velocity, castRay: (at, dir) => dir.y ? { distance: 0.85 } : null, applyImpulse: (a, v) => impulses.push(v), setVelocity: (a, v) => Object.assign(velocity, v), resetForces() {}, addForce() {}, bodyOf: () => ({ setTranslation: at => placements.push(at) }) },
49
+ };
50
+ return { scene, local, driver, nodes, impulses, placements };
51
+ }
52
+ const car = () => ({ ...parseCar({ look: 'car', color: '#ff0000', seats: [[1, 0, 1], [-1, 0.3, 0]] }), riders: {} });
53
+ const near = (a, b) => assert.ok(Math.abs(a - b) < 1e-8, `${a} ≈ ${b}`);
54
+ {
55
+ const { scene, local, nodes } = boot(), v = makeVehicle();
56
+ const before = nodes.get('local').node.children.length;
57
+ assert.equal(v.frame(scene, local, {}), null); v.draw(scene, local, {});
58
+ assert.equal(scene.playerDrive, undefined); assert.equal(nodes.get('local').node.children.length, before);
59
+ const cars = { me: car() }; hub.cars = cars;
60
+ v.frame(scene, local, cars); v.draw(scene, local, cars);
61
+ const group = nodes.get('local').node.children.find(c => c.name === 'hub:car');
62
+ assert.ok(group); group.position.toArray().forEach((v, i) => near(v, [-1, 0, -1][i])); assert.equal(group.children[0].scale.x, 2);
63
+ const text = JSON.parse(tintPaint(model, '#ff0000'));
64
+ assert.equal(text.parts[0].color, '#ff0000'); assert.equal(text.parts[1].color, '#111111');
65
+ assert.equal(JSON.parse(model).parts[0].color, '#00ff00', 'template unchanged');
66
+ const old = group; v.draw(scene, local, cars); assert.equal(nodes.get('local').node.children.find(c => c.name === 'hub:car'), old);
67
+ const boarded = { me: { ...cars.me, riders: { 1: 'driver' } } }; v.draw(scene, local, boarded);
68
+ assert.equal(nodes.get('local').node.children.find(c => c.name === 'hub:car'), old, 'a rider getting in keeps the drawn look');
69
+ nodes.get('local').node.visible = false; assert.equal(group.parent.visible, false, 'visibility follows the avatar');
70
+ const replacement = new Group(); scene.three.nodes.set('local', { node: replacement }); v.draw(scene, local, cars);
71
+ assert.equal(old.parent, null); assert.equal(replacement.children[0].name, 'hub:car');
72
+ v.clear(); assert.equal(replacement.children.length, 0); assert.equal(scene.playerDrive, undefined); assert.equal(local.components.Player.camDistance, 9);
73
+ }
74
+ {
75
+ const { scene, local, impulses } = boot(), v = makeVehicle();
76
+ hub.cars = { me: car() }; const previous = { step() {throw Error('previous must be replaced');} }; scene.playerDrive = previous;
77
+ v.frame(scene, local, hub.cars);
78
+ assert.equal(local.components.Player.camDistance, 12.6); near(local.components.Player.camHeight, 9.8);
79
+ new Player(local.components.Player).update(local, scene, 0.1);
80
+ assert.ok(impulses.some(v => v.z > 0)); assert.equal(local.runtime.jumpBuffer, 0, 'no jump');
81
+ hub.held.add('me'); new Player(local.components.Player).update(local, scene, 0.1);
82
+ near(scene.physics3d.getVelocity(local).z, 0); hub.held.clear();
83
+ // A bumper hit stops the actual body immediately, not just the target.
84
+ scene.physics3d.setVelocity(local, { x: 0, y: 2, z: 10 });
85
+ scene.physics3d.castRay = (at, dir) => dir.z > 0 ? { distance: 1 } : null;
86
+ new Player(local.components.Player).update(local, scene, 0.1);
87
+ assert.deepEqual(scene.physics3d.getVelocity(local), { x: 0, y: 2, z: 0 });
88
+ // An avatar ahead does not stop the car, but a gate just behind it does:
89
+ // the ray is asked to pass over avatars (physics-3d castRay's `skip`).
90
+ const skipped = [];
91
+ scene.physics3d.castRay = (at, dir, reach, self, skip) => {
92
+ if (dir.z <= 0) {return null;}
93
+ skipped.push(skip?.('other'), skip?.('gate'));
94
+ const hits = [{ distance: 0.5, actorId: 'other' }, ...(scene.wall ? [{ distance: 0.9, actorId: 'gate' }] : [])];
95
+ return hits.find(hit => !skip?.(hit.actorId) && hit.distance <= reach) ?? null;
96
+ };
97
+ scene.physics3d.setVelocity(local, { x: 0, y: 0, z: 10 }); scene.wall = true;
98
+ new Player(local.components.Player).update(local, scene, 0.1);
99
+ assert.deepEqual(scene.physics3d.getVelocity(local), { x: 0, y: 0, z: 0 }, 'a gate behind an avatar still stops the car');
100
+ assert.deepEqual(skipped.slice(0, 2), [true, false], 'avatars are skipped, other actors are not');
101
+ scene.wall = false; impulses.length = 0;
102
+ new Player(local.components.Player).update(local, scene, 0.1);
103
+ assert.ok(impulses.some(v => v.z > 0), 'an avatar alone does not stop it');
104
+ // Both Player camera/control branches call the same generic seam.
105
+ let calls = 0; scene.playerDrive = { step() {calls++;} }; scene.cameraControl = 'orbit';
106
+ new Player(local.components.Player).update(local, scene, 0.1); assert.equal(calls, 1);
107
+ // Restore only a seam we own; another system's replacement stays installed.
108
+ v.clear(); assert.equal(scene.playerDrive.step instanceof Function, true);
109
+ delete scene.cameraControl; scene.playerDrive = previous; v.frame(scene, local, hub.cars); v.frame(scene, local, {}); assert.equal(scene.playerDrive, previous);
110
+ }
111
+ {
112
+ const { scene, local, driver, placements, impulses } = boot(), v = makeVehicle();
113
+ hub.cars = { driver: { ...car(), riders: { 1: 'me' } } };
114
+ v.frame(scene, local, hub.cars);
115
+ scene.playerDrive.step(local, scene.physics3d, { keys: scene.keys, stick: scene.moveInput, grounded: true }, 0.1);
116
+ near(local.components.Transform.x, 9); near(local.components.Transform.y, 2.3); near(local.components.Transform.z, 22);
117
+ assert.equal(impulses.length, 0, 'rider input ignored'); assert.ok(placements.length);
118
+ // Not the raw 999 m server sample: this is the driver's interpolated pose.
119
+ driver.components.Transform.x = 12; pinRiders(scene, local, hub.cars); near(local.components.Transform.x, 11);
120
+ v.camera(scene, local, hub.cars); near(scene.three.camera.position.x, 12 - 12.6); near(scene.three.camera.position.z, 20);
121
+ const idle = makeIdle({}); idle.draw(scene, local);
122
+ for (const id of ['local', 'other']) {near(scene.three.nodes.get(id).node.children[0].position.y, -0.7 - SEAT_DROP_M);}
123
+ hub.cars = {}; idle.draw(scene, local); near(scene.three.nodes.get('local').node.children[0].position.y, -0.7);
124
+ v.frame(scene, local, hub.cars); assert.equal(scene.playerDrive, undefined); idle.release();
125
+ }
126
+ {
127
+ // Execute the actual kit hooks without the Vite-only module bootstrap.
128
+ const source = fs.readFileSync(new URL('../code/client/hookLayer.js', import.meta.url), 'utf8');
129
+ const start = source.indexOf(' beforeReport(scene, local) {');
130
+ const end = source.indexOf(' // Travel retains', start);
131
+ const hooks = Function('hub', 'vehicleOf', 'pinRiders', 'return ({' + source.slice(start, end) + '});')(hub, vehicleOf, pinRiders);
132
+ const { scene, local } = boot(); let sent = 0;
133
+ const system = { net: scene.multiplayer.net, report() {sent++;} };
134
+ hooks.report(scene, local, system); assert.equal(sent, 1, 'unchanged normal reporting');
135
+ hub.cars = { driver: { ...car(), riders: { 1: 'me' } } };
136
+ hooks.beforeReport(scene, local); hooks.report(scene, local, system);
137
+ assert.equal(sent, 1, 'no rider report'); near(local.components.Transform.x, 9);
138
+ hub.cars = { me: car() }; hooks.report(scene, local, system); assert.equal(sent, 2, 'driver uses ordinary report');
139
+ }
140
+ {
141
+ const source = fs.readFileSync(new URL('../code/systems/hub.js', import.meta.url), 'utf8');
142
+ const start = source.indexOf(' offerUnstick(scene, local, town, now) {');
143
+ const end = source.indexOf('\n }\n', start) + 5;
144
+ const method = Function('Hub', 'carInput', ...Object.keys(Stuck), 'TOAST_MS', 'return ({' + source.slice(start, end) + '});');
145
+ const { carInput } = await import('../code/client/car.js');
146
+ const system = method({ hub }, carInput, ...Object.values(Stuck), 2000);
147
+ const { scene, local } = boot();
148
+ scene.cameraControl = 'orbit'; scene.keys = new Set(['KeyD']); scene.moveInput = null;
149
+ system.chrome = { stuckPrompt(text) {this.text = text;} }; system.sceneKey = 'test';
150
+ hub.place = { id: 'main' }; hub.stuck = { to: 'square' }; hub.cars = { me: car() };
151
+ for (let t = 0; t <= 4000; t += 100) {system.offerUnstick(scene, local, true, t);}
152
+ assert.equal(system.chrome.text, null, 'steering alone does not count as drive progress');
153
+ scene.keys = new Set(['KeyW']);
154
+ for (let t = 4100; t <= 8000; t += 100) {system.offerUnstick(scene, local, true, t);}
155
+ assert.equal(system.chrome.text, 'Stuck? Tap to reset the car');
156
+ }
157
+ assert.equal(stuckText('square', false, true), 'Stuck? Tap to reset the car');
158
+ assert.equal(stuckText('square'), 'Stuck? Tap to go to square');
159
+ console.log('ok: car drawing, paint, node rebuilds, seats, drive seam, rider input/camera and stuck wording');
@@ -0,0 +1,135 @@
1
+ // Vehicle preset v1.160: real hub layer, fake transport/body, no Rapier needed.
2
+ import assert from 'node:assert/strict';
3
+ import { register } from 'node:module';
4
+ const sceneStub = 'export const readScene = () => globalThis.__hubTestActors ?? [];';
5
+ register(`data:text/javascript,${encodeURIComponent(`
6
+ export async function resolve(specifier, context, next) {
7
+ if (specifier === '@imports/castle.multiplayer-3d/code/server/sceneBodies.js') return { url: ${JSON.stringify('data:text/javascript,' + encodeURIComponent(sceneStub))}, shortCircuit: true };
8
+ if (specifier === '@imports/castle.multiplayer-3d/code/server/players.js') return { url: 'data:text/javascript,export function setPose(sim,id,msg){sim.reports.push([id,msg])}', shortCircuit: true };
9
+ if (specifier === '@imports/castle.multiplayer-3d/code/server/limits.js') return { url: 'data:text/javascript,export const readPoint=()=>null', shortCircuit: true };
10
+ return next(specifier, context);
11
+ }
12
+ `)}`);
13
+ const { layer } = await import('../code/server/hub.js');
14
+ const { hubPlayers } = await import('../code/server/players.js');
15
+ const spec = { look: 'car', seats: [[1, 0, 1], [-1, 0.3, 0]], horn: 'sounds/horn.wav' };
16
+ let clock = 1_800_000_000_000;
17
+ const realNow = Date.now;
18
+ Date.now = () => clock;
19
+ function boot({ retained = false, count = 3 } = {}) {
20
+ globalThis.__hubTestActors = [
21
+ { id: 'spawn', components: { Player: {}, Transform: { x: 0, y: 1, z: 0 } } },
22
+ { id: 'car', components: { Model: { file: 'car.pxmodel' }, Transform: {} } },
23
+ { id: 'bench', components: { HubSeat: {}, Transform: {}, Shape: { kind: 'box', height: 0.3 } } },
24
+ { id: 'door', components: { HubDoor: { id: 'game', to: 'game' }, Transform: {} } },
25
+ ];
26
+ const sent = [], broadcast = [], left = [];
27
+ const players = Array.from({ length: count }, (_, i) => ({ playerId: `p${i + 1}`, username: `user${i}`, userId: `${i + 1}` }));
28
+ const session = { sessionId: 'dev', players: [...players], send: (id, msg) => sent.push([id, msg]), broadcast: msg => broadcast.push(msg) };
29
+ const body = () => ({ at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
30
+ const sim = { timeMs: 0, scenePath: retained ? 'scenes/game.scene' : 'scenes/main.scene', players: new Map(players.map(p => [p.playerId, body()])), objects: new Map(), bodies: new Map(), reports: [] };
31
+ let hub;
32
+ const opts = { title: 'Town', contract: 1, stuck: true, idle: { seats: true, sounds: ['sounds/horn.wav'] }, places: { game: { title: 'Game', scene: 'scenes/game.scene', result: {}, ...(retained ? { resume: { keep: true } } : {}) } } };
33
+ if (retained) {session.place = 'game'; opts.places.game.idle = opts.idle;}
34
+ // resolvePlace reads session's authoritative place field.
35
+ const hooks = { ready(ctx) {hub = ctx;}, leave(ctx, id) {left.push(id);} };
36
+ const server = layer({ server: { maxPlayers: Math.max(8, count) }, hub: opts }, hooks, { game: hooks }, () => true);
37
+ server.sceneFor(session); server.ready(sim);
38
+ const say = (id, data) => server.message(session, { playerId: id }, data);
39
+ const tick = (ms = 50) => {sim.timeMs += ms; clock += ms; server.place(sim); server.step(sim, []);};
40
+ players.forEach(p => say(p.playerId, { k: 'hub-hello', avatar: 0, party: 1 }));
41
+ tick(2000); tick(5000);
42
+ for (const p of sim.players.values()) {p.at = { x: 0, y: 1, z: 0 };}
43
+ const drop = id => {session.players.splice(session.players.findIndex(p => p.playerId === id), 1); sim.players.delete(id);};
44
+ const back = id => {session.players.push(players.find(p => p.playerId === id)); sim.players.set(id, body()); say(id, { k: 'hub-hello', avatar: 0, party: 1, resume: true });};
45
+ return { hub, server, sim, session, sent, broadcast, say, tick, drop, back, left };
46
+ }
47
+ const near = (a, b) => assert.ok(Math.abs(a - b) < 1e-9, `${a} ≈ ${b}`);
48
+ let n = 0;
49
+ function test(name, fn) {fn(); n++; console.log(`ok: ${name}`);}
50
+ try {
51
+ test('unused places omit car fields, messages and deltas', () => {
52
+ const r = boot();
53
+ assert.equal(Object.hasOwn(r.server.join(), 'hubCars'), false);
54
+ r.server.delta(); r.tick();
55
+ assert.equal(Object.hasOwn(r.server.delta() ?? {}, 'hubCars'), false);
56
+ });
57
+ test('validation, held, unknown look, sound, riders and occupied seats', () => {
58
+ const r = boot();
59
+ assert.equal(r.hub.drive('unknown', spec), false);
60
+ assert.equal(r.hub.drive('p1', { look: 'bench' }), false);
61
+ assert.equal(r.hub.drive('p1', { look: 'car', speed: NaN }), false);
62
+ assert.equal(r.hub.drive('p1', { look: 'car', horn: 'else.wav' }), false);
63
+ r.hub.hold('p1'); assert.equal(r.hub.drive('p1', spec), false); r.hub.release('p1');
64
+ assert.equal(r.hub.drive('p1', spec), true);
65
+ assert.equal(r.hub.ride('p2', 'p1', 0), false);
66
+ assert.equal(r.hub.ride('p2', 'p1', 2), false);
67
+ r.hub.hold('p2'); assert.equal(r.hub.ride('p2', 'p1', 1), false); r.hub.release('p2');
68
+ r.sim.players.get('p2').at.x = 8; assert.equal(r.hub.ride('p2', 'p1', 1), false);
69
+ r.sim.players.get('p2').at.x = 0;
70
+ assert.equal(r.hub.ride('p2', 'p1', 1), true);
71
+ assert.equal(r.hub.ride('p3', 'p1', 1), false);
72
+ assert.equal(r.hub.drive('p2', spec), false);
73
+ assert.equal(r.hub.drive('p1', { look: 'car' }), false, 'cannot remove an occupied seat');
74
+ assert.equal(r.hub.drive('p1', { ...spec, color: '#ff0000' }), true);
75
+ assert.deepEqual(r.hub.vehicle('p2'), { driver: false, of: 'p1', seat: 1 });
76
+ r.say('p1', { k: 'hub-sit', seat: 'bench' }); assert.equal(r.hub.seat('p1'), null);
77
+ r.say('p2', { k: 'hub-sit', seat: 'bench' }); assert.equal(r.hub.seat('p2'), null);
78
+ });
79
+ test('rotated seat pinning, pose report refusal and tuning restore', () => {
80
+ const r = boot(); r.hub.tune('p1', { speed: 2, jump: 1 }); r.tick();
81
+ assert.equal(r.sim.players.get('p1').maxSpeed, 24);
82
+ r.hub.drive('p1', { ...spec, speed: 16 }); r.hub.ride('p2', 'p1', 1);
83
+ r.hub.placeAt('p1', { x: 10, y: 2, z: 20 }, 90); r.tick();
84
+ const p = r.sim.players.get('p2'); near(p.at.x, 9); near(p.at.y, 2.3); near(p.at.z, 22); near(p.facing, Math.PI / 2);
85
+ assert.equal(r.sim.players.get('p1').maxSpeed, 16);
86
+ const adapter = hubPlayers(r.server);
87
+ adapter.setPose(r.sim, 'p2', { p: [99, 1, 99] }); assert.equal(r.sim.reports.length, 0);
88
+ adapter.setPose(r.sim, 'p1', { p: [10, 2, 20] }); assert.equal(r.sim.reports.length, 1);
89
+ r.hub.hold('p1'); r.tick(); assert.equal(r.hub.vehicle('p1').driver, true); r.hub.release('p1');
90
+ assert.equal(r.hub.drive('p1', null), true);
91
+ assert.equal(r.hub.vehicle('p2'), null); assert.equal(r.server.join().held.includes('p2'), false);
92
+ near(r.sim.players.get('p1').at.x, 10); near(r.sim.players.get('p1').at.z, 21.6);
93
+ near(p.at.x, 9); near(p.at.z, 23.6);
94
+ assert.equal(r.sim.players.get('p1').maxSpeed, 24);
95
+ });
96
+ test('exit positions, rider exit, changed deltas and horn cooldown', () => {
97
+ const r = boot(); r.server.delta();
98
+ r.hub.drive('p1', spec); r.hub.ride('p2', 'p1', 1);
99
+ assert.ok(r.server.delta().hubCars.p1); assert.equal(r.server.delta(), null);
100
+ r.say('p2', { k: 'hub-horn' }); assert.equal(r.broadcast.length, 0);
101
+ r.say('p1', { k: 'hub-horn' }); r.say('p1', { k: 'hub-horn' }); assert.equal(r.broadcast.length, 1);
102
+ assert.equal(r.broadcast[0].player, 'p1'); r.tick(1000); r.say('p1', { k: 'hub-horn' }); assert.equal(r.broadcast.length, 2);
103
+ r.hub.ride('p2', null); assert.equal(r.hub.vehicle('p2'), null); near(r.sim.players.get('p2').at.x, -3.6);
104
+ assert.equal(r.hub.drive('p1', null, { x: NaN, z: 0 }), false);
105
+ assert.equal(r.hub.drive('p1', null, { x: 30, z: 20, facing: 180 }), true);
106
+ assert.deepEqual(r.sim.players.get('p1').at, { x: 30, y: 1, z: 20 }); near(r.sim.players.get('p1').facing, Math.PI);
107
+ assert.deepEqual(r.server.delta().hubCars, {});
108
+ });
109
+ test('leave, rider leave, trip, end and shutdown release occupants', () => {
110
+ let r = boot(); r.hub.drive('p1', spec); r.hub.ride('p2', 'p1', 1); r.drop('p2'); r.tick(); assert.deepEqual(r.hub.vehicle('p1').car.riders, {});
111
+ r = boot(); r.hub.drive('p1', spec); r.hub.ride('p2', 'p1', 1); r.drop('p1'); r.tick(); assert.equal(r.hub.vehicle('p2'), null);
112
+ r = boot(); r.hub.drive('p1', spec); r.hub.ride('p2', 'p1', 1); r.hub.go('game', ['p1']); assert.equal(r.hub.vehicle('p2'), null); assert.equal(r.hub.drive('p1', spec), false);
113
+ r = boot(); r.hub.drive('p1', spec); r.hub.ride('p2', 'p1', 1); r.hub.end(['p1']); assert.equal(r.hub.vehicle('p2'), null);
114
+ // A trip that fails (the door shut) or a fresh hello lets them drive again.
115
+ r = boot(); r.hub.drive('p1', spec); r.hub.go('game', ['p1']); assert.equal(r.hub.drive('p1', spec), false);
116
+ r.say('p1', { k: 'hub-shut', door: 'game' }); assert.equal(r.hub.drive('p1', spec), true);
117
+ r = boot(); r.hub.drive('p1', spec); r.hub.go('game', ['p1']); r.say('p1', { k: 'hub-hello', avatar: 0, party: 1 }); r.tick(); assert.equal(r.hub.drive('p1', spec), true);
118
+ });
119
+ test('24-car cap', () => {
120
+ const r = boot({ count: 25 });
121
+ for (let i = 1; i <= 24; i++) {assert.equal(r.hub.drive(`p${i}`, { look: 'car' }), true);}
122
+ assert.equal(r.hub.drive('p25', spec), false);
123
+ assert.equal(r.hub.drive('p1', { look: 'car', color: '#aabbcc' }), true);
124
+ });
125
+ test('retained reconnect keeps car/riders, expiry releases them', () => {
126
+ const r = boot({ retained: true });
127
+ assert.equal(r.server.join().hubPlace.resume, true);
128
+ assert.equal(r.hub.drive('p1', spec), true); assert.equal(r.hub.ride('p2', 'p1', 1), true);
129
+ r.drop('p1'); r.tick(); r.tick(30000); assert.equal(r.hub.vehicle('p2').of, 'p1');
130
+ r.back('p1'); r.tick(); assert.ok(r.server.join().hubCars.p1); assert.deepEqual(r.left, []);
131
+ r.drop('p1'); r.tick(); r.tick(60000); assert.equal(r.hub.vehicle('p2'), null); assert.deepEqual(r.left, ['p1']);
132
+ });
133
+ const shutdown = boot(); shutdown.hub.drive('p1', spec); shutdown.hub.ride('p2', 'p1', 1); await shutdown.server.shutdown(); assert.equal(shutdown.hub.vehicle('p2'), null);
134
+ } finally {Date.now = realNow;}
135
+ console.log(`ok: ${n} vehicle server cases`);
@@ -374,6 +374,39 @@ console.log('hub-game yours hearts: fresh read before every write, serialized qu
374
374
  assert.equal(blocked.ask(state, doors, [], 85000).kind, 'yours');
375
375
  }
376
376
 
377
+ // Back out of a House: no return offer for it, and no arrival offer that sends
378
+ // the player straight back in; another of their games may still be offered.
379
+ {
380
+ const homes = [{ id: 'home', title: 'House' }, ...doors];
381
+ const homeState = { rows: [{ door: 'home', title: 'House', line: '' }, ...rows], hearts: ['home', 'd1'] };
382
+ const back = makeYours({}, { getCurrent: async () => ({ userId: '1' }) }, () => {});
383
+ back.frame(true, homeState, 0);
384
+ await flush();
385
+ back.returned('home', null, true);
386
+ back.frame(true, homeState, 100);
387
+ const offer = back.ask(homeState, homes, [], 100);
388
+ assert.notEqual(offer?.door, 'home', 'the House just left is not offered');
389
+ assert.equal(offer.door, 'd1');
390
+ assert.equal(offer.requiresArrivalPlacement, undefined, 'a House exit is not a game return');
391
+ back.dismiss();
392
+ assert.equal(back.ask(homeState, homes, [], 200), null);
393
+
394
+ const only = makeYours({}, { getCurrent: async () => ({ userId: '1' }) }, () => {});
395
+ const onlyHome = { rows: [], hearts: ['home'] };
396
+ only.frame(true, onlyHome, 0);
397
+ await flush();
398
+ only.returned('home', null, true);
399
+ only.frame(true, onlyHome, 100);
400
+ assert.equal(only.ask(onlyHome, homes, [], 100), null, 'nothing else to offer: no offer at all');
401
+ only.returned('d1', { score: 4, unit: 'points' });
402
+ assert.equal(only.ask(onlyHome, homes, [], 200).door, 'd1', 'a later game return is offered as before');
403
+ only.clear();
404
+ only.frame(true, onlyHome, 300);
405
+ await flush();
406
+ only.frame(true, onlyHome, 400);
407
+ assert.equal(only.ask(onlyHome, homes, [], 400).door, 'home', 'a new visit forgets the House left');
408
+ }
409
+
377
410
  // Local calendar days, including opposite UTC boundaries and DST transitions.
378
411
  {
379
412
  const originalTZ = process.env.TZ;