Add player-only configuration to module managers
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using BepInEx.Configuration;
|
||||
using HarmonyLib;
|
||||
|
||||
@@ -7,12 +8,16 @@ namespace TerraTech {
|
||||
private static readonly MultipliedObjectManager<ModuleWeapon> manager =
|
||||
new MultipliedObjectManager<ModuleWeapon>(ConfigureManager);
|
||||
|
||||
public static ConfigEntry<bool> playerOnly;
|
||||
public static ConfigEntry<float> rotateSpeedMultiplier;
|
||||
|
||||
public static void Setup(ConfigFile config) {
|
||||
float min = 0.01f;
|
||||
float max = 32f;
|
||||
|
||||
playerOnly = config.Bind("ModuleWeapon", "Player Only", false, new ConfigDescription("Player Only"));
|
||||
playerOnly.SettingChanged += (sender, args) => DoPatch();
|
||||
|
||||
rotateSpeedMultiplier = config.Bind(
|
||||
"ModuleWeapon", "Rotate Speed Multiplier", 1f,
|
||||
new ConfigDescription("Rotate Speed Multiplier", new AcceptableValueRange<float>(min, max)));
|
||||
@@ -20,9 +25,15 @@ namespace TerraTech {
|
||||
}
|
||||
|
||||
private static void ConfigureManager(MultipliedObject<ModuleWeapon> obj) {
|
||||
obj.AddField(new FieldConfiguration<float, float>("m_RotateSpeed", rotateSpeedMultiplier));
|
||||
obj.AddField(new FieldConfiguration<float, float>("m_RotateSpeed", rotateSpeedMultiplier, ShouldApply));
|
||||
}
|
||||
|
||||
private static readonly Func<object, bool> ShouldApply = obj => {
|
||||
if (!playerOnly.Value)
|
||||
return true;
|
||||
return CykUtil.IsPlayerTank(obj as Module);
|
||||
};
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(ModuleWeapon), "OnAttached")]
|
||||
static void PostfixCreate(ModuleWeapon __instance) {
|
||||
|
Reference in New Issue
Block a user