Keep objects through a Load scene with a switch (#165)
A Load scene destroyed every object of the old scene. A player, a HUD or a music object had to be built again in each scene, with its state pushed through shared variables. A top-level object with the new switch Keep on scene load now travels into the next scene as the same entity, with everything below it. - The switch is a common property right under Enabled, off by default, on the asset and on a placed object. The inspector shows the row on top-level objects of a scene only, as answered in the issue. - runtime/keptObjects.ts holds the rules as pure functions. keptEntities picks what travels, objectsToBring copies the stored objects as the run parents them, and bringObjects puts them into the next scene. - World.instantiate takes a handed entity as it is instead of making one. The next syncToModel then writes the run's values into the scene. - BehaviorSystem.release takes the running instances out before the old world is destroyed, and the next system adopts them. They hear no On destroy and no second On start, and their sounds play on. - PhysicsSystem.resume gives a dynamic body the velocity and spin it had. - Duplicates: the object brought along wins. The next scene does not build its own object with the same id, which is the way back into the scene the object came from. - Decided here: the next scene does not build a top-level object of the same asset that is kept itself either. The issue only names the id. With the id alone a level that places its own player would hold two after a swap. - Decided here: kept objects land behind the scene's own, the switch is no animation row, and collisions are found anew. A finding, fixed along with it: Load scene did not build a scene as it is stored, but as the run had left it. A moved object stayed moved and a destroyed one stayed gone. The way back into a scene needs a clean build. - GameRun copies a scene's objects and groups before it first builds it and puts them back before it builds it again. - GameRun.end puts every such scene back. The player calls it on stop, so spawned objects no longer stay for "Click to play again". - The consequence: an edit made in a scene during Play is gone the next time that scene is loaded. Tests: - Gate: 199 files, 2944 tests (2929 + 15), exit 0 - e2e, full run: 1625 checks passed (1619 + 6), exit 0 - Smokes: 24 / 19 / 21, exit 0 - 15 unit tests in tests/core/keep-on-scene-load.test.ts - Six e2e checks in module 35: the switch is set with a real mouse, the child has no row, the object is in the new scene, its counter still reads 1, its sound plays on, and the stored scenes are unchanged after Stop - Eleven tests with fixed row lists only count the new schema row - 16 unit counter-probes all fail tests, run on stein2. One did not fail at first (same id not left out), it has its own test now. - The browser counter-probe fails 4 of the 6 new checks - Not looked at in the browser: the switch as a port of the Properties node, and a released game with a kept object Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3e8c88c66d
commit
1aa824ecb4
19 files changed
+825
-32
No files matched your search
@@ -280,6 +280,88 @@ export async function loadScene(t) {
|
||||
JSON.stringify(await playFrom()),
|
||||
);
|
||||
|
||||
// 35f². Keep on scene load (#165). The second box gets the switch, by hand in the inspector, and
|
||||
// then travels through the swap with its loader below it. The loader is the witness twice
|
||||
// over: it counts on start, so a behavior that started again would say 2, and it is the one
|
||||
// humming, so a behavior that was destroyed would have gone silent.
|
||||
await evaluate("__gm.state.select({ kind: 'asset', assetId: 'ls-scene' })");
|
||||
const secondRow = await json('__gm.assetRow("ls-scene")');
|
||||
await doubleClick(secondRow.x, secondRow.y);
|
||||
const boxRow = await json("__gm.hierarchyRow('ls-box')");
|
||||
await click(boxRow.x, boxRow.y);
|
||||
const keepRow = await json("__gm.inspectorField('Keep on scene load')");
|
||||
if (keepRow) await click(keepRow.x, keepRow.y);
|
||||
const keptBox = await json(
|
||||
"__gm.state.project.assets.find((a) => a.id === 'ls-scene').objects.find((o) => o.id === 'ls-box')",
|
||||
);
|
||||
check(
|
||||
'a top-level object has the switch "Keep on scene load", and a click writes it as an override',
|
||||
Boolean(keepRow) && keptBox.overrides.keepOnSceneLoad === true,
|
||||
JSON.stringify({ keepRow, overrides: keptBox.overrides }),
|
||||
);
|
||||
await evaluate(
|
||||
"__gm.state.select({ kind: 'object', holderId: 'ls-scene', objectIds: ['ls-brain'], objectId: 'ls-brain' })",
|
||||
);
|
||||
check(
|
||||
'an object below another one has no such switch, only a top-level one travels',
|
||||
(await json("__gm.inspectorField('Keep on scene load')")) === null &&
|
||||
(await json("__gm.inspectorField('Enabled')")) !== null,
|
||||
JSON.stringify(await json("__gm.inspectorField('Keep on scene load')")),
|
||||
);
|
||||
|
||||
await play();
|
||||
await waitFor(
|
||||
() => json('__gm.world()'),
|
||||
(w) => (w?.shared?.variables?.['ls-vars']?.score ?? 0) === 1,
|
||||
);
|
||||
await waitFor(stats, (s) => s.playing > 0);
|
||||
await press('g');
|
||||
const swapped = await waitFor(
|
||||
() => json('__gm.playInfo()'),
|
||||
(info) => info.sceneId === firstId,
|
||||
);
|
||||
const keptWorld = await json('__gm.world()');
|
||||
const ofBox = (w) => w.entities.filter((e) => e.objectId === 'ls-box' || e.objectId === 'ls-brain');
|
||||
check(
|
||||
'a kept object is in the next scene with what hangs below it, among that scene’s own objects',
|
||||
swapped.sceneId === firstId &&
|
||||
ofBox(keptWorld).length === 2 &&
|
||||
keptWorld.entities.find((e) => e.objectId === 'ls-brain')?.parent === 'ls-box' &&
|
||||
keptWorld.entities.length > 2,
|
||||
JSON.stringify({ swapped: swapped.sceneId, kept: ofBox(keptWorld), all: keptWorld.entities.length }),
|
||||
);
|
||||
check(
|
||||
'its behavior runs on rather than starting again, and its sound plays on',
|
||||
keptWorld.shared?.variables?.['ls-vars']?.score === 1 && (await stats()).playing >= 1,
|
||||
JSON.stringify({ shared: keptWorld.shared?.variables, sound: await stats() }),
|
||||
);
|
||||
await shot('35-kept-object');
|
||||
// Loading the scene it is in by now: the box is the scene's own by its id, and stays the one box.
|
||||
const timeBefore = (await playInfo()).time;
|
||||
await press('g');
|
||||
await waitFor(playInfo, (info) => info.time < timeBefore);
|
||||
const again = await json('__gm.world()');
|
||||
check(
|
||||
'loading the scene again keeps the one object, and its behavior still has not started twice',
|
||||
ofBox(again).length === 2 && again.shared?.variables?.['ls-vars']?.score === 1,
|
||||
JSON.stringify({ kept: ofBox(again), shared: again.shared?.variables }),
|
||||
);
|
||||
await stop();
|
||||
const storedIn = (sceneId) =>
|
||||
json(
|
||||
`__gm.state.project.assets.find((a) => a.id === ${JSON.stringify(sceneId)}).objects.map((o) => o.id)`,
|
||||
);
|
||||
check(
|
||||
'Stop leaves the stored scenes as they were: the box is back in its own and in no other',
|
||||
(await storedIn('ls-scene')).join() === 'ls-box,ls-brain' &&
|
||||
!(await storedIn(firstId)).includes('ls-box'),
|
||||
JSON.stringify({ second: await storedIn('ls-scene'), first: await storedIn(firstId) }),
|
||||
);
|
||||
await evaluate(`__gm.state.select({ kind: 'asset', assetId: ${JSON.stringify(firstId)} })`);
|
||||
const firstRow = await json(`__gm.assetRow(${JSON.stringify(firstId)})`);
|
||||
await doubleClick(firstRow.x, firstRow.y);
|
||||
await evaluate('__gm.state.select(null)');
|
||||
|
||||
// 35g. Everything this step made goes again, the start scene included.
|
||||
await mutate(`
|
||||
const p = __gm.state.project;
|
||||
|
||||
Reference in new issue
Block a user