diff --git a/NewHorizons/Builder/Props/PropBuildManager.cs b/NewHorizons/Builder/Props/PropBuildManager.cs index 8f7d1190..6605acbd 100644 --- a/NewHorizons/Builder/Props/PropBuildManager.cs +++ b/NewHorizons/Builder/Props/PropBuildManager.cs @@ -128,6 +128,7 @@ namespace NewHorizons.Builder.Props MakeGeneralProps(go, config.Props.warpReceivers, (warpReceiver) => WarpPadBuilder.Make(go, sector, mod, warpReceiver), (warpReceiver) => warpReceiver.frequency); MakeGeneralProps(go, config.Props.warpTransmitters, (warpTransmitter) => WarpPadBuilder.Make(go, sector, mod, warpTransmitter), (warpTransmitter) => warpTransmitter.frequency); MakeGeneralProps(go, config.Props.audioSources, (audioSource) => AudioSourceBuilder.Make(go, sector, audioSource, mod), (audioSource) => audioSource.audio); + RemoteBuilder.InternalMake(go, sector, config.Props.remotes, nhBody); RunMultiPass(); @@ -177,21 +178,6 @@ namespace NewHorizons.Builder.Props } } } - - if (config.Props.remotes != null) - { - foreach (var remoteInfo in config.Props.remotes) - { - try - { - RemoteBuilder.Make(go, sector, remoteInfo, nhBody); - } - catch (Exception ex) - { - NHLogger.LogError($"Couldn't make remote [{remoteInfo.id}] for [{go.name}]:\n{ex}"); - } - } - } } private static bool DoesParentExist(GameObject go, BasePropInfo prop) diff --git a/NewHorizons/Builder/Props/RemoteBuilder.cs b/NewHorizons/Builder/Props/RemoteBuilder.cs index 4ae0ac01..44eed05e 100644 --- a/NewHorizons/Builder/Props/RemoteBuilder.cs +++ b/NewHorizons/Builder/Props/RemoteBuilder.cs @@ -12,6 +12,7 @@ using NewHorizons.Utility.OWML; using OWML.Common; using System; using UnityEngine; +using NewHorizons.External.Modules; namespace NewHorizons.Builder.Props { @@ -122,10 +123,35 @@ namespace NewHorizons.Builder.Props } } + internal static void InternalMake(GameObject go, Sector sector, RemoteInfo[] remotes, NewHorizonsBody nhBody) + { + if (remotes != null) + { + foreach (var remoteInfo in remotes) + { + try + { + var mod = nhBody.Mod; + var id = RemoteHandler.GetPlatformID(remoteInfo.id); + + Texture2D decal = Texture2D.whiteTexture; + if (!string.IsNullOrWhiteSpace(remoteInfo.decalPath)) decal = ImageUtilities.GetTexture(mod, remoteInfo.decalPath, false, false); + else NHLogger.LogError($"Missing decal path on [{remoteInfo.id}] for [{go.name}]"); + + PropBuildManager.MakeGeneralProp(go, remoteInfo.platform, (platform) => MakePlatform(go, sector, id, decal, platform, mod), (platform) => remoteInfo.id); + PropBuildManager.MakeGeneralProp(go, remoteInfo.whiteboard, (whiteboard) => MakeWhiteboard(go, sector, id, decal, whiteboard, nhBody), (whiteboard) => remoteInfo.id); + PropBuildManager.MakeGeneralProps(go, remoteInfo.stones, (stone) => MakeStone(go, sector, id, decal, stone, mod), (stone) => remoteInfo.id); + } + catch (Exception ex) + { + NHLogger.LogError($"Couldn't make remote [{remoteInfo.id}] for [{go.name}]:\n{ex}"); + } + } + } + } + public static void Make(GameObject go, Sector sector, RemoteInfo info, NewHorizonsBody nhBody) { - InitPrefabs(); - var mod = nhBody.Mod; var id = RemoteHandler.GetPlatformID(info.id); @@ -149,7 +175,7 @@ namespace NewHorizons.Builder.Props { try { - MakeWhiteboard(go, sector, nhBody.Mod, id, decal, info.whiteboard, nhBody); + MakeWhiteboard(go, sector, id, decal, info.whiteboard, nhBody); } catch (Exception ex) { @@ -173,8 +199,10 @@ namespace NewHorizons.Builder.Props } } - public static void MakeWhiteboard(GameObject go, Sector sector, IModBehaviour mod, NomaiRemoteCameraPlatform.ID id, Texture2D decal, RemoteWhiteboardInfo info, NewHorizonsBody nhBody) + public static void MakeWhiteboard(GameObject go, Sector sector, NomaiRemoteCameraPlatform.ID id, Texture2D decal, RemoteWhiteboardInfo info, NewHorizonsBody nhBody) { + InitPrefabs(); + var mod = nhBody.Mod; var whiteboard = DetailBuilder.Make(go, sector, mod, _whiteboardPrefab, new DetailInfo(info)); whiteboard.SetActive(false); @@ -213,8 +241,9 @@ namespace NewHorizons.Builder.Props whiteboard.SetActive(true); } - public static void MakePlatform(GameObject go, Sector sector, NomaiRemoteCameraPlatform.ID id, Texture2D decal, PlatformInfo info, IModBehaviour mod) + public static void MakePlatform(GameObject go, Sector sector, NomaiRemoteCameraPlatform.ID id, Texture2D decal, RemotePlatformInfo info, IModBehaviour mod) { + InitPrefabs(); var platform = DetailBuilder.Make(go, sector, mod, _remoteCameraPlatformPrefab, new DetailInfo(info)); platform.SetActive(false); @@ -239,8 +268,9 @@ namespace NewHorizons.Builder.Props platform.SetActive(true); } - public static void MakeStone(GameObject go, Sector sector, NomaiRemoteCameraPlatform.ID id, Texture2D decal, StoneInfo info, IModBehaviour mod) + public static void MakeStone(GameObject go, Sector sector, NomaiRemoteCameraPlatform.ID id, Texture2D decal, ProjectionStoneInfo info, IModBehaviour mod) { + InitPrefabs(); var shareStone = GeneralPropBuilder.MakeFromPrefab(_shareStonePrefab, "ShareStone_" + id.ToString(), go, sector, info); shareStone.GetComponent()._connectedPlatform = id; diff --git a/NewHorizons/External/Modules/Props/Remote/StoneInfo.cs b/NewHorizons/External/Modules/Props/Remote/ProjectionStoneInfo.cs similarity index 66% rename from NewHorizons/External/Modules/Props/Remote/StoneInfo.cs rename to NewHorizons/External/Modules/Props/Remote/ProjectionStoneInfo.cs index 0380b676..eeeab082 100644 --- a/NewHorizons/External/Modules/Props/Remote/StoneInfo.cs +++ b/NewHorizons/External/Modules/Props/Remote/ProjectionStoneInfo.cs @@ -3,7 +3,7 @@ using Newtonsoft.Json; namespace NewHorizons.External.Modules.Props.Remote { [JsonObject] - public class StoneInfo : GeneralPropInfo + public class ProjectionStoneInfo : GeneralPropInfo { } diff --git a/NewHorizons/External/Modules/Props/Remote/RemoteInfo.cs b/NewHorizons/External/Modules/Props/Remote/RemoteInfo.cs index ab8e1faf..a9467892 100644 --- a/NewHorizons/External/Modules/Props/Remote/RemoteInfo.cs +++ b/NewHorizons/External/Modules/Props/Remote/RemoteInfo.cs @@ -23,11 +23,11 @@ namespace NewHorizons.External.Modules.Props.Remote /// /// Camera platform that the stones can project to and from /// - public PlatformInfo platform; + public RemotePlatformInfo platform; /// /// Projection stones /// - public StoneInfo[] stones; + public ProjectionStoneInfo[] stones; } } diff --git a/NewHorizons/External/Modules/Props/Remote/PlatformInfo.cs b/NewHorizons/External/Modules/Props/Remote/RemotePlatformInfo.cs similarity index 91% rename from NewHorizons/External/Modules/Props/Remote/PlatformInfo.cs rename to NewHorizons/External/Modules/Props/Remote/RemotePlatformInfo.cs index 5ad4afa9..e5b0cca7 100644 --- a/NewHorizons/External/Modules/Props/Remote/PlatformInfo.cs +++ b/NewHorizons/External/Modules/Props/Remote/RemotePlatformInfo.cs @@ -4,7 +4,7 @@ using System.ComponentModel; namespace NewHorizons.External.Modules.Props.Remote { [JsonObject] - public class PlatformInfo : GeneralPropInfo + public class RemotePlatformInfo : GeneralPropInfo { /// /// A ship log fact to reveal when the platform is connected to. diff --git a/NewHorizons/Handlers/RemoteHandler.cs b/NewHorizons/Handlers/RemoteHandler.cs index 28c52e9b..81c6c41e 100644 --- a/NewHorizons/Handlers/RemoteHandler.cs +++ b/NewHorizons/Handlers/RemoteHandler.cs @@ -2,6 +2,7 @@ using NewHorizons.Utility.OWML; using OWML.Utils; using System; using System.Collections.Generic; +using System.Diagnostics; namespace NewHorizons.Handlers @@ -33,24 +34,34 @@ namespace NewHorizons.Handlers return id.ToString(); } - public static NomaiRemoteCameraPlatform.ID GetPlatformID(string id) + public static bool TryGetPlatformID(string id, out NomaiRemoteCameraPlatform.ID platformID) { try { - NomaiRemoteCameraPlatform.ID platformID; - if (_customPlatformIDs.TryGetValue(id, out platformID) || EnumUtils.TryParse(id, out platformID)) + if (!(_customPlatformIDs.TryGetValue(id, out platformID) || EnumUtils.TryParse(id, out platformID))) { - return platformID; - } - else - { - return AddCustomPlatformID(id); + platformID = AddCustomPlatformID(id); } + return true; } catch (Exception e) { NHLogger.LogError($"Couldn't load platform id [{id}]:\n{e}"); - return NomaiRemoteCameraPlatform.ID.None; + platformID = NomaiRemoteCameraPlatform.ID.None; + return false; + } + } + + public static NomaiRemoteCameraPlatform.ID GetPlatformID(string id) + { + NomaiRemoteCameraPlatform.ID platformID = NomaiRemoteCameraPlatform.ID.None; + if (_customPlatformIDs.TryGetValue(id, out platformID) || EnumUtils.TryParse(id, out platformID)) + { + return platformID; + } + else + { + return AddCustomPlatformID(id); } }