private void SaveStory() { ChapterMap?.SaveChapter(); AllStories.RefreshStoryXML(Cur_Story); AllStories.ReloadStoryXML(); SetStory(AllStories.GetStory("DefaultStory", CloneVariantUtils.OperationType.Clone)); NoticeManager.Instance.ShowInfoPanelCenter("Success", 0, 1f); }
public static void Load(string configFolderPath) { ConfigFolderPath = configFolderPath; AllColors.AddAllColors(); AllSideEffects.AddAllSideEffects(); AllScriptExecuteSettings.AddAllScriptExecuteSettings(); AllBuffs.AddAllBuffs(); AllCards.AddAllCards(); AllBuilds.AddAllBuilds(); AllLevels.AddAllLevels(); AllStories.AddAllStories(); AllCards.RefreshAllCardXML(); }
/// <summary> /// Can only be executed in StoryEditor/CardEditor/LevelEditor /// </summary> public static void RenameLevel(LevelTypes levelType, string levelName_en_ori, Level newLevel) { string text; using (StreamReader sr = new StreamReader(LevelDefaultXMLDict[levelType])) { text = sr.ReadToEnd(); } XmlDocument doc = new XmlDocument(); doc.LoadXml(text); XmlElement allLevel = doc.DocumentElement; SortedDictionary <string, XmlElement> levelNodesDict = new SortedDictionary <string, XmlElement>(); foreach (XmlElement node in allLevel.ChildNodes) { string name = node.Attributes["name_en"].Value; if (name != levelName_en_ori && name != newLevel.LevelNames["en"]) { levelNodesDict.Add(name, node); } } allLevel.RemoveAll(); newLevel.ExportToXML(allLevel); foreach (KeyValuePair <string, XmlElement> kv in levelNodesDict) { allLevel.AppendChild(kv.Value); } using (StreamWriter sw = new StreamWriter(LevelDefaultXMLDict[levelType])) { doc.Save(sw); } ReloadLevelXML(); // 从Story中移除该Level HashSet <string> changeList = new HashSet <string>(); foreach (KeyValuePair <string, Story> kv in AllStories.StoryDict) { foreach (KeyValuePair <int, Chapter> _kv in kv.Value.Chapters) { foreach (KeyValuePair <int, Level> KV in _kv.Value.Levels) { if (KV.Value.LevelNames["en"].Equals(levelName_en_ori)) { changeList.Add(kv.Key); KV.Value.LevelNames["en"] = newLevel.LevelNames["en"]; } } } } foreach (string storyName in changeList) { Story story = AllStories.StoryDict[storyName]; AllStories.RefreshStoryXML(story); AllStories.ReloadStoryXML(); } }
/// <summary> /// Can only be executed in StoryEditor/CardEditor/LevelEditor /// </summary> public static void DeleteLevel(LevelTypes levelType, string levelName_en) { string text; using (StreamReader sr = new StreamReader(LevelDefaultXMLDict[levelType])) { text = sr.ReadToEnd(); } XmlDocument doc = new XmlDocument(); doc.LoadXml(text); XmlElement allLevel = doc.DocumentElement; SortedDictionary <string, XmlElement> levelNodesDict = new SortedDictionary <string, XmlElement>(); foreach (XmlElement node in allLevel.ChildNodes) { string name = node.Attributes["name_en"].Value; if (name != levelName_en) { levelNodesDict.Add(name, node); } } allLevel.RemoveAll(); foreach (KeyValuePair <string, XmlElement> kv in levelNodesDict) { allLevel.AppendChild(kv.Value); } using (StreamWriter sw = new StreamWriter(LevelDefaultXMLDict[levelType])) { doc.Save(sw); } ReloadLevelXML(); // 从Story中移除该Level SortedDictionary <string, SortedDictionary <int, List <int> > > removeList = new SortedDictionary <string, SortedDictionary <int, List <int> > >(); foreach (KeyValuePair <string, Story> kv in AllStories.StoryDict) { removeList.Add(kv.Key, new SortedDictionary <int, List <int> >()); foreach (KeyValuePair <int, Chapter> _kv in kv.Value.Chapters) { removeList[kv.Key].Add(_kv.Key, new List <int>()); foreach (KeyValuePair <int, Level> KV in _kv.Value.Levels) { if (KV.Value.LevelNames["en"].Equals(levelName_en)) { removeList[kv.Key][_kv.Key].Add(KV.Key); } } } } foreach (KeyValuePair <string, SortedDictionary <int, List <int> > > kv in removeList) { Story story = AllStories.StoryDict[kv.Key]; foreach (KeyValuePair <int, List <int> > _kv in kv.Value) { Chapter chapter = story.Chapters[_kv.Key]; foreach (int i in _kv.Value) { chapter.Levels.Remove(i); } } AllStories.RefreshStoryXML(story); AllStories.ReloadStoryXML(); } }
void Start() { SetStory(AllStories.GetStory("DefaultStory", CloneVariantUtils.OperationType.Variant)); }
public void InitializeLevelList() { SelectTab(LevelTypes.Enemy); foreach (KeyValuePair <LevelTypes, List <StoryEditorPanel_LevelButton> > kv in MyLevelButtons) { foreach (StoryEditorPanel_LevelButton btn in kv.Value) { btn.PoolRecycle(); } kv.Value.Clear(); } foreach (KeyValuePair <LevelTypes, SortedDictionary <string, Level> > kv in AllLevels.LevelDict) { SortedDictionary <int, List <Level> > sortedListByLevelDifficulty = new SortedDictionary <int, List <Level> >(); if (kv.Key == LevelTypes.Enemy) { foreach (KeyValuePair <string, Level> _kv in kv.Value) { if (!sortedListByLevelDifficulty.ContainsKey(_kv.Value.DifficultyLevel)) { sortedListByLevelDifficulty.Add(_kv.Value.DifficultyLevel, new List <Level>()); } sortedListByLevelDifficulty[_kv.Value.DifficultyLevel].Add(_kv.Value); } foreach (KeyValuePair <int, List <Level> > KV in sortedListByLevelDifficulty) { foreach (Level lv in KV.Value) { if (lv.LevelNames["en"].Equals("New" + kv.Key)) { continue; } StoryEditorPanel_LevelButton btn = StoryEditorPanel_LevelButton.BaseInitialize( level : lv.Clone(), parent : LevelContainerDict[kv.Key], onSetButtonClick : delegate(Level level) { ChapterMap.SetCurrentNodeLevel(level); }, onEditButtonClick: delegate { UIManager.Instance.CloseUIForm <StoryEditorPanel>(); UIManager.Instance.ShowUIForms <LevelEditorPanel>().SetLevel(lv.Clone()); }, onDeleteButtonClick: delegate { ConfirmPanel cp = UIManager.Instance.ShowUIForms <ConfirmPanel>(); cp.Initialize(LanguageManager.Instance.GetText("StoryEditorPanel_DeleteLevelFormLibrary0"), LanguageManager.Instance.GetText("Common_Yes"), LanguageManager.Instance.GetText("Common_No"), delegate { cp.CloseUIForm(); AllLevels.DeleteLevel(kv.Key, lv.LevelNames["en"]); InitializeLevelList(); SelectTab(kv.Key); SetStory(AllStories.GetStory("DefaultStory", CloneVariantUtils.OperationType.Clone)); }, delegate { cp.CloseUIForm(); }); } ); MyLevelButtons[kv.Key].Add(btn); } } } else { foreach (KeyValuePair <string, Level> _kv in kv.Value) { if (_kv.Key.Equals("New" + kv.Key)) { continue; } StoryEditorPanel_LevelButton btn = StoryEditorPanel_LevelButton.BaseInitialize( level : _kv.Value.Clone(), parent : LevelContainerDict[kv.Key], onSetButtonClick : delegate(Level level) { ChapterMap.SetCurrentNodeLevel(level); }, onEditButtonClick: delegate { UIManager.Instance.CloseUIForm <StoryEditorPanel>(); UIManager.Instance.ShowUIForms <LevelEditorPanel>().SetLevel(_kv.Value.Clone()); }, onDeleteButtonClick: delegate { ConfirmPanel cp = UIManager.Instance.ShowUIForms <ConfirmPanel>(); cp.Initialize(LanguageManager.Instance.GetText("StoryEditorPanel_DeleteLevelFormLibrary0"), LanguageManager.Instance.GetText("Common_Yes"), LanguageManager.Instance.GetText("Common_No"), delegate { cp.CloseUIForm(); AllLevels.DeleteLevel(kv.Key, _kv.Value.LevelNames["en"]); InitializeLevelList(); SelectTab(kv.Key); SetStory(AllStories.GetStory("DefaultStory", CloneVariantUtils.OperationType.Clone)); }, delegate { cp.CloseUIForm(); }); } ); MyLevelButtons[kv.Key].Add(btn); } } } }
public void RefreshStory() { AllStories.ReloadStoryXML(); SetStory(AllStories.GetStory("DefaultStory", CloneVariantUtils.OperationType.Clone)); }
public void GetListChapters(string url) { if (string.IsNullOrEmpty(url)) { return; } if (File.Exists(Path.Combine(Cfg.StoryDirectory, "chapters.json"))) { return; } List <LinkPage> linkPages = new List <LinkPage>(); linkPages.Add(new LinkPage() { Link = url }); while (linkPages.Any(o => !o.Processed)) { var page = linkPages.FirstOrDefault(o => !o.Processed); //ClearCurrentConsoleLine(); //using (var wc = new WebClient()) if (page != null) { Cfg.LogQueue.Enqueue($"{page.Link}"); try { //wc.Headers.Add("User-Agent", Cfg.StrUserAgent); //if (url != null) { //var bytes = wc.DownloadData(url); //var html = Encoding.UTF8.GetString(bytes); var html = Util.DownloadUrl(page.Link); var parser = new HtmlParser(); var doc = parser.Parse(html); var chaps = doc.QuerySelectorAll(".list-chapter") .Where(o => { var f = o.QuerySelector("h2"); if (f != null) { return(Regex.Match(f.TextContent, "Danh sách chương", RegexOptions.IgnoreCase) .Success); } return(false); }) .Select(o => o.QuerySelector("ul")) .SelectMany(o => o.QuerySelectorAll("a") .Select(p => new ChapterInfo() { Title = p.Text(), Link = p.Attributes["href"]?.Value }).ToList()) .Where(o => !string.IsNullOrEmpty(o.Link)) .ToList(); AllStories.AddRange(chaps); // get chapters link // get next list chapters var foundUrls = doc .QuerySelectorAll(".pagination > ul > li > a") .Where(o => { int.TryParse(o.Text(), out var i); return(i > 0); }) .Select(o => o.Attributes["href"]?.Value) .Where(o => !string.IsNullOrEmpty(o)) .ToList() .Except(linkPages.Select(o => o.Link).ToList()) .Select(o => new LinkPage() { Link = o }) .ToList(); linkPages.AddRange(foundUrls); } page.Processed = true; } catch (Exception ex) { Cfg.LogQueue.Enqueue($"download error:{ex.StackTrace}"); Task.Delay(1000).Wait(); } } } }
public void GetListChapters(string url) { if (string.IsNullOrEmpty(url)) { return; } if (File.Exists(Path.Combine(Cfg.StoryDirectory, "chapters.json"))) { return; } var found = true; while (found) { //ClearCurrentConsoleLine(); var url2 = url; Cfg.LogQueue.Enqueue($"{url2}"); using (var wc = new WebClient()) { try { wc.Headers.Add("User-Agent", Cfg.StrUserAgent); if (url != null) { var bytes = wc.DownloadData(url); var html = Encoding.UTF8.GetString(bytes); var parser = new HtmlParser(); var doc = parser.Parse(html); var chaps = doc.QuerySelectorAll("#list-chapter") .SelectMany(o => o.QuerySelectorAll("ul") .Where(p => p.Attributes["class"]?.Value?.ToString() .Contains("list-chapter") ?? false) .ToList() ) .Where(o => o != null) .SelectMany(o => o.QuerySelectorAll("a") .Select(p => new ChapterInfo() { Title = p.Text(), Link = p.Attributes["href"]?.Value }).ToList()) .Where(o => !string.IsNullOrEmpty(o.Link)) .ToList(); AllStories.AddRange(chaps); // get chapters link // get next list chapters url = doc .QuerySelectorAll(".pagination > li") .ToList() .Where(o => o.QuerySelectorAll(".glyphicon-menu-right").Length > 0) .Select(o => o.QuerySelector("a")) .Select(o => o.Attributes["href"]?.Value.Split('#').FirstOrDefault()) .FirstOrDefault(o => o != null); } found = !string.IsNullOrEmpty(url); } catch (Exception ex) { Cfg.LogQueue.Enqueue($"Error {url} -{ex.StackTrace}"); //Task.Delay(1000).Wait(); } } } }
/// <summary> /// Can only be executed in StoryEditor/CardEditor/LevelEditor /// </summary> public static void DeleteCard(int cardID) { string text; using (StreamReader sr = new StreamReader(CardsXMLFile)) { text = sr.ReadToEnd(); } XmlDocument doc = new XmlDocument(); doc.LoadXml(text); XmlElement allCards = doc.DocumentElement; SortedDictionary <int, XmlElement> cardNodesDict = new SortedDictionary <int, XmlElement>(); foreach (XmlElement node in allCards.ChildNodes) { int id = int.Parse(node.Attributes["id"].Value); if (cardID != id) { cardNodesDict.Add(id, node); } } allCards.RemoveAll(); foreach (KeyValuePair <int, XmlElement> kv in cardNodesDict) { allCards.AppendChild(kv.Value); } using (StreamWriter sw = new StreamWriter(CardsXMLFile)) { doc.Save(sw); } ReloadCardXML(); //从 Story、Builds、 Levels、和AddCard类型的SideEffect中移除该卡片ID //Story List <Story> refreshStories = new List <Story>(); foreach (KeyValuePair <string, Story> kv in AllStories.StoryDict) { bool thisNeedsRefresh = false; foreach (KeyValuePair <int, BuildInfo> _kv in kv.Value.PlayerBuildInfos) { if (_kv.Value.M_BuildCards.CardSelectInfos.ContainsKey(cardID)) { _kv.Value.M_BuildCards.CardSelectInfos.Remove(cardID); thisNeedsRefresh = true; } } if (thisNeedsRefresh) { refreshStories.Add(kv.Value); kv.Value.RefreshBaseCardLimitDict(); } } foreach (Story story in refreshStories) { AllStories.RefreshStoryXML(story); } if (refreshStories.Count > 0) { AllStories.ReloadStoryXML(); } //Build bool buildXMLNeedsReload = false; Dictionary <BuildGroups, List <BuildInfo> > refreshBuildInfoDict = new Dictionary <BuildGroups, List <BuildInfo> >(); foreach (KeyValuePair <BuildGroups, BuildGroup> kv in AllBuilds.BuildGroupDict) { refreshBuildInfoDict.Add(kv.Key, new List <BuildInfo>()); foreach (KeyValuePair <string, BuildInfo> _kv in kv.Value.Builds) { if (_kv.Value.M_BuildCards.CardSelectInfos.ContainsKey(cardID)) { _kv.Value.M_BuildCards.CardSelectInfos.Remove(cardID); refreshBuildInfoDict[kv.Key].Add(_kv.Value); buildXMLNeedsReload = true; } } } foreach (KeyValuePair <BuildGroups, List <BuildInfo> > kv in refreshBuildInfoDict) { foreach (BuildInfo bi in kv.Value) { AllBuilds.RefreshBuildXML(kv.Key, bi); } } if (buildXMLNeedsReload) { AllBuilds.ReloadBuildXML(); } //Levels List <Level> refreshLevel = new List <Level>(); foreach (KeyValuePair <LevelTypes, SortedDictionary <string, Level> > kv in AllLevels.LevelDict) { foreach (KeyValuePair <string, Level> _kv in kv.Value) { bool thisNeedsRefresh = _kv.Value.DeleteCard(cardID); refreshLevel.Add(_kv.Value); } } foreach (Level level in refreshLevel) { AllLevels.RefreshLevelXML(level); } if (refreshLevel.Count > 0) { AllLevels.ReloadLevelXML(); } //SideEffect, ICardDeckLinked bool sideEffectNeedsReload = false; foreach (KeyValuePair <int, CardInfo_Base> kv in CardDict) { bool thisCardNeedsRefresh = false; foreach (SideEffectExecute see in kv.Value.SideEffectBundle.SideEffectExecutes) { foreach (SideEffectBase se in see.SideEffectBases) { if (se is ICardDeckLinked link_se) { int value = link_se.GetCardIDSideEffectValue().Value; if (value == cardID) { link_se.GetCardIDSideEffectValue().SetValue(((int)EmptyCardTypes.NoCard).ToString()); sideEffectNeedsReload = true; thisCardNeedsRefresh = true; } } } } if (thisCardNeedsRefresh) { RefreshCardXML(kv.Value); } } if (sideEffectNeedsReload) { ReloadCardXML(); } }