ReadProperties() public static méthode

public static ReadProperties ( XmlNode node ) : List
node System.Xml.XmlNode
Résultat List
        public MapObjectContent(XmlNode node, ContentImporterContext context)
        {
            if (node.Attributes["name"] != null)
            {
                Name = node.Attributes["name"].Value;
            }

            if (node.Attributes["type"] != null)
            {
                Type = node.Attributes["type"].Value;
            }

            // values default to 0 if the attribute is missing from the node
            int x = node.Attributes["x"] != null?int.Parse(node.Attributes["x"].Value, CultureInfo.InvariantCulture) : 0;

            int y = node.Attributes["y"] != null?int.Parse(node.Attributes["y"].Value, CultureInfo.InvariantCulture) : 0;

            int width = node.Attributes["width"] != null?int.Parse(node.Attributes["width"].Value, CultureInfo.InvariantCulture) : 0;

            int height = node.Attributes["height"] != null?int.Parse(node.Attributes["height"].Value, CultureInfo.InvariantCulture) : 0;

            Location = new Rectangle(x, y, width, height);

            XmlNode propertiesNode = node["properties"];

            if (propertiesNode != null)
            {
                Properties = Property.ReadProperties(propertiesNode, context);
            }
        }
Exemple #2
0
        private void Initialize(XmlNode node, ContentImporterContext context)
        {
            this.Name       = node.Attributes["name"].Value;
            this.TileWidth  = int.Parse(node.Attributes["tilewidth"].Value, CultureInfo.InvariantCulture);
            this.TileHeight = int.Parse(node.Attributes["tileheight"].Value, CultureInfo.InvariantCulture);

            if (node.Attributes["spacing"] != null)
            {
                this.Spacing = int.Parse(node.Attributes["spacing"].Value, CultureInfo.InvariantCulture);
            }

            if (node.Attributes["margin"] != null)
            {
                this.Margin = int.Parse(node.Attributes["margin"].Value, CultureInfo.InvariantCulture);
            }

            XmlNode imageNode = node["image"];

            this.Image = imageNode.Attributes["source"].Value;

            // if the image is in any director up from us, just take the filename
            if (this.Image.StartsWith(".."))
            {
                this.Image = Path.GetFileName(this.Image);
            }

            if (imageNode.Attributes["trans"] != null)
            {
                string color = imageNode.Attributes["trans"].Value;
                string r     = color.Substring(0, 2);
                string g     = color.Substring(2, 2);
                string b     = color.Substring(4, 2);
                this.ColorKey = new Color((byte)Convert.ToInt32(r, 16), (byte)Convert.ToInt32(g, 16), (byte)Convert.ToInt32(b, 16));
            }
            foreach (XmlNode tileProperty in node.SelectNodes("tile"))
            {
                int             id         = this.FirstId + int.Parse(tileProperty.Attributes["id"].Value, CultureInfo.InvariantCulture);
                List <Property> properties = new List <Property>();

                XmlNode propertiesNode = tileProperty["properties"];
                if (propertiesNode != null)
                {
                    properties = Property.ReadProperties(propertiesNode, context);
                }

                this.TileProperties.Add(id, properties);
            }
        }
        public LayerContent(XmlNode node, ContentImporterContext context)
        {
            Type   = node.Name;
            Name   = node.Attributes["name"].Value;
            Width  = int.Parse(node.Attributes["width"].Value, CultureInfo.InvariantCulture);
            Height = int.Parse(node.Attributes["height"].Value, CultureInfo.InvariantCulture);

            if (node.Attributes["opacity"] != null)
            {
                Opacity = float.Parse(node.Attributes["opacity"].Value, CultureInfo.InvariantCulture);
            }

            if (node.Attributes["visible"] != null)
            {
                Visible = int.Parse(node.Attributes["visible"].Value, CultureInfo.InvariantCulture) == 1;
            }

            XmlNode propertiesNode = node["properties"];

            if (propertiesNode != null)
            {
                Properties = Property.ReadProperties(propertiesNode, context);
            }
        }
Exemple #4
0
        public MapContent(XmlDocument document, ContentImporterContext context)
        {
            XmlNode mapNode = document["map"];

            Version     = mapNode.Attributes["version"].Value;
            Orientation = (Orientation)Enum.Parse(typeof(Orientation), mapNode.Attributes["orientation"].Value, true);
            Width       = int.Parse(mapNode.Attributes["width"].Value, CultureInfo.InvariantCulture);
            Height      = int.Parse(mapNode.Attributes["height"].Value, CultureInfo.InvariantCulture);
            TileWidth   = int.Parse(mapNode.Attributes["tilewidth"].Value, CultureInfo.InvariantCulture);
            TileHeight  = int.Parse(mapNode.Attributes["tileheight"].Value, CultureInfo.InvariantCulture);

            XmlNode propertiesNode = document.SelectSingleNode("map/properties");

            if (propertiesNode != null)
            {
                Properties = Property.ReadProperties(propertiesNode, context);
            }

            foreach (XmlNode tileSet in document.SelectNodes("map/tileset"))
            {
                if (tileSet.Attributes["source"] != null)
                {
                    TileSets.Add(new ExternalTileSetContent(tileSet, context));
                }
                else
                {
                    TileSets.Add(new TileSetContent(tileSet, context));
                }
            }

            foreach (XmlNode layerNode in document.SelectNodes("map/layer|map/objectgroup"))
            {
                LayerContent layerContent;

                if (layerNode.Name == "layer")
                {
                    layerContent = new TileLayerContent(layerNode, context);
                }
                else if (layerNode.Name == "objectgroup")
                {
                    layerContent = new MapObjectLayerContent(layerNode, context);
                }
                else
                {
                    throw new Exception("Unknown layer name: " + layerNode.Name);
                }

                // Layer names need to be unique for our lookup system, but Tiled
                // doesn't require unique names.
                string layerName      = layerContent.Name;
                int    duplicateCount = 2;

                // if a layer already has the same name...
                if (Layers.Find(l => l.Name == layerName) != null)
                {
                    // figure out a layer name that does work
                    do
                    {
                        layerName = string.Format("{0}{1}", layerContent.Name, duplicateCount);
                        duplicateCount++;
                    } while (Layers.Find(l => l.Name == layerName) != null);

                    // log a warning for the user to see
                    context.Logger.LogWarning(string.Empty, new ContentIdentity(), "Renaming layer \"{1}\" to \"{2}\" to make a unique name.", layerContent.Type, layerContent.Name, layerName);

                    // save that name
                    layerContent.Name = layerName;
                }

                Layers.Add(layerContent);
            }
        }