castle-web-cli 0.4.228 → 0.4.230

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 (236) hide show
  1. package/dist/agent-prompts.d.ts +11 -3
  2. package/dist/agent-prompts.js +153 -53
  3. package/dist/agent.d.ts +2 -0
  4. package/dist/agent.js +43 -33
  5. package/dist/api.d.ts +47 -2
  6. package/dist/api.js +85 -16
  7. package/dist/castle-host/host.d.ts +91 -0
  8. package/dist/castle-host/host.js +779 -3
  9. package/dist/castleJson.d.ts +59 -0
  10. package/dist/castleJson.js +267 -3
  11. package/dist/check.js +27 -1
  12. package/dist/cloudGit.d.ts +20 -1
  13. package/dist/cloudGit.js +267 -10
  14. package/dist/contentPack.d.ts +49 -0
  15. package/dist/contentPack.js +273 -0
  16. package/dist/devExperiments.d.ts +21 -0
  17. package/dist/devExperiments.js +139 -0
  18. package/dist/devHub.d.ts +55 -0
  19. package/dist/devHub.js +187 -0
  20. package/dist/devSessionChild.js +3 -1
  21. package/dist/devSessionServer.d.ts +14 -1
  22. package/dist/devSessionServer.js +229 -44
  23. package/dist/experimentAssignment.d.ts +15 -0
  24. package/dist/experimentAssignment.js +41 -0
  25. package/dist/importCheckHook.d.ts +40 -0
  26. package/dist/importCheckHook.js +171 -0
  27. package/dist/importRegression.d.ts +15 -0
  28. package/dist/importRegression.js +100 -0
  29. package/dist/importTrust.d.ts +2 -0
  30. package/dist/importTrust.js +27 -0
  31. package/dist/importUpdateHook.d.ts +18 -0
  32. package/dist/importUpdateHook.js +31 -8
  33. package/dist/importUpdateHookRunner.js +19 -7
  34. package/dist/imports.d.ts +16 -0
  35. package/dist/imports.js +145 -33
  36. package/dist/index.js +8 -1
  37. package/dist/init.d.ts +3 -0
  38. package/dist/init.js +125 -8
  39. package/dist/install.js +4 -1
  40. package/dist/localPaths.js +4 -0
  41. package/dist/login.js +2 -2
  42. package/dist/platformDoc.js +3 -8
  43. package/dist/playPagePolicy.js +3 -1
  44. package/dist/remix.js +5 -0
  45. package/dist/routerTaskReport.d.ts +28 -0
  46. package/dist/routerTaskReport.js +56 -0
  47. package/dist/save-deck.d.ts +18 -0
  48. package/dist/save-deck.js +145 -6
  49. package/dist/serve.d.ts +8 -0
  50. package/dist/serve.js +94 -13
  51. package/dist/serverBundle.d.ts +1 -1
  52. package/dist/serverBundle.js +5 -1
  53. package/dist/sourceLineage.d.ts +42 -0
  54. package/dist/sourceLineage.js +380 -0
  55. package/dist/webSourceSync.d.ts +11 -0
  56. package/dist/webSourceSync.js +26 -9
  57. package/kits/base/CLAUDE.md +2 -3
  58. package/kits/base/castle.json +1 -1
  59. package/kits/base/sdk/README.md +301 -52
  60. package/kits/base/sdk/agent.js +4 -4
  61. package/kits/base/sdk/avatar.d.ts +12 -0
  62. package/kits/base/sdk/avatar.js +23 -0
  63. package/kits/base/sdk/castle.d.ts +6 -1
  64. package/kits/base/sdk/castle.js +3 -0
  65. package/kits/base/sdk/commands.d.ts +208 -0
  66. package/kits/base/sdk/commands.js +16 -0
  67. package/kits/base/sdk/context.d.ts +6 -0
  68. package/kits/base/sdk/experiments.d.ts +15 -0
  69. package/kits/base/sdk/experiments.js +83 -0
  70. package/kits/base/sdk/hub.d.ts +85 -0
  71. package/kits/base/sdk/hub.js +107 -0
  72. package/kits/base/sdk/multiplayer.d.ts +86 -6
  73. package/kits/base/sdk/multiplayer.js +157 -4
  74. package/kits/base/sdk/server/hub.d.ts +169 -0
  75. package/kits/base/sdk/server/hub.js +125 -0
  76. package/kits/base/sdk/server/platformHandle.d.ts +49 -2
  77. package/kits/base/sdk/server/storage.d.ts +55 -2
  78. package/kits/base/sdk/server/wrapper.d.ts +85 -6
  79. package/kits/base/sdk/server/wrapper.js +393 -30
  80. package/kits/base/sdk/transport.d.ts +2 -1
  81. package/kits/base/sdk/transport.js +13 -1
  82. package/kits/hub-game/.prettierrc +5 -0
  83. package/kits/hub-game/CLAUDE.md +146 -0
  84. package/kits/hub-game/blueprints/avatar-0.scene +28 -0
  85. package/kits/hub-game/blueprints/avatar-1.scene +28 -0
  86. package/kits/hub-game/blueprints/avatar-2.scene +28 -0
  87. package/kits/hub-game/blueprints/avatar-3.scene +28 -0
  88. package/kits/hub-game/blueprints/bean/avatar-0.scene +28 -0
  89. package/kits/hub-game/blueprints/bean/avatar-1.scene +28 -0
  90. package/kits/hub-game/blueprints/bean/avatar-2.scene +28 -0
  91. package/kits/hub-game/blueprints/bean/avatar-3.scene +28 -0
  92. package/kits/hub-game/blueprints/blocky/avatar-0.scene +28 -0
  93. package/kits/hub-game/blueprints/blocky/avatar-1.scene +28 -0
  94. package/kits/hub-game/blueprints/blocky/avatar-2.scene +28 -0
  95. package/kits/hub-game/blueprints/blocky/avatar-3.scene +28 -0
  96. package/kits/hub-game/blueprints/pixel/avatar-0.scene +28 -0
  97. package/kits/hub-game/blueprints/pixel/avatar-1.scene +28 -0
  98. package/kits/hub-game/blueprints/pixel/avatar-2.scene +28 -0
  99. package/kits/hub-game/blueprints/pixel/avatar-3.scene +28 -0
  100. package/kits/hub-game/castle.json +96 -0
  101. package/kits/hub-game/code/client/attention.js +133 -0
  102. package/kits/hub-game/code/client/avatar.js +288 -0
  103. package/kits/hub-game/code/client/cabinets.js +90 -0
  104. package/kits/hub-game/code/client/chat.js +135 -0
  105. package/kits/hub-game/code/client/chrome.js +1001 -0
  106. package/kits/hub-game/code/client/doorFrame.js +15 -0
  107. package/kits/hub-game/code/client/firstJoin.js +14 -0
  108. package/kits/hub-game/code/client/grab.js +241 -0
  109. package/kits/hub-game/code/client/hookLayer.js +230 -0
  110. package/kits/hub-game/code/client/idle.js +326 -0
  111. package/kits/hub-game/code/client/keys.js +48 -0
  112. package/kits/hub-game/code/client/pack.js +232 -0
  113. package/kits/hub-game/code/client/packFormat.js +397 -0
  114. package/kits/hub-game/code/client/say.js +127 -0
  115. package/kits/hub-game/code/client/sha256.js +80 -0
  116. package/kits/hub-game/code/client/sound.js +147 -0
  117. package/kits/hub-game/code/client/state.js +131 -0
  118. package/kits/hub-game/code/client/talk.js +259 -0
  119. package/kits/hub-game/code/client/together.js +365 -0
  120. package/kits/hub-game/code/client/wear.js +149 -0
  121. package/kits/hub-game/code/server/actors.js +627 -0
  122. package/kits/hub-game/code/server/blocks.js +103 -0
  123. package/kits/hub-game/code/server/cabinets.js +309 -0
  124. package/kits/hub-game/code/server/game.js +137 -0
  125. package/kits/hub-game/code/server/grab.js +247 -0
  126. package/kits/hub-game/code/server/history.js +96 -0
  127. package/kits/hub-game/code/server/hub.js +1904 -0
  128. package/kits/hub-game/code/server/idle.js +412 -0
  129. package/kits/hub-game/code/server/index.js +64 -0
  130. package/kits/hub-game/code/server/labels.js +59 -0
  131. package/kits/hub-game/code/server/manifest.js +527 -0
  132. package/kits/hub-game/code/server/npcs.js +745 -0
  133. package/kits/hub-game/code/server/party.js +381 -0
  134. package/kits/hub-game/code/server/place.js +43 -0
  135. package/kits/hub-game/code/server/say.js +83 -0
  136. package/kits/hub-game/code/server/wear.js +142 -0
  137. package/kits/hub-game/code/systems/hub.js +2230 -0
  138. package/kits/hub-game/docs/content-pack.md +151 -0
  139. package/kits/hub-game/docs/contract.md +1139 -0
  140. package/kits/hub-game/docs/style.md +137 -0
  141. package/kits/hub-game/drawings/blocky/castle-eye.sprite +58 -0
  142. package/kits/hub-game/drawings/blocky/dash.sprite +59 -0
  143. package/kits/hub-game/drawings/blocky/pom.sprite +59 -0
  144. package/kits/hub-game/drawings/blocky/tabby.sprite +59 -0
  145. package/kits/hub-game/drawings/pixel/castle-arm.sprite +13 -0
  146. package/kits/hub-game/drawings/pixel/castle-body.sprite +23 -0
  147. package/kits/hub-game/drawings/pixel/castle-leg.sprite +12 -0
  148. package/kits/hub-game/drawings/pixel/kai-arm.sprite +14 -0
  149. package/kits/hub-game/drawings/pixel/kai-head.sprite +24 -0
  150. package/kits/hub-game/drawings/pixel/kai-leg.sprite +15 -0
  151. package/kits/hub-game/drawings/pixel/kai-torso.sprite +18 -0
  152. package/kits/hub-game/drawings/pixel/mimi-arm.sprite +13 -0
  153. package/kits/hub-game/drawings/pixel/mimi-head.sprite +23 -0
  154. package/kits/hub-game/drawings/pixel/mimi-leg.sprite +15 -0
  155. package/kits/hub-game/drawings/pixel/mimi-torso.sprite +18 -0
  156. package/kits/hub-game/drawings/pixel/nox-arm.sprite +13 -0
  157. package/kits/hub-game/drawings/pixel/nox-head.sprite +21 -0
  158. package/kits/hub-game/drawings/pixel/nox-leg.sprite +14 -0
  159. package/kits/hub-game/drawings/pixel/nox-torso.sprite +18 -0
  160. package/kits/hub-game/eslint.config.js +20 -0
  161. package/kits/hub-game/fonts.generated.js +9 -0
  162. package/kits/hub-game/index.html +22 -0
  163. package/kits/hub-game/main.jsx +6 -0
  164. package/kits/hub-game/models/avatar-0.pxmodel +21 -0
  165. package/kits/hub-game/models/avatar-1.pxmodel +24 -0
  166. package/kits/hub-game/models/avatar-2.pxmodel +27 -0
  167. package/kits/hub-game/models/avatar-3.pxmodel +22 -0
  168. package/kits/hub-game/models/bean/avatar-0.pxmodel +19 -0
  169. package/kits/hub-game/models/bean/avatar-1.pxmodel +24 -0
  170. package/kits/hub-game/models/bean/avatar-2.pxmodel +22 -0
  171. package/kits/hub-game/models/bean/avatar-3.pxmodel +24 -0
  172. package/kits/hub-game/models/blocky/avatar-0.pxmodel +21 -0
  173. package/kits/hub-game/models/blocky/avatar-1.pxmodel +30 -0
  174. package/kits/hub-game/models/blocky/avatar-2.pxmodel +28 -0
  175. package/kits/hub-game/models/blocky/avatar-3.pxmodel +27 -0
  176. package/kits/hub-game/models/pixel/avatar-0.pxmodel +24 -0
  177. package/kits/hub-game/models/pixel/avatar-1.pxmodel +16 -0
  178. package/kits/hub-game/models/pixel/avatar-2.pxmodel +19 -0
  179. package/kits/hub-game/models/pixel/avatar-3.pxmodel +23 -0
  180. package/kits/hub-game/package-lock.json +365 -0
  181. package/kits/hub-game/package.json +32 -0
  182. package/kits/hub-game/scenes/main.scene +318 -0
  183. package/kits/hub-game/scripts/check.mjs +339 -0
  184. package/kits/hub-game/scripts/fixtures/sdk-stub.mjs +3 -0
  185. package/kits/hub-game/scripts/gen-avatars-bean.mjs +748 -0
  186. package/kits/hub-game/scripts/gen-avatars-blocky.mjs +607 -0
  187. package/kits/hub-game/scripts/gen-avatars-pixel.mjs +771 -0
  188. package/kits/hub-game/scripts/gen-avatars.mjs +621 -0
  189. package/kits/hub-game/scripts/pack.mjs +192 -0
  190. package/kits/hub-game/scripts/test-actors.mjs +666 -0
  191. package/kits/hub-game/scripts/test-attention.mjs +103 -0
  192. package/kits/hub-game/scripts/test-avatar.mjs +472 -0
  193. package/kits/hub-game/scripts/test-ban-join.mjs +194 -0
  194. package/kits/hub-game/scripts/test-blocks.mjs +351 -0
  195. package/kits/hub-game/scripts/test-chat.mjs +98 -0
  196. package/kits/hub-game/scripts/test-classic.mjs +590 -0
  197. package/kits/hub-game/scripts/test-door-jump.mjs +131 -0
  198. package/kits/hub-game/scripts/test-door.mjs +56 -0
  199. package/kits/hub-game/scripts/test-grab.mjs +331 -0
  200. package/kits/hub-game/scripts/test-hub-ops.mjs +835 -0
  201. package/kits/hub-game/scripts/test-hub-trip.mjs +1310 -0
  202. package/kits/hub-game/scripts/test-idle.mjs +518 -0
  203. package/kits/hub-game/scripts/test-interest.mjs +413 -0
  204. package/kits/hub-game/scripts/test-keys.mjs +50 -0
  205. package/kits/hub-game/scripts/test-manifest.mjs +224 -0
  206. package/kits/hub-game/scripts/test-no-forms.mjs +16 -0
  207. package/kits/hub-game/scripts/test-npcs.mjs +714 -0
  208. package/kits/hub-game/scripts/test-pack.mjs +424 -0
  209. package/kits/hub-game/scripts/test-party.mjs +286 -0
  210. package/kits/hub-game/scripts/test-say.mjs +149 -0
  211. package/kits/hub-game/scripts/test-together.mjs +183 -0
  212. package/kits/hub-game/theme.style +3 -0
  213. package/kits/multiplayer-3d/castle.json +5 -5
  214. package/kits/multiplayer-3d/code/client/avatars.js +101 -1
  215. package/kits/multiplayer-3d/code/server/players.js +4 -1
  216. package/kits/multiplayer-3d/code/server/sceneBodies.js +27 -6
  217. package/kits/multiplayer-3d/code/server/world.js +20 -7
  218. package/kits/multiplayer-3d/code/systems/multiplayer.js +222 -11
  219. package/kits/physics-2d/castle.json +2 -2
  220. package/kits/physics-2d/engine/art.js +13 -0
  221. package/kits/physics-2d/engine/assets.js +4 -2
  222. package/kits/physics-2d/engine/scene.js +25 -5
  223. package/kits/physics-3d/CLAUDE.md +6 -1
  224. package/kits/physics-3d/castle.json +3 -3
  225. package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +32 -4
  226. package/kits/physics-3d/engine3d/artobjects.js +2 -2
  227. package/kits/physics-3d/engine3d/materials.js +29 -1
  228. package/kits/physics-3d/engine3d/world3d.js +65 -1
  229. package/kits/physics-3d/systems/physics3d.js +5 -2
  230. package/kits/real-time/castle.json +2 -2
  231. package/kits/real-time/code/client/connection.js +77 -7
  232. package/kits/real-time/code/client/gameHooks.js +63 -3
  233. package/kits/real-time/code/client/messages.js +7 -0
  234. package/kits/real-time/code/server/gameHooks.js +24 -0
  235. package/kits/real-time/code/server/session.js +390 -22
  236. package/package.json +2 -2
