diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index fc497c91..8dcfaa2f 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -600,7 +600,7 @@ namespace NewHorizons #region Load - public void LoadStarSystemConfig(StarSystemConfig starSystemConfig, string relativePath, IModBehaviour mod) + public void LoadStarSystemConfig(string starSystemName, StarSystemConfig starSystemConfig, string relativePath, IModBehaviour mod) { starSystemConfig.Migrate(); starSystemConfig.FixCoordinates(); @@ -608,22 +608,22 @@ namespace NewHorizons 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") + if (starSystemName != "SolarSystem") { - SetDefaultSystem(name); - _currentStarSystem = name; + SetDefaultSystem(starSystemName); + _currentStarSystem = starSystemName; } } - if (SystemDict.ContainsKey(name)) + if (SystemDict.ContainsKey(starSystemName)) { - if (string.IsNullOrEmpty(SystemDict[name].Config.travelAudio) && SystemDict[name].Config.Skybox == null) - SystemDict[name].Mod = mod; - SystemDict[name].Config.Merge(starSystemConfig); + if (string.IsNullOrEmpty(SystemDict[starSystemName].Config.travelAudio) && SystemDict[starSystemName].Config.Skybox == null) + SystemDict[starSystemName].Mod = mod; + SystemDict[starSystemName].Config.Merge(starSystemConfig); } else { - SystemDict[name] = new NewHorizonsSystem(name, starSystemConfig, relativePath, mod); + SystemDict[starSystemName] = new NewHorizonsSystem(starSystemName, starSystemConfig, relativePath, mod); } } @@ -654,13 +654,13 @@ namespace NewHorizons foreach (var file in systemFiles) { - var name = Path.GetFileNameWithoutExtension(file); + var starSystemName = Path.GetFileNameWithoutExtension(file); - NHLogger.LogVerbose($"Loading system {name}"); + NHLogger.LogVerbose($"Loading system {starSystemName}"); var relativePath = file.Replace(folder, ""); var starSystemConfig = mod.ModHelper.Storage.Load(relativePath, false); - LoadStarSystemConfig(starSystemConfig, relativePath, mod); + LoadStarSystemConfig(starSystemName, starSystemConfig, relativePath, mod); } } if (Directory.Exists(planetsFolder)) diff --git a/NewHorizons/NewHorizonsApi.cs b/NewHorizons/NewHorizonsApi.cs index f0c6221a..b8cbb254 100644 --- a/NewHorizons/NewHorizonsApi.cs +++ b/NewHorizons/NewHorizonsApi.cs @@ -69,24 +69,27 @@ namespace NewHorizons public void AddShipLogXML(IModBehaviour mod, XElement xml, string planetName, string imageFolder, Dictionary entryPositions, Dictionary curiousityColours) { + // This method has to be called each time the ship log manager is created, i.e. each time a system loads so it will only ever be relevant to the current one. + var starSystem = Main.Instance.CurrentStarSystem; + var body = new NewHorizonsBody(new PlanetConfig() { name = planetName, - starSystem = Main.Instance.CurrentStarSystem, + starSystem = starSystem, ShipLog = new ShipLogModule() { spriteFolder = imageFolder } }, mod); - if (!Main.BodyDict.ContainsKey(Main.Instance.CurrentStarSystem)) + if (!Main.BodyDict.ContainsKey(starSystem)) { - Main.BodyDict.Add(Main.Instance.CurrentStarSystem, new List()); - Main.BodyDict[Main.Instance.CurrentStarSystem].Add(body); + Main.BodyDict.Add(starSystem, new List()); + Main.BodyDict[starSystem].Add(body); } else { - var existingBody = Main.BodyDict[Main.Instance.CurrentStarSystem] + var existingBody = Main.BodyDict[starSystem] .FirstOrDefault(x => x.Config.name == planetName && x.Mod.ModHelper.Manifest.UniqueName == mod.ModHelper.Manifest.UniqueName); if (existingBody != null) { @@ -94,7 +97,7 @@ namespace NewHorizons } else { - Main.BodyDict[Main.Instance.CurrentStarSystem].Add(body); + Main.BodyDict[starSystem].Add(body); } } @@ -108,7 +111,7 @@ namespace NewHorizons .ToArray() }; - Main.Instance.LoadStarSystemConfig(system, null, mod); + Main.Instance.LoadStarSystemConfig(starSystem, system, null, mod); RumorModeBuilder.AddShipLogXML(GameObject.FindObjectOfType(), xml, body); }