Skip to content

Commit

Permalink
Fix symmetry loops
Browse files Browse the repository at this point in the history
They ended up being harmless but still
  • Loading branch information
blowfishpro committed May 6, 2016
1 parent 5ac7489 commit 3a409a6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions B9PartSwitch/PartSwitch/ModuleB9PartSwitch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ private void SetupGUI()

private void UpdateFromGUI(BaseField field, object oldFieldValueObj)
{
SetNewSubtype(subtypeIndexControl, false, true);
BeginSubtypeChange(subtypeIndexControl);
}

private void UpdateDragCubesOnAttach()
Expand All @@ -334,35 +334,36 @@ private void UpdateDragCubesOnAttach()
RenderProceduralDragCubes();
}

private void SetNewSubtype(int newIndex, bool force, bool fireEvents)
private void BeginSubtypeChange(int newIndex)
{
if (newIndex < 0 || newIndex >= subtypes.Count)
throw new ArgumentException($"Subtype index must be between 0 and {subtypes.Count}");

// For symmetry
subtypeIndexControl = newIndex;

if (newIndex == currentSubtypeIndex && !force)
if (newIndex == currentSubtypeIndex)
return;

if (newIndex < 0 || newIndex >= subtypes.Count)
throw new ArgumentException($"Subtype index must be between 0 and {subtypes.Count}");
SetNewSubtype(newIndex);

if (newIndex != currentSubtypeIndex)
{
CurrentSubtype.DeactivateObjects();
if (HighLogic.LoadedSceneIsEditor)
CurrentSubtype.DeactivateNodes();
}
foreach (var counterpart in this.FindSymmetryCounterparts())
counterpart.SetNewSubtype(newIndex);

currentSubtypeIndex = newIndex;
FireEvents();
}

UpdateSubtype(true);
private void SetNewSubtype(int newIndex)
{
CurrentSubtype.DeactivateObjects();
if (HighLogic.LoadedSceneIsEditor)
CurrentSubtype.DeactivateNodes();

foreach (var counterpart in this.FindSymmetryCounterparts())
counterpart.SetNewSubtype(newIndex, force, false);
currentSubtypeIndex = newIndex;

if (fireEvents)
FireEvents();
UpdateSubtype(true);
}

private void FireEvents()
{
if (HighLogic.LoadedSceneIsEditor)
Expand Down
Binary file modified GameData/B9PartSwitch/Plugins/B9PartSwitch.dll
Binary file not shown.

0 comments on commit 3a409a6

Please sign in to comment.