From 8aca11fb9794cdd2596c404afdead53a238cac79 Mon Sep 17 00:00:00 2001 From: Ryan Reilly Date: Sat, 27 Jan 2024 11:57:10 -0500 Subject: [PATCH] Changed ProofNode.appliedRule to enum --- package-lock.json | 6 +-- src/Proof/ProofHistory.ts | 52 +++++++++++++++++------- src/Proof/ProofModeMove.ts | 19 +++++++++ src/Proof/ProofNode.ts | 8 ++-- src/ProofTools/DeiterationTool.ts | 3 +- src/ProofTools/DoubleCutDeletionTool.ts | 3 +- src/ProofTools/DoubleCutInsertionTool.ts | 3 +- src/ProofTools/ErasureTool.ts | 3 +- src/ProofTools/InsertionTool.ts | 3 +- src/ProofTools/IterationTool.ts | 3 +- src/ProofTools/PasteInProof.ts | 3 +- src/ProofTools/ProofMoveMultiTool.ts | 3 +- src/ProofTools/ProofMoveSingleTool.ts | 3 +- src/ProofTools/ProofResizeTool.ts | 3 +- src/TreeContext.ts | 7 ++-- 15 files changed, 88 insertions(+), 34 deletions(-) create mode 100644 src/Proof/ProofModeMove.ts diff --git a/package-lock.json b/package-lock.json index 53333445..86321ed9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4557,9 +4557,9 @@ } }, "node_modules/vite": { - "version": "5.0.11", - "resolved": "https://registry.npmjs.org/vite/-/vite-5.0.11.tgz", - "integrity": "sha512-XBMnDjZcNAw/G1gEiskiM1v6yzM4GE5aMGvhWTlHAYYhxb7S3/V1s3m2LDHa8Vh6yIWYYB0iJwsEaS523c4oYA==", + "version": "5.0.12", + "resolved": "https://registry.npmjs.org/vite/-/vite-5.0.12.tgz", + "integrity": "sha512-4hsnEkG3q0N4Tzf1+t6NdN9dg/L3BM+q8SWgbSPnJvrgH2kgdyzfVJwbR1ic69/4uMJJ/3dqDZZE5/WwqW8U1w==", "dev": true, "dependencies": { "esbuild": "^0.19.3", diff --git a/src/Proof/ProofHistory.ts b/src/Proof/ProofHistory.ts index 23ea3774..dcbfba00 100644 --- a/src/Proof/ProofHistory.ts +++ b/src/Proof/ProofHistory.ts @@ -7,6 +7,7 @@ import {ProofNode} from "./ProofNode"; import {redrawProof} from "../SharedToolUtils/DrawUtils"; +import {ProofModeMove} from "./ProofModeMove"; import {TreeContext} from "../TreeContext"; /** @@ -36,20 +37,43 @@ export function appendStep(newStep: ProofNode, step?: number): void { //Determines which type of step was taken to give the created button a corresponding icon. const icon = document.createElement("Text"); - icon.className = - "fa fa-" + - { - "Single Move": "mouse-pointer", - "Multi Move": "arrows", - Resize: "arrows-alt", - "DC Insert": "dot-circle-o", - "DC Delete": "times-circle", - Insertion: "plus", - Erasure: "trash", - Iteration: "expand", - Deiteration: "compress", - Pasted: "files-o", - }[newStep.appliedRule]; + + let iconString = ""; + + switch (newStep.appliedRule) { + case ProofModeMove.DC_INSERT: + iconString = "dot-circle-o"; + break; + case ProofModeMove.DC_DELETE: + iconString = "times-circle"; + break; + case ProofModeMove.MOVE_SINGLE: + iconString = "mouse-pointer"; + break; + case ProofModeMove.MOVE_MULTI: + iconString = "arrows"; + break; + case ProofModeMove.ITERATION: + iconString = "expand"; + break; + case ProofModeMove.DEITERATION: + iconString = "compress"; + break; + case ProofModeMove.INSERTION: + iconString = "plus"; + break; + case ProofModeMove.ERASURE: + iconString = "trash"; + break; + case ProofModeMove.RESIZE: + iconString = "arrows-alt"; + break; + case ProofModeMove.PASTE_GRAPH: + iconString = "files-o"; + break; + } + + icon.className = "fa fa-" + iconString; button.appendChild(icon); newDiv.appendChild(button); diff --git a/src/Proof/ProofModeMove.ts b/src/Proof/ProofModeMove.ts new file mode 100644 index 00000000..5ab93d3b --- /dev/null +++ b/src/Proof/ProofModeMove.ts @@ -0,0 +1,19 @@ +/** + * @file Contains the enum for applied moves in Proof Mode. + * + * @author Ryan R + */ + +export enum ProofModeMove { + CLEAR, + DC_INSERT, + DC_DELETE, + MOVE_SINGLE, + MOVE_MULTI, + ITERATION, + DEITERATION, + INSERTION, + ERASURE, + RESIZE, + PASTE_GRAPH, +} diff --git a/src/Proof/ProofNode.ts b/src/Proof/ProofNode.ts index e51a81e0..cab29036 100644 --- a/src/Proof/ProofNode.ts +++ b/src/Proof/ProofNode.ts @@ -5,6 +5,7 @@ */ import {AEGTree} from "../AEG/AEGTree"; +import {ProofModeMove} from "./ProofModeMove"; import {TreeContext} from "../TreeContext"; /** @@ -18,9 +19,8 @@ export class ProofNode { /** * Inference rule applied in this ProofNode. - * @todo Make this an enum. -James */ - public appliedRule: string; + public appliedRule: ProofModeMove; /** * Index of this ProofNode in treeContext.ts' proof array. @@ -36,8 +36,8 @@ export class ProofNode { * @param rule Inference rule applied. * If not passed in, appliedRule will be set as an empty string. */ - public constructor(tree?: AEGTree, rule?: string) { - this.appliedRule = rule ?? ""; + public constructor(tree?: AEGTree, rule?: ProofModeMove) { + this.appliedRule = rule ?? ProofModeMove.CLEAR; this.tree = new AEGTree(tree?.sheet); this.index = TreeContext.proof.length; } diff --git a/src/ProofTools/DeiterationTool.ts b/src/ProofTools/DeiterationTool.ts index f732f1b1..8118b670 100644 --- a/src/ProofTools/DeiterationTool.ts +++ b/src/ProofTools/DeiterationTool.ts @@ -13,6 +13,7 @@ import {highlightNode, redrawProof, redrawTree} from "../SharedToolUtils/DrawUti import {illegalColor} from "../Themes"; import {offset} from "../SharedToolUtils/DragTool"; import {Point} from "../AEG/Point"; +import {ProofModeMove} from "../Proof/ProofModeMove"; import {ProofNode} from "../Proof/ProofNode"; import {reInsertNode} from "../SharedToolUtils/EditModeUtils"; import {TreeContext} from "../TreeContext"; @@ -81,7 +82,7 @@ export function deiterationMouseUp(event: MouseEvent): void { if (currentParent instanceof CutNode) { currentParent.remove(currentPoint); } - TreeContext.pushToProof(new ProofNode(currentProofTree, "Deiteration")); + TreeContext.pushToProof(new ProofNode(currentProofTree, ProofModeMove.DEITERATION)); } } legalNode = false; diff --git a/src/ProofTools/DoubleCutDeletionTool.ts b/src/ProofTools/DoubleCutDeletionTool.ts index c0721d2a..ec24661d 100644 --- a/src/ProofTools/DoubleCutDeletionTool.ts +++ b/src/ProofTools/DoubleCutDeletionTool.ts @@ -13,6 +13,7 @@ import {getCurrentProofTree} from "./ProofToolUtils"; import {illegalColor} from "../Themes"; import {offset} from "../SharedToolUtils/DragTool"; import {Point} from "../AEG/Point"; +import {ProofModeMove} from "../Proof/ProofModeMove"; import {ProofNode} from "../Proof/ProofNode"; import {readdChildren, reInsertNode} from "../SharedToolUtils/EditModeUtils"; import {TreeContext} from "../TreeContext"; @@ -75,7 +76,7 @@ export function doubleCutDeletionMouseMove(event: MouseEvent): void { * @param event Incoming MouseEvent. */ export function doubleCutDeletionMouseUp(event: MouseEvent): void { - const nextProof = new ProofNode(currentProofTree, "DC Delete"); + const nextProof = new ProofNode(currentProofTree, ProofModeMove.DC_DELETE); currentPoint = new Point(event.x - offset.x, event.y - offset.y); if (legalNode && currentNode instanceof CutNode) { diff --git a/src/ProofTools/DoubleCutInsertionTool.ts b/src/ProofTools/DoubleCutInsertionTool.ts index c86fa6b7..c66b8b16 100644 --- a/src/ProofTools/DoubleCutInsertionTool.ts +++ b/src/ProofTools/DoubleCutInsertionTool.ts @@ -21,6 +21,7 @@ import {getCurrentProofTree} from "./ProofToolUtils"; import {illegalColor, legalColor} from "../Themes"; import {offset} from "../SharedToolUtils/DragTool"; import {Point} from "../AEG/Point"; +import {ProofModeMove} from "../Proof/ProofModeMove"; import {ProofNode} from "../Proof/ProofNode"; import {TreeContext} from "../TreeContext"; @@ -108,7 +109,7 @@ export function doubleCutInsertionMouseUp(event: MouseEvent): void { const largeCut: CutNode = new CutNode(createEllipse(startingPoint, currentPoint)); const smallCut: CutNode = new CutNode(calcSmallEllipse(largeCut.ellipse)); - const nextProof = new ProofNode(currentProofTree, "DC Insert"); + const nextProof = new ProofNode(currentProofTree, ProofModeMove.DC_INSERT); if (!wasOut && largeCut.ellipse !== null && smallCut.ellipse !== null) { const legal = diff --git a/src/ProofTools/ErasureTool.ts b/src/ProofTools/ErasureTool.ts index e4232510..e3d61786 100644 --- a/src/ProofTools/ErasureTool.ts +++ b/src/ProofTools/ErasureTool.ts @@ -14,6 +14,7 @@ import {highlightNode, redrawProof, redrawTree} from "../SharedToolUtils/DrawUti import {illegalColor} from "../Themes"; import {offset} from "../SharedToolUtils/DragTool"; import {Point} from "../AEG/Point"; +import {ProofModeMove} from "../Proof/ProofModeMove"; import {ProofNode} from "../Proof/ProofNode"; import {reInsertNode} from "../SharedToolUtils/EditModeUtils"; import {TreeContext} from "../TreeContext"; @@ -75,7 +76,7 @@ export function erasureMouseMove(event: MouseEvent): void { */ export function erasureMouseUp(event: MouseEvent): void { if (legalNode) { - const nextProof = new ProofNode(currentProofTree, "Erasure"); + const nextProof = new ProofNode(currentProofTree, ProofModeMove.ERASURE); currentPoint = new Point(event.x - offset.x, event.y - offset.y); const currentParent = nextProof.tree.getLowestParent(currentPoint); diff --git a/src/ProofTools/InsertionTool.ts b/src/ProofTools/InsertionTool.ts index b13f6731..fd16d4c4 100644 --- a/src/ProofTools/InsertionTool.ts +++ b/src/ProofTools/InsertionTool.ts @@ -18,6 +18,7 @@ import {getCurrentProofTree} from "./ProofToolUtils"; import {illegalColor, legalColor} from "../Themes"; import {offset} from "../SharedToolUtils/DragTool"; import {Point} from "../AEG/Point"; +import {ProofModeMove} from "../Proof/ProofModeMove"; import {ProofNode} from "../Proof/ProofNode"; import {TreeContext} from "../TreeContext"; @@ -244,7 +245,7 @@ export function insertionMouseUp(event: MouseEvent): void { ) as AtomNode; currentTree.insert(tempAtom); } - TreeContext.pushToProof(new ProofNode(currentTree, "Insertion")); + TreeContext.pushToProof(new ProofNode(currentTree, ProofModeMove.INSERTION)); } } redrawProof(); diff --git a/src/ProofTools/IterationTool.ts b/src/ProofTools/IterationTool.ts index e06bd6bf..ff5a487e 100644 --- a/src/ProofTools/IterationTool.ts +++ b/src/ProofTools/IterationTool.ts @@ -23,6 +23,7 @@ import {getCurrentProofTree} from "./ProofToolUtils"; import {illegalColor, legalColor} from "../Themes"; import {offset} from "../SharedToolUtils/DragTool"; import {Point} from "../AEG/Point"; +import {ProofModeMove} from "../Proof/ProofModeMove"; import {ProofNode} from "../Proof/ProofNode"; import {TreeContext} from "../TreeContext"; @@ -111,7 +112,7 @@ export function iterationMouseUp(event: MouseEvent): void { const tempAtom: AtomNode = EditModeUtils.alterAtom(currentNode, moveDifference); currentProofTree.insert(tempAtom); } - TreeContext.pushToProof(new ProofNode(currentProofTree, "Iteration")); + TreeContext.pushToProof(new ProofNode(currentProofTree, ProofModeMove.ITERATION)); } } redrawProof(); diff --git a/src/ProofTools/PasteInProof.ts b/src/ProofTools/PasteInProof.ts index c89dd101..ff4e538b 100644 --- a/src/ProofTools/PasteInProof.ts +++ b/src/ProofTools/PasteInProof.ts @@ -8,6 +8,7 @@ import {AEGTree} from "../AEG/AEGTree"; import {changeCursorStyle, redrawProof} from "../SharedToolUtils/DrawUtils"; import {CutNode} from "../AEG/CutNode"; import {getCurrentProofTree} from "./ProofToolUtils"; +import {ProofModeMove} from "../Proof/ProofModeMove"; import {ProofNode} from "../Proof/ProofNode"; import {TreeContext} from "../TreeContext"; @@ -53,7 +54,7 @@ export function pasteInProofMouseUp(): void { if (legalNode) { changeCursorStyle("cursor: default"); currentTree.sheet = currentGraph; - TreeContext.pushToProof(new ProofNode(currentTree, "Pasted")); + TreeContext.pushToProof(new ProofNode(currentTree, ProofModeMove.PASTE_GRAPH)); } legalNode = false; redrawProof(); diff --git a/src/ProofTools/ProofMoveMultiTool.ts b/src/ProofTools/ProofMoveMultiTool.ts index 437243e6..f0702187 100644 --- a/src/ProofTools/ProofMoveMultiTool.ts +++ b/src/ProofTools/ProofMoveMultiTool.ts @@ -22,6 +22,7 @@ import {getCurrentProofTree, isMoveLegal} from "./ProofToolUtils"; import {illegalColor, legalColor} from "../Themes"; import {offset} from "../SharedToolUtils/DragTool"; import {Point} from "../AEG/Point"; +import {ProofModeMove} from "../Proof/ProofModeMove"; import {ProofNode} from "../Proof/ProofNode"; import {TreeContext} from "../TreeContext"; @@ -111,7 +112,7 @@ export function proofMoveMultiMouseMove(event: MouseEvent): void { export function proofMoveMultiMouseUp(event: MouseEvent): void { if (legalNode) { changeCursorStyle("cursor: default"); - const nextStep = new ProofNode(currentProofTree, "Multi Move"); + const nextStep = new ProofNode(currentProofTree, ProofModeMove.MOVE_MULTI); const moveDifference: Point = new Point( event.x - startingPoint.x, event.y - startingPoint.y diff --git a/src/ProofTools/ProofMoveSingleTool.ts b/src/ProofTools/ProofMoveSingleTool.ts index 84fbc8da..aa7d9704 100644 --- a/src/ProofTools/ProofMoveSingleTool.ts +++ b/src/ProofTools/ProofMoveSingleTool.ts @@ -28,6 +28,7 @@ import {getCurrentProofTree, isMoveLegal} from "./ProofToolUtils"; import {illegalColor, legalColor} from "../Themes"; import {offset} from "../SharedToolUtils/DragTool"; import {Point} from "../AEG/Point"; +import {ProofModeMove} from "../Proof/ProofModeMove"; import {ProofNode} from "../Proof/ProofNode"; import {TreeContext} from "../TreeContext"; @@ -120,7 +121,7 @@ export function proofMoveSingleMouseMove(event: MouseEvent): void { export function proofMoveSingleMouseUp(event: MouseEvent): void { if (legalNode) { changeCursorStyle("cursor: default"); - const nextStep = new ProofNode(currentProofTree, "Single Move"); + const nextStep = new ProofNode(currentProofTree, ProofModeMove.MOVE_SINGLE); const moveDifference: Point = new Point( event.x - startingPoint.x, event.y - startingPoint.y diff --git a/src/ProofTools/ProofResizeTool.ts b/src/ProofTools/ProofResizeTool.ts index 1ebe2e6f..2b7e84c7 100644 --- a/src/ProofTools/ProofResizeTool.ts +++ b/src/ProofTools/ProofResizeTool.ts @@ -27,6 +27,7 @@ import {getCurrentProofTree, proofCanInsert} from "./ProofToolUtils"; import {illegalColor, legalColor} from "../Themes"; import {offset} from "../SharedToolUtils/DragTool"; import {Point} from "../AEG/Point"; +import {ProofModeMove} from "../Proof/ProofModeMove"; import {ProofNode} from "../Proof/ProofNode"; import {TreeContext} from "../TreeContext"; @@ -122,7 +123,7 @@ export function proofResizeMouseUp(event: MouseEvent): void { if (tempCut.ellipse !== null) { if (isValid(tempCut)) { currentProofTree.insert(tempCut); - TreeContext.pushToProof(new ProofNode(currentProofTree, "Resize")); + TreeContext.pushToProof(new ProofNode(currentProofTree, ProofModeMove.RESIZE)); } } } diff --git a/src/TreeContext.ts b/src/TreeContext.ts index 402d3a2f..a3391c65 100644 --- a/src/TreeContext.ts +++ b/src/TreeContext.ts @@ -5,9 +5,10 @@ */ import {AEGTree} from "./AEG/AEGTree"; -import {DrawModeStack} from "./History/DrawModeStack"; -import {DrawModeNode} from "./History/DrawModeNode"; import {appendStep, deleteButtons} from "./Proof/ProofHistory"; +import {DrawModeNode} from "./History/DrawModeNode"; +import {DrawModeStack} from "./History/DrawModeStack"; +import {ProofModeMove} from "./Proof/ProofModeMove"; import {ProofNode} from "./Proof/ProofNode"; /** @@ -91,7 +92,7 @@ export class TreeContext { * @param newStep Incoming ProofNode. */ public static pushToProof(newStep: ProofNode): void { - if (newStep.appliedRule === "Pasted") { + if (newStep.appliedRule === ProofModeMove.PASTE_GRAPH) { this.proof.pop(); document.getElementById("Row: 1")?.remove(); newStep.index = 0;