A state can transition to itself: make transition and a second click on the same state connects a self transition, taking it fires On state exited and then On state entered every time, for local and global machines, while Set state into the current state stays silent as before; only states may connect to themselves, every other node is still refused, one self transition per state; the loop is drawn over the middle of the top edge with its arrow pointing down and its name at the apex, the preview already shows it while armed, and the inspector lists it once under Transitions out; new test hook transitionLabelAt, e2e 26e5 (#163)
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cc285af10a
commit
010b6a7f6c
12 files changed
+355
-33
No files matched your search
@@ -294,6 +294,35 @@ export async function stateMachine(t) {
|
||||
await shot('05c-both-ways');
|
||||
await undo();
|
||||
|
||||
// 26e5. (#163) The click that lands on the state the transition started from makes one back into
|
||||
// it – a loop over the node, which re-enters the state when it is taken.
|
||||
const beforeLoop = (await transitions()).length;
|
||||
await makeTransition(first, first);
|
||||
const looped = await transitions();
|
||||
const loop = looped.find((e) => e.from.node === first && e.to.node === first);
|
||||
check(
|
||||
'clicking the state the transition started from makes one back into itself',
|
||||
looped.length === beforeLoop + 1 && loop !== undefined,
|
||||
JSON.stringify(looped),
|
||||
);
|
||||
await evaluate(`__gm.stateMachine.nameTransition(${JSON.stringify(loop?.id)}, 'again')`);
|
||||
await settle();
|
||||
const loopLabel = await json(`__gm.stateMachine.transitionLabelAt(${JSON.stringify(loop?.id)})`);
|
||||
const firstRect = await json(`__gm.stateMachine.nodeRect(${JSON.stringify(first)})`);
|
||||
check(
|
||||
'it is stroked as a loop over the state: its name sits above the node, within its width',
|
||||
(await json(`__gm.stateMachine.edgeDrawn(${JSON.stringify(loop?.id)})`)) === true &&
|
||||
loopLabel !== null &&
|
||||
loopLabel.y < firstRect.y &&
|
||||
loopLabel.x > firstRect.x &&
|
||||
loopLabel.x < firstRect.x + firstRect.w,
|
||||
JSON.stringify({ loopLabel, firstRect }),
|
||||
);
|
||||
await shot('05d-self');
|
||||
await undo();
|
||||
await undo();
|
||||
check('undo takes the loop back', (await transitions()).length === beforeLoop);
|
||||
|
||||
// 26f. A behavior reads the machine: Set state on start, State branch every frame.
|
||||
const rig = await scaffoldBehavior(t, {
|
||||
assetId: 'sm-logic',
|
||||
|
||||
Reference in new issue
Block a user