예제 #1
0
        public TmxTilesetTile(XElement xTile, TmxList <TmxTerrain> Terrains,
                              string tmxDir = "")
        {
            Id = (int)xTile.Attribute("id");

            TerrainEdges = new List <TmxTerrain>(4);

            int        result;
            TmxTerrain edge;

            var strTerrain = (string)xTile.Attribute("terrain") ?? ",,,";

            foreach (var v in strTerrain.Split(','))
            {
                var success = int.TryParse(v, out result);
                if (success)
                {
                    edge = Terrains[result];
                }
                else
                {
                    edge = null;
                }
                TerrainEdges.Add(edge);
            }

            Probability = (double?)xTile.Attribute("probability") ?? 1.0;
            Image       = new TmxImage(xTile.Element("image"), tmxDir);
            Properties  = new PropertyDict(xTile.Element("properties"));
        }
예제 #2
0
        public TilesetTile(XElement xTile, List <Terrain> Terrains)
        {
            Id = (int)xTile.Attribute("id");

            TerrainEdges = new List <Terrain>(4);

            int     result;
            Terrain edge;

            var strTerrain = (string)xTile.Attribute("terrain") ?? ",,,";

            foreach (var v in strTerrain.Split(','))
            {
                var success = int.TryParse(v, out result);
                if (success)
                {
                    edge = Terrains[result];
                }
                else
                {
                    edge = null;
                }
                TerrainEdges.Add(edge);
            }

            Probability = (double?)xTile.Attribute("probability") ?? 1.0;
            Image       = new Image(xTile.Element("image"));

            ObjectGroups = new List <ObjectGroup>();
            foreach (var e in xTile.Elements("objectgroup"))
            {
                ObjectGroups.Add(new ObjectGroup(e));
            }

            AnimationFrames = new List <TmxAnimationFrame>();
            if (xTile.Element("animation") != null)
            {
                foreach (var e in xTile.Element("animation").Elements("frame"))
                {
                    AnimationFrames.Add(new TmxAnimationFrame(e));
                }
            }

            Properties = new PropertyDict(xTile.Element("properties"));
        }
예제 #3
0
        // TMX tileset element constructor
        public Tileset(XElement xTileset, Func <string, TextReader> resolver)
        {
            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
                var xDocTileset = XDocument.Load(resolver(source));
                var ts          = new Tileset(xDocTileset.Root, resolver);

                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 Image(xTileset.Element("image"));

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

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

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