/// <summary>
 /// Generate new map from values stored in this view model.
 /// Note that this will also remove all placed items.
 /// </summary>
 public void GenerateMap()
 {
     GameMap = MapGeneratorFactory.CreateSimpleMapGenerator().GenerateMap(MapWidth, MapHeight, MapSeed);
     PlacedItems.Clear();
     GameMap.MapName   = MapName;
     HumanPlayerPlaced = false;
     OnPropertyChanged("PlacedItems");
 }
        /// <summary>
        /// Load map to this view model.
        /// </summary>
        /// <param name="map">Map to be loaded.</param>
        public void LoadMap(Map map)
        {
            // try to load all map items and if it's ok, place it, otherwise
            // throw exception, this way the old map will still remain in editor
            List <EditorToolboxItem> tmpPlacedItems = new List <EditorToolboxItem>();

            foreach (MapBlock mb in map.Grid)
            {
                if (mb.Creature != null)
                {
                    EditorToolboxItemType type;
                    if (mb.Creature is Monster)
                    {
                        type = EditorToolboxItemType.MONSTER;
                    }
                    else if (mb.Creature is HumanPlayer)
                    {
                        type = EditorToolboxItemType.HUMAN_PLAYER;
                    }
                    else if (mb.Creature is AbstractPlayer)
                    {
                        type = EditorToolboxItemType.AI_PLAYER;
                    }
                    else
                    {
                        throw new Exception($"Neznámý typ bytosti {mb.Creature.GetType()}!");
                    }
                    tmpPlacedItems.Add(new EditorToolboxItem()
                    {
                        UID = mb.Creature.UniqueId, Name = mb.Creature.Name, ItemType = type
                    });
                }

                if (mb.Item != null)
                {
                    EditorToolboxItemType type;
                    if (mb.Item is AbstractWeapon)
                    {
                        type = EditorToolboxItemType.WEAPON;
                    }
                    else if (mb.Item is AbstractArmor)
                    {
                        type = EditorToolboxItemType.ARMOR;
                    }
                    else if (mb.Item is AbstractInventoryItem)
                    {
                        type = EditorToolboxItemType.ITEM;
                    }
                    else
                    {
                        throw new Exception($"Neznámý typ předmětu {mb.Item.GetType()}!");
                    }
                    tmpPlacedItems.Add(new EditorToolboxItem()
                    {
                        UID = mb.Item.UniqueId, Name = mb.Item.Name, ItemType = type
                    });
                }
            }

            PlacedItems.Clear();
            tmpPlacedItems.ForEach(placedItem => PlacedItems.Add(placedItem));
            GameMap              = map;
            MapWidth             = map.Width;
            MapHeight            = map.Height;
            MapName              = map.MapName;
            GeneratePanelEnabled = true;
            DeselectToolboxItem();

            OnPropertyChanged("GeneratePanelEnabled");
            OnPropertyChanged("PlacedItems");
            OnPropertyChanged("MapWidth");
            OnPropertyChanged("Mapheight");
            OnPropertyChanged("MapName");
        }