public TMXGlueLib.property AddProperty(mapTilesetTile tile, string name, string type,
            bool raiseChangedEvent = true)
        {
            var newProperty = new TMXGlueLib.property();
            LayersController.SetPropertyNameFromNameAndType(name, type, newProperty);

            tile.properties.Add(newProperty);

            bool newTileAdded = false;
            if (AppState.Self.CurrentTileset.Tiles.Contains(tile) == false)
            {
                AppState.Self.CurrentTileset.Tiles.Add(tile);
                newTileAdded = true;
            }
            UpdateXnaDisplayToTileset();

            UpdatePropertiesUI();

            if (raiseChangedEvent && AnyTileMapChange != null)
            {
                TileMapChangeEventArgs args = new TileMapChangeEventArgs();
                args.ChangeType = ChangeType.Tileset;
                AnyTileMapChange(this, args);
            }
            return newProperty;
        }
        private void UpdatePropertiesToInstance(mapTilesetTile tileSet)
        {
            if (tileSet != null)
            {
                ExcludeAllMembers();

                string[] toExclude = new string[]
                {
                    TilesetController.HasCollisionVariableName,
                    TilesetController.EntityToCreatePropertyName,
                    "Name"

                };

                var enumerable = tileSet.properties.Where(item =>
                    {
                        string strippedName = property.GetStrippedName(item.name);

                        bool include = toExclude.Contains(strippedName) == false;

                        return include;

                    });

                this.DisplayProperties(enumerable);

            }
            PropertyGrid.Visible = tileSet != null;

            this.PropertyGrid.Refresh();
        }
        private void UpdatePropertiesToInstance(mapTilesetTile tileSet)
        {
            if (tileSet != null)
            {
                ExcludeAllMembers();

                this.DisplayProperties(tileSet.properties);

            }
            this.PropertyGrid.Refresh();
        }
        private void GetTilesetTileOver(out mapTilesetTile tileSetOver)
        {
            tileSetOver = null;

            float x = mCursor.GetWorldX(mManagers);
            float y = mCursor.GetWorldY(mManagers);

            foreach (var highlight in mTilesWithPropertiesMarkers)
            {
                if (x > highlight.X && x < highlight.X + highlight.Width &&
                    y > highlight.Y && y < highlight.Y + highlight.Height)
                {
                    tileSetOver = highlight.Tag as mapTilesetTile;
                }
            }
        }
        public property GetExistingProperty(string propertyName, mapTilesetTile tile)
        {
            Func<property, bool> predicate = item =>
            {
                if (propertyName != null)
                {
                    return item.StrippedNameLower == propertyName.ToLowerInvariant();
                }
                else
                {
                    return false;
                }
            };

            return tile.properties.FirstOrDefault(predicate);
        }
        private void UpdateInfoLabelToTileset(mapTilesetTile tileSetOver)
        {
            string whatToShow = null;
            if (tileSetOver != null)
            {

                foreach (var property in tileSetOver.properties)
                {

                    whatToShow += "(" + property.name + ", " + property.value + ") ";

                }

                whatToShow += "(ID, " + tileSetOver.id + ")";
            }
            else if(CurrentTileset != null)
            {
                var width = CurrentTileset.Tilewidth;

                int x = (int)(mCursor.GetWorldX(mManagers) / width);
                int y = (int)(mCursor.GetWorldY(mManagers) / width);

                whatToShow = "ID, " + (x + y* CurrentTileset.GetNumberOfTilesWide());
            }
            mInfoLabel.Text = whatToShow;
        }
        private mapTilesetTile TryGetOrMakeNewTilesetTileAtCursor( InputLibrary.Cursor cursor)
        {
            var tileset = AppState.Self.CurrentTileset;

            float worldX = cursor.GetWorldX(mManagers);
            float worldY = cursor.GetWorldY(mManagers);

            int id = tileset.CoordinateToLocalId(
                    (int)worldX,
                    (int)worldY);

            mapTilesetTile newTile = tileset.Tiles.FirstOrDefault(item=>item.id == id);

            if (newTile == null)
            {
                if (worldX > -1 && worldY > -1 &&
                    worldX < AppState.Self.CurrentTileset.Images[0].width &&
                    worldY < AppState.Self.CurrentTileset.Images[0].height)
                {
                    newTile = new mapTilesetTile();
                    newTile.id = id;

                    newTile.properties = new List<property>();
                }
            }

            return newTile;
        }