private static ConstructionInformation LoadConstructionInformation(XmlReader reader) { float constructionTime = Convert.ToSingle(reader["ConstructionTime"], CultureInfo.InvariantCulture); List <ResourceTypeSource> resources = new List <ResourceTypeSource>(); EnvironmentResource environmentResource = new EnvironmentResource(); do { reader.Read(); reader.MoveToContent(); if (reader.Name == nameof(EnvironmentResource)) { int winStep = Convert.ToInt32(reader["WinStep"] ?? "0", CultureInfo.InvariantCulture); int o2 = Convert.ToInt32(reader["O2"] ?? "0", CultureInfo.InvariantCulture); int energy = Convert.ToInt32(reader["Energy"] ?? "0", CultureInfo.InvariantCulture); environmentResource = new EnvironmentResource(winStep, o2, energy); } else if (reader.NodeType == XmlNodeType.Element) { var resourceName = reader.Name; bool fromHexagon = Convert.ToBoolean(reader["FromHexagon"] ?? "False", CultureInfo.InvariantCulture); var resourceType = (ResourceType)Enum.Parse(typeof(ResourceType), resourceName); var resourceTypeSource = new ResourceTypeSource(resourceType, fromHexagon ? SourceType.Hexagon : SourceType.Network); resources.Add(resourceTypeSource); } }while (reader.IsStartElement() || reader.Name != "ConstructionInformation"); var constructionInformation = new ConstructionInformation(constructionTime, environmentResource, resources.ToArray()); return(constructionInformation); }
private static BuildingDescription LoadBuilding(XmlReader reader) { var name = reader.GetAttribute("Name") ?? "empty"; var canExtractWater = Convert.ToBoolean(reader["CanExtractWater"] ?? "False"); name = name[0].ToString().ToLower() + name.Substring(1); var nameID = name + "Name"; var descriptionID = name + "Description"; var verbalStructureDescription = new VerbalStructureDescription(name, new TranslationKey(nameID), new TranslationKey(descriptionID)); ConstructionInformation constructionInformation = null; ProductionInformation productionInformation = null; RenderInformation renderInformation = new RenderInformation(name + "Fill", name + "Border"); Knowledge unlockCost = Knowledge.Zero; do { reader.Read(); if (!reader.IsStartElement()) { continue; } switch (reader.Name) { case "ConstructionInformation": constructionInformation = LoadConstructionInformation(reader); break; case "ProductionInformation": productionInformation = LoadProductionInformation(reader); break; case "UnlockCost": unlockCost = LoadUnlockCost(reader); break; } }while (!(string.Equals(reader.Name, "Building") && !reader.IsStartElement())); return(new BuildingDescription(verbalStructureDescription, unlockCost, constructionInformation, productionInformation, renderInformation, canExtractWater)); }