public void Redo() { if (_currentIndex > _maxIndex || _currentIndex < 0) { return; } using (var stream = new FileStream(string.Format(RedoFile, _currentIndex), FileMode.Open)) using (BinaryReader br = new BinaryReader(stream)) { foreach (var undoTile in UndoBuffer.ReadUndoTilesFromStream(br)) { var curTile = (Tile)_wvm.CurrentWorld.Tiles[undoTile.Location.X, undoTile.Location.Y]; if (Tile.IsChest(curTile.Type)) { var curchest = _wvm.CurrentWorld.GetChestAtTile(undoTile.Location.X, undoTile.Location.Y); if (curchest != null) { _wvm.CurrentWorld.Chests.Remove(curchest); } } if (Tile.IsSign(curTile.Type)) { var cursign = _wvm.CurrentWorld.GetSignAtTile(undoTile.Location.X, undoTile.Location.Y); if (cursign != null) { _wvm.CurrentWorld.Signs.Remove(cursign); } } _wvm.CurrentWorld.Tiles[undoTile.Location.X, undoTile.Location.Y] = (Tile)undoTile.Tile; _wvm.UpdateRenderPixel(undoTile.Location); /* Heathtech */ BlendRules.ResetUVCache(_wvm, undoTile.Location.X, undoTile.Location.Y, 1, 1); } foreach (var chest in World.LoadChestData(br)) { _wvm.CurrentWorld.Chests.Add(chest); } foreach (var sign in World.LoadSignData(br)) { _wvm.CurrentWorld.Signs.Add(sign); } } _currentIndex++; OnRedid(this, EventArgs.Empty); }
public void Undo() { if (_currentIndex <= 0) { return; } _currentIndex--; List <Chest> Chests = new List <Chest>(); List <Sign> Signs = new List <Sign>(); using (var ws = new FileStream(string.Format(RedoFile, _currentIndex), FileMode.Create)) using (var bw = new BinaryWriter(ws)) using (var stream = new FileStream(string.Format(UndoFile, _currentIndex), FileMode.Open)) using (BinaryReader br = new BinaryReader(stream)) { int count = br.ReadInt32(); br.BaseStream.Position -= 4; bw.Write(count); foreach (var undoTile in UndoBuffer.ReadUndoTilesFromStream(br)) { var curTile = (Tile)_wvm.CurrentWorld.Tiles[undoTile.Location.X, undoTile.Location.Y]; 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(); 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(); Signs.Add(sign); } } bw.Write(undoTile.Location.X); bw.Write(undoTile.Location.Y); World.WriteTileDataToStream(curTile, bw); _wvm.CurrentWorld.Tiles[undoTile.Location.X, undoTile.Location.Y] = (Tile)undoTile.Tile; _wvm.UpdateRenderPixel(undoTile.Location); /* Heathtech */ BlendRules.ResetUVCache(_wvm, undoTile.Location.X, undoTile.Location.Y, 1, 1); } World.WriteChestDataToStream(Chests, bw); World.WriteSignDataToStream(Signs, bw); foreach (var chest in World.ReadChestDataFromStream(br, World.CompatibleVersion)) { _wvm.CurrentWorld.Chests.Add(chest); } foreach (var sign in World.ReadSignDataFromStream(br)) { _wvm.CurrentWorld.Signs.Add(sign); } } OnUndid(this, EventArgs.Empty); }
public void Undo() { if (_currentIndex <= 0) { return; } _currentIndex--; UndoBuffer redo = new UndoBuffer(string.Format(RedoFile, _currentIndex)); using (var stream = new FileStream(string.Format(UndoFile, _currentIndex), FileMode.Open)) using (BinaryReader br = new BinaryReader(stream)) { foreach (var undoTile in UndoBuffer.ReadUndoTilesFromStream(br)) { var curTile = (Tile)_wvm.CurrentWorld.Tiles[undoTile.Location.X, undoTile.Location.Y]; redo.Add(undoTile.Location, curTile); 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); } } _wvm.CurrentWorld.Tiles[undoTile.Location.X, undoTile.Location.Y] = (Tile)undoTile.Tile; _wvm.UpdateRenderPixel(undoTile.Location); /* Heathtech */ BlendRules.ResetUVCache(_wvm, undoTile.Location.X, undoTile.Location.Y, 1, 1); } redo.Close(); redo.Dispose(); redo = null; foreach (var chest in World.LoadChestData(br)) { _wvm.CurrentWorld.Chests.Add(chest); } foreach (var sign in World.LoadSignData(br)) { _wvm.CurrentWorld.Signs.Add(sign); } } OnUndid(this, EventArgs.Empty); }