From 5625fd394e780ccc9d24835a17e9a3ab1a92f7d6 Mon Sep 17 00:00:00 2001 From: FreezeDriedMangoes Date: Wed, 29 Jun 2022 21:31:23 -0400 Subject: [PATCH] switched to a better method of connecting nodes that are created before the dimension they link to --- .../Builder/Props/BrambleNodeBuilder.cs | 32 ++++++++++++------- NewHorizons/Handlers/PlanetCreationHandler.cs | 7 +++- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/NewHorizons/Builder/Props/BrambleNodeBuilder.cs b/NewHorizons/Builder/Props/BrambleNodeBuilder.cs index 7df9e709..dc4d752d 100644 --- a/NewHorizons/Builder/Props/BrambleNodeBuilder.cs +++ b/NewHorizons/Builder/Props/BrambleNodeBuilder.cs @@ -11,18 +11,28 @@ namespace NewHorizons.Builder.Props { public static class BrambleNodeBuilder { - private static Dictionary unpairedNodes = new Dictionary(); + // keys are all dimension names that have been referenced by at least one node but do not (yet) exist + // values are all nodes' warp controllers that link to a given dimension + // unpairedNodes[name of dimension that doesn't exist yet] => List{warp controller for node that links to that dimension, ...} + private static Dictionary> unpairedNodes = new(); - public static void PairUnpairedNodes() + public static void PairUnpairedNodesForDimension(string dimensionName, AstroObject dimensionAO = null) { - // 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) + if (!unpairedNodes.ContainsKey(dimensionName)) return; + + foreach (var warpVolume in unpairedNodes[dimensionName]) { - var success = Pair(unpairedNodes[config], config.linksTo); - if (success) unpairedNodes.Remove(config); + Pair(warpVolume, dimensionName, dimensionAO); } + + unpairedNodes.Remove(dimensionName); + } + + private static void RecordUnpairedNode(InnerFogWarpVolume warpVolume, string linksTo) + { + if (!unpairedNodes.ContainsKey(linksTo)) unpairedNodes[linksTo] = new(); + + unpairedNodes[linksTo].Add(warpVolume); } private static OuterFogWarpVolume GetOuterFogWarpVolumeFromAstroObject(GameObject go) @@ -37,9 +47,9 @@ namespace NewHorizons.Builder.Props return outerFogWarpVolume; } - private static bool Pair(InnerFogWarpVolume nodeWarp, string destinationName) + private static bool Pair(InnerFogWarpVolume nodeWarp, string destinationName, AstroObject dimensionAO = null) { - var destinationAO = AstroObjectLocator.GetAstroObject(destinationName); // find child "Sector/OuterWarp" + var destinationAO = dimensionAO ?? AstroObjectLocator.GetAstroObject(destinationName); // find child "Sector/OuterWarp" if (destinationAO == null) return false; var destination = GetOuterFogWarpVolumeFromAstroObject(destinationAO.gameObject); @@ -93,7 +103,7 @@ namespace NewHorizons.Builder.Props warpController._attachedBody = go.GetComponent(); // I don't think this is necessary, it seems to be set correctly on its own 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; + if (!success) RecordUnpairedNode(warpController, config.linksTo); //var exitPointsParent = SearchUtilities.FindChild(brambleNode, "FogWarpExitPoints"); // "ExitPoint", "ExitPoint (1)" ... "ExitPoint (5)" //var exitPointsNames = new string[] diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index f28d98a9..79a1c191 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -286,7 +286,7 @@ namespace NewHorizons.Handlers if (ao.GetAstroObjectName() == AstroObject.Name.CustomString) { - AstroObjectLocator.RegisterCustomAstroObject(ao); + AstroObjectLocator.RegisterCustomAstroObject(ao); } return go; @@ -432,6 +432,11 @@ namespace NewHorizons.Handlers if (body.Config?.Bramble?.nodes != null) { BrambleNodeBuilder.Make(go, sector, body.Config.Bramble.nodes); + + if (body.Config.Bramble.dimension != null) + { + BrambleNodeBuilder.PairUnpairedNodesForDimension(body.Config.name, body.Object.GetComponent()); + } } if (body.Config.Ring != null)