From e74dbfb8633a0025e1d6f9eda509707c142d048a Mon Sep 17 00:00:00 2001 From: Joshua Thome Date: Fri, 29 Jul 2022 14:22:20 -0500 Subject: [PATCH] Handle potentially missing ship log canvas --- NewHorizons/Handlers/StarChartHandler.cs | 61 +++++++++++++----------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/NewHorizons/Handlers/StarChartHandler.cs b/NewHorizons/Handlers/StarChartHandler.cs index 6f3b1fe9..69e542c7 100644 --- a/NewHorizons/Handlers/StarChartHandler.cs +++ b/NewHorizons/Handlers/StarChartHandler.cs @@ -20,32 +20,40 @@ namespace NewHorizons.Handlers var shipLogRoot = SearchUtilities.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/ShipLogPivot/ShipLogCanvas"); - var starChartLog = new GameObject("StarChartMode"); - starChartLog.SetActive(false); - starChartLog.transform.parent = shipLogRoot.transform; - starChartLog.transform.localScale = Vector3.one * 1f; - starChartLog.transform.localPosition = Vector3.zero; - starChartLog.transform.localRotation = Quaternion.Euler(0, 0, 0); + if (shipLogRoot != null) + { + var starChartLog = new GameObject("StarChartMode"); + starChartLog.SetActive(false); + starChartLog.transform.parent = shipLogRoot.transform; + starChartLog.transform.localScale = Vector3.one * 1f; + starChartLog.transform.localPosition = Vector3.zero; + starChartLog.transform.localRotation = Quaternion.Euler(0, 0, 0); - ShipLogStarChartMode = starChartLog.AddComponent(); + ShipLogStarChartMode = starChartLog.AddComponent(); - var reticleImage = GameObject.Instantiate(SearchUtilities.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/ShipLogPivot/ShipLogCanvas/DetectiveMode/ReticleImage (1)/"), starChartLog.transform); + var reticleImage = GameObject.Instantiate(SearchUtilities.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/ShipLogPivot/ShipLogCanvas/DetectiveMode/ReticleImage (1)/"), starChartLog.transform); - var scaleRoot = new GameObject("ScaleRoot"); - scaleRoot.transform.parent = starChartLog.transform; - scaleRoot.transform.localScale = Vector3.one; - scaleRoot.transform.localPosition = Vector3.zero; - scaleRoot.transform.localRotation = Quaternion.Euler(0, 0, 0); + var scaleRoot = new GameObject("ScaleRoot"); + scaleRoot.transform.parent = starChartLog.transform; + scaleRoot.transform.localScale = Vector3.one; + scaleRoot.transform.localPosition = Vector3.zero; + scaleRoot.transform.localRotation = Quaternion.Euler(0, 0, 0); - var panRoot = new GameObject("PanRoot"); - panRoot.transform.parent = scaleRoot.transform; - panRoot.transform.localScale = Vector3.one; - panRoot.transform.localPosition = Vector3.zero; - panRoot.transform.localRotation = Quaternion.Euler(0, 0, 0); + var panRoot = new GameObject("PanRoot"); + panRoot.transform.parent = scaleRoot.transform; + panRoot.transform.localScale = Vector3.one; + panRoot.transform.localPosition = Vector3.zero; + panRoot.transform.localRotation = Quaternion.Euler(0, 0, 0); - var centerPromptList = shipLogRoot.transform.Find("ScreenPromptListScaleRoot/ScreenPromptList_Center")?.GetComponent(); - var upperRightPromptList = shipLogRoot.transform.Find("ScreenPromptListScaleRoot/ScreenPromptList_UpperRight")?.GetComponent(); - var oneShotSource = SearchUtilities.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/OneShotAudio_ShipLog")?.GetComponent(); + var centerPromptList = shipLogRoot.transform.Find("ScreenPromptListScaleRoot/ScreenPromptList_Center")?.GetComponent(); + var upperRightPromptList = shipLogRoot.transform.Find("ScreenPromptListScaleRoot/ScreenPromptList_UpperRight")?.GetComponent(); + var oneShotSource = SearchUtilities.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/OneShotAudio_ShipLog")?.GetComponent(); + + ShipLogStarChartMode.Initialize( + centerPromptList, + upperRightPromptList, + oneShotSource); + } _starSystemToFactID = new Dictionary(); _factIDToStarSystem = new Dictionary(); @@ -57,11 +65,6 @@ namespace NewHorizons.Handlers RegisterFactForSystem(system.Config.factRequiredForWarp, system.UniqueID); } } - - ShipLogStarChartMode.Initialize( - centerPromptList, - upperRightPromptList, - oneShotSource); } public static bool CanWarp() @@ -98,8 +101,10 @@ namespace NewHorizons.Handlers if (_factIDToStarSystem.TryGetValue(factID, out var systemUnlocked)) { Logger.Log($"Just learned [{factID}] and unlocked [{systemUnlocked}]"); - if (!Main.HasWarpDrive) Main.Instance.EnableWarpDrive(); - ShipLogStarChartMode.AddSystemCard(systemUnlocked); + if (!Main.HasWarpDrive) + Main.Instance.EnableWarpDrive(); + if (ShipLogStarChartMode != null) + ShipLogStarChartMode.AddSystemCard(systemUnlocked); } }