Make it actually use the loaded star system name

This commit is contained in:
xen-42 2024-10-03 00:46:41 -04:00
parent 302425fcab
commit 443b03e6f8
2 changed files with 18 additions and 21 deletions

View File

@ -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<StarSystemConfig>(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<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?");
starSystemConfig.Migrate();
starSystemConfig.FixCoordinates();
var system = new NewHorizonsSystem(config.starSystem, starSystemConfig, $"", mod);
SystemDict.Add(config.starSystem, system);
BodyDict.Add(config.starSystem, new List<NewHorizonsBody>());
NHLogger.LogError($"System config for {config.starSystem} does not exist?");
return null;
}
// Has to happen after we make sure theres a system config

View File

@ -253,7 +253,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)
@ -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<ShipLogManager>(), xml, body);
}