Add IModBehavior params to detail builder and hierarchy

This commit is contained in:
Joshua Thome 2023-10-31 01:31:05 -05:00
parent ee154fdb33
commit 358f130c0d
15 changed files with 54 additions and 49 deletions

View File

@ -6,6 +6,7 @@ using NewHorizons.External.Modules;
using NewHorizons.External.Modules.Props;
using NewHorizons.Utility;
using NewHorizons.Utility.OWML;
using OWML.Common;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
@ -80,7 +81,7 @@ namespace NewHorizons.Builder.Body
if (_wallCollision == null) _wallCollision = Main.NHPrivateAssetBundle.LoadAsset<GameObject>("BrambleCollision");
}
public static GameObject Make(NewHorizonsBody body, GameObject go, NHAstroObject ao, Sector sector, OWRigidbody owRigidBody)
public static GameObject Make(NewHorizonsBody body, GameObject go, NHAstroObject ao, Sector sector, IModBehaviour mod, OWRigidbody owRigidBody)
{
InitPrefabs();
@ -102,7 +103,7 @@ namespace NewHorizons.Builder.Body
default: geometryPrefab = _hubGeometry; break;
}
var geometry = DetailBuilder.Make(go, sector, geometryPrefab, new DetailInfo());
var geometry = DetailBuilder.Make(go, sector, mod, geometryPrefab, new DetailInfo());
var exitWarps = _exitWarps.InstantiateInactive();
var repelVolume = _repelVolume.InstantiateInactive();

View File

