Skip to content

Commit

Permalink
remove the cloned attachnode when detaching a part
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyOThan committed Feb 11, 2024
1 parent d43ea7e commit 302b4c4
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion KSPCommunityFixes/BugFixes/ReRootCloneSurfaceAttach.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using HarmonyLib;
using Expansions.Missions.Editor;
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -31,6 +32,11 @@ protected override void ApplyPatches(List<PatchInfo> patches)
PatchMethodType.Postfix,
AccessTools.Method(typeof(Part), nameof(Part.FindAttachNode)),
this));

patches.Add(new PatchInfo(
PatchMethodType.Postfix,
AccessTools.Method(typeof(EditorLogicBase), nameof(EditorLogicBase.clearAttachNodes)),
this));
}

// In stock, this function is called after reversing a surface attachment during a re-root operation.
Expand Down Expand Up @@ -81,5 +87,20 @@ static void Part_FindAttachNode_Postfix(Part __instance, string nodeId, ref Atta
__result = newSrfAttachNode;
}
}

// In the editor, when detaching parts, remove the extra attachnode we added
static void EditorLogicBase_clearAttachNodes_Postfix(Part part)
{
for (int i = 0; i < part.attachNodes.Count; i++)
{
AttachNode attachNode = part.attachNodes[i];

if (attachNode.id == CLONED_NODE_ID && attachNode.attachedPart.IsNullRef())
{
part.attachNodes.RemoveAt(i);
return;
}
}
}
}
}

0 comments on commit 302b4c4

Please sign in to comment.