Example #1
0
        public void Add(IAction action)
        {
            if(action.GetType() == typeof(SelectionAction) && firstSelectionAction == null)
                firstSelectionAction = (SelectionAction)action;
            else if (action.GetType() == typeof(BiomeAction) && firstBiomeAction == null)
                firstBiomeAction = (BiomeAction)action;
            else if (action.GetType() == typeof(PopulateAction) && firstPopulateAction == null)
                firstPopulateAction = (PopulateAction)action;

            //ensure the first action of each type isn't lost when the redo stack is emptied
            if(firstSelectionAction != null && action != firstSelectionAction && redoStack.Contains(firstSelectionAction))
            {
                redoStack.Remove(firstSelectionAction);
                undoStack.AddLast(firstSelectionAction);
            }
            if (firstBiomeAction != null && action != firstBiomeAction && redoStack.Contains(firstBiomeAction))
            {
                redoStack.Remove(firstBiomeAction);
                undoStack.AddLast(firstBiomeAction);
            }
            if (firstPopulateAction != null && action != firstPopulateAction && redoStack.Contains(firstPopulateAction))
            {
                redoStack.Remove(firstPopulateAction);
                undoStack.AddLast(firstPopulateAction);
            }

            action.PreviousAction = GetPreviousAction(undoStack.Last, action.GetType());
            undoStack.AddLast(action);
            foreach (IAction a in redoStack)
                a.Dispose();
            redoStack.Clear();
        }
Example #2
0
        public void FilterOutType(Type type)
        {
            LinkedList <IAction> newUndo = new LinkedList <IAction>();

            foreach (IAction action in undoStack)
            {
                if (type.Equals(action.GetType()))
                {
                    action.Dispose();
                }
                else
                {
                    newUndo.AddLast(action);
                }
            }

            undoStack = newUndo;

            LinkedList <IAction> newRedo = new LinkedList <IAction>();

            foreach (IAction action in redoStack)
            {
                if (type.Equals(action.GetType()))
                {
                    action.Dispose();
                }
                else
                {
                    newRedo.AddLast(action);
                }
            }

            if (firstBiomeAction != null && type == typeof(BiomeAction))
            {
                firstBiomeAction = null;
            }
            if (firstPopulateAction != null && type == typeof(PopulateAction))
            {
                firstPopulateAction = null;
            }
            if (firstSelectionAction != null && type == typeof(SelectionAction))
            {
                firstSelectionAction = null;
            }

            redoStack = newRedo;
        }
Example #3
0
 private void ApplyBiomeState(BiomeAction action, RegionFile region, Bitmap terrainOverlay, Bitmap biomeOverlay, ref String[,] tooltips, UpdateStatus updateStatus)
 {
     foreach (ChunkState state in action.Chunks)
     {
         Chunk c = region.Chunks[state.Coords.X, state.Coords.Z];
         if (c == null || c.Root == null)
         {
             continue;
         }
         ((TAG_Byte_Array)c.Root["Level"]["Biomes"]).Payload = (byte[])state.Biomes.Clone();
     }
     tooltips = new String[biomeOverlay.Width, biomeOverlay.Height];
     if (terrainOverlay != null)
     {
         updateStatus("Generating terrain map");
         RegionUtil.RenderRegionTerrain(region, terrainOverlay);
     }
     updateStatus("Generating biome map");
     RegionUtil.RenderRegionBiomes(region, biomeOverlay, tooltips);
     updateStatus("");
 }
Example #4
0
        public void Add(IAction action)
        {
            if (action.GetType() == typeof(SelectionAction) && firstSelectionAction == null)
            {
                firstSelectionAction = (SelectionAction)action;
            }
            else if (action.GetType() == typeof(BiomeAction) && firstBiomeAction == null)
            {
                firstBiomeAction = (BiomeAction)action;
            }
            else if (action.GetType() == typeof(PopulateAction) && firstPopulateAction == null)
            {
                firstPopulateAction = (PopulateAction)action;
            }

            //ensure the first action of each type isn't lost when the redo stack is emptied
            if (firstSelectionAction != null && action != firstSelectionAction && redoStack.Contains(firstSelectionAction))
            {
                redoStack.Remove(firstSelectionAction);
                undoStack.AddLast(firstSelectionAction);
            }
            if (firstBiomeAction != null && action != firstBiomeAction && redoStack.Contains(firstBiomeAction))
            {
                redoStack.Remove(firstBiomeAction);
                undoStack.AddLast(firstBiomeAction);
            }
            if (firstPopulateAction != null && action != firstPopulateAction && redoStack.Contains(firstPopulateAction))
            {
                redoStack.Remove(firstPopulateAction);
                undoStack.AddLast(firstPopulateAction);
            }

            action.PreviousAction = GetPreviousAction(undoStack.Last, action.GetType());
            undoStack.AddLast(action);
            foreach (IAction a in redoStack)
            {
                a.Dispose();
            }
            redoStack.Clear();
        }
