public static Tmx Create(string tmxPath) { var doc = XDocument.Load(Path.Combine("Content", tmxPath)); var map = doc.Element(XName.Get("map")); var result = new Tmx { Width = new XValue(map, "width").AsInt(), Height = new XValue(map, "height").AsInt(), TileWidth = new XValue(map, "tilewidth").AsInt(), TileHeight = new XValue(map, "tileheight").AsInt(), Tilesets = map.Elements(XName.Get("tileset")).Select(x => TmxTileset.Create(x, tmxPath)).ToList(), Layers = map.Elements(XName.Get("layer")).Select((x, i) => TmxLayer.Create(i, x)).ToList(), }; return(result); }
public static TmxLayer Create(int zIndex, XElement layer) { var result = new TmxLayer { ZIndex = zIndex, Width = new XValue(layer, "width").AsInt(), Height = new XValue(layer, "height").AsInt(), Tiles = new List <TmxLayerTile>() }; var layerData = layer.Element(XName.Get("data")).Value; var textureIds = new IntegersInText(layerData).Get().ToList(); for (var i = 0; i < textureIds.Count; i++) { if (textureIds[i] != 0) { result.Tiles.Add(TmxLayerTile.Create(i % result.Width, (int)Math.Floor((double)i / result.Width), textureIds[i])); } } return(result); }