// -------------------------------------------------------------------
        // DeleteMapEvents
        // -------------------------------------------------------------------

        public void DeleteMapEvents(Events events, int i, int j)
        {
            int[] portion = new int[] { i, j };
            if (events.CompleteList.ContainsKey(portion))
            {
                Dictionary <int[], SystemEvent> dictionary = events.CompleteList[portion];

                if (dictionary.Count > 0)
                {
                    WANOK.AddPortionsToAddCancel(Model.RealMapName, portion, 1);

                    List <int[]> coordsEvents = new List <int[]>();
                    foreach (int[] coords in dictionary.Keys)
                    {
                        if (coords[0] >= Width || coords[3] >= Height)
                        {
                            coordsEvents.Add(coords);
                        }
                    }
                    for (int k = 0; k < coordsEvents.Count; k++)
                    {
                        dictionary.Remove(coordsEvents[k]);
                    }
                    if (dictionary.Count == 0)
                    {
                        events.CompleteList.Remove(portion);
                    }
                }
            }
        }
        // -------------------------------------------------------------------
        // DeleteMapComplete
        // -------------------------------------------------------------------

        public void DeleteMapComplete(Events events, int i, int j)
        {
            string path = Path.Combine(WANOK.MapsDirectoryPath, RealMapName, "temp", i + "-" + j + ".pmap");

            int[] portion = new int[] { i, j };
            if (File.Exists(path))
            {
                WANOK.AddPortionsToAddCancel(Model.RealMapName, portion, 0);
                File.Delete(path);
            }
            if (events.CompleteList.ContainsKey(portion))
            {
                WANOK.AddPortionsToAddCancel(Model.RealMapName, portion, 1);
                events.CompleteList.Remove(portion);
            }
        }
        // -------------------------------------------------------------------
        // CreateMap
        // -------------------------------------------------------------------

        public void CreateMap()
        {
            if (!Directory.Exists(Path.Combine(WANOK.MapsDirectoryPath, RealMapName)))
            {
                Directory.CreateDirectory(Path.Combine(WANOK.MapsDirectoryPath, RealMapName));
                Directory.CreateDirectory(Path.Combine(WANOK.MapsDirectoryPath, RealMapName, "temp"));
                Directory.CreateDirectory(Path.Combine(WANOK.MapsDirectoryPath, RealMapName, "tempCancelRedo"));
                WANOK.SaveBinaryDatas(Model, Path.Combine(WANOK.MapsDirectoryPath, RealMapName, "infos.map"));
                WANOK.SaveBinaryDatas(new Events(), Path.Combine(WANOK.MapsDirectoryPath, RealMapName, "events.map"));
            }
            else
            {
                WANOK.CreateCancel(Model.RealMapName, true);
                ResizingMap();
                WANOK.AddPortionsToAddCancel(Model.RealMapName, new int[] { 0 }, 2);
                WANOK.SaveBinaryDatas(Model, Path.Combine(WANOK.MapsDirectoryPath, RealMapName, "temp", "infos.map"));
                WANOK.LoadCancel(Model.RealMapName);
            }
        }
        // -------------------------------------------------------------------
        // DeleteMapItems
        // -------------------------------------------------------------------

        public void DeleteMapItems(int i, int j)
        {
            string path = Path.Combine(WANOK.MapsDirectoryPath, RealMapName, "temp", i + "-" + j + ".pmap");

            if (File.Exists(path))
            {
                GameMapPortion gamePortion = WANOK.LoadBinaryDatas <GameMapPortion>(path);
                WANOK.AddPortionsToAddCancel(Model.RealMapName, new int[] { i, j }, 0);


                // Floors
                List <int[]> coordsFloors = new List <int[]>();
                foreach (int[] coords in gamePortion.Floors.Keys)
                {
                    if (coords[0] >= Width || coords[3] >= Height)
                    {
                        coordsFloors.Add(coords);
                    }
                }
                for (int k = 0; k < coordsFloors.Count; k++)
                {
                    gamePortion.Floors.Remove(coordsFloors[k]);
                }

                // Autotiles
                Dictionary <int, List <int[]> > coordsAutotiles = new Dictionary <int, List <int[]> >();
                foreach (KeyValuePair <int, Autotiles> entry in gamePortion.Autotiles)
                {
                    coordsAutotiles[entry.Key] = new List <int[]>();
                    foreach (int[] coords in entry.Value.Tiles.Keys)
                    {
                        if (coords[0] >= Width || coords[3] >= Height)
                        {
                            coordsAutotiles[entry.Key].Add(coords);
                        }
                    }
                }
                foreach (int id in coordsAutotiles.Keys)
                {
                    for (int k = 0; k < coordsAutotiles[id].Count; k++)
                    {
                        gamePortion.Autotiles[id].Tiles.Remove(coordsAutotiles[id][k]);
                    }
                    if (gamePortion.Autotiles[id].IsEmpty())
                    {
                        gamePortion.Autotiles.Remove(id);
                    }
                }

                // Sprites
                Dictionary <int[], List <int[]> > coordsSprites = new Dictionary <int[], List <int[]> >(new IntArrayComparer());
                foreach (KeyValuePair <int[], Sprites> entry in gamePortion.Sprites)
                {
                    coordsSprites[entry.Key] = new List <int[]>();
                    foreach (int[] coords in entry.Value.ListSprites.Keys)
                    {
                        if (coords[0] >= Width || coords[3] >= Height)
                        {
                            coordsSprites[entry.Key].Add(coords);
                        }
                    }
                }
                foreach (int[] texture in coordsSprites.Keys)
                {
                    for (int k = 0; k < coordsSprites[texture].Count; k++)
                    {
                        gamePortion.Sprites[texture].ListSprites.Remove(coordsSprites[texture][k]);
                    }
                    if (gamePortion.Sprites[texture].IsEmpty())
                    {
                        gamePortion.Sprites.Remove(texture);
                    }
                }

                // Mountains
                Dictionary <int, Dictionary <int, List <int[]> > > coordsMountains = new Dictionary <int, Dictionary <int, List <int[]> > >();
                foreach (KeyValuePair <int, Mountains> entry in gamePortion.Mountains)
                {
                    coordsMountains[entry.Key] = new Dictionary <int, List <int[]> >();
                    foreach (KeyValuePair <int, MountainsGroup> entry2 in entry.Value.Groups)
                    {
                        coordsMountains[entry.Key][entry2.Key] = new List <int[]>();
                        foreach (int[] coords in entry2.Value.Tiles.Keys)
                        {
                            if (coords[0] >= Width || coords[3] >= Height)
                            {
                                coordsMountains[entry.Key][entry2.Key].Add(coords);
                            }
                        }
                    }
                }
                foreach (int height in coordsMountains.Keys)
                {
                    foreach (int id in coordsMountains[height].Keys)
                    {
                        for (int k = 0; k < coordsMountains[height][id].Count; k++)
                        {
                            gamePortion.Mountains[height].Groups[id].Tiles.Remove(coordsMountains[height][id][k]);
                        }
                        if (gamePortion.Mountains[height].Groups[id].Tiles.Count == 0)
                        {
                            gamePortion.Mountains[height].Groups.Remove(id);
                        }
                    }
                    if (gamePortion.Mountains[height].IsEmpty())
                    {
                        gamePortion.Mountains.Remove(height);
                    }
                }


                // Saving
                if (gamePortion.IsEmpty())
                {
                    File.Delete(path);
                }
                else
                {
                    WANOK.SaveBinaryDatas(gamePortion, path);
                }
            }
        }