Skip to content

Commit

Permalink
Add a toggleable control range module
Browse files Browse the repository at this point in the history
  • Loading branch information
cheese3660 committed Jan 4, 2024
1 parent 291820b commit d848fe6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/WMCCModules/Patches/PartComponentModule_CommandPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ namespace WMCCModules.Patches;
public class PartComponentModule_CommandPatch
{
[HarmonyPatch(nameof(PartComponentModule_Command.UpdateControlStatus))]
[HarmonyPrefix]
public static bool UpdateControlStatus(PartComponentModule_Command __instance)
[HarmonyPostfix]
public static void UpdateControlStatus(PartComponentModule_Command __instance)
{
if (!__instance.Part.Modules.TryGetValue(typeof(PartComponentModule_ControlRange), out var comp)) return true;
if (!WMCCModulesPlugin.Instance.EnableControlRange.Value) return;
if (!__instance.Part.Modules.TryGetValue(typeof(PartComponentModule_ControlRange), out var comp)) return;
var mcr = comp as PartComponentModule_ControlRange;
if (mcr!.DataControlRange == null || mcr.DataControlRange.Controllable) return true;
__instance.dataCommand.controlStatus.SetValue(CommandControlState.NoCommNetConnection);
return false;
if (mcr!.DataControlRange == null || mcr.DataControlRange.Controllable) return;
if (__instance.dataCommand.controlStatus.GetValue() == CommandControlState.FullyFunctional)
__instance.dataCommand.controlStatus.SetValue(CommandControlState.Hibernating);
}
}
8 changes: 8 additions & 0 deletions src/WMCCModules/WMCCModulesPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using JetBrains.Annotations;
using SpaceWarp;
using SpaceWarp.API.Configuration;
using SpaceWarp.API.Mods;
using WMCCModules.Patches;

Expand All @@ -18,6 +20,12 @@ public class WMCCModulesPlugin : BaseSpaceWarpPlugin

// Singleton instance of the plugin class
[PublicAPI] public static WMCCModulesPlugin Instance { get; set; }
public ConfigValue<bool> EnableControlRange;
private void Start()
{
EnableControlRange = new ConfigValue<bool>(SWConfiguration.Bind("Module Settings", "Enable Control Range", true,
"Enable the control range module (what forces you to lose control in certain situations until you unlock a certain tech node)"));
}

/// <summary>
/// Runs when the mod is first initialized.
Expand Down

0 comments on commit d848fe6

Please sign in to comment.