Add the Variable node and show the variable name in node titles
Get/Set variable nodes now title themselves "Get <name>" / "Set <name>", and
the new Variable node just "<name>"; the title is the same folded or open,
and a collapsed node shrinks to it. The redundant "Variable: <name>" row is
gone unless the variable was deleted ("<name>?" is the only hint then).
The Variable node sets its value when an exec flow arrives and exposes the
value at any time. Its output is read when a downstream node pulls it, not
frozen at the write, so count = count + 1 is one Variable node plus an Add.
Get variable keeps reading once per pulse: switching it would change the
behaviour of existing games.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5f8a308d62
commit
e9fa592078
19 files changed
+354
-38
No files matched your search
@@ -1,7 +1,6 @@
|
||||
import type { NodeDef } from '../../NodeRegistry';
|
||||
import { any, variableParam } from '../shared';
|
||||
import { any, readVariable, variableParam, variableTitle } from '../shared';
|
||||
|
||||
import { textOf } from '../../../model/Properties';
|
||||
export const GetVariable: NodeDef = {
|
||||
type: 'GetVariable',
|
||||
label: 'Get variable',
|
||||
@@ -10,7 +9,6 @@ export const GetVariable: NodeDef = {
|
||||
inputs: [],
|
||||
outputs: [any('value')],
|
||||
params: [variableParam],
|
||||
run: (ctx, _inputs, params) => ({
|
||||
outputs: { value: ctx.variables[textOf(params.variable ?? '')] ?? null },
|
||||
}),
|
||||
derivePorts: variableTitle('Get'),
|
||||
run: (ctx, _inputs, params) => ({ outputs: readVariable(ctx, params) }),
|
||||
};
|
||||
@@ -1,8 +1,6 @@
|
||||
import type { NodeDef } from '../../NodeRegistry';
|
||||
import { writeTyped } from '../../values';
|
||||
import { any, exec, variableParam } from '../shared';
|
||||
import { any, exec, variableParam, variableTitle, writeVariable } from '../shared';
|
||||
|
||||
import { textOf } from '../../../model/Properties';
|
||||
export const SetVariable: NodeDef = {
|
||||
type: 'SetVariable',
|
||||
label: 'Set variable',
|
||||
@@ -11,9 +9,6 @@ export const SetVariable: NodeDef = {
|
||||
inputs: [exec(), any('value')],
|
||||
outputs: [exec()],
|
||||
params: [variableParam],
|
||||
run: (ctx, inputs, params) => {
|
||||
const key = textOf(params.variable ?? '');
|
||||
if (key) writeTyped(ctx.variables, key, inputs.value);
|
||||
return { next: 'exec' };
|
||||
},
|
||||
derivePorts: variableTitle('Set'),
|
||||
run: writeVariable,
|
||||
};
|
||||
@@ -0,0 +1,18 @@
|
||||
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,
|
||||
};
|
||||
Reference in new issue
Block a user