game-maker / suite (push) Successful in 10m22s
A state keeps its `in`/`out` exec pins in the model and the editor never draws
them. That is the whole trick: connecting, undo, deleting a state and saving all
keep working untouched, because `normalizeGraph` filters nodes and never edges,
and no edge ever checks its port key against a NodeDef. Only two places change --
`NodeView.redraw` stops drawing the row, and `portAt` refuses to hand one out, so
an invisible pin cannot be grabbed either.
Transitions are drawn by right-clicking a state, `Make transition`, then clicking
the target. The armed mode takes the same shape as a live drag, so the existing
preview draws it with no second code path, and it dies with Escape, a click on
empty canvas or a switch to another asset.
Removing the pins removed the only handle a transition had: edges have no
hit-test anywhere, and the pin right-click was the sole route to Disconnect.
The inspector's TRANSITIONS OUT / TRANSITIONS IN lists are therefore not a
convenience, they are the delete path.
`GraphEdge` gained an optional `label`, which `normalizeGraph` has to pass
through explicitly or a saved name is dropped on load. `State transition`
replaces `Next state`: it takes the machine on an input port and the name from a
picker, and resolves against the *current* state. Names are deliberately not
unique across a machine -- two states may both have an `alarm` -- so a node named
`alarm` moves whichever state has one, and an empty name follows the single
unnamed edge.
The geometry moved to a Pixi-free `transitions.ts`: a gap to the box border, and
a fan that puts a pair of opposite edges beside each other instead of on top of
each other. Keeping it as plain maths is what let a screenshot bug become a unit
test -- an earlier pin-to-pin line ran under the target node and took its
arrowhead with it, because `nodeLayer` sits above `edgeLayer`.
One limit stands and is not fixed here: `ConnectCommand` rejects a second edge
between the same two states ("Already connected"), because every transition
hangs off the same two ports. With names, `A --alarm--> B` beside
`A --seen--> B` is a sensible pair, so this is worth its own issue.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
28 lines
1014 B
TypeScript
28 lines
1014 B
TypeScript
import type { GraphLookup } from '../graph/lookup';
|
|
import { statesOf, transitionsOf } from '../graph/stateMachine';
|
|
import { resolveAssetProps } from '../properties/resolve';
|
|
import { findAssetOf, type Project } from './Project';
|
|
|
|
/**
|
|
* What a graph may see of the project around it. A behavior's `defaults` are its variable values;
|
|
* every call copies them, so a nested behavior never carries state from one call to the next.
|
|
*/
|
|
export function graphLookup(project: Project): GraphLookup {
|
|
return {
|
|
behavior: (assetId) => {
|
|
const asset = findAssetOf(project, assetId, 'behavior');
|
|
if (!asset) return null;
|
|
return { name: asset.name, graph: asset.graph, defaults: resolveAssetProps(project, asset) };
|
|
},
|
|
machine: (assetId) => {
|
|
const asset = findAssetOf(project, assetId, 'statemachine');
|
|
if (!asset) return null;
|
|
return {
|
|
name: asset.name,
|
|
states: statesOf(asset.graph),
|
|
transitions: transitionsOf(asset.graph),
|
|
};
|
|
},
|
|
};
|
|
}
|