public static void RefreshBuildXML(BuildGroups buildGroup, BuildInfo buildInfo) { buildInfo = buildInfo.Clone(); Dictionary<string, BuildInfo> dict = BuildGroupDict[buildGroup].Builds; if (dict.ContainsKey(buildInfo.BuildName)) { dict[buildInfo.BuildName] = buildInfo; } else { dict.Add(buildInfo.BuildName, buildInfo); } string text; using (StreamReader sr = new StreamReader(BuildGroupXMLDict[buildGroup])) { text = sr.ReadToEnd(); } XmlDocument doc = new XmlDocument(); doc.LoadXml(text); XmlElement allBuilds = doc.DocumentElement; buildInfo.ExportToXML(allBuilds); using (StreamWriter sw = new StreamWriter(BuildGroupXMLDict[buildGroup])) { doc.Save(sw); } }
/// <summary> /// Can only be executed in StoryEditor/CardEditor/LevelEditor /// </summary> public void DeleteBuild(BuildGroups buildGroup, string buildName) { string text; using (StreamReader sr = new StreamReader(BuildGroupXMLDict[buildGroup])) { text = sr.ReadToEnd(); } XmlDocument doc = new XmlDocument(); doc.LoadXml(text); XmlElement allBuilds = doc.DocumentElement; SortedDictionary<string, XmlElement> buildNodesDict = new SortedDictionary<string, XmlElement>(); foreach (XmlElement node in allBuilds.ChildNodes) { string name = node.Attributes["BuildName"].Value; if (name != buildName) { buildNodesDict.Add(name, node); } } allBuilds.RemoveAll(); foreach (KeyValuePair<string, XmlElement> kv in buildNodesDict) { allBuilds.AppendChild(kv.Value); } using (StreamWriter sw = new StreamWriter(BuildGroupXMLDict[buildGroup])) { doc.Save(sw); } ReloadBuildXML(); //删除Story中同名的Level SortedDictionary<LevelTypes, List<string>> removeLevelPath = new SortedDictionary<LevelTypes, List<string>>(); foreach (KeyValuePair<LevelTypes, SortedDictionary<string, Level>> kv in AllLevels.LevelDict) { removeLevelPath.Add(kv.Key, new List<string>()); foreach (KeyValuePair<string, Level> _kv in kv.Value) { if (_kv.Value is Enemy enemy) { if (enemy.BuildInfo.BuildName.Equals(buildName)) { removeLevelPath[kv.Key].Add(_kv.Key); } } } } foreach (KeyValuePair<LevelTypes, List<string>> kv in removeLevelPath) { SortedDictionary<string, Level> dict = AllLevels.LevelDict[kv.Key]; foreach (string s in kv.Value) { AllLevels.DeleteLevel(dict[s].LevelType, dict[s].LevelNames["en"]); } } }
public static BuildInfo GetBuildInfo(BuildGroups buildGroups, string buildName) { if (BuildGroupDict.ContainsKey(buildGroups)) { if (BuildGroupDict[buildGroups].Builds.ContainsKey(buildName)) { return BuildGroupDict[buildGroups].Builds[buildName].Clone(); } } return null; }