public ProjectContent(XmlDocument document) { XmlNode projectNode = document["project"]; // Name XmlNode nameNode = projectNode.SelectSingleNode("name"); if (nameNode != null) { this.Name = nameNode.InnerText; } // Settings XmlNode settingsNode = projectNode.SelectSingleNode("settings"); if (settingsNode != null) { this.Settings = new ProjectSettingsContent(settingsNode); } else { this.Settings = new ProjectSettingsContent(); } // Values XmlNode valuesNode = projectNode.SelectSingleNode("values"); if (valuesNode != null) { foreach (XmlNode valueNode in valuesNode.ChildNodes) { ValueTemplateContent valueContent = ValueContentTemplateParser.Parse(valueNode); if (valueContent != null) { this.Values.Add(valueContent); } } } // Tilesets XmlNode tilesetsNode = projectNode.SelectSingleNode("tilesets"); if (tilesetsNode != null) { foreach (XmlNode childNode in tilesetsNode) { this.Tilesets.Add(new TilesetContent(childNode)); } } // Objects XmlNode objectsNode = projectNode.SelectSingleNode("objects"); if (objectsNode != null) { foreach (XmlNode childNode in objectsNode.SelectNodes("object|folder/object")) { this.Objects.Add(new ObjectTemplateContent(childNode)); } } // Layer Settings XmlNode layerSettingsNode = projectNode.SelectSingleNode("layers"); if (layerSettingsNode != null) { foreach (XmlNode childNode in layerSettingsNode.ChildNodes) { LayerSettingsContent layerSettingsContent = LayerSettingsContentParser.Parse(childNode); if (layerSettingsContent != null) { this.LayerSettings.Add(layerSettingsContent); } } } }
public ObjectTemplateContent(XmlNode node) { if (node.Attributes["height"] != null) { this.Height = int.Parse(node.Attributes["height"].Value, CultureInfo.InvariantCulture); } if (node.Attributes["width"] != null) { this.Width = int.Parse(node.Attributes["width"].Value, CultureInfo.InvariantCulture); } if (node.Attributes["resizableX"] != null) { this.IsResizableX = bool.Parse(node.Attributes["resizableX"].Value); } if (node.Attributes["resizableY"] != null) { this.IsResizableY = bool.Parse(node.Attributes["resizableY"].Value); } if (node.Attributes["tile"] != null) { this.IsTiled = bool.Parse(node.Attributes["tile"].Value); } if (node.Attributes["name"] != null) { this.Name = node.Attributes["name"].Value; } if (node.Attributes["originX"] != null) { this.Origin.X = int.Parse(node.Attributes["originX"].Value, CultureInfo.InvariantCulture); } if (node.Attributes["originY"] != null) { this.Origin.Y = int.Parse(node.Attributes["originY"].Value, CultureInfo.InvariantCulture); } if (node.Attributes["imageOffsetX"] != null) { this.Source.X = int.Parse(node.Attributes["imageOffsetX"].Value, CultureInfo.InvariantCulture); } else { this.Source.X = 0; } if (node.Attributes["imageOffsetY"] != null) { this.Source.Y = int.Parse(node.Attributes["imageOffsetY"].Value, CultureInfo.InvariantCulture); } else { this.Source.Y = 0; } if (node.Attributes["imageWidth"] != null) { this.Source.Width = int.Parse(node.Attributes["imageWidth"].Value, CultureInfo.InvariantCulture); } else { this.Source.Width = this.Width; } if (node.Attributes["imageHeight"] != null) { this.Source.Height = int.Parse(node.Attributes["imageHeight"].Value, CultureInfo.InvariantCulture); } else { this.Source.Height = this.Height; } if (node.Attributes["image"] != null) { this.TextureFile = node.Attributes["image"].Value; } // Values XmlNode valuesNode = node.SelectSingleNode("values"); if (valuesNode != null) { foreach (XmlNode valueNode in valuesNode.SelectNodes("boolean|integer|number|string|text")) { ValueTemplateContent valueContent = ValueContentTemplateParser.Parse(valueNode); if (valueContent != null) { this.Values.Add(valueContent); } } } }