Consistency in Planet/System Config Name (#727)

## Improvements
- Consistency between planet and system name: use config value,
otherwise use file name
This commit is contained in:
xen-42 2024-10-03 01:03:45 -04:00 committed by GitHub
commit 0d283ac9b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 37 additions and 26 deletions

View File

@ -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
/// <summary>
/// Unique name of your planet
/// Unique name of your planet. If not specified, the file name (without the extension) is used.
/// </summary>
[Required]
public string name;
/// <summary>

View File

@ -16,6 +16,11 @@ namespace NewHorizons.External.Configs
[JsonObject]
public class StarSystemConfig
{
/// <summary>
/// Unique name of your system. If not specified, the file name (without the extension) is used.
/// </summary>
public string name;
/// <summary>
/// In this system should the player be able to rotate their map camera freely or be stuck above the plane of the solar system?
/// </summary>

View File

@ -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();
}

View File

@ -173,7 +173,7 @@ namespace NewHorizons
BodyDict["SolarSystem"] = new List<NewHorizonsBody>();
BodyDict["EyeOfTheUniverse"] = new List<NewHorizonsBody>(); // 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<StarSystemConfig>(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<StarSystemConfig>(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();

View File

@ -261,7 +261,8 @@ namespace NewHorizons
public void DefineStarSystem(string name, string config, IModBehaviour mod)
{
var starSystemConfig = JsonConvert.DeserializeObject<StarSystemConfig>(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<ShipLogManager>(), xml, body);
}

View File

@ -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": {

View File

@ -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?"

View File

@ -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");