Пример #1
0
        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);
        }
Пример #2
0
        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);
        }