castle-web-cli 0.4.231 → 0.4.232

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 (55) hide show
  1. package/dist/serverBundle.js +5 -3
  2. package/kits/hub-game/CLAUDE.md +26 -4
  3. package/kits/hub-game/code/client/avatar.js +39 -0
  4. package/kits/hub-game/code/client/chat.js +12 -0
  5. package/kits/hub-game/code/client/chrome.js +194 -4
  6. package/kits/hub-game/code/client/grab.js +31 -7
  7. package/kits/hub-game/code/client/hats.js +26 -0
  8. package/kits/hub-game/code/client/hookLayer.js +30 -3
  9. package/kits/hub-game/code/client/hudClear.js +126 -0
  10. package/kits/hub-game/code/client/state.js +22 -0
  11. package/kits/hub-game/code/client/tiers.js +31 -6
  12. package/kits/hub-game/code/client/together.js +66 -1
  13. package/kits/hub-game/code/client/wear.js +96 -14
  14. package/kits/hub-game/code/server/actors.js +5 -0
  15. package/kits/hub-game/code/server/grab.js +296 -11
  16. package/kits/hub-game/code/server/hub.js +63 -2
  17. package/kits/hub-game/code/server/manifest.js +48 -3
  18. package/kits/hub-game/code/server/party.js +11 -0
  19. package/kits/hub-game/code/server/say.js +8 -2
  20. package/kits/hub-game/code/server/wear.js +116 -11
  21. package/kits/hub-game/code/systems/hub.js +253 -5
  22. package/kits/hub-game/docs/contract.md +204 -8
  23. package/kits/hub-game/package.json +1 -1
  24. package/kits/hub-game/scripts/test-chat.mjs +32 -0
  25. package/kits/hub-game/scripts/test-grab-client.mjs +186 -3
  26. package/kits/hub-game/scripts/test-grab.mjs +857 -3
  27. package/kits/hub-game/scripts/test-hats.mjs +229 -0
  28. package/kits/hub-game/scripts/test-hub-trip.mjs +513 -0
  29. package/kits/hub-game/scripts/test-hud-clear.mjs +676 -0
  30. package/kits/hub-game/scripts/test-manifest.mjs +75 -0
  31. package/kits/hub-game/scripts/test-party.mjs +22 -1
  32. package/kits/hub-game/scripts/test-say.mjs +59 -2
  33. package/kits/hub-game/scripts/test-tiers.mjs +190 -2
  34. package/kits/hub-game/scripts/test-try-on.mjs +940 -0
  35. package/kits/physics-2d/castle.json +1 -1
  36. package/kits/physics-2d/engine/scene.js +35 -0
  37. package/kits/physics-2d/scripts/test-skip-unchanged.mjs +44 -0
  38. package/kits/physics-3d/CLAUDE.md +252 -0
  39. package/kits/physics-3d/behaviors/Player.jsx +363 -2
  40. package/kits/physics-3d/castle.json +2 -2
  41. package/kits/physics-3d/docs/pxmodel-format.md +4 -0
  42. package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +32 -0
  43. package/kits/physics-3d/engine3d/optimize.js +49 -0
  44. package/kits/physics-3d/engine3d/orbitinput.js +277 -0
  45. package/kits/physics-3d/engine3d/world3d.js +81 -25
  46. package/kits/physics-3d/scripts/Player.before-orbit.mjs +310 -0
  47. package/kits/physics-3d/scripts/Scene3DPlayer.before-orbit.jsx +337 -0
  48. package/kits/physics-3d/scripts/test-camera-follow.mjs +12 -2
  49. package/kits/physics-3d/scripts/test-camera-orbit.mjs +2105 -0
  50. package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +787 -0
  51. package/kits/physics-3d/scripts/test-static-actors.mjs +6 -1
  52. package/kits/physics-3d/scripts/test-static-passes.mjs +1 -1
  53. package/kits/physics-3d/scripts/test-steady-hover.mjs +633 -0
  54. package/kits/physics-3d/systems/physics3d.js +91 -6
  55. package/package.json +1 -1
