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 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); } } } }