mirror of
https://github.com/RHeavenStudioPlus/HeavenStudioPlus.git
synced 2024-12-01 13:57:32 +00:00
8d275a9e89
* done i think wahoo * this one too lol
70 lines
No EOL
1.7 KiB
C#
70 lines
No EOL
1.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
using HeavenStudio.Editor.Commands;
|
|
|
|
namespace HeavenStudio.Editor
|
|
{
|
|
public class CommandManager : MonoBehaviour
|
|
{
|
|
public static CommandManager Instance { get; private set; }
|
|
|
|
private Stack<ICommand> historyStack = new Stack<ICommand>();
|
|
private Stack<ICommand> redoHistoryStack = new Stack<ICommand>();
|
|
|
|
public int HistoryCount => historyStack.Count;
|
|
|
|
//private int maxItems = 128; Unused value - Marc
|
|
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
}
|
|
|
|
public void AddCommand(ICommand command)
|
|
{
|
|
command.Execute();
|
|
historyStack.Push(command);
|
|
redoHistoryStack.Clear();
|
|
}
|
|
|
|
public void UndoCommand()
|
|
{
|
|
if (!CanUndo() || Conductor.instance.NotStopped()) return;
|
|
|
|
if (historyStack.Count > 0)
|
|
{
|
|
redoHistoryStack.Push(historyStack.Peek());
|
|
historyStack.Pop().Undo();
|
|
}
|
|
}
|
|
|
|
public void RedoCommand()
|
|
{
|
|
if (!CanRedo() || Conductor.instance.NotStopped()) return;
|
|
|
|
if (redoHistoryStack.Count > 0)
|
|
{
|
|
historyStack.Push(redoHistoryStack.Peek());
|
|
redoHistoryStack.Pop().Execute();
|
|
}
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
historyStack.Clear();
|
|
redoHistoryStack.Clear();
|
|
}
|
|
|
|
public bool CanUndo()
|
|
{
|
|
return historyStack.Count > 0;
|
|
}
|
|
public bool CanRedo()
|
|
{
|
|
return redoHistoryStack.Count > 0;
|
|
}
|
|
|
|
}
|
|
} |