コード例 #1
0
        protected virtual TiledElementList <ILayer> ReadLayers(XElement mapElement, int width, int height, string path)
        {
            var layers = new TiledElementList <ILayer>();

            foreach (var element in mapElement.Elements())
            {
                if (element.Name.LocalName.Equals("layer", StringComparison.OrdinalIgnoreCase))
                {
                    Layer layer = ReadLayer(element, width, height);
                    layers.Add(layer);
                }
                else if (element.Name.LocalName.Equals("objectgroup", StringComparison.OrdinalIgnoreCase))
                {
                    ObjectGroup layer = ReadObjectGroup(element);
                    layers.Add(layer);
                }
                else if (element.Name.LocalName.Equals("imagelayer", StringComparison.OrdinalIgnoreCase))
                {
                    ImageLayer layer = ReadImageLayer(element, width, height, path);
                    layers.Add(layer);
                }
            }

            return(options.GetCollectionOrDefault(layers));
        }
コード例 #2
0
        protected virtual Tile ReadTileSetTile(XElement tileElement, TiledElementList <Terrain> terrains, string path)
        {
            var tile = new Tile();

            tile.Id           = (int)tileElement.Attribute("id");
            tile.TerrainEdges = ReadTerrainEdges(tileElement, terrains);

            tile.Probability = (double?)tileElement.Attribute("probability") ?? 1.0;

            var imageElement = tileElement.Element("image");

            if (imageElement != null)
            {
                tile.Image = ReadImage(imageElement, path);
            }

            var objectGroups        = new TiledElementList <ObjectGroup>();
            var objectGroupElements = tileElement.Elements("objectgroup");

            foreach (var objectGroupElement in objectGroupElements)
            {
                objectGroups.Add(ReadObjectGroup(objectGroupElement));
            }

            tile.ObjectGroups = options.GetCollectionOrDefault(objectGroups);

            tile.AnimationFrames = ReadAnimationFrames(tileElement);
            tile.Properties      = ReadProperties(tileElement);

            return(tile);
        }
コード例 #3
0
        public void TiledElementList_Add_Duplicate_Key()
        {
            var list = new TiledElementList <TiledObject>();

            list.Add(new TiledObject {
                Name = "Foo"
            });
            list.Add(new TiledObject {
                Name = "Foo_1"
            });
            list.Add(new TiledObject {
                Name = "Foo"
            });

            Assert.IsTrue(list.Contains("Foo"));
            Assert.IsTrue(list.Contains("Foo_1"));
            Assert.IsTrue(list.Contains("Foo_1__1"));
        }
コード例 #4
0
        protected virtual TiledElementList <Terrain> ReadTileTerrains(XElement tilesetElement)
        {
            TiledElementList <Terrain> terrains = null;
            var terrainTypeElements             = tilesetElement.Element("terraintypes")?.Elements("terrain");

            if (terrainTypeElements != null)
            {
                terrains = new TiledElementList <Terrain>();

                foreach (var e in terrainTypeElements)
                {
                    terrains.Add(ReadTerrain(e));
                }
            }

            return(options.GetCollectionOrDefault(terrains));
        }
コード例 #5
0
        protected virtual TiledElementList <TileSet> ReadTileSets(XElement mapElement, string path)
        {
            TiledElementList <TileSet> tileSets = null;

            var tilesetElements = mapElement.Elements("tileset");

            if (tilesetElements != null)
            {
                tileSets = new TiledElementList <TileSet>();

                foreach (var tilesetElement in tilesetElements)
                {
                    tileSets.Add(ReadTileSet(tilesetElement, path));
                }
            }

            return(options.GetCollectionOrDefault(tileSets));
        }
コード例 #6
0
        protected virtual ObjectGroup ReadObjectGroup(XElement layerElement)
        {
            var layer = ReadLayerBase <ObjectGroup>(layerElement, 0, 0);

            var drawOrderValue = (string)layerElement.Attribute("draworder");

            layer.DrawOrder = ParseEnum <ObjectGroupDrawOrder>(drawOrderValue);


            var objects        = new TiledElementList <TiledObject>();
            var objectElements = layerElement.Elements("object");

            foreach (var objectElement in objectElements)
            {
                objects.Add(ReadObject(objectElement));
            }

            layer.Objects = options.GetCollectionOrDefault(objects);

            return(layer);
        }