diff --git a/NewHorizons/Builder/Body/BrambleDimensionBuilder.cs b/NewHorizons/Builder/Body/BrambleDimensionBuilder.cs index c8288f45..435f731b 100644 --- a/NewHorizons/Builder/Body/BrambleDimensionBuilder.cs +++ b/NewHorizons/Builder/Body/BrambleDimensionBuilder.cs @@ -5,17 +5,30 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using UnityEngine; +using static NewHorizons.External.Modules.BrambleModule; namespace NewHorizons.Builder.Body { - public class BrambleDimensionBuilder + public static class BrambleDimensionBuilder { - public void Make() + public static GameObject Make(NewHorizonsBody body) { - var dimensionPrefab = SearchUtilities.Find("DB_HubDimension_Body/Sector_HubDimension"); + var config = body.Config.Bramble.dimension; + + // spawn the dimension body + var dimensionPrefab = SearchUtilities.Find("DB_HubDimension_Body"); var dimension = GameObject.Instantiate(dimensionPrefab); - //dimension.name = config.rename ?? "Custom Bramble Dimension"; - + var ao = dimension.GetComponent(); + + // fix name + var name = body.Config.name ?? "Custom Bramble Dimension"; + ao._customName = name; + ao._name = AstroObject.Name.CustomString; + dimension.name = name.Replace(" ", "").Replace("'", "") + "_Body"; + + // TODO: radius (need to determine what the base radius is first) + + // fix children's names and remove base game props (mostly just bramble nodes that are children to Interactibles) and set up the OuterWarp child var dimensionSector = SearchUtilities.FindChild(dimension, "Sector_HubDimension"); dimensionSector.name = "Sector"; var atmo = SearchUtilities.FindChild(dimension, "Atmosphere_HubDimension"); @@ -25,6 +38,7 @@ namespace NewHorizons.Builder.Body var intr = SearchUtilities.FindChild(dimension, "Interactables_HubDimension"); var exitWarps = SearchUtilities.FindChild(intr, "OuterWarp_Hub"); + exitWarps.name = "OuterWarp"; exitWarps.transform.parent = dimensionSector.transform; atmo.name = "Atmosphere"; geom.name = "Geometry"; // disable this? @@ -33,7 +47,9 @@ namespace NewHorizons.Builder.Body intr.name = "Interactibles"; GameObject.Destroy(intr); - // TODO: set "exitWarps/ExitPoint", "exitWarp/ExitPoint (1)", ... "exitWarp/ExitPoint (5)" + // TODO MAYBE: set "exitWarps/ExitPoint", "exitWarp/ExitPoint (1)", ... "exitWarp/ExitPoint (5)" + + return dimension; } } } diff --git a/NewHorizons/Builder/Props/BrambleNodeBuilder.cs b/NewHorizons/Builder/Props/BrambleNodeBuilder.cs index 687a755c..7df9e709 100644 --- a/NewHorizons/Builder/Props/BrambleNodeBuilder.cs +++ b/NewHorizons/Builder/Props/BrambleNodeBuilder.cs @@ -5,18 +5,64 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using UnityEngine; +using static NewHorizons.External.Modules.BrambleModule; namespace NewHorizons.Builder.Props { - public class BrambleNodeBuilder + public static class BrambleNodeBuilder { - + private static Dictionary unpairedNodes = new Dictionary(); - // DB_EscapePodDimension_Body/Sector_EscapePodDimension/Interactables_EscapePodDimension/InnerWarp_ToAnglerNest // need to change the light shaft color - // DB_ExitOnlyDimension_Body/Sector_ExitOnlyDimension/Interactables_ExitOnlyDimension/InnerWarp_ToExitOnly // need to change the colors - // DB_HubDimension_Body/Sector_HubDimension/Interactables_HubDimension/InnerWarp_ToCluster // need to delete the child "Signal_Harmonica" + public static void PairUnpairedNodes() + { + // copy the keys since we'll be modifying the dictionary as we loop over it + var configsToCheck = unpairedNodes.Keys.ToList(); + + foreach (var config in configsToCheck) + { + var success = Pair(unpairedNodes[config], config.linksTo); + if (success) unpairedNodes.Remove(config); + } + } - public void Make(GameObject go, Sector sector, BrambleNodeConfig config) + private static OuterFogWarpVolume GetOuterFogWarpVolumeFromAstroObject(GameObject go) + { + var sector = SearchUtilities.FindChild(go, "Sector"); + if (sector == null) return null; + + var outerWarpGO = SearchUtilities.FindChild(sector, "OuterWarp"); + if (outerWarpGO == null) return null; + + var outerFogWarpVolume = outerWarpGO.GetComponent(); + return outerFogWarpVolume; + } + + private static bool Pair(InnerFogWarpVolume nodeWarp, string destinationName) + { + var destinationAO = AstroObjectLocator.GetAstroObject(destinationName); // find child "Sector/OuterWarp" + if (destinationAO == null) return false; + + var destination = GetOuterFogWarpVolumeFromAstroObject(destinationAO.gameObject); + if (destination == null) return false; + + nodeWarp._linkedOuterWarpVolume = destination; + return true; + } + + + // DB_EscapePodDimension_Body/Sector_EscapePodDimension/Interactables_EscapePodDimension/InnerWarp_ToAnglerNest // need to change the light shaft color + // DB_ExitOnlyDimension_Body/Sector_ExitOnlyDimension/Interactables_ExitOnlyDimension/InnerWarp_ToExitOnly // need to change the colors + // DB_HubDimension_Body/Sector_HubDimension/Interactables_HubDimension/InnerWarp_ToCluster // need to delete the child "Signal_Harmonica" + + public static void Make(GameObject go, Sector sector, BrambleNodeInfo[] configs) + { + foreach(var config in configs) + { + Make(go, sector, config); + } + } + + public static GameObject Make(GameObject go, Sector sector, BrambleNodeInfo config) { // // spawn the bramble node @@ -45,8 +91,9 @@ namespace NewHorizons.Builder.Props var warpController = brambleNode.GetComponent(); warpController._sector = sector; warpController._attachedBody = go.GetComponent(); // I don't think this is necessary, it seems to be set correctly on its own - // warpController._linkedOuterWarpVolume = the outer warp volume of the dimension this node leads to - // warpController._containerWarpVolume = the OuterFogWarpVolume of the dimension this node is inside of (null if this node is not inside of a bramble dimension (eg it's sitting on a planet or something)) + warpController._containerWarpVolume = GetOuterFogWarpVolumeFromAstroObject(go); // the OuterFogWarpVolume of the dimension this node is inside of (null if this node is not inside of a bramble dimension (eg it's sitting on a planet or something)) + var success = Pair(warpController, config.linksTo); + if (!success) unpairedNodes[config] = warpController; //var exitPointsParent = SearchUtilities.FindChild(brambleNode, "FogWarpExitPoints"); // "ExitPoint", "ExitPoint (1)" ... "ExitPoint (5)" //var exitPointsNames = new string[] @@ -68,6 +115,10 @@ namespace NewHorizons.Builder.Props // // TODO: support adding signals to these nodes // + + + // Done! + return brambleNode; } } } diff --git a/NewHorizons/External/Modules/BrambleModule.cs b/NewHorizons/External/Modules/BrambleModule.cs index 405ce008..43e8a076 100644 --- a/NewHorizons/External/Modules/BrambleModule.cs +++ b/NewHorizons/External/Modules/BrambleModule.cs @@ -51,6 +51,11 @@ namespace NewHorizons.External.Modules /// public MVector3 rotation; + /// + /// The physical scale of the node + /// + public float scale; + /// /// The name of the planet that hosts the dimension this node links to /// diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 003cbe4e..f28d98a9 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -264,7 +264,36 @@ namespace NewHorizons.Handlers // Only called when making new planets public static GameObject GenerateBody(NewHorizonsBody body, bool defaultPrimaryToSun = false) - { + { + if (body.Config?.Bramble?.dimension != null) + { + return GenerateBrambleDimensionBody(body); + } + else + { + return GenerateStandardBody(body, defaultPrimaryToSun); + } + } + + public static GameObject GenerateBrambleDimensionBody(NewHorizonsBody body) + { + var go = BrambleDimensionBuilder.Make(body); + var ao = go.GetComponent(); + var sector = SearchUtilities.FindChild(go, "Sector").GetComponent(); + var owRigidBody = go.GetComponent(); + + go = SharedGenerateBody(body, go, sector, owRigidBody); + + if (ao.GetAstroObjectName() == AstroObject.Name.CustomString) + { + AstroObjectLocator.RegisterCustomAstroObject(ao); + } + + return go; + } + + public static GameObject GenerateStandardBody(NewHorizonsBody body, bool defaultPrimaryToSun = false) + { AstroObject primaryBody; if (body.Config.Orbit.primaryBody != null) { @@ -399,6 +428,11 @@ namespace NewHorizons.Handlers { StarLightController.AddStar(StarBuilder.Make(go, sector, body.Config.Star)); } + + if (body.Config?.Bramble?.nodes != null) + { + BrambleNodeBuilder.Make(go, sector, body.Config.Bramble.nodes); + } if (body.Config.Ring != null) {