From 0c420e61e74ba0447fbb8a4968c2629718d76c76 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 5 Jul 2022 23:12:23 -0400 Subject: [PATCH] Fix null stuff + NHAO --- .../Builder/Body/BrambleDimensionBuilder.cs | 29 +++++++++---------- .../Builder/Props/BrambleNodeBuilder.cs | 14 ++++----- NewHorizons/Handlers/PlanetCreationHandler.cs | 3 +- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/NewHorizons/Builder/Body/BrambleDimensionBuilder.cs b/NewHorizons/Builder/Body/BrambleDimensionBuilder.cs index a65849da..4796405e 100644 --- a/NewHorizons/Builder/Body/BrambleDimensionBuilder.cs +++ b/NewHorizons/Builder/Body/BrambleDimensionBuilder.cs @@ -26,12 +26,12 @@ namespace NewHorizons.Builder.Body // keys are all node names that have been referenced as an exit by at least one dimension but do not (yet) exist // values are all dimensions' warp controllers that link to a given dimension // unpairedNodes[name of node that doesn't exist yet] => List{warp controller for dimension that exits to that node, ...} - private static Dictionary> _unpairedDimensions = new(); + private static Dictionary> _unpairedDimensions; public static void Init() { // Just in case something went wrong and a dimension never got paired last time - _unpairedDimensions.Clear(); + _unpairedDimensions = new(); } public static GameObject Make(NewHorizonsBody body) @@ -42,19 +42,18 @@ namespace NewHorizons.Builder.Body var dimensionPrefab = SearchUtilities.Find("DB_HubDimension_Body"); var dimension = dimensionPrefab.InstantiateInactive(); - PlanetCreationHandler.UpdateBodyOrbit(body, dimension); + // Fix AO + var ao = dimension.GetComponent(); + var nhao = dimension.AddComponent(); + nhao.CopyPropertiesFrom(ao); + Component.Destroy(ao); - // fix name - var ao = dimension.GetComponent(); - ao.IsDimension = true; + nhao.IsDimension = true; var name = body.Config.name ?? "Custom Bramble Dimension"; - ao._customName = name; - ao._name = AstroObject.Name.CustomString; + nhao._customName = name; + nhao._name = AstroObject.Name.CustomString; dimension.name = name.Replace(" ", "").Replace("'", "") + "_Body"; - // set position - ao.transform.position = body.Config.Orbit.staticPosition; - // 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 = dimension.FindChild("Sector_HubDimension"); dimensionSector.name = "Sector"; @@ -74,9 +73,9 @@ namespace NewHorizons.Builder.Body intr.name = "Interactibles"; GameObject.Destroy(intr); - // set up warps + // Set up warps var outerFogWarpVolume = exitWarps.GetComponent(); - outerFogWarpVolume._senderWarps.Clear(); + outerFogWarpVolume._senderWarps = new List(); outerFogWarpVolume._linkedInnerWarpVolume = null; outerFogWarpVolume._name = OuterFogWarpVolume.Name.None; @@ -97,14 +96,14 @@ namespace NewHorizons.Builder.Body public static void PairExit(string exitName, OuterFogWarpVolume warpController) { - if (!BrambleNodeBuilder.namedNodes.ContainsKey(exitName)) + if (!BrambleNodeBuilder.NamedNodes.ContainsKey(exitName)) { if (!_unpairedDimensions.ContainsKey(exitName)) _unpairedDimensions[exitName] = new(); _unpairedDimensions[exitName].Add(warpController); return; } - warpController._linkedInnerWarpVolume = BrambleNodeBuilder.namedNodes[exitName]; + warpController._linkedInnerWarpVolume = BrambleNodeBuilder.NamedNodes[exitName]; } public static void FinishPairingDimensionsForExitNode(string nodeName) diff --git a/NewHorizons/Builder/Props/BrambleNodeBuilder.cs b/NewHorizons/Builder/Props/BrambleNodeBuilder.cs index e1da4ad6..94056b93 100644 --- a/NewHorizons/Builder/Props/BrambleNodeBuilder.cs +++ b/NewHorizons/Builder/Props/BrambleNodeBuilder.cs @@ -23,15 +23,15 @@ namespace NewHorizons.Builder.Props private static Dictionary> _unpairedNodes = new(); private static Dictionary> _propogatedSignals = null; - public static readonly Dictionary namedNodes = new(); - public static readonly Dictionary builtBrambleNodes = new(); + public static Dictionary NamedNodes { get; private set; } + public static Dictionary BuiltBrambleNodes { get; private set; } public static void Init() { - _unpairedNodes.Clear(); - _propogatedSignals.Clear(); - namedNodes.Clear(); - builtBrambleNodes.Clear(); + _unpairedNodes = new(); + _propogatedSignals = null; + NamedNodes = new(); + BuiltBrambleNodes = new(); } public static void FinishPairingNodesForDimension(string dimensionName, AstroObject dimensionAO = null) @@ -199,7 +199,7 @@ namespace NewHorizons.Builder.Props // if (config.name != null) { - namedNodes[config.name] = warpController; + NamedNodes[config.name] = warpController; BrambleDimensionBuilder.FinishPairingDimensionsForExitNode(config.name); } diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index f8716fbb..7dbe1f88 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -611,7 +611,8 @@ namespace NewHorizons.Handlers newAO._primaryBody = primary; // Since we destroyed the AO we have to replace links to it in other places - newAO.gameObject.GetComponentInChildren()._referenceFrame._attachedAstroObject = newAO; + var referenceFrame = newAO.gameObject.GetComponentInChildren()._referenceFrame; + if (referenceFrame != null) referenceFrame._attachedAstroObject = newAO; // QM and stuff don't have orbit lines var orbitLine = go.GetComponentInChildren()?.gameObject;