Skip to content

Commit 9cdb905

Browse files
author
PatrickSachs
committed
Fixed: Clearing undo/redo when resetting/loading
1 parent 259c990 commit 9cdb905

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/commands/CommandManager.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ export default class CommandManager {
3535
}
3636
}
3737

38+
/**
39+
* Clears the undo/redo stacks.
40+
*/
41+
public clear() {
42+
this._undo = [];
43+
this._redo = [];
44+
}
45+
3846
/**
3947
* Redoes the last undone command and removes it from the redo stack. If no command has
4048
* been undone before no action is performed.

src/commands/DestroyTreeElementCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default class DestroyTreeElementCommand implements ICommand {
4040
if (!owner) {
4141
throw new SlowTreeError("Could not un-delete tree element with owner " + this.owner);
4242
}
43-
// A kinda hacky workaround leveraging the fact that the save data strcuture is the
43+
// A kinda hacky workaround leveraging the fact that the save data structure is the
4444
// same as the one used in game.
4545
// For a larger project a better solution might be warraned, but in this case it does
4646
// the job just fine.

src/components/App.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ export default class STApp extends Vue {
426426
const json = JSON.parse(reader.result as string);
427427
console.log("Uploaded file ...", json);
428428
try {
429+
this.game!.cmd.clear();
429430
scene.loadGame(json);
430431
this.cache();
431432
} catch (error) {
@@ -443,8 +444,9 @@ export default class STApp extends Vue {
443444
* Called when the user clicks on the delete button.
444445
*/
445446
onClickDelete() {
446-
if (this.scene) {
447+
if (this.game && this.scene) {
447448
this.scene.clear();
449+
this.game.cmd.clear();
448450
this.tree = this.scene.tree.treeType.id;
449451
}
450452
localStorage.removeItem("cache");

0 commit comments

Comments
 (0)