Add ModuleWheelsManager for configurable wheel torque settings
This commit is contained in:
@@ -37,6 +37,7 @@ namespace TerraTech {
|
|||||||
ModuleItemHolderManager.Setup(Config);
|
ModuleItemHolderManager.Setup(Config);
|
||||||
ModuleItemProducerManager.Setup(Config);
|
ModuleItemProducerManager.Setup(Config);
|
||||||
ModuleRemoteChargerManager.Setup(Config);
|
ModuleRemoteChargerManager.Setup(Config);
|
||||||
|
ModuleWheelsManager.Setup(Config);
|
||||||
|
|
||||||
xpMultiplier =
|
xpMultiplier =
|
||||||
Config.Bind("General", "XP Multiplier", 1f,
|
Config.Bind("General", "XP Multiplier", 1f,
|
||||||
|
54
Projects/TerraTech/TerraTech/ModuleWheelsManager.cs
Normal file
54
Projects/TerraTech/TerraTech/ModuleWheelsManager.cs
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
using System;
|
||||||
|
using BepInEx.Configuration;
|
||||||
|
using HarmonyLib;
|
||||||
|
|
||||||
|
namespace TerraTech {
|
||||||
|
[HarmonyPatch]
|
||||||
|
public class ModuleWheelsManager {
|
||||||
|
private static readonly MultipliedObjectManager<ManWheels.TorqueParams> torqueParamsManager =
|
||||||
|
new MultipliedObjectManager<ManWheels.TorqueParams>(ConfigureTorqueParams);
|
||||||
|
|
||||||
|
public static ConfigEntry<float> torqueRpmMultiplier;
|
||||||
|
public static ConfigEntry<float> torqueMultiplier;
|
||||||
|
|
||||||
|
public static void Setup(ConfigFile config) {
|
||||||
|
float min = 0.01f;
|
||||||
|
float max = 32f;
|
||||||
|
|
||||||
|
torqueRpmMultiplier =
|
||||||
|
config.Bind("TorqueParams", "Torque RPM Multiplier", 1f,
|
||||||
|
new ConfigDescription("Torque RPM Multiplier", new AcceptableValueRange<float>(min, max)));
|
||||||
|
torqueRpmMultiplier.SettingChanged += (sender, args) => DoPatch();
|
||||||
|
|
||||||
|
torqueMultiplier =
|
||||||
|
config.Bind("TorqueParams", "Torque Multiplier", 1f,
|
||||||
|
new ConfigDescription("Torque Multiplier", new AcceptableValueRange<float>(min, max)));
|
||||||
|
torqueMultiplier.SettingChanged += (sender, args) => DoPatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ConfigureTorqueParams(MultipliedObject<ManWheels.TorqueParams> obj) {
|
||||||
|
obj.AddField(new FieldConfiguration<float, float>("torqueCurveMaxRpm", torqueRpmMultiplier));
|
||||||
|
obj.AddField(new FieldConfiguration<float, float>("torqueCurveMaxTorque", torqueMultiplier));
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPrefix]
|
||||||
|
[HarmonyPatch(typeof(ModuleWheels), "OnAttached")]
|
||||||
|
static void PostfixCreate(ModuleWheels __instance) {
|
||||||
|
var trav = Traverse.Create(__instance);
|
||||||
|
var torqueParams = trav.Field("torqueParams");
|
||||||
|
torqueParamsManager.OnObjectAttached(torqueParams.GetValue<ManWheels.TorqueParams>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPrefix]
|
||||||
|
[HarmonyPatch(typeof(ModuleWheels), "OnDetaching")]
|
||||||
|
static void PostfixDestroy(ModuleWheels __instance) {
|
||||||
|
var trav = Traverse.Create(__instance);
|
||||||
|
var torqueParams = trav.Field("torqueParams");
|
||||||
|
torqueParamsManager.OnObjectDetached(torqueParams.GetValue<ManWheels.TorqueParams>());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void DoPatch() {
|
||||||
|
torqueParamsManager.ApplyAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -323,8 +323,7 @@ namespace TerraTech {
|
|||||||
/// Manages a collection of objects whose fields can be multiplied
|
/// Manages a collection of objects whose fields can be multiplied
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T">The type of objects being managed</typeparam>
|
/// <typeparam name="T">The type of objects being managed</typeparam>
|
||||||
public class MultipliedObjectManager<T>
|
public class MultipliedObjectManager<T> {
|
||||||
where T : class {
|
|
||||||
private readonly Dictionary<T, MultipliedObject<T>> _managedObjects;
|
private readonly Dictionary<T, MultipliedObject<T>> _managedObjects;
|
||||||
private readonly Action<MultipliedObject<T>> _configureObject;
|
private readonly Action<MultipliedObject<T>> _configureObject;
|
||||||
|
|
||||||
|
@@ -52,6 +52,7 @@
|
|||||||
<Compile Include="ModuleItemHolderManager.cs" />
|
<Compile Include="ModuleItemHolderManager.cs" />
|
||||||
<Compile Include="ModuleItemProducerManager.cs" />
|
<Compile Include="ModuleItemProducerManager.cs" />
|
||||||
<Compile Include="ModuleRemoteChargerManager.cs" />
|
<Compile Include="ModuleRemoteChargerManager.cs" />
|
||||||
|
<Compile Include="ModuleWheelsManager.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="0Harmony">
|
<Reference Include="0Harmony">
|
||||||
|
Reference in New Issue
Block a user