Skip to content

Commit 45d7aa8

Browse files
author
PatrickSachs
committed
Potentially fixed undo/redo error
1 parent 1b4393a commit 45d7aa8

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/commands/AddTreeElementCommand.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,24 @@ import TreeElement from "./../gameobjects/IBranchContainer";
22
import { ITreeElementDetails } from "@/gameobjects/IBranchContainer";
33
import TreeGameObject from "@/gameobjects/TreeGameObject";
44
import ICommand from "@/commands/ICommand";
5+
import SlowTreeError from "@/errors/SlowTreeError";
56

67
export default class AddTreeElementCommand implements ICommand {
7-
private element: TreeElement | null = null;
8-
98
constructor(private tree: TreeGameObject, private parent: string, private details: ITreeElementDetails) {
109
}
1110

1211
do(): void {
1312
const owner = this.tree.find(this.parent);
1413
if (owner) {
15-
this.element = owner.addTreeElement(this.details);
14+
owner.addTreeElement(this.details).id;
1615
}
1716
}
1817

1918
undo(): void {
20-
if (this.element) {
21-
this.element.destroy();
19+
const element = this.tree.find(this.details.id);
20+
if (!element) {
21+
throw new SlowTreeError("Could not find element with ID " + this.details.id);
2222
}
23+
element.destroy();
2324
}
2425
}

0 commit comments

Comments
 (0)