castle-web-cli 0.4.230 → 0.4.231

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 (69) hide show
  1. package/dist/castle-host/host.js +81 -0
  2. package/dist/devSaveStorage.d.ts +36 -0
  3. package/dist/devSaveStorage.js +469 -0
  4. package/dist/devSessionChild.js +22 -12
  5. package/dist/devSessionServer.js +8 -2
  6. package/dist/devSessionStorage.d.ts +9 -0
  7. package/dist/devSessionStorage.js +66 -1
  8. package/dist/init.js +1 -1
  9. package/dist/serve.js +5 -1
  10. package/kits/base/castle.json +1 -1
  11. package/kits/base/sdk/README.md +148 -1
  12. package/kits/base/sdk/castle.d.ts +4 -0
  13. package/kits/base/sdk/castle.js +2 -0
  14. package/kits/base/sdk/commands.d.ts +15 -0
  15. package/kits/base/sdk/multiplayer.js +52 -4
  16. package/kits/base/sdk/save.d.ts +197 -0
  17. package/kits/base/sdk/save.js +525 -0
  18. package/kits/base/sdk/saveCoordinator.d.ts +39 -0
  19. package/kits/base/sdk/saveCoordinator.js +252 -0
  20. package/kits/base/sdk/server/storage.d.ts +3 -2
  21. package/kits/base/sdk/server/storage.js +25 -5
  22. package/kits/base/sdk/server/wrapper.d.ts +4 -0
  23. package/kits/base/sdk/server/wrapper.js +2 -0
  24. package/kits/base/sdk/store.d.ts +3 -2
  25. package/kits/base/sdk/store.js +5 -0
  26. package/kits/hub-game/CLAUDE.md +4 -1
  27. package/kits/hub-game/code/client/chrome.js +43 -9
  28. package/kits/hub-game/code/client/grab.js +142 -7
  29. package/kits/hub-game/code/client/hookLayer.js +7 -1
  30. package/kits/hub-game/code/client/state.js +13 -1
  31. package/kits/hub-game/code/client/talk.js +10 -36
  32. package/kits/hub-game/code/client/tiers.js +480 -0
  33. package/kits/hub-game/code/client/together.js +78 -3
  34. package/kits/hub-game/code/server/grab.js +3 -2
  35. package/kits/hub-game/code/server/hub.js +99 -5
  36. package/kits/hub-game/code/server/manifest.js +34 -7
  37. package/kits/hub-game/code/server/npcs.js +21 -33
  38. package/kits/hub-game/code/server/party.js +64 -6
  39. package/kits/hub-game/code/systems/hub.js +133 -16
  40. package/kits/hub-game/docs/contract.md +84 -14
  41. package/kits/hub-game/package.json +1 -1
  42. package/kits/hub-game/scripts/test-grab-client.mjs +328 -0
  43. package/kits/hub-game/scripts/test-hub-trip.mjs +208 -0
  44. package/kits/hub-game/scripts/test-manifest.mjs +47 -1
  45. package/kits/hub-game/scripts/test-npcs.mjs +34 -24
  46. package/kits/hub-game/scripts/test-party.mjs +87 -4
  47. package/kits/hub-game/scripts/test-tiers.mjs +666 -0
  48. package/kits/hub-game/scripts/test-together.mjs +33 -1
  49. package/kits/physics-2d/CLAUDE.md +2 -0
  50. package/kits/physics-2d/castle.json +2 -2
  51. package/kits/physics-2d/engine/scene.js +92 -0
  52. package/kits/physics-2d/package.json +1 -1
  53. package/kits/physics-2d/scripts/test-skip-unchanged.mjs +254 -0
  54. package/kits/physics-3d/CLAUDE.md +279 -0
  55. package/kits/physics-3d/behaviors/Player.jsx +74 -1
  56. package/kits/physics-3d/castle.json +3 -3
  57. package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +1 -1
  58. package/kits/physics-3d/engine3d/actornode.js +253 -0
  59. package/kits/physics-3d/engine3d/nearshadows.js +600 -0
  60. package/kits/physics-3d/engine3d/unchanged.js +153 -0
  61. package/kits/physics-3d/engine3d/world3d.js +465 -7
  62. package/kits/physics-3d/package.json +1 -1
  63. package/kits/physics-3d/scripts/test-camera-follow.mjs +533 -0
  64. package/kits/physics-3d/scripts/test-near-shadows.mjs +1073 -0
  65. package/kits/physics-3d/scripts/test-static-actors.mjs +662 -0
  66. package/kits/physics-3d/scripts/test-static-passes.mjs +459 -0
  67. package/kits/physics-3d/scripts/test-static-physics.mjs +128 -0
  68. package/kits/physics-3d/systems/physics3d.js +182 -3
  69. package/package.json +1 -1
