public static TmxImageLayer LoadTmxImageLayer(this TmxImageLayer layer, TmxMap map, XElement xImageLayer, string tmxDir = "") { layer.Map = map; layer.Name = (string)xImageLayer.Attribute("name"); layer.Width = (int?)xImageLayer.Attribute("width"); layer.Height = (int?)xImageLayer.Attribute("height"); layer.Visible = (bool?)xImageLayer.Attribute("visible") ?? true; layer.Opacity = (float?)xImageLayer.Attribute("opacity") ?? 1.0f; layer.OffsetX = (float?)xImageLayer.Attribute("offsetx") ?? 0.0f; layer.OffsetY = (float?)xImageLayer.Attribute("offsety") ?? 0.0f; var xImage = xImageLayer.Element("image"); if (xImage != null) { //var xSource = xImage.Attribute("source"); //var image = new TmxImage(); //image.Source = Path.Combine(tmxDir, (string)xSource); //image.Texture = (CanvasBitmap)CanvasBitmap.LoadAsync(Graphics, image.Source); //layer.Image = image; layer.Image = new TmxImage().LoadTmxImage(xImage, tmxDir); } layer.Properties = ParsePropertyDict(xImageLayer.Element("properties")); return(layer); }
/// <summary> /// parses all the layers in xEle putting them in the container /// </summary> public static void ParseLayers(object container, XElement xEle, TmxMap map, int width, int height, string tmxDirectory) { foreach (var e in xEle.Elements().Where(x => x.Name == "layer" || x.Name == "objectgroup" || x.Name == "imagelayer" || x.Name == "group")) { ITmxLayer layer; switch (e.Name.LocalName) { case "layer": var tileLayer = new TmxLayer().LoadTmxLayer(map, e, width, height); layer = tileLayer; if (container is TmxMap m) { m.TileLayers.Add(tileLayer); } else if (container is TmxGroup g) { g.TileLayers.Add(tileLayer); } break; case "objectgroup": var objectgroup = new TmxObjectGroup().LoadTmxObjectGroup(map, e); layer = objectgroup; if (container is TmxMap mm) { mm.ObjectGroups.Add(objectgroup); } else if (container is TmxGroup gg) { gg.ObjectGroups.Add(objectgroup); } break; case "imagelayer": var imagelayer = new TmxImageLayer().LoadTmxImageLayer(map, e, tmxDirectory); layer = imagelayer; if (container is TmxMap mmm) { mmm.ImageLayers.Add(imagelayer); } else if (container is TmxGroup ggg) { ggg.ImageLayers.Add(imagelayer); } break; case "group": var newGroup = new TmxGroup().LoadTmxGroup(map, e, width, height, tmxDirectory); layer = newGroup; if (container is TmxMap mmmm) { mmmm.Groups.Add(newGroup); } else if (container is TmxGroup gggg) { gggg.Groups.Add(newGroup); } break; default: throw new InvalidOperationException(); } if (container is TmxMap mmmmm) { mmmmm.Layers.Add(layer); } else if (container is TmxGroup g) { g.Layers.Add(layer); } } }