Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TilesetTile" /> class.
        /// </summary>>
        /// <param name="tmxTilesetTile">The TMX parsed tileset tile.</param>
        /// <param name="tileset">The associated tileset</param>
        public TilesetTile(TmxTilesetTile tmxTilesetTile, Tileset tileset)
        {
            this.Tileset = tileset;
            this.ID = tmxTilesetTile.Id;
            this.Probability = tmxTilesetTile.Probability;
            this.Properties = new Dictionary<string, string>(tmxTilesetTile.Properties);

            this.TerrainEdges = new List<TilesetTerrain>();

            if (tmxTilesetTile.BottomRight != null)
            {
                this.BottomRight = this.Tileset.Terrains[tmxTilesetTile.BottomRight.Name];
                this.TerrainEdges.Add(this.BottomRight);
            }

            if (tmxTilesetTile.BottomLeft != null)
            {
                this.BottomLeft = this.Tileset.Terrains[tmxTilesetTile.BottomLeft.Name];
                this.TerrainEdges.Add(this.BottomLeft);
            }

            if (tmxTilesetTile.TopRight != null)
            {
                this.TopRight = this.Tileset.Terrains[tmxTilesetTile.TopRight.Name];
                this.TerrainEdges.Add(this.TopRight);
            }

            if (tmxTilesetTile.TopLeft != null)
            {
                this.TopLeft = this.Tileset.Terrains[tmxTilesetTile.TopLeft.Name];
                this.TerrainEdges.Add(this.TopLeft);
            }
        }
Exemple #2
0
        private void ProcessTileset(XElement xTileset, string tmxDir = "")
        {
            Name       = (string)xTileset.Attribute("name");
            TileWidth  = (int)xTileset.Attribute("tilewidth");
            TileHeight = (int)xTileset.Attribute("tileheight");
            Spacing    = (int?)xTileset.Attribute("spacing") ?? 0;
            Margin     = (int?)xTileset.Attribute("margin") ?? 0;
            Columns    = (int?)xTileset.Attribute("columns");
            TileCount  = (int?)xTileset.Attribute("tilecount");
            TileOffset = new TmxTileOffset(xTileset.Element("tileoffset"));
            Image      = new TmxImage(xTileset.Element("image"), tmxDir);

            Terrains = new TmxList <TmxTerrain>();
            var xTerrainType = xTileset.Element("terraintypes");

            if (xTerrainType != null)
            {
                foreach (var e in xTerrainType.Elements("terrain"))
                {
                    Terrains.Add(new TmxTerrain(e));
                }
            }

            Tiles = new Dictionary <int, TmxTilesetTile>();
            foreach (var xTile in xTileset.Elements("tile"))
            {
                var tile = new TmxTilesetTile(xTile, Terrains, tmxDir);
                Tiles[tile.Id] = tile;
            }

            Properties = new PropertyDict(xTileset.Element("properties"));
        }
Exemple #3
0
        public TmxTilesetTile GetTmxTilesetTileByGID(int GID)
        {
            TmxTilesetTile oFoundTile = null;

            for (int i = 0; i < this.Tilesets.Count; i++)
            {
                if (this.Tilesets[i].FirstGid == GID && GID == 62)
                {
                    System.Diagnostics.Debugger.Break();
                }
                for (int j = 0; j < this.Tilesets[i].Tiles.Count; j++)
                {
                    if (this.Tilesets[i].Tiles[j].Id + this.Tilesets[i].FirstGid == GID)
                    {
                        oFoundTile = this.Tilesets[i].Tiles[j];
                    }
                }
            }

            return(oFoundTile);
        }
Exemple #4
0
        // TMX tileset element constructor
        public TmxTileset(XElement xTileset, string tmxDir = "", Func <string, Stream> readerFunc = null)
        {
            var xFirstGid = xTileset.Attribute("firstgid");
            var source    = (string)xTileset.Attribute("source");

            if (source != null)
            {
                // source is always preceded by firstgid
                FirstGid = (int)xFirstGid;

                // Everything else is in the TSX file
                // Prepend the parent TMX directory if necessary

                XDocument xDocTileset;

                if (readerFunc == null)
                {
                    source      = Path.Combine(tmxDir, source);
                    xDocTileset = ReadXml(source);
                }
                else
                {
                    using (Stream inputStream = readerFunc(source))
                    {
                        xDocTileset = XDocument.Load(inputStream);
                    }
                }

                var ts = new TmxTileset(xDocTileset, TmxDirectory);

                Name       = ts.Name;
                TileWidth  = ts.TileWidth;
                TileHeight = ts.TileHeight;
                Spacing    = ts.Spacing;
                Margin     = ts.Margin;
                Columns    = ts.Columns;
                TileCount  = ts.TileCount;
                TileOffset = ts.TileOffset;
                Image      = ts.Image;
                Terrains   = ts.Terrains;
                Tiles      = ts.Tiles;
                Properties = ts.Properties;
            }
            else
            {
                // firstgid is always in TMX, but not TSX
                if (xFirstGid != null)
                {
                    FirstGid = (int)xFirstGid;
                }

                Name       = (string)xTileset.Attribute("name");
                TileWidth  = (int)xTileset.Attribute("tilewidth");
                TileHeight = (int)xTileset.Attribute("tileheight");
                Spacing    = (int?)xTileset.Attribute("spacing") ?? 0;
                Margin     = (int?)xTileset.Attribute("margin") ?? 0;
                Columns    = (int?)xTileset.Attribute("columns");
                TileCount  = (int?)xTileset.Attribute("tilecount");
                TileOffset = new TmxTileOffset(xTileset.Element("tileoffset"));
                Image      = new TmxImage(xTileset.Element("image"), tmxDir);

                Terrains = new TmxList <TmxTerrain>();
                var xTerrainType = xTileset.Element("terraintypes");
                if (xTerrainType != null)
                {
                    foreach (var e in xTerrainType.Elements("terrain"))
                    {
                        Terrains.Add(new TmxTerrain(e));
                    }
                }

                Tiles = new Dictionary <int, TmxTilesetTile>();
                foreach (var xTile in xTileset.Elements("tile"))
                {
                    var tile = new TmxTilesetTile(xTile, Terrains, tmxDir);
                    Tiles[tile.Id] = tile;
                }

                Properties = new PropertyDict(xTileset.Element("properties"));
            }
        }
