Skip to content

Commit 38d04d3

Browse files
committed
Support B9PS
- Support mixing and matching what center follows the transform using B9PS
1 parent 0dd34d9 commit 38d04d3

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Source/Modules/ModuleCenterFollowTransform.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,22 @@ public class ModuleCenterFollowTransform : PartModule
1515

1616
[KSPField]
1717
public bool enableCoP = false;
18+
private bool wasEnabledCoP;
1819

1920
[KSPField]
2021
public bool enableCoM = false;
22+
private bool wasEnabledCoM;
2123

2224
[KSPField]
2325
public bool enableCoL = false;
26+
private bool wasEnabledCoL;
2427

2528
[KSPField]
2629
public string transformName;
2730

2831
[SerializeField]
2932
private Transform followTransform;
3033

31-
// TODO: Reset offset to prefab value if B9PS disables one of the fields.
3234
public override void OnLoad(ConfigNode node)
3335
{
3436
bool anyModeActive = enableCoP || enableCoM || enableCoL;
@@ -51,7 +53,14 @@ public override void OnLoad(ConfigNode node)
5153
if (enableCoM) part.CoMOffset = part.partInfo.partPrefab.CoMOffset;
5254
if (enableCoL) part.CoLOffset = part.partInfo.partPrefab.CoLOffset;
5355
}
54-
56+
// Set offets back to the values in the prefab if the mode is disabled after initial initialisation; e.g. B9PS
57+
if (!enableCoP && wasEnabledCoP) part.CoPOffset = part.partInfo.partPrefab.CoPOffset;
58+
if (!enableCoM && wasEnabledCoM) part.CoMOffset = part.partInfo.partPrefab.CoMOffset;
59+
if (!enableCoL && wasEnabledCoL) part.CoLOffset = part.partInfo.partPrefab.CoLOffset;
60+
wasEnabledCoP = enableCoP;
61+
wasEnabledCoM = enableCoM;
62+
wasEnabledCoL = enableCoL;
63+
5564
// NOTE: isEnabled will be persisted to the save file, but we want to treat it purely as runtime state
5665
isEnabled = followTransform != null && anyModeActive;
5766
enabled = followTransform != null && anyModeActive && HighLogic.LoadedSceneIsFlight;

0 commit comments

Comments
 (0)