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:
rootandClaude Opus 5 committed 2026-09-11 16:56:24 +02:00
1 parent 854ae2e756
commit 7c63c884ef
40 files changed
+895 -590

No files matched your search

@@ -1,14 +0,0 @@
import type { NodeDef } from '../../NodeRegistry';
import { any, readVariable, variableParam, variableTitle } from '../shared';
export const GetVariable: NodeDef = {
type: 'GetVariable',
label: 'Get variable',
category: 'variable',
description: "Reads one of this behavior's variables.",
inputs: [],
outputs: [any('value')],
params: [variableParam],
derivePorts: variableTitle('Get'),
run: (ctx, _inputs, params) => ({ outputs: readVariable(ctx, params) }),
};
@@ -1,24 +0,0 @@
import type { NodeDef } from '../../NodeRegistry';
import { GET_VARIABLES } from '../../nested';
import type { Value } from '../../values';
/**
* The plural of Get variable: one output per variable picked, so a graph reading a handful of them
* is one node instead of a column of five. The ports are declared on the node, the way Expand
* declares the fields of a struct.
*/
export const GetVariables: NodeDef = {
type: GET_VARIABLES,
label: 'Get variables',
category: 'variable',
description: "Reads several of this behavior's variables at once, one output per variable.",
inputs: [],
outputs: [],
params: [],
declaresPorts: 'outputs',
run: (ctx, _inputs, _params, def) => {
const outputs: Record<string, Value> = {};
for (const port of def.outputs) outputs[port.key] = ctx.variables[port.key] ?? null;
return { outputs };
},
};
@@ -1,14 +0,0 @@
import type { NodeDef } from '../../NodeRegistry';
import { any, exec, variableParam, variableTitle, writeVariable } from '../shared';
export const SetVariable: NodeDef = {
type: 'SetVariable',
label: 'Set variable',
category: 'variable',
description: "Writes one of this behavior's variables.",
inputs: [exec(), any('value')],
outputs: [exec()],
params: [variableParam],
derivePorts: variableTitle('Set'),
run: writeVariable,
};
@@ -1,25 +0,0 @@
import type { NodeDef } from '../../NodeRegistry';
import { SET_VARIABLES } from '../../nested';
import { writeTyped } from '../../values';
import { exec } from '../shared';
/**
* The plural of Set variable: one input per variable picked. An input left unconnected writes the
* value typed on the node, exactly as it does on the singular node – the node writes every variable
* it lists, every time it runs.
*/
export const SetVariables: NodeDef = {
type: SET_VARIABLES,
label: 'Set variables',
category: 'variable',
description: "Writes several of this behavior's variables at once, one input per variable.",
inputs: [exec()],
outputs: [exec()],
params: [],
declaresPorts: 'inputs',
run: (ctx, inputs, _params, def) => {
for (const port of def.inputs)
if (port.type !== 'exec') writeTyped(ctx.variables, port.key, inputs[port.key]);
return { next: 'exec' };
},
};
-18
View File
@@ -1,18 +0,0 @@
import type { NodeDef } from '../../NodeRegistry';
import { any, exec, readVariable, variableParam, variableTitle, writeVariable } from '../shared';
/** Get and Set in one node: the output can be read at any time, an arriving flow writes the input. */
export const Variable: NodeDef = {
type: 'Variable',
label: 'Variable',
category: 'variable',
description:
"Reads one of this behavior's variables at any time, and writes it when the flow arrives. " +
'A read after the write sees the new value.',
inputs: [exec(), any('value')],
outputs: [exec(), any('value')],
params: [variableParam],
derivePorts: variableTitle(''),
read: readVariable,
run: writeVariable,
};
@@ -0,0 +1,34 @@
import { portDefOf, VARIABLES } from '../../nested';
import { type NodeDef, withInlineDefault } from '../../NodeRegistry';
import { writeTyped } from '../../values';
import { exec } from '../shared';
/**
* Every variable picked is an output, read at the moment it is asked for. One switched to Set is an
* input too; the flow pins exist only while at least one is.
*/
export const Variables: NodeDef = {
type: VARIABLES,
label: 'Variables',
category: 'variable',
description:
"Reads this behavior's variables at any time. Those switched to Set are written together when " +
'the flow arrives, and a read after that sees the new value.',
inputs: [],
outputs: [],
params: [],
declaresPorts: 'both',
declaredPort: (port) => withInlineDefault(portDefOf(port)),
derivePorts: ({ node }) => {
const ports = node.ports ?? [];
const only = ports.length === 1 ? ports[0]?.key : undefined;
const shape = ports.some((p) => p.write) ? { inputs: [exec()], outputs: [exec()] } : {};
return only ? { ...shape, label: only } : shape;
},
read: (ctx) => ctx.variables,
run: (ctx, inputs, _params, def) => {
for (const port of def.inputs)
if (port.type !== 'exec') writeTyped(ctx.variables, port.key, inputs[port.key]);
return { next: 'exec' };
},
};