(61d00a474) v0.9.7.1

This commit is contained in:
Regalis
2020-03-04 13:04:10 +01:00
parent 3c50efa5c9
commit 3c09ebe02f
5086 changed files with 786063 additions and 295871 deletions
@@ -0,0 +1,62 @@
using System.Collections.Generic;
using System.Linq;
namespace Barotrauma
{
interface IMemorizable<T>
{
Memento<T> Memento { get; }
void StoreSnapshot();
void Undo();
void Redo();
void ClearHistory();
}
public class Memento<T>
{
public T Current { get; private set; }
public int UndoCount => undoStack.Count;
public int RedoCount => redoStack.Count;
private Stack<T> undoStack = new Stack<T>();
private Stack<T> redoStack = new Stack<T>();
public void Store(T newState)
{
redoStack.Clear();
if (Current != null && !Current.Equals(default(T)))
{
undoStack.Push(Current);
}
Current = newState;
}
public T Undo()
{
if (undoStack.Any())
{
redoStack.Push(Current);
Current = undoStack.Pop();
}
return Current;
}
public T Redo()
{
if (redoStack.Any())
{
undoStack.Push(Current);
Current = redoStack.Pop();
}
return Current;
}
public void Clear()
{
undoStack.Clear();
redoStack.Clear();
Current = default(T);
}
}
}