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 a5fcb088..72613588 100644 --- a/NewHorizons/External/Configs/StarSystemConfig.cs +++ b/NewHorizons/External/Configs/StarSystemConfig.cs @@ -2,6 +2,7 @@ using System; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Linq; +using System.Xml; using NewHorizons.External.Modules; using NewHorizons.External.SerializableData; using Newtonsoft.Json; @@ -31,10 +32,29 @@ namespace NewHorizons.External.Configs public float farClipPlaneOverride; /// - /// Whether this system can be warped to via the warp drive. If you set factRequiredForWarp, this will be true. + /// 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 `canExitViaWarpDrive` and `factRequiredToExitViaWarpDrive` /// [DefaultValue(true)] public bool canEnterViaWarpDrive = true; + /// + /// The FactID that must be revealed before it can be warped to. Don't set `canEnterViaWarpDrive` to `false` if + /// you're using this, because it will be overwritten. + /// + public string factRequiredForWarp; + + /// + /// Can you use the warp drive to leave this system? If you set `factRequiredToExitViaWarpDrive` + /// this will be 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 factRequiredToExitViaWarpDrive; + /// /// Do you want a clean slate for this star system? Or will it be a modified version of the original. /// @@ -45,12 +65,6 @@ namespace NewHorizons.External.Configs /// [DefaultValue(true)] public bool enableTimeLoop = true; - /// - /// The FactID that must be revealed before it can be warped to. Don't set `canEnterViaWarpDrive` to `false` if - /// you're using this, because it will be overwritten. - /// - public string factRequiredForWarp; - /// /// The duration of the time loop in minutes. This is the time the sun explodes. End Times plays 85 seconds before this time, and your memories get sent back about 40 seconds after this time. /// @@ -414,6 +428,10 @@ namespace NewHorizons.External.Configs Vessel.warpExit.attachToVessel = true; } } + if (!string.IsNullOrEmpty(factRequiredToExitViaWarpDrive)) + { + canExitViaWarpDrive = true; + } } } } \ No newline at end of file diff --git a/NewHorizons/External/NewHorizonsSystem.cs b/NewHorizons/External/NewHorizonsSystem.cs index 0724a027..07f1ba08 100644 --- a/NewHorizons/External/NewHorizonsSystem.cs +++ b/NewHorizons/External/NewHorizonsSystem.cs @@ -1,6 +1,7 @@ using NewHorizons.External.Configs; using NewHorizons.External.Modules; using OWML.Common; +using System.Linq; namespace NewHorizons.External { @@ -19,6 +20,12 @@ namespace NewHorizons.External Config = config; RelativePath = relativePath; Mod = mod; + + // Backwards compat + if (new string[] { "2walker2.OogaBooga", "2walker2.EndingIfYouWarpHereYouAreMean", "FeldsparSystem" }.Contains(uniqueID)) + { + config.canExitViaWarpDrive = false; + } } } } diff --git a/NewHorizons/Handlers/StarChartHandler.cs b/NewHorizons/Handlers/StarChartHandler.cs index 3b874ee9..e0ed3585 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) @@ -56,12 +59,20 @@ namespace NewHorizons.Handlers _starSystemToFactID = new Dictionary(); _factIDToStarSystem = new Dictionary(); + _factRequiredToExitViaWarpDrive = string.Empty; + foreach (NewHorizonsSystem system in _systems) { - if (system.Config.factRequiredForWarp != default) + if (system.Config.factRequiredForWarp != default && system.UniqueID != "SolarSystem") { RegisterFactForSystem(system.Config.factRequiredForWarp, system.UniqueID); } + + if (system.UniqueID == Main.Instance.CurrentStarSystem && !string.IsNullOrEmpty(system.Config.factRequiredToExitViaWarpDrive)) + { + _factRequiredToExitViaWarpDrive = system.Config.factRequiredToExitViaWarpDrive; + _canExitViaWarpDrive = system.Config.canExitViaWarpDrive || !string.IsNullOrEmpty(_factRequiredToExitViaWarpDrive); + } } } @@ -88,6 +99,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; @@ -99,6 +114,9 @@ namespace NewHorizons.Handlers return ShipLogHandler.KnowsFact(factID); } + public static bool CanExitViaWarpDrive() => Main.Instance.CurrentStarSystem == "SolarSystem" || (_canExitViaWarpDrive + && (string.IsNullOrEmpty(_factRequiredToExitViaWarpDrive) || ShipLogHandler.KnowsFact(_factRequiredToExitViaWarpDrive))); + /// /// Is it actually a valid warp target /// @@ -113,21 +131,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 || system == "SolarSystem"; + + 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 - && Main.SystemDict[system].Config.canEnterViaWarpDrive + && 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); } } diff --git a/NewHorizons/Schemas/star_system_schema.json b/NewHorizons/Schemas/star_system_schema.json index 814773c5..68d3f216 100644 --- a/NewHorizons/Schemas/star_system_schema.json +++ b/NewHorizons/Schemas/star_system_schema.json @@ -20,9 +20,22 @@ }, "canEnterViaWarpDrive": { "type": "boolean", - "description": "Whether this system can be warped to via the warp drive. If you set factRequiredForWarp, this will be true.", + "description": "Whether this system can be warped to via the warp drive. If you set `factRequiredForWarp`, this will be true.\nDoes NOT effect the base SolarSystem. For that, see `canExitViaWarpDrive` and `factRequiredToExitViaWarpDrive`", "default": true }, + "factRequiredForWarp": { + "type": "string", + "description": "The FactID that must be revealed before it can be warped to. Don't set `canEnterViaWarpDrive` to `false` if\nyou're using this, because it will be overwritten." + }, + "canExitViaWarpDrive": { + "type": "boolean", + "description": "Can you use the warp drive to leave this system? If you set `factRequiredToExitViaWarpDrive`\nthis will be true.", + "default": true + }, + "factRequiredToExitViaWarpDrive": { + "type": "string", + "description": "The FactID that must be revealed for you to warp back to the main solar system from here. Don't set `canWarpHome`\nto `false` if you're using this, because it will be overwritten." + }, "destroyStockPlanets": { "type": "boolean", "description": "Do you want a clean slate for this star system? Or will it be a modified version of the original.", @@ -33,10 +46,6 @@ "description": "Should the time loop be enabled in this system?", "default": true }, - "factRequiredForWarp": { - "type": "string", - "description": "The FactID that must be revealed before it can be warped to. Don't set `canEnterViaWarpDrive` to `false` if\nyou're using this, because it will be overwritten." - }, "loopDuration": { "type": "number", "description": "The duration of the time loop in minutes. This is the time the sun explodes. End Times plays 85 seconds before this time, and your memories get sent back about 40 seconds after this time.", diff --git a/NewHorizons/manifest.json b/NewHorizons/manifest.json index ab7181ac..03b343b9 100644 --- a/NewHorizons/manifest.json +++ b/NewHorizons/manifest.json @@ -4,7 +4,7 @@ "author": "xen, Bwc9876, JohnCorby, MegaPiggy, Clay, Trifid, and friends", "name": "New Horizons", "uniqueName": "xen.NewHorizons", - "version": "1.22.5", + "version": "1.22.6", "owmlVersion": "2.12.1", "dependencies": [ "JohnCorby.VanillaFix", "xen.CommonCameraUtility", "dgarro.CustomShipLogModes" ], "conflicts": [ "PacificEngine.OW_CommonResources" ],