public void Load(XElement modifierElement) { XElement fElement = XMLUtils.GetElement(modifierElement, "ModifiersF"); if (fElement != null) { ModifiersF = new Dictionary <string, double>(); foreach (XElement childElement in fElement.Elements()) { ModifiersF.Add(XMLUtils.GetName(childElement), double.Parse(childElement.Value)); } } XElement aElement = XMLUtils.GetElement(modifierElement, "ModifiersA"); if (aElement != null) { ModifiersA = new Dictionary <string, double>(); foreach (XElement childElement in aElement.Elements()) { ModifiersA.Add(XMLUtils.GetName(childElement), double.Parse(childElement.Value)); } } XElement aAfterElement = XMLUtils.GetElement(modifierElement, "ModifiersAAfter"); if (aAfterElement != null) { ModifiersAAfter = new Dictionary <string, double>(); foreach (XElement childElement in aElement.Elements()) { ModifiersAAfter.Add(XMLUtils.GetName(childElement), double.Parse(childElement.Value)); } } }
public void Load(string filename = null) { Console.WriteLine("Loading..."); XDocument xd = null; if (filename == null) { xd = XDocument.Load(@"saves/save.xml"); } else { xd = XDocument.Load(@"saves/" + filename + ".xml"); } XElement element = xd.Element("Forest"); // Loads values and soft values XElement valuesElement = XMLUtils.GetElement(element, "Values"); foreach (XElement valueElement in valuesElement.Elements()) { string name = XMLUtils.GetName(valueElement); if (name.StartsWith("sv")) //Soft value { SoftValues[name] = double.Parse(valueElement.Value, System.Globalization.NumberFormatInfo.InvariantInfo); } else { Values[XMLUtils.GetName(valueElement)] = double.Parse(valueElement.Value, System.Globalization.NumberFormatInfo.InvariantInfo); } } // Loads skills XElement skillsElement = XMLUtils.GetElement(element, "skills"); foreach (string skill in Statics.skills) { if (XMLUtils.HasChild(skillsElement, skill)) { string skillValue = skillsElement.GetString(skill); if (skillValue.Contains(":")) { Xp[skill] = double.Parse(skillValue.Split(':')[0]); TalentPoints[skill] = int.Parse(skillValue.Split(':')[1]); } else { Xp[skill] = double.Parse(skillValue); } } } // Loads growths XElement growthsElement = XMLUtils.GetElement(element, "Growths"); foreach (Entity g in Entities.Values) { XElement growthElement = XMLUtils.GetElement(growthsElement, g.Name); if (growthElement != null) { g.Load(growthElement); } } // Loads doables XElement doablesElement = XMLUtils.GetElement(element, "Doables"); foreach (Doable d in Doables.Values) { XElement doableElement = XMLUtils.GetElement(doablesElement, d.Name); if (doableElement != null) { d.Load(doableElement); } } // Loads modifiers TODO: if anything needs modifiers to stay past loads, do something about it then Modifiers.Clear(); XElement modifiersElement = XMLUtils.GetElement(element, "Modifiers"); foreach (XElement modifierElement in modifiersElement.Elements()) { Modifier m = new Modifier(XMLUtils.GetName(modifierElement)); m.Load(modifierElement); Modifiers[m.Name] = m; } string path = element.GetString("Path"); CurBoss = element.GetInt("PathBoss"); foreach (Path p in Path.paths) { if (p.Name == path) { CurPath = p; Boss = p.Bosses[CurBoss]; break; } } Count = element.GetInt("Count"); Hp = element.GetDouble("Hp"); if (element.HasChild("Mana")) { Mana = element.GetDouble("Mana"); } OfflineTicks = element.GetInt("OfflineTicks"); if (element.HasChild("FightingStyle")) { FightingStyle = element.GetString("FightingStyle"); } if (element.HasChild("LifeCount")) { LifeCount = element.GetInt("LifeCount"); } }