Skip to content

Commit

Permalink
Fix planet ordering logic
Browse files Browse the repository at this point in the history
  • Loading branch information
DMagic1 committed Jun 18, 2020
1 parent 9a0aec6 commit 46bd53b
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 134 deletions.
63 changes: 18 additions & 45 deletions SCANsat/SCAN_Unity/SCAN_UI_BigMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
using FinePrint;
using FinePrint.Utilities;
using palette = SCANsat.SCAN_UI.UI_Framework.SCANcolorUtil;
using KSPAchievements;

namespace SCANsat.SCAN_Unity
{
Expand Down Expand Up @@ -1563,59 +1564,31 @@ public IList<string> CelestialBodies
{
get
{
List<string> bodyList = new List<string>();

var bodies = FlightGlobals.Bodies.Where(b => b.referenceBody == Planetarium.fetch.Sun && b.referenceBody != b);

var orderedBodies = bodies.OrderBy(b => b.orbit.semiMajorAxis).ToList();

for (int i = 0; i < orderedBodies.Count; i++)
{
CelestialBody body = orderedBodies[i];

if (SCANcontroller.controller.getData(body.bodyName) != null)
bodyList.Add(body.displayName.LocalizeBodyName());

for (int j = 0; j < body.orbitingBodies.Count; j++)
{
CelestialBody moon = body.orbitingBodies[j];

if (SCANcontroller.controller.getData(moon.bodyName) != null)
bodyList.Add(moon.displayName.LocalizeBodyName());

for (int k = 0; k < moon.orbitingBodies.Count; k++)
{
CelestialBody subMoon = moon.orbitingBodies[k];

if (SCANcontroller.controller.getData(subMoon.bodyName) != null)
bodyList.Add(subMoon.displayName.LocalizeBodyName());

for (int l = 0; l < subMoon.orbitingBodies.Count; l++)
{
CelestialBody subSubMoon = subMoon.orbitingBodies[l];
List<string> bodyList = SCANUtil.RecursiveCelestialBodies(orderedBodies);

if (SCANcontroller.controller.getData(subSubMoon.bodyName) != null)
bodyList.Add(subSubMoon.displayName.LocalizeBodyName());
bool missingHome = true;

for (int m = 0; m < subSubMoon.orbitingBodies.Count; m++)
{
CelestialBody subSubSubMoon = subSubMoon.orbitingBodies[m];
for (int i = bodyList.Count - 1; i >= 0; i--)
{
string b = bodyList[i];

if (SCANcontroller.controller.getData(subSubSubMoon.bodyName) != null)
bodyList.Add(subSubSubMoon.displayName.LocalizeBodyName());
if (b == FlightGlobals.GetHomeBody().displayName.LocalizeBodyName())
{
missingHome = false;
break;
}
}

for (int n = 0; n < subSubSubMoon.orbitingBodies.Count; n++)
{
CelestialBody subSubSubSubMoon = subSubSubMoon.orbitingBodies[n];
if (missingHome)
{
List<string> missingHomeBodies = SCANUtil.RecursiveCelestialBodies(new List<CelestialBody>() { FlightGlobals.GetHomeBody() });

if (SCANcontroller.controller.getData(subSubSubSubMoon.bodyName) != null)
bodyList.Add(subSubSubSubMoon.displayName.LocalizeBodyName());
}
}
}
}
}
}
bodyList.InsertRange(0, missingHomeBodies);
}

if (HighLogic.LoadedSceneIsFlight)
{
Expand Down Expand Up @@ -1977,7 +1950,7 @@ private string mouseOverInfo(double lon, double lat)
SCANUtil.getBiomeDisplayName(infoString, body, lon, lat);
}

if (bigmap.ResourceActive && SCANconfigLoader.GlobalResource && bigmap.Resource != null)
if (SCANconfigLoader.GlobalResource && bigmap.Resource != null)
{
bool resources = false;
bool fuzzy = false;
Expand Down
54 changes: 15 additions & 39 deletions SCANsat/SCAN_Unity/SCAN_UI_Color.cs
Original file line number Diff line number Diff line change
Expand Up @@ -558,54 +558,30 @@ public IList<string> CelestialBodies
{
get
{
List<string> bodyList = new List<string>();

var bodies = FlightGlobals.Bodies.Where(b => b.referenceBody == Planetarium.fetch.Sun && b.referenceBody != b);

var orderedBodies = bodies.OrderBy(b => b.orbit.semiMajorAxis).ToList();

for (int i = 0; i < orderedBodies.Count; i++)
{
CelestialBody body = orderedBodies[i];

bodyList.Add(body.displayName.LocalizeBodyName());

for (int j = 0; j < body.orbitingBodies.Count; j++)
{
CelestialBody moon = body.orbitingBodies[j];

bodyList.Add(moon.displayName.LocalizeBodyName());

for (int k = 0; k < moon.orbitingBodies.Count; k++)
{
CelestialBody subMoon = moon.orbitingBodies[k];

bodyList.Add(subMoon.displayName.LocalizeBodyName());
List<string> bodyList = SCANUtil.RecursiveCelestialBodies(orderedBodies);

for (int l = 0; l < subMoon.orbitingBodies.Count; l++)
{
CelestialBody subSubMoon = subMoon.orbitingBodies[l];
bool missingHome = true;

bodyList.Add(subSubMoon.displayName.LocalizeBodyName());

for (int m = 0; m < subSubMoon.orbitingBodies.Count; m++)
{
CelestialBody subSubSubMoon = subSubMoon.orbitingBodies[m];
for (int i = bodyList.Count - 1; i >= 0; i--)
{
string b = bodyList[i];

if (SCANcontroller.controller.getData(subSubSubMoon.bodyName) != null)
bodyList.Add(subSubSubMoon.displayName.LocalizeBodyName());
if (b == FlightGlobals.GetHomeBody().displayName.LocalizeBodyName())
{
missingHome = false;
break;
}
}

for (int n = 0; n < subSubSubMoon.orbitingBodies.Count; n++)
{
CelestialBody subSubSubSubMoon = subSubSubMoon.orbitingBodies[n];
if (missingHome)
{
List<string> missingHomeBodies = SCANUtil.RecursiveCelestialBodies(new List<CelestialBody>() { FlightGlobals.GetHomeBody() });

if (SCANcontroller.controller.getData(subSubSubSubMoon.bodyName) != null)
bodyList.Add(subSubSubSubMoon.displayName.LocalizeBodyName());
}
}
}
}
}
bodyList.InsertRange(0, missingHomeBodies);
}

if (HighLogic.LoadedSceneIsFlight)
Expand Down
66 changes: 16 additions & 50 deletions SCANsat/SCAN_Unity/SCAN_UI_Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -589,58 +589,30 @@ public IList<string> BackgroundBodies
{
get
{
List<string> bodyList = new List<string>();

var bodies = FlightGlobals.Bodies.Where(b => b.referenceBody == Planetarium.fetch.Sun && b.referenceBody != b);

var orderedBodies = bodies.OrderBy(b => b.orbit.semiMajorAxis).ToList();

for (int i = 0; i < orderedBodies.Count; i++)
{
CelestialBody body = orderedBodies[i];

if (SCANcontroller.controller.getData(body.bodyName) != null)
bodyList.Add(body.displayName.LocalizeBodyName());

for (int j = 0; j < body.orbitingBodies.Count; j++)
{
CelestialBody moon = body.orbitingBodies[j];

if (SCANcontroller.controller.getData(moon.bodyName) != null)
bodyList.Add(moon.displayName.LocalizeBodyName());

for (int k = 0; k < moon.orbitingBodies.Count; k++)
{
CelestialBody subMoon = moon.orbitingBodies[k];

if (SCANcontroller.controller.getData(subMoon.bodyName) != null)
bodyList.Add(subMoon.displayName.LocalizeBodyName());
List<string> bodyList = SCANUtil.RecursiveCelestialBodies(orderedBodies);

for (int l = 0; l < subMoon.orbitingBodies.Count; l++)
{
CelestialBody subSubMoon = subMoon.orbitingBodies[l];
bool missingHome = true;

if (SCANcontroller.controller.getData(subSubMoon.bodyName) != null)
bodyList.Add(subSubMoon.displayName.LocalizeBodyName());

for (int m = 0; m < subSubMoon.orbitingBodies.Count; m++)
{
CelestialBody subSubSubMoon = subSubMoon.orbitingBodies[m];
for (int i = bodyList.Count - 1; i >= 0; i--)
{
string b = bodyList[i];

if (SCANcontroller.controller.getData(subSubSubMoon.bodyName) != null)
bodyList.Add(subSubSubMoon.displayName.LocalizeBodyName());
if (b == FlightGlobals.GetHomeBody().displayName.LocalizeBodyName())
{
missingHome = false;
break;
}
}

for (int n = 0; n < subSubSubMoon.orbitingBodies.Count; n++)
{
CelestialBody subSubSubSubMoon = subSubSubMoon.orbitingBodies[n];
if (missingHome)
{
List<string> missingHomeBodies = SCANUtil.RecursiveCelestialBodies(new List<CelestialBody>() { FlightGlobals.GetHomeBody() });

if (SCANcontroller.controller.getData(subSubSubSubMoon.bodyName) != null)
bodyList.Add(subSubSubSubMoon.displayName.LocalizeBodyName());
}
}
}
}
}
bodyList.InsertRange(0, missingHomeBodies);
}

SCANdata sun = SCANcontroller.controller.getData(Planetarium.fetch.Sun.bodyName);
Expand All @@ -658,13 +630,7 @@ public IList<string> MapDataTypes
{
List<int> availableTypes = new List<int>() { 0, 1, 3, 4, 5, 2, 6, 7, 8 };

//if (SCAN_Settings_Config.Instance.DisableStockResource || !SCAN_Settings_Config.Instance.InstantScan)
// {
// availableTypes.Add(7);
// availableTypes.Add(8);
// }

List<string> types = new List<string>() { "All Data" };//, "SCAN Data Types" };
List<string> types = new List<string>() { "All Data" };

for (int i = 0; i < availableTypes.Count; i++)
types.Add(((SCANtype)(1 << availableTypes[i])).ToString());
Expand Down
54 changes: 54 additions & 0 deletions SCANsat/SCANutil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,60 @@ internal static Vector2d fixRetardCoordinates(Vector2d coords)
return coords;
}

internal static List<string> RecursiveCelestialBodies(List<CelestialBody> bodies)
{
List<string> bodyList = new List<string>();

for (int i = 0; i < bodies.Count; i++)
{
CelestialBody body = bodies[i];
if (SCANcontroller.controller.getData(body.bodyName) != null)
bodyList.Add(body.displayName.LocalizeBodyName());

for (int j = 0; j < body.orbitingBodies.Count; j++)
{
CelestialBody moon = body.orbitingBodies[j];

if (SCANcontroller.controller.getData(moon.bodyName) != null)
bodyList.Add(moon.displayName.LocalizeBodyName());

for (int k = 0; k < moon.orbitingBodies.Count; k++)
{
CelestialBody subMoon = moon.orbitingBodies[k];

if (SCANcontroller.controller.getData(subMoon.bodyName) != null)
bodyList.Add(subMoon.displayName.LocalizeBodyName());

for (int l = 0; l < subMoon.orbitingBodies.Count; l++)
{
CelestialBody subSubMoon = subMoon.orbitingBodies[l];

if (SCANcontroller.controller.getData(subSubMoon.bodyName) != null)
bodyList.Add(subSubMoon.displayName.LocalizeBodyName());

for (int m = 0; m < subSubMoon.orbitingBodies.Count; m++)
{
CelestialBody subSubSubMoon = subSubMoon.orbitingBodies[m];

if (SCANcontroller.controller.getData(subSubSubMoon.bodyName) != null)
bodyList.Add(subSubSubMoon.displayName.LocalizeBodyName());

for (int n = 0; n < subSubSubMoon.orbitingBodies.Count; n++)
{
CelestialBody subSubSubSubMoon = subSubSubMoon.orbitingBodies[n];

if (SCANcontroller.controller.getData(subSubSubSubMoon.bodyName) != null)
bodyList.Add(subSubSubSubMoon.displayName.LocalizeBodyName());
}
}
}
}
}
}

return bodyList;
}

internal static double getElevation(CelestialBody body, double lon, double lat)
{
if (body.pqsController == null) return 0;
Expand Down

0 comments on commit 46bd53b

Please sign in to comment.