Skip to content

Commit

Permalink
Local moons will now have visible orbits when orbiting a sibling
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinZeidler committed Mar 15, 2023
1 parent 8c29ec4 commit 275d78a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
2 changes: 1 addition & 1 deletion HideOrbitsProject/HideOrbits.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<AssemblyName>com.github.colinzeidler.hide_distant_orbits</AssemblyName>
<Product>Hide Orbits</Product>
<Description>Automatically hide distant orbits while zoomed in</Description>
<Version>0.2.0</Version>
<Version>0.3.0</Version>
<RestoreAdditionalProjectSources>
https://api.nuget.org/v3/index.json;
https://nuget.bepinex.dev/v3/index.json
Expand Down
37 changes: 35 additions & 2 deletions HideOrbitsProject/OrbitHiderPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,36 @@ public static void OrbitRenderer_UpdateOrbitStyling(Dictionary<IGGuid, OrbitRend
//HideOrbitsPlugin.Instance.logger.LogInfo($"Vessel parent Guid {vesselParentBody.SimulationObject.GlobalId}");
}

//HideOrbitsPlugin.Instance.logger.LogInfo("OrbitRenderer Called");
if (HideOrbitsPlugin.Instance != null && HideOrbitsPlugin.Instance.AutoHideOrbits) {
//HideOrbitsPlugin.Instance.logger.LogInfo("Updating orbits");

//Collect bodies related to local planet (and its moons)
Dictionary<IGGuid, CelestialBodyComponent> vesselParentChildren = new();
foreach (OrbitRenderer.OrbitRenderData orbitRenderData in ____orbitRenderData.Values)
{
if (orbitRenderData.Segments != null)
{
if (orbitRenderData.IsCelestialBody)
{
CelestialBodyComponent orbitBody = GameManager.Instance.Game.SpaceSimulation.GetSimulationObjectComponent<CelestialBodyComponent>(orbitRenderData.ParentGuid);
if (orbitBody.HasChild(vesselParentBody) || orbitBody.SimulationObject.GlobalId == vesselParentBody.SimulationObject.GlobalId)
{
if (!orbitBody.IsStar)
{
foreach (CelestialBodyComponent child in orbitBody.orbitingBodies)
{
if (child != null)
{
vesselParentChildren.Add(child.SimulationObject.GlobalId, child);
}
}
}
}
}
}
}

// Hide unimportant orbits
foreach (OrbitRenderer.OrbitRenderData orbitRenderData in ____orbitRenderData.Values)
{
if (orbitRenderData.Segments != null)
Expand All @@ -40,13 +67,18 @@ public static void OrbitRenderer_UpdateOrbitStyling(Dictionary<IGGuid, OrbitRend

// check if current orbitRenderData body is a child of vesselParentBody
CelestialBodyComponent orbitBody = GameManager.Instance.Game.SpaceSimulation.GetSimulationObjectComponent<CelestialBodyComponent>(orbitRenderData.ParentGuid);
if (vesselParentChildren.ContainsKey(orbitRenderData.ParentGuid))
{
continue;
}

if ((bool)orbitBody?.HasParent(vesselParentBody))
{
continue;
}

// TODO what happens if we orbit Mun, will we see Minmus Orbit? Kerbin Orbit?
if ((bool)orbitBody.HasChild(vesselParentBody))
if (orbitBody.HasChild(vesselParentBody))
{
continue;
}
Expand All @@ -55,6 +87,7 @@ public static void OrbitRenderer_UpdateOrbitStyling(Dictionary<IGGuid, OrbitRend
if (targetOrbit)
{
continue;
// TODO change color of target orbits?
}

foreach (OrbitRenderSegment segment in orbitRenderData.Segments)
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ Requires SpaceWarp 0.4.0: https://github.com/SpaceWarpDev/SpaceWarp
## Issues
- Distant orbits are always hidden (can be displayed using the toggle in the mods UI menu)

Please report any issues at https://github.com/ColinZeidler/KSP2-HideDistantOrbits/issues
Please report any issues at https://github.com/ColinZeidler/KSP2-HideDistantOrbits/issues

## Changelog
### v0.3.0
- Local moons should now always show their orbits
2 changes: 1 addition & 1 deletion hide_orbits/swinfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "Hide Orbits",
"description": "Automatically hide distant orbits while zoomed in",
"source": "https://github.com/ColinZeidler/KSP2-HideDistantOrbits",
"version": "0.2.0",
"version": "0.3.0",
"dependencies": [
{
"id": "SpaceWarp",
Expand Down

0 comments on commit 275d78a

Please sign in to comment.