diff --git a/NewHorizons/External/Configs/PlanetConfig.cs b/NewHorizons/External/Configs/PlanetConfig.cs
index 28f00318..f1828c7d 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
{
@@ -25,9 +23,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 72613588..4440c5d5 100644
--- a/NewHorizons/External/Configs/StarSystemConfig.cs
+++ b/NewHorizons/External/Configs/StarSystemConfig.cs
@@ -16,6 +16,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?
///
diff --git a/NewHorizons/External/NewHorizonBody.cs b/NewHorizons/External/NewHorizonBody.cs
index 6779e526..a38af522 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();
}
diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs
index b9d0ecbb..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 =
{
@@ -677,8 +677,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();
@@ -748,13 +755,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))
@@ -903,11 +909,7 @@ 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?");
-
+ var starSystemConfig = new StarSystemConfig() { name = config.starSystem };
starSystemConfig.Migrate();
starSystemConfig.FixCoordinates();
diff --git a/NewHorizons/NewHorizonsApi.cs b/NewHorizons/NewHorizonsApi.cs
index 6c46ac3c..c9193f61 100644
--- a/NewHorizons/NewHorizonsApi.cs
+++ b/NewHorizons/NewHorizonsApi.cs
@@ -261,7 +261,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)
@@ -312,6 +313,7 @@ namespace NewHorizons
var system = new StarSystemConfig()
{
+ name = starSystem,
entryPositions = entryPositions?
.Select((pair) => new EntryPositionInfo() { id = pair.Key, position = pair.Value })
.ToArray(),
@@ -320,7 +322,7 @@ namespace NewHorizons
.ToArray()
};
- Main.Instance.LoadStarSystemConfig(starSystem, system, null, mod);
+ Main.Instance.LoadStarSystemConfig(system, null, mod);
RumorModeBuilder.AddShipLogXML(GameObject.FindObjectOfType(), xml, body);
}
diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json
index 1f2fd960..6582e215 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",
@@ -1118,7 +1114,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": {
diff --git a/NewHorizons/Schemas/star_system_schema.json b/NewHorizons/Schemas/star_system_schema.json
index 68d3f216..0bd6055c 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?"
diff --git a/SchemaExporter/SchemaExporter.cs b/SchemaExporter/SchemaExporter.cs
index 3874aa87..9dd0b459 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");