diff --git a/NewHorizons/Builder/Body/BrambleDimensionBuilder.cs b/NewHorizons/Builder/Body/BrambleDimensionBuilder.cs index 243061e3..0a702930 100644 --- a/NewHorizons/Builder/Body/BrambleDimensionBuilder.cs +++ b/NewHorizons/Builder/Body/BrambleDimensionBuilder.cs @@ -1,4 +1,6 @@ using NewHorizons.Builder.Props; +using NewHorizons.Components.Orbital; +using NewHorizons.Handlers; using NewHorizons.Utility; using System; using System.Collections.Generic; @@ -43,10 +45,13 @@ namespace NewHorizons.Builder.Body // spawn the dimension body var dimensionPrefab = SearchUtilities.Find("DB_HubDimension_Body"); - var dimension = GameObject.Instantiate(dimensionPrefab); - var ao = dimension.GetComponent(); + var dimension = dimensionPrefab.InstantiateInactive(); + + PlanetCreationHandler.UpdateBodyOrbit(body, dimension); // fix name + var ao = dimension.GetComponent(); + ao.IsDimension = true; var name = body.Config.name ?? "Custom Bramble Dimension"; ao._customName = name; ao._name = AstroObject.Name.CustomString; @@ -89,7 +94,8 @@ namespace NewHorizons.Builder.Body var fog = fogGO.GetComponent(); fog.fogTint = body.Config.Bramble.dimension.fogTint.ToColor(); } - + + dimension.SetActive(true); return dimension; } diff --git a/NewHorizons/Components/Orbital/NHAstroObject.cs b/NewHorizons/Components/Orbital/NHAstroObject.cs index 29c79208..9fe7e7f2 100644 --- a/NewHorizons/Components/Orbital/NHAstroObject.cs +++ b/NewHorizons/Components/Orbital/NHAstroObject.cs @@ -1,4 +1,4 @@ -using NewHorizons.External.Modules; +using NewHorizons.External.Modules; namespace NewHorizons.Components.Orbital { public class NHAstroObject : AstroObject, IOrbitalParameters @@ -10,6 +10,7 @@ namespace NewHorizons.Components.Orbital public float argumentOfPeriapsis { get; set; } public float trueAnomaly { get; set; } public bool HideDisplayName { get; set; } + public bool IsDimension { get; set; } public void SetOrbitalParametersFromConfig(OrbitModule orbit) { diff --git a/NewHorizons/External/Configs/PlanetConfig.cs b/NewHorizons/External/Configs/PlanetConfig.cs index c65c68c3..c595fc26 100644 --- a/NewHorizons/External/Configs/PlanetConfig.cs +++ b/NewHorizons/External/Configs/PlanetConfig.cs @@ -6,6 +6,7 @@ using System.Linq; using NewHorizons.External.Modules; using NewHorizons.External.Modules.VariableSize; using Newtonsoft.Json; +using Logger = NewHorizons.Utility.Logger; namespace NewHorizons.External.Configs { @@ -175,13 +176,18 @@ namespace NewHorizons.External.Configs if (ReferenceFrame == null) ReferenceFrame = new ReferenceFrameModule(); } - public void MigrateAndValidate() + public void Validate() { - // Validate + // If we can correct a part of the config, do it + // If it cannot be solved, throw an exception if (Base.centerOfSolarSystem) Orbit.isStatic = true; if (Atmosphere?.clouds?.lightningGradient != null) Atmosphere.clouds.hasLightning = true; - if (Bramble?.dimension != null && Orbit?.staticPosition == null) NewHorizons.Utility.Logger.LogError($"Dimension {name} must have Orbit.staticPosition defined."); + if (Bramble?.dimension != null && Orbit?.staticPosition == null) throw new Exception($"Dimension {name} must have Orbit.staticPosition defined."); + if (Orbit?.staticPosition != null) Orbit.isStatic = true; + } + public void Migrate() + { // Backwards compatability // Should be the only place that obsolete things are referenced #pragma warning disable 612, 618 diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 3dae68ca..af0f1a51 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -239,10 +239,11 @@ namespace NewHorizons.Handlers GameObject planetObject = GenerateBody(body, defaultPrimaryToSun); if (planetObject == null) return false; planetObject.SetActive(true); - var nhAO = planetObject.GetComponent(); - var owAO = planetObject.GetComponent(); - if (nhAO != null) _dict.Add(nhAO, body); - else if (owAO != null) _dimensions.Add(owAO, body); + + var ao = planetObject.GetComponent(); + + if (!ao.IsDimension) _dict.Add(ao, body); + else _dimensions.Add(ao, body); } catch (Exception e) { @@ -306,7 +307,7 @@ namespace NewHorizons.Handlers public static GameObject GenerateBrambleDimensionBody(NewHorizonsBody body) { var go = BrambleDimensionBuilder.Make(body); - var ao = go.GetComponent(); + var ao = go.GetComponent(); var sector = go.FindChild("Sector").GetComponent(); var owRigidBody = go.GetComponent(); diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index d2cb9fae..d9488f9a 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -489,7 +489,8 @@ namespace NewHorizons } // Has to happen after we make sure theres a system config - config.MigrateAndValidate(); + config.Validate(); + config.Migrate(); body = new NewHorizonsBody(config, mod, relativePath); }