Skip to content

Commit aa1e81e

Browse files
Merge pull request #3 from StonesmileGit/MFTSupport
Mft support - Handle ModuleFuelTanks nodes
2 parents 7d7be3d + 9f5088d commit aa1e81e

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

B9PartSwitch/B9PartSwitch.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
44
<PropertyGroup>
@@ -129,6 +129,7 @@
129129
<Compile Include="PartSwitch\MaterialModifierInfo.cs" />
130130
<Compile Include="PartSwitch\PartModifiers\ModuleDataHandlerBasic.cs" />
131131
<Compile Include="PartSwitch\PartModifiers\ModuleDeactivator.cs" />
132+
<Compile Include="PartSwitch\PartModifiers\ModuleFuelTanksHandler.cs" />
132133
<Compile Include="PartSwitch\PartModifiers\ModuleOutputResourceResetter.cs" />
133134
<Compile Include="PartSwitch\PartModifiers\PartAttachNodeModifier.cs" />
134135
<Compile Include="PartSwitch\PartModifiers\PartCenterOfBuoyancyModifier.cs" />

B9PartSwitch/PartSwitch/ModuleModifierInfo.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ public IEnumerable<IPartModifier> CreatePartModifiers(Part part, PartModule pare
139139
yield return new ModuleOutputResourceResetter(module);
140140
yield return new ModuleDataHandlerBasic(module, originalNode, dataNode, moduleDataChangedEventDetails);
141141
}
142+
else if (module.moduleName == "ModuleFuelTanks") {
143+
yield return new ModuleFuelTanksHandler(module, originalNode, dataNode, moduleDataChangedEventDetails);
144+
}
142145
else
143146
yield return new ModuleDataHandlerBasic(module, originalNode, dataNode, moduleDataChangedEventDetails);
144147
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
namespace B9PartSwitch.PartSwitch.PartModifiers
3+
{
4+
public class ModuleFuelTanksHandler : PartModifierBase, IPartAspectLock
5+
{
6+
public const string PART_ASPECT_LOCK = "ModuleFuelTanks";
7+
8+
private readonly PartModule module;
9+
private readonly ConfigNode originalNode;
10+
private readonly ConfigNode dataNode;
11+
private readonly BaseEventDetails moduleDataChangedEventDetails;
12+
public ModuleFuelTanksHandler(PartModule module, ConfigNode originalNode, ConfigNode dataNode, BaseEventDetails moduleDataChangedEventDetails)
13+
{
14+
this.module = module;
15+
this.originalNode = originalNode;
16+
this.dataNode = dataNode;
17+
this.moduleDataChangedEventDetails = moduleDataChangedEventDetails;
18+
}
19+
20+
public object PartAspectLock => PART_ASPECT_LOCK;
21+
public override string Description => "a part's ModuleFuelTanks";
22+
public override void DeactivateOnStartEditor() => Deactivate();
23+
public override void ActivateOnStartEditor() => Activate();
24+
public override void DeactivateOnSwitchEditor() => Deactivate();
25+
public override void ActivateOnSwitchEditor() => Activate();
26+
27+
private void Activate() => ApplyNode(dataNode);
28+
private void Deactivate() => ApplyNode(originalNode);
29+
30+
private void ApplyNode(ConfigNode sourceNode)
31+
{
32+
var evtDetails = new BaseEventDetails(BaseEventDetails.Sender.USER);
33+
evtDetails.Set<ConfigNode>("MFTNode", sourceNode);
34+
module.Events.Send("LoadMFTModuleFromConfigNode", evtDetails);
35+
module.Events.Send("ModuleDataChanged", moduleDataChangedEventDetails);
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)