Exemple #5
0
        private void LoadXml(XElement xTileset, string tmxDir)
        {
            var xFirstGid = xTileset.Attribute("firstgid");
            var source = (string)xTileset.Attribute("source");

            if (source != null)
            {
                // Prepend the parent TMX directory if necessary
                source = Path.Combine(tmxDir, source);

                // source is always preceded by firstgid
                FirstGid = (int)xFirstGid;

                // Everything else is in the TSX file
                var xDocTileset = ReadXml(source);
                var ts = new TmxTileset(xDocTileset, TmxDirectory);
                Name = ts.Name;
                TileWidth = ts.TileWidth;
                TileHeight = ts.TileHeight;
                Spacing = ts.Spacing;
                Margin = ts.Margin;
                Columns = ts.Columns;
                TileCount = ts.TileCount;
                TileOffset = ts.TileOffset;
                Image = ts.Image;
                Terrains = ts.Terrains;
                Tiles = ts.Tiles;
                Properties = ts.Properties;
            }
            else
            {
                // firstgid is always in TMX, but not TSX
                if (xFirstGid != null)
                    FirstGid = (int)xFirstGid;

                Name = (string)xTileset.Attribute("name");
                TileWidth = (int)xTileset.Attribute("tilewidth");
                TileHeight = (int)xTileset.Attribute("tileheight");
                Spacing = (int?)xTileset.Attribute("spacing") ?? 0;
                Margin = (int?)xTileset.Attribute("margin") ?? 0;
                Columns = (int?)xTileset.Attribute("columns");
                TileCount = (int?)xTileset.Attribute("tilecount");
                TileOffset = new TmxTileOffset(xTileset.Element("tileoffset"));
                Image = new TmxImage(xTileset.Element("image"), tmxDir);

                Terrains = new TmxList<TmxTerrain>();
                var xTerrainType = xTileset.Element("terraintypes");
                if (xTerrainType != null)
                {
                    foreach (var e in xTerrainType.Elements("terrain"))
                        Terrains.Add(new TmxTerrain(e));
                }

                Tiles = new Collection<TmxTilesetTile>();
                foreach (var xTile in xTileset.Elements("tile"))
                {
                    var tile = new TmxTilesetTile(xTile, Terrains, tmxDir);
                    Tiles.Add(tile);
                }

                Properties = new PropertyDict(xTileset.Element("properties"));
            }
        }
Exemple #6
0
        // TMX tileset element constructor
        public TmxTileset(XElement xTileset, string tmxDir = "")
        {
            var xFirstGid = xTileset.Attribute("firstgid");
            var source    = (string)xTileset.Attribute("source");

            if (source != null)
            {
                // Prepend the parent TMX directory if necessary
                source = Path.Combine(tmxDir, source);

                // source is always preceded by firstgid
                FirstGid = (int)xFirstGid;

                // Everything else is in the TSX file
                var xDocTileset = ReadXml(source);
                var ts          = new TmxTileset(xDocTileset, TmxDirectory);

                Name       = ts.Name;
                TileWidth  = ts.TileWidth;
                TileHeight = ts.TileHeight;
                Spacing    = ts.Spacing;
                Margin     = ts.Margin;
                TileOffset = ts.TileOffset;
                Image      = ts.Image;
                Terrains   = ts.Terrains;
                Tiles      = ts.Tiles;
                Properties = ts.Properties;
            }
            else
            {
                // firstgid is always in TMX, but not TSX
                if (xFirstGid != null)
                {
                    FirstGid = (int)xFirstGid;
                }

                Name       = (string)xTileset.Attribute("name");
                TileWidth  = (int)xTileset.Attribute("tilewidth");
                TileHeight = (int)xTileset.Attribute("tileheight");
                Spacing    = (int?)xTileset.Attribute("spacing") ?? 0;
                Margin     = (int?)xTileset.Attribute("margin") ?? 0;

                TileOffset = new TmxTileOffset(xTileset.Element("tileoffset"));
                Image      = new TmxImage(xTileset.Element("image"), tmxDir);

                Terrains = new TmxList <TmxTerrain>();
                var xTerrainType = xTileset.Element("terraintypes");
                if (xTerrainType != null)
                {
                    foreach (var e in xTerrainType.Elements("terrain"))
                    {
                        Terrains.Add(new TmxTerrain(e));
                    }
                }

                Tiles = new List <TmxTilesetTile>();
                foreach (var xTile in xTileset.Elements("tile"))
                {
                    var tile = new TmxTilesetTile(xTile, Terrains, tmxDir);
                    Tiles.Add(tile);
                }

                Properties = new PropertyDict(xTileset.Element("properties"));
            }
        }