From a8c4641743bd5053814bc45223c5864fd3864094 Mon Sep 17 00:00:00 2001 From: Magnus Date: Sun, 4 Aug 2024 13:32:15 -0700 Subject: [PATCH 1/5] Fix documentation error and add log for future debuging --- NewHorizons/NewHorizonsApi.cs | 8 +++++--- docs/src/content/docs/guides/extending-configs.md | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/NewHorizons/NewHorizonsApi.cs b/NewHorizons/NewHorizonsApi.cs index 6a165fa2..dea9f8eb 100644 --- a/NewHorizons/NewHorizonsApi.cs +++ b/NewHorizons/NewHorizonsApi.cs @@ -143,9 +143,11 @@ namespace NewHorizons public object QueryBody(Type outType, string bodyName, string jsonPath) { var planet = Main.BodyDict[Main.Instance.CurrentStarSystem].Find((b) => b.Config.name == bodyName); - return planet == null - ? null - : QueryJson(outType, Path.Combine(planet.Mod.ModHelper.Manifest.ModFolderPath, planet.RelativePath), jsonPath); + if (planet == null){ + NHLogger.LogError($"Could not find planet with body name {bodyName}.") + return null; + } + return QueryJson(outType, Path.Combine(planet.Mod.ModHelper.Manifest.ModFolderPath, planet.RelativePath), jsonPath); } public T QueryBody(string bodyName, string jsonPath) diff --git a/docs/src/content/docs/guides/extending-configs.md b/docs/src/content/docs/guides/extending-configs.md index 0d3ee903..63b39fc5 100644 --- a/docs/src/content/docs/guides/extending-configs.md +++ b/docs/src/content/docs/guides/extending-configs.md @@ -49,7 +49,7 @@ Then, use the `QueryBody` method: var api = ModHelper.Interactions.TryGetModApi("xen.NewHorizons"); api.GetBodyLoadedEvent().AddListener((name) => { ModHelper.Console.WriteLine($"Body: {name} Loaded!"); - var data = api.QueryBody("$.extras.myCoolExtensionData", name); + var data = api.QueryBody(name, "$.extras.myCoolExtensionData"); // Makes sure the module is not null if (data != null) { ModHelper.Console.WriteLine($"myCoolExtensionProperty for {name} is {data.myCoolExtensionProperty}!"); From 1fa4664b348eaf2bb1006e87ea74d3d202e8aeed Mon Sep 17 00:00:00 2001 From: Magnus Date: Mon, 5 Aug 2024 12:13:51 -0700 Subject: [PATCH 2/5] Added missing semicolon --- NewHorizons/NewHorizonsApi.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NewHorizons/NewHorizonsApi.cs b/NewHorizons/NewHorizonsApi.cs index dea9f8eb..40362fb2 100644 --- a/NewHorizons/NewHorizonsApi.cs +++ b/NewHorizons/NewHorizonsApi.cs @@ -144,7 +144,7 @@ namespace NewHorizons { var planet = Main.BodyDict[Main.Instance.CurrentStarSystem].Find((b) => b.Config.name == bodyName); if (planet == null){ - NHLogger.LogError($"Could not find planet with body name {bodyName}.") + NHLogger.LogError($"Could not find planet with body name {bodyName}."); return null; } return QueryJson(outType, Path.Combine(planet.Mod.ModHelper.Manifest.ModFolderPath, planet.RelativePath), jsonPath); @@ -163,6 +163,7 @@ namespace NewHorizons public object QuerySystem(Type outType, string jsonPath) { var system = Main.SystemDict[Main.Instance.CurrentStarSystem]; + NHLogger.Log("System Relative Path: " + system.RelativePath); return system == null ? null : QueryJson(outType, Path.Combine(system.Mod.ModHelper.Manifest.ModFolderPath, system.RelativePath), jsonPath); From 5fae85f209584453e38fd8e611e33f05169e0591 Mon Sep 17 00:00:00 2001 From: Magnus Date: Mon, 5 Aug 2024 12:14:20 -0700 Subject: [PATCH 3/5] Set the SolarSystem's relative path if changed by a mod. --- NewHorizons/Main.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 4df680c9..5a5060d0 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -695,6 +695,9 @@ namespace NewHorizons if (SystemDict[starSystemName].Config.GlobalMusic == null && SystemDict[starSystemName].Config.Skybox == null) SystemDict[starSystemName].Mod = mod; SystemDict[starSystemName].Config.Merge(starSystemConfig); + // If a mod contains a change to the default system, set the relative path. + // Warning: If multiple systems make changes to the default system, only the relativePath will be set to the last mod loaded. + SystemDict[starSystemName].RelativePath = relativePath; } else { From a6037db5628b9176c0c36ea479e3608e01561a2b Mon Sep 17 00:00:00 2001 From: xen-42 Date: Mon, 5 Aug 2024 15:35:37 -0400 Subject: [PATCH 4/5] Only change relative path for base system, else log a warning --- NewHorizons/Main.cs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 79606f29..b80cf1e3 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -694,14 +694,26 @@ namespace NewHorizons if (SystemDict.ContainsKey(starSystemName)) { + // Both changing the Mod and RelativePath are weird and will likely cause incompat issues if two mods both affected the same system + // It's mostly just to fix up the config compared to the default one NH makes for the base StarSystem + if (SystemDict[starSystemName].Config.GlobalMusic == null && SystemDict[starSystemName].Config.Skybox == null) + { SystemDict[starSystemName].Mod = mod; - if (SystemDict[starSystemName].Config.extras == null) - SystemDict[starSystemName].RelativePath = relativePath; - SystemDict[starSystemName].Config.Merge(starSystemConfig); + } + // If a mod contains a change to the default system, set the relative path. // Warning: If multiple systems make changes to the default system, only the relativePath will be set to the last mod loaded. - SystemDict[starSystemName].RelativePath = relativePath; + if (string.IsNullOrEmpty(SystemDict[starSystemName].RelativePath)) + { + SystemDict[starSystemName].RelativePath = relativePath; + } + else + { + NHLogger.LogWarning($"Two (or more) mods are making system changes to {starSystemName} which may result in errors"); + } + + SystemDict[starSystemName].Config.Merge(starSystemConfig); } else { From fb00001e36f9c89373e04a1c4b5b1b1887e0b655 Mon Sep 17 00:00:00 2001 From: xen-42 Date: Wed, 7 Aug 2024 14:22:43 -0400 Subject: [PATCH 5/5] Remove debug log --- NewHorizons/NewHorizonsApi.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/NewHorizons/NewHorizonsApi.cs b/NewHorizons/NewHorizonsApi.cs index 40362fb2..6c46ac3c 100644 --- a/NewHorizons/NewHorizonsApi.cs +++ b/NewHorizons/NewHorizonsApi.cs @@ -163,7 +163,6 @@ namespace NewHorizons public object QuerySystem(Type outType, string jsonPath) { var system = Main.SystemDict[Main.Instance.CurrentStarSystem]; - NHLogger.Log("System Relative Path: " + system.RelativePath); return system == null ? null : QueryJson(outType, Path.Combine(system.Mod.ModHelper.Manifest.ModFolderPath, system.RelativePath), jsonPath);