Add remote builder to multi pass

Do not try catch anymore
This would cause some addon devs to just ignore an error when they really shouldn't. Now it will show the body where this error occurs since the error gets handled higher up.
This commit is contained in:
Noah Pilarski 2024-06-07 07:22:09 -04:00
parent 3cf384accf
commit 96bb04ef6b
6 changed files with 61 additions and 34 deletions

View File

@ -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)

View File

@ -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<SharedStone>()._connectedPlatform = id;

View File

@ -3,7 +3,7 @@ using Newtonsoft.Json;
namespace NewHorizons.External.Modules.Props.Remote
{
[JsonObject]
public class StoneInfo : GeneralPropInfo
public class ProjectionStoneInfo : GeneralPropInfo
{
}

View File

@ -23,11 +23,11 @@ namespace NewHorizons.External.Modules.Props.Remote
/// <summary>
/// Camera platform that the stones can project to and from
/// </summary>
public PlatformInfo platform;
public RemotePlatformInfo platform;
/// <summary>
/// Projection stones
/// </summary>
public StoneInfo[] stones;
public ProjectionStoneInfo[] stones;
}
}

View File

@ -4,7 +4,7 @@ using System.ComponentModel;
namespace NewHorizons.External.Modules.Props.Remote
{
[JsonObject]
public class PlatformInfo : GeneralPropInfo
public class RemotePlatformInfo : GeneralPropInfo
{
/// <summary>
/// A ship log fact to reveal when the platform is connected to.

View File

@ -2,6 +2,7 @@ using NewHorizons.Utility.OWML;
using OWML.Utils;
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace NewHorizons.Handlers
@ -33,11 +34,27 @@ 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<NomaiRemoteCameraPlatform.ID>(id, out platformID)))
{
platformID = AddCustomPlatformID(id);
}
return true;
}
catch (Exception e)
{
NHLogger.LogError($"Couldn't load platform id [{id}]:\n{e}");
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<NomaiRemoteCameraPlatform.ID>(id, out platformID))
{
return platformID;
@ -47,12 +64,6 @@ namespace NewHorizons.Handlers
return AddCustomPlatformID(id);
}
}
catch (Exception e)
{
NHLogger.LogError($"Couldn't load platform id [{id}]:\n{e}");
return NomaiRemoteCameraPlatform.ID.None;
}
}
public static NomaiRemoteCameraPlatform.ID AddCustomPlatformID(string id)
{