Split a struct output into one pin per field (#256)
Reading one field of a struct needed its own Expand node, even where the graph already knows the struct type. A split output shows the fields directly on the node, so a Find … Match test becomes a single Equals and the wires keep running left to right. - Right-clicking an output pin offers "Split into <Type> fields" when the type is known and "Split as …" for every other struct asset. The output is replaced by one pin per field with the field's kind. - The type is known for typed struct variables, typed Pack/Expand, fields of another split and item of For each, Find, Match and Item at over a typed list (portSplits.ts). - Right-clicking a field pin offers "Recombine". Splitting drops the edges of the whole output, recombining drops the field edges. One undo step brings them back. - The split is stored as GraphNode.splits and saved with the graph. Copy and paste carry it along. - Field pins follow the struct asset like a typed Expand. A new field gets a pin, a removed field loses pin and edge, a renamed field keeps its edge. Deleting the asset keeps the last fields. The delete dialog counts splits, so it now says "node(s)" instead of "Pack/Expand node(s)". - Renaming a variable carries its split and the field edges along. - At run time the node still produces the whole value. A field pin reads its field like Expand, a missing field reads as empty. - Limits: outputs only, one level, behavior graphs only. Tests: - ./check.sh: 185 files, 2706 tests, CHECK EXIT 0 - e2e GM_STEPS=1-6,54,55: ALL PASSED, 303 checks - New port-splits.test.ts with 12 tests. e2e 6z-vi with 3 checks using a real mouse: split Find.item, wire item.Name into the test and Match.item.Amount into the log (logs 7), recombine. - Counter-checks: without field reads in the interpreter, without rename in the split, without moving edges on rename and without cleanup on field removal one unit test fails each. In the browser, without field reads nothing is logged and without type inference the split entry is missing. - Check total in README: 1520. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2aaca01929
commit
38e0f656be
17 files changed
+705
-22
No files matched your search
@@ -55,6 +55,7 @@ import { DRAG_THRESHOLD, GraphDrags } from './graphDrags';
|
||||
import type { GraphCanvasHost } from './graphHost';
|
||||
import { openAnnotationMenu, openLinkMenu, openNodeMenu } from './graphMenus';
|
||||
import { NodePalette, type PaletteAction } from './NodePalette';
|
||||
import { splitEntries } from './splitMenu';
|
||||
import { type PaletteEntry, paletteEntries } from './paletteEntries';
|
||||
import { NODE_WIDTH, NodeView, TITLE_HEIGHT } from './NodeView';
|
||||
import { drawGraphGrid, FIT_MARGIN, ZOOM_LIMITS, zoomedAbout } from './graphView';
|
||||
@@ -490,7 +491,12 @@ export class GraphCanvas extends Widget {
|
||||
const { id } = view.node;
|
||||
if (hit) {
|
||||
const key = hit.port.key;
|
||||
this.openLinks((g) => (hit.isOutput ? edgesOutOf(g, id, key) : edgesInto(g, id, key)), e.global);
|
||||
const extras = hit.isOutput ? splitEntries(this.state, this.assetId, view.node, hit.port) : [];
|
||||
this.openLinks(
|
||||
(g) => (hit.isOutput ? edgesOutOf(g, id, key) : edgesInto(g, id, key)),
|
||||
e.global,
|
||||
extras,
|
||||
);
|
||||
} else {
|
||||
// Right-clicking inside a multi-selection acts on all of it; outside it, on that node alone.
|
||||
if (!this.state.selectedNodeIds.includes(id)) this.state.select(nodeSelection(this.assetId, [id]));
|
||||
@@ -743,9 +749,13 @@ export class GraphCanvas extends Widget {
|
||||
if (this.state.execute(command)) this.state.select(nodeSelection(this.assetId, [command.node.id]));
|
||||
}
|
||||
|
||||
private openLinks(pick: (graph: Graph) => Graph['edges'], at: { x: number; y: number }): void {
|
||||
private openLinks(
|
||||
pick: (graph: Graph) => Graph['edges'],
|
||||
at: { x: number; y: number },
|
||||
extras: readonly MenuItem[] = [],
|
||||
): void {
|
||||
const graph = this.asset()?.graph;
|
||||
if (graph) openLinkMenu(this.state, this.assetId, pick(graph), at.x, at.y);
|
||||
if (graph) openLinkMenu(this.state, this.assetId, pick(graph), at.x, at.y, extras);
|
||||
}
|
||||
|
||||
/** Shortened to the canvas: since the Particles tab put a preview beside it, a canvas can be narrow. */
|
||||
|
||||
Reference in new issue
Block a user