Add player-only configuration to module managers

This commit is contained in:
2025-02-24 15:51:16 +01:00
parent 0b4883ed6c
commit dc7be36bdb
12 changed files with 174 additions and 36 deletions

View File

@@ -1,3 +1,4 @@
using System;
using BepInEx.Configuration;
using HarmonyLib;
@@ -7,12 +8,16 @@ namespace TerraTech {
private static readonly MultipliedObjectManager<ModuleEnergyStore> manager =
new MultipliedObjectManager<ModuleEnergyStore>(ConfigureModuleEnergyStore);
public static ConfigEntry<bool> playerOnly;
public static ConfigEntry<float> capacityMultiplier;
public static void Setup(ConfigFile config) {
float min = 0.01f;
float max = 32f;
playerOnly = config.Bind("Energy", "Player Only", false, new ConfigDescription("Player Only"));
playerOnly.SettingChanged += (sender, args) => DoPatch();
capacityMultiplier =
config.Bind("Energy", "Capacity Multiplier", 1f,
new ConfigDescription("Capacity Multiplier", new AcceptableValueRange<float>(min, max)));
@@ -20,9 +25,15 @@ namespace TerraTech {
}
private static void ConfigureModuleEnergyStore(MultipliedObject<ModuleEnergyStore> obj) {
obj.AddField(new FieldConfiguration<float, float>("m_Capacity", capacityMultiplier));
obj.AddField(new FieldConfiguration<float, float>("m_Capacity", capacityMultiplier, ShouldApply));
}
private static readonly Func<object, bool> ShouldApply = obj => {
if (!playerOnly.Value)
return true;
return CykUtil.IsPlayerTank(obj as Module);
};
[HarmonyPrefix]
[HarmonyPatch(typeof(ModuleEnergyStore), "OnAttached")]
static void PostfixCreate(ModuleEnergyStore __instance) {