diff --git a/NewHorizons/Builder/Body/ProxyBuilder.cs b/NewHorizons/Builder/Body/ProxyBuilder.cs index 1c8f08ab..5bbe0ae0 100644 --- a/NewHorizons/Builder/Body/ProxyBuilder.cs +++ b/NewHorizons/Builder/Body/ProxyBuilder.cs @@ -93,18 +93,21 @@ namespace NewHorizons.Builder.Body if (realSize < body.Config.Sand.size) realSize = body.Config.Sand.size; } // Could improve this to actually use the proper renders and materials - if (body.Config.Singularity != null) + if (body.Config.Props?.singularities != null) { - if (body.Config.Singularity.type == SingularityModule.SingularityType.BlackHole) + foreach(var singularity in body.Config.Props.singularities) { - MakeBlackHole(newProxy, body.Config.Singularity.size); - } - else - { - MakeWhiteHole(newProxy, body.Config.Singularity.size); - } + if (singularity.type == SingularityModule.SingularityType.BlackHole) + { + MakeBlackHole(newProxy, singularity.size); + } + else + { + MakeWhiteHole(newProxy, singularity.size); + } - if (realSize < body.Config.Singularity.size) realSize = body.Config.Singularity.size; + if (realSize < singularity.size) realSize = singularity.size; + } } if (body.Config.Base.hasCometTail) { diff --git a/NewHorizons/Builder/Body/SingularityBuilder.cs b/NewHorizons/Builder/Body/SingularityBuilder.cs index b9a031f6..ef261d82 100644 --- a/NewHorizons/Builder/Body/SingularityBuilder.cs +++ b/NewHorizons/Builder/Body/SingularityBuilder.cs @@ -5,6 +5,9 @@ using System; using NewHorizons.External.Modules.VariableSize; using UnityEngine; using Logger = NewHorizons.Utility.Logger; +using System.Collections.Generic; +using System.Linq; + namespace NewHorizons.Builder.Body { public static class SingularityBuilder @@ -18,61 +21,73 @@ namespace NewHorizons.Builder.Body private static readonly int DistortFadeDist = Shader.PropertyToID("_DistortFadeDist"); private static readonly int Color1 = Shader.PropertyToID("_Color"); - public static void Make(GameObject go, Sector sector, OWRigidbody OWRB, PlanetConfig config) + private static Dictionary _singularitiesByID; + + public static void Make(GameObject go, Sector sector, OWRigidbody OWRB, PlanetConfig config, SingularityModule singularity) { - var size = config.Singularity.size; - var pairedSingularity = config.Singularity.pairedSingularity; + // If we've reloaded the first one will now be null so we have to refresh the list + if (_singularitiesByID?.Values?.FirstOrDefault() == null) _singularitiesByID = new Dictionary(); - var polarity = config.Singularity.type; + var size = singularity.size; + var pairedSingularity = singularity.pairedSingularity; - bool isWormHole = config.Singularity?.targetStarSystem != null; + var polarity = singularity.type; + + bool isWormHole = singularity?.targetStarSystem != null; bool hasHazardVolume = !isWormHole && (pairedSingularity == null); - bool makeZeroGVolume = config.Singularity == null ? true : config.Singularity.makeZeroGVolume; + bool makeZeroGVolume = singularity == null ? true : singularity.makeZeroGVolume; - Vector3 localPosition = config.Singularity?.position == null ? Vector3.zero : (Vector3)config.Singularity.position; + Vector3 localPosition = singularity?.position == null ? Vector3.zero : singularity.position; GameObject newSingularity = null; switch (polarity) { case SingularityModule.SingularityType.BlackHole: - newSingularity = MakeBlackHole(go, sector, localPosition, size, hasHazardVolume, config.Singularity.targetStarSystem); + newSingularity = MakeBlackHole(go, sector, localPosition, size, hasHazardVolume, singularity.targetStarSystem); break; case SingularityModule.SingularityType.WhiteHole: newSingularity = MakeWhiteHole(go, sector, OWRB, localPosition, size, makeZeroGVolume); break; } + var uniqueID = string.IsNullOrEmpty(singularity.uniqueID) ? config.name : singularity.uniqueID; + _singularitiesByID.Add(uniqueID, newSingularity); + // Try to pair them - if (pairedSingularity != null && newSingularity != null) + if (!string.IsNullOrEmpty(pairedSingularity) && newSingularity != null) { - var pairedSingularityAO = AstroObjectLocator.GetAstroObject(pairedSingularity); - if (pairedSingularityAO != null) + if (_singularitiesByID.TryGetValue(pairedSingularity, out var pairedSingularityGO)) { switch (polarity) { case SingularityModule.SingularityType.BlackHole: - PairSingularities(newSingularity, pairedSingularityAO.gameObject); + PairSingularities(uniqueID, pairedSingularity, newSingularity, pairedSingularityGO); break; case SingularityModule.SingularityType.WhiteHole: - PairSingularities(pairedSingularityAO.gameObject, newSingularity); + PairSingularities(pairedSingularity, uniqueID, pairedSingularityGO, newSingularity); break; } } } } - public static void PairSingularities(GameObject blackHole, GameObject whiteHole) + public static void PairSingularities(string blackHoleID, string whiteHoleID, GameObject blackHole, GameObject whiteHole) { - Logger.Log($"Pairing singularities {blackHole?.name}, {whiteHole?.name}"); - try + if (blackHole == null || whiteHole == null) return; + + Logger.Log($"Pairing singularities [{blackHoleID}], [{whiteHoleID}]"); + + var whiteHoleVolume = whiteHole.GetComponentInChildren(); + var blackHoleVolume = blackHole.GetComponentInChildren(); + + if (whiteHoleVolume == null || blackHoleVolume == null) { - blackHole.GetComponentInChildren()._whiteHole = whiteHole.GetComponentInChildren(); - } - catch (Exception) - { - Logger.LogError($"Couldn't pair singularities"); + Logger.Log($"[{blackHoleID}] and [{whiteHoleID}] do not have compatible polarities"); + return; } + + blackHoleVolume._whiteHole = whiteHoleVolume; } public static GameObject MakeBlackHole(GameObject planetGO, Sector sector, Vector3 localPosition, float size, bool hasDestructionVolume, string targetSolarSystem, bool makeAudio = true) diff --git a/NewHorizons/Builder/General/GravityBuilder.cs b/NewHorizons/Builder/General/GravityBuilder.cs index 1a61f0f3..5fa6c33e 100644 --- a/NewHorizons/Builder/General/GravityBuilder.cs +++ b/NewHorizons/Builder/General/GravityBuilder.cs @@ -15,8 +15,8 @@ namespace NewHorizons.Builder.General var gravityRadius = GM / 0.1f; if (exponent == 2f) gravityRadius = Mathf.Sqrt(gravityRadius); - // To let you actually orbit things the way you would expect we cap this at 4x the diameter if its not a star or black hole (this is what giants deep has) - if (config.Star == null && config.Singularity == null) gravityRadius = Mathf.Min(gravityRadius, 4 * config.Base.surfaceSize); + // To let you actually orbit things the way you would expect we cap this at 4x the diameter if its not a star (this is what giants deep has) + if (config.Star == null) gravityRadius = Mathf.Min(gravityRadius, 4 * config.Base.surfaceSize); else gravityRadius = Mathf.Min(gravityRadius, 15 * config.Base.surfaceSize); if (config.Base.soiOverride != 0f) gravityRadius = config.Base.soiOverride; diff --git a/NewHorizons/Builder/Orbital/OrbitlineBuilder.cs b/NewHorizons/Builder/Orbital/OrbitlineBuilder.cs index e6ad0a53..006b63c0 100644 --- a/NewHorizons/Builder/Orbital/OrbitlineBuilder.cs +++ b/NewHorizons/Builder/Orbital/OrbitlineBuilder.cs @@ -52,7 +52,6 @@ namespace NewHorizons.Builder.Orbital if (config.Orbit.tint != null) color = config.Orbit.tint.ToColor(); else if (config.Star?.tint != null) color = config.Star.tint.ToColor(); else if (config.Atmosphere?.clouds?.tint != null) color = config.Atmosphere.clouds.tint.ToColor(); - else if (config.Singularity != null) color = new Color(1f, 0.5f, 1f); else if (config.Water != null) color = new Color(0.5f, 0.5f, 1f); else if (config.Lava != null) color = new Color(1f, 0.5f, 0.5f); else if (config.Atmosphere != null && config.Atmosphere.fogTint != null) color = config.Atmosphere.fogTint.ToColor(); diff --git a/NewHorizons/Builder/Props/PropBuildManager.cs b/NewHorizons/Builder/Props/PropBuildManager.cs index 5f488529..76123765 100644 --- a/NewHorizons/Builder/Props/PropBuildManager.cs +++ b/NewHorizons/Builder/Props/PropBuildManager.cs @@ -1,3 +1,4 @@ +using NewHorizons.Builder.Body; using NewHorizons.Builder.ShipLog; using NewHorizons.External.Configs; using OWML.Common; @@ -190,6 +191,13 @@ namespace NewHorizons.Builder.Props Logger.LogError($"Couldn't make quantum group \"{quantumGroup.id}\" for [{go.name}] : {ex.Message}, {ex.StackTrace}"); } } + } + if (config.Props.singularities != null) + { + foreach (var singularity in config.Props.singularities) + { + SingularityBuilder.Make(go, sector, go.GetComponent(), config, singularity); + } } } } diff --git a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs index 06be3068..171c1912 100644 --- a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs +++ b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs @@ -522,14 +522,6 @@ namespace NewHorizons.Builder.ShipLog { try { - switch (body.Config?.Singularity?.type) - { - case SingularityModule.SingularityType.BlackHole: - return Color.black; - case SingularityModule.SingularityType.WhiteHole: - return Color.white; - } - var starColor = body.Config?.Star?.tint; if (starColor != null) return starColor.ToColor(); @@ -555,6 +547,14 @@ namespace NewHorizons.Builder.ShipLog var sandColor = body.Config.Sand?.tint; if (sandColor != null) return sandColor.ToColor(); + + switch (body.Config?.Props?.singularities?.FirstOrDefault()?.type) + { + case SingularityModule.SingularityType.BlackHole: + return Color.black; + case SingularityModule.SingularityType.WhiteHole: + return Color.white; + } } catch (Exception) { diff --git a/NewHorizons/External/Configs/PlanetConfig.cs b/NewHorizons/External/Configs/PlanetConfig.cs index 842ca7e3..075ec326 100644 --- a/NewHorizons/External/Configs/PlanetConfig.cs +++ b/NewHorizons/External/Configs/PlanetConfig.cs @@ -45,6 +45,9 @@ namespace NewHorizons.External.Configs [Obsolete("ChildrenToDestroy is deprecated, please use RemoveChildren instead")] public string[] childrenToDestroy; + [Obsolete("Singularity is deprecated, please use Props->singularities")] + public SingularityModule Singularity; + #endregion Obsolete /// @@ -133,11 +136,6 @@ namespace NewHorizons.External.Configs /// public SignalModule Signal; - /// - /// Add a black or white hole to this planet - /// - public SingularityModule Singularity; - /// /// Spawn the player at this planet /// @@ -323,6 +321,13 @@ namespace NewHorizons.External.Configs } } + // Singularity is now a list in props so you can have many per planet + if (Singularity != null) + { + if (Props == null) Props = new PropModule(); + if (Props.singularities == null) Props.singularities = new SingularityModule[0]; + Props.singularities = Props.singularities.Append(Singularity).ToArray(); + } } } } \ No newline at end of file diff --git a/NewHorizons/External/Modules/PropModule.cs b/NewHorizons/External/Modules/PropModule.cs index 85c7c157..d0db2bf4 100644 --- a/NewHorizons/External/Modules/PropModule.cs +++ b/NewHorizons/External/Modules/PropModule.cs @@ -6,6 +6,7 @@ using System.Runtime.Serialization; using Newtonsoft.Json; using Newtonsoft.Json.Converters; using System; +using NewHorizons.External.Modules.VariableSize; namespace NewHorizons.External.Modules { @@ -77,6 +78,11 @@ namespace NewHorizons.External.Modules /// public VolcanoInfo[] volcanoes; + /// + /// Add black/white-holes to this planet + /// + public SingularityModule[] singularities; + [JsonObject] public class ScatterInfo { diff --git a/NewHorizons/External/Modules/VariableSize/SingularityModule.cs b/NewHorizons/External/Modules/VariableSize/SingularityModule.cs index 001dcb56..6068907b 100644 --- a/NewHorizons/External/Modules/VariableSize/SingularityModule.cs +++ b/NewHorizons/External/Modules/VariableSize/SingularityModule.cs @@ -1,4 +1,4 @@ -using System.ComponentModel; +using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Runtime.Serialization; using NewHorizons.Utility; @@ -24,11 +24,16 @@ namespace NewHorizons.External.Modules.VariableSize [DefaultValue(true)] public bool makeZeroGVolume = true; /// - /// The name of the white hole or black hole that is paired to this one. If you don't set a value, entering will kill + /// The uniqueID of the white hole or black hole that is paired to this one. If you don't set a value, entering will kill /// the player /// public string pairedSingularity; + /// + /// The uniqueID of this white hole or black hole. If not set it will default to the name of the planet + /// + public string uniqueID; + /// /// Position of the singularity /// diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 2c7246f3..a65a77db 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -469,11 +469,6 @@ namespace NewHorizons.Handlers SignalBuilder.Make(go, sector, body.Config.Signal, body.Mod); } - if (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);