Add ModuleEnergyManager for configurable energy module settings
This commit is contained in:
@@ -68,7 +68,7 @@ namespace TerraTech {
|
||||
ModuleBoosterManager.Setup(Config);
|
||||
ModuleShieldGeneratorManager.Setup(Config);
|
||||
ModuleWeaponGunManager.Setup(Config);
|
||||
|
||||
ModuleEnergyManager.Setup(Config);
|
||||
xpMultiplier =
|
||||
Config.Bind("General", "XP Multiplier", 1f,
|
||||
new ConfigDescription("XP Multiplier", new AcceptableValueRange<float>(min, max)));
|
||||
|
50
Projects/TerraTech/TerraTech/ModuleEnergyManager.cs
Normal file
50
Projects/TerraTech/TerraTech/ModuleEnergyManager.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using BepInEx.Configuration;
|
||||
using HarmonyLib;
|
||||
|
||||
namespace TerraTech {
|
||||
[HarmonyPatch]
|
||||
public class ModuleEnergyManager {
|
||||
private static readonly MultipliedObjectManager<ModuleEnergy> manager =
|
||||
new MultipliedObjectManager<ModuleEnergy>(ConfigureModuleEnergy);
|
||||
|
||||
public static ConfigEntry<float> outputMultiplier;
|
||||
public static ConfigEntry<float> powerUpDelayMultiplier;
|
||||
|
||||
public static void Setup(ConfigFile config) {
|
||||
float min = 0.01f;
|
||||
float max = 32f;
|
||||
|
||||
outputMultiplier =
|
||||
config.Bind("Energy", "Output Multiplier", 1f,
|
||||
new ConfigDescription("Output Multiplier", new AcceptableValueRange<float>(min, max)));
|
||||
outputMultiplier.SettingChanged += (sender, args) => DoPatch();
|
||||
|
||||
powerUpDelayMultiplier = config.Bind(
|
||||
"Energy", "Power Up Delay Multiplier", 1f,
|
||||
new ConfigDescription("Power Up Delay Multiplier", new AcceptableValueRange<float>(min, max)));
|
||||
powerUpDelayMultiplier.SettingChanged += (sender, args) => DoPatch();
|
||||
}
|
||||
|
||||
private static void ConfigureModuleEnergy(MultipliedObject<ModuleEnergy> obj) {
|
||||
obj.AddField(new FieldConfiguration<float>("m_OutputPerSecond", outputMultiplier));
|
||||
obj.AddField(new FieldConfiguration<float>("m_PowerUpDelay", powerUpDelayMultiplier));
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(ModuleEnergy), "OnAttached")]
|
||||
static void PostfixCreate(ModuleEnergy __instance) {
|
||||
manager.OnObjectAttached(__instance);
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(ModuleEnergy), "OnDetaching")]
|
||||
static void PostfixDestroy(ModuleEnergy __instance) {
|
||||
manager.OnObjectDetached(__instance);
|
||||
}
|
||||
|
||||
public static void DoPatch() {
|
||||
manager.ApplyAll();
|
||||
}
|
||||
}
|
||||
}
|
@@ -46,6 +46,7 @@
|
||||
<Compile Include="ModuleWingManager.cs" />
|
||||
<Compile Include="ModuleBoosterManager.cs" />
|
||||
<Compile Include="ModuleWeaponGunManager.cs" />
|
||||
<Compile Include="ModuleEnergyManager.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="0Harmony">
|
||||
|
Reference in New Issue
Block a user