static Embed genUrban(DefinitionData definition) { EmbedBuilder em = new EmbedBuilder(); em.Color = Discord.Color.Blue; em.Title = definition.Word; string def = definition.Definition; if (def.Length > 1024) { def = $"{def.Substring(0, 1021)}..."; } em.AddField("Definition:", def); string exp = definition.Example; if (exp.Length > 1024) { exp = $"{exp.Substring(0, 1021)}..."; } em.AddField("Example:", exp); EmbedFooterBuilder emfb = new EmbedFooterBuilder(); emfb.Text = $"By {definition.Author}"; em.Footer = emfb; em.Url = definition.Permalink; return(em.Build()); }
public static void Gen_DefsTemplate(string defsPath, string outputPath) { if (!Directory.Exists(defsPath)) { Log.Error(); Log.WriteLine($"Directory no found: {defsPath}"); return; } string sourceCodePath = Path.Combine(Directory.GetCurrentDirectory(), "Assembly-CSharp"); if (Directory.Exists(sourceCodePath)) { Log.Info(); Log.WriteLine(); } else { sourceCodePath = null; } DefinitionData coreDefinitionData = DefinitionData.Load(defsPath); Capture capture = Capture.Parse(coreDefinitionData); capture.ProcessFieldNames(coreDefinitionData); coreDefinitionData.Save(Path.Combine(outputPath, "CoreDefsProcessed")); Capture templates = Capture.Parse(coreDefinitionData, sourceCodePath, true); templates.Save(Path.Combine(outputPath, "Templates")); }
/// <summary> /// Process case and alias of all fields in this definition data. /// </summary> /// <param name="definitionData"></param> public void ProcessFieldNames(DefinitionData definitionData) { if (this.isTemplate) { return; } Log.Info(); Log.WriteLine("Start processing field names for all Defs."); definitionData.MarkProcessedFieldNames(); foreach (XElement curDef in from doc in definitionData.Data.Values from ele in doc.Root.Elements() select ele) { string curDefTypeName = curDef.Name.ToString(); DefInfo defInfo; if (this.allDefInfo.TryGetValue(curDefTypeName, out defInfo)) { defInfo.ProcessFieldNames(curDef); } else { //Log.Warning(); //Log.WriteLine($"'{curDefTypeName}' no matched."); } } Log.Info(); Log.WriteLine("Completed processing field names for all Defs."); }
public async Task SettingWordIndexer() { var result = await Client.GetRandomWordAsync(); Assert.DoesNotThrow(() => { result = new DefinitionData(); }); }
public static void Gen_DefsTemplate() { DefinitionData coreDefinitionData = DefinitionData.Load(@"D:\Games\SteamLibrary\steamapps\common\RimWorld\Mods\Core\Defs"); Capture capture = Capture.Parse(coreDefinitionData); capture.ProcessFieldNames(coreDefinitionData); coreDefinitionData.Save(@"C:\git\rw\RimWorld-Defs-Templates\CoreDefsProcessed"); string sourceCodePath = @"C:\git\rw\RimWorld-Decompile\Assembly-CSharp"; Capture templates = Capture.Parse(coreDefinitionData, sourceCodePath, true); templates.Save(@"C:\git\rw\RimWorld-Defs-Templates\Templates"); }
public void TaskDefinitionRestrictionsEnforcementMode(string mode, bool variableExpected, bool warningExpected) { using (TestHostContext hc = CreateTestContext()) { _ec.Setup(x => x.GetVariableValueOrDefault("agent.taskRestrictionsEnforcementMode")).Returns(mode); var definition = new DefinitionData { Name = "TestTask", Version = new DefinitionVersion { Major = 2, Minor = 7, Patch = 1 } }; // allow no variables var restrictions = new TaskDefinitionRestrictions(definition) { SettableVariables = new TaskVariableRestrictions() }; _ec.Object.Restrictions.Add(restrictions); var variable = "myVar"; var value = "myValue"; Command command = SetVariableCommand(variable, value); TaskSetVariableCommand setVariable = new TaskSetVariableCommand(); setVariable.Execute(_ec.Object, command); Assert.Equal((variableExpected ? value : null), _variables.Get(variable)); if (warningExpected) { Assert.Equal(1, _warnings.Count); if (variableExpected) { Assert.EndsWith("SetVariableNotAllowedWarnOnly", _warnings[0]); } else { Assert.EndsWith("SetVariableNotAllowed", _warnings[0]); } } else { Assert.Equal(0, _warnings.Count); } } }
/// <summary> /// Partitions the <see cref="DefinitionData"/> and then builds <see cref="IbanRegionDefinition"/>s from the resulting data. The <see cref="DefinitionData"/> is expected to have 8 segments per definition. /// </summary> /// <returns></returns> private static IDictionary <string, IbanRegionDefinition> GetDefinitions() { var definitions = DefinitionData .Partition(8) .Select(d => { var parts = d.ToList(); return(new IbanRegionDefinition { TwoLetterISORegionName = (string)parts[0], Length = (int)parts[1], Structure = (string)parts[2], Example = (string)parts[3] }); }) .OrderBy(d => d.TwoLetterISORegionName) .ToDictionary(kvp => kvp.TwoLetterISORegionName); // At dev time, ensure all definitions are valid. Debug.Assert(definitions.All(kvp => kvp.Value.Validate()), "One or more IBAN definitions are invalid."); return(definitions); }
static void Main(string[] args) { if (args.Length == 0) { return; } #region Application Info Assembly asm = Assembly.GetExecutingAssembly(); string title = asm.GetCustomAttribute <AssemblyTitleAttribute>().Title; string version = asm.GetCustomAttribute <AssemblyFileVersionAttribute>().Version; string copyright = asm.GetCustomAttribute <AssemblyCopyrightAttribute>().Copyright; Console.Title = title; Console.OutputEncoding = Encoding.Unicode; Log.WriteLine(); Log.WriteLine(ConsoleColor.Cyan, $" {FaceGood()}{FaceGood()}{FaceGood()}"); Log.WriteLine(); Log.WriteLine(ConsoleColor.Cyan, $" {title}"); Log.WriteLine(); Log.WriteLine(ConsoleColor.Cyan, $" Version {version}"); Log.WriteLine(); Log.WriteLine(ConsoleColor.Cyan, $" {copyright}"); Log.WriteLine(); #endregion #region Check Arguments string projectFile = null; string corePath = null; bool cleanModeOn = false; string modPath = null; string generateOption = null; foreach (string argument in args) { if (argument.StartsWith("-p:") && argument.Length > 3) { projectFile = argument.Substring(3); } else if (argument.StartsWith("-Core:") && argument.Length > 6) { corePath = argument.Substring(6); } else if (argument == "-Clean") { cleanModeOn = true; } } // Check Project File if (string.IsNullOrWhiteSpace(projectFile) || !File.Exists(projectFile)) { Log.Error(); Log.WriteLine(ConsoleColor.Red, $"Project File {projectFile} NO FOUND."); Log.WriteLine(); Console.Write("Press any key to exit..."); Console.ReadKey(); return; } Log.WriteLine(ConsoleColor.Green, $"======== Start Project {FaceGood()} ========"); Log.WriteLine(); Log.WriteLine(ConsoleColor.Green, "Porject File: "); Log.Indent(); Log.WriteLine(ConsoleColor.Cyan, projectFile); XDocument doc = XDocument.Load(projectFile); XElement root = doc.Root; modPath = root.Element("ModPath").Value; // Check Mod Path if (string.IsNullOrWhiteSpace(modPath) || !Directory.Exists(modPath)) { Log.Error(); Log.WriteLine(ConsoleColor.Red, $"Mod Directory {modPath} NO FOUND."); Log.WriteLine(); Console.Write("Press any key to exit..."); Console.ReadKey(); return; } Log.WriteLine(ConsoleColor.Green, "Mod Path: "); Log.Indent(); Log.WriteLine(ConsoleColor.Cyan, modPath); generateOption = root.Element("GenerateOption").Value; Log.WriteLine(ConsoleColor.Green, "Generate Option: "); Log.Indent(); Log.Write(ConsoleColor.Cyan, generateOption + " Mode"); if (cleanModeOn) { Log.WriteLine(ConsoleColor.Green, " | Clean Mode"); } else { Log.WriteLine(); } // Check Core Path if (generateOption == "Standard" && (string.IsNullOrWhiteSpace(corePath) || !Directory.Exists(corePath))) { generateOption = "Core"; Log.Warning(); Log.WriteLine(ConsoleColor.Yellow, "Core Directory NO FOUND."); Log.Indent(); Log.Write(ConsoleColor.Yellow, "Changed Generate Option to "); Log.WriteLine(ConsoleColor.Cyan, "Core Mode"); } if (generateOption == "Standard") { Log.WriteLine(ConsoleColor.Green, "Core Path: "); Log.Indent(); Log.WriteLine(ConsoleColor.Cyan, corePath); } Log.WriteLine(); #endregion #region Process Core and Special Mode if (generateOption == "Core") { Log.WriteLine(ConsoleColor.Green, "======== Start Processing Defs and Original Language Data ========"); string defsPath = Path.Combine(modPath, "Defs"); Console.WriteLine(defsPath); string keyedPath_English = Path.Combine(modPath, "Languages", "English", "Keyed"); string stringsPath_English = Path.Combine(modPath, "Languages", "English", "Strings"); DefinitionData Defs = DefinitionData.Load(defsPath); Capture capture = Capture.Parse(Defs); capture.ProcessFieldNames(Defs); InjectionData DefInjected_Original = InjectionData.Parse("Original", Defs); KeyedData Keyed_English = KeyedData.Load("English", keyedPath_English); Log.WriteLine(ConsoleColor.Green, "======== Completed Processing Defs and Original Language Data ========"); Log.WriteLine(); XElement Languages = root.Element("Languages"); foreach (XElement li in Languages.Elements()) { // If IsChecked if (string.Compare(li.Element("IsChecked").Value, "false", true) == 0) { continue; } string realName = li.Element("RealName").Value; string nativeName = li.Element("NativeName").Value; // Check Language Real Name if (string.IsNullOrWhiteSpace(realName)) { Log.Error(); Log.WriteLine(ConsoleColor.Red, "Missing Language Name."); continue; } Log.WriteLine(ConsoleColor.Green, $"======== Start Processing Language: {realName} ( {nativeName} ) ========"); string langPath = Path.Combine(modPath, "Languages", realName); bool isCustom = (string.Compare(li.Element("IsCustom").Value, "true", true) == 0); if (isCustom) { langPath = li.Element("CustomPath").Value; Log.WriteLine(ConsoleColor.Cyan, "Use Custom Language Output Directory: "); } else { Log.WriteLine(ConsoleColor.Cyan, "Language Path: "); } Log.Indent(); Log.WriteLine(ConsoleColor.Cyan, langPath); string defInjectedPath = Path.Combine(langPath, "DefInjected"); string keyedPath = Path.Combine(langPath, "Keyed"); string stringsPath = Path.Combine(langPath, "Strings"); InjectionData DefInjected_New = new InjectionData(realName, DefInjected_Original); KeyedData Keyed_New = new KeyedData(realName, Keyed_English); if (cleanModeOn) { DirectoryHelper.CleanDirectory(defInjectedPath, "*.xml"); DirectoryHelper.CleanDirectory(keyedPath, "*.xml"); DirectoryHelper.CleanDirectory(stringsPath, "*.txt"); } else { InjectionData DefInjected_Existed = InjectionData.Load(realName, defInjectedPath, true); DefInjected_New.MatchExisted(DefInjected_Existed); KeyedData Keyed_Existed = KeyedData.Load(realName, keyedPath, true); Keyed_New.MatchExisted(Keyed_Existed); } DefInjected_New.Save(defInjectedPath); Keyed_New.Save(keyedPath); DirectoryHelper.CopyDirectoryEx(stringsPath_English, stringsPath, "*.txt"); Log.WriteLine(ConsoleColor.Green, $"======== Completed Processing Language: {realName} ( {nativeName} ) ========"); Log.WriteLine(); } } #endregion #region Process Standard Mode else if (generateOption == "Standard") { Log.WriteLine(ConsoleColor.Green, "======== Start Processing Core Defs and Original Language Data ========"); string core_defsPath = Path.Combine(corePath, "Defs"); string core_langPath = Path.Combine(corePath, "Languages"); string core_keyedPath_English = Path.Combine(core_langPath, "English", "Keyed"); DefinitionData Core_Defs = DefinitionData.Load(core_defsPath); Capture capture = Capture.Parse(Core_Defs); capture.ProcessFieldNames(Core_Defs); InjectionData Core_DefInjected_Original = InjectionData.Parse("Original", Core_Defs); KeyedData Core_Keyed_English = KeyedData.Load("English", core_keyedPath_English); Log.WriteLine(ConsoleColor.Green, "======== Completed Processing Core Defs and Original Language Data ========"); Log.WriteLine(); Log.WriteLine(ConsoleColor.Green, "======== Start Processing Mod Defs and Original Language Data ========"); string defsPath = Path.Combine(modPath, "Defs"); string keyedPath_English = Path.Combine(modPath, "Languages", "English", "Keyed"); string stringsPath_English = Path.Combine(modPath, "Languages", "English", "Strings"); DefinitionData Defs = DefinitionData.Load(defsPath, Core_Defs); capture.ProcessFieldNames(Defs); InjectionData DefInjected_Original = InjectionData.Parse("Original", Defs); KeyedData Keyed_English = KeyedData.Load("English", keyedPath_English); Log.WriteLine(ConsoleColor.Green, "======== Completed Processing Mod Defs and Original Language Data ========"); Log.WriteLine(); XElement Languages = root.Element("Languages"); foreach (XElement li in Languages.Elements()) { // If IsChecked if (string.Compare(li.Element("IsChecked").Value, "false", true) == 0) { continue; } string realName = li.Element("RealName").Value; string nativeName = li.Element("NativeName").Value; // Check Language Real Name if (string.IsNullOrWhiteSpace(realName)) { Log.Error(); Log.WriteLine(ConsoleColor.Red, "Missing Language Name."); continue; } Log.WriteLine(ConsoleColor.Green, $"======== Start Processing Language: {realName} ( {nativeName} ) ========"); string langPath = Path.Combine(modPath, "Languages", realName); bool isCustom = (string.Compare(li.Element("IsCustom").Value, "true", true) == 0); if (isCustom) { langPath = li.Element("CustomPath").Value; Log.WriteLine(ConsoleColor.Cyan, "Use Custom Language Output Directory: "); } else { Log.WriteLine(ConsoleColor.Cyan, "Language Path: "); } Log.Indent(); Log.WriteLine(ConsoleColor.Cyan, langPath); // Check Custom Path if (string.IsNullOrWhiteSpace(langPath)) { Log.Error(); Log.WriteLine(ConsoleColor.Red, "Invalid Custom Output Directory Path."); continue; } string core_defInjectedPath = Path.Combine(core_langPath, realName, "DefInjected"); string core_keyedPath = Path.Combine(core_langPath, realName, "Keyed"); InjectionData Core_DefInjected_New = new InjectionData(realName, Core_DefInjected_Original); InjectionData Core_DefInjected_Existed = InjectionData.Load(realName, core_defInjectedPath); Core_DefInjected_New.MatchExisted(Core_DefInjected_Existed); KeyedData Core_Keyed_New = new KeyedData(realName, Core_Keyed_English); KeyedData Core_Keyed_Existed = KeyedData.Load(realName, core_keyedPath); Core_Keyed_New.MatchExisted(Core_Keyed_Existed); string defInjectedPath = Path.Combine(langPath, "DefInjected"); string keyedPath = Path.Combine(langPath, "Keyed"); string stringsPath = Path.Combine(langPath, "Strings"); InjectionData DefInjected_New = new InjectionData(realName, DefInjected_Original); DefInjected_New.MatchCore(Core_DefInjected_New); KeyedData Keyed_New = new KeyedData(realName, Keyed_English); Keyed_New.MatchCore(Core_Keyed_New); if (cleanModeOn) { DirectoryHelper.CleanDirectory(defInjectedPath, "*.xml"); DirectoryHelper.CleanDirectory(keyedPath, "*.xml"); DirectoryHelper.CleanDirectory(stringsPath, "*.txt"); } else { InjectionData DefInjected_Existed = InjectionData.Load(realName, defInjectedPath, true); DefInjected_New.MatchExisted(DefInjected_Existed); KeyedData Keyed_Existed = KeyedData.Load(realName, keyedPath, true); Keyed_New.MatchExisted(Keyed_Existed); } DefInjected_New.Save(defInjectedPath); Keyed_New.Save(keyedPath); DirectoryHelper.CopyDirectoryEx(stringsPath_English, stringsPath, "*.txt"); Log.WriteLine(ConsoleColor.Green, $"======== Completed Processing Language: {realName} ( {nativeName} ) ========"); Log.WriteLine(); } } #endregion #region Special Mode else if (generateOption == "Special") { Log.WriteLine(ConsoleColor.Green, "======== Start Processing Core Defs and Original Language Data ========"); string core_defsPath = Path.Combine(corePath, "Defs"); string core_langPath = Path.Combine(corePath, "Languages"); string core_keyedPath_English = Path.Combine(core_langPath, "English", "Keyed"); DefinitionData Core_Defs = DefinitionData.Load(core_defsPath); Capture capture = Capture.Parse(Core_Defs); capture.ProcessFieldNames(Core_Defs); //InjectionData Core_DefInjected_Original = InjectionData.Parse(Core_Defs); //KeyedData Core_Keyed_English = KeyedData.Load(core_keyedPath_English); Log.WriteLine(ConsoleColor.Green, "======== Completed Processing Core Defs ========"); Log.WriteLine(); Log.WriteLine(ConsoleColor.Green, "======== Start Processing Mod Defs and Original Language Data ========"); string defsPath = Path.Combine(modPath, "Defs"); string keyedPath_English = Path.Combine(modPath, "Languages", "English", "Keyed"); string stringsPath_English = Path.Combine(modPath, "Languages", "English", "Strings"); DefinitionData Defs = DefinitionData.Load(defsPath, Core_Defs); capture.ProcessFieldNames(Defs); InjectionData DefInjected_Original = InjectionData.Parse("Original", Defs); KeyedData Keyed_English = KeyedData.Load("English", keyedPath_English); Log.WriteLine(ConsoleColor.Green, "======== Completed Processing Mod Defs and Original Language Data ========"); Log.WriteLine(); XElement Languages = root.Element("Languages"); foreach (XElement li in Languages.Elements()) { // If IsChecked if (string.Compare(li.Element("IsChecked").Value, "false", true) == 0) { continue; } string realName = li.Element("RealName").Value; string nativeName = li.Element("NativeName").Value; // Check Language Real Name if (string.IsNullOrWhiteSpace(realName)) { Log.Error(); Log.WriteLine(ConsoleColor.Red, "Missing Language Name."); continue; } Log.WriteLine(ConsoleColor.Green, $"======== Start Processing Language: {realName} ( {nativeName} ) ========"); string langPath = Path.Combine(modPath, "Languages", realName); bool isCustom = (string.Compare(li.Element("IsCustom").Value, "true", true) == 0); if (isCustom) { langPath = li.Element("CustomPath").Value; Log.WriteLine(ConsoleColor.Cyan, "Use Custom Language Output Directory: "); } else { Log.WriteLine(ConsoleColor.Cyan, "Language Path: "); } Log.Indent(); Log.WriteLine(ConsoleColor.Cyan, langPath); // Check Custom Path if (string.IsNullOrWhiteSpace(langPath)) { Log.Error(); Log.WriteLine(ConsoleColor.Red, "Invalid Custom Output Directory Path."); continue; } string core_defInjectedPath = Path.Combine(core_langPath, realName, "DefInjected"); string core_keyedPath = Path.Combine(core_langPath, realName, "Keyed"); //InjectionData Core_DefInjected_New = new InjectionData(Core_DefInjected_Original); //InjectionData Core_DefInjected_Existed = InjectionData.Load(core_defInjectedPath); //Core_DefInjected_New.MatchExisted(Core_DefInjected_Existed); //KeyedData Core_Keyed_New = new KeyedData(Core_Keyed_English); //KeyedData Core_Keyed_Existed = KeyedData.Load(core_keyedPath); //Core_Keyed_New.MatchExisted(Core_Keyed_Existed); string defInjectedPath = Path.Combine(langPath, "DefInjected"); string keyedPath = Path.Combine(langPath, "Keyed"); string stringsPath = Path.Combine(langPath, "Strings"); InjectionData DefInjected_New = new InjectionData(realName, DefInjected_Original); //DefInjected_New.MatchCore(Core_DefInjected_New); KeyedData Keyed_New = new KeyedData(realName, Keyed_English); //Keyed_New.MatchCore(Core_Keyed_New); if (cleanModeOn) { DirectoryHelper.CleanDirectory(defInjectedPath, "*.xml"); DirectoryHelper.CleanDirectory(keyedPath, "*.xml"); DirectoryHelper.CleanDirectory(stringsPath, "*.txt"); } else { InjectionData DefInjected_Existed = InjectionData.Load(realName, defInjectedPath, true); DefInjected_New.MatchExisted(DefInjected_Existed); KeyedData Keyed_Existed = KeyedData.Load(realName, keyedPath, true); Keyed_New.MatchExisted(Keyed_Existed); } DefInjected_New.Save(defInjectedPath); Keyed_New.Save(keyedPath); DirectoryHelper.CopyDirectoryEx(stringsPath_English, stringsPath, "*.txt"); Log.WriteLine(ConsoleColor.Green, $"======== Completed Processing Language: {realName} ( {nativeName} ) ========"); Log.WriteLine(); } } #endregion // End Log.WriteLine(ConsoleColor.Green, $"======== Completed Project {FaceGood()}========"); Log.WriteLine(); Console.Write("Press any key to exit..."); Console.ReadKey(); return; }
/// <summary> /// Create wiki data from definition data and template capture. /// </summary> /// <param name="coreDefinitionData"></param> /// <param name="template"></param> /// <returns></returns> public static WikiData Parse(DefinitionData coreDefinitionData, Capture template, params InjectionData[] injectionDatas) { if (!coreDefinitionData.IsProcessedFieldNames) { throw new ArgumentException("Non-processed definition data.", "definitionData"); } if (!template.IsTemplate) { throw new ArgumentException("Used non-template capture", "template"); } Log.Info(); Log.Write("Start parsing Core Defs and Template Capture to generating "); Log.Write(ConsoleColor.Cyan, "Wiki Data"); Log.WriteLine("."); WikiData wikiData = new WikiData(); int countSetDicts = 0; coreDefinitionData = new DefinitionData(coreDefinitionData); Dictionary <string, List <XElement> > unnamedDefsDict = new Dictionary <string, List <XElement> >(); foreach (XElement curDefElement in from doc in coreDefinitionData.Data.Values from ele in doc.Root.Elements() where ele.Attribute("Abstract") == null select ele) { string curDefType = curDefElement.Name.ToString(); XElement defName = curDefElement.Element("defName"); string curPageName; if (defName == null) { int count_curUnnamedDefs; List <XElement> curUnnamedDefsList; if (unnamedDefsDict.TryGetValue(curDefType, out curUnnamedDefsList)) { count_curUnnamedDefs = curUnnamedDefsList.Count; curUnnamedDefsList.Add(curDefElement); } else { count_curUnnamedDefs = 0; curUnnamedDefsList = new List <XElement>(); curUnnamedDefsList.Add(curDefElement); unnamedDefsDict.Add(curDefType, curUnnamedDefsList); } curPageName = $"Defs_{curDefType}_UnnamedDef_{count_curUnnamedDefs}"; } else { curPageName = $"Defs_{curDefType}_{defName.Value}"; } Inject(curDefElement, injectionDatas); DefInfo curDefInfo = template.Def(curDefElement); if (curDefInfo == null) { Log.Warning(); Log.WriteLine($"'{curPageName}' no matched DefInfo."); continue; } if (!curDefInfo.IsValid) { Log.Warning(); Log.WriteLine($"'{curPageName}' matched invalid DefInfo."); continue; } SetDict curSetDict = new SetDict(curDefElement, curDefInfo); SortedDictionary <string, SetDict> curSubDict; if (wikiData.allSetDict.TryGetValue(curDefType, out curSubDict)) { if (curSubDict.ContainsKey(curPageName)) { Log.Warning(); Log.WriteLine($"Duplicated SetDict '{curPageName}'."); curSubDict[curPageName] = curSetDict; } else { curSubDict.Add(curPageName, curSetDict); } } else { curSubDict = new SortedDictionary <string, SetDict>(); curSubDict.Add(curPageName, curSetDict); wikiData.allSetDict.Add(curDefType, curSubDict); } countSetDicts++; } Log.Info(); Log.WriteLine($"Complete generating wiki data: {wikiData.allSetDict.Count} DefTypes, {countSetDicts} SetDicts."); return(wikiData); }
/// <summary> /// Create capture from Core definition data. /// </summary> /// <param name="coreDefinitionData"></param> /// <param name="sourceCodePath">The path of source code folder.</param> /// <param name="isTemplate">If true, distinguish ThingDef category.</param> /// <returns></returns> public static Capture Parse(DefinitionData coreDefinitionData, string sourceCodePath = null, bool isTemplate = false) { Helper.sourceCodePath = sourceCodePath; Capture capture = new Capture(isTemplate); Log.Info(); Log.Write("Start parsing Core Defs and generating "); if (isTemplate) { Log.Write(ConsoleColor.Cyan, "Templates"); } else { Log.Write(ConsoleColor.Cyan, "Capture"); } Log.WriteLine("."); SortedDictionary <string, XElement> allUniqueDefElements = new SortedDictionary <string, XElement>(); foreach (XDocument doc in coreDefinitionData.Data.Values) { foreach (XElement current in doc.Root.Elements()) { XAttribute isAbstract = current.Attribute("Abstract"); if (isAbstract != null && string.Compare(isAbstract.Value, "True", true) == 0) { continue; } string key = current.Name.ToString(); if (isTemplate && key == DefTypeNameOf.ThingDef) { XElement thingClass = current.Field(FieldNameOf.category); if (thingClass == null) { key = $"{key}_None"; } else { key = $"{key}_{thingClass.Value}"; } } XElement def; if (allUniqueDefElements.TryGetValue(key, out def)) { Helper.MergeElement(def, current); } else { allUniqueDefElements.Add(key, new XElement(current)); continue; } } } foreach (XElement curDef in allUniqueDefElements.Values) { Helper.MergeListItems(curDef); } foreach (XElement curDef in allUniqueDefElements.Values) { curDef.RemoveAttributes(); string key = curDef.Name.ToString(); if (isTemplate && key == DefTypeNameOf.ThingDef) { XElement category = curDef.Field(FieldNameOf.category); if (category != null) { key = $"{key}_{category.Value}"; } } capture.allDefInfo.Add(key, new DefInfo(curDef)); } Log.Info(); if (isTemplate) { Log.WriteLine($"Completed generating Templates: {capture.allDefInfo.Count} templates."); } else { Log.WriteLine($"Completed generating Capture: {capture.allDefInfo.Count} Def types."); } return(capture); }
private void _addAttributeViewList(string name, DefinitionData data) { _addAttributeViewList(new KeyValuePair <string, DefinitionData>(name, data)); }