Add ModuleGyroManager for configurable gyro active speed
This commit is contained in:
@@ -33,6 +33,7 @@ namespace TerraTech {
|
||||
ModuleWeaponGunManager.Setup(Config);
|
||||
ModuleEnergyManager.Setup(Config);
|
||||
ModuleEnergyStoreManager.Setup(Config);
|
||||
ModuleGyroManager.Setup(Config);
|
||||
|
||||
xpMultiplier =
|
||||
Config.Bind("General", "XP Multiplier", 1f,
|
||||
|
43
Projects/TerraTech/TerraTech/ModuleGyroManager.cs
Normal file
43
Projects/TerraTech/TerraTech/ModuleGyroManager.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using BepInEx.Configuration;
|
||||
using HarmonyLib;
|
||||
|
||||
namespace TerraTech {
|
||||
[HarmonyPatch]
|
||||
public class ModuleGyroManager {
|
||||
private static readonly MultipliedObjectManager<ModuleGyro> manager =
|
||||
new MultipliedObjectManager<ModuleGyro>(ConfigureModuleGyro);
|
||||
|
||||
public static ConfigEntry<float> activeSpeedMultiplier;
|
||||
|
||||
public static void Setup(ConfigFile config) {
|
||||
float min = 0.01f;
|
||||
float max = 32f;
|
||||
|
||||
activeSpeedMultiplier = config.Bind(
|
||||
"Gyro", "Active Speed Multiplier", 1f,
|
||||
new ConfigDescription("Active Speed Multiplier", new AcceptableValueRange<float>(min, max)));
|
||||
activeSpeedMultiplier.SettingChanged += (sender, args) => DoPatch();
|
||||
}
|
||||
|
||||
private static void ConfigureModuleGyro(MultipliedObject<ModuleGyro> obj) {
|
||||
obj.AddField(new FieldConfiguration<float>("m_ActiveSpeed", activeSpeedMultiplier));
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(ModuleGyro), "OnAttached")]
|
||||
static void PostfixCreate(ModuleGyro __instance) {
|
||||
manager.OnObjectAttached(__instance);
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(ModuleGyro), "OnDetaching")]
|
||||
static void PostfixDestroy(ModuleGyro __instance) {
|
||||
manager.OnObjectDetached(__instance);
|
||||
}
|
||||
|
||||
public static void DoPatch() {
|
||||
manager.ApplyAll();
|
||||
}
|
||||
}
|
||||
}
|
@@ -48,6 +48,7 @@
|
||||
<Compile Include="ModuleWeaponGunManager.cs" />
|
||||
<Compile Include="ModuleEnergyManager.cs" />
|
||||
<Compile Include="ModuleEnergyStoreManager.cs" />
|
||||
<Compile Include="ModuleGyroManager.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="0Harmony">
|
||||
|
Reference in New Issue
Block a user