public void DeserializeByaml(IDictionary <string, object> dictionary) { void PopulateGlickoConstants(string sourceDictKey, Dictionary <VersusRule, GlickoConstants> constantsDict) { // Get the source dictionary Dictionary <string, object> sourceDict = (Dictionary <string, object>)dictionary[sourceDictKey]; // Get the raw constants dictionary for every mode foreach (KeyValuePair <string, object> pair in sourceDict) { // Create a new GlickoConstants instance and populate it GlickoConstants glickoConstants = new GlickoConstants(); glickoConstants.DeserializeByaml((Dictionary <string, object>)pair.Value); // Get the VersusRule enum VersusRule VersusRule = (VersusRule)EnumUtil.GetEnumValueFromString(typeof(VersusRule), pair.Key); // Add this to the target dictionary constantsDict.Add(VersusRule, glickoConstants); } } // Create the dictionaries PairGlickoConstants = new Dictionary <VersusRule, GlickoConstants>(); TeamGlickoConstants = new Dictionary <VersusRule, GlickoConstants>(); // Populate them PopulateGlickoConstants("Pair", PairGlickoConstants); PopulateGlickoConstants("Team", TeamGlickoConstants); }
public void DeserializeByaml(IDictionary <string, object> dictionary) { // Deserialize the VersusRule VersusRule = (VersusRule)EnumUtil.GetEnumValueFromString(typeof(VersusRule), (string)dictionary["Rule"]); // Create the News dictionary News = new Dictionary <string, Dictionary <Language, List <ScriptCommand> > >(); // Get the news list List <object> newsList = (List <object>)dictionary["News"]; // Loop over every news foreach (object obj in newsList) { // Create a new inner dictionary Dictionary <Language, List <ScriptCommand> > innerDict = new Dictionary <Language, List <ScriptCommand> >(); // Get the news dictionary Dictionary <string, object> news = (Dictionary <string, object>)obj; // Loop over every language key foreach (string code in news.Keys) { // Skip NewsType if (code == "NewsType") { continue; } // Create the script list List <ScriptCommand> commandList = ScriptParser.ParseCommandList((List <object>)news[code]); // Get the language code Language language = LanguageExtensions.FromSeadCode(code); // Add this to the inner dictionary innerDict.Add(language, commandList); } // Add the inner dictionary News.Add((string)news["NewsType"], innerDict); } // Load the Glicko constants GlickoConstants = new GlickoConstants(); GlickoConstants.DeserializeByaml((Dictionary <string, object>)dictionary[VersusRule.ToString()]); }