@@ -62,6 +62,18 @@ test("tiers: the deck's, true or false", () => {
62
62
  assert.match(errors.join('\n'), /hub\.places\.arena\.tiers is not part/);
63
63
  });
64
64
 
65
+ test("cues: the deck's, true or false, and off unless asked for", () => {
66
+ assert.deepEqual(readManifest(base({ cues: true }), has).errors, []);
67
+ assert.deepEqual(readManifest(base({ cues: false }), has).errors, []);
68
+ assert.match(readManifest(base({ cues: 'yes' }), has).errors.join(), /hub\.cues must be true or false/);
69
+ const { errors } = readManifest(base({ places: { arena: { title: 'Arena', scene: 'scenes/arena.scene', cues: true } } }), has);
70
+ assert.match(errors.join('\n'), /hub\.places\.arena\.cues is not part/);
71
+ // The server reads it off the manifest: on only for `true`.
72
+ assert.equal(readManifest(base({ cues: true }), has).manifest.cues, true);
73
+ assert.equal(readManifest(base({ cues: false }), has).manifest.cues, false);
74
+ assert.equal(readManifest(base(), has).manifest.cues, false);
75
+ });
76
+
65
77
  test('player counts', () => {
66
78
  assert.match(readManifest(base({ minPlayers: 5, maxPlayers: 4 }), has).errors.join(), /more than maxPlayers/);
67
79
  assert.match(readManifest(base({ maxPlayers: 12 }), has).errors.join(), /server\.maxPlayers/);
@@ -169,6 +181,69 @@ test('grab.reach and grab.steady (v1.22): kept only when set, bounded, and the r
169
181
  assert.ok(GRAB_REACH_LIMITS[1] < SERVER_GRAB_REACH);
170
182
  });
171
183
 
184
+ test('hud.clear (v1.26): a place carries it only when true, and one without it is read and sent as before', () => {
185
+ const read = (hud, rest = {}) => readManifest(base(hud === undefined ? rest : { hud, ...rest }), has);
186
+ const before = read(undefined, { grab: true, idle: true, result: {} });
187
+ // Left out, empty, or false: exactly the place, and the client message, of before.
188
+ for (const hud of [undefined, {}, { clear: false }]) {
189
+ const { errors, manifest } = read(hud, { grab: true, idle: true, result: {} });
190
+ assert.deepEqual(errors, []);
191
+ assert.ok(!('hud' in manifest.places.main));
192
+ assert.deepEqual(manifest, before.manifest);
193
+ const sent = publicPlace('main', manifest.places.main);
194
+ assert.ok(!('hud' in sent));
195
+ assert.deepEqual(sent, publicPlace('main', before.manifest.places.main));
196
+ assert.equal(JSON.stringify(sent), JSON.stringify(publicPlace('main', before.manifest.places.main)), 'the same keys in the same order');
197
+ }
198
+ assert.deepEqual(Object.keys(publicPlace('main', before.manifest.places.main)), ['contract', 'id', 'title', 'scene', 'controller', 'maxDurationSec', 'grab', 'idle', 'result']);
199
+ // Asked: on the place, and told to the client.
200
+ const asked = read({ clear: true }, { grab: true, idle: true, result: {} });
201
+ assert.deepEqual(asked.errors, []);
202
+ assert.deepEqual(asked.manifest.places.main.hud, { clear: true });
203
+ const sent = publicPlace('main', asked.manifest.places.main);
204
+ assert.deepEqual(sent.hud, { clear: true });
205
+ const { hud: _hud, ...rest } = sent;
206
+ assert.deepEqual(rest, publicPlace('main', before.manifest.places.main), 'nothing else of the message moves');
207
+ // A place's own, in a deck of several: one asks, the other is as it was.
208
+ const two = readManifest(base({ places: { arena: { title: 'Arena', scene: 'scenes/race.scene', hud: { clear: true } } } }), has);
209
+ assert.deepEqual(two.errors, []);
210
+ assert.deepEqual(two.manifest.places.arena.hud, { clear: true });
211
+ assert.ok(!('hud' in two.manifest.places.main));
212
+ // Anything else is refused, not ignored.
213
+ for (const clear of ['yes', 1, 0, null, {}, []]) {
214
+ assert.match(read({ clear }).errors.join(), /hub\.hud\.clear must be true or false/);
215
+ assert.equal(read({ clear }).manifest, null);
216
+ }
217
+ for (const hud of [true, false, 'clear', 1, null, []]) {
218
+ assert.match(read(hud).errors.join(), /hub\.hud must be an object/);
219
+ }
220
+ assert.match(read({ clear: true, big: 32 }).errors.join(), /hub\.hud\.big is not part/);
221
+ assert.match(read({ Clear: true }).errors.join(), /hub\.hud\.Clear is not part/);
222
+ assert.match(
223
+ readManifest(base({ places: { arena: { title: 'Arena', scene: 'scenes/race.scene', hud: { clear: 'on' } } } }), has).errors.join(),
224
+ /places\.arena\.hud\.clear must be true or false/,
225
+ );
226
+ });
227
+
228
+ test('grab.keepHeld (v1.25): kept only when true, true or false, and the rest unchanged', () => {
229
+ const place = (grab) => readManifest(base({ grab }), has);
230
+ for (const grab of [true, {}, { throwSpeed: 6 }, { keepHeld: false }]) {
231
+ const read = place(grab).manifest.places.main.grab;
232
+ assert.ok(!('keepHeld' in read));
233
+ assert.deepEqual(Object.keys(publicPlace('main', place(grab).manifest.places.main).grab), Object.keys(GRAB_DEFAULTS));
234
+ }
235
+ assert.deepEqual(place({ keepHeld: true }).manifest.places.main.grab, { ...GRAB_DEFAULTS, keepHeld: true });
236
+ assert.deepEqual(publicPlace('main', place({ keepHeld: true, steady: true }).manifest.places.main).grab, {
237
+ ...GRAB_DEFAULTS,
238
+ steady: true,
239
+ keepHeld: true,
240
+ });
241
+ for (const keepHeld of ['yes', 1, null, {}]) {
242
+ assert.match(place({ keepHeld }).errors.join(), /grab\.keepHeld must be true or false/);
243
+ }
244
+ assert.match(place({ keepheld: true }).errors.join(), /hub\.grab\.keepheld is not part/);
245
+ });
246
+
172
247
  test('results are checked against the declared shape', () => {
173
248
  const { manifest } = readManifest(
174
249
  base({ result: { outcomes: ['win', 'lose'], score: { min: 0, max: 100 }, stats: { kart: 'string' } } }),
@@ -6,7 +6,7 @@
6
6
  // installed.
7
7
 
8
8
  import assert from 'node:assert/strict';
9
- import { padPoint } from '../code/server/party.js';
9
+ import { padPoint, proposalDoor } from '../code/server/party.js';
10
10
  import { register } from 'node:module';
11
11
 
12
12
  const sceneStub = 'export const readScene = () => globalThis.__hubTestActors ?? [];';
@@ -366,4 +366,25 @@ let n = 0;
366
366
  n += 1;
367
367
  }
368
368
 
369
+ // Cues (contract v1.23): the door of a player's live proposal, for "Let's
370
+ // play…" -- the proposer's and each member still asked, nobody else's, and
371
+ // not once it is answered or has run out.
372
+ {
373
+ const now = Date.now();
374
+ const h = {
375
+ players: new Map([['p1', { userId: '101' }], ['p2', { userId: '102' }], ['p3', { userId: '103' }], ['g4', { userId: null }]]),
376
+ party: {
377
+ of: new Map([['u:101', 'party-1'], ['u:102', 'party-1'], ['u:103', 'party-1'], ['p:g4', 'party-2']]),
378
+ proposals: new Map(),
379
+ },
380
+ };
381
+ const doors = () => ['p1', 'p2', 'p3', 'g4', 'nobody'].map((id) => proposalDoor(h, id));
382
+ assert.deepEqual(doors(), [null, null, null, null, null], 'no proposal');
383
+ h.party.proposals.set('party-1', { id: 1, door: 'race', by: 'p1', until: now + 45000, asked: new Set(['p2']) });
384
+ assert.deepEqual(doors(), ['race', 'race', null, null, null], 'the proposer and the member still asked');
385
+ h.party.proposals.get('party-1').until = now - 1;
386
+ assert.deepEqual(doors(), [null, null, null, null, null], 'run out');
387
+ n += 1;
388
+ }
389
+
369
390
  console.log(`test-party: ${n} passed`);
@@ -25,6 +25,7 @@ const { makeSay, REACTIONS } = await import('../code/client/say.js');
25
25
  globalThis.__hubTestActors = [
26
26
  { id: 'spawn', components: { Player: {}, Transform: { x: 0, y: 1, z: 0 } } },
27
27
  { id: 'door-race', components: { HubDoor: { id: 'race', to: 'race' }, Transform: { x: -28, y: 1.4, z: 0, rotationY: 90 } } },
28
+ { id: 'door-gems', components: { HubDoor: { id: 'gems', to: 'race', title: 'Gem Rush' }, Transform: { x: 60, y: 1.4, z: 0, rotationY: 270 } } },
28
29
  ];
29
30
  const castleJson = {
30
31
  server: { maxPlayers: 8 },
@@ -37,8 +38,8 @@ const castleJson = {
37
38
  const sceneExists = (scene) => ['scenes/main.scene', 'scenes/race.scene'].includes(scene);
38
39
  const ROSTER = ['p1', 'p2', 'p3'].map((playerId, i) => ({ playerId, userId: String(101 + i), username: playerId }));
39
40
 
40
- function boot({ sessionId = 'dev:test', hiddenPair = null } = {}) {
41
- const h = layer(castleJson, {}, {}, sceneExists);
41
+ function boot({ sessionId = 'dev:test', hiddenPair = null, cues = undefined } = {}) {
42
+ const h = layer(cues === undefined ? castleJson : { ...castleJson, hub: { ...castleJson.hub, cues } }, {}, {}, sceneExists);
42
43
  const sent = [];
43
44
  const session = {
44
45
  sessionId,
@@ -66,6 +67,8 @@ function boot({ sessionId = 'dev:test', hiddenPair = null } = {}) {
66
67
  const say = (b, playerId, data) => b.h.message(b.session, { playerId }, { k: 'hub-say', ...data });
67
68
  const said = (b) => b.sent.filter(([, msg]) => msg.k === 'hub-said');
68
69
 
70
+ // The phrase id the kit once had and no longer does.
71
+ const GONE = 'join';
69
72
  let n = 0;
70
73
 
71
74
  // A reaction and a phrase go to everyone; text, an unknown id and a game's
@@ -116,6 +119,51 @@ let n = 0;
116
119
  n += 1;
117
120
  }
118
121
 
122
+ // Cues (contract v1.23). "Let's play" names the door of the speaker's open
123
+ // party proposal first; a deck without cues names the door they stand by, as
124
+ // it always did.
125
+ const party = (b, playerId, data) => b.h.message(b.session, { playerId }, { k: 'hub-party', ...data });
126
+ for (const cues of [true, false, undefined]) {
127
+ const b = boot({ cues });
128
+ party(b, 'p1', { op: 'invite', player: 'p2' });
129
+ party(b, 'p2', { op: 'accept', from: 'p1' });
130
+ party(b, 'p1', { op: 'go', door: 'race' });
131
+ // p2 was asked and has not answered; they stand by another door, p3 by none.
132
+ Object.assign(b.world.players.get('p2').at, { x: 55, z: 0 });
133
+ say(b, 'p2', { p: 'play' });
134
+ say(b, 'p1', { p: 'play' });
135
+ say(b, 'p3', { p: 'play' });
136
+ assert.deepEqual(said(b).map(([, msg]) => msg.door), cues ? ['race', 'race', null] : ['gems', 'race', null], `cues ${cues}`);
137
+ // Answered: the proposal is no longer p2's, who names the door they stand by.
138
+ b.h.place(b.world, []);
139
+ b.h.step(b.world, []);
140
+ const id = b.sent.filter(([to, msg]) => to === 'p2' && msg.k === 'hub-party').at(-1)[1].proposal.id;
141
+ party(b, 'p2', { op: 'go-no', id });
142
+ const realNow = Date.now;
143
+ Date.now = () => realNow() + 5000;
144
+ say(b, 'p2', { p: 'play' });
145
+ Date.now = realNow;
146
+ assert.equal(said(b).at(-1)[1].door, 'gems', `cues ${cues}: answered`);
147
+ n += 1;
148
+ }
149
+
150
+ // There is no `join` phrase, with cues or without: it is an unknown id like
151
+ // any other, whatever came before it and whatever it carries. And a `door` a
152
+ // client puts on "Let's play" is never read.
153
+ for (const cues of [true, false, undefined]) {
154
+ const b = boot({ cues });
155
+ party(b, 'p1', { op: 'invite', player: 'p2' });
156
+ party(b, 'p2', { op: 'accept', from: 'p1' });
157
+ b.h.message(b.session, { playerId: 'p1' }, { k: 'hub-door-jump', door: 'race' });
158
+ say(b, 'p1', { p: GONE, door: 'race', to: ['p2', 'p3'] });
159
+ say(b, 'p1', { p: GONE });
160
+ assert.deepEqual(said(b), [], `cues ${cues}: join is refused`);
161
+ Object.assign(b.world.players.get('p3').at, { x: 0, z: 0 });
162
+ say(b, 'p3', { p: 'play', door: 'race' });
163
+ assert.deepEqual(said(b), [['*', { k: 'hub-said', player: 'p3', p: 'play', door: null }]], 'the door a client names is ignored');
164
+ n += 1;
165
+ }
166
+
119
167
  // The client words what was said: bubbles, the feed, and "Over here!" heard.
120
168
  {
121
169
  HubState.hub.place = { title: 'Town', result: null };
@@ -141,6 +189,15 @@ let n = 0;
141
189
  s.frame(30000, 'me', () => 'bo');
142
190
  s.clear();
143
191
  assert.deepEqual(s.feed(), []);
192
+ // A phrase the kit does not have (`join`, say) is skipped, cues or not.
193
+ for (const cues of [true, false]) {
194
+ HubState.deck.cues = cues;
195
+ const plays = [];
196
+ HubState.hub.saidEvents.push({ player: 'p2', p: GONE, door: 'race' }, { player: 'me', p: GONE, door: 'race' });
197
+ s.frame(40000, 'me', () => 'bo', () => {}, (...args) => plays.push(args));
198
+ assert.deepEqual([plays, s.feed(), s.labels(scene, { id: 'local' }, null, null, (cam, x) => ({ x, y: 0 }), 'me')], [[], [], []], `cues ${cues}`);
199
+ }
200
+ HubState.deck.cues = false;
144
201
  HubState.hub.place = null;
145
202
  HubState.hub.doors = [];
146
203
  n += 1;
@@ -2,7 +2,8 @@
2
2
  // GPU, its memory, a slow visit remembered for a week), the frame-time judge
3
3
  // (median windows, never back up, hidden pages and swaps ignored), storage that
4
4
  // throws, the player's own Auto / Low / High winning, and the low picture's
5
- // levers put on and taken off exactly on a fake physics-3d world. Last, the hub
5
+ // levers put on and taken off exactly on a fake physics-3d world (with the
6
+ // scene file's `"tier": "keep"` mark: an actor drawn on every tier). Last, the hub
6
7
  // system with the deck's `hub.tiers` absent: nothing of the tiers is made, run
7
8
  // or read. `npm run check` runs this.
8
9
 
@@ -12,6 +13,7 @@ import { register } from 'node:module';
12
13
  import {
13
14
  CHECK_EVERY_MS,
14
15
  FIRST_WINDOW_MS,
16
+ KEEP,
15
17
  MODE_KEY,
16
18
  REMEMBER_MS,
17
19
  TIER_KEY,
@@ -358,7 +360,8 @@ function fakeWorld(actors) {
358
360
  content: null,
359
361
  data: {},
360
362
  scenePath: 'scenes/main.scene',
361
- readFromFile: () => ({ actors: actors.filter((a) => !a.spawned).map((a) => ({ id: a.id })) }),
363
+ // The scene file: an actor's id and, where it has one, its `tier` mark.
364
+ readFromFile: () => ({ actors: actors.filter((a) => !a.spawned).map((a) => ('tier' in a ? { id: a.id, tier: a.tier } : { id: a.id })) }),
362
365
  getActor: (id) => byId.get(id),
363
366
  };
364
367
  return { world, scene, sun, sky, touched, parents: () => new Map([...world.nodes].map(([id, e]) => [id, e.node.parent])) };
@@ -579,6 +582,191 @@ test('levers: a hidden node the engine rebuilds in place is taken out at once (r
579
582
  assert.equal(drawn(world, 'npc-far'), false);
580
583
  });
581
584
 
585
+ // `"tier": "keep"` on an actor in the scene file: drawn on every tier.
586
+
587
+ const GROUND = { Transform: {}, Shape: {}, Model: {} };
588
+ const WALL = { Transform: {}, Shape: {}, Solid: {} };
589
+ const NPC = { Transform: {}, Body: {}, HubNpc: {}, Model: {} };
590
+ const MARKED = [
591
+ { id: 'paving', components: GROUND, at: [0, 0, 0], tier: 'keep' },
592
+ { id: 'grass-far', components: GROUND, at: [90, 0, 0], tier: 'keep' },
593
+ { id: 'tower-far', components: WALL, at: [70, 0, 0], tier: 'keep' },
594
+ { id: 'guide-far', components: NPC, at: [0, 0, 40], tier: 'keep' },
595
+ // Unmarked, and marked with something that is no mark: as before.
596
+ { id: 'lamp', components: GROUND, at: [3, 0, 3] },
597
+ { id: 'wall-near', components: WALL, at: [10, 0, 0] },
598
+ { id: 'wall-far', components: WALL, at: [60, 0, 0] },
599
+ { id: 'npc-far', components: NPC, at: [0, 0, 25] },
600
+ { id: 'vase', components: GROUND, at: [2, 0, 2], tier: 'low' },
601
+ { id: 'urn', components: GROUND, at: [2, 0, 4], tier: true },
602
+ { id: 'pot', components: GROUND, at: [2, 0, 6], tier: 'Keep' },
603
+ { id: 'bush', components: GROUND, at: [2, 0, 8], tier: null },
604
+ // A spawned actor is not in the file: never hidden, mark or none.
605
+ { id: 'wear:p1:0', components: GROUND, at: [1, 0, 1], spawned: true },
606
+ ];
607
+
608
+ test('keep: a marked actor is drawn on Low whatever it is; unmarked ones and other values are as before', () => {
609
+ assert.equal(KEEP, 'keep');
610
+ const { world, scene } = fakeWorld(MARKED);
611
+ const lv = makeLevers({ boundsOf: bounds(0) });
612
+ lv.apply(world, scene, 0);
613
+ assert.equal(drawn(world, 'paving'), true, 'marked decor is drawn');
614
+ assert.equal(drawn(world, 'grass-far'), true, 'at any distance');
615
+ assert.equal(drawn(world, 'tower-far'), true, 'marked scenery past 30 m stays');
616
+ assert.equal(drawn(world, 'guide-far'), true, 'a marked NPC body past 20 m stays');
617
+ assert.equal(drawn(world, 'lamp'), false);
618
+ assert.equal(drawn(world, 'wall-near'), true);
619
+ assert.equal(drawn(world, 'wall-far'), false);
620
+ assert.equal(drawn(world, 'npc-far'), false);
621
+ for (const id of ['vase', 'urn', 'pot', 'bush']) {
622
+ assert.equal(drawn(world, id), false, `${id}: only "keep" is the mark`);
623
+ }
624
+ assert.equal(drawn(world, 'wear:p1:0'), true);
625
+ assert.equal(lv.hidden, 7);
626
+ assert.deepEqual([...lv.kept].sort(), ['grass-far', 'guide-far', 'paving', 'tower-far']);
627
+ // The next looks keep them, from wherever the camera stands.
628
+ world.camera.position = { x: -200, y: 2, z: -200 };
629
+ lv.apply(world, scene, CHECK_EVERY_MS + 1);
630
+ for (const id of ['paving', 'grass-far', 'tower-far', 'guide-far']) {
631
+ assert.equal(drawn(world, id), true, id);
632
+ }
633
+ assert.equal(drawn(world, 'wall-near'), false, 'unmarked scenery now far is not');
634
+ });
635
+
636
+ test('keep: High, Low, High leaves every node attached where it was', () => {
637
+ const { world, scene, parents } = fakeWorld(MARKED);
638
+ const before = parents();
639
+ const t = makeTiers({ storage: memoryStorage(), deviceMemory: 8, levers: makeLevers({ boundsOf: bounds(0) }) });
640
+ const s = { ...scene, three: world };
641
+ let now = 0;
642
+ const frames = () => {
643
+ for (let i = 0; i < 3; i += 1) {
644
+ t.frame(s, true, (now += 16));
645
+ }
646
+ };
647
+ t.handle.set('high');
648
+ frames();
649
+ assert.deepEqual(parents(), before);
650
+ t.handle.set('low');
651
+ frames();
652
+ assert.equal(drawn(world, 'paving'), true);
653
+ assert.equal(drawn(world, 'tower-far'), true);
654
+ assert.equal(drawn(world, 'lamp'), false);
655
+ assert.equal(t.handle.hidden, 7);
656
+ t.handle.set('high');
657
+ frames();
658
+ assert.deepEqual(parents(), before, 'everything attached again');
659
+ assert.equal(t.handle.hidden, 0);
660
+ });
661
+
662
+ test('keep: a scene with no marks keeps no list and reads its file as often as before', () => {
663
+ const { world, scene } = fakeWorld(TOWN);
664
+ let reads = 0;
665
+ scene.readFromFile = ((read) => (path) => {
666
+ reads += 1;
667
+ return read(path);
668
+ })(scene.readFromFile);
669
+ const lv = makeLevers({ boundsOf: bounds(0) });
670
+ lv.apply(world, scene, 0);
671
+ assert.equal(lv.kept, null, 'no set is made');
672
+ assert.equal(lv.hidden, 3, 'what the town hid before');
673
+ for (let i = 1; i <= 5; i += 1) {
674
+ lv.apply(world, scene, i * (CHECK_EVERY_MS + 1));
675
+ }
676
+ assert.equal(reads, 1, 'the file is read once per scene, marks and ids together');
677
+ assert.equal(lv.kept, null);
678
+ // A scene whose file cannot be read hides nothing and keeps no list.
679
+ const broken = fakeWorld(MARKED);
680
+ broken.scene.readFromFile = () => {
681
+ throw new Error('scene file not found');
682
+ };
683
+ const lv2 = makeLevers({ boundsOf: bounds(0) });
684
+ lv2.apply(broken.world, broken.scene, 0);
685
+ assert.equal(lv2.hidden, 0);
686
+ assert.equal(lv2.kept, null);
687
+ });
688
+
689
+ test('keep: the marks follow the scene -- one hidden is put back when marked, another scene has its own, another world none', () => {
690
+ const actors = MARKED.map((a) => ({ ...a }));
691
+ const { world, scene } = fakeWorld(actors);
692
+ let reads = 0;
693
+ scene.readFromFile = ((read) => (path) => {
694
+ reads += 1;
695
+ return read(path);
696
+ })(scene.readFromFile);
697
+ const lv = makeLevers({ boundsOf: bounds(0) });
698
+ lv.apply(world, scene, 0);
699
+ assert.equal(drawn(world, 'lamp'), false);
700
+ assert.equal(drawn(world, 'paving'), true);
701
+ // The scene loaded again (new scene data) with the marks moved: the lamp
702
+ // gains one and is put back, the paving loses its and goes.
703
+ actors.find((a) => a.id === 'lamp').tier = 'keep';
704
+ delete actors.find((a) => a.id === 'paving').tier;
705
+ lv.apply(world, scene, CHECK_EVERY_MS + 1);
706
+ assert.equal(drawn(world, 'lamp'), false, 'the same scene data: the file is not read again');
707
+ assert.equal(reads, 1);
708
+ scene.data = {};
709
+ lv.apply(world, scene, 2 * (CHECK_EVERY_MS + 1));
710
+ assert.equal(reads, 2);
711
+ assert.equal(drawn(world, 'lamp'), true, 'hidden before, marked now: put back');
712
+ assert.equal(drawn(world, 'paving'), false, 'no longer marked: decor again');
713
+ assert.equal(drawn(world, 'tower-far'), true);
714
+ // Another scene with no marks at all: the list is dropped.
715
+ for (const a of actors) {
716
+ delete a.tier;
717
+ }
718
+ scene.data = {};
719
+ world.scenePath = 'scenes/other.scene';
720
+ lv.apply(world, scene, 3 * (CHECK_EVERY_MS + 1));
721
+ assert.equal(lv.kept, null);
722
+ assert.equal(drawn(world, 'lamp'), false);
723
+ assert.equal(drawn(world, 'tower-far'), false);
724
+ assert.equal(drawn(world, 'guide-far'), false);
725
+ // A game through a door (another deck's content) hides nothing either way.
726
+ lv.apply(world, scene, 4 * (CHECK_EVERY_MS + 1), { actors: false });
727
+ assert.equal(lv.hidden, 0);
728
+ // Another world starts with no marks remembered.
729
+ const other = fakeWorld(TOWN);
730
+ lv.kept = new Set(['lamp']);
731
+ lv.apply(other.world, other.scene, 5 * (CHECK_EVERY_MS + 1));
732
+ assert.equal(lv.kept, null);
733
+ assert.equal(drawn(other.world, 'lamp'), false);
734
+ });
735
+
736
+ test('keep: a reload that adds the mark puts the node back on the very next frame, not at the next look (review P2)', () => {
737
+ const actors = MARKED.map((a) => ({ ...a }));
738
+ const { world, scene } = fakeWorld(actors);
739
+ const lv = makeLevers({ boundsOf: bounds(0) });
740
+ lv.apply(world, scene, 0);
741
+ assert.equal(drawn(world, 'lamp'), false);
742
+ assert.equal(drawn(world, 'paving'), true);
743
+ const nodes = world.nodes;
744
+ const size = nodes.size;
745
+ // The same scene loaded again: the same path, the same nodes map and
746
+ // nodes, new scene data, and the file now marks the lamp and not the paving.
747
+ actors.find((a) => a.id === 'lamp').tier = 'keep';
748
+ delete actors.find((a) => a.id === 'paving').tier;
749
+ scene.data = {};
750
+ lv.apply(world, scene, 16);
751
+ assert.equal(world.nodes, nodes);
752
+ assert.equal(world.nodes.size, size);
753
+ assert.equal(drawn(world, 'lamp'), true, 'back 16 ms later, well inside the 500 ms');
754
+ assert.equal(drawn(world, 'paving'), false, 'and the one no longer marked is out');
755
+ // With the scene data unchanged the next frames wait for the look as before.
756
+ let reads = 0;
757
+ scene.readFromFile = ((read) => (path) => {
758
+ reads += 1;
759
+ return read(path);
760
+ })(scene.readFromFile);
761
+ world.camera.position = { x: 60, y: 2, z: 0 };
762
+ lv.apply(world, scene, 32);
763
+ lv.apply(world, scene, 48);
764
+ assert.equal(drawn(world, 'wall-far'), false, 'no look between looks');
765
+ assert.equal(reads, 0);
766
+ lv.apply(world, scene, 16 + CHECK_EVERY_MS + 1);
767
+ assert.equal(drawn(world, 'wall-far'), true);
768
+ });
769
+
582
770
  // The hub system with `hub.tiers` absent: never a call into tiers.js, never a
583
771
  // storage read, no harness handle. tiers.js is stubbed for hub.js so any call
584
772
  // is counted.