public TmxLayer(XMLReader xLayer, int width, int height) { Name = xLayer.Attribute("name") ?? ""; Width = width; Height = height; Opacity = xLayer.AttributeFloatN("opacity") ?? 1.0f; Visible = xLayer.AttributeBoolN("visible") ?? true; OffsetX = xLayer.AttributeFloat("offsetx"); OffsetY = xLayer.AttributeFloat("offsety"); Properties = TmxHelpers.GetPropertyDict(xLayer.Element("properties")); // Not a layer which contains tiles. if (width == 0) { return; } XMLReader xData = xLayer.Element("data"); string encoding = xData.Attribute("encoding"); Tiles = new Collection <TmxLayerTile>(); switch (encoding) { case "csv": { string csvData = xData.CurrentContents(); foreach (string s in csvData.Split(',')) { uint gid = uint.Parse(s.Trim()); Tiles.Add(new TmxLayerTile(gid)); } break; } case null: { foreach (XMLReader e in xData.Elements("tile")) { uint gid = e.AttributeUInt("gid"); Tiles.Add(new TmxLayerTile(gid)); } break; } default: Engine.Log.Warning($"Unknown tmx layer encoding {encoding}", MessageSource.TMX); return; } }
public TmxText(XMLReader xText) { FontFamily = xText.Attribute("fontfamily") ?? "sans-serif"; PixelSize = xText.AttributeIntN("pixelsize") ?? 16; Wrap = xText.AttributeBool("wrap"); Color = TmxHelpers.ParseTmxColor(xText.Attribute("color")); Bold = xText.AttributeBool("bold"); Italic = xText.AttributeBool("italic"); Underline = xText.AttributeBool("underline"); Strikeout = xText.AttributeBool("strikeout"); Kerning = xText.AttributeBoolN("kerning") ?? true; Alignment = new TmxAlignment(xText.Attribute("halign"), xText.Attribute("valign")); Value = xText.CurrentContents(); }
public static Dictionary <string, string> GetPropertyDict(XMLReader containingElement) { var attributes = new Dictionary <string, string>(); if (containingElement == null) { return(attributes); } List <XMLReader> properties = containingElement.Elements("property"); for (var i = 0; i < properties.Count; i++) { XMLReader p = properties[i]; string value = p.Attribute("value") ?? p.CurrentContents(); attributes.Add(p.Attribute("name"), value); } return(attributes); }
public static TmxProperties GetPropertyDict(XMLReader containingElement) { if (containingElement == null) { return(new TmxProperties(null)); } var attributes = new Dictionary <string, string>(); List <XMLReader> properties = containingElement.Elements("property"); for (var i = 0; i < properties.Count; i++) { XMLReader p = properties[i]; string name = p.Attribute("name"); if (name == null) { continue; } string value = p.Attribute("value") ?? p.CurrentContents(); attributes.Add(name, value); } return(new TmxProperties(attributes)); }