public static TmxProperties FromXml(XElement elem)
        {
            TmxProperties tmxProps = new TmxProperties();

            var props = from elem1 in elem.Elements("properties")
                        from elem2 in elem1.Elements("property")
                        select new
            {
                Name = TmxHelper.GetAttributeAsString(elem2, "name"),
                Type = TmxHelper.GetAttributeAsEnum(elem2, "type", TmxPropertyType.String),

                // Value may be attribute or inner text
                Value = TmxHelper.GetAttributeAsString(elem2, "value", null) ?? elem2.Value,
            };

            if (props.Count() > 0)
            {
                Logger.WriteVerbose("Parse properites ...");
            }

            foreach (var p in props)
            {
                tmxProps.PropertyMap[p.Name] = new TmxProperty {
                    Name = p.Name, Type = p.Type, Value = p.Value
                };
            }

            return(tmxProps);
        }
示例#2
0
        private void ParseMapXml(XDocument doc)
        {
            Program.WriteLine("Parsing map root ...");
            //Program.WriteVerbose(doc.ToString()); // Some TMX files are far too big (cause out of memory exception) so don't do this
            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);

            ParseAllTilesets(doc);
            ParseAllLayers(doc);
            ParseAllObjectGroups(doc);

            // Once everything is loaded, take a moment to do additional plumbing
            ParseCompleted();
        }
示例#3
0
        private void ParseMap(XDocument doc)
        {
            Program.WriteLine("Parsing map root ...");
            Program.WriteVerbose(doc.ToString());
            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);

            ParseAllTilesets(doc);
            ParseAllLayers(doc);
            ParseAllObjectGroups(doc);
        }
示例#4
0
        public static TmxProperties FromXml(XElement elem)
        {
            TmxProperties tmxProperties = new TmxProperties();
            var           enumerable    = from elem1 in elem.Elements("properties")
                                          from elem2 in elem1.Elements("property")
                                          select new
            {
                Name  = TmxHelper.GetAttributeAsString(elem2, "name"),
                Type  = TmxHelper.GetAttributeAsEnum(elem2, "type", TmxPropertyType.String),
                Value = (TmxHelper.GetAttributeAsString(elem2, "value", null) ?? elem2.Value)
            };

            if (enumerable.Count() > 0)
            {
                Logger.WriteVerbose("Parse properties ...");
            }
            foreach (var item in enumerable)
            {
                tmxProperties.PropertyMap[item.Name] = new TmxProperty
                {
                    Name  = item.Name,
                    Type  = item.Type,
                    Value = item.Value
                };
            }
            return(tmxProperties);
        }
示例#5
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);
        }
示例#6
0
        public static TmxData FromDataXml(XElement xml, TmxLayer parentLayer)
        {
            TmxData tmxData = new TmxData(parentLayer);

            tmxData.Encoding    = TmxHelper.GetAttributeAsEnum(xml, "encoding", DataEncoding.Xml);
            tmxData.Compression = TmxHelper.GetAttributeAsEnum(xml, "compression", DataCompression.None);
            tmxData.Chunks      = TmxChunk.ListFromDataXml(xml, tmxData);
            return(tmxData);
        }
示例#7
0
        public static Dictionary <string, TmxObjectTypeProperty> FromObjectTypeXml(XElement xmlObjectType)
        {
            Dictionary <string, TmxObjectTypeProperty> dictionary = new Dictionary <string, TmxObjectTypeProperty>();

            foreach (XElement item in xmlObjectType.Elements("property"))
            {
                TmxObjectTypeProperty tmxObjectTypeProperty = new TmxObjectTypeProperty();
                tmxObjectTypeProperty.Name    = TmxHelper.GetAttributeAsString(item, "name", "");
                tmxObjectTypeProperty.Type    = TmxHelper.GetAttributeAsEnum(item, "type", TmxPropertyType.String);
                tmxObjectTypeProperty.Default = TmxHelper.GetAttributeAsString(item, "default", "");
                dictionary.Add(tmxObjectTypeProperty.Name, tmxObjectTypeProperty);
            }
            return(dictionary);
        }
示例#8
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);
        }
示例#9
0
        private void ParseMapXml(XDocument doc)
        {
            Logger.WriteLine("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);
            ParseAllLayers(doc);
            ParseAllObjectGroups(doc);

            // Once everything is loaded, take a moment to do additional plumbing
            ParseCompleted();
        }