Fix improperly loading prod multiplier

This commit is contained in:
2024-09-29 00:05:07 +02:00
parent 2e030b6fe2
commit 34ad8bef4d

View File

@@ -179,30 +179,8 @@ namespace InfectionFreeZone {
productionProfitMultiplier = productionProfitMultiplier =
Config.Bind("General", "Production Profit Multiplier (Resource ID: multiplier)", ""); Config.Bind("General", "Production Profit Multiplier (Resource ID: multiplier)", "");
productionProfitMultiplierDict = new Dictionary<ResourceID, float>(); productionProfitMultiplierDict = new Dictionary<ResourceID, float>();
productionProfitMultiplier.SettingChanged += delegate(object sender, EventArgs e) { productionProfitMultiplier.SettingChanged += delegate { UpdateProductionProfitMultiplierDict(); };
productionProfitMultiplierDict.Clear(); UpdateProductionProfitMultiplierDict();
var str = productionProfitMultiplier.Value;
if (str == "")
return;
var split = str.Split(',');
foreach (var s in split) {
if (Main.productionProfitMultiplierDebug.Value)
Console.WriteLine($"Parsing {s}");
var split2 = s.Split(':');
if (split2.Length != 2)
continue;
var success = Enum.TryParse<ResourceID>(split2[0], out var resourceID);
if (!success) {
Console.WriteLine($"Failed to parse {split2[0]} as a resource ID");
continue;
}
var multiplier = float.Parse(split2[1]);
productionProfitMultiplierDict.Add(resourceID, multiplier);
if (Main.productionProfitMultiplierDebug.Value)
Console.WriteLine($"Added {resourceID} with multiplier {multiplier}");
}
};
towerEchoSelectionDebug = Config.Bind("General", "Tower Echo Selection Debug", false); towerEchoSelectionDebug = Config.Bind("General", "Tower Echo Selection Debug", false);
towerEchoSelection = Config.Bind("General", "Tower Echo Selection", false); towerEchoSelection = Config.Bind("General", "Tower Echo Selection", false);
@@ -218,6 +196,31 @@ namespace InfectionFreeZone {
Logger.LogInfo("Patched " + method.Name); Logger.LogInfo("Patched " + method.Name);
} }
} }
public static void UpdateProductionProfitMultiplierDict() {
Main.productionProfitMultiplierDict.Clear();
var str = productionProfitMultiplier.Value;
if (str == "")
return;
var split = str.Split(',');
foreach (var s in split) {
if (productionProfitMultiplierDebug.Value)
Console.WriteLine($"Parsing {s}");
var split2 = s.Split(':');
if (split2.Length != 2)
continue;
var success = Enum.TryParse<ResourceID>(split2[0], out var resourceID);
if (!success) {
Console.WriteLine($"Failed to parse {split2[0]} as a resource ID");
continue;
}
var multiplier = float.Parse(split2[1]);
productionProfitMultiplierDict.Add(resourceID, multiplier);
if (productionProfitMultiplierDebug.Value)
Console.WriteLine($"Added {resourceID} with multiplier {multiplier}");
}
}
} }
[HarmonyPatch] [HarmonyPatch]