@ -52,24 +52,16 @@ namespace NewHorizons.Builder.Props
/// <summary>
/// Create a detail using an asset bundle or a path in the scene hierarchy of the item to copy.
/// </summary>
public static GameObject Make(GameObject go, Sector sector, IModBehaviour mod, DetailInfo detail)
public static GameObject Make(GameObject planetGO, Sector sector, IModBehaviour mod, DetailInfo info)
{
if (detail.assetBundle != null)
if (info.assetBundle != null)
{
// Shouldn't happen
if (mod == null) return null;
return Make(go, sector, AssetBundleUtilities.LoadPrefab(detail.assetBundle, detail.path, mod), detail);
return Make(planetGO, sector, mod, AssetBundleUtilities.LoadPrefab(info.assetBundle, info.path, mod), info);
}
else
return Make(go, sector, detail);
}
/// <summary>
/// Create a detail using a path in the scene hierarchy of the item to copy.
/// </summary>
public static GameObject Make(GameObject planetGO, Sector sector, DetailInfo info)
{
if (_emptyPrefab == null) _emptyPrefab = new GameObject("Empty");
// Allow for empty game objects so you can set up conditional activation on them and parent other props to them
@ -82,14 +74,14 @@ namespace NewHorizons.Builder.Props
}
else
{
return Make(planetGO, sector, prefab, info);
return Make(planetGO, sector, mod, prefab, info);
}
}
/// <summary>
/// Create a detail using a prefab.
/// </summary>
public static GameObject Make(GameObject go, Sector sector, GameObject prefab, DetailInfo detail)
public static GameObject Make(GameObject go, Sector sector, IModBehaviour mod, GameObject prefab, DetailInfo detail)
{
if (prefab == null) return null;
@ -165,7 +157,7 @@ namespace NewHorizons.Builder.Props
if (detail.item != null)
{
ItemBuilder.MakeItem(prop, go, sector, detail.item);
ItemBuilder.MakeItem(prop, go, sector, detail.item, mod);
}
if (detail.itemSocket != null)

View File

@ -76,7 +76,7 @@ namespace NewHorizons.Builder.Props
if (_interfacePrefab == null || planetGO == null || sector == null || _detailedPlatformPrefab == null || _platformPrefab == null || _orbPrefab == null) return null;
var detailInfo = new DetailInfo(info.controls) { keepLoaded = true };
var gravityCannonObject = DetailBuilder.Make(planetGO, sector, _interfacePrefab, detailInfo);
var gravityCannonObject = DetailBuilder.Make(planetGO, sector, mod, _interfacePrefab, detailInfo);
gravityCannonObject.SetActive(false);
var gravityCannonController = gravityCannonObject.GetComponent<GravityCannonController>();
@ -87,7 +87,7 @@ namespace NewHorizons.Builder.Props
gravityCannonController._retrieveShipLogFact = info.retrieveReveal ?? string.Empty;
gravityCannonController._launchShipLogFact = info.launchReveal ?? string.Empty;
CreatePlatform(planetGO, sector, gravityCannonController, info);
CreatePlatform(planetGO, sector, mod, gravityCannonController, info);
if (info.computer != null)
{
@ -175,9 +175,9 @@ namespace NewHorizons.Builder.Props
return computer;
}
private static GameObject CreatePlatform(GameObject planetGO, Sector sector, GravityCannonController gravityCannonController, GravityCannonInfo platformInfo)
private static GameObject CreatePlatform(GameObject planetGO, Sector sector, IModBehaviour mod, GravityCannonController gravityCannonController, GravityCannonInfo platformInfo)
{
var platform = DetailBuilder.Make(planetGO, sector, platformInfo.detailed ? _detailedPlatformPrefab : _platformPrefab, new DetailInfo(platformInfo) { keepLoaded = true });
var platform = DetailBuilder.Make(planetGO, sector, mod, platformInfo.detailed ? _detailedPlatformPrefab : _platformPrefab, new DetailInfo(platformInfo) { keepLoaded = true });
gravityCannonController._forceVolume = platform.FindChild("ForceVolume").GetComponent<DirectionalForceVolume>();
gravityCannonController._platformTrigger = platform.FindChild("PlatformTrigger").GetComponent<OWTriggerVolume>();

View File

@ -376,7 +376,7 @@ namespace NewHorizons.Builder.Props
}
case NomaiTextType.PreCrashComputer:
{
var computerObject = DetailBuilder.Make(planetGO, sector, _preCrashComputerPrefab, new DetailInfo(info));
var computerObject = DetailBuilder.Make(planetGO, sector, mod, _preCrashComputerPrefab, new DetailInfo(info));
computerObject.SetActive(false);
var up = computerObject.transform.position - planetGO.transform.position;
@ -493,7 +493,7 @@ namespace NewHorizons.Builder.Props
case NomaiTextType.Recorder:
{
var prefab = (info.type == NomaiTextType.PreCrashRecorder ? _preCrashRecorderPrefab : _recorderPrefab);
var recorderObject = DetailBuilder.Make(planetGO, sector, prefab, new DetailInfo(info));
var recorderObject = DetailBuilder.Make(planetGO, sector, mod, prefab, new DetailInfo(info));
recorderObject.SetActive(false);
if (info.rotation == null)

View File

@ -203,7 +203,7 @@ namespace NewHorizons.Builder.Props
if (_visionTorchDetectorPrefab == null) return null;
// spawn a trigger for the vision torch
var g = DetailBuilder.Make(planetGO, sector, _visionTorchDetectorPrefab, new DetailInfo(info) { scale = 2, rename = !string.IsNullOrEmpty(info.rename) ? info.rename : "VisionStaffDetector" });
var g = DetailBuilder.Make(planetGO, sector, mod, _visionTorchDetectorPrefab, new DetailInfo(info) { scale = 2, rename = !string.IsNullOrEmpty(info.rename) ? info.rename : "VisionStaffDetector" });
if (g == null)
{
@ -240,7 +240,7 @@ namespace NewHorizons.Builder.Props
if (_standingVisionTorchPrefab == null) return null;
// Spawn the torch itself
var standingTorch = DetailBuilder.Make(planetGO, sector, _standingVisionTorchPrefab, new DetailInfo(info));
var standingTorch = DetailBuilder.Make(planetGO, sector, mod, _standingVisionTorchPrefab, new DetailInfo(info));
if (standingTorch == null)
{

View File

@ -39,7 +39,7 @@ namespace NewHorizons.Builder.Props
{
try
{
ShuttleBuilder.Make(go, sector, shuttleInfo);
ShuttleBuilder.Make(go, sector, nhBody.Mod, shuttleInfo);
}
catch (Exception ex)
{
@ -283,7 +283,7 @@ namespace NewHorizons.Builder.Props
{
try
{
WarpPadBuilder.Make(go, sector, warpReceiver);
WarpPadBuilder.Make(go, sector, nhBody.Mod, warpReceiver);
}
catch (Exception ex)
{
@ -297,7 +297,7 @@ namespace NewHorizons.Builder.Props
{
try
{
WarpPadBuilder.Make(go, sector, warpTransmitter);
WarpPadBuilder.Make(go, sector, nhBody.Mod, warpTransmitter);
}
catch (Exception ex)
{

View File

@ -149,7 +149,7 @@ namespace NewHorizons.Builder.Props
{
try
{
MakeWhiteboard(go, sector, id, decal, info.whiteboard, nhBody);
MakeWhiteboard(go, sector, nhBody.Mod, id, decal, info.whiteboard, nhBody);
}
catch (Exception ex)
{
@ -173,9 +173,9 @@ namespace NewHorizons.Builder.Props
}
}
public static void MakeWhiteboard(GameObject go, Sector sector, NomaiRemoteCameraPlatform.ID id, Texture2D decal, RemoteWhiteboardInfo info, NewHorizonsBody nhBody)
public static void MakeWhiteboard(GameObject go, Sector sector, IModBehaviour mod, NomaiRemoteCameraPlatform.ID id, Texture2D decal, RemoteWhiteboardInfo info, NewHorizonsBody nhBody)
{
var whiteboard = DetailBuilder.Make(go, sector, _whiteboardPrefab, new DetailInfo(info));
var whiteboard = DetailBuilder.Make(go, sector, mod, _whiteboardPrefab, new DetailInfo(info));
whiteboard.SetActive(false);
var decalMat = new Material(_decalMaterial);
@ -215,7 +215,7 @@ namespace NewHorizons.Builder.Props
public static void MakePlatform(GameObject go, Sector sector, NomaiRemoteCameraPlatform.ID id, Texture2D decal, PlatformInfo info, IModBehaviour mod)
{
var platform = DetailBuilder.Make(go, sector, _remoteCameraPlatformPrefab, new DetailInfo(info));
var platform = DetailBuilder.Make(go, sector, mod, _remoteCameraPlatformPrefab, new DetailInfo(info));
platform.SetActive(false);
var decalMat = new Material(_decalMaterial);

View File

@ -77,7 +77,7 @@ namespace NewHorizons.Builder.Props
stretch = propInfo.stretch,
keepLoaded = propInfo.keepLoaded
};
var scatterPrefab = DetailBuilder.Make(go, sector, prefab, detailInfo);
var scatterPrefab = DetailBuilder.Make(go, sector, mod, prefab, detailInfo);
for (int i = 0; i < propInfo.count; i++)
{

View File

@ -3,6 +3,7 @@ using NewHorizons.External.Modules.Props;
using NewHorizons.External.Modules.Props.Shuttle;
using NewHorizons.Handlers;
using NewHorizons.Utility;
using OWML.Common;
using System.Collections.Generic;
using UnityEngine;
@ -69,14 +70,14 @@ namespace NewHorizons.Builder.Props
}
}
public static GameObject Make(GameObject planetGO, Sector sector, ShuttleInfo info)
public static GameObject Make(GameObject planetGO, Sector sector, IModBehaviour mod, ShuttleInfo info)
{
InitPrefab();
if (_prefab == null || planetGO == null || sector == null) return null;
var detailInfo = new DetailInfo(info) { keepLoaded = true };
var shuttleObject = DetailBuilder.Make(planetGO, sector, _prefab, detailInfo);
var shuttleObject = DetailBuilder.Make(planetGO, sector, mod, _prefab, detailInfo);
shuttleObject.SetActive(false);
StreamingHandler.SetUpStreaming(shuttleObject, sector);

View File

@ -242,7 +242,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, nhBody.Mod, PreCrashComputerPrefab, new DetailInfo(info));
computerObject.SetActive(false);
var computer = computerObject.GetComponent<NomaiVesselComputer>();
@ -323,7 +323,7 @@ namespace NewHorizons.Builder.Props.TranslatorText
case NomaiTextType.Recorder:
{
var prefab = (info.type == NomaiTextType.PreCrashRecorder ? _preCrashRecorderPrefab : _recorderPrefab);
var recorderObject = DetailBuilder.Make(planetGO, sector, prefab, new DetailInfo(info));
var recorderObject = DetailBuilder.Make(planetGO, sector, nhBody.Mod, prefab, new DetailInfo(info));
recorderObject.SetActive(false);
var nomaiText = recorderObject.GetComponentInChildren<NomaiText>();
@ -373,7 +373,7 @@ namespace NewHorizons.Builder.Props.TranslatorText
path = "BrittleHollow_Body/Sector_BH/Sector_NorthHemisphere/Sector_NorthPole/Sector_HangingCity/Sector_HangingCity_District2/Interactables_HangingCity_District2/VisibleFrom_HangingCity/Props_NOM_Whiteboard (1)",
rename = info.rename ?? "Props_NOM_Whiteboard",
};
var whiteboardObject = DetailBuilder.Make(planetGO, sector, whiteboardInfo);
var whiteboardObject = DetailBuilder.Make(planetGO, sector, nhBody.Mod, whiteboardInfo);
// Spawn a scroll and insert it into the whiteboard, but only if text is provided
if (!string.IsNullOrEmpty(info.xmlFile))

View File

@ -6,6 +6,7 @@ using NewHorizons.External.Modules.WarpPad;
using NewHorizons.Utility;
using NewHorizons.Utility.OuterWilds;
using NewHorizons.Utility.OWML;
using OWML.Common;
using OWML.Utils;
using UnityEngine;
@ -86,10 +87,10 @@ namespace NewHorizons.Builder.Props
}
}
public static void Make(GameObject planetGO, Sector sector, NomaiWarpReceiverInfo info)
public static void Make(GameObject planetGO, Sector sector, IModBehaviour mod, NomaiWarpReceiverInfo info)
{
var detailInfo = new DetailInfo(info);
var receiverObject = DetailBuilder.Make(planetGO, sector, info.detailed ? _detailedReceiverPrefab : _receiverPrefab, detailInfo);
var receiverObject = DetailBuilder.Make(planetGO, sector, mod, info.detailed ? _detailedReceiverPrefab : _receiverPrefab, detailInfo);
NHLogger.Log($"Position is {detailInfo.position} was {info.position}");
@ -122,13 +123,13 @@ namespace NewHorizons.Builder.Props
if (info.computer != null)
{
CreateComputer(planetGO, sector, info.computer, receiver);
CreateComputer(planetGO, sector, mod, info.computer, receiver);
}
}
public static void Make(GameObject planetGO, Sector sector, NomaiWarpTransmitterInfo info)
public static void Make(GameObject planetGO, Sector sector, IModBehaviour mod, NomaiWarpTransmitterInfo info)
{
var transmitterObject = DetailBuilder.Make(planetGO, sector, _transmitterPrefab, new DetailInfo(info));
var transmitterObject = DetailBuilder.Make(planetGO, sector, mod, _transmitterPrefab, new DetailInfo(info));
var transmitter = transmitterObject.GetComponentInChildren<NomaiWarpTransmitter>();
transmitter._frequency = GetFrequency(info.frequency);
@ -145,9 +146,9 @@ namespace NewHorizons.Builder.Props
transmitterObject.SetActive(true);
}
private static void CreateComputer(GameObject planetGO, Sector sector, GeneralPropInfo computerInfo, NomaiWarpReceiver receiver)
private static void CreateComputer(GameObject planetGO, Sector sector, IModBehaviour mod, GeneralPropInfo computerInfo, NomaiWarpReceiver receiver)
{
var computerObject = DetailBuilder.Make(planetGO, sector, TranslatorTextBuilder.ComputerPrefab, new DetailInfo(computerInfo));
var computerObject = DetailBuilder.Make(planetGO, sector, mod, TranslatorTextBuilder.ComputerPrefab, new DetailInfo(computerInfo));
var computer = computerObject.GetComponentInChildren<NomaiComputer>();
computer.SetSector(sector);

View File

@ -377,7 +377,7 @@ namespace NewHorizons.Handlers
ao._rootSector = sector;
ao._type = AstroObject.Type.None;
BrambleDimensionBuilder.Make(body, go, ao, sector, owRigidBody);
BrambleDimensionBuilder.Make(body, go, ao, sector, body.Mod, owRigidBody);
go = SharedGenerateBody(body, go, sector, owRigidBody);

View File

@ -16,6 +16,9 @@ namespace NewHorizons
[Obsolete("Create(Dictionary<string, object> config) is deprecated, please use LoadConfigs(IModBehaviour mod) instead")]
void Create(Dictionary<string, object> config, IModBehaviour mod);
[Obsolete("SpawnObject(GameObject planet, Sector sector, string propToCopyPath, Vector3 position, Vector3 eulerAngles, float scale, bool alignRadial) is deprecated, please use SpawnObject(IModBehaviour mod, GameObject planet, Sector sector, string propToCopyPath, Vector3 position, Vector3 eulerAngles, float scale, bool alignRadial) instead")]
GameObject SpawnObject(GameObject planet, Sector sector, string propToCopyPath, Vector3 position, Vector3 eulerAngles, float scale, bool alignWithNormal);
#endregion
/// <summary>
@ -105,7 +108,7 @@ namespace NewHorizons
/// 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.
/// </summary>
GameObject SpawnObject(GameObject planet, Sector sector, string propToCopyPath, Vector3 position, Vector3 eulerAngles,
GameObject SpawnObject(IModBehaviour mod, GameObject planet, Sector sector, string propToCopyPath, Vector3 position, Vector3 eulerAngles,
float scale, bool alignWithNormal);
/// <summary>

View File

@ -70,6 +70,13 @@ namespace NewHorizons
}
}
[Obsolete("SpawnObject(GameObject planet, Sector sector, string propToCopyPath, Vector3 position, Vector3 eulerAngles, float scale, bool alignRadial) is deprecated, please use SpawnObject(IModBehaviour mod, GameObject planet, Sector sector, string propToCopyPath, Vector3 position, Vector3 eulerAngles, float scale, bool alignRadial) instead")]
public GameObject SpawnObject(GameObject planet, Sector sector, string propToCopyPath, Vector3 position, Vector3 eulerAngles,
float scale, bool alignRadial)
{
return SpawnObject(null, planet, sector, propToCopyPath, position, eulerAngles, scale, alignRadial);
}
public void LoadConfigs(IModBehaviour mod)
{
Main.Instance.LoadConfigs(mod);
@ -170,7 +177,7 @@ namespace NewHorizons
return default;
}
public GameObject SpawnObject(GameObject planet, Sector sector, string propToCopyPath, Vector3 position, Vector3 eulerAngles,
public GameObject SpawnObject(IModBehaviour mod, GameObject planet, Sector sector, string propToCopyPath, Vector3 position, Vector3 eulerAngles,
float scale, bool alignRadial)
{
var prefab = SearchUtilities.Find(propToCopyPath);
@ -181,7 +188,7 @@ namespace NewHorizons
scale = scale,
alignRadial = alignRadial
};
return DetailBuilder.Make(planet, sector, prefab, detailInfo);
return DetailBuilder.Make(planet, sector, mod, prefab, detailInfo);
}
public AudioSignal SpawnSignal(IModBehaviour mod, GameObject root, string audio, string name, string frequency,

View File

@ -157,7 +157,7 @@ namespace NewHorizons.Utility.DebugTools
position = data.pos,
rotation = data.rot.eulerAngles,
};
var prop = DetailBuilder.Make(planetGO, sector, prefab, detailInfo);
var prop = DetailBuilder.Make(planetGO, sector, null, prefab, detailInfo);
var body = data.hitBodyGameObject.GetComponent<AstroObject>();
if (body != null) RegisterProp(body, prop);