Skip to content

Commit

Permalink
Changed ProofNode.appliedRule to enum
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanR712 committed Jan 27, 2024
1 parent 531aced commit 8aca11f
Show file tree
Hide file tree
Showing 15 changed files with 88 additions and 34 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 38 additions & 14 deletions src/Proof/ProofHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import {ProofNode} from "./ProofNode";
import {redrawProof} from "../SharedToolUtils/DrawUtils";
import {ProofModeMove} from "./ProofModeMove";
import {TreeContext} from "../TreeContext";

/**
Expand Down Expand Up @@ -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);
Expand Down
19 changes: 19 additions & 0 deletions src/Proof/ProofModeMove.ts
Original file line number Diff line number Diff line change
@@ -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,
}
8 changes: 4 additions & 4 deletions src/Proof/ProofNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import {AEGTree} from "../AEG/AEGTree";
import {ProofModeMove} from "./ProofModeMove";
import {TreeContext} from "../TreeContext";

/**
Expand All @@ -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.
Expand All @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion src/ProofTools/DeiterationTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/ProofTools/DoubleCutDeletionTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/ProofTools/DoubleCutInsertionTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -108,7 +109,7 @@ export function doubleCutInsertionMouseUp(event: MouseEvent): void {
const largeCut: CutNode = new CutNode(createEllipse(startingPoint, currentPoint));
const smallCut: CutNode = new CutNode(calcSmallEllipse(<Ellipse>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 =
Expand Down
3 changes: 2 additions & 1 deletion src/ProofTools/ErasureTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/ProofTools/InsertionTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/ProofTools/IterationTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/ProofTools/PasteInProof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/ProofTools/ProofMoveMultiTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/ProofTools/ProofMoveSingleTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/ProofTools/ProofResizeTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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));
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/TreeContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/**
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8aca11f

Please sign in to comment.