Try catch pairing singularities, get radius from black hole size

This commit is contained in:
Nick 2024-02-25 20:07:08 -05:00
parent 73817ed54b
commit ceb688c988

View File

@ -12,6 +12,7 @@ using NewHorizons.Utility.OWML;
using NewHorizons.Utility.OuterWilds; using NewHorizons.Utility.OuterWilds;
using NewHorizons.External.SerializableData; using NewHorizons.External.SerializableData;
using NewHorizons.Builder.Volumes; using NewHorizons.Builder.Volumes;
using System;
namespace NewHorizons.Builder.Body namespace NewHorizons.Builder.Body
{ {
@ -109,6 +110,8 @@ namespace NewHorizons.Builder.Body
public static void PairAllSingularities() public static void PairAllSingularities()
{ {
foreach (var pair in _pairsToLink) foreach (var pair in _pairsToLink)
{
try
{ {
var (blackHoleID, whiteHoleID) = pair; var (blackHoleID, whiteHoleID) = pair;
if (!_singularitiesByID.TryGetValue(blackHoleID, out GameObject blackHole)) if (!_singularitiesByID.TryGetValue(blackHoleID, out GameObject blackHole))
@ -140,13 +143,21 @@ namespace NewHorizons.Builder.Body
var streamingGroup = whiteHoleVolume.GetAttachedOWRigidbody().GetComponentInChildren<StreamingGroup>(); var streamingGroup = whiteHoleVolume.GetAttachedOWRigidbody().GetComponentInChildren<StreamingGroup>();
if (streamingGroup != null) if (streamingGroup != null)
{ {
var sphereCollider = blackHoleVolume.GetComponent<SphereCollider>();
// Shouldn't ever be null but doesn't hurt ig
var loadRadius = sphereCollider == null ? 100f : sphereCollider.radius + 50f;
var streamingVolume = VolumeBuilder.Make<StreamingWarpVolume>(blackHoleVolume.GetAttachedOWRigidbody().gameObject, blackHoleVolume.GetComponentInParent<Sector>(), var streamingVolume = VolumeBuilder.Make<StreamingWarpVolume>(blackHoleVolume.GetAttachedOWRigidbody().gameObject, blackHoleVolume.GetComponentInParent<Sector>(),
new External.Modules.Volumes.VolumeInfos.VolumeInfo() { radius = 100f }); new External.Modules.Volumes.VolumeInfos.VolumeInfo() { radius = loadRadius });
streamingVolume.streamingGroup = streamingGroup; streamingVolume.streamingGroup = streamingGroup;
streamingVolume.transform.parent = blackHoleVolume.transform; streamingVolume.transform.parent = blackHoleVolume.transform;
streamingVolume.transform.localPosition = Vector3.zero; streamingVolume.transform.localPosition = Vector3.zero;
} }
} }
catch (Exception e)
{
NHLogger.LogError($"Failed to pair singularities {e}");
}
}
} }
public static GameObject MakeSingularity(GameObject planetGO, Sector sector, Vector3 position, Vector3 rotation, bool polarity, float horizon, float distort, public static GameObject MakeSingularity(GameObject planetGO, Sector sector, Vector3 position, Vector3 rotation, bool polarity, float horizon, float distort,
@ -179,7 +190,7 @@ namespace NewHorizons.Builder.Body
OWAudioSource oneShotOWAudioSource = null; OWAudioSource oneShotOWAudioSource = null;
var singularityAmbience = Object.Instantiate(_blackHoleAmbience, singularity.transform); var singularityAmbience = GameObject.Instantiate(_blackHoleAmbience, singularity.transform);
singularityAmbience.name = polarity ? "BlackHoleAmbience" : "WhiteHoleAmbience"; singularityAmbience.name = polarity ? "BlackHoleAmbience" : "WhiteHoleAmbience";
singularityAmbience.SetActive(true); singularityAmbience.SetActive(true);
singularityAmbience.GetComponent<SectorAudioGroup>().SetSector(sector); singularityAmbience.GetComponent<SectorAudioGroup>().SetSector(sector);
@ -226,7 +237,7 @@ namespace NewHorizons.Builder.Body
} }
else else
{ {
var blackHoleOneShot = Object.Instantiate(_blackHoleEmissionOneShot, singularity.transform); var blackHoleOneShot = GameObject.Instantiate(_blackHoleEmissionOneShot, singularity.transform);
blackHoleOneShot.name = "BlackHoleEmissionOneShot"; blackHoleOneShot.name = "BlackHoleEmissionOneShot";
blackHoleOneShot.SetActive(true); blackHoleOneShot.SetActive(true);
oneShotOWAudioSource = blackHoleOneShot.GetComponent<OWAudioSource>(); oneShotOWAudioSource = blackHoleOneShot.GetComponent<OWAudioSource>();
@ -235,7 +246,7 @@ namespace NewHorizons.Builder.Body
oneShotAudioSource.minDistance = horizon; oneShotAudioSource.minDistance = horizon;
if (sizeController != null) sizeController.oneShotAudioSource = oneShotAudioSource; if (sizeController != null) sizeController.oneShotAudioSource = oneShotAudioSource;
var blackHoleVolume = Object.Instantiate(_blackHoleVolume, singularity.transform); var blackHoleVolume = GameObject.Instantiate(_blackHoleVolume, singularity.transform);
blackHoleVolume.name = "BlackHoleVolume"; blackHoleVolume.name = "BlackHoleVolume";
// Scale vanish effect to black hole size // Scale vanish effect to black hole size
@ -261,7 +272,7 @@ namespace NewHorizons.Builder.Body
{ {
foreach (var renderer in blackHoleVolume.GetComponentsInChildren<ParticleSystemRenderer>(true)) foreach (var renderer in blackHoleVolume.GetComponentsInChildren<ParticleSystemRenderer>(true))
{ {
Object.Destroy(renderer); GameObject.Destroy(renderer);
} }
}); });
} }
@ -269,7 +280,7 @@ namespace NewHorizons.Builder.Body
} }
else else
{ {
GameObject whiteHoleVolumeGO = Object.Instantiate(_whiteHoleVolume); GameObject whiteHoleVolumeGO = GameObject.Instantiate(_whiteHoleVolume);
whiteHoleVolumeGO.transform.parent = singularity.transform; whiteHoleVolumeGO.transform.parent = singularity.transform;
whiteHoleVolumeGO.transform.localPosition = Vector3.zero; whiteHoleVolumeGO.transform.localPosition = Vector3.zero;
whiteHoleVolumeGO.transform.localScale = Vector3.one; whiteHoleVolumeGO.transform.localScale = Vector3.one;