From a12b714f28d7ba3f0e9848d5e190ef46c743b298 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Thu, 18 Aug 2022 14:26:26 -0400 Subject: [PATCH] Just use separate config >:( --- .../Builder/Body/StellarRemnantBuilder.cs | 29 +++-- NewHorizons/External/Configs/PlanetConfig.cs | 5 + .../Modules/VariableSize/StarModule.cs | 107 ------------------ NewHorizons/Handlers/PlanetCreationHandler.cs | 10 +- NewHorizons/Schemas/body_schema.json | 4 + 5 files changed, 32 insertions(+), 123 deletions(-) diff --git a/NewHorizons/Builder/Body/StellarRemnantBuilder.cs b/NewHorizons/Builder/Body/StellarRemnantBuilder.cs index 9202d64d..eb3c1fd2 100644 --- a/NewHorizons/Builder/Body/StellarRemnantBuilder.cs +++ b/NewHorizons/Builder/Body/StellarRemnantBuilder.cs @@ -18,14 +18,15 @@ namespace NewHorizons.Builder.Body { public static class StellarRemnantBuilder { - public static void Make(GameObject go, OWRigidbody rb, PlanetConfig config, IModBehaviour mod, float sphereOfInfluence) + public static void Make(NewHorizonsBody star, GameObject go, OWRigidbody rb, IModBehaviour mod, NewHorizonsBody stellarRemnant = null) { - Logger.Log($"Creating stellar remnant for [{config.name}]"); + Logger.Log($"Creating stellar remnant for [{star.Config.name}]"); try { - var starModule = config.Star; + var config = star.Config; + var starModule = star.Config.Star; var size = starModule.size; - var sector = SectorBuilder.Make(go, rb, sphereOfInfluence); + var sector = SectorBuilder.Make(go, rb, 0); sector.name = "StellarRemnant"; var ss = sector.GetComponent(); @@ -36,21 +37,19 @@ namespace NewHorizons.Builder.Body sector.gameObject.SetActive(false); - if (starModule.stellarRemnant != null) + if (stellarRemnant != null) { - var srConfig = starModule.stellarRemnant.ConvertToPlanetConfig(config); - var srBody = new NewHorizonsBody(srConfig, mod); stellarRemnantController.SetRemnantType(StellarRemnantType.Custom); - stellarRemnantController.SetSurfaceSize(starModule.stellarRemnant.Base.surfaceSize); - stellarRemnantController.SetSurfaceGravity(starModule.stellarRemnant.Base.surfaceGravity); - stellarRemnantController.SetSiderealPeriod(starModule.stellarRemnant.siderealPeriod); - var srSphereOfInfluence = PlanetCreationHandler.GetSphereOfInfluence(srBody); + stellarRemnantController.SetSurfaceSize(stellarRemnant.Config.Base.surfaceSize); + stellarRemnantController.SetSurfaceGravity(stellarRemnant.Config.Base.surfaceGravity); + stellarRemnantController.SetSiderealPeriod(stellarRemnant.Config.Orbit.siderealPeriod); + var srSphereOfInfluence = PlanetCreationHandler.GetSphereOfInfluence(stellarRemnant); stellarRemnantController.SetSphereOfInfluence(srSphereOfInfluence); ss.radius = srSphereOfInfluence + 10; - var alignmentRadius = srBody.Config.Atmosphere?.clouds?.outerCloudRadius ?? 1.5f * srBody.Config.Base.surfaceSize; - if (srBody.Config.Base.surfaceGravity == 0) alignmentRadius = 0; + var alignmentRadius = stellarRemnant.Config.Atmosphere?.clouds?.outerCloudRadius ?? 1.5f * stellarRemnant.Config.Base.surfaceSize; + if (stellarRemnant.Config.Base.surfaceGravity == 0) alignmentRadius = 0; stellarRemnantController.SetAlignmentRadius(alignmentRadius); - PlanetCreationHandler.SharedGenerateBody(srBody, go, sector, rb, true); + PlanetCreationHandler.SharedGenerateBody(stellarRemnant, go, sector, rb, true); } else { @@ -127,7 +126,7 @@ namespace NewHorizons.Builder.Body } catch (Exception ex) { - Logger.LogError($"Couldn't make stellar remnant for [{config.name}]:\n{ex}"); + Logger.LogError($"Couldn't make stellar remnant for [{star.Config.name}]:\n{ex}"); } } } diff --git a/NewHorizons/External/Configs/PlanetConfig.cs b/NewHorizons/External/Configs/PlanetConfig.cs index 057aba8f..0801d9e7 100644 --- a/NewHorizons/External/Configs/PlanetConfig.cs +++ b/NewHorizons/External/Configs/PlanetConfig.cs @@ -100,6 +100,11 @@ namespace NewHorizons.External.Configs /// public bool isQuantumState; + /// + /// Does this config describe a stellar remnant of a custom star defined in another file? + /// + public bool isStellarRemnant; + /// /// Add lava to this planet /// diff --git a/NewHorizons/External/Modules/VariableSize/StarModule.cs b/NewHorizons/External/Modules/VariableSize/StarModule.cs index 2833a1c3..f4a4291d 100644 --- a/NewHorizons/External/Modules/VariableSize/StarModule.cs +++ b/NewHorizons/External/Modules/VariableSize/StarModule.cs @@ -97,113 +97,6 @@ namespace NewHorizons.External.Modules.VariableSize /// The type of stellar remnant your star will leave behind. /// [DefaultValue("default")] public StellarRemnantType stellarRemnantType = StellarRemnantType.Default; - - /// - /// If you want a custom stellar remnant, use this. - /// - public StellarRemnantModule stellarRemnant; - - public class StellarRemnantModule - { - /// - /// Describes this Body's atmosphere - /// - public AtmosphereModule Atmosphere; - - /// - /// Base Properties of this Body - /// - public BaseModule Base; - - /// - /// Add bramble nodes to this planet and/or make this planet a bramble dimension - /// - public BrambleModule Bramble; - - /// - /// Add a cloaking field to this planet - /// - public CloakModule Cloak; - - /// - /// Add funnel from this planet to another - /// - public FunnelModule Funnel; - - /// - /// Generate the surface of this planet using a heightmap - /// - public HeightMapModule HeightMap; - - /// - /// Add lava to this planet - /// - public LavaModule Lava; - - /// - /// Procedural Generation - /// - public ProcGenModule ProcGen; - - /// - /// Spawn various objects on this body - /// - public PropModule Props; - - /// - /// A list of paths to child GameObjects to destroy on this planet - /// - public string[] removeChildren; - - /// - /// Creates a ring around the planet - /// - public RingModule Ring; - - /// - /// Add sand to this planet - /// - public SandModule Sand; - - /// - /// Rotation period in minutes. - /// - public float siderealPeriod; - - /// - /// Make this body a star - /// - public StarModule Star; - - /// - /// Add water to this planet - /// - public WaterModule Water; - - public PlanetConfig ConvertToPlanetConfig(PlanetConfig star) - { - PlanetConfig planetConfig = new PlanetConfig(); - planetConfig.name = star.name; - planetConfig.starSystem = star.starSystem; - planetConfig.Atmosphere = Atmosphere; - planetConfig.Base = Base; - planetConfig.Bramble = Bramble; - planetConfig.Cloak = Cloak; - planetConfig.Funnel = Funnel; - planetConfig.HeightMap = HeightMap; - planetConfig.Lava = Lava; - planetConfig.Orbit = star.Orbit; - planetConfig.ProcGen = ProcGen; - planetConfig.Props = Props; - planetConfig.removeChildren = removeChildren; - planetConfig.Ring = Ring; - planetConfig.Sand = Sand; - planetConfig.Water = Water; - planetConfig.Validate(); - planetConfig.Migrate(); - return planetConfig; - } - } } [JsonConverter(typeof(StringEnumConverter))] diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 5cd1026c..f42dc189 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -200,6 +200,10 @@ namespace NewHorizons.Handlers return false; } } + else if (body.Config.isStellarRemnant) + { + //Skip + } else { UpdateBody(body, existingPlanet); @@ -218,6 +222,10 @@ namespace NewHorizons.Handlers // If the ground state object isn't made yet do it later _nextPassBodies.Add(body); } + else if (body.Config.isStellarRemnant) + { + //Skip + } else { try @@ -500,7 +508,7 @@ namespace NewHorizons.Handlers else { StarLightController.AddStar(StarBuilder.Make(go, sector, body.Config.Star, body.Mod, false)); - StellarRemnantBuilder.Make(go, rb, body.Config, body.Mod, sphereOfInfluence); + StellarRemnantBuilder.Make(body, go, rb, body.Mod, Main.BodyDict[body.Config.starSystem].Where(x => x.Config.name == body.Config.name && body.Config.isStellarRemnant).FirstOrDefault()); } } diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 408fb1eb..99739838 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -69,6 +69,10 @@ "type": "boolean", "description": "Does this config describe a quantum state of a custom planet defined in another file?" }, + "isStellarRemnant": { + "type": "boolean", + "description": "Does this config describe a stellar remnant of a custom star defined in another file?" + }, "Lava": { "description": "Add lava to this planet", "$ref": "#/definitions/LavaModule"