Skip to content

Commit

Permalink
Refactoring and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanR712 committed Mar 18, 2024
1 parent e4252a5 commit e2807f7
Show file tree
Hide file tree
Showing 34 changed files with 206 additions and 125 deletions.
16 changes: 8 additions & 8 deletions src/AEG-IO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {AtomNode} from "./AEG/AtomNode";
import {CutNode} from "./AEG/CutNode";
import {Ellipse} from "./AEG/Ellipse";
import {Point} from "./AEG/Point";
import {ProofModeMove} from "./Proof/ProofModeMove";
import {ProofNode} from "./Proof/ProofNode";
import {ProofModeMove} from "./ProofHistory/ProofModeMove";
import {ProofModeNode} from "./ProofHistory/ProofModeNode";

/**
* Describes The Sheet of Assertion in JSON files.
Expand Down Expand Up @@ -53,14 +53,14 @@ interface proofNodeObj {
* Creates and saves a file to the incoming FileSystemFileHandle
* and containing the incoming save data.
*
* The save data will either be an AEGTree from Draw Mode or a series of ProofNodes from Proof Mode.
* The save data will either be an AEGTree from Draw Mode or a series of ProofModeNodes from Proof Mode.
*
* @param handle Incoming FileSystemFileHandle.
* @param aegData Incoming save data.
*/
export async function saveFile(
handle: FileSystemFileHandle,
saveData: AEGTree | ProofNode[]
saveData: AEGTree | ProofModeNode[]
): Promise<void> {
const data: string = JSON.stringify(saveData, null, "\t");

Expand All @@ -75,22 +75,22 @@ export async function saveFile(
*
* @param mode Incoming mode string.
* @param fileData Incoming data read from a file.
* @returns AEGTree representation of fileData if in Draw Mode. Otherwise, a series of ProofNodes.
* @returns AEGTree representation of fileData if in Draw Mode. Otherwise, a series of ProofModeNodes.
*/
export function loadFile(mode: "Draw" | "Proof", fileData: string): AEGTree | ProofNode[] {
export function loadFile(mode: "Draw" | "Proof", fileData: string): AEGTree | ProofModeNode[] {
const data = JSON.parse(fileData);

if (mode === "Draw") {
const childData: (atomObj | cutObj)[] = (data as sheetObj).internalSheet.internalChildren;
return toTree(childData);
} else {
//Construct the tree at every step of the proof and store them in an array
const arr: ProofNode[] = [];
const arr: ProofModeNode[] = [];

let node: proofNodeObj;
for (node of data) {
const childData: (atomObj | cutObj)[] = node.tree.internalSheet.internalChildren;
arr.push(new ProofNode(toTree(childData), node.appliedRule));
arr.push(new ProofModeNode(toTree(childData), node.appliedRule));
}

return arr;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ export class DrawModeNode {
public tree: AEGTree;
public appliedMove: DrawModeMove;

/**
* Sets tree to the incoming AEGTree and appliedMove to the incoming DrawModeMove.
*
* @param tree Incoming AEGTree. Defaults to a default AEGTree construction.
* @param appliedMove Incoming DrawModeMove. Defaults to CLEAR.
*/
public constructor(tree?: AEGTree, appliedMove?: DrawModeMove) {
this.tree = new AEGTree(tree?.sheet) ?? new AEGTree();
this.appliedMove = appliedMove ?? DrawModeMove.CLEAR;
Expand Down
31 changes: 27 additions & 4 deletions src/History/DrawModeStack.ts → src/DrawHistory/DrawModeStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,28 @@ import {DrawModeNode} from "./DrawModeNode";
export class DrawModeStack {
public history: DrawModeNode[];

/**
* Initializes the stack.
*/
public constructor() {
this.history = [];
}

/**
* Adds the incoming DrawModeNode to the stack.
*
* @param incomingMove Incoming DrawModeNode.
*/
public push(incomingMove: DrawModeNode): void {
this.history.push(incomingMove);
}

/**
* Removes and returns the DrawModeNode at the top of this stack, if one exists.
*
* @returns null if the stack is empty, or,
* if the stack is not empty, the DrawModeNode at its top.
*/
public pop(): DrawModeNode | null {
if (this.history.length === 0) {
return null;
Expand All @@ -28,13 +42,22 @@ export class DrawModeStack {
return poppedNode;
}

public clear(): void {
this.history = [];
}

/**
* Returns the DrawModeNode at the top of the stack.
*
* @returns DrawModeNode at the top of the stack, or,
* if the stack is empty, an empty DrawModeNode.
*/
public peek(): DrawModeNode {
return this.history.length !== 0
? this.history[this.history.length - 1]
: new DrawModeNode();
}

/**
* Removes all entries in the stack.
*/
public clear(): void {
this.history = [];
}
}
2 changes: 1 addition & 1 deletion src/DrawTools/AtomTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import {AtomNode} from "../AEG/AtomNode";
import {changeCursorStyle} from "../SharedToolUtils/DrawUtils";
import {drawAtom} from "../SharedToolUtils/DrawUtils";
import {DrawModeMove} from "../History/DrawModeMove";
import {DrawModeMove} from "../DrawHistory/DrawModeMove";
import {illegalColor, legalColor} from "../Themes";
import {offset} from "../SharedToolUtils/DragTool";
import {Point} from "../AEG/Point";
Expand Down
2 changes: 1 addition & 1 deletion src/DrawTools/CopyFromDraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {AtomNode} from "../AEG/AtomNode";
import {changeCursorStyle} from "../SharedToolUtils/DrawUtils";
import {cleanCanvas, highlightNode, redrawTree} from "../SharedToolUtils/DrawUtils";
import {CutNode} from "../AEG/CutNode";
import {DrawModeMove} from "../History/DrawModeMove";
import {DrawModeMove} from "../DrawHistory/DrawModeMove";
import {legalColor} from "../Themes";
import {offset} from "../SharedToolUtils/DragTool";
import {Point} from "../AEG/Point";
Expand Down
2 changes: 1 addition & 1 deletion src/DrawTools/CopyMultiTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {AtomNode} from "../AEG/AtomNode";
import {changeCursorStyle, determineAndChangeCursorStyle} from "../SharedToolUtils/DrawUtils";
import {CutNode} from "../AEG/CutNode";
import {drawAtom, redrawTree} from "../SharedToolUtils/DrawUtils";
import {DrawModeMove} from "../History/DrawModeMove";
import {DrawModeMove} from "../DrawHistory/DrawModeMove";
import {illegalColor, legalColor} from "../Themes";
import {offset} from "../SharedToolUtils/DragTool";
import {Point} from "../AEG/Point";
Expand Down
2 changes: 1 addition & 1 deletion src/DrawTools/CopySingleTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {AtomNode} from "../AEG/AtomNode";
import {changeCursorStyle, determineAndChangeCursorStyle} from "../SharedToolUtils/DrawUtils";
import {CutNode} from "../AEG/CutNode";
import {drawAtom, drawCut, redrawTree} from "../SharedToolUtils/DrawUtils";
import {DrawModeMove} from "../History/DrawModeMove";
import {DrawModeMove} from "../DrawHistory/DrawModeMove";
import {illegalColor, legalColor} from "../Themes";
import {offset} from "../SharedToolUtils/DragTool";
import {Point} from "../AEG/Point";
Expand Down
2 changes: 1 addition & 1 deletion src/DrawTools/CutTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {changeCursorStyle, determineAndChangeCursorStyle} from "../SharedToolUti
import {createEllipse, ellipseLargeEnough} from "../SharedToolUtils/EditModeUtils";
import {CutNode} from "../AEG/CutNode";
import {drawCut, drawGuidelines, redrawTree} from "../SharedToolUtils/DrawUtils";
import {DrawModeMove} from "../History/DrawModeMove";
import {DrawModeMove} from "../DrawHistory/DrawModeMove";
import {Ellipse} from "../AEG/Ellipse";
import {illegalColor, legalColor} from "../Themes";
import {offset} from "../SharedToolUtils/DragTool";
Expand Down
2 changes: 1 addition & 1 deletion src/DrawTools/DeleteMultiTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import {AtomNode} from "../AEG/AtomNode";
import {CutNode} from "../AEG/CutNode";
import {DrawModeMove} from "../History/DrawModeMove";
import {DrawModeMove} from "../DrawHistory/DrawModeMove";
import {highlightNode, redrawTree} from "../SharedToolUtils/DrawUtils";
import {illegalColor} from "../Themes";
import {offset} from "../SharedToolUtils/DragTool";
Expand Down
2 changes: 1 addition & 1 deletion src/DrawTools/DeleteSingleTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import {AtomNode} from "../AEG/AtomNode";
import {CutNode} from "../AEG/CutNode";
import {drawAtom, drawCut, redrawTree} from "../SharedToolUtils/DrawUtils";
import {DrawModeMove} from "../History/DrawModeMove";
import {DrawModeMove} from "../DrawHistory/DrawModeMove";
import {illegalColor} from "../Themes";
import {offset} from "../SharedToolUtils/DragTool";
import {Point} from "../AEG/Point";
Expand Down
2 changes: 1 addition & 1 deletion src/DrawTools/DrawClearTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import {AEGTree} from "../AEG/AEGTree";
import {cleanCanvas, highlightNode, redrawTree} from "../SharedToolUtils/DrawUtils";
import {DrawModeMove} from "../History/DrawModeMove";
import {DrawModeMove} from "../DrawHistory/DrawModeMove";
import {illegalColor} from "../Themes";
import {TreeContext} from "../TreeContext";

Expand Down
2 changes: 1 addition & 1 deletion src/DrawTools/DrawMoveMultiTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {AtomNode} from "../AEG/AtomNode";
import {changeCursorStyle, determineAndChangeCursorStyle} from "../SharedToolUtils/DrawUtils";
import {CutNode} from "../AEG/CutNode";
import {drawAtom, highlightNode, redrawTree} from "../SharedToolUtils/DrawUtils";
import {DrawModeMove} from "../History/DrawModeMove";
import {DrawModeMove} from "../DrawHistory/DrawModeMove";
import {illegalColor, legalColor} from "../Themes";
import {offset} from "../SharedToolUtils/DragTool";
import {Point} from "../AEG/Point";
Expand Down
2 changes: 1 addition & 1 deletion src/DrawTools/DrawMoveSingleTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {AtomNode} from "../AEG/AtomNode";
import {changeCursorStyle, determineAndChangeCursorStyle} from "../SharedToolUtils/DrawUtils";
import {CutNode} from "../AEG/CutNode";
import {drawAtom, drawCut, redrawTree} from "../SharedToolUtils/DrawUtils";
import {DrawModeMove} from "../History/DrawModeMove";
import {DrawModeMove} from "../DrawHistory/DrawModeMove";
import {illegalColor, legalColor} from "../Themes";
import {offset} from "../SharedToolUtils/DragTool";
import {Point} from "../AEG/Point";
Expand Down
2 changes: 1 addition & 1 deletion src/DrawTools/DrawResizeTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {AtomNode} from "../AEG/AtomNode";
import {changeCursorStyle, determineAndChangeCursorStyle} from "../SharedToolUtils/DrawUtils";
import {CutNode} from "../AEG/CutNode";
import {determineDirection, drawCut, redrawTree} from "../SharedToolUtils/DrawUtils";
import {DrawModeMove} from "../History/DrawModeMove";
import {DrawModeMove} from "../DrawHistory/DrawModeMove";
import {ellipseLargeEnough, resizeCut} from "../SharedToolUtils/EditModeUtils";
import {illegalColor, legalColor} from "../Themes";
import {offset} from "../SharedToolUtils/DragTool";
Expand Down
38 changes: 0 additions & 38 deletions src/Proof/ProofModeStack.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

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

Expand All @@ -17,7 +17,7 @@ import {TreeContext} from "../TreeContext";
* @param newStep Incoming ProofNode.
* @param step Index of newStep in the history.
*/
export function appendStep(newStep: ProofNode, step?: number): void {
export function appendStep(newStep: ProofModeNode, step?: number): void {
const newDiv = document.createElement("div");
newDiv.className = "row";
const stepNumber = step ? step : TreeContext.proof.length;
Expand Down Expand Up @@ -86,7 +86,7 @@ export function appendStep(newStep: ProofNode, step?: number): void {
*
* @param selectedStep Incoming ProofNode.
*/
export function stepBack(selectedStep: ProofNode): void {
export function stepBack(selectedStep: ProofModeNode): void {
TreeContext.currentProofStep = selectedStep;
redrawProof();
}
Expand All @@ -102,6 +102,9 @@ export function deleteButtons(stopIndex: number): void {
}
}

/**
* Removes the most recent move's button from the proof bar.
*/
export function deleteMostRecentButton(): void {
document.getElementById("Row: " + TreeContext.proof.length)?.remove();
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {TreeContext} from "../TreeContext";
/**
* Defines a single step in a proof.
*/
export class ProofNode {
export class ProofModeNode {
/**
* The AEGTree at this proof step.
*/
Expand Down
61 changes: 61 additions & 0 deletions src/ProofHistory/ProofModeStack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* @file Contains the ProofModeStack class, which models an undo/redo stack in Proof Mode.
*
* @author Ryan R
*/

import {ProofModeNode} from "./ProofModeNode";

export class ProofModeStack {
public history: ProofModeNode[];

/**
* Initializes the stack.
*/
public constructor() {
this.history = [];
}

/**
* Adds the incoming ProofModeNode to the stack.
*
* @param incomingMove Incoming ProofModeNode.
*/
public push(incomingMove: ProofModeNode): void {
this.history.push(incomingMove);
}

/**
* Removes and returns the ProofModeNode at the top of this stack, if one exists.
*
* @returns null if the stack is empty, or, if the stack is not empty, the ProofModeNode at its top.
*/
public pop(): ProofModeNode | null {
if (this.history.length === 0) {
return null;
}

const poppedNode: ProofModeNode = this.history[this.history.length - 1];

this.history.splice(this.history.length - 1, 1);
return poppedNode;
}

/**
* Returns the ProofModeNode at the top of the stack.
*
* @returns ProofModeNode at the top of the stack, or, if the stack is empty, an empty ProofModeNode.
*/
public peek(): ProofModeNode {
return this.history.length !== 0
? this.history[this.history.length - 1]
: new ProofModeNode();
}

/**
* Removes all entries in the stack.
*/
public clear(): void {
this.history = [];
}
}
6 changes: 3 additions & 3 deletions src/ProofTools/DeiterationTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ 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 {ProofModeMove} from "../ProofHistory/ProofModeMove";
import {ProofModeNode} from "../ProofHistory/ProofModeNode";
import {reInsertNode} from "../SharedToolUtils/EditModeUtils";
import {TreeContext} from "../TreeContext";

Expand Down Expand Up @@ -82,7 +82,7 @@ export function deiterationMouseUp(event: MouseEvent): void {
if (currentParent instanceof CutNode) {
currentParent.remove(currentPoint);
}
TreeContext.pushToProof(new ProofNode(currentProofTree, ProofModeMove.DEITERATION));
TreeContext.pushToProof(new ProofModeNode(currentProofTree, ProofModeMove.DEITERATION));
}
}
legalNode = false;
Expand Down
Loading

0 comments on commit e2807f7

Please sign in to comment.