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);
                            }
                        }
                        if (Tile.IsTileEntity(curTile.Type))
                        {
                            var curTe = _wvm.CurrentWorld.GetTileEntityAtTile(undoTile.Location.X, undoTile.Location.Y);
                            if (curTe != null)
                            {
                                _wvm.CurrentWorld.TileEntities.Remove(curTe);
                            }
                        }

                        _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++;
            _wvm.CurrentWorld.UpgradeLegacyTileEntities();
            OnRedid(this, EventArgs.Empty);
        }
Пример #2
0
        public void Undo()
        {
            if (_currentIndex <= 0)
            {
                return;
            }

            ErrorLogging.TelemetryClient?.TrackEvent(nameof(Undo));


            string     undoFileName = string.Format(UndoFile, _currentIndex - 1); // load previous undo file
            string     redoFileName = string.Format(RedoFile, _currentIndex);     // create redo file at current index
            UndoBuffer redo         = new UndoBuffer(redoFileName);

            Debug.WriteLine($"Opening undo file for undo: {Path.GetFileNameWithoutExtension(undoFileName)}");
            using (var stream = new FileStream(undoFileName, FileMode.Open))
                using (BinaryReader br = new BinaryReader(stream, System.Text.Encoding.UTF8, false))
                {
                    foreach (var undoTile in UndoBuffer.ReadUndoTilesFromStream(br))
                    {
                        Vector2Int32 pixel = undoTile.Location;
                        SaveTileToBuffer(redo, pixel.X, pixel.Y, true);
                        _wvm.CurrentWorld.Tiles[pixel.X, pixel.Y] = (Tile)undoTile.Tile;
                        _wvm.UpdateRenderPixel(pixel);

                        /* Heathtech */
                        BlendRules.ResetUVCache(_wvm, pixel.X, pixel.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);
                    }
                    foreach (var te in World.LoadTileEntityData(br, World.CompatibleVersion))
                    {
                        _wvm.CurrentWorld.TileEntities.Add(te);
                    }
                }

            _currentIndex--; // move index back one, create a new buffer
            CreateBuffer();
            //_wvm.CurrentWorld.UpgradeLegacyTileEntities();
            OnUndid(this, EventArgs.Empty);
        }
Пример #3
0
        public void Redo()
        {
            if (_currentIndex > _maxIndex || _currentIndex < 0)
            {
                return;
            }

            ErrorLogging.TelemetryClient?.TrackEvent(nameof(Redo));


            // close current undo buffer and get a new one with a new name after redo
            string redoFileName = string.Format(RedoFile, _currentIndex + 1); // load redo file at +1

            Debug.WriteLine($"Opening redo file for redo: {Path.GetFileNameWithoutExtension(redoFileName)}");
            using (var stream = new FileStream(redoFileName, 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];
                        SaveTile(undoTile.Location);

                        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);
                            }
                        }
                        if (Tile.IsTileEntity(curTile.Type))
                        {
                            var curTe = _wvm.CurrentWorld.GetTileEntityAtTile(undoTile.Location.X, undoTile.Location.Y);
                            if (curTe != null)
                            {
                                _wvm.CurrentWorld.TileEntities.Remove(curTe);
                            }
                        }

                        _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);
                    }
                    foreach (var te in World.LoadTileEntityData(br, World.CompatibleVersion))
                    {
                        _wvm.CurrentWorld.TileEntities.Add(te);
                    }
                }

            SaveUndo(updateMax: false);

            _wvm.CurrentWorld.UpgradeLegacyTileEntities();
            OnRedid(this, EventArgs.Empty);
        }
Пример #4
0
        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 (Tile.IsChest(curTile.Type))
                        {
                            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 (Tile.IsSign(curTile.Type))
                        {
                            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);
                            }
                        }
                        if (Tile.IsTileEntity(curTile.Type))
                        {
                            var curTe = _wvm.CurrentWorld.GetTileEntityAtTile(undoTile.Location.X, undoTile.Location.Y);
                            if (curTe != null)
                            {
                                _wvm.CurrentWorld.TileEntities.Remove(curTe);
                                var te = curTe.Copy();
                                redo.TileEntities.Add(te);
                            }
                        }
                        _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);
                    }
                }
            _wvm.CurrentWorld.FixTileEntityUV();
            OnUndid(this, EventArgs.Empty);
        }