using System.Collections.Generic; using System.Linq; namespace BizHawk.MultiClient { public class HistoryCollection { public List> History { get; private set; } private int curPos; //1-based public HistoryCollection() { History = new List>(); } public HistoryCollection(List newState) { History = new List>(); AddState(newState); } public void Clear() { History = new List>(); } public bool CanUndo { get { return curPos > 1; } } public bool CanRedo { get { return curPos < History.Count; } } public bool HasHistory { get { return History.Any(); } } public void AddState(List 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 Undo() { if (CanUndo) { curPos--; return History[curPos - 1]; } else { return null; } } public List Redo() { if (CanRedo) { curPos++; return History[curPos - 1]; } else { return null; } } } }