72 lines
1.0 KiB
C#
72 lines
1.0 KiB
C#
using System.Collections.Generic;
|
|
|
|
namespace BizHawk.MultiClient
|
|
{
|
|
public class HistoryCollection
|
|
{
|
|
public List<List<Watch>> History = new List<List<Watch>>();
|
|
private int curPos; //1-based
|
|
|
|
public HistoryCollection(List<Watch> newState)
|
|
{
|
|
AddState(newState);
|
|
}
|
|
|
|
public bool CanUndo
|
|
{
|
|
get
|
|
{
|
|
return curPos > 1;
|
|
}
|
|
}
|
|
|
|
public bool CanRedo
|
|
{
|
|
get
|
|
{
|
|
return curPos < History.Count;
|
|
}
|
|
}
|
|
|
|
public void AddState(List<Watch> newState)
|
|
{
|
|
if (curPos < History.Count)
|
|
{
|
|
for (int i = curPos + 1; i <= History.Count; i++)
|
|
{
|
|
History.Remove(History[i - 1]);
|
|
}
|
|
}
|
|
|
|
History.Add(newState);
|
|
curPos = History.Count;
|
|
}
|
|
|
|
public List<Watch> Undo()
|
|
{
|
|
if (CanUndo)
|
|
{
|
|
curPos--;
|
|
return History[curPos - 1];
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public List<Watch> Redo()
|
|
{
|
|
if (CanRedo)
|
|
{
|
|
curPos++;
|
|
return History[curPos - 1];
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
}
|