From 69747bb7ccbbddc6d74f48d1e083c6e3187add45 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 7 May 2022 16:03:59 -0400 Subject: [PATCH] Finialize updating orbits --- NewHorizons/Handlers/PlanetCreationHandler.cs | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index b52fe1af..11d670cb 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -21,11 +21,14 @@ namespace NewHorizons.Handlers { public static List NextPassBodies = new List(); private static List ToLoad; + private static Dictionary ExistingAOConfigs; public static void Init(List bodies) { Main.FurthestOrbit = 30000; + ExistingAOConfigs = new Dictionary(); + // Set up stars // Need to manage this when there are multiple stars var sun = GameObject.Find("Sun_Body"); @@ -428,13 +431,14 @@ namespace NewHorizons.Handlers var children = AstroObjectLocator.GetChildren(ao).Concat(AstroObjectLocator.GetMoons(ao)).ToArray(); AstroObjectLocator.DeregisterCustomAstroObject(ao); GameObject.Destroy(ao); + Locator.RegisterAstroObject(newAO); AstroObjectLocator.RegisterCustomAstroObject(newAO); newAO._primaryBody = primary; - var orbitLine = go.GetComponentInChildren(); + GameObject.Destroy(go.GetComponentInChildren().gameObject); var isMoon = newAO.GetAstroObjectType() == AstroObject.Type.Moon || newAO.GetAstroObjectType() == AstroObject.Type.Satellite; - var newOrbitLine = OrbitlineBuilder.Make(go, newAO, isMoon, body.Config); + if(body.Config.Orbit.ShowOrbitLine) OrbitlineBuilder.Make(go, newAO, isMoon, body.Config); DetectorBuilder.SetDetector(primary, newAO, go.GetComponentInChildren()); @@ -456,16 +460,24 @@ namespace NewHorizons.Handlers var child = children[i]; // If the child is an AO we do stuff too - var childAO = child.GetComponent(); + var childAO = child.GetComponent() ?? child.GetComponent(); if (childAO != null) { - foreach (var childChild in AstroObjectLocator.GetChildren(childAO)) + if (childAO is NHAstroObject && ExistingAOConfigs.ContainsKey(childAO)) { - var dPos = childChild.transform.position - child.transform.position; - childChild.transform.position = go.transform.position + relativeMoonPositions[i] + dPos; + // If it's already and NH object we repeat the whole process else it doesn't work idk + NextPassBodies.Add(ExistingAOConfigs[childAO]); + } + else + { + foreach (var childChild in AstroObjectLocator.GetChildren(childAO)) + { + var dPos = childChild.transform.position - child.transform.position; + childChild.transform.position = go.transform.position + relativeMoonPositions[i] + dPos; + } + // Make sure the moons get updated to the new AO + childAO._primaryBody = newAO; } - // Make sure the moons get updated to the new AO - childAO._primaryBody = newAO; } child.transform.position = go.transform.position + relativeMoonPositions[i]; @@ -476,6 +488,8 @@ namespace NewHorizons.Handlers // Have to register this new AO to the locator Locator.RegisterAstroObject(newAO); + + ExistingAOConfigs.Add(newAO, body); } catch (Exception ex) {