Variables assets can keep their values from one run to the next (#166)
game-maker / suite (push) Successful in 8m21s
game-maker / gate (push) Failing after 3h5m52s

A game needs a high score or an unlocked level to survive the end of
a run. As agreed in the issue there are no save or load nodes. A
Variables asset gets a switch instead, and the existing Variables
nodes read and write the values as before.

- A "Persistent" checkbox in the Variables inspector. Toggling it is
  one undo step, and absent means not persistent.
- The behavior system loads the saved values at start and writes them
  after every frame that changed one, so a closed tab loses nothing.
- Values live in localStorage per project, not in the project file.
  Another browser or person starts fresh.
- Play and "Run in editor" save apart, so trying a behavior in the
  editor leaves the Play save alone.
- Saved values are read through the current declaration. A removed
  variable drops out, a new one starts from its default, and a changed
  kind is converted.
- "Clear saved values" in the inspector clears this asset in both
  areas. The main menu gets "Clear saved data" for the whole project.
  Clearing takes effect from the next run on.

Decisions:
- The switch covers the whole asset, not single variables. Mixing
  both means two assets.
- A changed default in the inspector shows only after the save is
  cleared. That is what persistent means.

Findings:
- The first e2e run died at "debug hook present" right after a Vulkan
  error from Chrome. The second run passed, so it was a GPU flake at
  start-up.

Tests:
- ./check.sh: 140 files, 2070 tests, exit 0 (before 138 / 2055).
- 15 new unit tests in tests/core/saved-values.test.ts and
  tests/editor/saves.test.ts.
- GM_STEPS=32,46 fresh: ALL PASSED, 24 checks. Six new checks in
  module 32 go through the UI. Module 46 knows the new menu entry.
- Counter-checks both fail as expected. Loading switched off: 2 unit
  tests and 2 e2e checks fail. Editor run writing into the Play area:
  1 e2e check fails.
- Check total 1278 (1272 measured by CI at bbbf341, plus 6).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
adminandClaude Opus 5 committed 2026-09-22 10:23:57 +02:00
1 parent bbbf34109b
commit 41772e53f7
17 files changed
+619 -19

No files matched your search

+99 -2
View File
@@ -4,7 +4,8 @@ import { MAKE_OBJECT } from './lib/scaffold.mjs';
/**
* Shared state: a Variables asset holds one value per key for the whole run, and a state machine
* declared `global` one current state. The step checks the run (two objects counting into one
* number), that the node offers the asset's declarations, and the switch on the machine.
* number), that the node offers the asset's declarations, the switch on the machine, and a
* persistent asset going on from the last run (#166).
*
* The step brings its own boxes, behavior, Variables asset and machine; everything goes at the end.
*/
@@ -147,7 +148,103 @@ export async function scope(t) {
);
await shot('03-machine-scope');
// 32f. Everything this step added goes again.
// 32f. Persistent (#166): the switch on the asset, a second run going on from the first, the
// editor run saving apart, and both ways of clearing. Saves live in this browser, so the
// step starts by forgetting whatever an earlier run of the suite left there.
// 32d pointed the reading node at the behavior; counting on from a save needs it back on the asset.
await mutate(`
const g = __gm.state.project.assets.find((a) => a.id === 'sc-logic').graph;
g.nodes.find((n) => n.id === 'sc-read').params.variablesAsset = 'sc-vars';
`);
const pid = await json('__gm.state.project.id');
const saveKey = (area) => `game-maker.saves.${pid}.${area}`;
const saved = (area) =>
json(`JSON.parse(localStorage.getItem(${JSON.stringify(saveKey(area))}) ?? 'null')`);
await t.evaluate(
`localStorage.removeItem(${JSON.stringify(saveKey('play'))}); localStorage.removeItem(${JSON.stringify(saveKey('editor'))})`,
);
await selectAsset('sc-vars');
const persistentBox = await json(`__gm.inspectorField('Persistent')`);
if (persistentBox) await click(persistentBox.x, persistentBox.y);
await sleep(200);
const kept = await asset('sc-vars');
const keptNote = await has('Kept between runs, in this browser.');
check(
'the Persistent switch on a Variables asset marks it and says what it means',
Boolean(persistentBox) && kept.persistent === true && keptNote,
JSON.stringify({ box: persistentBox, persistent: kept.persistent, note: keptNote }),
);
await shot('04-persistent');
const scoreOfRun = async () => {
await t.play();
await sleep(600);
const score = (await json('__gm.world()')).shared.variables['sc-vars']?.score;
await stop();
return score;
};
const firstRun = await scoreOfRun();
const secondRun = await scoreOfRun();
const afterPlay = await saved('play');
check(
'the next run goes on where the last one ended, and the save says so',
firstRun === 2 && secondRun === 4 && afterPlay?.['sc-vars']?.score === 4,
JSON.stringify({ firstRun, secondRun, saved: afterPlay }),
);
const declaredScore = (await asset('sc-vars')).props.score;
check(
'the project itself keeps the declared start value',
declaredScore === 0,
`props.score = ${JSON.stringify(declaredScore)}`,
);
// One box runs in the editor: a run of its own, which must not touch what Play saved.
await t.select({
kind: 'object',
holderId: await json('__gm.state.project.activeSceneId'),
objectId: 'sc-brain-a',
});
await sleep(200);
const runBox = await json(`__gm.inspectorField('Run in editor')`);
if (runBox) await click(runBox.x, runBox.y);
await sleep(600);
const editorSave = await saved('editor');
const playSave = await saved('play');
if (runBox) await click(runBox.x, runBox.y);
await sleep(200);
check(
'an editor run saves into an area of its own and leaves the played save alone',
editorSave?.['sc-vars']?.score === 1 && playSave?.['sc-vars']?.score === 4,
JSON.stringify({ box: runBox, editor: editorSave, play: playSave }),
);
await selectAsset('sc-vars');
const clearButton = await t.find('Clear saved values');
if (clearButton) await click(clearButton.x, clearButton.y);
await sleep(200);
const clearedNotice = await json('__gm.state.notice');
const clearedBoth = (await saved('play')) === null && (await saved('editor')) === null;
const freshRun = await scoreOfRun();
check(
'"Clear saved values" forgets both saves, and the next run starts from the declared value',
Boolean(clearButton) &&
clearedBoth &&
freshRun === 2 &&
clearedNotice === 'Saved values of Score cleared',
JSON.stringify({ button: Boolean(clearButton), clearedBoth, freshRun, notice: clearedNotice }),
);
await t.clickToolbar('menu');
await t.clickText('Clear saved data');
await sleep(200);
const menuCleared = await saved('play');
check(
'"Clear saved data" in the menu forgets the saves of the whole project',
menuCleared === null && (await json('__gm.state.notice')) === 'Saved data cleared',
JSON.stringify({ play: menuCleared }),
);
// 32g. Everything this step added goes again.
await mutate(`
const p = __gm.state.project;
const scene = __gm.state.activeScene;
+5 -4
View File
@@ -47,13 +47,14 @@ export async function topbar(t) {
);
await shot('46-topbar');
// 46b. The one menu. Four entries, and the separator between what opens a project and what
// changes the one that is open.
// 46b. The one menu, with the separator between what opens a project and what changes the one
// that is open. Clearing the saved data is checked in 32.
await clickToolbar('menu');
const rows = await json('__gm.menuRows()');
const expected = ['New project', 'Open project…', null, 'Project settings…', 'Clear saved data'];
check(
'the menu button opens new project, the project picker and the project settings',
JSON.stringify(rows) === JSON.stringify(['New project', 'Open project…', null, 'Project settings…']),
'the menu button opens new project, the project picker, the settings and clearing saves',
JSON.stringify(rows) === JSON.stringify(expected),
JSON.stringify(rows),
);