protected void FromXmlInternal(XElement xml) { // Get common elements amoung layer nodes from xml this.Name = TmxHelper.GetAttributeAsString(xml, "name", ""); this.Visible = TmxHelper.GetAttributeAsInt(xml, "visible", 1) == 1; this.Opacity = TmxHelper.GetAttributeAsFloat(xml, "opacity", 1); // Get the offset PointF offset = new PointF(0, 0); offset.X = TmxHelper.GetAttributeAsFloat(xml, "offsetx", 0); offset.Y = TmxHelper.GetAttributeAsFloat(xml, "offsety", 0); this.Offset = offset; // Get all the properties this.Properties = TmxProperties.FromXml(xml); // Set the "ignore" setting on this object group this.Ignore = this.Properties.GetPropertyValueAsEnum <IgnoreSettings>("unity:ignore", IgnoreSettings.False); // Explicit sorting properties this.ExplicitSortingLayerName = this.Properties.GetPropertyValueAsString("unity:sortingLayerName", ""); if (this.Properties.PropertyMap.ContainsKey("unity:sortingOrder")) { this.ExplicitSortingOrder = this.Properties.GetPropertyValueAsInt("unity:sortingOrder"); } // Are we using a unity:layer override? this.UnityLayerOverrideName = this.Properties.GetPropertyValueAsString("unity:layer", ""); // Add all our children this.LayerNodes = TmxLayerNode.ListFromXml(xml, this, this.TmxMap); }
private void ParseMapXml(XDocument doc) { Logger.WriteVerbose("Parsing map root ..."); XElement xElement = doc.Element("map"); try { Orientation = TmxHelper.GetAttributeAsEnum <MapOrientation>(xElement, "orientation"); StaggerAxis = TmxHelper.GetAttributeAsEnum(xElement, "staggeraxis", MapStaggerAxis.Y); StaggerIndex = TmxHelper.GetAttributeAsEnum(xElement, "staggerindex", MapStaggerIndex.Odd); HexSideLength = TmxHelper.GetAttributeAsInt(xElement, "hexsidelength", 0); DrawOrderHorizontal = (TmxHelper.GetAttributeAsString(xElement, "renderorder", "right-down").Contains("right") ? 1 : (-1)); DrawOrderVertical = (TmxHelper.GetAttributeAsString(xElement, "renderorder", "right-down").Contains("down") ? 1 : (-1)); Width = TmxHelper.GetAttributeAsInt(xElement, "width"); Height = TmxHelper.GetAttributeAsInt(xElement, "height"); TileWidth = TmxHelper.GetAttributeAsInt(xElement, "tilewidth"); TileHeight = TmxHelper.GetAttributeAsInt(xElement, "tileheight"); BackgroundColor = TmxHelper.GetAttributeAsColor(xElement, "backgroundcolor", new Color32(128, 128, 128, 255)); } catch (Exception inner) { TmxException.FromAttributeException(inner, xElement); } Properties = TmxProperties.FromXml(xElement); IsResource = Properties.GetPropertyValueAsBoolean("unity:resource", false); IsResource = (IsResource || !string.IsNullOrEmpty(Properties.GetPropertyValueAsString("unity:resourcePath", null))); ExplicitSortingLayerName = Properties.GetPropertyValueAsString("unity:sortingLayerName", ""); ParseAllTilesets(doc); ParseAllTemplates(doc); LayerNodes = TmxLayerNode.ListFromXml(xElement, null, this); MapSizeInPixels = CalculateMapSizeInPixels(); TmxDisplayOrderVisitor visitor = new TmxDisplayOrderVisitor(); Visit(visitor); }
private void ParseMapXml(XDocument doc) { Logger.WriteVerbose("Parsing map root ..."); XElement map = doc.Element("map"); try { this.Orientation = TmxHelper.GetAttributeAsEnum <MapOrientation>(map, "orientation"); this.StaggerAxis = TmxHelper.GetAttributeAsEnum(map, "staggeraxis", MapStaggerAxis.Y); this.StaggerIndex = TmxHelper.GetAttributeAsEnum(map, "staggerindex", MapStaggerIndex.Odd); this.HexSideLength = TmxHelper.GetAttributeAsInt(map, "hexsidelength", 0); this.DrawOrderHorizontal = TmxHelper.GetAttributeAsString(map, "renderorder", "right-down").Contains("right") ? 1 : -1; this.DrawOrderVertical = TmxHelper.GetAttributeAsString(map, "renderorder", "right-down").Contains("down") ? 1 : -1; this.Width = TmxHelper.GetAttributeAsInt(map, "width"); this.Height = TmxHelper.GetAttributeAsInt(map, "height"); this.TileWidth = TmxHelper.GetAttributeAsInt(map, "tilewidth"); this.TileHeight = TmxHelper.GetAttributeAsInt(map, "tileheight"); this.BackgroundColor = TmxHelper.GetAttributeAsColor(map, "backgroundcolor", Color.FromArgb(128, 128, 128)); } catch (Exception e) { TmxException.FromAttributeException(e, map); } // Collect our map properties this.Properties = TmxProperties.FromXml(map); // Check properties for us being a resource this.IsResource = this.Properties.GetPropertyValueAsBoolean("unity:resource", false); this.IsResource = this.IsResource || !String.IsNullOrEmpty(this.Properties.GetPropertyValueAsString("unity:resourcePath", null)); ParseAllTilesets(doc); // Get all our child layer nodes this.LayerNodes = TmxLayerNode.ListFromXml(map, null, this); // Calcuate the size of the map. Isometric and hex maps make this more complicated than a simple width and height thing. this.MapSizeInPixels = CalculateMapSizeInPixels(); // Visit each node in the map to assign display order TmxDisplayOrderVisitor visitor = new TmxDisplayOrderVisitor(); this.Visit(visitor); }