Add ModuleManagerMapper for dynamic module management
This commit is contained in:
@@ -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;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user