Skip to content

Commit

Permalink
Added command: /undostack [clear]
Browse files Browse the repository at this point in the history
  • Loading branch information
TechPizzaDev committed Oct 17, 2023
1 parent fdbbc9c commit 1511fa7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ public void stopRecording() {
this.isRecording = false;
}

public void clear() {
assert !this.isRecording;

this.undoStack.clear();
this.redoStack.clear();
this.undoSelectionStack.clear();
this.redoSelectionStack.clear();
}

public boolean isRecording() {
return this.isRecording;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ public static void registerCommandsWithArgs(
(ctx, name) -> ServerCommands.cmdHelp(ctx, dispatcher, descs, name)));
descs.attach(node.getChild("path").getCommand(), "Gets the description of a command node");
}

// TODO: save/restore for undostacks
dispatcher.register(literal("undostack")
.executes(descs.attach(ServerCommands::cmdUndoStack, "Gets info about the undo stack"))
.then(literal("clear")
.executes(descs.attach(ServerCommands::cmdUndoStackClear, "Clears the undo stack"))));
}

public static int cmdConfig(CommandContext<ServerCommandSource> context) {
Expand Down Expand Up @@ -557,4 +563,35 @@ public static int cmdHelp(
client.overlay.addChatMessage(String.join("\n", lines));
return result;
}

public static int cmdUndoStack(CommandContext<ServerCommandSource> context) {
var source = context.getSource();
var world = source.getWorld();
if (world instanceof ExWorld exWorld) {
var undoStack = exWorld.getUndoStack();

source.getClient().overlay.addChatMessage(String.format(
"Undos left: %d, Redos left: %d",
undoStack.undoStack.size(),
undoStack.redoStack.size()));
return Command.SINGLE_SUCCESS;
}
return 0;
}

public static int cmdUndoStackClear(CommandContext<ServerCommandSource> context) {
var source = context.getSource();
var world = source.getWorld();
if (world instanceof ExWorld exWorld) {
var undoStack = exWorld.getUndoStack();
int undoCount = undoStack.undoStack.size();
int redoCount = undoStack.redoStack.size();
undoStack.clear();

source.getClient().overlay.addChatMessage(String.format(
"Undos cleared: %d, Redos cleared: %d", undoCount, redoCount));
return Command.SINGLE_SUCCESS;
}
return 0;
}
}

0 comments on commit 1511fa7

Please sign in to comment.