@@ -0,0 +1,518 @@
1
+ // Idle play (contract §6, v1.6), the server's half: a client's `hub-emote` is
2
+ // checked (a kit emote, a player who is here, one every 2 s, the place's
3
+ // `emote` hook) and latched for everyone; `hub-sit` holds a player on a free
4
+ // seat near them and `hub-stand`, the place's own hold or release, or leaving
5
+ // gets them up; `hub.sound` plays a declared file at an actor, within bounds.
6
+ // A place without `idle` is sent exactly what it was. `npm run check` runs it;
7
+ // it needs nothing installed.
8
+
9
+ import assert from 'node:assert/strict';
10
+ import { register } from 'node:module';
11
+
12
+ const sceneStub = 'export const readScene = () => globalThis.__hubTestActors ?? [];';
13
+ register(
14
+ `data:text/javascript,${encodeURIComponent(`
15
+ export async function resolve(specifier, context, next) {
16
+ if (specifier === '@imports/castle.multiplayer-3d/code/server/sceneBodies.js') {
17
+ return { url: 'data:text/javascript,${encodeURIComponent(sceneStub)}', shortCircuit: true };
18
+ }
19
+ return next(specifier, context);
20
+ }
21
+ `)}`,
22
+ );
23
+ const { layer } = await import('../code/server/hub.js');
24
+ const Idle = await import('../code/server/idle.js');
25
+ const Manifest = await import('../code/server/manifest.js');
26
+ const ClientIdle = await import('../code/client/idle.js');
27
+
28
+ const bench = { kind: 'box', width: 2.4, height: 0.5, depth: 0.6 };
29
+ globalThis.__hubTestActors = [
30
+ { id: 'spawn', components: { Player: {}, Transform: { x: 0, y: 1, z: 0 } } },
31
+ { id: 'bench-a', components: { Transform: { x: 1, y: 0.25, z: 0, rotationY: 90 }, Shape: bench, Solid: {}, HubSeat: { face: 180 } } },
32
+ { id: 'bench-b', components: { Transform: { x: -1, y: 0.25, z: 0 }, Shape: bench, Solid: {}, HubSeat: {} } },
33
+ { id: 'stool', components: { Transform: { x: 0, y: 0, z: 1 }, HubSeat: { height: 1.2 } } },
34
+ { id: 'cart', components: { Transform: { x: 0, y: 0.25, z: -1 }, Shape: bench, Body: { type: 'kinematic' }, HubSeat: {} } },
35
+ { id: 'far-bench', components: { Transform: { x: 20, y: 0.25, z: 0 }, Shape: bench, HubSeat: {} } },
36
+ { id: 'jukebox', components: { Transform: { x: 3, y: 1, z: 3 }, Shape: { kind: 'box' } } },
37
+ { id: 'lamp', components: { Transform: { x: -3, y: 1, z: 3 }, Shape: { kind: 'box' } } },
38
+ { id: 'door-a', components: { Transform: { x: 0, y: 1, z: -20 }, HubDoor: { id: 'a', to: 'game' } } },
39
+ ];
40
+
41
+ const SOUNDS = ['sounds/juke.mp3', 'sounds/ding.wav'];
42
+
43
+ function boot(options = {}) {
44
+ const idle = 'idle' in options ? options.idle : { emotes: true, seats: true, sounds: SOUNDS };
45
+ const hooks = options.hooks ?? {};
46
+ const json = {
47
+ server: { maxPlayers: 8 },
48
+ hub: {
49
+ contract: 1,
50
+ title: 'Town',
51
+ ...(idle === undefined ? {} : { idle }),
52
+ places: { game: { title: 'Game', scene: 'scenes/game.scene', result: {} } },
53
+ },
54
+ };
55
+ let hub = null;
56
+ const sent = [];
57
+ const broadcasts = [];
58
+ const h = layer(json, { ...hooks, ready: (x) => (hub = x) }, {}, () => true);
59
+ const players = [
60
+ { playerId: 'p1', username: 'ada' },
61
+ { playerId: 'p2', username: 'bo' },
62
+ ];
63
+ const session = {
64
+ sessionId: 'dev',
65
+ players,
66
+ hub: null,
67
+ send: (id, d) => sent.push([id, d]),
68
+ broadcast: (d) => broadcasts.push(d),
69
+ };
70
+ h.sceneFor(session);
71
+ const body = () => ({ at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
72
+ const world = {
73
+ timeMs: 0,
74
+ players: new Map([
75
+ ['p1', body()],
76
+ ['p2', body()],
77
+ ]),
78
+ bodies: new Map(),
79
+ objects: new Map(),
80
+ scenePath: 'scenes/main.scene',
81
+ };
82
+ h.ready(world);
83
+ for (const p of players) {
84
+ h.message(session, p, { k: 'hub-hello', avatar: 0, party: 2 });
85
+ }
86
+ h.place(world);
87
+ for (const p of world.players.values()) {
88
+ p.at = { x: 0, y: 1, z: 0 };
89
+ }
90
+ const say = (playerId, data) => h.message(session, { playerId }, data);
91
+ const tick = (ms = 50) => {
92
+ world.timeMs += ms;
93
+ h.place(world);
94
+ h.step(world, []);
95
+ };
96
+ return { h, hub, world, sent, broadcasts, say, tick, session };
97
+ }
98
+
99
+ const warn = console.warn;
100
+ const warned = [];
101
+ console.warn = (...args) => warned.push(args.join(' '));
102
+ let n = 0;
103
+ function test(name, fn) {
104
+ try {
105
+ fn();
106
+ } catch (err) {
107
+ console.warn = warn;
108
+ console.error(`FAIL ${name}`);
109
+ throw err;
110
+ }
111
+ n += 1;
112
+ }
113
+
114
+ // --- the manifest -------------------------------------------------------------
115
+
116
+ test('idle: true is emotes and seats; an object turns each part on; absent is no key at all', () => {
117
+ const read = (idle) => Manifest.readManifest({ hub: { contract: 1, title: 'T', ...(idle === undefined ? {} : { idle }) } });
118
+ assert.deepEqual(read(true).manifest.places.main.idle, { emotes: true, seats: true, sounds: [] });
119
+ assert.deepEqual(read({ seats: true }).manifest.places.main.idle, { emotes: false, seats: true, sounds: [] });
120
+ assert.deepEqual(read({ sounds: ['a/b.mp3'] }).manifest.places.main.idle, { emotes: false, seats: false, sounds: ['a/b.mp3'] });
121
+ for (const off of [undefined, false, {}]) {
122
+ const place = read(off).manifest.places.main;
123
+ assert.equal('idle' in place, false);
124
+ assert.equal('idle' in Manifest.publicPlace('main', place), false);
125
+ }
126
+ assert.deepEqual(Manifest.publicPlace('main', read(true).manifest.places.main).idle, { emotes: true, seats: true, sounds: [] });
127
+ });
128
+
129
+ test('idle: unknown keys, wrong types and bad sound paths are check errors', () => {
130
+ const errors = (idle) => Manifest.readManifest({ hub: { contract: 1, title: 'T', idle } }).errors;
131
+ assert.match(errors({ emotes: true, chairs: true }).join(), /idle\.chairs is not part/);
132
+ assert.match(errors({ emotes: 'yes' }).join(), /idle\.emotes must be true or false/);
133
+ assert.match(errors(3).join(), /idle must be true, false or an object/);
134
+ for (const sounds of [['../x.mp3'], ['a.ogg'], ['a.mp3', 'a.mp3'], 'a.mp3', ['/a.mp3'], Array(17).fill(0).map((_, i) => `s${i}.mp3`)]) {
135
+ assert.match(errors({ sounds }).join(), /idle\.sounds must be/, JSON.stringify(sounds));
136
+ }
137
+ assert.deepEqual(errors({ sounds: ['sounds/a.mp3', 'imports/kit/b.wav', 'c.m4a'] }), []);
138
+ // Upper-case extensions are not bundled by the engine's media glob.
139
+ for (const file of ['sounds/a.MP3', 'b.Wav', 'c.M4A']) {
140
+ assert.match(errors({ sounds: [file] }).join(), /idle\.sounds must be/, file);
141
+ }
142
+ });
143
+
144
+ // --- a place that does not opt in --------------------------------------------
145
+
146
+ test('a place without idle is sent exactly what it was, whatever clients and the place ask', () => {
147
+ const quiet = boot({ idle: undefined });
148
+ const busy = boot({ idle: undefined });
149
+ const join = quiet.h.join();
150
+ assert.deepEqual(Object.keys(join), [
151
+ 'hubPlace',
152
+ 'hubAv',
153
+ 'hud',
154
+ 'hidden',
155
+ 'held',
156
+ 'labels',
157
+ 'tints',
158
+ 'marks',
159
+ 'hubDoors',
160
+ 'spawned',
161
+ 'spawnTemplates',
162
+ ]);
163
+ assert.equal('idle' in join.hubPlace, false);
164
+ busy.say('p1', { k: 'hub-emote', id: 'wave' });
165
+ busy.say('p1', { k: 'hub-sit', seat: 'bench-a' });
166
+ busy.say('p2', { k: 'hub-stand' });
167
+ assert.equal(busy.hub.emote('p1', 'wave'), false);
168
+ assert.equal(busy.hub.sound('jukebox', SOUNDS[0], { loop: true }), false);
169
+ assert.equal(busy.hub.sound('jukebox', SOUNDS[1]), false);
170
+ assert.equal(busy.hub.seat('p1'), null);
171
+ for (const run of [quiet, busy]) {
172
+ run.tick();
173
+ }
174
+ assert.equal(JSON.stringify(busy.h.join()), JSON.stringify(quiet.h.join()));
175
+ assert.equal(JSON.stringify(busy.h.delta()), JSON.stringify(quiet.h.delta()));
176
+ quiet.tick();
177
+ busy.tick();
178
+ assert.equal(JSON.stringify(busy.h.delta()), JSON.stringify(quiet.h.delta()));
179
+ assert.deepEqual(busy.sent, quiet.sent);
180
+ assert.deepEqual(busy.broadcasts, []);
181
+ assert.equal(busy.world.players.get('p1').at.x, 0);
182
+ });
183
+
184
+ test('a place turns on only the parts it names: each rides the snapshot alone', () => {
185
+ const join = (idle) => Object.keys(boot({ idle }).h.join()).filter((k) => k.startsWith('hubE') || k.startsWith('hubSe') || k.startsWith('hubSo'));
186
+ assert.deepEqual(join({ emotes: true }), ['hubEmotes']);
187
+ assert.deepEqual(join({ seats: true }), ['hubSeated']);
188
+ assert.deepEqual(join({ sounds: SOUNDS }), ['hubSounds']);
189
+ assert.deepEqual(join(true), ['hubEmotes', 'hubSeated']);
190
+ });
191
+
192
+ // --- emotes -------------------------------------------------------------------
193
+
194
+ test('an emote is latched for everyone with when it began and ends, then dropped', () => {
195
+ const { h, say, tick, world } = boot();
196
+ h.delta();
197
+ say('p1', { k: 'hub-emote', id: 'wave' });
198
+ const d = h.delta();
199
+ assert.deepEqual(d.hubEmotes, { p1: { id: 'wave', at: world.timeMs, until: world.timeMs + Idle.EMOTES.wave } });
200
+ assert.equal(h.delta(), null);
201
+ world.timeMs += Idle.EMOTES.wave;
202
+ assert.deepEqual(h.delta().hubEmotes, {});
203
+ tick();
204
+ assert.equal(h.join().hubEmotes.p1, undefined);
205
+ });
206
+
207
+ test('emotes: unknown ids, malformed messages and a player who has not arrived are refused', () => {
208
+ const { h, hub, say } = boot();
209
+ for (const id of ['moonwalk', '', null, 7, 'toString', '__proto__']) {
210
+ say('p1', { k: 'hub-emote', id });
211
+ }
212
+ say('nobody', { k: 'hub-emote', id: 'wave' });
213
+ assert.deepEqual(h.join().hubEmotes, {});
214
+ assert.equal(hub.emote('p1', 'moonwalk'), false);
215
+ assert.equal(hub.emote('nobody', 'wave'), false);
216
+ assert.deepEqual(h.join().hubEmotes, {});
217
+ });
218
+
219
+ test('emotes: one every 2 s per player', () => {
220
+ const { h, say, world } = boot();
221
+ say('p1', { k: 'hub-emote', id: 'wave' });
222
+ world.timeMs += 500;
223
+ say('p1', { k: 'hub-emote', id: 'dance' });
224
+ say('p2', { k: 'hub-emote', id: 'cheer' });
225
+ assert.equal(h.join().hubEmotes.p1.id, 'wave');
226
+ assert.equal(h.join().hubEmotes.p2.id, 'cheer');
227
+ world.timeMs += Idle.EMOTE_EVERY_MS - 500;
228
+ say('p1', { k: 'hub-emote', id: 'dance' });
229
+ assert.equal(h.join().hubEmotes.p1.id, 'dance');
230
+ });
231
+
232
+ test('emotes: the place hook vetoes with false, and a hook that throws vetoes too; hub.emote is the place’s own', () => {
233
+ const calls = [];
234
+ const { h, hub, say, world } = boot({ hooks: { emote: (x, playerId, id) => (calls.push([playerId, id]), id !== 'bow') } });
235
+ say('p1', { k: 'hub-emote', id: 'bow' });
236
+ assert.deepEqual(h.join().hubEmotes, {});
237
+ world.timeMs += Idle.EMOTE_EVERY_MS;
238
+ say('p1', { k: 'hub-emote', id: 'spin' });
239
+ assert.equal(h.join().hubEmotes.p1.id, 'spin');
240
+ assert.deepEqual(calls, [
241
+ ['p1', 'bow'],
242
+ ['p1', 'spin'],
243
+ ]);
244
+ // The place's own call skips the hook and the rate.
245
+ assert.equal(hub.emote('p1', 'bow'), true);
246
+ assert.equal(h.join().hubEmotes.p1.id, 'bow');
247
+ assert.equal(calls.length, 2);
248
+ world.timeMs += 10;
249
+ assert.equal(hub.emote('p1', 'cheer'), true);
250
+ const broken = boot({
251
+ hooks: {
252
+ emote: () => {
253
+ throw new Error('boom');
254
+ },
255
+ },
256
+ });
257
+ broken.say('p1', { k: 'hub-emote', id: 'wave' });
258
+ assert.deepEqual(broken.h.join().hubEmotes, {});
259
+ });
260
+
261
+ test('emotes: a refused emote spends the cooldown, so the hook is asked at most once every 2 s', () => {
262
+ let asked = 0;
263
+ const { h, say, world } = boot({ hooks: { emote: () => ((asked += 1), false) } });
264
+ for (let i = 0; i < 10; i += 1) {
265
+ say('p1', { k: 'hub-emote', id: 'wave' });
266
+ }
267
+ assert.equal(asked, 1);
268
+ const broken = boot({
269
+ hooks: {
270
+ emote: () => {
271
+ asked += 1;
272
+ throw new Error('boom');
273
+ },
274
+ },
275
+ });
276
+ for (let i = 0; i < 10; i += 1) {
277
+ broken.say('p1', { k: 'hub-emote', id: 'wave' });
278
+ }
279
+ assert.equal(asked, 2);
280
+ world.timeMs += Idle.EMOTE_EVERY_MS;
281
+ say('p1', { k: 'hub-emote', id: 'wave' });
282
+ assert.equal(asked, 3);
283
+ assert.deepEqual(h.join().hubEmotes, {});
284
+ });
285
+
286
+ test('emotes: a place with seats only ignores them', () => {
287
+ const { h, hub, say } = boot({ idle: { seats: true } });
288
+ say('p1', { k: 'hub-emote', id: 'wave' });
289
+ assert.equal(hub.emote('p1', 'wave'), false);
290
+ assert.equal('hubEmotes' in h.join(), false);
291
+ });
292
+
293
+ // --- seats --------------------------------------------------------------------
294
+
295
+ test('sitting near a free seat holds the player on it, facing its way, until they stand', () => {
296
+ const calls = [];
297
+ const { h, hub, say, tick, world } = boot({ hooks: { sit: (x, ...args) => calls.push(args) } });
298
+ say('p1', { k: 'hub-sit', seat: 'bench-a' });
299
+ assert.deepEqual(calls, [['p1', 'bench-a']]);
300
+ assert.equal(hub.seat('p1'), 'bench-a');
301
+ const body = world.players.get('p1');
302
+ // On top of the bench (0.25 + 0.25), a standing body's height above it.
303
+ assert.deepEqual(body.at, { x: 1, y: 0.5 + Idle.SIT_BODY, z: 0 });
304
+ assert.ok(Math.abs(body.facing - Math.PI) < 1e-9);
305
+ assert.deepEqual(h.join().hubSeated, { p1: 'bench-a' });
306
+ assert.deepEqual(h.join().held, ['p1']);
307
+ // The hold keeps them there.
308
+ body.at = { x: 3, y: 1.35, z: 0 };
309
+ tick();
310
+ assert.equal(body.at.x, 1);
311
+ // A seat with no face faces its own turn; one with a height is held there.
312
+ say('p2', { k: 'hub-sit', seat: 'stool' });
313
+ assert.deepEqual(world.players.get('p2').at, { x: 0, y: 1.2, z: 1 });
314
+ world.timeMs += 1000;
315
+ say('p1', { k: 'hub-stand' });
316
+ assert.equal(hub.seat('p1'), null);
317
+ assert.deepEqual(h.join().hubSeated, { p2: 'stool' });
318
+ assert.deepEqual(h.join().held, ['p2']);
319
+ });
320
+
321
+ test('seats: one player per seat; too far, not a seat, hidden, or vetoed is refused', () => {
322
+ const { h, hub, say, world } = boot({ hooks: { sit: (x, playerId, seatId) => seatId !== 'bench-b' } });
323
+ say('p1', { k: 'hub-sit', seat: 'bench-a' });
324
+ say('p2', { k: 'hub-sit', seat: 'bench-a' });
325
+ assert.equal(hub.seat('p2'), null);
326
+ world.timeMs += 1000;
327
+ say('p2', { k: 'hub-sit', seat: 'bench-b' });
328
+ say('p2', { k: 'hub-sit', seat: 'far-bench' });
329
+ world.timeMs += 1000;
330
+ say('p2', { k: 'hub-sit', seat: 'jukebox' });
331
+ say('p2', { k: 'hub-sit', seat: { id: 'stool' } });
332
+ hub.hide('stool');
333
+ say('p2', { k: 'hub-sit', seat: 'stool' });
334
+ assert.equal(hub.seat('p2'), null);
335
+ assert.deepEqual(h.join().hubSeated, { p1: 'bench-a' });
336
+ // The first sitter gets up; the seat is free again.
337
+ world.timeMs += 1000;
338
+ say('p1', { k: 'hub-stand' });
339
+ world.players.get('p2').at = { x: 0, y: 1, z: 0 };
340
+ say('p2', { k: 'hub-sit', seat: 'bench-a' });
341
+ assert.equal(hub.seat('p2'), 'bench-a');
342
+ });
343
+
344
+ test('seats: a sit is checked again after the hook, which may have held, ended or seated someone', () => {
345
+ // The hook holds the player itself: its hold stands, no seat.
346
+ let run = boot({ hooks: { sit: (x, playerId) => x.hold(playerId, { x: 5, y: 1, z: 5 }) } });
347
+ run.say('p1', { k: 'hub-sit', seat: 'bench-a' });
348
+ assert.equal(run.hub.seat('p1'), null);
349
+ assert.deepEqual(run.world.players.get('p1').at, { x: 5, y: 1, z: 5 });
350
+ assert.deepEqual(run.h.join().held, ['p1']);
351
+ // The hook ends the player's visit.
352
+ run = boot({ hooks: { sit: (x, playerId) => x.end([playerId]) } });
353
+ run.say('p1', { k: 'hub-sit', seat: 'bench-a' });
354
+ assert.equal(run.hub.seat('p1'), null);
355
+ assert.deepEqual(run.h.join().held, []);
356
+ // The hook hides the seat.
357
+ run = boot({ hooks: { sit: (x, playerId, seatId) => x.hide(seatId) } });
358
+ run.say('p1', { k: 'hub-sit', seat: 'bench-a' });
359
+ assert.equal(run.hub.seat('p1'), null);
360
+ // The hook seats someone else there first (a sit that re-enters).
361
+ let inner = false;
362
+ run = boot({
363
+ hooks: {
364
+ sit: (x, playerId) => {
365
+ if (playerId === 'p1' && !inner) {
366
+ inner = true;
367
+ run.say('p2', { k: 'hub-sit', seat: 'bench-a' });
368
+ }
369
+ },
370
+ },
371
+ });
372
+ run.say('p1', { k: 'hub-sit', seat: 'bench-a' });
373
+ assert.equal(run.hub.seat('p2'), 'bench-a');
374
+ assert.equal(run.hub.seat('p1'), null);
375
+ assert.deepEqual(run.h.join().hubSeated, { p2: 'bench-a' });
376
+ });
377
+
378
+ test('seats: an actor that can move (a dynamic or kinematic Body) is not a seat', () => {
379
+ const { hub, say } = boot();
380
+ say('p1', { k: 'hub-sit', seat: 'cart' });
381
+ assert.equal(hub.seat('p1'), null);
382
+ });
383
+
384
+ test('seats: hub-sit and hub-stand are rate-limited per player', () => {
385
+ const { hub, say } = boot();
386
+ for (let i = 0; i < 6; i += 1) {
387
+ say('p1', { k: 'hub-sit', seat: i % 2 ? 'bench-b' : 'bench-a' });
388
+ }
389
+ // Three went through (a, b, a); the rest were dropped.
390
+ assert.equal(hub.seat('p1'), 'bench-a');
391
+ say('p1', { k: 'hub-stand' });
392
+ assert.equal(hub.seat('p1'), 'bench-a');
393
+ });
394
+
395
+ test('seats and the place’s holds: a held player cannot sit; the place’s hold or release gets a sitter up', () => {
396
+ const { h, hub, say, tick, world } = boot();
397
+ hub.hold('p2');
398
+ say('p2', { k: 'hub-sit', seat: 'bench-b' });
399
+ assert.equal(hub.seat('p2'), null);
400
+ hub.release('p2');
401
+ say('p1', { k: 'hub-sit', seat: 'bench-a' });
402
+ hub.release('p1');
403
+ tick();
404
+ assert.equal(hub.seat('p1'), null);
405
+ assert.deepEqual(h.join().hubSeated, {});
406
+ assert.deepEqual(h.join().held, []);
407
+ // Held by the place while sitting: they stay put, held, but the seat is free.
408
+ world.timeMs += 1000;
409
+ world.players.get('p1').at = { x: 0, y: 1, z: 0 };
410
+ say('p1', { k: 'hub-sit', seat: 'bench-a' });
411
+ assert.equal(hub.seat('p1'), 'bench-a');
412
+ hub.hold('p1');
413
+ tick();
414
+ assert.equal(hub.seat('p1'), null);
415
+ assert.deepEqual(h.join().held, ['p1']);
416
+ say('p1', { k: 'hub-stand' });
417
+ assert.deepEqual(h.join().held, ['p1']);
418
+ world.players.get('p2').at = { x: 1, y: 1, z: 0 };
419
+ say('p2', { k: 'hub-sit', seat: 'bench-a' });
420
+ assert.equal(hub.seat('p2'), 'bench-a');
421
+ // A game's end stands a sitter.
422
+ hub.end(['p2']);
423
+ tick();
424
+ assert.equal(hub.seat('p2'), null);
425
+ });
426
+
427
+ test('seats: a sitter who leaves frees the seat; a hidden seat stands its sitter', () => {
428
+ const { h, hub, say, tick, world, session } = boot();
429
+ say('p1', { k: 'hub-sit', seat: 'bench-a' });
430
+ say('p2', { k: 'hub-sit', seat: 'bench-b' });
431
+ world.players.delete('p1');
432
+ session.players.splice(0, 1);
433
+ tick();
434
+ assert.deepEqual(h.join().hubSeated, { p2: 'bench-b' });
435
+ hub.hide('bench-b');
436
+ tick();
437
+ assert.equal(hub.seat('p2'), null);
438
+ assert.deepEqual(h.join().held, []);
439
+ });
440
+
441
+ test('seats: a sitter who jumps to a door gets up first', () => {
442
+ const { hub, say, world } = boot();
443
+ say('p1', { k: 'hub-sit', seat: 'bench-a' });
444
+ say('p1', { k: 'hub-door-jump', door: 'a' });
445
+ assert.equal(hub.seat('p1'), null);
446
+ assert.ok(world.players.get('p1').at.z < -10);
447
+ });
448
+
449
+ // --- sounds -------------------------------------------------------------------
450
+
451
+ test('a loop is latched at its actor until stopped; one-shots are broadcast', () => {
452
+ const { h, hub, broadcasts, world } = boot();
453
+ h.delta();
454
+ assert.equal(hub.sound('jukebox', SOUNDS[0], { loop: true, volume: 0.6, radius: 12 }), true);
455
+ assert.deepEqual(h.delta().hubSounds, { jukebox: { file: SOUNDS[0], volume: 0.6, radius: 12, since: world.timeMs } });
456
+ assert.equal(hub.sound('lamp', SOUNDS[1], { volume: 3, radius: 500 }), true);
457
+ assert.deepEqual(broadcasts, [{ k: 'hub-sound', actor: 'lamp', file: SOUNDS[1], volume: 1, radius: Idle.RADIUS.max }]);
458
+ assert.equal(hub.sound('jukebox', null), true);
459
+ assert.deepEqual(h.delta().hubSounds, {});
460
+ // A one-shot at an actor replaces the loop playing there.
461
+ assert.equal(hub.sound('jukebox', SOUNDS[0], { loop: true }), true);
462
+ assert.equal(hub.sound('lamp', SOUNDS[0], { loop: true }), true);
463
+ assert.equal(hub.sound('jukebox', SOUNDS[1]), true);
464
+ assert.deepEqual(Object.keys(h.delta().hubSounds), ['lamp']);
465
+ });
466
+
467
+ test('sounds: an undeclared file, an unknown actor, too many loops or one-shots are refused', () => {
468
+ const { h, hub, broadcasts } = boot();
469
+ assert.equal(hub.sound('jukebox', 'sounds/other.mp3', { loop: true }), false);
470
+ assert.equal(hub.sound('nobody', SOUNDS[0], { loop: true }), false);
471
+ assert.deepEqual(h.join().hubSounds, {});
472
+ for (const id of ['spawn', 'bench-a', 'bench-b', 'stool']) {
473
+ assert.equal(hub.sound(id, SOUNDS[0], { loop: true }), true);
474
+ }
475
+ assert.equal(hub.sound('lamp', SOUNDS[0], { loop: true }), false);
476
+ // Replacing a loop at an actor that has one is fine.
477
+ assert.equal(hub.sound('stool', SOUNDS[1], { loop: true }), true);
478
+ assert.equal(Object.keys(h.join().hubSounds).length, Idle.MAX_LOOPS);
479
+ let played = 0;
480
+ for (let i = 0; i < Idle.SHOT_BURST + 3; i += 1) {
481
+ played += hub.sound('lamp', SOUNDS[1]) ? 1 : 0;
482
+ }
483
+ assert.equal(played, Idle.SHOT_BURST);
484
+ assert.equal(broadcasts.length, Idle.SHOT_BURST);
485
+ });
486
+
487
+ test('sounds: a place that declares none refuses them', () => {
488
+ const { h, hub, broadcasts } = boot({ idle: true });
489
+ assert.equal(hub.sound('jukebox', SOUNDS[0], { loop: true }), false);
490
+ assert.equal(hub.sound('jukebox', SOUNDS[0]), false);
491
+ assert.equal('hubSounds' in h.join(), false);
492
+ assert.deepEqual(broadcasts, []);
493
+ });
494
+
495
+ // --- the client's drawing -------------------------------------------------------
496
+
497
+ test('every emote starts and ends at rest, and moves between', () => {
498
+ for (const [id] of ClientIdle.EMOTES) {
499
+ const seconds = Idle.EMOTES[id] / 1000;
500
+ for (const u of [0, 1]) {
501
+ const p = ClientIdle.emotePose(id, u, u * seconds);
502
+ for (const [k, v] of Object.entries(p)) {
503
+ const turn = k === 'ry' ? Math.abs(Math.sin(v)) : Math.abs(v);
504
+ assert.ok(turn < 1e-9, `${id} ${k} at ${u}: ${v}`);
505
+ }
506
+ }
507
+ const mid = ClientIdle.emotePose(id, 0.4, 0.4 * seconds);
508
+ assert.ok(Object.values(mid).some((v) => Math.abs(v) > 0.01), id);
509
+ }
510
+ assert.deepEqual(
511
+ ClientIdle.EMOTES.map(([id]) => id),
512
+ Object.keys(Idle.EMOTES),
513
+ );
514
+ assert.equal(ClientIdle.emotePose('moonwalk', 0.5, 1), null);
515
+ });
516
+
517
+ console.warn = warn;
518
+ console.log(`test-idle: ${n} passed`);