diff --git a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs index f67bc42f..ecb273b1 100644 --- a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs +++ b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs @@ -454,6 +454,8 @@ namespace NewHorizons.Components.SizeControllers public float GetSupernovaRadius() => supernova.GetSupernovaRadius(); + public float GetSurfaceRadius() => transform.localScale.x; + public float GetMaxSupernovaRadius() => supernovaSize; protected new void FixedUpdate() diff --git a/NewHorizons/Components/Stars/SunLightEffectsController.cs b/NewHorizons/Components/Stars/SunLightEffectsController.cs index 6d26808e..14af0ee9 100644 --- a/NewHorizons/Components/Stars/SunLightEffectsController.cs +++ b/NewHorizons/Components/Stars/SunLightEffectsController.cs @@ -1,4 +1,5 @@ using NewHorizons.Builder.Atmosphere; +using NewHorizons.Components.SizeControllers; using NewHorizons.Utility.OWML; using System.Collections.Generic; using UnityEngine; @@ -17,7 +18,11 @@ namespace NewHorizons.Components.Stars private readonly List _stars = new(); private readonly List _lights = new(); - private StarController _activeStar; + // SunController or StarEvolutionController + public StarEvolutionController ActiveStarEvolutionController { get; private set; } + public SunController ActiveSunController { get; private set; } + + private StarController _activeStarController; private SunLightController _sunLightController; private SunLightParamUpdater _sunLightParamUpdater; @@ -54,7 +59,7 @@ namespace NewHorizons.Components.Stars NHLogger.LogVerbose($"Removing star from list: {star?.gameObject?.name}"); if (Instance._stars.Contains(star)) { - if (Instance._activeStar != null && Instance._activeStar.Equals(star)) + if (Instance._activeStarController != null && Instance._activeStarController.Equals(star)) { Instance._stars.Remove(star); if (Instance._stars.Count > 0) Instance.ChangeActiveStar(Instance._stars[0]); @@ -121,11 +126,11 @@ namespace NewHorizons.Components.Stars if (_stars.Count > 0) { - if (_activeStar == null || !_activeStar.gameObject.activeInHierarchy) + if (_activeStarController == null || !_activeStarController.gameObject.activeInHierarchy) { - if (_stars.Contains(_activeStar)) + if (_stars.Contains(_activeStarController)) { - _stars.Remove(_activeStar); + _stars.Remove(_activeStarController); } if (_stars.Count > 0) @@ -145,8 +150,8 @@ namespace NewHorizons.Components.Stars // Update atmo shaders foreach (var (planet, material) in AtmosphereBuilder.Skys) { - var sqrDist = (planet.transform.position - _activeStar.transform.position).sqrMagnitude; - var intensity = Mathf.Min(_activeStar.Intensity / (sqrDist / hearthSunDistanceSqr), 1f); + var sqrDist = (planet.transform.position - _activeStarController.transform.position).sqrMagnitude; + var intensity = Mathf.Min(_activeStarController.Intensity / (sqrDist / hearthSunDistanceSqr), 1f); material.SetFloat(SunIntensity, intensity); } @@ -156,7 +161,7 @@ namespace NewHorizons.Components.Stars if (star == null) continue; if (!(star.gameObject.activeSelf && star.gameObject.activeInHierarchy)) continue; - if (star.Intensity * (star.transform.position - origin).sqrMagnitude < _activeStar.Intensity * (_activeStar.transform.position - origin).sqrMagnitude) + if (star.Intensity * (star.transform.position - origin).sqrMagnitude < _activeStarController.Intensity * (_activeStarController.transform.position - origin).sqrMagnitude) { ChangeActiveStar(star); break; @@ -170,11 +175,13 @@ namespace NewHorizons.Components.Stars { if (_sunLightController == null || _sunLightParamUpdater == null) return; - if (_activeStar != null) _activeStar.Disable(); + _activeStarController?.Disable(); NHLogger.LogVerbose($"Switching active star: {star.gameObject.name}"); - _activeStar = star; + _activeStarController = star; + ActiveStarEvolutionController = star.GetComponentInChildren(); + ActiveSunController = star.GetComponent(); star.Enable(); diff --git a/NewHorizons/Patches/SunPatches/SunLightParamUpdaterPatches.cs b/NewHorizons/Patches/SunPatches/SunLightParamUpdaterPatches.cs index 45d68e3e..8062a9c2 100644 --- a/NewHorizons/Patches/SunPatches/SunLightParamUpdaterPatches.cs +++ b/NewHorizons/Patches/SunPatches/SunLightParamUpdaterPatches.cs @@ -1,4 +1,5 @@ using HarmonyLib; +using NewHorizons.Components.Stars; using UnityEngine; namespace NewHorizons.Patches.SunPatches { @@ -13,10 +14,20 @@ namespace NewHorizons.Patches.SunPatches { Vector3 position = __instance.transform.position; float w = 2000f; - if (__instance._sunController != null) + + var sunController = SunLightEffectsController.Instance.ActiveSunController; + var starEvolutionController = SunLightEffectsController.Instance.ActiveStarEvolutionController; + + if (sunController != null) { - w = __instance._sunController.HasSupernovaStarted() ? __instance._sunController.GetSupernovaRadius() : __instance._sunController.GetSurfaceRadius(); + w = sunController.HasSupernovaStarted() ? sunController.GetSupernovaRadius() : sunController.GetSurfaceRadius(); } + // This is an addition in this patch, to work with our stars + else if (starEvolutionController != null) + { + w = starEvolutionController.HasSupernovaStarted() ? starEvolutionController.GetSupernovaRadius() : starEvolutionController.GetSurfaceRadius(); + } + float range = __instance.sunLight.range; Color color = __instance._sunLightController != null ? __instance._sunLightController.sunColor : __instance.sunLight.color; float w2 = __instance._sunLightController != null ? __instance._sunLightController.sunIntensity : __instance.sunLight.intensity;