From 0f187f6aca1fcbd9bbe284c8b060d4ed9988554e Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 21 Jul 2023 11:03:26 -0400 Subject: [PATCH 01/11] Add api method to make ship logs --- .../Builder/ShipLog/RumorModeBuilder.cs | 15 ++++++---- NewHorizons/INewHorizons.cs | 10 +++++++ NewHorizons/NewHorizonsApi.cs | 28 +++++++++++++++++++ 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/NewHorizons/Builder/ShipLog/RumorModeBuilder.cs b/NewHorizons/Builder/ShipLog/RumorModeBuilder.cs index 727f4c075..d224fffa4 100644 --- a/NewHorizons/Builder/ShipLog/RumorModeBuilder.cs +++ b/NewHorizons/Builder/ShipLog/RumorModeBuilder.cs @@ -55,15 +55,20 @@ public static void AddBodyToShipLog(ShipLogManager manager, NewHorizonsBody body { string systemName = body.Config.starSystem; XElement astroBodyFile = XElement.Load(Path.Combine(body.Mod.ModHelper.Manifest.ModFolderPath, body.Config.ShipLog.xmlFile)); - XElement astroBodyId = astroBodyFile.Element("ID"); + AddShipLogXML(manager, astroBodyFile, body); + } + + public static void AddShipLogXML(ShipLogManager manager, XElement xml, NewHorizonsBody body) + { + XElement astroBodyId = xml.Element("ID"); if (astroBodyId == null) { - NHLogger.LogError("Failed to load ship logs for " + systemName + "!"); + NHLogger.LogError("Failed to load ship logs for " + body.Config.name + "!"); } else { var entryIDs = new List(); - foreach (XElement entryElement in astroBodyFile.DescendantsAndSelf("Entry")) + foreach (XElement entryElement in xml.DescendantsAndSelf("Entry")) { XElement curiosityName = entryElement.Element("Curiosity"); XElement id = entryElement.Element("ID"); @@ -98,8 +103,8 @@ public static void AddBodyToShipLog(ShipLogManager manager, NewHorizonsBody body } AddTranslation(entryElement); } - TextAsset newAsset = new TextAsset(astroBodyFile.ToString()); - List newBodies = new List(manager._shipLogXmlAssets) { newAsset }; + var newAsset = new TextAsset(xml.ToString()); + var newBodies = new List(manager._shipLogXmlAssets) { newAsset }; manager._shipLogXmlAssets = newBodies.ToArray(); ShipLogHandler.AddConfig(astroBodyId.Value, entryIDs, body); } diff --git a/NewHorizons/INewHorizons.cs b/NewHorizons/INewHorizons.cs index 14093b0d9..a284270e0 100644 --- a/NewHorizons/INewHorizons.cs +++ b/NewHorizons/INewHorizons.cs @@ -1,6 +1,7 @@ using OWML.Common; using System; using System.Collections.Generic; +using System.Xml.Linq; using UnityEngine; using UnityEngine.Events; @@ -14,6 +15,15 @@ public interface INewHorizons [Obsolete("Create(Dictionary config) is deprecated, please use LoadConfigs(IModBehaviour mod) instead")] void Create(Dictionary config, IModBehaviour mod); + /// + /// Directly add ship logs from XML. Call this method right before ShipLogManager awake. + /// + /// + /// + /// + /// + void AddShipLogXML(IModBehaviour mod, ShipLogManager manager, XElement xml, string planetName); + /// /// Will load all configs in the regular folders (planets, systems, translations, etc) for this mod. /// The NH addon config template is just a single call to this API method. diff --git a/NewHorizons/NewHorizonsApi.cs b/NewHorizons/NewHorizonsApi.cs index ee3ea62f2..fd2c8b449 100644 --- a/NewHorizons/NewHorizonsApi.cs +++ b/NewHorizons/NewHorizonsApi.cs @@ -1,6 +1,8 @@ using NewHorizons.Builder.Props; using NewHorizons.Builder.Props.Audio; +using NewHorizons.Builder.ShipLog; using NewHorizons.External; +using NewHorizons.External.Configs; using NewHorizons.External.Modules; using NewHorizons.External.Modules.Props; using NewHorizons.External.Modules.Props.Audio; @@ -15,6 +17,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Xml.Linq; using UnityEngine; using UnityEngine.Events; @@ -62,6 +65,31 @@ public void Create(Dictionary config, IModBehaviour mod) } } + public void AddShipLogXML(IModBehaviour mod, ShipLogManager manager, XElement xml, string planetName) + { + var body = new NewHorizonsBody(new PlanetConfig() { name = planetName, starSystem = Main.Instance.CurrentStarSystem }, mod); + + if (!Main.BodyDict.ContainsKey(Main.Instance.CurrentStarSystem)) + { + Main.BodyDict.Add(Main.Instance.CurrentStarSystem, new List()); + Main.BodyDict[Main.Instance.CurrentStarSystem].Add(body); + } + else + { + var existingBody = Main.BodyDict[Main.Instance.CurrentStarSystem].FirstOrDefault(x => x.Config.name == planetName); + if (existingBody != null) + { + body = existingBody; + } + else + { + Main.BodyDict[Main.Instance.CurrentStarSystem].Add(body); + } + } + + RumorModeBuilder.AddShipLogXML(manager, xml, body); + } + public void LoadConfigs(IModBehaviour mod) { Main.Instance.LoadConfigs(mod); From 74b10f4e53fe8b0810a0c9c402ae989ebf7608cd Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 21 Jul 2023 11:15:24 -0400 Subject: [PATCH 02/11] 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 a284270e0..d1872826b 100644 --- a/NewHorizons/INewHorizons.cs +++ b/NewHorizons/INewHorizons.cs @@ -22,7 +22,8 @@ public interface INewHorizons /// /// /// - 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 e204ccdcb..fc497c91a 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -600,6 +600,33 @@ public void EnableWarpDrive() #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 @@ public void LoadConfigs(IModBehaviour mod) 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 fd2c8b449..dd5a524e4 100644 --- a/NewHorizons/NewHorizonsApi.cs +++ b/NewHorizons/NewHorizonsApi.cs @@ -20,6 +20,7 @@ using System.Xml.Linq; using UnityEngine; using UnityEngine.Events; +using static NewHorizons.External.Modules.ShipLogModule; namespace NewHorizons { @@ -65,7 +66,7 @@ public void Create(Dictionary config, IModBehaviour mod) } } - 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 @@ public void AddShipLogXML(IModBehaviour mod, ShipLogManager manager, XElement xm } } + 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); } From ba30f130769173722ecb7240501b46cb213ef9fe Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 21 Jul 2023 11:54:52 -0400 Subject: [PATCH 03/11] Added curiousities to api --- .../External/SerializableData/MColor.cs | 8 +++++ NewHorizons/INewHorizons.cs | 13 +++++---- NewHorizons/NewHorizonsApi.cs | 29 +++++++++++++++---- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/NewHorizons/External/SerializableData/MColor.cs b/NewHorizons/External/SerializableData/MColor.cs index 0f08bd698..9c1d2fa18 100644 --- a/NewHorizons/External/SerializableData/MColor.cs +++ b/NewHorizons/External/SerializableData/MColor.cs @@ -14,6 +14,14 @@ public MColor(int r, int g, int b, int a = 255) this.a = a; } + public MColor(Color color) + { + r = (int)(color.r * 255); + g = (int)(color.g * 255); + b = (int)(color.b * 255); + a = (int)(color.a * 255); + } + /// /// The red component of this colour from 0-255, higher values will make the colour glow if applicable. /// diff --git a/NewHorizons/INewHorizons.cs b/NewHorizons/INewHorizons.cs index d1872826b..9f74f8837 100644 --- a/NewHorizons/INewHorizons.cs +++ b/NewHorizons/INewHorizons.cs @@ -18,12 +18,13 @@ public interface INewHorizons /// /// Directly add ship logs from XML. Call this method right before ShipLogManager awake. /// - /// - /// - /// - /// - /// - void AddShipLogXML(IModBehaviour mod, ShipLogManager manager, XElement xml, string planetName, Dictionary entryPositions); + /// The mod this method is being called from. This is required for loading files. + /// The ship log xml contents + /// The planet that these ship logs correspond to in the map mode + /// The relative path from your mod manifest.json where the ship log images are located. The filename must be the same as the fact id. Optional. + /// A dictionary of each fact id to its 2D position in the ship log. Optional. + /// A dictionary of each curiousity ID to its colour and highlight colour in the ship log. Optional. + void AddShipLogXML(IModBehaviour mod, XElement xml, string planetName, string imageFolder = null, Dictionary entryPositions = null, Dictionary curiousityColours = null); /// /// Will load all configs in the regular folders (planets, systems, translations, etc) for this mod. diff --git a/NewHorizons/NewHorizonsApi.cs b/NewHorizons/NewHorizonsApi.cs index dd5a524e4..f0c6221a0 100644 --- a/NewHorizons/NewHorizonsApi.cs +++ b/NewHorizons/NewHorizonsApi.cs @@ -7,6 +7,7 @@ using NewHorizons.External.Modules.Props; using NewHorizons.External.Modules.Props.Audio; using NewHorizons.External.Modules.Props.Dialogue; +using NewHorizons.External.SerializableData; using NewHorizons.Utility; using NewHorizons.Utility.OWML; using Newtonsoft.Json; @@ -66,9 +67,17 @@ public void Create(Dictionary config, IModBehaviour mod) } } - public void AddShipLogXML(IModBehaviour mod, ShipLogManager manager, XElement xml, string planetName, Dictionary entryPositions) + public void AddShipLogXML(IModBehaviour mod, XElement xml, string planetName, string imageFolder, Dictionary entryPositions, Dictionary curiousityColours) { - var body = new NewHorizonsBody(new PlanetConfig() { name = planetName, starSystem = Main.Instance.CurrentStarSystem }, mod); + var body = new NewHorizonsBody(new PlanetConfig() + { + name = planetName, + starSystem = Main.Instance.CurrentStarSystem, + ShipLog = new ShipLogModule() + { + spriteFolder = imageFolder + } + }, mod); if (!Main.BodyDict.ContainsKey(Main.Instance.CurrentStarSystem)) { @@ -77,7 +86,8 @@ public void AddShipLogXML(IModBehaviour mod, ShipLogManager manager, XElement xm } else { - var existingBody = Main.BodyDict[Main.Instance.CurrentStarSystem].FirstOrDefault(x => x.Config.name == planetName); + var existingBody = Main.BodyDict[Main.Instance.CurrentStarSystem] + .FirstOrDefault(x => x.Config.name == planetName && x.Mod.ModHelper.Manifest.UniqueName == mod.ModHelper.Manifest.UniqueName); if (existingBody != null) { body = existingBody; @@ -88,10 +98,19 @@ public void AddShipLogXML(IModBehaviour mod, ShipLogManager manager, XElement xm } } - var system = new StarSystemConfig() { entryPositions = entryPositions.Select((pair) => new EntryPositionInfo() { id = pair.Key, position = pair.Value }).ToArray() }; + var system = new StarSystemConfig() + { + entryPositions = entryPositions + .Select((pair) => new EntryPositionInfo() { id = pair.Key, position = pair.Value }) + .ToArray(), + curiosities = curiousityColours + .Select((pair) => new CuriosityColorInfo() { id = pair.Key, color = new MColor(pair.Value.colour), highlightColor = new MColor(pair.Value.highlight) }) + .ToArray() + }; + Main.Instance.LoadStarSystemConfig(system, null, mod); - RumorModeBuilder.AddShipLogXML(manager, xml, body); + RumorModeBuilder.AddShipLogXML(GameObject.FindObjectOfType(), xml, body); } public void LoadConfigs(IModBehaviour mod) From 6aef5c76f6bd325ca40419d80364921f4466a6ea Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 21 Jul 2023 12:34:07 -0400 Subject: [PATCH 04/11] Fix star system name --- NewHorizons/Main.cs | 24 ++++++++++++------------ NewHorizons/NewHorizonsApi.cs | 17 ++++++++++------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index fc497c91a..8dcfaa2fe 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -600,7 +600,7 @@ public void EnableWarpDrive() #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 @@ public void LoadStarSystemConfig(StarSystemConfig starSystemConfig, string relat 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 @@ public void LoadConfigs(IModBehaviour mod) 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 f0c6221a0..b8cbb2540 100644 --- a/NewHorizons/NewHorizonsApi.cs +++ b/NewHorizons/NewHorizonsApi.cs @@ -69,24 +69,27 @@ public void Create(Dictionary config, IModBehaviour mod) 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 @@ public void AddShipLogXML(IModBehaviour mod, XElement xml, string planetName, st } else { - Main.BodyDict[Main.Instance.CurrentStarSystem].Add(body); + Main.BodyDict[starSystem].Add(body); } } @@ -108,7 +111,7 @@ public void AddShipLogXML(IModBehaviour mod, XElement xml, string planetName, st .ToArray() }; - Main.Instance.LoadStarSystemConfig(system, null, mod); + Main.Instance.LoadStarSystemConfig(starSystem, system, null, mod); RumorModeBuilder.AddShipLogXML(GameObject.FindObjectOfType(), xml, body); } From 664f9463224fc254c18cd62f4a0b8facb28fe6c5 Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 21 Jul 2023 12:39:34 -0400 Subject: [PATCH 05/11] Don't break colors --- NewHorizons/External/SerializableData/MColor.cs | 7 ++----- NewHorizons/NewHorizonsApi.cs | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/NewHorizons/External/SerializableData/MColor.cs b/NewHorizons/External/SerializableData/MColor.cs index 9c1d2fa18..156c2cd63 100644 --- a/NewHorizons/External/SerializableData/MColor.cs +++ b/NewHorizons/External/SerializableData/MColor.cs @@ -14,12 +14,9 @@ public MColor(int r, int g, int b, int a = 255) this.a = a; } - public MColor(Color color) + public static MColor FromColor(Color color) { - r = (int)(color.r * 255); - g = (int)(color.g * 255); - b = (int)(color.b * 255); - a = (int)(color.a * 255); + return new MColor((int)(color.r * 255), (int)(color.g * 255), (int)(color.b * 255), (int)(color.a * 255)); } /// diff --git a/NewHorizons/NewHorizonsApi.cs b/NewHorizons/NewHorizonsApi.cs index b8cbb2540..4518f9fe0 100644 --- a/NewHorizons/NewHorizonsApi.cs +++ b/NewHorizons/NewHorizonsApi.cs @@ -107,7 +107,7 @@ public void AddShipLogXML(IModBehaviour mod, XElement xml, string planetName, st .Select((pair) => new EntryPositionInfo() { id = pair.Key, position = pair.Value }) .ToArray(), curiosities = curiousityColours - .Select((pair) => new CuriosityColorInfo() { id = pair.Key, color = new MColor(pair.Value.colour), highlightColor = new MColor(pair.Value.highlight) }) + .Select((pair) => new CuriosityColorInfo() { id = pair.Key, color = MColor.FromColor(pair.Value.colour), highlightColor = MColor.FromColor(pair.Value.highlight) }) .ToArray() }; From d89ad0ff84c7ec3b5db10e4b0c77d16f89343740 Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 21 Jul 2023 13:03:02 -0400 Subject: [PATCH 06/11] Implement API methods for creating planet, system, dialogue directly from json/xml strings --- NewHorizons/Builder/Props/DialogueBuilder.cs | 17 ++- NewHorizons/INewHorizons.cs | 91 +++++++++---- NewHorizons/Main.cs | 50 ++++--- NewHorizons/NewHorizonsApi.cs | 133 ++++++++++++------- 4 files changed, 188 insertions(+), 103 deletions(-) diff --git a/NewHorizons/Builder/Props/DialogueBuilder.cs b/NewHorizons/Builder/Props/DialogueBuilder.cs index 8016f80d5..c2068b1ce 100644 --- a/NewHorizons/Builder/Props/DialogueBuilder.cs +++ b/NewHorizons/Builder/Props/DialogueBuilder.cs @@ -7,6 +7,7 @@ using OWML.Common; using System.IO; using System.Xml; +using System.Xml.Linq; using UnityEngine; namespace NewHorizons.Builder.Props @@ -15,6 +16,14 @@ public static class DialogueBuilder { // Returns the character dialogue tree and remote dialogue trigger, if applicable. public static (CharacterDialogueTree, RemoteDialogueTrigger) Make(GameObject go, Sector sector, DialogueInfo info, IModBehaviour mod) + { + var xml = File.ReadAllText(Path.Combine(mod.ModHelper.Manifest.ModFolderPath, info.xmlFile)); + var dialogueName = Path.GetFileNameWithoutExtension(info.xmlFile); + return Make(go, sector, info, xml, dialogueName); + } + + // Create dialogue directly from xml string instead of loading it from a file + public static (CharacterDialogueTree, RemoteDialogueTrigger) Make(GameObject go, Sector sector, DialogueInfo info, string xml, string dialogueName) { NHLogger.LogVerbose($"[DIALOGUE] Created a new character dialogue [{info.rename}] on [{info.parentPath}]"); @@ -26,7 +35,7 @@ public static (CharacterDialogueTree, RemoteDialogueTrigger) Make(GameObject go, return (null, null); } - var dialogue = MakeConversationZone(go, sector, info, mod.ModHelper); + var dialogue = MakeConversationZone(go, sector, info, xml, dialogueName); RemoteDialogueTrigger remoteTrigger = null; if (info.remoteTrigger != null) @@ -76,7 +85,7 @@ private static RemoteDialogueTrigger MakeRemoteDialogueTrigger(GameObject planet return remoteDialogueTrigger; } - private static CharacterDialogueTree MakeConversationZone(GameObject planetGO, Sector sector, DialogueInfo info, IModHelper mod) + private static CharacterDialogueTree MakeConversationZone(GameObject planetGO, Sector sector, DialogueInfo info, string xml, string dialogueName) { var conversationZone = GeneralPropBuilder.MakeNew("ConversationZone", planetGO, sector, info, defaultParentPath: info.pathToAnimController); @@ -100,13 +109,11 @@ private static CharacterDialogueTree MakeConversationZone(GameObject planetGO, S var dialogueTree = conversationZone.AddComponent(); - var xml = File.ReadAllText(Path.Combine(mod.Manifest.ModFolderPath, info.xmlFile)); var text = new TextAsset(xml) { // Text assets need a name to be used with VoiceMod - name = Path.GetFileNameWithoutExtension(info.xmlFile) + name = dialogueName }; - dialogueTree.SetTextXml(text); AddTranslation(xml); diff --git a/NewHorizons/INewHorizons.cs b/NewHorizons/INewHorizons.cs index 9f74f8837..717819c09 100644 --- a/NewHorizons/INewHorizons.cs +++ b/NewHorizons/INewHorizons.cs @@ -9,22 +9,13 @@ namespace NewHorizons { public interface INewHorizons { + #region Obsolete [Obsolete("Create(Dictionary config) is deprecated, please use LoadConfigs(IModBehaviour mod) instead")] void Create(Dictionary config); [Obsolete("Create(Dictionary config) is deprecated, please use LoadConfigs(IModBehaviour mod) instead")] void Create(Dictionary config, IModBehaviour mod); - - /// - /// Directly add ship logs from XML. Call this method right before ShipLogManager awake. - /// - /// The mod this method is being called from. This is required for loading files. - /// The ship log xml contents - /// The planet that these ship logs correspond to in the map mode - /// The relative path from your mod manifest.json where the ship log images are located. The filename must be the same as the fact id. Optional. - /// A dictionary of each fact id to its 2D position in the ship log. Optional. - /// A dictionary of each curiousity ID to its colour and highlight colour in the ship log. Optional. - void AddShipLogXML(IModBehaviour mod, XElement xml, string planetName, string imageFolder = null, Dictionary entryPositions = null, Dictionary curiousityColours = null); + #endregion /// /// Will load all configs in the regular folders (planets, systems, translations, etc) for this mod. @@ -38,11 +29,30 @@ public interface INewHorizons /// GameObject GetPlanet(string name); + /// + /// Returns the uniqueIDs of each installed NH addon. + /// + string[] GetInstalledAddons(); + + #region Get/set/change star system /// /// The name of the current star system loaded. /// string GetCurrentStarSystem(); + /// + /// Allows you to overwrite the default system. This is where the player is respawned after dying. + /// + bool SetDefaultSystem(string name); + + /// + /// Allows you to instantly begin a warp to a new star system. + /// Will return false if that system does not exist (cannot be warped to). + /// + bool ChangeCurrentStarSystem(string name); + #endregion + + #region events /// /// An event invoked when the player begins loading the new star system, before the scene starts to load. /// Gives the name of the star system being switched to. @@ -60,7 +70,9 @@ public interface INewHorizons /// Gives the name of the planet that was just loaded. /// UnityEvent GetBodyLoadedEvent(); + #endregion + #region Querying configs /// /// Uses JSONPath to query a body /// @@ -80,23 +92,9 @@ public interface INewHorizons /// Uses JSONPath to query the current star system /// T QuerySystem(string path); + #endregion - /// - /// Allows you to overwrite the default system. This is where the player is respawned after dying. - /// - bool SetDefaultSystem(string name); - - /// - /// Allows you to instantly begin a warp to a new star system. - /// Will return false if that system does not exist (cannot be warped to). - /// - bool ChangeCurrentStarSystem(string name); - - /// - /// Returns the uniqueIDs of each installed NH addon. - /// - string[] GetInstalledAddons(); - + #region Spawn props /// /// Allows you to spawn a copy of a prop by specifying its path. /// This is the same as using Props->details in a config, but also returns the spawned gameObject to you. @@ -121,5 +119,44 @@ public interface INewHorizons (CharacterDialogueTree, RemoteDialogueTrigger) SpawnDialogue(IModBehaviour mod, GameObject root, string xmlFile, float radius = 1f, float range = 1f, string blockAfterPersistentCondition = null, float lookAtRadius = 1f, string pathToAnimController = null, float remoteTriggerRadius = 0f); + #endregion + + #region Load json/xml directly + /// + /// Allows creation of a planet by directly passing the json contents as a string. + /// + /// + /// + void CreatePlanet(string config, IModBehaviour mod); + + /// + /// Allows defining details of a star system by directly passing the json contents as a string. + /// + /// + /// + /// + void DefineStarSystem(string name, string config, IModBehaviour mod); + + /// + /// Allows creation of dialogue by directly passing the xml and dialogueInfo json contents as strings + /// + /// TextAsset name used for compatibility with voice mod. Just has to be a unique identifier. + /// The contents of the dialogue xml file as a string + /// The json dialogue info as a string. See the documentation/schema for what this can contain. + /// The root planet rigidbody that this dialogue is attached to. Any paths in the dialogueInfo are relative to this body. + /// + (CharacterDialogueTree, RemoteDialogueTrigger) CreateDialogueFromXML(string textAssetID, string xml, string dialogueInfo, GameObject planetGO); + + /// + /// Directly add ship logs from XML. Call this method right before ShipLogManager awake. + /// + /// The mod this method is being called from. This is required for loading files. + /// The ship log xml contents + /// The planet that these ship logs correspond to in the map mode + /// The relative path from your mod manifest.json where the ship log images are located. The filename must be the same as the fact id. Optional. + /// A dictionary of each fact id to its 2D position in the ship log. Optional. + /// A dictionary of each curiousity ID to its colour and highlight colour in the ship log. Optional. + void AddShipLogXML(IModBehaviour mod, XElement xml, string planetName, string imageFolder = null, Dictionary entryPositions = null, Dictionary curiousityColours = null); + #endregion } } diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 8dcfaa2fe..499c2468a 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -33,6 +33,7 @@ using NewHorizons.Utility.DebugTools.Menu; using NewHorizons.Components.Ship; using NewHorizons.Builder.Props.Audio; +using Epic.OnlineServices; namespace NewHorizons { @@ -771,28 +772,7 @@ public NewHorizonsBody LoadConfig(IModBehaviour mod, string relativePath) NHLogger.LogVerbose($"Loaded {config.name}"); - 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?"); - - starSystemConfig.Migrate(); - starSystemConfig.FixCoordinates(); - - var system = new NewHorizonsSystem(config.starSystem, starSystemConfig, $"", mod); - - SystemDict.Add(config.starSystem, system); - - BodyDict.Add(config.starSystem, new List()); - } - - // Has to happen after we make sure theres a system config - config.Validate(); - config.Migrate(); - - body = new NewHorizonsBody(config, mod, relativePath); + body = RegisterPlanetConfig(config, mod, relativePath); } catch (Exception e) { @@ -803,6 +783,32 @@ public NewHorizonsBody LoadConfig(IModBehaviour mod, string relativePath) return body; } + public NewHorizonsBody RegisterPlanetConfig(PlanetConfig config, IModBehaviour mod, string relativePath) + { + 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?"); + + starSystemConfig.Migrate(); + starSystemConfig.FixCoordinates(); + + var system = new NewHorizonsSystem(config.starSystem, starSystemConfig, $"", mod); + + SystemDict.Add(config.starSystem, system); + + BodyDict.Add(config.starSystem, new List()); + } + + // Has to happen after we make sure theres a system config + config.Validate(); + config.Migrate(); + + return new NewHorizonsBody(config, mod, relativePath); + } + public void SetDefaultSystem(string defaultSystem) { _defaultStarSystem = defaultSystem; diff --git a/NewHorizons/NewHorizonsApi.cs b/NewHorizons/NewHorizonsApi.cs index 4518f9fe0..611233b9e 100644 --- a/NewHorizons/NewHorizonsApi.cs +++ b/NewHorizons/NewHorizonsApi.cs @@ -8,6 +8,7 @@ using NewHorizons.External.Modules.Props.Audio; using NewHorizons.External.Modules.Props.Dialogue; using NewHorizons.External.SerializableData; +using NewHorizons.OtherMods.MenuFramework; using NewHorizons.Utility; using NewHorizons.Utility.OWML; using Newtonsoft.Json; @@ -67,55 +68,6 @@ public void Create(Dictionary config, IModBehaviour mod) } } - 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 = starSystem, - ShipLog = new ShipLogModule() - { - spriteFolder = imageFolder - } - }, mod); - - if (!Main.BodyDict.ContainsKey(starSystem)) - { - Main.BodyDict.Add(starSystem, new List()); - Main.BodyDict[starSystem].Add(body); - } - else - { - var existingBody = Main.BodyDict[starSystem] - .FirstOrDefault(x => x.Config.name == planetName && x.Mod.ModHelper.Manifest.UniqueName == mod.ModHelper.Manifest.UniqueName); - if (existingBody != null) - { - body = existingBody; - } - else - { - Main.BodyDict[starSystem].Add(body); - } - } - - var system = new StarSystemConfig() - { - entryPositions = entryPositions - .Select((pair) => new EntryPositionInfo() { id = pair.Key, position = pair.Value }) - .ToArray(), - curiosities = curiousityColours - .Select((pair) => new CuriosityColorInfo() { id = pair.Key, color = MColor.FromColor(pair.Value.colour), highlightColor = MColor.FromColor(pair.Value.highlight) }) - .ToArray() - }; - - Main.Instance.LoadStarSystemConfig(starSystem, system, null, mod); - - RumorModeBuilder.AddShipLogXML(GameObject.FindObjectOfType(), xml, body); - } - public void LoadConfigs(IModBehaviour mod) { Main.Instance.LoadConfigs(mod); @@ -269,5 +221,88 @@ public object QuerySystem(Type outType, string jsonPath) return DialogueBuilder.Make(root, null, info, mod); } + + public void CreatePlanet(string config, IModBehaviour mod) + { + try + { + var planet = JsonConvert.DeserializeObject(config); + if (planet == null) + { + NHLogger.LogError($"Couldn't load planet via API. Is your Json formatted correctly? {config}"); + return; + } + + var body = Main.Instance.RegisterPlanetConfig(planet, mod, null); + + if (!Main.BodyDict.ContainsKey(body.Config.starSystem)) Main.BodyDict.Add(body.Config.starSystem, new List()); + Main.BodyDict[body.Config.starSystem].Add(body); + } + catch (Exception ex) + { + NHLogger.LogError($"Error in CreatePlanet API:\n{ex}"); + } + } + + public void DefineStarSystem(string name, string config, IModBehaviour mod) + { + var starSystemConfig = JsonConvert.DeserializeObject(config); + Main.Instance.LoadStarSystemConfig(name, starSystemConfig, null, mod); + } + + public (CharacterDialogueTree, RemoteDialogueTrigger) CreateDialogueFromXML(string textAssetID, string xml, string dialogueInfo, GameObject planetGO) + { + var info = JsonConvert.DeserializeObject(dialogueInfo); + return DialogueBuilder.Make(planetGO, null, info, xml, textAssetID); + } + + 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 = starSystem, + ShipLog = new ShipLogModule() + { + spriteFolder = imageFolder + } + }, mod); + + if (!Main.BodyDict.ContainsKey(starSystem)) + { + Main.BodyDict.Add(starSystem, new List()); + Main.BodyDict[starSystem].Add(body); + } + else + { + var existingBody = Main.BodyDict[starSystem] + .FirstOrDefault(x => x.Config.name == planetName && x.Mod.ModHelper.Manifest.UniqueName == mod.ModHelper.Manifest.UniqueName); + if (existingBody != null) + { + body = existingBody; + } + else + { + Main.BodyDict[starSystem].Add(body); + } + } + + var system = new StarSystemConfig() + { + entryPositions = entryPositions + .Select((pair) => new EntryPositionInfo() { id = pair.Key, position = pair.Value }) + .ToArray(), + curiosities = curiousityColours + .Select((pair) => new CuriosityColorInfo() { id = pair.Key, color = MColor.FromColor(pair.Value.colour), highlightColor = MColor.FromColor(pair.Value.highlight) }) + .ToArray() + }; + + Main.Instance.LoadStarSystemConfig(starSystem, system, null, mod); + + RumorModeBuilder.AddShipLogXML(GameObject.FindObjectOfType(), xml, body); + } } } From 629154cba58c921ce9f108f2315e8d827ec86851 Mon Sep 17 00:00:00 2001 From: Raicuparta Date: Fri, 21 Jul 2023 22:02:23 +0200 Subject: [PATCH 07/11] Add missing null checks --- NewHorizons/NewHorizonsApi.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NewHorizons/NewHorizonsApi.cs b/NewHorizons/NewHorizonsApi.cs index 611233b9e..d95994531 100644 --- a/NewHorizons/NewHorizonsApi.cs +++ b/NewHorizons/NewHorizonsApi.cs @@ -292,10 +292,10 @@ public void AddShipLogXML(IModBehaviour mod, XElement xml, string planetName, st var system = new StarSystemConfig() { - entryPositions = entryPositions + entryPositions = entryPositions? .Select((pair) => new EntryPositionInfo() { id = pair.Key, position = pair.Value }) .ToArray(), - curiosities = curiousityColours + curiosities = curiousityColours? .Select((pair) => new CuriosityColorInfo() { id = pair.Key, color = MColor.FromColor(pair.Value.colour), highlightColor = MColor.FromColor(pair.Value.highlight) }) .ToArray() }; From 509282914631190ab4b4ea71e0eca379807773ab Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 22 Jul 2023 02:50:45 -0400 Subject: [PATCH 08/11] Pitch anglerfish sounds based on size --- .../AnglerfishAudioControllerPatches.cs | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 NewHorizons/Patches/AnglerfishAudioControllerPatches.cs diff --git a/NewHorizons/Patches/AnglerfishAudioControllerPatches.cs b/NewHorizons/Patches/AnglerfishAudioControllerPatches.cs new file mode 100644 index 000000000..4ddffcf13 --- /dev/null +++ b/NewHorizons/Patches/AnglerfishAudioControllerPatches.cs @@ -0,0 +1,47 @@ +using HarmonyLib; +using UnityEngine; +using static AnglerfishController; + +namespace NewHorizons.Patches +{ + [HarmonyPatch(typeof(AnglerfishAudioController))] + public static class AnglerfishAudioControllerPatches + { + [HarmonyPrefix] + [HarmonyPatch(nameof(AnglerfishAudioController.OnChangeAnglerState))] + public static bool AnglerfishAudioController_OnChangeAnglerState(AnglerfishAudioController __instance, AnglerState anglerState) + { + var scale = __instance.transform.parent.localScale.x; + + if (scale == 1) + { + return true; + } + else + { + var modifier = 1f / Mathf.Clamp(scale, 0.5f, 2f); + + __instance.UpdateLoopingAudio(anglerState); + if (anglerState == AnglerState.Investigating) + { + __instance._longRangeOneShotSource.pitch = modifier * Random.Range(0.8f, 1f); + __instance._longRangeOneShotSource.PlayOneShot(AudioType.DBAnglerfishDetectDisturbance, 1f); + return false; + } + if (anglerState == AnglerState.Chasing) + { + if (Time.time > AnglerfishAudioController.s_lastDetectTime + 2f) + { + AnglerfishAudioController.s_lastDetectTime = Time.time; + __instance._oneShotSource.pitch = modifier * Random.Range(0.8f, 1f); + __instance._oneShotSource.PlayOneShot(AudioType.DBAnglerfishDetectTarget, 1f); + return false; + } + MonoBehaviour.print("ANGLER DETECT TARGET SOUND BLOCKED"); + } + + return false; + } + } + } +} From b4b0345e653381e64cf59c53d0cdde29f5467985 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 22 Jul 2023 03:51:10 -0400 Subject: [PATCH 09/11] Fix spawn on center of universe garbage --- .../Builder/General/SpawnPointBuilder.cs | 37 ++++-------- .../Components/Ship/ShipWarpController.cs | 2 + NewHorizons/Handlers/PlayerSpawnHandler.cs | 57 ++++++++++++++++--- 3 files changed, 60 insertions(+), 36 deletions(-) diff --git a/NewHorizons/Builder/General/SpawnPointBuilder.cs b/NewHorizons/Builder/General/SpawnPointBuilder.cs index 87520d52e..cc7feddf5 100644 --- a/NewHorizons/Builder/General/SpawnPointBuilder.cs +++ b/NewHorizons/Builder/General/SpawnPointBuilder.cs @@ -13,6 +13,9 @@ namespace NewHorizons.Builder.General public static class SpawnPointBuilder { private static bool suitUpQueued = false; + public static SpawnPoint ShipSpawn { get; private set; } + public static Vector3 ShipSpawnOffset { get; private set; } + public static SpawnPoint Make(GameObject planetGO, SpawnModule module, OWRigidbody owRigidBody) { SpawnPoint playerSpawn = null; @@ -35,41 +38,21 @@ public static SpawnPoint Make(GameObject planetGO, SpawnModule module, OWRigidbo if (module.shipSpawn != null) { - GameObject spawnGO = GeneralPropBuilder.MakeNew("ShipSpawnPoint", planetGO, null, module.shipSpawn); + var spawnGO = GeneralPropBuilder.MakeNew("ShipSpawnPoint", planetGO, null, module.shipSpawn); spawnGO.SetActive(false); spawnGO.layer = Layer.PlayerSafetyCollider; - var shipSpawn = spawnGO.AddComponent(); - shipSpawn._isShipSpawn = true; - shipSpawn._attachedBody = owRigidBody; - shipSpawn._spawnLocation = SpawnLocation.None; + ShipSpawn = spawnGO.AddComponent(); + ShipSpawn._isShipSpawn = true; + ShipSpawn._attachedBody = owRigidBody; + ShipSpawn._spawnLocation = SpawnLocation.None; // #601 we need to actually set the right trigger volumes here - shipSpawn._triggerVolumes = new OWTriggerVolume[0]; + ShipSpawn._triggerVolumes = new OWTriggerVolume[0]; - // TODO: this should happen elsewhere - var ship = SearchUtilities.Find("Ship_Body"); - if (ship != null) - { - ship.transform.position = spawnGO.transform.position; - ship.transform.rotation = spawnGO.transform.rotation; + ShipSpawnOffset = module.shipSpawn.offset ?? (module.shipSpawn.alignRadial.GetValueOrDefault() ? Vector3.up * 4 : Vector3.zero); - // Move it up a bit more when aligning to surface - if (module.shipSpawn.offset != null) - { - ship.transform.position += spawnGO.transform.TransformDirection(module.shipSpawn.offset); - } - else if (module.shipSpawn.alignRadial.GetValueOrDefault()) - { - ship.transform.position += ship.transform.up * 4f; - } - - ship.GetRequiredComponent().SetBodyToMatch(owRigidBody); - } spawnGO.SetActive(true); - - // Ship doesn't get activated sometimes - Delay.RunWhen(() => Main.IsSystemReady, () => ship.gameObject.SetActive(true)); } if ((Main.Instance.IsWarpingFromVessel || (!Main.Instance.IsWarpingFromShip && (module.playerSpawn?.startWithSuit ?? false))) && !suitUpQueued) diff --git a/NewHorizons/Components/Ship/ShipWarpController.cs b/NewHorizons/Components/Ship/ShipWarpController.cs index cbd091981..d1f8e62de 100644 --- a/NewHorizons/Components/Ship/ShipWarpController.cs +++ b/NewHorizons/Components/Ship/ShipWarpController.cs @@ -201,6 +201,8 @@ public void FinishWarpIn() GlobalMessenger.FireEvent("EnterShip"); PlayerState.OnEnterShip(); + + PlayerSpawnHandler.SpawnShip(); } } } diff --git a/NewHorizons/Handlers/PlayerSpawnHandler.cs b/NewHorizons/Handlers/PlayerSpawnHandler.cs index cb1a607a6..8a9eb6f84 100644 --- a/NewHorizons/Handlers/PlayerSpawnHandler.cs +++ b/NewHorizons/Handlers/PlayerSpawnHandler.cs @@ -1,3 +1,4 @@ +using NewHorizons.Builder.General; using NewHorizons.Utility; using NewHorizons.Utility.OWML; using System.Collections; @@ -45,33 +46,71 @@ public static void OnSystemReady(bool shouldWarpInFromShip, bool shouldWarpInFro } } + public static void SpawnShip() + { + var ship = SearchUtilities.Find("Ship_Body"); + if (ship != null) + { + ship.SetActive(true); + + var pos = SpawnPointBuilder.ShipSpawn.transform.position; + + // Move it up a bit more when aligning to surface + if (SpawnPointBuilder.ShipSpawnOffset != null) + { + pos += SpawnPointBuilder.ShipSpawn.transform.TransformDirection(SpawnPointBuilder.ShipSpawnOffset); + } + + SpawnBody(ship.GetAttachedOWRigidbody(), SpawnPointBuilder.ShipSpawn, pos); + } + } + private static IEnumerator SpawnCoroutine(int length) { for(int i = 0; i < length; i++) { - FixVelocity(); + FixPlayerVelocity(); yield return new WaitForEndOfFrame(); } InvulnerabilityHandler.MakeInvulnerable(false); + + if (!Main.Instance.IsWarpingFromShip) + { + if (SpawnPointBuilder.ShipSpawn != null) + { + NHLogger.Log("Spawning player ship"); + SpawnShip(); + } + else + { + NHLogger.Log("System has no ship spawn. Deactivating it."); + SearchUtilities.Find("Ship_Body")?.SetActive(false); + } + } } - private static void FixVelocity() + private static void FixPlayerVelocity() { var playerBody = SearchUtilities.Find("Player_Body").GetAttachedOWRigidbody(); - var spawn = GetDefaultSpawn(); var resources = playerBody.GetComponent(); - playerBody.WarpToPositionRotation(spawn.transform.position, spawn.transform.rotation); + SpawnBody(playerBody, GetDefaultSpawn()); + + resources._currentHealth = 100f; + } + + public static void SpawnBody(OWRigidbody body, SpawnPoint spawn, Vector3? positionOverride = null) + { + var pos = positionOverride ?? spawn.transform.position; + + body.WarpToPositionRotation(pos, spawn.transform.rotation); var spawnVelocity = spawn._attachedBody.GetVelocity(); - var spawnAngularVelocity = spawn._attachedBody.GetPointTangentialVelocity(playerBody.transform.position); + var spawnAngularVelocity = spawn._attachedBody.GetPointTangentialVelocity(pos); var velocity = spawnVelocity + spawnAngularVelocity; - playerBody.SetVelocity(velocity); - NHLogger.LogVerbose($"Player spawn velocity {velocity} Player velocity {playerBody.GetVelocity()} spawn body {spawnVelocity} spawn angular vel {spawnAngularVelocity}"); - - resources._currentHealth = 100f; + body.SetVelocity(velocity); } private static Vector3 CalculateMatchVelocity(OWRigidbody owRigidbody, OWRigidbody bodyToMatch, bool ignoreAngularVelocity) From 3b40fac5a494a649627092c9c91fe1fd5d82ca9e Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 26 Jul 2023 23:59:23 -0400 Subject: [PATCH 10/11] Fix Stranger cloak breaking --- .../Components/EOTE/CloakLocatorController.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/NewHorizons/Components/EOTE/CloakLocatorController.cs b/NewHorizons/Components/EOTE/CloakLocatorController.cs index ad168e823..6bb964638 100644 --- a/NewHorizons/Components/EOTE/CloakLocatorController.cs +++ b/NewHorizons/Components/EOTE/CloakLocatorController.cs @@ -1,6 +1,7 @@ using NewHorizons.Components.Stars; using NewHorizons.Handlers; using NewHorizons.Utility.OWML; +using System.Linq; using UnityEngine; namespace NewHorizons.Components.EOTE @@ -12,11 +13,17 @@ internal class CloakLocatorController : MonoBehaviour public void Start() { - // Enable and disable all cloaks, else Stranger state is weird at the start - foreach (var cloak in CloakHandler.Cloaks) + if (CloakHandler.Cloaks.Any()) { - SetCurrentCloak(cloak); - cloak.enabled = false; + // Enable and disable all cloaks, else Stranger state is weird at the start + foreach (var cloak in CloakHandler.Cloaks) + { + SetCurrentCloak(cloak); + cloak.enabled = false; + } + + // Make sure a cloak is enabled + SetCurrentCloak(CloakHandler.Cloaks.First()); } } From 8d5828207eb8f1ca435b45b01e47b0d520fe9222 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 27 Jul 2023 00:02:10 -0400 Subject: [PATCH 11/11] Update manifest.json --- NewHorizons/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/manifest.json b/NewHorizons/manifest.json index e9c9beafb..273520daf 100644 --- a/NewHorizons/manifest.json +++ b/NewHorizons/manifest.json @@ -4,7 +4,7 @@ "author": "xen, Bwc9876, clay, MegaPiggy, John, Trifid, Hawkbar, Book", "name": "New Horizons", "uniqueName": "xen.NewHorizons", - "version": "1.12.7", + "version": "1.13.0", "owmlVersion": "2.9.3", "dependencies": [ "JohnCorby.VanillaFix", "_nebula.MenuFramework", "xen.CommonCameraUtility", "dgarro.CustomShipLogModes" ], "conflicts": [ "Raicuparta.QuantumSpaceBuddies", "PacificEngine.OW_CommonResources" ],