diff --git a/NewHorizons/Components/ShipLog/ShipLogStarChartMode.cs b/NewHorizons/Components/ShipLog/ShipLogStarChartMode.cs index 2c1828d1..86d6cfa8 100644 --- a/NewHorizons/Components/ShipLog/ShipLogStarChartMode.cs +++ b/NewHorizons/Components/ShipLog/ShipLogStarChartMode.cs @@ -96,7 +96,7 @@ namespace NewHorizons.Components.ShipLog if (_cardTemplate == null) { var panRoot = SearchUtilities.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/ShipLogPivot/ShipLogCanvas/DetectiveMode/ScaleRoot/PanRoot"); - _cardTemplate = Instantiate(panRoot.GetComponentInChildren().gameObject); + _cardTemplate = Instantiate(panRoot.GetComponentInChildren(true).gameObject); _cardTemplate.SetActive(false); } @@ -209,6 +209,12 @@ namespace NewHorizons.Components.ShipLog private void UpdateMapCamera() { + if (_starSystemCards.Count == 0) + { + NHLogger.LogWarning("Showing star chart mode when there are no avaialble systems"); + return; + } + Vector2 b = -_starSystemCards[_cardIndex].transform.localPosition; float num = Mathf.InverseLerp(_startPanTime, _startPanTime + _panDuration, Time.unscaledTime); num = 1f - (num - 1f) * (num - 1f); diff --git a/NewHorizons/External/Configs/StarSystemConfig.cs b/NewHorizons/External/Configs/StarSystemConfig.cs index a087587b..72613588 100644 --- a/NewHorizons/External/Configs/StarSystemConfig.cs +++ b/NewHorizons/External/Configs/StarSystemConfig.cs @@ -33,7 +33,7 @@ namespace NewHorizons.External.Configs /// /// Whether this system can be warped to via the warp drive. If you set `factRequiredForWarp`, this will be true. - /// Does NOT effect the base SolarSystem. For that, see `canWarpHome` and `factRequiredForWarpHome` + /// Does NOT effect the base SolarSystem. For that, see `canExitViaWarpDrive` and `factRequiredToExitViaWarpDrive` /// [DefaultValue(true)] public bool canEnterViaWarpDrive = true; @@ -44,16 +44,16 @@ namespace NewHorizons.External.Configs public string factRequiredForWarp; /// - /// Can you use the warp drive to return home to the Outer Wilds from this system? If you set `factRequiredForWarpHome` + /// Can you use the warp drive to leave this system? If you set `factRequiredToExitViaWarpDrive` /// this will be true. /// - [DefaultValue(true)] public bool canWarpHome = true; + [DefaultValue(true)] public bool canExitViaWarpDrive = true; /// /// The FactID that must be revealed for you to warp back to the main solar system from here. Don't set `canWarpHome` /// to `false` if you're using this, because it will be overwritten. /// - public string factRequiredForWarpHome; + public string factRequiredToExitViaWarpDrive; /// /// Do you want a clean slate for this star system? Or will it be a modified version of the original. @@ -428,9 +428,9 @@ namespace NewHorizons.External.Configs Vessel.warpExit.attachToVessel = true; } } - if (!string.IsNullOrEmpty(factRequiredForWarpHome)) + if (!string.IsNullOrEmpty(factRequiredToExitViaWarpDrive)) { - canWarpHome = true; + canExitViaWarpDrive = true; } } } diff --git a/NewHorizons/External/NewHorizonsSystem.cs b/NewHorizons/External/NewHorizonsSystem.cs index 08bc01a7..07f1ba08 100644 --- a/NewHorizons/External/NewHorizonsSystem.cs +++ b/NewHorizons/External/NewHorizonsSystem.cs @@ -24,7 +24,7 @@ namespace NewHorizons.External // Backwards compat if (new string[] { "2walker2.OogaBooga", "2walker2.EndingIfYouWarpHereYouAreMean", "FeldsparSystem" }.Contains(uniqueID)) { - config.canWarpHome = false; + config.canExitViaWarpDrive = false; } } } diff --git a/NewHorizons/Handlers/StarChartHandler.cs b/NewHorizons/Handlers/StarChartHandler.cs index 6cd6cf22..3e4c53dd 100644 --- a/NewHorizons/Handlers/StarChartHandler.cs +++ b/NewHorizons/Handlers/StarChartHandler.cs @@ -16,6 +16,9 @@ namespace NewHorizons.Handlers private static Dictionary _starSystemToFactID; private static Dictionary _factIDToStarSystem; + private static bool _canExitViaWarpDrive; + private static string _factRequiredToExitViaWarpDrive; + private static NewHorizonsSystem[] _systems; public static void Init(NewHorizonsSystem[] systems) @@ -63,9 +66,10 @@ namespace NewHorizons.Handlers RegisterFactForSystem(system.Config.factRequiredForWarp, system.UniqueID); } - if (system.UniqueID == Main.Instance.CurrentStarSystem && !string.IsNullOrEmpty(system.Config.factRequiredForWarpHome)) + if (system.UniqueID == Main.Instance.CurrentStarSystem && !string.IsNullOrEmpty(system.Config.factRequiredToExitViaWarpDrive)) { - RegisterFactForSystem(system.Config.factRequiredForWarpHome, "SolarSystem"); + _factRequiredToExitViaWarpDrive = system.Config.factRequiredToExitViaWarpDrive; + _canExitViaWarpDrive = system.Config.canExitViaWarpDrive || !string.IsNullOrEmpty(_factRequiredToExitViaWarpDrive); } } } @@ -93,6 +97,10 @@ namespace NewHorizons.Handlers /// public static bool HasUnlockedSystem(string system) { + // If warp drive is entirely disabled, then no + if (!CanExitViaWarpDrive()) + return false; + if (_starSystemToFactID == null || _starSystemToFactID.Count == 0) return true; @@ -104,6 +112,9 @@ namespace NewHorizons.Handlers return ShipLogHandler.KnowsFact(factID); } + public static bool CanExitViaWarpDrive() => _canExitViaWarpDrive + && (string.IsNullOrEmpty(_factRequiredToExitViaWarpDrive) || ShipLogHandler.KnowsFact(_factRequiredToExitViaWarpDrive)); + /// /// Is it actually a valid warp target /// @@ -118,29 +129,55 @@ namespace NewHorizons.Handlers else if (system.Equals("EyeOfTheUniverse")) canWarpTo = false; else if (config.Spawn?.shipSpawn != null) canWarpTo = true; - var canEnterViaWarpDrive = Main.SystemDict[system].Config.canEnterViaWarpDrive; + var canEnterViaWarpDrive = Main.SystemDict[system].Config.canEnterViaWarpDrive || system == "SolarSystem"; - // For the base solar system, use canWarpHome instead for better mod compat - if (system.Equals("SolarSystem")) - { - canEnterViaWarpDrive = Main.SystemDict[Main.Instance.CurrentStarSystem].Config.canWarpHome; - } + var canExitViaWarpDrive = CanExitViaWarpDrive(); + + // Make base system always ignore canExitViaWarpDrive + if (Main.Instance.CurrentStarSystem == "SolarSystem") + canExitViaWarpDrive = true; + + NHLogger.Log(canEnterViaWarpDrive, canExitViaWarpDrive, system, HasUnlockedSystem(system)); return canWarpTo && canEnterViaWarpDrive + && canExitViaWarpDrive && system != Main.Instance.CurrentStarSystem && HasUnlockedSystem(system); } public static void OnRevealFact(string factID) { + if (!string.IsNullOrEmpty(_factRequiredToExitViaWarpDrive) && factID == _factRequiredToExitViaWarpDrive) + { + if (!Main.HasWarpDrive) + { + Main.Instance.EnableWarpDrive(); + // Add all cards that now work + foreach (var starSystem in Main.SystemDict.Keys) + { + if (CanWarpToSystem(starSystem)) + { + ShipLogStarChartMode.AddSystemCard(starSystem); + } + } + } + else + { + NHLogger.LogWarning("Warp drive was enabled before learning fact?"); + } + } + if (_factIDToStarSystem != null && _factIDToStarSystem.TryGetValue(factID, out var systemUnlocked)) { + var knowsWarpFact = string.IsNullOrEmpty(_factRequiredToExitViaWarpDrive) || ShipLogHandler.KnowsFact(_factRequiredToExitViaWarpDrive); + NHLogger.Log($"Just learned [{factID}] and unlocked [{systemUnlocked}]"); - if (!Main.HasWarpDrive) + if (!Main.HasWarpDrive && knowsWarpFact) + { Main.Instance.EnableWarpDrive(); - if (ShipLogStarChartMode != null) - ShipLogStarChartMode.AddSystemCard(systemUnlocked); + } + ShipLogStarChartMode?.AddSystemCard(systemUnlocked); } }