diff --git a/NewHorizons/Builder/Body/CometTailBuilder.cs b/NewHorizons/Builder/Body/CometTailBuilder.cs index 6cb8c267..95359416 100644 --- a/NewHorizons/Builder/Body/CometTailBuilder.cs +++ b/NewHorizons/Builder/Body/CometTailBuilder.cs @@ -1,6 +1,8 @@ using NewHorizons.External.Configs; +using NewHorizons.External.Modules; using NewHorizons.Utility; using UnityEngine; + namespace NewHorizons.Builder.Body { public static class CometTailBuilder @@ -12,17 +14,15 @@ namespace NewHorizons.Builder.Body if (_tailPrefab == null) _tailPrefab = SearchUtilities.Find("Comet_Body/Sector_CO/Effects_CO/Effects_CO_TailMeshes").InstantiateInactive().Rename("Prefab_CO_Tail").DontDestroyOnLoad(); } - public static void Make(GameObject planetGO, Sector sector, PlanetConfig config) + public static void Make(GameObject planetGO, Sector sector, CometTailModule cometTailModule, float surfaceSize) { - InitPrefab(); - var cometTail = GameObject.Instantiate(_tailPrefab, sector?.transform ?? planetGO.transform); cometTail.transform.position = planetGO.transform.position; cometTail.name = "CometTail"; - cometTail.transform.localScale = Vector3.one * config.Base.surfaceSize / 110; + cometTail.transform.localScale = Vector3.one * (cometTailModule.innerRadius ?? surfaceSize) / 110; - Vector3 alignment = new Vector3(0, 270, 90); - if (config.Base.cometTailRotation != null) alignment = config.Base.cometTailRotation; + var alignment = new Vector3(0, 270, 90); + if (cometTailModule.rotationOverride != null) alignment = cometTailModule.rotationOverride; cometTail.transform.rotation = Quaternion.Euler(alignment); diff --git a/NewHorizons/Builder/Body/ProxyBuilder.cs b/NewHorizons/Builder/Body/ProxyBuilder.cs index 15e6953e..9a48f7c4 100644 --- a/NewHorizons/Builder/Body/ProxyBuilder.cs +++ b/NewHorizons/Builder/Body/ProxyBuilder.cs @@ -194,9 +194,9 @@ namespace NewHorizons.Builder.Body } } - if (body.Config.Base.hasCometTail) + if (body.Config.CometTail != null) { - CometTailBuilder.Make(proxy, null, body.Config); + CometTailBuilder.Make(proxy, null, body.Config.CometTail, body.Config.Base.surfaceSize); } if (body.Config.Props?.proxyDetails != null) diff --git a/NewHorizons/External/Configs/PlanetConfig.cs b/NewHorizons/External/Configs/PlanetConfig.cs index c934a721..d0176289 100644 --- a/NewHorizons/External/Configs/PlanetConfig.cs +++ b/NewHorizons/External/Configs/PlanetConfig.cs @@ -21,6 +21,7 @@ namespace NewHorizons.External.Configs [JsonObject(Title = "Celestial Body")] public class PlanetConfig { + #region Fields /// /// Unique name of your planet /// @@ -32,6 +33,34 @@ namespace NewHorizons.External.Configs /// [DefaultValue("SolarSystem")] public string starSystem = "SolarSystem"; + /// + /// Does this config describe a quantum state of a custom planet defined in another file? + /// + public bool isQuantumState; + + /// + /// Does this config describe a stellar remnant of a custom star defined in another file? + /// + public bool isStellarRemnant; + + /// + /// Should this planet ever be shown on the title screen? + /// + [DefaultValue(true)] public bool canShowOnTitle = true; + + /// + /// `true` if you want to delete this planet + /// + public bool destroy; + + /// + /// A list of paths to child GameObjects to destroy on this planet + /// + public string[] removeChildren; + + #endregion + + #region Modules /// /// Add ambient lights to this body /// @@ -57,37 +86,11 @@ namespace NewHorizons.External.Configs /// public BrambleModule Bramble; - /// - /// Should this planet ever be shown on the title screen? - /// - [DefaultValue(true)] public bool canShowOnTitle = true; - - #region Obsolete - - [Obsolete("ChildrenToDestroy is deprecated, please use RemoveChildren instead")] - public string[] childrenToDestroy; - - [Obsolete("Singularity is deprecated, please use Props->singularities")] - public SingularityModule Singularity; - - [Obsolete("Signal is deprecated, please use Props->signals")] - public SignalModule Signal; - - [Obsolete("Ring is deprecated, please use Rings")] - public RingModule Ring; - - #endregion Obsolete - /// /// Add a cloaking field to this planet /// public CloakModule Cloak; - /// - /// `true` if you want to delete this planet - /// - public bool destroy; - /// /// Make this body into a focal point (barycenter) /// @@ -103,16 +106,6 @@ namespace NewHorizons.External.Configs /// public HeightMapModule HeightMap; - /// - /// Does this config describe a quantum state of a custom planet defined in another file? - /// - 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 /// @@ -138,11 +131,6 @@ namespace NewHorizons.External.Configs /// public ReferenceFrameModule ReferenceFrame; - /// - /// A list of paths to child GameObjects to destroy on this planet - /// - public string[] removeChildren; - /// /// Create rings around the planet /// @@ -183,11 +171,35 @@ namespace NewHorizons.External.Configs /// public VolumesModule Volumes; + /// + /// Add a comet tail to this body, like the Interloper + /// + public CometTailModule CometTail; + /// /// Extra data that may be used by extension mods /// public object extras; + #endregion + + #region Obsolete + + [Obsolete("ChildrenToDestroy is deprecated, please use RemoveChildren instead")] + public string[] childrenToDestroy; + + [Obsolete("Singularity is deprecated, please use Props->singularities")] + public SingularityModule Singularity; + + [Obsolete("Signal is deprecated, please use Props->signals")] + public SignalModule Signal; + + [Obsolete("Ring is deprecated, please use Rings")] + public RingModule Ring; + + #endregion Obsolete + + #region ctor validation and migration public PlanetConfig() { // Always have to have a base module @@ -566,6 +578,16 @@ namespace NewHorizons.External.Configs } } } + + if (Base.hasCometTail) + { + CometTail ??= new(); + if (Base.cometTailRotation != null) + { + CometTail.rotationOverride = Base.cometTailRotation; + } + } } + #endregion } } \ No newline at end of file diff --git a/NewHorizons/External/Modules/BaseModule.cs b/NewHorizons/External/Modules/BaseModule.cs index ffd754f5..2f36f5a4 100644 --- a/NewHorizons/External/Modules/BaseModule.cs +++ b/NewHorizons/External/Modules/BaseModule.cs @@ -25,11 +25,6 @@ namespace NewHorizons.External.Modules /// public bool centerOfSolarSystem; - /// - /// If it has a comet tail, it'll be oriented according to these Euler angles. - /// - public MVector3 cometTailRotation; - /// /// How gravity falls off with distance. Most planets use linear but the sun and some moons use inverseSquared. /// @@ -41,11 +36,6 @@ namespace NewHorizons.External.Modules /// public float groundSize; - /// - /// If you want the body to have a tail like the Interloper. - /// - public bool hasCometTail; - /// /// If the body should have a marker on the map screen. /// @@ -116,6 +106,12 @@ namespace NewHorizons.External.Modules [Obsolete("zeroGravityRadius is deprecated, please use Volumes->ZeroGravityVolumes instead")] public float zeroGravityRadius; + [Obsolete("hasCometTail is deprecated, please use CometTail instead")] + public bool hasCometTail; + + [Obsolete("cometTailRotation is deprecated, please use CometTail->rotationOverride instead")] + public MVector3 cometTailRotation; + #endregion Obsolete } } \ No newline at end of file diff --git a/NewHorizons/External/Modules/CometTailModule.cs b/NewHorizons/External/Modules/CometTailModule.cs new file mode 100644 index 00000000..2704ad1e --- /dev/null +++ b/NewHorizons/External/Modules/CometTailModule.cs @@ -0,0 +1,25 @@ +using NewHorizons.External.SerializableData; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NewHorizons.External.Modules +{ + [JsonObject] + public class CometTailModule + { + /// + /// Manually sets the local rotation + /// + public MVector3 rotationOverride; + + /// + /// Inner radius of the comet tail, defaults to match surfaceSize + /// + public float? innerRadius; + } +} diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index db6f8f22..9b7c90f0 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -599,9 +599,9 @@ namespace NewHorizons.Handlers AsteroidBeltBuilder.Make(body.Config.name, body.Config, body.Mod); } - if (body.Config.Base.hasCometTail) + if (body.Config.CometTail != null) { - CometTailBuilder.Make(go, sector, body.Config); + CometTailBuilder.Make(go, sector, body.Config.CometTail, body.Config.Base.surfaceSize); } if (body.Config.Lava != null)