Finialize updating orbits

This commit is contained in:
Nick 2022-05-07 16:03:59 -04:00
parent 7359283f37
commit 69747bb7cc

View File

@ -21,11 +21,14 @@ namespace NewHorizons.Handlers
{ {
public static List<NewHorizonsBody> NextPassBodies = new List<NewHorizonsBody>(); public static List<NewHorizonsBody> NextPassBodies = new List<NewHorizonsBody>();
private static List<NewHorizonsBody> ToLoad; private static List<NewHorizonsBody> ToLoad;
private static Dictionary<AstroObject, NewHorizonsBody> ExistingAOConfigs;
public static void Init(List<NewHorizonsBody> bodies) public static void Init(List<NewHorizonsBody> bodies)
{ {
Main.FurthestOrbit = 30000; Main.FurthestOrbit = 30000;
ExistingAOConfigs = new Dictionary<AstroObject, NewHorizonsBody>();
// Set up stars // Set up stars
// Need to manage this when there are multiple stars // Need to manage this when there are multiple stars
var sun = GameObject.Find("Sun_Body"); var sun = GameObject.Find("Sun_Body");
@ -428,13 +431,14 @@ namespace NewHorizons.Handlers
var children = AstroObjectLocator.GetChildren(ao).Concat(AstroObjectLocator.GetMoons(ao)).ToArray(); var children = AstroObjectLocator.GetChildren(ao).Concat(AstroObjectLocator.GetMoons(ao)).ToArray();
AstroObjectLocator.DeregisterCustomAstroObject(ao); AstroObjectLocator.DeregisterCustomAstroObject(ao);
GameObject.Destroy(ao); GameObject.Destroy(ao);
Locator.RegisterAstroObject(newAO);
AstroObjectLocator.RegisterCustomAstroObject(newAO); AstroObjectLocator.RegisterCustomAstroObject(newAO);
newAO._primaryBody = primary; newAO._primaryBody = primary;
var orbitLine = go.GetComponentInChildren<OrbitLine>(); GameObject.Destroy(go.GetComponentInChildren<OrbitLine>().gameObject);
var isMoon = newAO.GetAstroObjectType() == AstroObject.Type.Moon || newAO.GetAstroObjectType() == AstroObject.Type.Satellite; 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<ConstantForceDetector>()); DetectorBuilder.SetDetector(primary, newAO, go.GetComponentInChildren<ConstantForceDetector>());
@ -456,16 +460,24 @@ namespace NewHorizons.Handlers
var child = children[i]; var child = children[i];
// If the child is an AO we do stuff too // If the child is an AO we do stuff too
var childAO = child.GetComponent<AstroObject>(); var childAO = child.GetComponent<NHAstroObject>() ?? child.GetComponent<AstroObject>();
if (childAO != null) 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; // If it's already and NH object we repeat the whole process else it doesn't work idk
childChild.transform.position = go.transform.position + relativeMoonPositions[i] + dPos; 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]; child.transform.position = go.transform.position + relativeMoonPositions[i];
@ -476,6 +488,8 @@ namespace NewHorizons.Handlers
// Have to register this new AO to the locator // Have to register this new AO to the locator
Locator.RegisterAstroObject(newAO); Locator.RegisterAstroObject(newAO);
ExistingAOConfigs.Add(newAO, body);
} }
catch (Exception ex) catch (Exception ex)
{ {