Add ModuleEnergyStoreManager for configurable energy store capacity
This commit is contained in:
43
Projects/TerraTech/TerraTech/ModuleEnergyStoreManager.cs
Normal file
43
Projects/TerraTech/TerraTech/ModuleEnergyStoreManager.cs
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
using System;
|
||||||
|
using BepInEx.Configuration;
|
||||||
|
using HarmonyLib;
|
||||||
|
|
||||||
|
namespace TerraTech {
|
||||||
|
[HarmonyPatch]
|
||||||
|
public class ModuleEnergyStoreManager {
|
||||||
|
private static readonly MultipliedObjectManager<ModuleEnergyStore> manager =
|
||||||
|
new MultipliedObjectManager<ModuleEnergyStore>(ConfigureModuleEnergyStore);
|
||||||
|
|
||||||
|
public static ConfigEntry<float> capacityMultiplier;
|
||||||
|
|
||||||
|
public static void Setup(ConfigFile config) {
|
||||||
|
float min = 0.01f;
|
||||||
|
float max = 32f;
|
||||||
|
|
||||||
|
capacityMultiplier =
|
||||||
|
config.Bind("Energy", "Capacity Multiplier", 1f,
|
||||||
|
new ConfigDescription("Capacity Multiplier", new AcceptableValueRange<float>(min, max)));
|
||||||
|
capacityMultiplier.SettingChanged += (sender, args) => DoPatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ConfigureModuleEnergyStore(MultipliedObject<ModuleEnergyStore> obj) {
|
||||||
|
obj.AddField(new FieldConfiguration<float>("m_Capacity", capacityMultiplier));
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPrefix]
|
||||||
|
[HarmonyPatch(typeof(ModuleEnergyStore), "OnAttached")]
|
||||||
|
static void PostfixCreate(ModuleEnergyStore __instance) {
|
||||||
|
manager.OnObjectAttached(__instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPrefix]
|
||||||
|
[HarmonyPatch(typeof(ModuleEnergyStore), "OnDetaching")]
|
||||||
|
static void PostfixDestroy(ModuleEnergyStore __instance) {
|
||||||
|
manager.OnObjectDetached(__instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void DoPatch() {
|
||||||
|
manager.ApplyAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -47,6 +47,7 @@
|
|||||||
<Compile Include="ModuleBoosterManager.cs" />
|
<Compile Include="ModuleBoosterManager.cs" />
|
||||||
<Compile Include="ModuleWeaponGunManager.cs" />
|
<Compile Include="ModuleWeaponGunManager.cs" />
|
||||||
<Compile Include="ModuleEnergyManager.cs" />
|
<Compile Include="ModuleEnergyManager.cs" />
|
||||||
|
<Compile Include="ModuleEnergyStoreManager.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="0Harmony">
|
<Reference Include="0Harmony">
|
||||||
|
Reference in New Issue
Block a user