This commit is contained in:
wsh
2025-04-03 11:56:48 +09:00
parent 86157ee5d8
commit 70c2b7ae57
3 changed files with 13 additions and 5 deletions

View File

@@ -4,8 +4,16 @@ namespace XED.Command
{
public class CommandInvoker
{
public Stack<ICommand> commandStack = new Stack<ICommand>();
public void Invoke<T>(T command) where T : IReversibleCommand
Stack<ICommand> commandStack = new();
Stack<IReversibleCommand> undoableStack = new ();
public void Invoke(IReversibleCommand command)
{
command.Execute();
commandStack.Push(command);
undoableStack.Push(command);
}
public void Invoke(IIrreversibleCommand command)
{
command.Execute();
commandStack.Push(command);
@@ -13,12 +21,12 @@ namespace XED.Command
public void Undo()
{
if (commandStack.Count == 0)
if (undoableStack.Count == 0)
{
return;
}
var command = commandStack.Pop();
(command as IReversibleCommand) .Undo();
var command = undoableStack.Pop();
command.Undo();
}
}
}