Skip to content

Commit

Permalink
Add escape action to avoid acting on an escape frame bug
Browse files Browse the repository at this point in the history
  • Loading branch information
vezwork committed Dec 11, 2024
1 parent 7970984 commit a062ea0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/edits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// initialValue,
// );

import { Action, Flowchart } from "./interpreter";
import { Action, Flowchart, Frame } from "./interpreter";

export const makeId = () => Math.random() + "";

Expand Down Expand Up @@ -67,8 +67,11 @@ export const setActionOnFrameOrAfter = (

export const addEscapeRoute = (fc: Flowchart, frameId: string) => {
const newFc = structuredClone(fc);
const newFrame = {
const newFrame: Frame = {
id: Math.random() + "",
action: {
type: "escape",
},
};
newFc.frames[frameId].escapeRouteFrameId = newFrame.id;
newFc.frames[newFrame.id] = newFrame;
Expand Down
9 changes: 7 additions & 2 deletions src/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export type Action =
| {
type: "start";
}
| {
type: "escape";
}
| {
// this one won't be used in the real deal; we'll want to have
// better ways than opaque functions to specify & show actions
Expand Down Expand Up @@ -302,7 +305,7 @@ function performAction(
}
}

if (!action || action.type === "start") {
if (!action || action.type === "start" || action.type === "escape") {
proceedWith([{ ...scene, actionAnnotation: undefined }]);
} else if (action.type === "test-func") {
proceedWith(action.func(scene));
Expand Down Expand Up @@ -901,7 +904,9 @@ export function getActionText(action?: Action): string {
} else if (action.type === "test-cond") {
return "if";
} else if (action.type === "start") {
return "start";
return "†enter";
} else if (action.type === "escape") {
return "⛧salvation";
} else if (action.type === "workspace-pick") {
return (
"move " +
Expand Down

0 comments on commit a062ea0

Please sign in to comment.