castle-web-cli 0.4.230 → 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.
- package/dist/castle-host/host.js +81 -0
- package/dist/devSaveStorage.d.ts +36 -0
- package/dist/devSaveStorage.js +469 -0
- package/dist/devSessionChild.js +22 -12
- package/dist/devSessionServer.js +8 -2
- package/dist/devSessionStorage.d.ts +9 -0
- package/dist/devSessionStorage.js +66 -1
- package/dist/init.js +1 -1
- package/dist/serve.js +5 -1
- package/dist/serverBundle.js +5 -3
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +148 -1
- package/kits/base/sdk/castle.d.ts +4 -0
- package/kits/base/sdk/castle.js +2 -0
- package/kits/base/sdk/commands.d.ts +15 -0
- package/kits/base/sdk/multiplayer.js +52 -4
- package/kits/base/sdk/save.d.ts +197 -0
- package/kits/base/sdk/save.js +525 -0
- package/kits/base/sdk/saveCoordinator.d.ts +39 -0
- package/kits/base/sdk/saveCoordinator.js +252 -0
- package/kits/base/sdk/server/storage.d.ts +3 -2
- package/kits/base/sdk/server/storage.js +25 -5
- package/kits/base/sdk/server/wrapper.d.ts +4 -0
- package/kits/base/sdk/server/wrapper.js +2 -0
- package/kits/base/sdk/store.d.ts +3 -2
- package/kits/base/sdk/store.js +5 -0
- package/kits/hub-game/CLAUDE.md +29 -4
- package/kits/hub-game/code/client/avatar.js +39 -0
- package/kits/hub-game/code/client/chat.js +12 -0
- package/kits/hub-game/code/client/chrome.js +237 -13
- package/kits/hub-game/code/client/grab.js +166 -7
- package/kits/hub-game/code/client/hats.js +26 -0
- package/kits/hub-game/code/client/hookLayer.js +36 -3
- package/kits/hub-game/code/client/hudClear.js +126 -0
- package/kits/hub-game/code/client/state.js +35 -1
- package/kits/hub-game/code/client/talk.js +10 -36
- package/kits/hub-game/code/client/tiers.js +505 -0
- package/kits/hub-game/code/client/together.js +144 -4
- package/kits/hub-game/code/client/wear.js +96 -14
- package/kits/hub-game/code/server/actors.js +5 -0
- package/kits/hub-game/code/server/grab.js +299 -13
- package/kits/hub-game/code/server/hub.js +162 -7
- package/kits/hub-game/code/server/manifest.js +80 -8
- package/kits/hub-game/code/server/npcs.js +21 -33
- package/kits/hub-game/code/server/party.js +75 -6
- package/kits/hub-game/code/server/say.js +8 -2
- package/kits/hub-game/code/server/wear.js +116 -11
- package/kits/hub-game/code/systems/hub.js +386 -21
- package/kits/hub-game/docs/contract.md +285 -19
- package/kits/hub-game/package.json +1 -1
- package/kits/hub-game/scripts/test-chat.mjs +32 -0
- package/kits/hub-game/scripts/test-grab-client.mjs +511 -0
- package/kits/hub-game/scripts/test-grab.mjs +857 -3
- package/kits/hub-game/scripts/test-hats.mjs +229 -0
- package/kits/hub-game/scripts/test-hub-trip.mjs +721 -0
- package/kits/hub-game/scripts/test-hud-clear.mjs +676 -0
- package/kits/hub-game/scripts/test-manifest.mjs +122 -1
- package/kits/hub-game/scripts/test-npcs.mjs +34 -24
- package/kits/hub-game/scripts/test-party.mjs +108 -4
- package/kits/hub-game/scripts/test-say.mjs +59 -2
- package/kits/hub-game/scripts/test-tiers.mjs +854 -0
- package/kits/hub-game/scripts/test-together.mjs +33 -1
- package/kits/hub-game/scripts/test-try-on.mjs +940 -0
- package/kits/physics-2d/CLAUDE.md +2 -0
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/scene.js +127 -0
- package/kits/physics-2d/package.json +1 -1
- package/kits/physics-2d/scripts/test-skip-unchanged.mjs +298 -0
- package/kits/physics-3d/CLAUDE.md +531 -0
- package/kits/physics-3d/behaviors/Player.jsx +437 -3
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/docs/pxmodel-format.md +4 -0
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +33 -1
- package/kits/physics-3d/engine3d/actornode.js +253 -0
- package/kits/physics-3d/engine3d/nearshadows.js +600 -0
- package/kits/physics-3d/engine3d/optimize.js +49 -0
- package/kits/physics-3d/engine3d/orbitinput.js +277 -0
- package/kits/physics-3d/engine3d/unchanged.js +153 -0
- package/kits/physics-3d/engine3d/world3d.js +525 -11
- package/kits/physics-3d/package.json +1 -1
- package/kits/physics-3d/scripts/Player.before-orbit.mjs +310 -0
- package/kits/physics-3d/scripts/Scene3DPlayer.before-orbit.jsx +337 -0
- package/kits/physics-3d/scripts/test-camera-follow.mjs +543 -0
- package/kits/physics-3d/scripts/test-camera-orbit.mjs +2105 -0
- package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +787 -0
- package/kits/physics-3d/scripts/test-near-shadows.mjs +1073 -0
- package/kits/physics-3d/scripts/test-static-actors.mjs +667 -0
- package/kits/physics-3d/scripts/test-static-passes.mjs +459 -0
- package/kits/physics-3d/scripts/test-static-physics.mjs +128 -0
- package/kits/physics-3d/scripts/test-steady-hover.mjs +633 -0
- package/kits/physics-3d/systems/physics3d.js +273 -9
- package/package.json +1 -1
|
@@ -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-
|
|
71
|
+
"publishedVersion": "2026-10-05T08:03:43.791Z",
|
|
72
72
|
"imports": {
|
|
73
73
|
"castle.base": {
|
|
74
74
|
"deckId": "yRcmH4_aYllE",
|
|
75
|
-
"version": "2026-10-
|
|
75
|
+
"version": "2026-10-04T22:42:38.248Z"
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
}
|
|
@@ -101,6 +101,78 @@ 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": { "dropEmptyParts": true }` at a scene file's top level: the
|
|
124
|
+
// scene asks the 3d kit to leave out of a placed model the groups that draw
|
|
125
|
+
// nothing (its CLAUDE.md has the terms). Off unless a scene says so with
|
|
126
|
+
// exactly `true`. Nothing in this kit reads it.
|
|
127
|
+
function sceneDropsEmptyParts(data) {
|
|
128
|
+
return data?.engine?.dropEmptyParts === true;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// `"engine": { "camera": { "follow": "rigid" } }` at a scene file's top level:
|
|
132
|
+
// the scene asks the 3d kit's Player for a follow camera that moves with the
|
|
133
|
+
// player rather than easing after it (its CLAUDE.md has the terms). Off unless
|
|
134
|
+
// a scene says so with exactly "rigid". Nothing in this kit reads it.
|
|
135
|
+
function sceneCameraFollowsRigidly(data) {
|
|
136
|
+
return data?.engine?.camera?.follow === 'rigid';
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// `"engine": { "camera": { "follow": "rigid", "control": "orbit" } }`: the
|
|
140
|
+
// scene asks the 3d kit's Player for a camera the player turns, tilts and
|
|
141
|
+
// zooms (its CLAUDE.md has the terms). 'orbit' only when the scene says
|
|
142
|
+
// exactly "orbit" beside exactly `"follow": "rigid"`; null otherwise. Nothing
|
|
143
|
+
// in this kit reads it.
|
|
144
|
+
function sceneCameraControl(data) {
|
|
145
|
+
return sceneCameraFollowsRigidly(data) && data.engine.camera.control === 'orbit' ? 'orbit' : null;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Whether a Layout's z is plain data: its own stored value, or absent
|
|
149
|
+
// altogether. One that is computed when read (an accessor, or carried by a
|
|
150
|
+
// prototype) is left to the sort, which reads it in the sort's own order.
|
|
151
|
+
function hasPlainZ(layout) {
|
|
152
|
+
if (typeof layout !== 'object') return false;
|
|
153
|
+
const own = Object.getOwnPropertyDescriptor(layout, 'z');
|
|
154
|
+
return own ? 'value' in own : !('z' in layout);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Whether the actors are already in the order `getActors` sorts them into:
|
|
158
|
+
// every Layout z plain data and a finite number (or absent, which is 0), none
|
|
159
|
+
// below the one before it. Sorting is stable, so sorting such a list would
|
|
160
|
+
// change nothing.
|
|
161
|
+
function alreadyInLayoutOrder(actors) {
|
|
162
|
+
let last = -Infinity;
|
|
163
|
+
for (let i = 0; i < actors.length; i++) {
|
|
164
|
+
const layout = getLayout(actors[i]);
|
|
165
|
+
let z = 0;
|
|
166
|
+
if (layout !== undefined && layout !== null) {
|
|
167
|
+
if (!hasPlainZ(layout)) return false;
|
|
168
|
+
z = layout.z ?? 0;
|
|
169
|
+
}
|
|
170
|
+
if (typeof z !== 'number' || !Number.isFinite(z) || z < last) return false;
|
|
171
|
+
last = z;
|
|
172
|
+
}
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
|
|
104
176
|
// Shared by the constructor and `setBehaviors` -- both build the same
|
|
105
177
|
// behaviorName -> class Map from a list of classes.
|
|
106
178
|
function behaviorMapFrom(classes) {
|
|
@@ -108,6 +180,47 @@ function behaviorMapFrom(classes) {
|
|
|
108
180
|
}
|
|
109
181
|
|
|
110
182
|
export class SceneRuntime {
|
|
183
|
+
// Whether the loaded scene asked for `skipUnchangedActors`. Set by `load`
|
|
184
|
+
// from the scene's data and by nothing else, so one scene runs one way from
|
|
185
|
+
// its load to the next.
|
|
186
|
+
#skipUnchanged = false;
|
|
187
|
+
|
|
188
|
+
get skipsUnchangedActors() {
|
|
189
|
+
return this.#skipUnchanged;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// The distance the loaded scene asked for with `engine.shadows.distance`,
|
|
193
|
+
// or 0. Set by `load`, as `skipsUnchangedActors` is.
|
|
194
|
+
#nearShadowDistance = 0;
|
|
195
|
+
|
|
196
|
+
get nearShadowDistance() {
|
|
197
|
+
return this.#nearShadowDistance;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Whether the loaded scene asked for `engine.dropEmptyParts`. Set by `load`,
|
|
201
|
+
// as `skipsUnchangedActors` is.
|
|
202
|
+
#dropsEmptyParts = false;
|
|
203
|
+
|
|
204
|
+
get dropsEmptyParts() {
|
|
205
|
+
return this.#dropsEmptyParts;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Whether the loaded scene asked for `engine.camera.follow: "rigid"`. Set
|
|
209
|
+
// by `load`, as `skipsUnchangedActors` is.
|
|
210
|
+
#cameraFollowsRigidly = false;
|
|
211
|
+
|
|
212
|
+
get cameraFollowsRigidly() {
|
|
213
|
+
return this.#cameraFollowsRigidly;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// What the loaded scene asked for with `engine.camera.control` ('orbit' or
|
|
217
|
+
// null). Set by `load`, as `skipsUnchangedActors` is.
|
|
218
|
+
#cameraControl = null;
|
|
219
|
+
|
|
220
|
+
get cameraControl() {
|
|
221
|
+
return this.#cameraControl;
|
|
222
|
+
}
|
|
223
|
+
|
|
111
224
|
// `files` is the live deck files map (path -> text), used to resolve every
|
|
112
225
|
// actor's `blueprint` ref against the CURRENT blueprint file content -- not
|
|
113
226
|
// a load-time snapshot -- so a blueprint edit propagates to every scene that
|
|
@@ -240,6 +353,11 @@ export class SceneRuntime {
|
|
|
240
353
|
// No-op on the constructor's first load, before any system is registered.
|
|
241
354
|
for (const system of this.systems) system.reset?.(this);
|
|
242
355
|
this.data = structuredClone(sceneData);
|
|
356
|
+
this.#skipUnchanged = sceneSkipsUnchangedActors(this.data);
|
|
357
|
+
this.#nearShadowDistance = sceneNearShadowDistance(this.data);
|
|
358
|
+
this.#dropsEmptyParts = sceneDropsEmptyParts(this.data);
|
|
359
|
+
this.#cameraFollowsRigidly = sceneCameraFollowsRigidly(this.data);
|
|
360
|
+
this.#cameraControl = sceneCameraControl(this.data);
|
|
243
361
|
this.actors = new Map();
|
|
244
362
|
for (const actor of this.data.actors ?? []) {
|
|
245
363
|
this.#initActor(actor);
|
|
@@ -329,6 +447,7 @@ export class SceneRuntime {
|
|
|
329
447
|
}
|
|
330
448
|
|
|
331
449
|
getActors() {
|
|
450
|
+
if (this.#skipUnchanged) return this.#actorsSkippingSort();
|
|
332
451
|
return [...this.actors.values()].sort((a, b) => {
|
|
333
452
|
const az = getLayout(a)?.z ?? 0;
|
|
334
453
|
const bz = getLayout(b)?.z ?? 0;
|
|
@@ -336,6 +455,14 @@ export class SceneRuntime {
|
|
|
336
455
|
});
|
|
337
456
|
}
|
|
338
457
|
|
|
458
|
+
// `getActors` for a scene that set `skipUnchangedActors`: the same list,
|
|
459
|
+
// sorted only when it is not already in order.
|
|
460
|
+
#actorsSkippingSort() {
|
|
461
|
+
const actors = [...this.actors.values()];
|
|
462
|
+
if (alreadyInLayoutOrder(actors)) return actors;
|
|
463
|
+
return actors.sort((a, b) => (getLayout(a)?.z ?? 0) - (getLayout(b)?.z ?? 0));
|
|
464
|
+
}
|
|
465
|
+
|
|
339
466
|
getComponent(actor, behaviorName) {
|
|
340
467
|
return actor?.components?.[behaviorName] ?? null;
|
|
341
468
|
}
|
|
@@ -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,298 @@
|
|
|
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.dropEmptyParts`, which the 3d kit reads: latched the same way.
|
|
237
|
+
const drops = (engine) => new SceneRuntime({ ...data, engine }, classes, {}, {}).dropsEmptyParts;
|
|
238
|
+
assert.equal(scene.dropsEmptyParts, false, 'off unless the scene says so');
|
|
239
|
+
assert.equal(drops({ skipUnchangedActors: true, shadows: { distance: 40 }, camera: { follow: 'rigid' } }), false);
|
|
240
|
+
assert.equal(drops({ dropEmptyParts: true }), true);
|
|
241
|
+
for (const not of [false, 1, 'true', {}, [], null, undefined]) {
|
|
242
|
+
assert.equal(drops({ dropEmptyParts: not }), false, JSON.stringify(not));
|
|
243
|
+
}
|
|
244
|
+
assert.equal(new SceneRuntime({ ...data, dropEmptyParts: true }, classes, {}, {}).dropsEmptyParts, false, 'only under `engine`');
|
|
245
|
+
scene.load({ ...data, engine: { dropEmptyParts: true } });
|
|
246
|
+
assert.equal(scene.clone().dropsEmptyParts, true, 'and by a clone');
|
|
247
|
+
scene.data.engine.dropEmptyParts = false;
|
|
248
|
+
assert.equal(scene.dropsEmptyParts, true, 'read when the scene loads');
|
|
249
|
+
assert.equal(scene.skipsUnchangedActors, false, 'and the one key does not set the others');
|
|
250
|
+
assert.equal(scene.nearShadowDistance, 0);
|
|
251
|
+
scene.load(data);
|
|
252
|
+
assert.equal(scene.dropsEmptyParts, false, 'and is off again for a scene without it');
|
|
253
|
+
// `engine.camera.follow`, which the 3d kit's Player reads: latched the same way.
|
|
254
|
+
const rigid = (engine) => new SceneRuntime({ ...data, engine }, classes, {}, {}).cameraFollowsRigidly;
|
|
255
|
+
assert.equal(scene.cameraFollowsRigidly, false, 'off unless the scene says so');
|
|
256
|
+
assert.equal(rigid({ skipUnchangedActors: true, shadows: { distance: 40 } }), false);
|
|
257
|
+
assert.equal(rigid({ camera: { follow: 'rigid' } }), true);
|
|
258
|
+
for (const not of [true, 'rigid', {}, { follow: true }, { follow: 'Rigid' }, { follow: 'smooth' }, { follow: null }, null]) {
|
|
259
|
+
assert.equal(rigid({ camera: not }), false, JSON.stringify(not));
|
|
260
|
+
}
|
|
261
|
+
scene.load({ ...data, engine: { camera: { follow: 'rigid' } } });
|
|
262
|
+
assert.equal(scene.clone().cameraFollowsRigidly, true, 'and by a clone');
|
|
263
|
+
scene.data.engine.camera.follow = 'smooth';
|
|
264
|
+
assert.equal(scene.cameraFollowsRigidly, true, 'read when the scene loads');
|
|
265
|
+
assert.equal(scene.skipsUnchangedActors, false, 'and the one key does not set the others');
|
|
266
|
+
assert.equal(scene.nearShadowDistance, 0);
|
|
267
|
+
scene.load(data);
|
|
268
|
+
assert.equal(scene.cameraFollowsRigidly, false, 'and is off again for a scene without it');
|
|
269
|
+
// `engine.camera.control`, which the 3d kit's Player and input read:
|
|
270
|
+
// latched the same way, and only beside `follow: "rigid"`.
|
|
271
|
+
const made = (engine) => new SceneRuntime({ ...data, engine }, classes, {}, {});
|
|
272
|
+
const control = (camera) => made({ camera }).cameraControl;
|
|
273
|
+
assert.equal(scene.cameraControl, null, 'off unless the scene says so');
|
|
274
|
+
assert.equal(made({ skipUnchangedActors: true, shadows: { distance: 40 } }).cameraControl, null);
|
|
275
|
+
assert.equal(control({ follow: 'rigid', control: 'orbit' }), 'orbit');
|
|
276
|
+
assert.equal(control({ follow: 'rigid' }), null, 'the rigid camera alone is not the orbit one');
|
|
277
|
+
assert.equal(made({ camera: { follow: 'rigid' } }).cameraFollowsRigidly, true);
|
|
278
|
+
assert.equal(made({ camera: { follow: 'rigid', control: 'orbit' } }).cameraFollowsRigidly, true, 'and the orbit one is still rigid');
|
|
279
|
+
for (const not of [true, 'orbit', {}, null, { control: 'orbit' }, { follow: 'smooth', control: 'orbit' }, { follow: true, control: 'orbit' }, { follow: 'rigid', control: true }, { follow: 'rigid', control: 'Orbit' }, { follow: 'rigid', control: 'free' }, { follow: 'rigid', control: null }, { follow: 'rigid', control: ['orbit'] }]) {
|
|
280
|
+
assert.equal(control(not), null, JSON.stringify(not));
|
|
281
|
+
}
|
|
282
|
+
scene.load({ ...data, engine: { camera: { follow: 'rigid', control: 'orbit' } } });
|
|
283
|
+
assert.equal(scene.clone().cameraControl, 'orbit', 'and by a clone');
|
|
284
|
+
scene.data.engine.camera.control = 'free';
|
|
285
|
+
scene.data.engine.camera.follow = 'smooth';
|
|
286
|
+
assert.equal(scene.cameraControl, 'orbit', 'read when the scene loads');
|
|
287
|
+
assert.equal(scene.skipsUnchangedActors, false, 'and the key does not set the others');
|
|
288
|
+
assert.equal(scene.nearShadowDistance, 0);
|
|
289
|
+
scene.load({ ...data, engine: { camera: { follow: 'rigid' } } });
|
|
290
|
+
assert.equal(scene.cameraControl, null, 'off again for a scene with the rigid camera alone');
|
|
291
|
+
assert.equal(scene.cameraFollowsRigidly, true);
|
|
292
|
+
scene.load({ ...data, engine: { camera: { follow: 'rigid', control: 'orbit' } } });
|
|
293
|
+
assert.equal(scene.cameraControl, 'orbit', 'on again for a scene that says so');
|
|
294
|
+
scene.load(data);
|
|
295
|
+
assert.equal(scene.cameraControl, null, 'and off again for a scene without it');
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
console.log(`skip unchanged: ${scenarios} scenarios call the same hooks with and without the key`);
|