Keep items a running game puts into a typed list
A typed global list lost the items the game had added to it. The item showed up in the inspector for a moment and then was gone again. - Since #254 the project hands out a typed list as a fresh copy each time, with the `$struct` marks stripped. - While a game runs, every change to the project runs `adoptDeclarations`. It took a declared value over when it differed from the last one it had seen, compared with `!==`. - The fresh copy never equals the last one by identity. So the empty list from the project overwrote the live list on every project change, for example when the game writes something back to the scene. - The comparison now uses `sameValue`. A real edit to the variable during a run still reaches the game. Tests: - ./check.sh: CHECK EXIT 0 - New unit test in scope.test.ts, red without the fix. - e2e 55i: a graph appends to a typed global list, then another asset changes during the run. With the fix {"filled":2,"afterEdit":2}, without it afterEdit is 1 and the check fails. - GM_STEPS=1,55: ALL PASSED, 26 checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b0d0868f55
commit
e1d3c0cadb
4 files changed
+85
-5
No files matched your search
@@ -180,6 +180,23 @@ describe('a declaration edited during the run', () => {
|
||||
expect(bag().score).toBe(1);
|
||||
});
|
||||
|
||||
/**
|
||||
* A list of typed items is declared as a fresh copy each time, the `$struct` marks taken off
|
||||
* (#254). Equal but not the same object must still count as unchanged.
|
||||
*/
|
||||
it('leaves a list the run has filled when the declaration only reads the same again', () => {
|
||||
const { f, shared, started, bag } = counting();
|
||||
f.stack.execute(new AddVariableCommand(shared.id, 'bags', 'list'));
|
||||
f.stack.execute(new SetAssetPropertyCommand(shared.id, 'bags', [{ Owner: 'Player', $struct: 'inv' }]));
|
||||
started.behaviors!.syncDeclarations();
|
||||
expect(bag().bags).toEqual([{ Owner: 'Player' }]);
|
||||
|
||||
bag().bags = [{ Owner: 'Player' }, { Owner: 'Test' }];
|
||||
f.stack.execute(new SetAssetPropertyCommand(shared.id, 'lives', 3));
|
||||
started.behaviors!.syncDeclarations();
|
||||
expect(bag().bags).toEqual([{ Owner: 'Player' }, { Owner: 'Test' }]);
|
||||
});
|
||||
|
||||
it('writes nothing back into the document', () => {
|
||||
const { f, shared, started, bag } = counting();
|
||||
f.stack.execute(new SetAssetPropertyCommand(shared.id, 'lives', 3));
|
||||
|
||||
Reference in new issue
Block a user