示例#1
0
        public TileLayerContent(XmlNode node, LevelContent level, TileLayerSettingsContent settings)
            : base(node)
        {
            XmlNodeList tileNodes = node.SelectNodes("tile");

            if (!settings.MultipleTilesets)
            {
                // Just one tileset for this layer, so get it and save it.
                if (node.Attributes["set"] != null)
                {
                    this.Tilesets.Add(node.Attributes["set"].Value);
                }
                if (settings.ExportTileSize)
                {
                    if (node.Attributes["tileWidth"] != null)
                    {
                        this.TileWidth = int.Parse(node.Attributes["tileWidth"].Value, CultureInfo.InvariantCulture);
                    }
                    if (node.Attributes["tileHeight"] != null)
                    {
                        this.TileHeight = int.Parse(node.Attributes["tileHeight"].Value, CultureInfo.InvariantCulture);
                    }
                }
                else
                {
                    if (this.Tilesets.Count > 0)
                    {
                        // Extract the tileset so we can get the default tile width/height for the layer.
                        TilesetContent tileset = (from x in level.Project.Tilesets
                                                  where (x.Name == this.Tilesets[0])
                                                  select x).First <TilesetContent>();
                        if (tileset != null)
                        {
                            this.TileWidth  = tileset.TileWidth;
                            this.TileHeight = tileset.TileHeight;
                        }
                    }
                }
            }
            else
            {
                // Multiple tilesets for this layer, all saved to each tile.  We want to save these up front, so we
                // need to extract them all.
                List <XmlNode> nodes = new List <XmlNode>(tileNodes.Count);
                foreach (XmlNode tileNode in tileNodes)
                {
                    nodes.Add(tileNode);
                }
                string[] tilesetNames = (from x in nodes
                                         where (x.Attributes["set"] != null)
                                         select x.Attributes["set"].Value).Distinct <string>().ToArray <string>();
                this.Tilesets.AddRange(tilesetNames);
            }
            foreach (XmlNode tileNode in tileNodes)
            {
                this.Tiles.Add(new TileContent(tileNode, this, settings));
            }
        }
示例#2
0
 public TileContent(XmlNode node, TileLayerContent layer, TileLayerSettingsContent settings)
 {
     if (settings.ExportTileSize)
     {
         if (!settings.MultipleTilesets)
         {
             this.Height = layer.TileHeight;
             this.Width  = layer.TileWidth;
         }
         else
         {
             if (node.Attributes["th"] != null)
             {
                 this.Height = int.Parse(node.Attributes["th"].Value, CultureInfo.InvariantCulture);
             }
             if (node.Attributes["tw"] != null)
             {
                 this.Width = int.Parse(node.Attributes["tw"].Value, CultureInfo.InvariantCulture);
             }
         }
     }
     if (node.Attributes["x"] != null)
     {
         this.Position.X = int.Parse(node.Attributes["x"].Value, CultureInfo.InvariantCulture);
     }
     if (node.Attributes["y"] != null)
     {
         this.Position.Y = int.Parse(node.Attributes["y"].Value, CultureInfo.InvariantCulture);
     }
     if (node.Attributes["tx"] != null)
     {
         this.TextureOffset.X = int.Parse(node.Attributes["tx"].Value, CultureInfo.InvariantCulture);
     }
     if (node.Attributes["ty"] != null)
     {
         this.TextureOffset.Y = int.Parse(node.Attributes["ty"].Value, CultureInfo.InvariantCulture);
     }
     if (node.Attributes["id"] != null)
     {
         this.SourceIndex = int.Parse(node.Attributes["id"].Value, CultureInfo.InvariantCulture);
     }
     if (settings.MultipleTilesets)
     {
         if (node.Attributes["set"] != null)
         {
             this.TilesetName = node.Attributes["set"].Value;
         }
     }
     else
     {
         this.TilesetName = layer.Tilesets[0];
     }
 }
示例#3
0
        public LevelContent(ProjectContent project, XmlDocument document)
        {
            this.Project = project;
            XmlNode levelNode = document["level"];

            // Level values/attributes
            foreach (ValueTemplateContent value in project.Values)
            {
                XmlNode attribute = null;
                if ((attribute = levelNode.Attributes[value.Name]) != null)
                {
                    if (value is BooleanValueTemplateContent)
                    {
                        this.Values.Add(new BooleanValueContent(value.Name, bool.Parse(attribute.Value)));
                    }
                    else if (value is IntegerValueTemplateContent)
                    {
                        this.Values.Add(new IntegerValueContent(value.Name,
                                                                int.Parse(attribute.Value, CultureInfo.InvariantCulture)));
                    }
                    else if (value is NumberValueTemplateContent)
                    {
                        this.Values.Add(new NumberValueContent(value.Name,
                                                               float.Parse(attribute.Value, CultureInfo.InvariantCulture)));
                    }
                    else if (value is StringValueTemplateContent)
                    {
                        this.Values.Add(new StringValueContent(value.Name, attribute.Value));
                    }
                }
            }
            // Height
            this.Height = int.Parse(levelNode.SelectSingleNode("height").InnerText, CultureInfo.InvariantCulture);
            // Width
            this.Width = int.Parse(levelNode.SelectSingleNode("width").InnerText, CultureInfo.InvariantCulture);
            // Layers
            // Here we'll construct an XPath query of all possible layer names so we can just extract the nodes all
            // at once.
            string[] layerNames = (from x in project.LayerSettings select x.Name).ToArray <string>();
            string   layerXPath = string.Join("|", layerNames);

            foreach (XmlNode layerNode in levelNode.SelectNodes(layerXPath))
            {
                // Attempt to extract the settings for this layer.
                LayerSettingsContent[] s = (from x in project.LayerSettings
                                            where x.Name.Equals(layerNode.Name)
                                            select x).ToArray <LayerSettingsContent>();
                if (!(s.Length > 0))
                {
                    continue;
                }
                LayerSettingsContent layerSettings = s[0];
                // We have a grid layer.
                if (layerSettings is GridLayerSettingsContent)
                {
                    GridLayerSettingsContent settings  = layerSettings as GridLayerSettingsContent;
                    GridLayerContent         gridLayer = new GridLayerContent(layerNode, this, settings);
                    if (gridLayer != null)
                    {
                        this.Layers.Add(gridLayer);
                    }
                }
                else if (layerSettings is TileLayerSettingsContent)
                {
                    TileLayerSettingsContent settings  = layerSettings as TileLayerSettingsContent;
                    TileLayerContent         tileLayer = new TileLayerContent(layerNode, this, settings);
                    if (tileLayer != null)
                    {
                        this.Layers.Add(tileLayer);
                    }
                }
                else if (layerSettings is ObjectLayerSettingsContent)
                {
                    ObjectLayerContent objectLayer = new ObjectLayerContent(layerNode, this);
                    if (objectLayer != null)
                    {
                        this.Layers.Add(objectLayer);
                    }
                }
            }
        }