@@ -123,7 +123,27 @@ let n = 0;
123
123
  n += 1;
124
124
  }
125
125
 
126
- // Join puts a player beside the other, facing them, and tells their camera.
126
+ // Join never puts a player on a door's pad, nor at its edge (a pad takes
127
+ // whoever stands on it into its game), even beside a friend standing on one.
128
+ {
129
+ const b = boot();
130
+ put(b, 'p2', -25.5, 0);
131
+ b.h.message(b.session, { playerId: 'p1' }, { k: 'hub-goto', player: 'p2' });
132
+ // To p2's right (x + 1.6) is on the Foot Race pad: the other side.
133
+ assert.ok(Math.abs(at(b, 'p1').x - -27.1) < 1e-9, `off the pad: ${JSON.stringify(at(b, 'p1'))}`);
134
+ // Just off the pad's edge (x -24): they are not on it, so neither is the joiner.
135
+ const c = boot();
136
+ put(c, 'p2', -24.2, 0);
137
+ c.h.message(c.session, { playerId: 'p1' }, { k: 'hub-goto', player: 'p2' });
138
+ assert.ok(Math.abs(at(c, 'p1').x - -25.8) < 1e-9, `off the pad: ${JSON.stringify(at(c, 'p1'))}`);
139
+ put(b, 'p2', -22, 0);
140
+ b.h.message(b.session, { playerId: 'p3' }, { k: 'hub-goto', player: 'p2' });
141
+ // On the pad themselves (v1.19): just off its edge, facing them, never on it.
142
+ assert.ok(Math.abs(at(b, 'p3').x - -18.8) < 1e-9 && Math.abs(at(b, 'p3').z) < 1e-9, `off their pad: ${JSON.stringify(at(b, 'p3'))}`);
143
+ assert.ok(Math.abs(b.world.players.get('p3').facing - -Math.PI / 2) < 1e-9, 'facing them');
144
+ n += 1;
145
+ }
146
+
127
147
  {
128
148
  const b = boot();
129
149
  put(b, 'p2', 10, 10);
@@ -168,6 +188,18 @@ let n = 0;
168
188
  n += 1;
169
189
  }
170
190
 
191
+ // Whoever stays is told who went through which door.
192
+ {
193
+ const b = boot();
194
+ b.ctx().go('race', ['p1']);
195
+ const went = b.sent.filter(([, msg]) => msg.k === 'hub-went');
196
+ assert.deepEqual(went, [
197
+ ['p2', { k: 'hub-went', players: ['p1'], door: 'race' }],
198
+ ['p3', { k: 'hub-went', players: ['p1'], door: 'race' }],
199
+ ]);
200
+ n += 1;
201
+ }
202
+
171
203
  // A game answers neither.
172
204
  {
173
205
  const b = boot({ sessionId: 'dev:hub.race.abc123' });
@@ -384,6 +384,8 @@ A scene is a background plus a list of actors. Every actor is an **instance of a
384
384
  }
