From 74b10f4e53fe8b0810a0c9c402ae989ebf7608cd Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 21 Jul 2023 11:15:24 -0400 Subject: [PATCH] Add entry positions to the api --- NewHorizons/INewHorizons.cs | 3 ++- NewHorizons/Main.cs | 51 +++++++++++++++++++---------------- NewHorizons/NewHorizonsApi.cs | 6 ++++- 3 files changed, 35 insertions(+), 25 deletions(-) diff --git a/NewHorizons/INewHorizons.cs b/NewHorizons/INewHorizons.cs index a284270e..d1872826 100644 --- a/NewHorizons/INewHorizons.cs +++ b/NewHorizons/INewHorizons.cs @@ -22,7 +22,8 @@ namespace NewHorizons /// /// /// - void AddShipLogXML(IModBehaviour mod, ShipLogManager manager, XElement xml, string planetName); + /// + void AddShipLogXML(IModBehaviour mod, ShipLogManager manager, XElement xml, string planetName, Dictionary entryPositions); /// /// Will load all configs in the regular folders (planets, systems, translations, etc) for this mod. diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index e204ccdc..fc497c91 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -600,6 +600,33 @@ namespace NewHorizons #region Load + public void LoadStarSystemConfig(StarSystemConfig starSystemConfig, string relativePath, IModBehaviour mod) + { + starSystemConfig.Migrate(); + starSystemConfig.FixCoordinates(); + + if (starSystemConfig.startHere) + { + // We always want to allow mods to overwrite setting the main SolarSystem as default but not the other way around + if (name != "SolarSystem") + { + SetDefaultSystem(name); + _currentStarSystem = name; + } + } + + if (SystemDict.ContainsKey(name)) + { + if (string.IsNullOrEmpty(SystemDict[name].Config.travelAudio) && SystemDict[name].Config.Skybox == null) + SystemDict[name].Mod = mod; + SystemDict[name].Config.Merge(starSystemConfig); + } + else + { + SystemDict[name] = new NewHorizonsSystem(name, starSystemConfig, relativePath, mod); + } + } + public void LoadConfigs(IModBehaviour mod) { try @@ -633,29 +660,7 @@ namespace NewHorizons var relativePath = file.Replace(folder, ""); var starSystemConfig = mod.ModHelper.Storage.Load(relativePath, false); - starSystemConfig.Migrate(); - starSystemConfig.FixCoordinates(); - - if (starSystemConfig.startHere) - { - // We always want to allow mods to overwrite setting the main SolarSystem as default but not the other way around - if (name != "SolarSystem") - { - SetDefaultSystem(name); - _currentStarSystem = name; - } - } - - if (SystemDict.ContainsKey(name)) - { - if (string.IsNullOrEmpty(SystemDict[name].Config.travelAudio) && SystemDict[name].Config.Skybox == null) - SystemDict[name].Mod = mod; - SystemDict[name].Config.Merge(starSystemConfig); - } - else - { - SystemDict[name] = new NewHorizonsSystem(name, starSystemConfig, relativePath, mod); - } + LoadStarSystemConfig(starSystemConfig, relativePath, mod); } } if (Directory.Exists(planetsFolder)) diff --git a/NewHorizons/NewHorizonsApi.cs b/NewHorizons/NewHorizonsApi.cs index fd2c8b44..dd5a524e 100644 --- a/NewHorizons/NewHorizonsApi.cs +++ b/NewHorizons/NewHorizonsApi.cs @@ -20,6 +20,7 @@ using System.Linq; using System.Xml.Linq; using UnityEngine; using UnityEngine.Events; +using static NewHorizons.External.Modules.ShipLogModule; namespace NewHorizons { @@ -65,7 +66,7 @@ namespace NewHorizons } } - public void AddShipLogXML(IModBehaviour mod, ShipLogManager manager, XElement xml, string planetName) + public void AddShipLogXML(IModBehaviour mod, ShipLogManager manager, XElement xml, string planetName, Dictionary entryPositions) { var body = new NewHorizonsBody(new PlanetConfig() { name = planetName, starSystem = Main.Instance.CurrentStarSystem }, mod); @@ -87,6 +88,9 @@ namespace NewHorizons } } + var system = new StarSystemConfig() { entryPositions = entryPositions.Select((pair) => new EntryPositionInfo() { id = pair.Key, position = pair.Value }).ToArray() }; + Main.Instance.LoadStarSystemConfig(system, null, mod); + RumorModeBuilder.AddShipLogXML(manager, xml, body); }