static TechAdvancingStartupClass() // Initialize the mod { ConfigTabValueSavedAttribute.BuildDefaultValueCache(); ConfigButtonTexture = ContentFinder <Texture2D> .Get("TechAdvancingSettingsLogo", true); HarmonyDetours.Setup(); if (MP.enabled) { MP.RegisterAll(); } }
public override void ExposeData() { if (Current.ProgramState == ProgramState.Entry) { if (Scribe.mode == LoadSaveMode.LoadingVars) { ConfigTabValueSavedAttribute.BuildDefaultValueCache(); LogOutput.WriteLogMessage(Errorlevel.Debug, "Loading default vars"); var dict = new Dictionary <string, int>(); Scribe_Collections.Look(ref dict, "TA_Expose_Default_Numbers", LookMode.Value, LookMode.Value); //LogOutput.WriteLogMessage(Errorlevel.Debug, $"DefaultDict: {string.Join(";", ConfigTabValueSavedAttribute.attributeDefaultValues.Select(x => $"{x.Key}={x.Value}"))}"); if (dict != null) { //LogOutput.WriteLogMessage(Errorlevel.Debug, $"SavedDict: {string.Join(";", dict.Select(x => $"{x.Key}={x.Value}"))}"); foreach (var kv in dict) { if (ConfigTabValueSavedAttribute.attributeDefaultValues.ContainsKey(kv.Key)) // load existing keys { ConfigTabValueSavedAttribute.attributeDefaultValues[kv.Key] = kv.Value; } else { LogOutput.WriteLogMessage(Errorlevel.Debug, $"Wiped old value with key {kv.Key}"); } } } } else if (Scribe.mode == LoadSaveMode.Saving) { LogOutput.WriteLogMessage(Errorlevel.Debug, "Saving default vars"); var dict = ConfigTabValueSavedAttribute.attributeDefaultValues.ToDictionary(x => x.Key, x => x.Value); Scribe_Collections.Look(ref dict, "TA_Expose_Default_Numbers", LookMode.Value, LookMode.Value); settingsText = null; } } else { this.tempdict = ConfigTabValueSavedAttribute.attributeDefaultValues.ToDictionary(x => x.Key, x => x.Value); Scribe_Collections.Look(ref this.tempdict, "TA_Expose_Default_Numbers", LookMode.Value, LookMode.Value); // because rimworld thinks its a great idea to clear configs otherwise... } base.ExposeData(); }
public void TA_ExposeData(ConfigTabValueSavedAttribute attrib, ref int value, TA_Expose_Mode mode = TA_Expose_Mode.Load) { string saveName = attrib.SaveName; object defaultValue = attrib.DefaultValue; if (mode == TA_Expose_Mode.Save) { LogOutput.WriteLogMessage(Errorlevel.Debug, "Adding " + saveName + " : " + value + " to save dictionary"); if (this.ConfigValues.ContainsKey(saveName)) { this.ConfigValues.Remove(saveName); } this.ConfigValues.Add(saveName, value); } else if (mode == TA_Expose_Mode.Load) { if (this.ConfigValues.TryGetValue(saveName, out int tempval)) { value = tempval; } else if (this.ConfigValues.TryGetValue(Enum.GetNames(typeof(TA_Expose_Name)).Contains(saveName) ? ((int)Enum.Parse(typeof(TA_Expose_Name), saveName)).ToString() : saveName, out tempval)) // TODO remove backwards compatability fallback { value = tempval; LogOutput.WriteLogMessage(Errorlevel.Information, "Value " + saveName + " was loaded via fallback. (A new save system is in place. But this message shouldnt appear anymore after saving)"); } else { LogOutput.WriteLogMessage(Errorlevel.Information, "Value " + saveName + " is not present. Using default value."); if (defaultValue == null) { LogOutput.WriteLogMessage(Errorlevel.Error, $"Default value of {saveName} is null!"); } else { value = (int)defaultValue; } } LogOutput.WriteLogMessage(Errorlevel.Debug, "Successfully loaded " + saveName + " : " + value + " from save dictionary."); } }