Example #5
0
        public void RecordBiomeState(RegionFile region, String description)
        {
            BiomeAction action = new BiomeAction(description);

            for (int chunkX = 0; chunkX < 32; chunkX++)
            {
                for (int chunkZ = 0; chunkZ < 32; chunkZ++)
                {
                    Chunk c = region.Chunks[chunkX, chunkZ];
                    if (c == null || c.Root == null)
                    {
                        continue;
                    }

                    //first point of accessing chunk's biomes, make sure it exists
                    TAG_Compound level = (TAG_Compound)c.Root["Level"];
                    byte[]       biomes;
                    if (level.Payload.ContainsKey("Biomes"))
                    {
                        biomes = (byte[])level["Biomes"];
                    }
                    else
                    {
                        biomes = new byte[256];
                        for (int i = 0; i < biomes.Length; i++)
                        {
                            biomes[i] = (byte)Biome.Unspecified;
                        }
                        level.Payload.Add("Biomes", new TAG_Byte_Array(biomes, "Biomes"));
                    }

                    action.Chunks.Add(new ChunkState(chunkX, chunkZ, (byte[])biomes.Clone()));
                }
            }
            Add(action);
            OnChange();
        }
Example #6
0
        public void FilterOutType(Type type)
        {
            LinkedList<IAction> newUndo = new LinkedList<IAction>();

            foreach (IAction action in undoStack)
            {
                if (type.Equals(action.GetType()))
                    action.Dispose();
                else
                    newUndo.AddLast(action);
            }

            undoStack = newUndo;

            LinkedList<IAction> newRedo = new LinkedList<IAction>();

            foreach (IAction action in redoStack)
            {
                if (type.Equals(action.GetType()))
                    action.Dispose();
                else
                    newRedo.AddLast(action);
            }

            if (firstBiomeAction != null && type == typeof(BiomeAction))
                firstBiomeAction = null;
            if (firstPopulateAction != null && type == typeof(PopulateAction))
                firstPopulateAction = null;
            if (firstSelectionAction != null && type == typeof(SelectionAction))
                firstSelectionAction = null;

            redoStack = newRedo;
        }
Example #7
0
 private void ApplyBiomeState(BiomeAction action, RegionFile region, Bitmap terrainOverlay, Bitmap biomeOverlay, ref String[,] tooltips, UpdateStatus updateStatus)
 {
     foreach (ChunkState state in action.Chunks)
     {
         Chunk c = region.Chunks[state.Coords.X, state.Coords.Z];
         if (c == null || c.Root == null)
             continue;
         ((TAG_Byte_Array)c.Root["Level"]["Biomes"]).Payload = (byte[])state.Biomes.Clone();
     }
     tooltips = new String[biomeOverlay.Width, biomeOverlay.Height];
     if (terrainOverlay != null)
     {
         updateStatus("Generating terrain map");
         RegionUtil.RenderRegionTerrain(region, terrainOverlay);
     }
     updateStatus("Generating biome map");
     RegionUtil.RenderRegionBiomes(region, biomeOverlay, tooltips);
     updateStatus("");
 }
Example #8
0
 public void SetLastSaveActions()
 {
     lastBiomeAction = (BiomeAction)GetPreviousAction(undoStack.Last, typeof(BiomeAction));
     lastPopulateAction = (PopulateAction)GetPreviousAction(undoStack.Last, typeof(PopulateAction));
 }
Example #9
0
        public void RecordBiomeState(RegionFile region, String description)
        {
            BiomeAction action = new BiomeAction(description);
            for (int chunkX = 0; chunkX < 32; chunkX++)
            {
                for(int chunkZ = 0; chunkZ < 32; chunkZ++)
                {
                    Chunk c = region.Chunks[chunkX, chunkZ];
                    if (c == null || c.Root == null)
                        continue;

                    //first point of accessing chunk's biomes, make sure it exists
                    TAG_Compound level = (TAG_Compound)c.Root["Level"];
                    byte[] biomes;
                    if (level.Payload.ContainsKey("Biomes"))
                        biomes = (byte[])level["Biomes"];
                    else
                    {
                        biomes = new byte[256];
                        for (int i = 0; i < biomes.Length; i++)
                            biomes[i] = (byte)Biome.Unspecified;
                        level.Payload.Add("Biomes", new TAG_Byte_Array(biomes, "Biomes"));
                    }

                    action.Chunks.Add(new ChunkState(chunkX, chunkZ, (byte[])biomes.Clone()));
                }
            }
            Add(action);
            OnChange();
        }
Example #10
0
 public void SetLastSaveActions()
 {
     lastBiomeAction    = (BiomeAction)GetPreviousAction(undoStack.Last, typeof(BiomeAction));
     lastPopulateAction = (PopulateAction)GetPreviousAction(undoStack.Last, typeof(PopulateAction));
 }