Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion B9PartSwitch/B9PartSwitch.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.Net.Compilers.3.9.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.3.9.0\build\Microsoft.Net.Compilers.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
Expand Down Expand Up @@ -132,6 +132,7 @@
<Compile Include="PartSwitch\MaterialModifierInfo.cs" />
<Compile Include="PartSwitch\PartModifiers\ModuleDataHandlerBasic.cs" />
<Compile Include="PartSwitch\PartModifiers\ModuleDeactivator.cs" />
<Compile Include="PartSwitch\PartModifiers\ModuleFuelTanksHandler.cs" />
<Compile Include="PartSwitch\PartModifiers\ModuleOutputResourceResetter.cs" />
<Compile Include="PartSwitch\PartModifiers\PartAttachNodeModifier.cs" />
<Compile Include="PartSwitch\PartModifiers\PartCenterOfBuoyancyModifier.cs" />
Expand Down
3 changes: 3 additions & 0 deletions B9PartSwitch/PartSwitch/ModuleModifierInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ public IEnumerable<IPartModifier> CreatePartModifiers(Part part, PartModule pare
yield return new ModuleOutputResourceResetter(module);
yield return new ModuleDataHandlerBasic(module, originalNode, dataNode, moduleDataChangedEventDetails);
}
else if (module.moduleName == "ModuleFuelTanks") {
yield return new ModuleFuelTanksHandler(module, originalNode, dataNode, moduleDataChangedEventDetails);
}
else
yield return new ModuleDataHandlerBasic(module, originalNode, dataNode, moduleDataChangedEventDetails);
}
Expand Down
38 changes: 38 additions & 0 deletions B9PartSwitch/PartSwitch/PartModifiers/ModuleFuelTanksHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

namespace B9PartSwitch.PartSwitch.PartModifiers
{
public class ModuleFuelTanksHandler : PartModifierBase, IPartAspectLock
{
public const string PART_ASPECT_LOCK = "ModuleFuelTanks";

private readonly PartModule module;
private readonly ConfigNode originalNode;
private readonly ConfigNode dataNode;
private readonly BaseEventDetails moduleDataChangedEventDetails;
public ModuleFuelTanksHandler(PartModule module, ConfigNode originalNode, ConfigNode dataNode, BaseEventDetails moduleDataChangedEventDetails)
{
this.module = module;
this.originalNode = originalNode;
this.dataNode = dataNode;
this.moduleDataChangedEventDetails = moduleDataChangedEventDetails;
}

public object PartAspectLock => PART_ASPECT_LOCK;
public override string Description => "a part's ModuleFuelTanks";
public override void DeactivateOnStartEditor() => Deactivate();
public override void ActivateOnStartEditor() => Activate();
public override void DeactivateOnSwitchEditor() => Deactivate();
public override void ActivateOnSwitchEditor() => Activate();

private void Activate() => ApplyNode(dataNode);
private void Deactivate() => ApplyNode(originalNode);

private void ApplyNode(ConfigNode sourceNode)
{
var evtDetails = new BaseEventDetails(BaseEventDetails.Sender.USER);
evtDetails.Set<ConfigNode>("MFTNode", sourceNode);
module.Events.Send("LoadMFTModuleFromConfigNode", evtDetails);
module.Events.Send("ModuleDataChanged", moduleDataChangedEventDetails);
}
}
}
Loading