예제 #1
0
        private TileChange ApplyChange(TileChange change)
        {
            TileChange undoChange = new TileChange(change.X, change.Y, change.Width, change.Height, this.trackMap);

            this.trackMap.SetTiles(change.X, change.Y, change);
            return(undoChange);
        }
예제 #2
0
        private void Add(IEnumerable <TileChange> changes)
        {
            if (this.undoBuffer.Count == Limit)
            {
                this.undoBuffer.RemoveFirst();
            }

            this.redoBuffer.Clear();

            // Consolidate tile changes into a single one
            TileChange change = new TileChange(changes, this.trackMap);

            this.undoBuffer.AddLast(change);
        }
예제 #3
0
        /// <summary>
        /// Reapplies the last undone change.
        /// </summary>
        /// <returns>The change that has been reapplied.</returns>
        public TileChange Redo()
        {
            if (!this.HasRedo || this.buffer != null)
            {
                // Nothing to redo, or a change is already ongoing
                return(null);
            }

            TileChange redoChange = this.redoBuffer.First.Value;
            TileChange undoChange = this.ApplyChange(redoChange);

            this.redoBuffer.RemoveFirst();
            this.undoBuffer.AddLast(undoChange);

            return(redoChange);
        }
예제 #4
0
 public void Add(TileChange change)
 {
     if (this.buffer == null)
     {
         this.BeginAdd();
         this.Add(change);
         this.EndAdd();
     }
     else
     {
         this.buffer.Push(change);
         if (this.buffer.Count == ChangeLimit)
         {
             // Consolidate tile changes to improve performances
             TileChange tileChange = new TileChange(this.buffer, this.trackMap);
             this.buffer.Clear();
             this.buffer.Push(tileChange);
         }
     }
 }