385
385
  ```
386
386
 
387
+ A scene can set `"engine": { "skipUnchangedActors": true }` at its top level, beside `background`; the terms are in the 3d kit's `CLAUDE.md`. In this kit it does one thing: the actor list is not sorted again while every `Layout.z` is a stored number already in order. The update loop and every behavior hook are the same with and without it, so a 2d scene gains little.
388
+
387
389
  ### Switching a behavior off without losing its settings
388
390
 
389
391
  Any component may carry `"$enabled": false` to stop the behavior running while
@@ -68,11 +68,11 @@
68
68
  "onUpdate": "scripts/onUpdate.mjs",
69
69
  "title": "physics-2d",
70
70
  "description": "Scene Editor. Works like classic Castle: actors, blueprints, behaviors and drawing tools, with physics built in.",
71
- "publishedVersion": "2026-10-03T04:25:18.207Z",
71
+ "publishedVersion": "2026-10-04T22:43:17.146Z",
72
72
  "imports": {
73
73
  "castle.base": {
74
74
  "deckId": "yRcmH4_aYllE",
75
- "version": "2026-10-03T04:17:27.840Z"
75
+ "version": "2026-10-04T22:42:38.248Z"
76
76
  }
77
77
  }
78
78
  }
@@ -101,6 +101,61 @@ function makeBehaviorsProxy(scene, actor) {
101
101
  });
102
102
  }
103
103
 
104
+ // `"engine": { "skipUnchangedActors": true }` at a scene file's top level: the
105
+ // scene asks the engine not to redo, every frame, work whose answer cannot
106
+ // have changed (the 3d kit's CLAUDE.md has the terms). It is off unless a scene
107
+ // says so. In this file it does one thing: `getActors` does not sort a list
108
+ // that is already in order. The update loop is the same loop either way.
109
+ function sceneSkipsUnchangedActors(data) {
110
+ return data?.engine?.skipUnchangedActors === true;
111
+ }
112
+
113
+ // `"engine": { "shadows": { "distance": <metres> } }` at a scene file's top
114
+ // level: the scene asks the 3d kit to draw the sun's shadows in a box that
115
+ // follows the view, complete out to that far from the camera (its CLAUDE.md
116
+ // has the terms). 0 unless a scene says so with a finite number above 0.
117
+ // Nothing in this kit reads it.
118
+ function sceneNearShadowDistance(data) {
119
+ const distance = data?.engine?.shadows?.distance;
120
+ return typeof distance === 'number' && Number.isFinite(distance) && distance > 0 ? distance : 0;
121
+ }
122
+
123
+ // `"engine": { "camera": { "follow": "rigid" } }` at a scene file's top level:
124
+ // the scene asks the 3d kit's Player for a follow camera that moves with the
125
+ // player rather than easing after it (its CLAUDE.md has the terms). Off unless
126
+ // a scene says so with exactly "rigid". Nothing in this kit reads it.
127
+ function sceneCameraFollowsRigidly(data) {
128
+ return data?.engine?.camera?.follow === 'rigid';
129
+ }
130
+
131
+ // Whether a Layout's z is plain data: its own stored value, or absent
132
+ // altogether. One that is computed when read (an accessor, or carried by a
133
+ // prototype) is left to the sort, which reads it in the sort's own order.
134
+ function hasPlainZ(layout) {
135
+ if (typeof layout !== 'object') return false;
136
+ const own = Object.getOwnPropertyDescriptor(layout, 'z');
137
+ return own ? 'value' in own : !('z' in layout);
138
+ }
139
+
140
+ // Whether the actors are already in the order `getActors` sorts them into:
141
+ // every Layout z plain data and a finite number (or absent, which is 0), none
142
+ // below the one before it. Sorting is stable, so sorting such a list would
143
+ // change nothing.
144
+ function alreadyInLayoutOrder(actors) {
145
+ let last = -Infinity;
146
+ for (let i = 0; i < actors.length; i++) {
147
+ const layout = getLayout(actors[i]);
148
+ let z = 0;
149
+ if (layout !== undefined && layout !== null) {
150
+ if (!hasPlainZ(layout)) return false;
151
+ z = layout.z ?? 0;
152
+ }
153
+ if (typeof z !== 'number' || !Number.isFinite(z) || z < last) return false;
154
+ last = z;
155
+ }
156
+ return true;
157
+ }
158
+
104
159
  // Shared by the constructor and `setBehaviors` -- both build the same
105
160
  // behaviorName -> class Map from a list of classes.
106
161
  function behaviorMapFrom(classes) {
@@ -108,6 +163,31 @@ function behaviorMapFrom(classes) {
108
163
  }
109
164
 
110
165
  export class SceneRuntime {
166
+ // Whether the loaded scene asked for `skipUnchangedActors`. Set by `load`
167
+ // from the scene's data and by nothing else, so one scene runs one way from
168
+ // its load to the next.
169
+ #skipUnchanged = false;
170
+
171
+ get skipsUnchangedActors() {
172
+ return this.#skipUnchanged;
173
+ }
174
+
175
+ // The distance the loaded scene asked for with `engine.shadows.distance`,
176
+ // or 0. Set by `load`, as `skipsUnchangedActors` is.
177
+ #nearShadowDistance = 0;
178
+
179
+ get nearShadowDistance() {
180
+ return this.#nearShadowDistance;
181
+ }
182
+
183
+ // Whether the loaded scene asked for `engine.camera.follow: "rigid"`. Set
184
+ // by `load`, as `skipsUnchangedActors` is.
185
+ #cameraFollowsRigidly = false;
186
+
187
+ get cameraFollowsRigidly() {
188
+ return this.#cameraFollowsRigidly;
189
+ }
190
+
111
191
  // `files` is the live deck files map (path -> text), used to resolve every
112
192
  // actor's `blueprint` ref against the CURRENT blueprint file content -- not
113
193
  // a load-time snapshot -- so a blueprint edit propagates to every scene that
@@ -240,6 +320,9 @@ export class SceneRuntime {
240
320
  // No-op on the constructor's first load, before any system is registered.
241
321
  for (const system of this.systems) system.reset?.(this);
242
322
  this.data = structuredClone(sceneData);
323
+ this.#skipUnchanged = sceneSkipsUnchangedActors(this.data);
324
+ this.#nearShadowDistance = sceneNearShadowDistance(this.data);
325
+ this.#cameraFollowsRigidly = sceneCameraFollowsRigidly(this.data);
243
326
  this.actors = new Map();
244
327
  for (const actor of this.data.actors ?? []) {
245
328
  this.#initActor(actor);
@@ -329,6 +412,7 @@ export class SceneRuntime {
329
412
  }
330
413
 
331
414
  getActors() {
415
+ if (this.#skipUnchanged) return this.#actorsSkippingSort();
332
416
  return [...this.actors.values()].sort((a, b) => {
333
417
  const az = getLayout(a)?.z ?? 0;
334
418
  const bz = getLayout(b)?.z ?? 0;
@@ -336,6 +420,14 @@ export class SceneRuntime {
336
420
  });
337
421
  }
338
422
 
423
+ // `getActors` for a scene that set `skipUnchangedActors`: the same list,
424
+ // sorted only when it is not already in order.
425
+ #actorsSkippingSort() {
426
+ const actors = [...this.actors.values()];
427
+ if (alreadyInLayoutOrder(actors)) return actors;
428
+ return actors.sort((a, b) => (getLayout(a)?.z ?? 0) - (getLayout(b)?.z ?? 0));
429
+ }
430
+
339
431
  getComponent(actor, behaviorName) {
340
432
  return actor?.components?.[behaviorName] ?? null;
341
433
  }
@@ -7,7 +7,7 @@
7
7
  "palette": "node scripts/palette.mjs",
8
8
  "restart": "node ../../cli/dist/index.js restart .",
9
9
  "screenshot": "node ../../cli/dist/index.js screenshot .",
10
- "check": "node ../../scripts/sync-shared.mjs --check && eslint . && jscpd && node --input-type=module -e \"const { bundleProject } = await import('../../cli/dist/bundle.js'); await bundleProject('.');\""
10
+ "check": "node ../../scripts/sync-shared.mjs --check && eslint . && jscpd && node scripts/test-skip-unchanged.mjs && node --input-type=module -e \"const { bundleProject } = await import('../../cli/dist/bundle.js'); await bundleProject('.');\""
11
11
  },
12
12
  "jscpd": {
13
13
  "path": [
@@ -0,0 +1,254 @@
1
+ // In the runtime (`engine/scene.js`) a scene that sets
2
+ // `"engine": { "skipUnchangedActors": true }` differs in one thing: `getActors`
3
+ // does not sort a list already in order. So every scenario here runs twice,
4
+ // once each way, and the hooks called and the order of the actors after each
5
+ // step must be equal. The runtime is loaded by itself, with the modules that
6
+ // need the bundler (the deck's files, fonts, systems, art) stood in for.
7
+ //
8
+ // `npm run check` runs it. node scripts/test-skip-unchanged.mjs
9
+ // OTHER=<file in engine/> compares against another copy of the runtime instead
10
+ // of against the key; ONLY=<part of a scenario's name> runs those alone.
11
+ import assert from 'node:assert/strict';
12
+ import { register } from 'node:module';
13
+
14
+ const stubs = {
15
+ 'castle-web-sdk': `export const resolveDeckFile = (name) => String(name).replace(/^\\.\\//, '');
16
+ export const deckPrefixOf = () => ''; export const IMPORTS_DIR = 'imports'; export const IMPORTS_PREFIX = 'imports/';`,
17
+ './files': `export const initialFiles = {}; export const parseJsonFile = (path, text) => ({ value: JSON.parse(text) });
18
+ export const formatJson = (value) => JSON.stringify(value);`,
19
+ './blueprint': `export const actorUsesBlueprint = () => false; export const getBlueprintTemplate = () => null;
20
+ export const mergeComponents = (template, own) => ({ ...(template ?? {}), ...(own ?? {}) });`,
21
+ './collider': `export const getColliderRect = () => null; export const intersects = () => false; export const spriteIsEmpty = () => false;`,
22
+ './systemRegistry': `export const systemInstallers = [];`,
23
+ './fonts': `export const deckFontFamily = 'sans-serif';`,
24
+ };
25
+ const hooks = `
26
+ const stubs = ${JSON.stringify(stubs)};
27
+ export async function resolve(specifier, context, next) {
28
+ if (context.parentURL?.includes('/physics-2d/engine/')) {
29
+ if (stubs[specifier]) return { url: 'stub:' + specifier, shortCircuit: true };
30
+ if (specifier.startsWith('.') && !/\\.m?js$/.test(specifier)) return next(specifier + '.js', context);
31
+ }
32
+ return next(specifier, context);
33
+ }
34
+ export async function load(url, context, next) {
35
+ if (url.startsWith('stub:')) return { format: 'module', source: stubs[url.slice(5)], shortCircuit: true };
36
+ return next(url, context);
37
+ }`;
38
+ register(`data:text/javascript,${encodeURIComponent(hooks)}`);
39
+ const { SceneRuntime } = await import('../engine/scene.js');
40
+ const Other = process.env.OTHER ? (await import(`../engine/${process.env.OTHER}`)).SceneRuntime : null;
41
+
42
+ // A scenario builds its scene data and returns the steps to take; each step
43
+ // gets the runtime. `log` collects what the behaviours were called with.
44
+ function run(scenario, skip) {
45
+ const log = [];
46
+ const made = scenario(log);
47
+ const data = structuredClone(made.data);
48
+ if (skip) data.engine = { skipUnchangedActors: true };
49
+ const scene = new (skip && Other ? Other : SceneRuntime)(data, made.classes, {}, {});
50
+ if (!Other) assert.equal(scene.skipsUnchangedActors, skip);
51
+ for (const step of made.steps) {
52
+ try {
53
+ step(scene);
54
+ } catch (error) {
55
+ log.push(`threw ${error.message}`);
56
+ }
57
+ log.push(`order ${scene.getActors().map((actor) => actor.id).join(',')}`);
58
+ }
59
+ return log;
60
+ }
61
+
62
+ let scenarios = 0;
63
+ function sameBothWays(name, scenario, mustHave) {
64
+ if (process.env.ONLY && !name.includes(process.env.ONLY)) return;
65
+ const plain = run(scenario, false);
66
+ const skipping = run(scenario, true);
67
+ assert.deepEqual(skipping, plain, `${name}: the hooks differ with skipUnchangedActors`);
68
+ if (mustHave) assert.ok(plain.some((line) => line.includes(mustHave)), `${name}: the scenario never reached "${mustHave}"`);
69
+ scenarios += 1;
70
+ }
71
+
72
+ const behavior = (log, name, version = 1, more = {}) =>
73
+ class {
74
+ static behaviorName = name;
75
+ static defaultProps = {};
76
+ constructor(props) {
77
+ this.props = props;
78
+ log.push(`${name}v${version} ctor`);
79
+ }
80
+ update(actor, scene) {
81
+ log.push(`${name}v${version} update ${actor.id}`);
82
+ more.update?.(actor, scene, this);
83
+ }
84
+ onEnable(actor) {
85
+ log.push(`${name}v${version} enable ${actor.id}`);
86
+ more.onEnable?.(actor);
87
+ }
88
+ onDisable(actor) {
89
+ log.push(`${name}v${version} disable ${actor.id}`);
90
+ more.onDisable?.(actor);
91
+ }
92
+ };
93
+ const frames = (n) => Array.from({ length: n }, () => (scene) => scene.update(1 / 60));
94
+ const actor = (id, components) => ({ id, components });
95
+
96
+ // The plain run of things: updates, a switch off and on, a component added
97
+ // and removed, Style first, a spawn and a despawn.
98
+ sameBothWays(
99
+ 'ordinary frames',
100
+ (log) => ({
101
+ classes: [behavior(log, 'A'), behavior(log, 'B'), behavior(log, 'Style')],
102
+ data: { actors: [actor('one', { A: {}, Style: {}, B: {} }), actor('two', { B: {}, Unknown: {} })] },
103
+ steps: [
104
+ ...frames(3),
105
+ (s) => { s.getActor('one').components.B.$enabled = false; },
106
+ ...frames(2),
107
+ (s) => { delete s.getActor('one').components.B.$enabled; },
108
+ ...frames(2),
109
+ (s) => { s.getActor('two').components.A = {}; },
110
+ ...frames(2),
111
+ (s) => { delete s.getActor('two').components.B; },
112
+ ...frames(2),
113
+ (s) => { s.spawnActor(actor('three', { A: {} })); },
114
+ ...frames(2),
115
+ (s) => { s.despawnActor('one'); },
116
+ ...frames(2),
117
+ ],
118
+ }),
119
+ 'B v1 enable one'.replace('B v1', 'Bv1'),
120
+ );
121
+
122
+ // An update that updates again from inside a behavior (a review's case, from
123
+ // when the key also changed the update loop): B is switched off, the scene is
124
+ // updated from within A's update, and B is switched back on. Both hooks are
125
+ // called, as they are without the key. With the key the loop is the same loop,
126
+ // so this holds by construction; it is here so it stays so.
127
+ sameBothWays(
128
+ 'an update from inside an update',
129
+ (log) => {
130
+ let frame = 0;
131
+ let inside = false;
132
+ return {
133
+ classes: [
134
+ behavior(log, 'A', 1, {
135
+ update(a, scene) {
136
+ if (inside) return;
137
+ frame += 1;
138
+ if (frame !== 3) return;
139
+ scene.behavior(a, 'B').enabled = false;
140
+ inside = true;
141
+ scene.update(0);
142
+ inside = false;
143
+ scene.behavior(a, 'B').enabled = true;
144
+ },
145
+ }),
146
+ behavior(log, 'B'),
147
+ ],
148
+ data: { actors: [actor('one', { A: {}, B: {} })] },
149
+ steps: frames(6),
150
+ };
151
+ },
152
+ 'Bv1 enable one',
153
+ );
154
+
155
+ // A Layout z that is computed when read is left to the sort, which reads it
156
+ // in the sort's own order (a review's case).
157
+ sameBothWays('a z that counts its reads', () => {
158
+ let reads = 0;
159
+ const counting = () => Object.defineProperty({ x: 0, y: 0 }, 'z', { get: () => ++reads, enumerable: true });
160
+ return {
161
+ classes: [],
162
+ data: { actors: [actor('a', {}), actor('b', {})] },
163
+ steps: [
164
+ (s) => {
165
+ s.getActor('a').components.Layout = counting();
166
+ s.getActor('b').components.Layout = counting();
167
+ },
168
+ ...frames(2),
169
+ ],
170
+ };
171
+ });
172
+
173
+ // z of every other kind: in order, out of order, equal, changed in place,
174
+ // NaN, a string, missing, carried by a prototype.
175
+ sameBothWays('Layout z of every kind', (log) => ({
176
+ classes: [behavior(log, 'A')],
177
+ data: {
178
+ actors: [
179
+ actor('a', { A: {}, Layout: { z: 3 } }),
180
+ actor('b', { A: {}, Layout: { z: 1 } }),
181
+ actor('c', { A: {} }),
182
+ actor('d', { A: {}, Layout: { z: 1 } }),
183
+ actor('e', { A: {}, Layout: {} }),
184
+ ],
185
+ },
186
+ steps: [
187
+ ...frames(2),
188
+ (s) => { s.getActor('a').components.Layout.z = -4; },
189
+ ...frames(1),
190
+ (s) => { s.getActor('b').components.Layout.z = NaN; },
191
+ ...frames(1),
192
+ (s) => { s.getActor('b').components.Layout.z = '2'; },
193
+ ...frames(1),
194
+ (s) => { s.getActor('b').components.Layout.z = Infinity; },
195
+ ...frames(1),
196
+ (s) => { s.getActor('b').components.Layout = Object.create({ z: -9 }); },
197
+ ...frames(1),
198
+ (s) => { s.getActor('d').components.Layout = null; },
199
+ ...frames(1),
200
+ ],
201
+ }));
202
+
203
+ // The scene is reloaded, with and without the key: the switch follows the
204
+ // data that was loaded, and nothing is carried over.
205
+ if (!Other && !process.env.ONLY) {
206
+ const log = [];
207
+ const classes = [behavior(log, 'A')];
208
+ const data = { actors: [actor('one', { A: {} })] };
209
+ const scene = new SceneRuntime(data, classes, {}, {});
210
+ assert.equal(scene.skipsUnchangedActors, false, 'off unless the scene says so');
211
+ assert.ok(Object.getPrototypeOf(scene.behaviors) === Map.prototype, 'the registry is a plain Map');
212
+ scene.load({ ...data, engine: { skipUnchangedActors: true } });
213
+ assert.equal(scene.skipsUnchangedActors, true);
214
+ assert.deepEqual(scene.serialize().engine, { skipUnchangedActors: true }, 'the key is kept in the scene data');
215
+ assert.equal(scene.clone().skipsUnchangedActors, true, 'and by a clone');
216
+ scene.update(0);
217
+ scene.load(data);
218
+ assert.equal(scene.skipsUnchangedActors, false, 'and is off again for a scene without it');
219
+ for (const not of [{ engine: {} }, { engine: { skipUnchangedActors: 1 } }, { engine: null }, { engine: 'yes' }]) {
220
+ assert.equal(new SceneRuntime({ ...data, ...not }, classes, {}, {}).skipsUnchangedActors, false);
221
+ }
222
+ // `engine.shadows.distance`, which the 3d kit reads: latched the same way.
223
+ const far = (engine) => new SceneRuntime({ ...data, engine }, classes, {}, {}).nearShadowDistance;
224
+ assert.equal(scene.nearShadowDistance, 0, 'off unless the scene says so');
225
+ assert.equal(far({ skipUnchangedActors: true }), 0);
226
+ assert.equal(far({ shadows: { distance: 40 } }), 40);
227
+ for (const not of [true, {}, { distance: '40' }, { distance: 0 }, { distance: -3 }, { distance: Infinity }, { distance: NaN }, { distance: null }]) {
228
+ assert.equal(far({ shadows: not }), 0, JSON.stringify(not));
229
+ }
230
+ scene.load({ ...data, engine: { shadows: { distance: 25 } } });
231
+ scene.data.engine.shadows.distance = 99;
232
+ assert.equal(scene.nearShadowDistance, 25, 'read when the scene loads');
233
+ assert.equal(scene.skipsUnchangedActors, false, 'and the one key does not set the other');
234
+ scene.load(data);
235
+ assert.equal(scene.nearShadowDistance, 0, 'and is off again for a scene without it');
236
+ // `engine.camera.follow`, which the 3d kit's Player reads: latched the same way.
237
+ const rigid = (engine) => new SceneRuntime({ ...data, engine }, classes, {}, {}).cameraFollowsRigidly;
238
+ assert.equal(scene.cameraFollowsRigidly, false, 'off unless the scene says so');
239
+ assert.equal(rigid({ skipUnchangedActors: true, shadows: { distance: 40 } }), false);
240
+ assert.equal(rigid({ camera: { follow: 'rigid' } }), true);
241
+ for (const not of [true, 'rigid', {}, { follow: true }, { follow: 'Rigid' }, { follow: 'smooth' }, { follow: null }, null]) {
242
+ assert.equal(rigid({ camera: not }), false, JSON.stringify(not));
243
+ }
244
+ scene.load({ ...data, engine: { camera: { follow: 'rigid' } } });
245
+ assert.equal(scene.clone().cameraFollowsRigidly, true, 'and by a clone');
246
+ scene.data.engine.camera.follow = 'smooth';
247
+ assert.equal(scene.cameraFollowsRigidly, true, 'read when the scene loads');
248
+ assert.equal(scene.skipsUnchangedActors, false, 'and the one key does not set the others');
249
+ assert.equal(scene.nearShadowDistance, 0);
250
+ scene.load(data);
251
+ assert.equal(scene.cameraFollowsRigidly, false, 'and is off again for a scene without it');
252
+ }
253
+
254
+ console.log(`skip unchanged: ${scenarios} scenarios call the same hooks with and without the key`);