Skip to content

Commit 0cc450e

Browse files
committed
Code cleanup
- Removed harmony patch for ModuleAutoCutDrogue from the module's cs file and moved it to its own harmony patches folder
1 parent 6a21846 commit 0cc450e

File tree

3 files changed

+41
-36
lines changed

3 files changed

+41
-36
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using HarmonyLib;
2+
using System;
3+
4+
namespace KSPCommunityPartModules.HarmonyPatches
5+
{
6+
[HarmonyPatch(typeof(ModuleParachute))]
7+
public class ModuleParachuteEvents
8+
{
9+
public static void ModuleManagerPostLoad()
10+
{
11+
Harmony harmony = new Harmony("KSPCommunityPartModules.ModuleParachutePatch");
12+
harmony.PatchAll();
13+
}
14+
15+
public static event Action<ModuleParachute> OnDeployed;
16+
public static event Action<ModuleParachute> OnRepacked;
17+
18+
[HarmonyPostfix]
19+
[HarmonyPatch("OnParachuteSemiDeployed")]
20+
static void RaiseEventOnSemiDeployed(ModuleParachute __instance)
21+
{
22+
OnDeployed?.Invoke(__instance);
23+
}
24+
25+
[HarmonyPostfix]
26+
[HarmonyPatch("OnParachuteFullyDeployed")]
27+
static void RaiseEventOnFullyDeployed(ModuleParachute __instance)
28+
{
29+
OnDeployed?.Invoke(__instance);
30+
}
31+
32+
[HarmonyPostfix]
33+
[HarmonyPatch("Repack")]
34+
static void RaiseEventOnRepack(ModuleParachute __instance)
35+
{
36+
OnRepacked?.Invoke(__instance);
37+
}
38+
}
39+
}

Source/KSPCommunityPartModules.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<PackageReference Include="KSPBuildTools" Version="0.0.2-alpha.7" />
3535
</ItemGroup>
3636
<ItemGroup>
37+
<Compile Include="HarmonyPatches\ModuleParachutePatch.cs" />
3738
<Compile Include="Modules\ModuleAutoCutDrogue.cs" />
3839
<Compile Include="Modules\ModuleCoPFollowTransform.cs" />
3940
<Compile Include="Properties\AssemblyInfo.cs" />

Source/Modules/ModuleAutoCutDrogue.cs

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
Originally By: Jsolson
55
Originally For: Bluedog Design Bureau
66
*/
7-
using HarmonyLib;
8-
using System;
97
using System.Linq;
108
using UnityEngine;
9+
using KSPCommunityPartModules.HarmonyPatches;
1110

1211
namespace KSPCommunityPartModules.Modules
1312
{
@@ -71,38 +70,4 @@ private void OnParachuteRepacked(ModuleParachute pChute)
7170
if (triggered && pChute == chute) triggered = false;
7271
}
7372
}
74-
75-
[HarmonyPatch(typeof(ModuleParachute))]
76-
internal class ModuleParachuteEvents
77-
{
78-
public static void ModuleManagerPostLoad()
79-
{
80-
Harmony harmony = new Harmony("KSPCommunityPartModules");
81-
harmony.PatchAll();
82-
}
83-
84-
public static event Action<ModuleParachute> OnDeployed;
85-
public static event Action<ModuleParachute> OnRepacked;
86-
87-
[HarmonyPostfix]
88-
[HarmonyPatch("OnParachuteSemiDeployed")]
89-
static void RaiseEventOnSemiDeployed(ModuleParachute __instance)
90-
{
91-
OnDeployed?.Invoke(__instance);
92-
}
93-
94-
[HarmonyPostfix]
95-
[HarmonyPatch("OnParachuteFullyDeployed")]
96-
static void RaiseEventOnFullyDeployed(ModuleParachute __instance)
97-
{
98-
OnDeployed?.Invoke(__instance);
99-
}
100-
101-
[HarmonyPostfix]
102-
[HarmonyPatch("Repack")]
103-
static void RaiseEventOnRepack(ModuleParachute __instance)
104-
{
105-
OnRepacked?.Invoke(__instance);
106-
}
107-
}
10873
}

0 commit comments

Comments
 (0)