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)); }
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); }
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")); }
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)); }
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)); }
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); }