Add ModuleManagerMapper for dynamic module management

This commit is contained in:
2025-02-25 11:56:03 +01:00
parent e4700847df
commit 8fbabf3931
20 changed files with 350 additions and 255 deletions

View File

@@ -5,11 +5,11 @@ using HarmonyLib;
namespace TerraTech {
[HarmonyPatch]
public class ModuleEnergyStoreManager {
private static readonly MultipliedObjectManager<ModuleEnergyStore> manager =
private static readonly MultipliedObjectManager<ModuleEnergyStore> Manager =
new MultipliedObjectManager<ModuleEnergyStore>(ConfigureModuleEnergyStore);
public static ConfigEntry<bool> playerOnly;
public static ConfigEntry<float> capacityMultiplier;
private static ConfigEntry<bool> playerOnly;
private static ConfigEntry<float> capacityMultiplier;
public static void Setup(ConfigFile config) {
float min = 0.01f;
@@ -36,18 +36,25 @@ namespace TerraTech {
[HarmonyPrefix]
[HarmonyPatch(typeof(ModuleEnergyStore), "OnAttached")]
static void PostfixCreate(ModuleEnergyStore __instance) {
manager.OnObjectAttached(__instance);
public static void PostfixCreate(ModuleEnergyStore __instance) {
Manager.OnObjectAttached(__instance);
}
[HarmonyPrefix]
[HarmonyPatch(typeof(ModuleEnergyStore), "OnDetaching")]
static void PostfixDestroy(ModuleEnergyStore __instance) {
manager.OnObjectDetached(__instance);
public static void PostfixDestroy(ModuleEnergyStore __instance) {
Manager.OnObjectDetached(__instance);
}
public static void DoPatch() {
manager.ApplyAll();
private static void DoPatch() {
Manager.ApplyAll();
}
public static readonly Func<Module, bool> Register = obj => {
if (Main.debug.Value)
Console.WriteLine("Registering ModuleEnergyStore: {0}", obj);
PostfixCreate(obj as ModuleEnergyStore);
return true;
};
}
}