Let a node work out its own ports

Ports that vary per node already existed, but only for the three nested-behavior
types, and the rule for them sat as a switch on type names in nested.ts – the
one place in the project that knew node types by name. It dissolves into two
optional contracts on NodeDef, so a type carries its own rule:

  declaresPorts  the node holds an editable list, shown as a section in the
                 inspector – behavior start/end, and now Pack/Expand
  derivePorts    the node computes them from its settings – Sequence from a
                 count, Run behavior from the behavior it names

Sequence gains an Outputs setting (2 to 26). Its keys stay a, b, c and count on
with d, e, so the edges of the sequences already out there survive.

A param can now take a port away, and the edge on it would stay: it draws as
nothing yet survives every save, and comes back to life if the port returns.
SetNodeParamCommand takes those edges with it, which also closes the same leak
that switching a Run behavior node's target has always had.

The port editor addresses its node by id rather than by type, so two Pack nodes
can live in one graph, and it calls the rows Fields when they are not a
behavior's signature.
This commit is contained in:
root committed 2026-09-10 08:14:18 +02:00
1 parent 2cf788eedd
commit b6a609ae24
23 files changed
+438 -98

No files matched your search

+29 -1
View File
@@ -114,8 +114,15 @@ export class MoveNodeCommand implements Command {
}
}
/** Sets a node param or the inline value of an unconnected data input. */
/**
* Sets a node param or the inline value of an unconnected data input. A param can decide how many
* ports the node has, so this takes the edges of ports the new value does away with: an edge on a
* port that is gone draws as nothing but survives every save, and comes back to life if the port
* ever returns.
*/
export class SetNodeParamCommand extends SetBagValueCommand<GraphNode> {
private orphans: Removed<GraphEdge>[] = [];
constructor(
private readonly assetId: string,
private readonly nodeId: string,
@@ -125,6 +132,27 @@ export class SetNodeParamCommand extends SetBagValueCommand<GraphNode> {
super(key, `Set ${key}`);
}
override execute(project: Project): void {
super.execute(project);
const graph = requireBehavior(project, this.assetId).graph;
const node = requireNode(project, this.assetId, this.nodeId);
const def = resolveDef(node, behaviorLookup(project));
if (!def) return;
const outputs = new Set(def.outputs.map((p) => p.key));
const inputs = new Set(def.inputs.map((p) => p.key));
this.orphans = removeWhere(
graph.edges,
(e) =>
(e.from.node === this.nodeId && !outputs.has(e.from.port)) ||
(e.to.node === this.nodeId && !inputs.has(e.to.port)),
);
}
override undo(project: Project): void {
super.undo(project);
restoreAt(requireBehavior(project, this.assetId).graph.edges, this.orphans);
}
protected override resolveTarget(project: Project): GraphNode {
return requireNode(project, this.assetId, this.nodeId);
}