Replace the five variable nodes with one Variables node
A single node now lists any number of variables. Every entry is an output that reads the current value whenever it is pulled; an entry switched to Set is also an input and is written when the flow arrives. Exec pins only exist while at least one entry writes, and all inputs are read before any write, so one node can swap two variables. Get/Set variable, Get/Set variables and Variable are gone. Old project files are converted on load: each old node becomes a Variables node with the same variables, edges and typed values. A written port without a typed value now shows the zero of its kind on the node body, matching what the inspector shows and what the run writes. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
854ae2e756
commit
7c63c884ef
40 files changed
+895
-590
No files matched your search
+25
-25
@@ -44,13 +44,13 @@ function withMover<F extends ProjectFixture>(fixture: F) {
|
||||
const edit = graphEditor(fixture, behavior);
|
||||
const held = edit.addNode('OnKeyHeld', { key: 'ArrowRight' });
|
||||
const owner = edit.addNode('Owner');
|
||||
const speed = edit.addNode('GetVariable', { variable: 'speed' });
|
||||
const speed = edit.variables(['speed']);
|
||||
const mul = edit.addNode('Multiply');
|
||||
const move = edit.addNode('Move');
|
||||
edit.wire([
|
||||
[held, 'exec', move, 'exec'],
|
||||
[owner, 'object', move, 'object'],
|
||||
[speed, 'value', mul, 'a'],
|
||||
[speed, 'speed', mul, 'a'],
|
||||
[held, 'dt', mul, 'b'],
|
||||
[mul, 'result', move, 'dx'],
|
||||
]);
|
||||
@@ -137,7 +137,7 @@ describe('GraphInterpreter', () => {
|
||||
const update = edit.addNode('OnUpdate');
|
||||
const owner = edit.addNode('Owner');
|
||||
const axis = edit.addNode('AxisInput');
|
||||
const speed = edit.addNode('GetVariable', { variable: 'speed' });
|
||||
const speed = edit.variables(['speed']);
|
||||
const move = edit.addNode('Move');
|
||||
edit.wire([
|
||||
[update, 'exec', move, 'exec'],
|
||||
@@ -145,7 +145,7 @@ describe('GraphInterpreter', () => {
|
||||
[owner, 'object', move, 'object'],
|
||||
[axis, 'x', move, 'dx'],
|
||||
[axis, 'y', move, 'dy'],
|
||||
[speed, 'value', move, 'scale'],
|
||||
[speed, 'speed', move, 'scale'],
|
||||
]);
|
||||
expect(behavior.graph.nodes).toHaveLength(5);
|
||||
|
||||
@@ -196,20 +196,20 @@ describe('GraphInterpreter', () => {
|
||||
it('follows Branch, writes variables and logs', () => {
|
||||
const { behavior, edit } = emptyBehavior(['count']);
|
||||
const start = edit.addNode('OnStart');
|
||||
const get = edit.addNode('GetVariable', { variable: 'count' });
|
||||
const get = edit.variables(['count']);
|
||||
const cmp = edit.addNode('Compare', { op: '<', b: 3 });
|
||||
const branch = edit.addNode('Branch');
|
||||
const add = edit.addNode('Add', { b: 1 });
|
||||
const set = edit.addNode('SetVariable', { variable: 'count' });
|
||||
const set = edit.variables(['count'], { write: true });
|
||||
const logThen = edit.addNode('Log', { message: 'then' });
|
||||
const logElse = edit.addNode('Log', { message: 'else' });
|
||||
edit.wire([
|
||||
[start, 'exec', branch, 'exec'],
|
||||
[get, 'value', cmp, 'a'],
|
||||
[get, 'count', cmp, 'a'],
|
||||
[cmp, 'result', branch, 'condition'],
|
||||
[branch, 'then', set, 'exec'],
|
||||
[get, 'value', add, 'a'],
|
||||
[add, 'result', set, 'value'],
|
||||
[get, 'count', add, 'a'],
|
||||
[add, 'result', set, 'count'],
|
||||
[set, 'exec', logThen, 'exec'],
|
||||
[branch, 'else', logElse, 'exec'],
|
||||
]);
|
||||
@@ -301,15 +301,15 @@ describe('Repeat', () => {
|
||||
const { edit } = fixture;
|
||||
const start = edit.addNode('OnStart');
|
||||
const repeat = edit.addNode('Repeat', { times });
|
||||
const get = edit.addNode('GetVariable', { variable: 'count' });
|
||||
const get = edit.variables(['count']);
|
||||
const add = edit.addNode('Add');
|
||||
const set = edit.addNode('SetVariable', { variable: 'count' });
|
||||
const set = edit.variables(['count'], { write: true });
|
||||
edit.wire([
|
||||
[start, 'exec', repeat, 'exec'],
|
||||
[repeat, 'body', set, 'exec'],
|
||||
[get, 'value', add, 'a'],
|
||||
[get, 'count', add, 'a'],
|
||||
[repeat, 'index', add, 'b'],
|
||||
[add, 'result', set, 'value'],
|
||||
[add, 'result', set, 'count'],
|
||||
]);
|
||||
return { ...fixture, nodes: { repeat, set } };
|
||||
}
|
||||
@@ -343,15 +343,15 @@ describe('Repeat', () => {
|
||||
const start = edit.addNode('OnStart');
|
||||
const outer = edit.addNode('Repeat', { times: 3 });
|
||||
const inner = edit.addNode('Repeat', { times: 4 });
|
||||
const get = edit.addNode('GetVariable', { variable: 'count' });
|
||||
const get = edit.variables(['count']);
|
||||
const add = edit.addNode('Add', { b: 1 });
|
||||
const set = edit.addNode('SetVariable', { variable: 'count' });
|
||||
const set = edit.variables(['count'], { write: true });
|
||||
edit.wire([
|
||||
[start, 'exec', outer, 'exec'],
|
||||
[outer, 'body', inner, 'exec'],
|
||||
[inner, 'body', set, 'exec'],
|
||||
[get, 'value', add, 'a'],
|
||||
[add, 'result', set, 'value'],
|
||||
[get, 'count', add, 'a'],
|
||||
[add, 'result', set, 'count'],
|
||||
]);
|
||||
const ctx = fakeContext({ variables: { count: 0 } });
|
||||
new GraphInterpreter(behavior.graph).fire('OnStart', ctx);
|
||||
@@ -362,19 +362,19 @@ describe('Repeat', () => {
|
||||
const { behavior, edit } = emptyBehavior(['count']);
|
||||
const start = edit.addNode('OnStart');
|
||||
const repeat = edit.addNode('Repeat', { times: 3 });
|
||||
const get = edit.addNode('GetVariable', { variable: 'count' });
|
||||
const get = edit.variables(['count']);
|
||||
const add = edit.addNode('Add', { b: 1 });
|
||||
const set = edit.addNode('SetVariable', { variable: 'count' });
|
||||
const after = edit.addNode('SetVariable', { variable: 'count' });
|
||||
const set = edit.variables(['count'], { write: true });
|
||||
const after = edit.variables(['count'], { write: true });
|
||||
const afterAdd = edit.addNode('Multiply', { b: 10 });
|
||||
edit.wire([
|
||||
[start, 'exec', repeat, 'exec'],
|
||||
[repeat, 'body', set, 'exec'],
|
||||
[get, 'value', add, 'a'],
|
||||
[add, 'result', set, 'value'],
|
||||
[get, 'count', add, 'a'],
|
||||
[add, 'result', set, 'count'],
|
||||
[repeat, 'done', after, 'exec'],
|
||||
[get, 'value', afterAdd, 'a'],
|
||||
[afterAdd, 'result', after, 'value'],
|
||||
[get, 'count', afterAdd, 'a'],
|
||||
[afterAdd, 'result', after, 'count'],
|
||||
]);
|
||||
const ctx = fakeContext({ variables: { count: 0 } });
|
||||
new GraphInterpreter(behavior.graph).fire('OnStart', ctx);
|
||||
@@ -447,7 +447,7 @@ describe('variable commands', () => {
|
||||
expect(behavior.variables[0]!.key).toBe('velocity');
|
||||
expect(behavior.props).toEqual({ enabled: true, runInEditor: false, velocity: 0 });
|
||||
expect(object(logic).overrides).toEqual({ velocity: 5 });
|
||||
expect(findNode(behavior.graph, nodes.speed.id)!.params.variable).toBe('velocity');
|
||||
expect(findNode(behavior.graph, nodes.speed.id)!.ports).toEqual([{ key: 'velocity', kind: 'number' }]);
|
||||
stack.undo();
|
||||
expect(behavior.variables[0]!.key).toBe('speed');
|
||||
expect(object(logic).overrides).toEqual({ speed: 5 });
|
||||
|
||||
Reference in new issue
Block a user