public void Add(TimeSpan?time, BoardInfo scan) { int? parent; double changeCost; FindParent(scan, out parent, out changeCost); if (changeCost == 0 && parent == Game.Replay.Actions.Count - 1) { return; } if (time != null) { Replay.SetEndTime((TimeSpan)time); } if (parent == null) { Replay.AddAction(new CreateBoardAction(scan.Width, scan.Height)); parent = Replay.Actions.Count - 1; } else { Replay.AddAction(new SelectStateAction((int)parent)); } FillImages(); BoardInfo old = Images[(int)parent]; Debug.Assert(old.Width == scan.Width && old.Height == scan.Height); foreach (GameAction action in StateDelta.Delta(BoardToGameState(old), BoardToGameState(scan))) { Replay.AddAction(action); } }
public static string Export(Replay replay) { Game game = new Game(replay); GameState oldState = null; List <GameAction> actions = new List <GameAction>(); for (int i = 0; i < replay.Actions.Count; i++) { if (replay.Actions[i] is ReplayTimeAction) { actions.Add(replay.Actions[i]); } game.Seek(i); List <GameAction> newActions = StateDelta.Delta(oldState, game.State); actions.AddRange(newActions); if (game.State != null) { oldState = game.State.Clone(); } } List <JObject> jActions = new List <JObject>(); TimeSpan time = TimeSpan.Zero; foreach (var action in actions) { if (action is ReplayTimeAction) { time = ((ReplayTimeAction)action).Time; } else { jActions.Add(SerializeAction(action, time)); } } JObject json = new JObject(new JProperty("changes", new JArray(jActions))); return(json.ToString(Newtonsoft.Json.Formatting.None)); }