public void SaveUndo() { ValidateAndRemoveChests(); _maxIndex = _currentIndex; _buffer.Write(string.Format(UndoFile, _currentIndex)); _currentIndex++; Buffer = new UndoBuffer(); }
public void Undo() { if (_currentIndex <= 0) { return; } _currentIndex--; var buffer = UndoBuffer.Read(string.Format(UndoFile, _currentIndex)); var redo = new UndoBuffer(); foreach (var undoTile in buffer.Tiles) { var curTile = (Tile)_wvm.CurrentWorld.Tiles[undoTile.Location.X, undoTile.Location.Y].Clone(); if (curTile.Type == 21) { var curchest = _wvm.CurrentWorld.GetChestAtTile(undoTile.Location.X, undoTile.Location.Y); if (curchest != null) { _wvm.CurrentWorld.Chests.Remove(curchest); var chest = curchest.Copy(); redo.Chests.Add(chest); } } if (curTile.Type == 55 || curTile.Type == 85) { var cursign = _wvm.CurrentWorld.GetSignAtTile(undoTile.Location.X, undoTile.Location.Y); if (cursign != null) { _wvm.CurrentWorld.Signs.Remove(cursign); var sign = cursign.Copy(); redo.Signs.Add(sign); } } redo.Tiles.Add(new UndoTile(undoTile.Location, curTile)); _wvm.CurrentWorld.Tiles[undoTile.Location.X, undoTile.Location.Y] = (Tile)undoTile.Tile.Clone(); _wvm.UpdateRenderPixel(undoTile.Location); /* Heathtech */ BlendRules.ResetUVCache(_wvm, undoTile.Location.X, undoTile.Location.Y, 1, 1); } foreach (var chest in buffer.Chests) { _wvm.CurrentWorld.Chests.Add(chest.Copy()); } foreach (var sign in buffer.Signs) { _wvm.CurrentWorld.Signs.Add(sign.Copy()); } redo.Write(string.Format(RedoFile, _currentIndex)); }
public void Undo() { if (_currentIndex <= 0) return; _currentIndex--; var buffer = UndoBuffer.Read(string.Format(UndoFile, _currentIndex)); var redo = new UndoBuffer(); foreach (var undoTile in buffer.Tiles) { var curTile = (Tile)_wvm.CurrentWorld.Tiles[undoTile.Location.X, undoTile.Location.Y].Clone(); if (curTile.Type == 21) { var curchest = _wvm.CurrentWorld.GetChestAtTile(undoTile.Location.X, undoTile.Location.Y); if (curchest != null) { _wvm.CurrentWorld.Chests.Remove(curchest); var chest = curchest.Copy(); redo.Chests.Add(chest); } } if (curTile.Type == 55 || curTile.Type == 85) { var cursign = _wvm.CurrentWorld.GetSignAtTile(undoTile.Location.X, undoTile.Location.Y); if (cursign != null) { _wvm.CurrentWorld.Signs.Remove(cursign); var sign = cursign.Copy(); redo.Signs.Add(sign); } } redo.Tiles.Add(new UndoTile(undoTile.Location, curTile)); _wvm.CurrentWorld.Tiles[undoTile.Location.X, undoTile.Location.Y] = (Tile)undoTile.Tile.Clone(); _wvm.UpdateRenderPixel(undoTile.Location); /* Heathtech */ BlendRules.ResetUVCache(_wvm, undoTile.Location.X, undoTile.Location.Y, 1, 1); } foreach (var chest in buffer.Chests) { _wvm.CurrentWorld.Chests.Add(chest.Copy()); } foreach (var sign in buffer.Signs) { _wvm.CurrentWorld.Signs.Add(sign.Copy()); } redo.Write(string.Format(RedoFile, _currentIndex)); }