/// <summary>
        /// Handles the <see cref="DialogMap"/> form, checks all the directories and builds the <see cref="TileMap"/> object.
        /// </summary>
        public void NewMap()
        {
            using (var dialog = new DialogMap())
            {
                var result = dialog.ShowDialog();
                if (result != DialogResult.OK) return;

                var name = dialog.MapName;
                var width = dialog.MapWidth;
                var height = dialog.MapHeight;
                var tileWidth = dialog.TileWidth;
                var tileHeight = dialog.TileHeight;

                if (CheckMap(name))
                {
                    MessageBox.Show(@"A map with this name already exists.", @"New Map");
                    return;
                }

                var index = 1;
                while (true)
                {
                    var exit = true;
                    foreach (var tmp in Maps)
                    {
                        if (tmp.ID == index)
                            exit = false;
                    }

                    if (exit)
                        break;

                    index++;
                }

                var map = new TileMap(index, name, width, height, tileWidth, tileHeight);
                map.Layers.Add(new TileLayer("Default", 100, true));

                var editormap = new EditorTileMap(map);

                Maps.Add(editormap);

                Console.WriteLine(@"Map {0} created.", editormap.Name);

                SaveMap(index);

                if (MapAdded != null)
                    MapAdded.Invoke(this, new MapAddedEventArgs(editormap));

                SelectMap(index);
            }
        }
        /// <summary>
        /// Handles the <see cref="DialogMap"/> form and updates the <see cref="TileMap"/> object with the new data.
        /// </summary>
        public void EditMap(int id)
        {
            var map = GetMap(id);
            if (map == null) return;

            using (var dialog = new DialogMap(map.Name, map.Width, map.Height, map.TileWidth, map.TileHeight))
            {
                var result = dialog.ShowDialog();
                if (result != DialogResult.OK) return;

                var name = dialog.MapName;
                var width = dialog.MapWidth;
                var height = dialog.MapHeight;
                var tileWidth = dialog.TileWidth;
                var tileHeight = dialog.TileHeight;

                if (map.Name.ToLower() != name.ToLower())
                {
                    if (CheckMap(name))
                    {
                        MessageBox.Show(@"A map with this name already exists.", @"Edit Map");
                        return;
                    }
                }

                Console.WriteLine(@"Map {0} edited.", map.Name);

                UpdateMap(id, name, width, height, tileWidth, tileHeight);
            }
        }