public TmxImage(XElement xImage, string tmxDir = "") { if (xImage == null) { return; } var xSource = xImage.Attribute("source"); if (xSource != null) { // Append directory if present Source = Path.Combine(tmxDir, (string)xSource); } else { Format = (string)xImage.Attribute("format"); var xData = xImage.Element("data"); var decodedStream = new TmxBase64Data(xData); Data = decodedStream.Data; } Trans = new TmxColor(xImage.Attribute("trans")); Width = (int?)xImage.Attribute("width"); Height = (int?)xImage.Attribute("height"); }
public TmxObjectGroup(XElement xObjectGroup) { Name = (string)xObjectGroup.Attribute("name") ?? String.Empty; Color = new TmxColor(xObjectGroup.Attribute("color")); Opacity = (double?)xObjectGroup.Attribute("opacity") ?? 1.0; Visible = (bool?)xObjectGroup.Attribute("visible") ?? true; OffsetX = (double?)xObjectGroup.Attribute("offsetx") ?? 0.0; OffsetY = (double?)xObjectGroup.Attribute("offsety") ?? 0.0; var drawOrderDict = new Dictionary <string, DrawOrderType> { { "unknown", DrawOrderType.UnknownOrder }, { "topdown", DrawOrderType.TopDown }, { "index", DrawOrderType.IndexOrder } }; var drawOrderValue = (string)xObjectGroup.Attribute("draworder"); if (drawOrderValue != null) { DrawOrder = drawOrderDict[drawOrderValue]; } Objects = new TmxList <TmxObject>(); foreach (var e in xObjectGroup.Elements("object")) { Objects.Add(new TmxObject(e)); } Properties = new PropertyDict(xObjectGroup.Element("properties")); }
public TmxText(XElement xText) { FontFamily = (string)xText.Attribute("fontfamily") ?? "sans-serif"; PixelSize = (int?)xText.Attribute("pixelsize") ?? 16; Wrap = (bool?)xText.Attribute("wrap") ?? false; Color = new TmxColor(xText.Attribute("color")); Bold = (bool?)xText.Attribute("bold") ?? false; Italic = (bool?)xText.Attribute("italic") ?? false; Underline = (bool?)xText.Attribute("underline") ?? false; Strikeout = (bool?)xText.Attribute("strikeout") ?? false; Kerning = (bool?)xText.Attribute("kerning") ?? true; Alignment = new TmxAlignment(xText.Attribute("halign"), xText.Attribute("valign")); Value = xText.Value; }
public TmxObjectGroup(XElement xObjectGroup) { Name = (string)xObjectGroup.Attribute("name"); Color = new TmxColor(xObjectGroup.Attribute("color")); Opacity = (double?)xObjectGroup.Attribute("opacity") ?? 1.0; Visible = (bool?)xObjectGroup.Attribute("visible") ?? true; Objects = new TmxList <TmxObject>(); foreach (var e in xObjectGroup.Elements("object")) { Objects.Add(new TmxObject(e)); } Properties = new PropertyDict(xObjectGroup.Element("properties")); }
public TmxMap(string filename) { XDocument xDoc = ReadXml(filename); var xMap = xDoc.Element("map"); Version = (string)xMap.Attribute("version"); Orientation = (OrientationType)Enum.Parse( typeof(OrientationType), xMap.Attribute("orientation").Value, true); RenderOrder = (RenderOrderType)Enum.Parse( typeof(RenderOrderType), xMap.Attribute("renderorder").Value.Replace('-', '_'), true); Width = (int)xMap.Attribute("width"); Height = (int)xMap.Attribute("height"); TileWidth = (int)xMap.Attribute("tilewidth"); TileHeight = (int)xMap.Attribute("tileheight"); BackgroundColor = new TmxColor(xMap.Attribute("backgroundcolor")); Tilesets = new TmxList <TmxTileset>(); foreach (var e in xMap.Elements("tileset")) { Tilesets.Add(new TmxTileset(e, TmxDirectory)); } Layers = new TmxList <TmxLayer>(); foreach (var e in xMap.Elements("layer")) { Layers.Add(new TmxLayer(e, Width, Height)); } ObjectGroups = new TmxList <TmxObjectGroup>(); foreach (var e in xMap.Elements("objectgroup")) { ObjectGroups.Add(new TmxObjectGroup(e)); } ImageLayers = new TmxList <TmxImageLayer>(); foreach (var e in xMap.Elements("imagelayer")) { ImageLayers.Add(new TmxImageLayer(e, TmxDirectory)); } Properties = new PropertyDict(xMap.Element("properties")); }
private void Load(XDocument xDoc) { var xMap = xDoc.Element("map"); Version = (string)xMap.Attribute("version"); Width = (int)xMap.Attribute("width"); Height = (int)xMap.Attribute("height"); TileWidth = (int)xMap.Attribute("tilewidth"); TileHeight = (int)xMap.Attribute("tileheight"); HexSideLength = (int?)xMap.Attribute("hexsidelength"); // Map orientation type var orientDict = new Dictionary <string, OrientationType> { { "unknown", OrientationType.Unknown }, { "orthogonal", OrientationType.Orthogonal }, { "isometric", OrientationType.Isometric }, { "staggered", OrientationType.Staggered }, { "hexagonal", OrientationType.Hexagonal }, }; var orientValue = (string)xMap.Attribute("orientation"); if (orientValue != null) { Orientation = orientDict[orientValue]; } // Hexagonal stagger axis var staggerAxisDict = new Dictionary <string, StaggerAxisType> { { "x", StaggerAxisType.X }, { "y", StaggerAxisType.Y }, }; var staggerAxisValue = (string)xMap.Attribute("staggeraxis"); if (staggerAxisValue != null) { StaggerAxis = staggerAxisDict[staggerAxisValue]; } // Hexagonal stagger index var staggerIndexDict = new Dictionary <string, StaggerIndexType> { { "odd", StaggerIndexType.Odd }, { "even", StaggerIndexType.Even }, }; var staggerIndexValue = (string)xMap.Attribute("staggerindex"); if (staggerIndexValue != null) { StaggerIndex = staggerIndexDict[staggerIndexValue]; } // Tile render order var renderDict = new Dictionary <string, RenderOrderType> { { "right-down", RenderOrderType.RightDown }, { "right-up", RenderOrderType.RightUp }, { "left-down", RenderOrderType.LeftDown }, { "left-up", RenderOrderType.LeftUp } }; var renderValue = (string)xMap.Attribute("renderorder"); if (renderValue != null) { RenderOrder = renderDict[renderValue]; } NextObjectID = (int?)xMap.Attribute("nextobjectid"); BackgroundColor = new TmxColor(xMap.Attribute("backgroundcolor")); Properties = new PropertyDict(xMap.Element("properties")); Tilesets = new TmxList <TmxTileset>(); foreach (var e in xMap.Elements("tileset")) { Tilesets.Add(new TmxTileset(e, TmxDirectory)); } Layers = new TmxList <TmxLayer>(); foreach (var e in xMap.Elements("layer")) { Layers.Add(new TmxLayer(e, Width, Height)); } ObjectGroups = new TmxList <TmxObjectGroup>(); foreach (var e in xMap.Elements("objectgroup")) { ObjectGroups.Add(new TmxObjectGroup(e)); } ImageLayers = new TmxList <TmxImageLayer>(); foreach (var e in xMap.Elements("imagelayer")) { ImageLayers.Add(new TmxImageLayer(e, TmxDirectory)); } }
private void Load(XDocument xDoc) { var xMap = xDoc.Element("map"); Version = (string)xMap.Attribute("version"); TiledVersion = (string)xMap.Attribute("tiledversion"); Width = (int)xMap.Attribute("width"); Height = (int)xMap.Attribute("height"); TileWidth = (int)xMap.Attribute("tilewidth"); TileHeight = (int)xMap.Attribute("tileheight"); HexSideLength = (int?)xMap.Attribute("hexsidelength"); // Map orientation type var orientDict = new Dictionary <string, OrientationType> { { "unknown", OrientationType.Unknown }, { "orthogonal", OrientationType.Orthogonal }, { "isometric", OrientationType.Isometric }, { "staggered", OrientationType.Staggered }, { "hexagonal", OrientationType.Hexagonal }, }; var orientValue = (string)xMap.Attribute("orientation"); if (orientValue != null) { Orientation = orientDict[orientValue]; } // Hexagonal stagger axis var staggerAxisDict = new Dictionary <string, StaggerAxisType> { { "x", StaggerAxisType.X }, { "y", StaggerAxisType.Y }, }; var staggerAxisValue = (string)xMap.Attribute("staggeraxis"); if (staggerAxisValue != null) { StaggerAxis = staggerAxisDict[staggerAxisValue]; } // Hexagonal stagger index var staggerIndexDict = new Dictionary <string, StaggerIndexType> { { "odd", StaggerIndexType.Odd }, { "even", StaggerIndexType.Even }, }; var staggerIndexValue = (string)xMap.Attribute("staggerindex"); if (staggerIndexValue != null) { StaggerIndex = staggerIndexDict[staggerIndexValue]; } // Tile render order var renderDict = new Dictionary <string, RenderOrderType> { { "right-down", RenderOrderType.RightDown }, { "right-up", RenderOrderType.RightUp }, { "left-down", RenderOrderType.LeftDown }, { "left-up", RenderOrderType.LeftUp } }; var renderValue = (string)xMap.Attribute("renderorder"); if (renderValue != null) { RenderOrder = renderDict[renderValue]; } NextObjectID = (int?)xMap.Attribute("nextobjectid"); BackgroundColor = new TmxColor(xMap.Attribute("backgroundcolor")); Properties = new PropertyDict(xMap.Element("properties")); Tilesets = new TmxList <TmxTileset>(); foreach (var e in xMap.Elements("tileset")) { Tilesets.Add(new TmxTileset(e, TmxDirectory, CustomLoader)); } Layers = new TmxList <ITmxLayer>(); TileLayers = new TmxList <TmxLayer>(); ObjectGroups = new TmxList <TmxObjectGroup>(); ImageLayers = new TmxList <TmxImageLayer>(); Groups = new TmxList <TmxGroup>(); foreach (var e in xMap.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(e, Width, Height); layer = tileLayer; TileLayers.Add(tileLayer); break; case "objectgroup": var objectgroup = new TmxObjectGroup(e); layer = objectgroup; ObjectGroups.Add(objectgroup); break; case "imagelayer": var imagelayer = new TmxImageLayer(e, TmxDirectory); layer = imagelayer; ImageLayers.Add(imagelayer); break; case "group": var group = new TmxGroup(e, Width, Height, TmxDirectory); layer = group; Groups.Add(group); break; default: throw new InvalidOperationException(); } Layers.Add(layer); } }