A transition carries a name, so a state needs no visible port (#52)
game-maker / suite (push) Successful in 10m22s
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>
This commit is contained in:
1 parent
a041322a0e
commit
68c92daaa6
27 files changed
+1186
-38
No files matched your search
@@ -8,6 +8,7 @@ import { BUILT_IN_NODES } from '../../src/core/graph/nodes';
|
||||
import {
|
||||
createEmptyGraph,
|
||||
type DeclaredPort,
|
||||
type GraphLookup,
|
||||
NO_LOOKUP,
|
||||
type NodeContext,
|
||||
resolveDef,
|
||||
@@ -38,10 +39,19 @@ interface Case {
|
||||
repeat?: RunResult['repeat'] | null;
|
||||
/** Expected nested-behavior call; `null` asserts the node calls nothing. */
|
||||
call?: RunResult['call'] | null;
|
||||
/** The project around the graph – for a node whose step is written in another asset. */
|
||||
lookup?: GraphLookup;
|
||||
/** Assertions on what the node did to the context or to the handles it was given. */
|
||||
after?(ctx: FakeContext): void;
|
||||
}
|
||||
|
||||
/** A lookup holding one machine "m" with the given transitions – what `State transition` reads. */
|
||||
const machineLookup = (transitions: { from: string; to: string; name?: string }[]): GraphLookup => ({
|
||||
...NO_LOOKUP,
|
||||
machine: (id) =>
|
||||
id === 'm' ? { name: 'M', states: [], transitions: transitions.map((t) => ({ name: '', ...t })) } : null,
|
||||
});
|
||||
|
||||
const run = (type: string, c: Case): { result: RunResult; ctx: FakeContext } => {
|
||||
const ctx = fakeContext(c.context);
|
||||
const node = { id: 'n', type, x: 0, y: 0, params: c.params ?? {}, ports: c.ports };
|
||||
@@ -52,7 +62,8 @@ const run = (type: string, c: Case): { result: RunResult; ctx: FakeContext } =>
|
||||
inputs: [...execPorts(c.derivedInputs), ...registered.inputs],
|
||||
outputs: [...registered.outputs, ...execPorts(c.derivedOutputs)],
|
||||
};
|
||||
return { result: def.run!(ctx, c.inputs ?? {}, c.params ?? {}, def, c.entry ?? 'exec'), ctx };
|
||||
const lookup = c.lookup ?? NO_LOOKUP;
|
||||
return { result: def.run!(ctx, c.inputs ?? {}, c.params ?? {}, def, c.entry ?? 'exec', lookup), ctx };
|
||||
};
|
||||
|
||||
const at = (name: string, x: number, y: number) => ({ ...fakeEntity(name), x, y });
|
||||
@@ -140,6 +151,76 @@ const CASES: Record<string, Case[]> = {
|
||||
after: (ctx) => expect(ctx.states).toEqual({}),
|
||||
},
|
||||
],
|
||||
StateTransition: [
|
||||
{
|
||||
name: 'follows the transition of the asked-for name out of the current state',
|
||||
inputs: { machine: 'm' },
|
||||
params: { transition: 'alarm' },
|
||||
context: { states: { m: 's1' } },
|
||||
lookup: machineLookup([{ from: 's1', to: 's2', name: 'alarm' }]),
|
||||
next: 'exec',
|
||||
after: (ctx) => expect(ctx.states).toEqual({ m: 's2' }),
|
||||
},
|
||||
{
|
||||
// The point of naming transitions: one node works from every state that has that name.
|
||||
name: 'picks the same name out of whichever state the machine is in',
|
||||
inputs: { machine: 'm' },
|
||||
params: { transition: 'alarm' },
|
||||
context: { states: { m: 'searching' } },
|
||||
lookup: machineLookup([
|
||||
{ from: 'patrolling', to: 'chasing', name: 'alarm' },
|
||||
{ from: 'chasing', to: 'searching', name: 'lost' },
|
||||
{ from: 'searching', to: 'chasing', name: 'alarm' },
|
||||
]),
|
||||
next: 'exec',
|
||||
after: (ctx) => expect(ctx.states).toEqual({ m: 'chasing' }),
|
||||
},
|
||||
{
|
||||
name: 'a name the current state does not carry moves nothing',
|
||||
inputs: { machine: 'm' },
|
||||
params: { transition: 'lost' },
|
||||
context: { states: { m: 's1' } },
|
||||
lookup: machineLookup([{ from: 's1', to: 's2', name: 'alarm' }]),
|
||||
next: 'exec',
|
||||
after: (ctx) => expect(ctx.states).toEqual({ m: 's1' }),
|
||||
},
|
||||
{
|
||||
name: 'two of the name out of one state is no move: the graph never picked between them',
|
||||
inputs: { machine: 'm' },
|
||||
params: { transition: 'alarm' },
|
||||
context: { states: { m: 's1' } },
|
||||
lookup: machineLookup([
|
||||
{ from: 's1', to: 's2', name: 'alarm' },
|
||||
{ from: 's1', to: 's3', name: 'alarm' },
|
||||
]),
|
||||
next: 'exec',
|
||||
after: (ctx) => expect(ctx.states).toEqual({ m: 's1' }),
|
||||
},
|
||||
{
|
||||
// An unnamed transition is a name too, so a machine nobody named still steps.
|
||||
name: 'with no name asked for, follows the one unnamed transition',
|
||||
inputs: { machine: 'm' },
|
||||
context: { states: { m: 's1' } },
|
||||
lookup: machineLookup([{ from: 's1', to: 's2' }]),
|
||||
next: 'exec',
|
||||
after: (ctx) => expect(ctx.states).toEqual({ m: 's2' }),
|
||||
},
|
||||
{
|
||||
name: 'a state with nothing drawn out of it stays put',
|
||||
inputs: { machine: 'm' },
|
||||
context: { states: { m: 's2' } },
|
||||
lookup: machineLookup([{ from: 's1', to: 's2' }]),
|
||||
next: 'exec',
|
||||
after: (ctx) => expect(ctx.states).toEqual({ m: 's2' }),
|
||||
},
|
||||
{
|
||||
name: 'in no state yet there is nothing to move from',
|
||||
inputs: { machine: 'm' },
|
||||
lookup: machineLookup([{ from: 's1', to: 's2' }]),
|
||||
next: 'exec',
|
||||
after: (ctx) => expect(ctx.states).toEqual({}),
|
||||
},
|
||||
],
|
||||
Repeat: [
|
||||
{
|
||||
name: 'asks for as many body rounds as it was given, then continues at done',
|
||||
|
||||
Reference in new issue
Block a user