/// <summary> /// Parse a set of color sources, using fields on this module (if available) or globally /// configured values (if not). /// </summary> /// <returns></returns> private Dictionary <string, IColorSource> ParseColorSources() { Dictionary <string, IColorSource> sources = new Dictionary <string, IColorSource>(); if (!string.IsNullOrEmpty(pilotColor)) { sources.Add(Kerbals.PilotClass, ColorSources.Find(this, pilotColor)); } if (!string.IsNullOrEmpty(engineerColor)) { sources.Add(Kerbals.EngineerClass, ColorSources.Find(this, engineerColor)); } if (!string.IsNullOrEmpty(scientistColor)) { sources.Add(Kerbals.ScientistClass, ColorSources.Find(this, scientistColor)); } if (!string.IsNullOrEmpty(touristColor)) { sources.Add(Kerbals.TouristClass, ColorSources.Find(this, touristColor)); } if (!string.IsNullOrEmpty(otherColor)) { sources.Add(KERBAL_CLASS_UNKNOWN, ColorSources.Find(this, otherColor)); } foreach (KeyValuePair <string, string> pair in _kerbalClassColorDefaults) { if (sources.ContainsKey(pair.Key)) { continue; } sources.Add(pair.Key, ColorSources.Find(this, pair.Value)); } return(sources); }
/// <summary> /// This gets called once at game load time, from the Loader class in this mod. We load our kerbal /// colors from this. It's assumed that it has one key for each kerbal class, whose value is the /// default ColorSource value to use for that class. If there's a kerbal class that doesn't have /// a corresponding entry here, then it will get displayed with the "Unknown" color. /// </summary> /// <param name="config"></param> public static void LoadConfig(ConfigNode config) { // Read in all the configs. _kerbalClassColorDefaults = new Dictionary <string, string>(); for (int i = 0; i < config.values.Count; ++i) { ConfigNode.Value entry = config.values[i]; if (Kerbals.Classes.Contains(entry.name) || KERBAL_CLASS_UNKNOWN.Equals(entry.name)) { if (string.IsNullOrEmpty(entry.value)) { Logging.Warn(config.name + " config: No value specified for class " + entry.name + ", skipping"); continue; } try { ColorSources.Validate(entry.value); } catch (ArgumentException e) { Logging.Warn(config.name + " config: Invalid value '" + entry.value + "' for class " + entry.name + ", skipping. " + e.Message); continue; } Logging.Log(config.name + " config: " + entry.name + " = " + entry.value); _kerbalClassColorDefaults.Add(entry.name, entry.value); } else { Logging.Warn(config.name + " config: No such class '" + entry.name + "' exists, skipping"); continue; } } }
/// <summary> /// Find the specified color source. /// </summary> /// <param name="sourceID"></param> /// <returns></returns> protected IColorSource FindColorSource(string sourceID) { return(ColorSources.Find(this, sourceID)); }