From 0f6f67e55fa8645db6a17ef813d785aa91d87efa Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Fri, 1 Sep 2023 18:01:01 -0700 Subject: [PATCH 01/12] edit config --- NewHorizons/External/Configs/PlanetConfig.cs | 3 +-- NewHorizons/External/Configs/StarSystemConfig.cs | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/NewHorizons/External/Configs/PlanetConfig.cs b/NewHorizons/External/Configs/PlanetConfig.cs index d1248900..1ec1fe72 100644 --- a/NewHorizons/External/Configs/PlanetConfig.cs +++ b/NewHorizons/External/Configs/PlanetConfig.cs @@ -25,9 +25,8 @@ namespace NewHorizons.External.Configs { #region Fields /// - /// Unique name of your planet + /// Unique name of your planet. If not specified, the file name (without the extension) is used. /// - [Required] public string name; /// diff --git a/NewHorizons/External/Configs/StarSystemConfig.cs b/NewHorizons/External/Configs/StarSystemConfig.cs index bd998909..025465bd 100644 --- a/NewHorizons/External/Configs/StarSystemConfig.cs +++ b/NewHorizons/External/Configs/StarSystemConfig.cs @@ -15,6 +15,11 @@ namespace NewHorizons.External.Configs [JsonObject] public class StarSystemConfig { + /// + /// Unique name of your system. If not specified, the file name (without the extension) is used. + /// + public string name; + /// /// In this system should the player be able to rotate their map camera freely or be stuck above the plane of the solar system? /// From bd3177c71a5e3bf6e59c8873b9cc70dba3a478cb Mon Sep 17 00:00:00 2001 From: Ben C Date: Sat, 2 Sep 2023 01:03:25 +0000 Subject: [PATCH 02/12] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 6 +----- NewHorizons/Schemas/star_system_schema.json | 4 ++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 1cb51aec..39da4c40 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -4,14 +4,10 @@ "type": "object", "description": "Describes a celestial body to generate", "additionalProperties": false, - "required": [ - "name" - ], "properties": { "name": { "type": "string", - "description": "Unique name of your planet", - "minLength": 1 + "description": "Unique name of your planet. If not specified, the file name (without the extension) is used." }, "starSystem": { "type": "string", diff --git a/NewHorizons/Schemas/star_system_schema.json b/NewHorizons/Schemas/star_system_schema.json index 0cba8563..047e7dd1 100644 --- a/NewHorizons/Schemas/star_system_schema.json +++ b/NewHorizons/Schemas/star_system_schema.json @@ -5,6 +5,10 @@ "description": "Configuration for a specific star system", "additionalProperties": false, "properties": { + "name": { + "type": "string", + "description": "Unique name of your system. If not specified, the file name (without the extension) is used." + }, "freeMapAngle": { "type": "boolean", "description": "In this system should the player be able to rotate their map camera freely or be stuck above the plane of the solar system?" From d917b04bb2791eea6724f947439aa733a2bb9d14 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Fri, 1 Sep 2023 18:05:41 -0700 Subject: [PATCH 03/12] OrbitModule.semiMajorAxis does not default to 5000, stop lying in schema exporter --- SchemaExporter/SchemaExporter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SchemaExporter/SchemaExporter.cs b/SchemaExporter/SchemaExporter.cs index 6aa43dcd..0096fa49 100644 --- a/SchemaExporter/SchemaExporter.cs +++ b/SchemaExporter/SchemaExporter.cs @@ -81,7 +81,7 @@ public static class SchemaExporter switch (_title) { case "Celestial Body Schema": - schema.Definitions["OrbitModule"].Properties["semiMajorAxis"].Default = 5000f; + // obsolete/ignored stuff schema.Definitions["NomaiTextType"].Enumeration.Remove("cairn"); schema.Definitions["NomaiTextType"].EnumerationNames.Remove("Cairn"); schema.Definitions["NomaiTextType"].Enumeration.Remove("cairnVariant"); From dc03cd28448cad718aaa8d6e0be63526dc06220e Mon Sep 17 00:00:00 2001 From: Ben C Date: Sat, 2 Sep 2023 01:08:03 +0000 Subject: [PATCH 04/12] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 1 - 1 file changed, 1 deletion(-) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 5a1a7f7c..beca9fc9 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -1094,7 +1094,6 @@ "type": "number", "description": "The semi-major axis of the ellipse that is the body's orbit. For a circular orbit this is the radius.", "format": "float", - "default": 5000.0, "minimum": 0.0 }, "inclination": { From 795af7db59436fede5f286079628c7756c99c7f5 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Fri, 1 Sep 2023 21:31:48 -0400 Subject: [PATCH 05/12] Revert "OrbitModule.semiMajorAxis does not default to 5000, stop lying in schema exporter" This reverts commit d917b04bb2791eea6724f947439aa733a2bb9d14. --- SchemaExporter/SchemaExporter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SchemaExporter/SchemaExporter.cs b/SchemaExporter/SchemaExporter.cs index 0096fa49..6aa43dcd 100644 --- a/SchemaExporter/SchemaExporter.cs +++ b/SchemaExporter/SchemaExporter.cs @@ -81,7 +81,7 @@ public static class SchemaExporter switch (_title) { case "Celestial Body Schema": - // obsolete/ignored stuff + schema.Definitions["OrbitModule"].Properties["semiMajorAxis"].Default = 5000f; schema.Definitions["NomaiTextType"].Enumeration.Remove("cairn"); schema.Definitions["NomaiTextType"].EnumerationNames.Remove("Cairn"); schema.Definitions["NomaiTextType"].Enumeration.Remove("cairnVariant"); From 2ab04d065d17758a7c222e081fec77cae97312ec Mon Sep 17 00:00:00 2001 From: Ben C Date: Sat, 2 Sep 2023 01:34:05 +0000 Subject: [PATCH 06/12] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 1 + 1 file changed, 1 insertion(+) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index beca9fc9..5a1a7f7c 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -1094,6 +1094,7 @@ "type": "number", "description": "The semi-major axis of the ellipse that is the body's orbit. For a circular orbit this is the radius.", "format": "float", + "default": 5000.0, "minimum": 0.0 }, "inclination": { From 45ce315bfc1ddfed01704824b3943a8209f0a1ce Mon Sep 17 00:00:00 2001 From: xen-42 Date: Thu, 3 Oct 2024 00:34:12 -0400 Subject: [PATCH 07/12] John wins --- NewHorizons/External/Configs/PlanetConfig.cs | 2 -- SchemaExporter/SchemaExporter.cs | 1 - 2 files changed, 3 deletions(-) diff --git a/NewHorizons/External/Configs/PlanetConfig.cs b/NewHorizons/External/Configs/PlanetConfig.cs index 1ec1fe72..d7656a6a 100644 --- a/NewHorizons/External/Configs/PlanetConfig.cs +++ b/NewHorizons/External/Configs/PlanetConfig.cs @@ -11,9 +11,7 @@ using Newtonsoft.Json; using System; using System.Collections.Generic; using System.ComponentModel; -using System.ComponentModel.DataAnnotations; using System.Linq; -using UnityEngine; namespace NewHorizons.External.Configs { diff --git a/SchemaExporter/SchemaExporter.cs b/SchemaExporter/SchemaExporter.cs index 6aa43dcd..21ef3d13 100644 --- a/SchemaExporter/SchemaExporter.cs +++ b/SchemaExporter/SchemaExporter.cs @@ -81,7 +81,6 @@ public static class SchemaExporter switch (_title) { case "Celestial Body Schema": - schema.Definitions["OrbitModule"].Properties["semiMajorAxis"].Default = 5000f; schema.Definitions["NomaiTextType"].Enumeration.Remove("cairn"); schema.Definitions["NomaiTextType"].EnumerationNames.Remove("Cairn"); schema.Definitions["NomaiTextType"].Enumeration.Remove("cairnVariant"); From 59055c1ad06a28eb983db81bd755b90fe891a077 Mon Sep 17 00:00:00 2001 From: Ben C Date: Thu, 3 Oct 2024 04:35:37 +0000 Subject: [PATCH 08/12] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 1 - 1 file changed, 1 deletion(-) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 5a1a7f7c..beca9fc9 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -1094,7 +1094,6 @@ "type": "number", "description": "The semi-major axis of the ellipse that is the body's orbit. For a circular orbit this is the radius.", "format": "float", - "default": 5000.0, "minimum": 0.0 }, "inclination": { From 6f4e7cc4b376c7fff8cacf1a4aa2921d23690e93 Mon Sep 17 00:00:00 2001 From: xen-42 Date: Thu, 3 Oct 2024 00:36:27 -0400 Subject: [PATCH 09/12] Fall back to file name if planet name not defined --- NewHorizons/External/NewHorizonBody.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/NewHorizons/External/NewHorizonBody.cs b/NewHorizons/External/NewHorizonBody.cs index fa80de75..5af5cd59 100644 --- a/NewHorizons/External/NewHorizonBody.cs +++ b/NewHorizons/External/NewHorizonBody.cs @@ -3,6 +3,7 @@ using NewHorizons.Utility.Files; using NewHorizons.Utility.OWML; using OWML.Common; using System; +using System.IO; using System.Linq; using UnityEngine; @@ -16,6 +17,12 @@ namespace NewHorizons.External Mod = mod; RelativePath = relativePath; + // Fall back to file name if name not given + if (!string.IsNullOrEmpty(relativePath) && string.IsNullOrEmpty(config.name)) + { + config.name = Path.GetFileNameWithoutExtension(relativePath); + } + Migrate(); } From 443b03e6f8e126079806f84ffe44c7e50d2f144a Mon Sep 17 00:00:00 2001 From: xen-42 Date: Thu, 3 Oct 2024 00:46:41 -0400 Subject: [PATCH 10/12] 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); } From dc1a0b08327872d3aaa46fd89edad47a3a573d9c Mon Sep 17 00:00:00 2001 From: xen-42 Date: Thu, 3 Oct 2024 00:52:02 -0400 Subject: [PATCH 11/12] Dont explode --- NewHorizons/Main.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 14e67eb0..4217f0ee 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -909,8 +909,15 @@ namespace NewHorizons { if (!SystemDict.ContainsKey(config.starSystem)) { - NHLogger.LogError($"System config for {config.starSystem} does not exist?"); - return null; + var starSystemConfig = new StarSystemConfig() { name = config.starSystem }; + starSystemConfig.Migrate(); + starSystemConfig.FixCoordinates(); + + var system = new NewHorizonsSystem(config.starSystem, starSystemConfig, $"", mod); + + SystemDict.Add(config.starSystem, system); + + BodyDict.Add(config.starSystem, new List()); } // Has to happen after we make sure theres a system config From 81e7fbef7da10fa8e805f3e93595ec221b5ffab9 Mon Sep 17 00:00:00 2001 From: xen-42 Date: Thu, 3 Oct 2024 00:59:41 -0400 Subject: [PATCH 12/12] Update Main.cs --- NewHorizons/Main.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 4217f0ee..f8f18718 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -173,7 +173,7 @@ namespace NewHorizons BodyDict["SolarSystem"] = new List(); BodyDict["EyeOfTheUniverse"] = new List(); // Keep this empty tho fr - SystemDict["SolarSystem"] = new NewHorizonsSystem("SolarSystem", new StarSystemConfig(), "", Instance) + SystemDict["SolarSystem"] = new NewHorizonsSystem("SolarSystem", new StarSystemConfig() { name = "SolarSystem" }, "", Instance) { Config = { @@ -189,7 +189,7 @@ namespace NewHorizons } } }; - SystemDict["EyeOfTheUniverse"] = new NewHorizonsSystem("EyeOfTheUniverse", new StarSystemConfig(), "", Instance) + SystemDict["EyeOfTheUniverse"] = new NewHorizonsSystem("EyeOfTheUniverse", new StarSystemConfig() { name = "EyeOfTheUniverse" }, "", Instance) { Config = {