From 443b03e6f8e126079806f84ffe44c7e50d2f144a Mon Sep 17 00:00:00 2001 From: xen-42 Date: Thu, 3 Oct 2024 00:46:41 -0400 Subject: [PATCH] Make it actually use the loaded star system name --- NewHorizons/Main.cs | 33 ++++++++++++++------------------- NewHorizons/NewHorizonsApi.cs | 6 ++++-- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index facd1493..fb94ff6a 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -585,8 +585,15 @@ namespace NewHorizons #region Load - public void LoadStarSystemConfig(string starSystemName, StarSystemConfig starSystemConfig, string relativePath, IModBehaviour mod) + public void LoadStarSystemConfig(StarSystemConfig starSystemConfig, string relativePath, IModBehaviour mod) { + if (string.IsNullOrEmpty(starSystemConfig.name)) + { + starSystemConfig.name = Path.GetFileNameWithoutExtension(relativePath); + } + + var starSystemName = starSystemConfig.name; + starSystemConfig.Migrate(); starSystemConfig.FixCoordinates(); @@ -639,13 +646,12 @@ namespace NewHorizons foreach (var file in systemFiles) { - var starSystemName = Path.GetFileNameWithoutExtension(file); - - NHLogger.LogVerbose($"Loading system {starSystemName}"); - var relativePath = file.Replace(folder, ""); + + NHLogger.LogVerbose($"Loading system {Path.GetFileNameWithoutExtension(relativePath)}"); + var starSystemConfig = mod.ModHelper.Storage.Load(relativePath, false); - LoadStarSystemConfig(starSystemName, starSystemConfig, relativePath, mod); + LoadStarSystemConfig(starSystemConfig, relativePath, mod); } } if (Directory.Exists(planetsFolder)) @@ -771,19 +777,8 @@ namespace NewHorizons { if (!SystemDict.ContainsKey(config.starSystem)) { - // Since we didn't load it earlier there shouldn't be a star system config - var starSystemConfig = mod.ModHelper.Storage.Load(Path.Combine("systems", config.starSystem + ".json"), false); - if (starSystemConfig == null) starSystemConfig = new StarSystemConfig(); - else NHLogger.LogWarning($"Loaded system config for {config.starSystem}. Why wasn't this loaded earlier?"); - - starSystemConfig.Migrate(); - starSystemConfig.FixCoordinates(); - - var system = new NewHorizonsSystem(config.starSystem, starSystemConfig, $"", mod); - - SystemDict.Add(config.starSystem, system); - - BodyDict.Add(config.starSystem, new List()); + NHLogger.LogError($"System config for {config.starSystem} does not exist?"); + return null; } // Has to happen after we make sure theres a system config diff --git a/NewHorizons/NewHorizonsApi.cs b/NewHorizons/NewHorizonsApi.cs index 0b25a339..17fcb113 100644 --- a/NewHorizons/NewHorizonsApi.cs +++ b/NewHorizons/NewHorizonsApi.cs @@ -253,7 +253,8 @@ namespace NewHorizons public void DefineStarSystem(string name, string config, IModBehaviour mod) { var starSystemConfig = JsonConvert.DeserializeObject(config); - Main.Instance.LoadStarSystemConfig(name, starSystemConfig, null, mod); + starSystemConfig.name = name; + Main.Instance.LoadStarSystemConfig(starSystemConfig, null, mod); } public (CharacterDialogueTree, RemoteDialogueTrigger) CreateDialogueFromXML(string textAssetID, string xml, string dialogueInfo, GameObject planetGO) @@ -304,6 +305,7 @@ namespace NewHorizons var system = new StarSystemConfig() { + name = starSystem, entryPositions = entryPositions? .Select((pair) => new EntryPositionInfo() { id = pair.Key, position = pair.Value }) .ToArray(), @@ -312,7 +314,7 @@ namespace NewHorizons .ToArray() }; - Main.Instance.LoadStarSystemConfig(starSystem, system, null, mod); + Main.Instance.LoadStarSystemConfig(system, null, mod); RumorModeBuilder.AddShipLogXML(GameObject.FindObjectOfType(), xml, body); }