From ed66cb06650414e2c1bc540f540fd8f559fd01c4 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 22 Jul 2023 12:04:02 -0400 Subject: [PATCH] Fix update from dev --- .../Builder/Props/GravityCannonBuilder.cs | 65 +++++++++---------- NewHorizons/Builder/Props/NomaiTextBuilder.cs | 2 +- NewHorizons/Builder/Props/PropBuildManager.cs | 4 +- NewHorizons/Builder/Props/ShuttleBuilder.cs | 16 ++--- .../TranslatorText/TranslatorTextBuilder.cs | 8 +-- NewHorizons/Builder/Props/WarpPadBuilder.cs | 11 +++- NewHorizons/External/Modules/PropModule.cs | 11 ++++ .../Modules/Props/NomaiComputerInfo.cs | 23 +++++++ .../Props/Shuttle/GravityCannonInfo.cs | 33 ++++++++++ .../Modules/Props/Shuttle/ShuttleInfo.cs | 18 +++++ .../Modules/WarpPad/NomaiWarpComputerInfo.cs | 9 --- .../WarpPad/NomaiWarpPadReceiverInfo.cs | 3 +- NewHorizons/Handlers/ShuttleHandler.cs | 14 ++-- 13 files changed, 141 insertions(+), 76 deletions(-) create mode 100644 NewHorizons/External/Modules/Props/NomaiComputerInfo.cs create mode 100644 NewHorizons/External/Modules/Props/Shuttle/GravityCannonInfo.cs create mode 100644 NewHorizons/External/Modules/Props/Shuttle/ShuttleInfo.cs delete mode 100644 NewHorizons/External/Modules/WarpPad/NomaiWarpComputerInfo.cs diff --git a/NewHorizons/Builder/Props/GravityCannonBuilder.cs b/NewHorizons/Builder/Props/GravityCannonBuilder.cs index 4201c6c6..cc62756e 100644 --- a/NewHorizons/Builder/Props/GravityCannonBuilder.cs +++ b/NewHorizons/Builder/Props/GravityCannonBuilder.cs @@ -1,11 +1,11 @@ -using NewHorizons.Components; -using NewHorizons.Components.Volumes; -using NewHorizons.External.Modules; +using NewHorizons.Builder.Props.TranslatorText; +using NewHorizons.External.Modules.Props; +using NewHorizons.External.Modules.Props.Shuttle; using NewHorizons.Handlers; using NewHorizons.Utility; +using NewHorizons.Utility.OWML; using OWML.Common; using UnityEngine; -using Logger = NewHorizons.Utility.Logger; namespace NewHorizons.Builder.Props { @@ -32,20 +32,13 @@ namespace NewHorizons.Builder.Props } } - public static GameObject Make(GameObject planetGO, Sector sector, PropModule.GravityCannonInfo info, IModBehaviour mod) + public static GameObject Make(GameObject planetGO, Sector sector, GravityCannonInfo info, IModBehaviour mod) { InitPrefab(); if (_prefab == null || planetGO == null || sector == null) return null; - var detailInfo = new PropModule.DetailInfo() - { - position = info.position, - rotation = info.rotation, - parentPath = info.parentPath, - isRelativeToParent = info.isRelativeToParent, - rename = info.rename - }; + var detailInfo = new DetailInfo(info); var gravityCannonObject = DetailBuilder.Make(planetGO, sector, _prefab, detailInfo); gravityCannonObject.SetActive(false); @@ -55,38 +48,40 @@ namespace NewHorizons.Builder.Props gravityCannonController._shuttleID = ShuttleHandler.GetShuttleID(info.shuttleID); gravityCannonController._retrieveShipLogFact = info.retrieveReveal; gravityCannonController._launchShipLogFact = info.launchReveal; + if (info.computer != null) { - gravityCannonController._nomaiComputer = NomaiTextBuilder.Make(planetGO, sector, new PropModule.NomaiTextInfo - { - type = PropModule.NomaiTextInfo.NomaiTextType.Computer, - position = info.computer.position, - rotation = info.computer.rotation, - normal = info.computer.normal, - isRelativeToParent = info.computer.isRelativeToParent, - rename = info.computer.rename, - location = info.computer.location, - xmlFile = info.computer.xmlFile, - parentPath = info.computer.parentPath - }, mod).GetComponent(); + gravityCannonController._nomaiComputer = CreateComputer(planetGO, sector, info.computer); } else { - gravityCannonController._nomaiComputer = NomaiTextBuilder.Make(planetGO, sector, new PropModule.NomaiTextInfo - { - type = PropModule.NomaiTextInfo.NomaiTextType.Computer, - position = new MVector3(-2.556838f, -0.8018004f, 10.01348f), - rotation = new MVector3(8.293f, 2.403f, 0.9f), - isRelativeToParent = true, - rename = "Computer", - xmlFile = "Assets/GravityCannonComputer.xml", - parentPath = gravityCannonObject.transform.GetPath().Remove(0, planetGO.name.Length + 1) - }, Main.Instance).GetComponent(); + gravityCannonController._nomaiComputer = null; } gravityCannonObject.SetActive(true); return gravityCannonObject; } + + private static NomaiComputer CreateComputer(GameObject planetGO, Sector sector, NomaiComputerInfo computerInfo) + { + var prefab = computerInfo.type switch + { + NomaiComputerType.NORMAL => TranslatorTextBuilder.ComputerPrefab, + NomaiComputerType.PRECRASH => TranslatorTextBuilder.PreCrashComputerPrefab, + _ => throw new System.NotImplementedException() + }; + + var computerObject = DetailBuilder.Make(planetGO, sector, prefab, new DetailInfo(computerInfo)); + + var computer = computerObject.GetComponentInChildren(); + computer.SetSector(sector); + + Delay.FireOnNextUpdate(computer.ClearAllEntries); + + computerObject.SetActive(true); + + return computer; + } } } diff --git a/NewHorizons/Builder/Props/NomaiTextBuilder.cs b/NewHorizons/Builder/Props/NomaiTextBuilder.cs index 6dd55761..e7035365 100644 --- a/NewHorizons/Builder/Props/NomaiTextBuilder.cs +++ b/NewHorizons/Builder/Props/NomaiTextBuilder.cs @@ -747,7 +747,7 @@ namespace NewHorizons.Builder.Props if (rootNode == null) { - Logger.LogError($"Couldn't find NomaiObject in [{xmlPath}]"); + NHLogger.LogError($"Couldn't find NomaiObject in [{xmlPath}]"); return dict; } diff --git a/NewHorizons/Builder/Props/PropBuildManager.cs b/NewHorizons/Builder/Props/PropBuildManager.cs index 8c6b1c4c..af781f52 100644 --- a/NewHorizons/Builder/Props/PropBuildManager.cs +++ b/NewHorizons/Builder/Props/PropBuildManager.cs @@ -29,7 +29,7 @@ namespace NewHorizons.Builder.Props } catch (Exception ex) { - Logger.LogError($"Couldn't make gravity cannon [{gravityCannonInfo.shuttleID}] for [{go.name}]:\n{ex}"); + NHLogger.LogError($"Couldn't make gravity cannon [{gravityCannonInfo.shuttleID}] for [{go.name}]:\n{ex}"); } } } @@ -43,7 +43,7 @@ namespace NewHorizons.Builder.Props } catch (Exception ex) { - Logger.LogError($"Couldn't make shuttle [{shuttleInfo.id}] for [{go.name}]:\n{ex}"); + NHLogger.LogError($"Couldn't make shuttle [{shuttleInfo.id}] for [{go.name}]:\n{ex}"); } } } diff --git a/NewHorizons/Builder/Props/ShuttleBuilder.cs b/NewHorizons/Builder/Props/ShuttleBuilder.cs index 39adfba4..cc0cde18 100644 --- a/NewHorizons/Builder/Props/ShuttleBuilder.cs +++ b/NewHorizons/Builder/Props/ShuttleBuilder.cs @@ -1,10 +1,9 @@ using NewHorizons.Components; -using NewHorizons.Components.Volumes; -using NewHorizons.External.Modules; +using NewHorizons.External.Modules.Props; +using NewHorizons.External.Modules.Props.Shuttle; using NewHorizons.Handlers; using NewHorizons.Utility; using UnityEngine; -using Logger = NewHorizons.Utility.Logger; namespace NewHorizons.Builder.Props { @@ -66,20 +65,13 @@ namespace NewHorizons.Builder.Props } } - public static GameObject Make(GameObject planetGO, Sector sector, PropModule.ShuttleInfo info) + public static GameObject Make(GameObject planetGO, Sector sector, ShuttleInfo info) { InitPrefab(); if (_prefab == null || planetGO == null || sector == null) return null; - var detailInfo = new PropModule.DetailInfo() - { - position = info.position, - rotation = info.rotation, - parentPath = info.parentPath, - isRelativeToParent = info.isRelativeToParent, - rename = info.rename - }; + var detailInfo = new DetailInfo(info); var shuttleObject = DetailBuilder.Make(planetGO, sector, _prefab, detailInfo); shuttleObject.SetActive(false); diff --git a/NewHorizons/Builder/Props/TranslatorText/TranslatorTextBuilder.cs b/NewHorizons/Builder/Props/TranslatorText/TranslatorTextBuilder.cs index 862257ed..b189ee75 100644 --- a/NewHorizons/Builder/Props/TranslatorText/TranslatorTextBuilder.cs +++ b/NewHorizons/Builder/Props/TranslatorText/TranslatorTextBuilder.cs @@ -26,7 +26,7 @@ namespace NewHorizons.Builder.Props.TranslatorText private static Material _childArcMaterial; private static GameObject _scrollPrefab; public static GameObject ComputerPrefab { get; private set; } - private static GameObject _preCrashComputerPrefab; + public static GameObject PreCrashComputerPrefab { get; private set; } private static GameObject _cairnBHPrefab; private static GameObject _cairnTHPrefab; private static GameObject _cairnCTPrefab; @@ -89,9 +89,9 @@ namespace NewHorizons.Builder.Props.TranslatorText ComputerPrefab = SearchUtilities.Find("VolcanicMoon_Body/Sector_VM/Interactables_VM/Prefab_NOM_Computer").InstantiateInactive().Rename("Prefab_NOM_Computer").DontDestroyOnLoad(); } - if (_preCrashComputerPrefab == null) + if (PreCrashComputerPrefab == null) { - _preCrashComputerPrefab = SearchUtilities.Find("BrittleHollow_Body/Sector_BH/Sector_EscapePodCrashSite/Sector_CrashFragment/EscapePod_Socket/Interactibles_EscapePod/Prefab_NOM_Vessel_Computer").InstantiateInactive().Rename("Prefab_NOM_Vessel_Computer").DontDestroyOnLoad(); + PreCrashComputerPrefab = SearchUtilities.Find("BrittleHollow_Body/Sector_BH/Sector_EscapePodCrashSite/Sector_CrashFragment/EscapePod_Socket/Interactibles_EscapePod/Prefab_NOM_Vessel_Computer").InstantiateInactive().Rename("Prefab_NOM_Vessel_Computer").DontDestroyOnLoad(); } if (_cairnBHPrefab == null) @@ -238,7 +238,7 @@ namespace NewHorizons.Builder.Props.TranslatorText } case NomaiTextType.PreCrashComputer: { - var computerObject = DetailBuilder.Make(planetGO, sector, _preCrashComputerPrefab, new DetailInfo(info)); + var computerObject = DetailBuilder.Make(planetGO, sector, PreCrashComputerPrefab, new DetailInfo(info)); computerObject.SetActive(false); var computer = computerObject.GetComponent(); diff --git a/NewHorizons/Builder/Props/WarpPadBuilder.cs b/NewHorizons/Builder/Props/WarpPadBuilder.cs index 41bf6ed6..5cc6c511 100644 --- a/NewHorizons/Builder/Props/WarpPadBuilder.cs +++ b/NewHorizons/Builder/Props/WarpPadBuilder.cs @@ -144,9 +144,16 @@ namespace NewHorizons.Builder.Props transmitterObject.SetActive(true); } - private static void CreateComputer(GameObject planetGO, Sector sector, NomaiWarpComputerLoggerInfo computerInfo, NomaiWarpReceiver receiver) + private static void CreateComputer(GameObject planetGO, Sector sector, NomaiComputerInfo computerInfo, NomaiWarpReceiver receiver) { - var computerObject = DetailBuilder.Make(planetGO, sector, TranslatorTextBuilder.ComputerPrefab, new DetailInfo(computerInfo)); + var prefab = computerInfo.type switch + { + NomaiComputerType.NORMAL => TranslatorTextBuilder.ComputerPrefab, + NomaiComputerType.PRECRASH => TranslatorTextBuilder.PreCrashComputerPrefab, + _ => throw new System.NotImplementedException() + }; + + var computerObject = DetailBuilder.Make(planetGO, sector, prefab, new DetailInfo(computerInfo)); var computer = computerObject.GetComponentInChildren(); computer.SetSector(sector); diff --git a/NewHorizons/External/Modules/PropModule.cs b/NewHorizons/External/Modules/PropModule.cs index e6bc7d5e..b77c2f68 100644 --- a/NewHorizons/External/Modules/PropModule.cs +++ b/NewHorizons/External/Modules/PropModule.cs @@ -4,6 +4,7 @@ using NewHorizons.External.Modules.Props.Dialogue; using NewHorizons.External.Modules.Props.EchoesOfTheEye; using NewHorizons.External.Modules.Props.Quantum; using NewHorizons.External.Modules.Props.Remote; +using NewHorizons.External.Modules.Props.Shuttle; using NewHorizons.External.Modules.TranslatorText; using NewHorizons.External.Modules.VariableSize; using NewHorizons.External.Modules.Volumes.VolumeInfos; @@ -112,6 +113,16 @@ namespace NewHorizons.External.Modules /// public AudioSourceInfo[] audioSources; + /// + /// Add a gravity cannon to this planet. Must be paired to a new shuttle, which can be placed on this planet or elsewhere. + /// + public GravityCannonInfo[] gravityCannons; + + /// + /// Add a Nomai shuttle to this planet. Can be paired to a gravity cannon on this planet or elsewhere. + /// + public ShuttleInfo[] shuttles; + [Obsolete("reveal is deprecated. Use Volumes->revealVolumes instead.")] public RevealVolumeInfo[] reveal; [Obsolete("audioVolumes is deprecated. Use Volumes->audioVolumes instead.")] public AudioVolumeInfo[] audioVolumes; diff --git a/NewHorizons/External/Modules/Props/NomaiComputerInfo.cs b/NewHorizons/External/Modules/Props/NomaiComputerInfo.cs new file mode 100644 index 00000000..90b58c34 --- /dev/null +++ b/NewHorizons/External/Modules/Props/NomaiComputerInfo.cs @@ -0,0 +1,23 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using System.ComponentModel; +using System.Runtime.Serialization; + +namespace NewHorizons.External.Modules.Props +{ + [JsonObject] + public class NomaiComputerInfo : GeneralPropInfo + { + /// + /// What design the computer will use. + /// + [DefaultValue(NomaiComputerType.NORMAL)] public NomaiComputerType type = NomaiComputerType.NORMAL; + } + + [JsonConverter(typeof(StringEnumConverter))] + public enum NomaiComputerType + { + [EnumMember(Value = @"normal")] NORMAL = 0, + [EnumMember(Value = @"precrash")] PRECRASH = 1 + } +} diff --git a/NewHorizons/External/Modules/Props/Shuttle/GravityCannonInfo.cs b/NewHorizons/External/Modules/Props/Shuttle/GravityCannonInfo.cs new file mode 100644 index 00000000..7f6a3b84 --- /dev/null +++ b/NewHorizons/External/Modules/Props/Shuttle/GravityCannonInfo.cs @@ -0,0 +1,33 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NewHorizons.External.Modules.Props.Shuttle +{ + [JsonObject] + public class GravityCannonInfo : GeneralPropInfo + { + /// + /// Unique ID for the shuttle that pairs with this gravity cannon + /// + public string shuttleID; + + /// + /// Ship log fact revealed when retrieving the shuttle to this pad. Optional. + /// + public string retrieveReveal; + + /// + /// Ship log fact revealed when launching from this pad. Optional. + /// + public string launchReveal; + + /// + /// Will create a modern Nomai computer linked to this gravity cannon. + /// + public NomaiComputerInfo computer; + } +} diff --git a/NewHorizons/External/Modules/Props/Shuttle/ShuttleInfo.cs b/NewHorizons/External/Modules/Props/Shuttle/ShuttleInfo.cs new file mode 100644 index 00000000..8bf959c1 --- /dev/null +++ b/NewHorizons/External/Modules/Props/Shuttle/ShuttleInfo.cs @@ -0,0 +1,18 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NewHorizons.External.Modules.Props.Shuttle +{ + [JsonObject] + public class ShuttleInfo : GeneralPropInfo + { + /// + /// Unique ID for this shuttle + /// + public string id; + } +} diff --git a/NewHorizons/External/Modules/WarpPad/NomaiWarpComputerInfo.cs b/NewHorizons/External/Modules/WarpPad/NomaiWarpComputerInfo.cs deleted file mode 100644 index bd2bb6d7..00000000 --- a/NewHorizons/External/Modules/WarpPad/NomaiWarpComputerInfo.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Newtonsoft.Json; - -namespace NewHorizons.External.Modules.WarpPad -{ - [JsonObject] - public class NomaiWarpComputerLoggerInfo : GeneralPropInfo - { - } -} diff --git a/NewHorizons/External/Modules/WarpPad/NomaiWarpPadReceiverInfo.cs b/NewHorizons/External/Modules/WarpPad/NomaiWarpPadReceiverInfo.cs index 6680284c..05b0b20a 100644 --- a/NewHorizons/External/Modules/WarpPad/NomaiWarpPadReceiverInfo.cs +++ b/NewHorizons/External/Modules/WarpPad/NomaiWarpPadReceiverInfo.cs @@ -1,3 +1,4 @@ +using NewHorizons.External.Modules.Props; using Newtonsoft.Json; namespace NewHorizons.External.Modules.WarpPad @@ -14,7 +15,7 @@ namespace NewHorizons.External.Modules.WarpPad /// /// Will create a modern Nomai computer linked to this receiver. /// - public NomaiWarpComputerLoggerInfo computer; + public NomaiComputerInfo computer; /// /// Set to true if you want to include Nomai ruin details around the warp pad. diff --git a/NewHorizons/Handlers/ShuttleHandler.cs b/NewHorizons/Handlers/ShuttleHandler.cs index e728851d..60f4493f 100644 --- a/NewHorizons/Handlers/ShuttleHandler.cs +++ b/NewHorizons/Handlers/ShuttleHandler.cs @@ -1,11 +1,6 @@ -using NewHorizons.Utility; -using OWML.Common; +using NewHorizons.Utility.OWML; using OWML.Utils; using System; -using System.Collections.Generic; -using System.Linq; -using UnityEngine; -using Logger = NewHorizons.Utility.Logger; namespace NewHorizons.Handlers { @@ -15,8 +10,7 @@ namespace NewHorizons.Handlers { try { - NomaiShuttleController.ShuttleID shuttleID; - if (EnumUtils.TryParse(id, out shuttleID)) + if (EnumUtils.TryParse(id, out NomaiShuttleController.ShuttleID shuttleID)) { return shuttleID; } @@ -27,14 +21,14 @@ namespace NewHorizons.Handlers } catch (Exception e) { - Logger.LogError($"Couldn't load shuttle id [{id}]:\n{e}"); + NHLogger.LogError($"Couldn't load shuttle id [{id}]:\n{e}"); return EnumUtils.FromObject(-1); } } public static NomaiShuttleController.ShuttleID AddCustomShuttleID(string id) { - Logger.LogVerbose($"Registering new shuttle id [{id}]"); + NHLogger.LogVerbose($"Registering new shuttle id [{id}]"); return EnumUtilities.Create(id); }