A state machine is an asset whose graph holds one `State` node per state (no ports, name as title), edited in a new "State machine" tab that reuses the graph canvas: right-click places "State n", snap toggle shared with the Behavior tab via SnapToggle. `statemachine` is a value kind like texture (port, literal node, variable, struct field, tagged list item). Behaviors use it through `State branch` (one exec output per state) and `Set state` (one exec input per state; the interpreter now hands `run` the entry port). States live per behavior instance in NodeContext.states, with no initial state. Ports derive from the inline picker or a wired `State machine` literal; BehaviorLookup became GraphLookup with behavior(id) and machine(id). The Graph tab is labelled "Behavior" (key unchanged). Unit tests (state-machine, kinds, catalog, ports), e2e step 26 and README added. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
23 lines
902 B
TypeScript
23 lines
902 B
TypeScript
import type { GraphLookup } from '../graph/lookup';
|
|
import { statesOf } 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(asset) };
|
|
},
|
|
machine: (assetId) => {
|
|
const asset = findAssetOf(project, assetId, 'statemachine');
|
|
return asset ? { name: asset.name, states: statesOf(asset.graph) } : null;
|
|
},
|
|
};
|
|
}
|