game-maker / suite (push) Failing after 8m59s
This reverses the design of the previous commit. `PropertyDef.scope` is gone without replacement: a behavior variable is an object property again, without exception, and sharing is something you point at rather than something you declare twice. A **Variables asset** is declarations and nothing else -- no graph, no position, never placed, no tab of its own (`TAB_OF_ASSET` is already `Partial<>`, so that costs no line). A `Variables` node names one through its new `variablesAsset` setting, empty meaning the behavior's own variables as before, and then reads and writes one value per key for the whole run. Its property list follows the chosen source, which was the actual request: a value another graph declared is now offerable, where before every participant had to declare the name itself. That deletes more than it adds (-72 lines net): `globalConflicts` and its run-stopping kind clash, `SetVariableScopeCommand`, the scope picker, both object-inspector filters and the "shared by the whole run" note on the placed object. A typo is no longer a silent second variable -- naming an asset is picking from a list. And two Variables assets may carry the same key without meeting, because the asset is the key, not the name. The one shape it copies is the one that already existed: `Set state` picks its machine the same way. Lifetime is unchanged. The bag is built at `BehaviorSystem.start()` from the declarations and never written back, so playing in the editor cannot change the project -- which is the whole reason a counter must not be an object property (`World.syncToModel` would `commit()` it, and the coin counter would stand at 7 for good). Full symmetry across that gap, without mirroring anything. Two named wires: `Inspector.liveVariables` shows the values as they stand while a run is on and falls back to the declarations when it ends, and `adoptDeclarations()` takes a key into the run *only where the document changed it since the last sync*. Without that condition any unrelated project edit would snap a running counter back to its starting value; a counter-test bends exactly that and falls over. Nothing was ever cached, incidentally: `GraphInterpreter` only pulse-caches nodes without a `read`, and the variable node has one. The wire was missing. The state machine `Scope` row is now an ordinary `enum` row through `createFieldRow`. It was hand-built from an `HStack` with a ghost dropdown and began ~34px left of every value above it; the explanations beside `Local` and `Global` are gone from the menu, the sentence below the row keeps saying it. Machine scope is otherwise untouched -- `StateMachineAsset.scope`, `SetMachineScopeCommand`, `stateBag()` and its persistence all stand, so #59 stays closed as built and `Scope` as a type now carries machines alone. Six counter-proofs, each biting at its own guard. One of them did not bite at first: the suggestion list was computed twice, in `nodeSection` and `portSection`, so only the browser test covered the request itself. It is one named function now, `variableChoices`, with a unit test of its own. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
119 lines
4.5 KiB
TypeScript
119 lines
4.5 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import {
|
|
CreateAssetCommand,
|
|
SetAssetPropertyCommand,
|
|
SetMachineScopeCommand,
|
|
} from '../../src/core/commands/assetCommands';
|
|
import { SetOverrideCommand } from '../../src/core/commands/sceneObjectCommands';
|
|
import { AddVariableCommand } from '../../src/core/commands/variableCommands';
|
|
import { deserializeProject, serializeProject } from '../../src/core/store/serialize';
|
|
import { makeBehavior, makeSpriteScene, place, roundTrip } from '../helpers';
|
|
|
|
describe('serialize', () => {
|
|
it('round-trips a project', () => {
|
|
const f = makeSpriteScene();
|
|
const box = place(f, f.spriteId, { x: 7, y: 8 });
|
|
f.stack.execute(new SetOverrideCommand(f.sceneId, box, 'width', 33));
|
|
expect(roundTrip(f.project)).toEqual(f.project);
|
|
});
|
|
|
|
/** A behavior's own rows are not the common ones: coercing against those alone dropped the value. */
|
|
it('keeps a behavior running in the editor across a save', () => {
|
|
const f = makeSpriteScene();
|
|
const behavior = makeBehavior(f, 'B');
|
|
f.stack.execute(new SetAssetPropertyCommand(behavior.id, 'runInEditor', true));
|
|
const loaded = roundTrip(f.project).assets.find((a) => a.id === behavior.id)!;
|
|
expect(loaded.props.runInEditor).toBe(true);
|
|
});
|
|
|
|
/** The declarations of a Variables asset and their starting values are the whole asset. */
|
|
it('round-trips a Variables asset and the scope of a state machine', () => {
|
|
const f = makeSpriteScene();
|
|
const shared = new CreateAssetCommand('variables', 'Score');
|
|
f.stack.execute(shared);
|
|
f.stack.execute(new AddVariableCommand(shared.asset.id, 'score', 'number'));
|
|
f.stack.execute(new SetAssetPropertyCommand(shared.asset.id, 'score', 7));
|
|
const machine = new CreateAssetCommand('statemachine', 'M');
|
|
f.stack.execute(machine);
|
|
f.stack.execute(new SetMachineScopeCommand(machine.asset.id, 'global'));
|
|
expect(roundTrip(f.project)).toEqual(f.project);
|
|
});
|
|
|
|
/** `local` is the absence of the field, so a project made before scopes existed saves back byte-alike. */
|
|
it('writes no scope for a local machine and reads an unknown one as local', () => {
|
|
const f = makeSpriteScene();
|
|
makeBehavior(f, 'B', ['score']);
|
|
f.stack.execute(new CreateAssetCommand('statemachine', 'M'));
|
|
expect(JSON.stringify(serializeProject(f.project))).not.toContain('scope');
|
|
|
|
const loaded = deserializeProject({
|
|
assets: [{ id: 'm1', type: 'statemachine', name: 'M', scope: 'planet' }],
|
|
});
|
|
const machine = loaded.assets[0]!;
|
|
if (machine.type !== 'statemachine') throw new Error('wrong types');
|
|
expect(machine.scope).toBeUndefined();
|
|
});
|
|
|
|
it('repairs broken documents', () => {
|
|
const project = deserializeProject(
|
|
{
|
|
name: 'Broken',
|
|
activeSceneId: 'missing',
|
|
assets: [
|
|
{
|
|
id: 's1',
|
|
type: 'scene',
|
|
name: 'Scene',
|
|
props: { backgroundColor: '#000000', junk: 1 },
|
|
objects: [
|
|
{
|
|
id: 'o1',
|
|
assetId: 'sp1',
|
|
position: { x: '5', y: null },
|
|
overrides: { color: '#00ff00', width: -3, foo: 1 },
|
|
},
|
|
{ id: 'o2', assetId: 'nope', position: {} },
|
|
{ id: 'o3', assetId: 's1', position: {} },
|
|
],
|
|
},
|
|
{ id: 'sp1', type: 'sprite', props: { width: 10 } },
|
|
// An asset type this build does not know (a newer document, a renamed type).
|
|
{ id: 'x', type: 'sound' },
|
|
{ type: 'camera' },
|
|
],
|
|
},
|
|
'fallback-id',
|
|
);
|
|
expect(project.id).toBe('fallback-id');
|
|
expect(project.activeSceneId).toBe('s1');
|
|
expect(project.assets.map((a) => a.id)).toEqual(['s1', 'sp1']);
|
|
const scene = project.assets[0]!;
|
|
expect(scene.type === 'scene' && scene.props).toEqual({ backgroundColor: 0 });
|
|
const objects = scene.type === 'scene' ? scene.objects : [];
|
|
expect(objects).toHaveLength(1);
|
|
expect(objects[0]).toEqual({
|
|
id: 'o1',
|
|
assetId: 'sp1',
|
|
name: '',
|
|
position: { x: 5, y: 0, z: 0 },
|
|
editorOffset: { x: 0, y: 0 },
|
|
overrides: { color: 0x00ff00, width: 1 },
|
|
parentId: '',
|
|
instanceEdits: {},
|
|
});
|
|
expect(project.assets[1]!.name).toBe('sprite');
|
|
expect(project.assets[1]!.props).toEqual({
|
|
enabled: true,
|
|
scale: 1,
|
|
rotation: 0,
|
|
mirrorX: false,
|
|
mirrorY: false,
|
|
width: 10,
|
|
height: 100,
|
|
color: 0xffffff,
|
|
texture: '',
|
|
shader: '',
|
|
});
|
|
});
|
|
});
|