From 084ab5ea76b331a13cd6eed531ceda47ec2029f0 Mon Sep 17 00:00:00 2001 From: "Nick J. Connors" Date: Sun, 30 Jan 2022 14:05:03 -0500 Subject: [PATCH] Improved astroobjectlocator + funnels on existing planets --- NewHorizons/Main.cs | 24 +++++++------------ NewHorizons/Utility/AstroObjectLocator.cs | 28 +++++++++++++++-------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 407f6325..e2c01d43 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -331,18 +331,11 @@ namespace NewHorizons private bool LoadBody(NewHorizonsBody body, bool defaultPrimaryToSun = false) { - var stringID = body.Config.Name.ToUpper().Replace(" ", "_").Replace("'", ""); - if (stringID.Equals("ATTLEROCK")) stringID = "TIMBER_MOON"; - if (stringID.Equals("HOLLOWS_LANTERN")) stringID = "VOLCANIC_MOON"; - if (stringID.Equals("ASH_TWIN")) stringID = "TOWER_TWIN"; - if (stringID.Equals("EMBER_TWIN")) stringID = "CAVE_TWIN"; - if (stringID.Equals("INTERLOPER")) stringID = "COMET"; - + // I don't remember doing this why is it exceptions what am I doing GameObject existingPlanet = null; try { - existingPlanet = AstroObjectLocator.GetAstroObject(stringID).gameObject; - if (existingPlanet == null) existingPlanet = AstroObjectLocator.GetAstroObject(body.Config.Name.Replace(" ", "")).gameObject; + existingPlanet = AstroObjectLocator.GetAstroObject(body.Config.Name).gameObject; } catch (Exception) { @@ -356,8 +349,8 @@ namespace NewHorizons if (body.Config.Destroy) { var ao = existingPlanet.GetComponent(); - if (ao != null) Instance.ModHelper.Events.Unity.FireInNUpdates(() => PlanetDestroyer.RemoveBody(ao), 2); - else Instance.ModHelper.Events.Unity.FireInNUpdates(() => existingPlanet.SetActive(false), 2); + if (ao != null) Instance.ModHelper.Events.Unity.FireInNUpdates(() => PlanetDestroyer.RemoveBody(ao), 5); + else Instance.ModHelper.Events.Unity.FireInNUpdates(() => existingPlanet.SetActive(false), 5); } else UpdateBody(body, existingPlanet); } @@ -395,7 +388,7 @@ namespace NewHorizons { foreach (var child in body.Config.ChildrenToDestroy) { - GameObject.Find(go.name + "/" + child).SetActive(false); + Instance.ModHelper.Events.Unity.FireInNUpdates(() => GameObject.Find(go.name + "/" + child).SetActive(false), 2); } } @@ -504,9 +497,6 @@ namespace NewHorizons if (!body.Config.Orbit.IsStatic) DetectorBuilder.Make(go, owRigidBody, primaryBody, ao); - if (body.Config.Funnel != null) - FunnelBuilder.Make(go, go.GetComponentInChildren(), owRigidBody, body.Config.Funnel); - if (ao.GetAstroObjectName() == AstroObject.Name.CustomString) AstroObjectLocator.RegisterCustomAstroObject(ao); HeavenlyBodyBuilder.Make(go, body.Config, sphereOfInfluence, gv, initialMotion); @@ -570,7 +560,6 @@ namespace NewHorizons AtmosphereBuilder.Make(go, body.Config.Atmosphere, body.Config.Base.SurfaceSize); } - // Do this next tick so we can raycast the planet to place things on the surface if (body.Config.Props != null) PropBuildManager.Make(go, sector, body.Config, body.Mod.Assets, body.Mod.Manifest.UniqueName); @@ -580,6 +569,9 @@ namespace NewHorizons if (body.Config.Base.BlackHoleSize != 0 || body.Config.Singularity != null) SingularityBuilder.Make(go, sector, rb, body.Config); + if (body.Config.Funnel != null) + FunnelBuilder.Make(go, go.GetComponentInChildren(), rb, body.Config.Funnel); + return go; } diff --git a/NewHorizons/Utility/AstroObjectLocator.cs b/NewHorizons/Utility/AstroObjectLocator.cs index f86edd36..3a3b6cd4 100644 --- a/NewHorizons/Utility/AstroObjectLocator.cs +++ b/NewHorizons/Utility/AstroObjectLocator.cs @@ -17,17 +17,27 @@ namespace NewHorizons.Utility private static List _list = new List(); - public static AstroObject GetAstroObject(string name) + public static AstroObject GetAstroObject(string name, bool flag = false) { - if (name.ToUpper().Replace("_", "").Equals("MAPSATELLITE")) + if (_customAstroObjectDictionary.ContainsKey(name)) return _customAstroObjectDictionary[name]; + + var stringID = name.ToUpper().Replace(" ", "_").Replace("'", ""); + if (stringID.Equals("ATTLEROCK")) stringID = "TIMBER_MOON"; + if (stringID.Equals("HOLLOWS_LANTERN")) stringID = "VOLCANIC_MOON"; + if (stringID.Equals("ASH_TWIN")) stringID = "TOWER_TWIN"; + if (stringID.Equals("EMBER_TWIN")) stringID = "CAVE_TWIN"; + if (stringID.Equals("INTERLOPER")) stringID = "COMET"; + + if (stringID.ToUpper().Replace("_", "").Equals("MAPSATELLITE")) return GetAstroObject(AstroObject.Name.MapSatellite); - var aoName = AstroObject.StringIDToAstroObjectName(name); - if(aoName == AstroObject.Name.None) aoName = AstroObject.StringIDToAstroObjectName(name.ToUpper().Replace(" ", "_")); - if (aoName != AstroObject.Name.None && aoName != AstroObject.Name.CustomString) - return GetAstroObject(aoName); - if (_customAstroObjectDictionary.ContainsKey(name)) - return _customAstroObjectDictionary[name]; - else return null; + + var aoName = AstroObject.StringIDToAstroObjectName(stringID); + if (aoName != AstroObject.Name.None && aoName != AstroObject.Name.CustomString) return GetAstroObject(aoName); + + // Try again + if (!flag) return GetAstroObject(name.Replace(" ", ""), true); + + return null; } public static AstroObject GetAstroObject(AstroObject.Name astroObjectName, string customName = null)