Skip to content

Commit

Permalink
1.14.7 (#707)
Browse files Browse the repository at this point in the history
## Minor features
- Can change the distance that orbit lines are shown at now using
`orbitLineFadeStartDistance` and `orbitLineFadeEndDistance`.

## Bug fixes
- Fixed spawning inside cloaks. Fixes #671 
- Fixed default system override logging errors on load
- Fixed star size in shader params
- Fixed water inside of cloaks. Was a bug affecting Tesseract's Secret,
although they have their own workaround so this won't change anything.
- Fixed missing null check in detail builder orb fix (solves an issue in
Intervention). Fixes #708
  • Loading branch information
xen-42 committed Aug 24, 2023
2 parents ee62400 + 3e23e43 commit 3ed6ba8
Show file tree
Hide file tree
Showing 18 changed files with 251 additions and 63 deletions.
12 changes: 11 additions & 1 deletion NewHorizons/Builder/Body/WaterBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
using Tessellation;
using NewHorizons.Utility.OWML;
using NewHorizons.Utility.OuterWilds;
using NewHorizons.External.Configs;
using NewHorizons.Components.Volumes;
using System.Linq;

namespace NewHorizons.Builder.Body
{
Expand Down Expand Up @@ -41,10 +44,12 @@ internal static void InitPrefabs()
if (_oceanAmbientLight == null) _oceanAmbientLight = SearchUtilities.Find("Ocean_GD").GetComponent<OceanLODController>()._ambientLight.gameObject.InstantiateInactive().Rename("OceanAmbientLight").DontDestroyOnLoad();
}

public static RadialFluidVolume Make(GameObject planetGO, Sector sector, OWRigidbody rb, WaterModule module)
public static RadialFluidVolume Make(GameObject planetGO, Sector sector, OWRigidbody rb, PlanetConfig config)
{
InitPrefabs();

var module = config.Water;

var waterSize = module.size;

GameObject waterGO = new GameObject("Water");
Expand Down Expand Up @@ -154,6 +159,11 @@ public static RadialFluidVolume Make(GameObject planetGO, Sector sector, OWRigid
fogGO.GetComponent<MeshRenderer>().material.SetFloat("_Radius2", 0);
}

if (config.Cloak != null)
{
fluidVolume.gameObject.AddComponent<WaterCloakFixerVolume>().material = TSR.sharedMaterials.First(x => x.name == "Ocean_GD_Surface_mat");
}

// TODO: fix ruleset making the sand bubble pop up

waterGO.transform.position = planetGO.transform.position;
Expand Down
14 changes: 8 additions & 6 deletions NewHorizons/Builder/Orbital/OrbitlineBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,17 @@ public static OrbitLine Make(GameObject planetGO, NHAstroObject astroObject, boo

var fade = isMoon;

/*
if (config.Base.IsSatellite)
if (config.Orbit.orbitLineFadeStartDistance >= 0)
{
if (config.Orbit.Tint != null) color = new Color(0.4082f, 0.516f, 0.4469f, 1f);
fade = true;
orbitLine._fadeEndDist = 5000;
orbitLine._fadeStartDist = 3000;
orbitLine._fadeStartDist = config.Orbit.orbitLineFadeStartDistance;
}

if (config.Orbit.orbitLineFadeEndDistance >= 0)
{
fade = true;
orbitLine._fadeEndDist = config.Orbit.orbitLineFadeEndDistance;
}
*/

orbitLine._color = color;
lineRenderer.endColor = new Color(color.r, color.g, color.b, 0f);
Expand Down
2 changes: 2 additions & 0 deletions NewHorizons/Builder/Props/BrambleNodeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,9 @@ public static GameObject Make(GameObject go, Sector sector, BrambleNodeInfo conf

// Seed fog works differently, so it doesn't need to be fixed
// (it's also located on a different child path, so the below FindChild calls wouldn't work)
// Default size is 70
var fog = brambleNode.FindChild("Effects/InnerWarpFogSphere");
fog.transform.localScale = Vector3.one * config.scale * 70f;
var fogMaterial = fog.GetComponent<MeshRenderer>().material;
fogMaterial.SetFloat("_Radius", fogMaterial.GetFloat("_Radius") * config.scale);
fogMaterial.SetFloat("_Density", fogMaterial.GetFloat("_Density") / config.scale);
Expand Down
42 changes: 25 additions & 17 deletions NewHorizons/Builder/Props/DetailBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,25 +116,33 @@ public static GameObject Make(GameObject go, Sector sector, GameObject prefab, D

foreach (var component in prop.GetComponentsInChildren<Component>(true))
{
// Components can come through as null here (yes, really),
// Usually if a script was added to a prefab in an asset bundle but isn't present in the loaded mod DLLs
if (component == null)
// Rather than having the entire prop not exist when a detail fails let's just try-catch and log an error
try
{
invalidComponentFound = true;
continue;
// Components can come through as null here (yes, really),
// Usually if a script was added to a prefab in an asset bundle but isn't present in the loaded mod DLLs
if (component == null)
{
invalidComponentFound = true;
continue;
}
if (component.gameObject == prop && component is OWItem) isItem = true;

if (sector == null)
{
if (FixUnsectoredComponent(component)) continue;
}
else
{
FixSectoredComponent(component, sector, existingSectors, detail.keepLoaded);
}

FixComponent(component, go, detail.ignoreSun);
}
if (component.gameObject == prop && component is OWItem) isItem = true;

if (sector == null)
{
if (FixUnsectoredComponent(component)) continue;
}
else
catch(Exception e)
{
FixSectoredComponent(component, sector, existingSectors, detail.keepLoaded);
NHLogger.LogError($"Failed to correct component {component?.GetType()?.Name} on {go?.name} - {e}");
}

FixComponent(component, go, detail.ignoreSun);
}

if (detail.path != null)
Expand All @@ -155,7 +163,7 @@ public static GameObject Make(GameObject go, Sector sector, GameObject prefab, D
}
}

// Items shouldn't use these else they get weird
// Items should always be kept loaded else they will vanish in your hand as you leave the sector
if (isItem) detail.keepLoaded = true;

prop.transform.localScale = detail.stretch ?? (detail.scale != 0 ? Vector3.one * detail.scale : prefab.transform.localScale);
Expand Down Expand Up @@ -374,7 +382,7 @@ private static void FixComponent(Component component, GameObject planetGO, bool
else if (component is NomaiInterfaceOrb orb)
{
// detect planet gravity
var gravityVolume = planetGO.GetAttachedOWRigidbody().GetAttachedGravityVolume();
var gravityVolume = planetGO.GetAttachedOWRigidbody()?.GetAttachedGravityVolume();
orb.GetComponent<ConstantForceDetector>()._detectableFields = gravityVolume ? new ForceVolume[] { gravityVolume } : new ForceVolume[] { };
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,8 @@ public void StopSupernova()

public float GetSupernovaRadius() => supernova.GetSupernovaRadius();

public float GetSurfaceRadius() => transform.localScale.x;

public float GetMaxSupernovaRadius() => supernovaSize;

protected new void FixedUpdate()
Expand Down
30 changes: 19 additions & 11 deletions NewHorizons/Components/Stars/SunLightEffectsController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NewHorizons.Builder.Atmosphere;
using NewHorizons.Components.SizeControllers;
using NewHorizons.Utility.OWML;
using System.Collections.Generic;
using UnityEngine;
Expand All @@ -17,7 +18,11 @@ public class SunLightEffectsController : MonoBehaviour
private readonly List<StarController> _stars = new();
private readonly List<Light> _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;

Expand Down Expand Up @@ -54,7 +59,7 @@ public static void RemoveStar(StarController star)
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]);
Expand Down Expand Up @@ -121,11 +126,11 @@ public void Update()

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)
Expand All @@ -145,8 +150,8 @@ public void Update()
// 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);
}
Expand All @@ -156,7 +161,7 @@ public void Update()
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;
Expand All @@ -170,11 +175,13 @@ private void ChangeActiveStar(StarController star)
{
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<StarEvolutionController>();
ActiveSunController = star.GetComponent<SunController>();

star.Enable();

Expand All @@ -194,7 +201,8 @@ private void ChangeActiveStar(StarController star)
transform.localPosition = Vector3.zero;

// Some effects use Locator.GetSunTransform so hopefully its fine to change it
Locator._sunTransform = transform;
// Use the root transform of the star because that's the default behaviour, breaks SunProxy if not (potentially others)
Locator._sunTransform = star.transform;

// TODO?: maybe also turn off star controller stuff (mainly proxy light) since idk if that can handle more than 1 being on
}
Expand Down
54 changes: 54 additions & 0 deletions NewHorizons/Components/Volumes/WaterCloakFixerVolume.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using UnityEngine;

namespace NewHorizons.Components.Volumes
{
/// <summary>
/// A cloak can interfere with the rendering of water
/// Water has a lower render queue and is transparent, so you can see the background black cloak over top of the water
/// We fix this by setting the water's render queue to that of the cloak
/// However, this means that when you are inside the water you will see through the cloak since it's not rendered on top
/// To fix that, we set the render queue back to normal when the player enters the water
/// Currently this doesnt nothing to fix probe camera pictures. If you are outside of the water, the probe will see the stars and through the cloak
/// Oh well
/// </summary>
internal class WaterCloakFixerVolume : MonoBehaviour
{
public Material material;
private OWTriggerVolume _volume;

public const int WATER_RENDER_QUEUE = 2990;
public const int CLOAK_RENDER_QUEUE = 3000;

public void Start()
{
_volume = GetComponent<RadialFluidVolume>().GetOWTriggerVolume();

_volume.OnEntry += WaterCloakFixerVolume_OnEntry;
_volume.OnExit += WaterCloakFixerVolume_OnExit;

material.renderQueue = CLOAK_RENDER_QUEUE;
}

public void OnDestroy()
{
_volume.OnEntry -= WaterCloakFixerVolume_OnEntry;
_volume.OnExit -= WaterCloakFixerVolume_OnExit;
}

private void WaterCloakFixerVolume_OnEntry(GameObject hitObj)
{
if (hitObj.CompareTag("PlayerDetector"))
{
material.renderQueue = WATER_RENDER_QUEUE;
}
}

private void WaterCloakFixerVolume_OnExit(GameObject hitObj)
{
if (hitObj.CompareTag("PlayerDetector"))
{
material.renderQueue = CLOAK_RENDER_QUEUE;
}
}
}
}
22 changes: 16 additions & 6 deletions NewHorizons/External/Modules/OrbitModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public class OrbitModule : IOrbitalParameters
/// </summary>
public bool isTidallyLocked;

/// <summary>
/// Is the body meant to stay in one place without moving? If staticPosition is not set, the initial position
/// will be determined using its orbital parameters.
/// </summary>
public bool isStatic;

/// <summary>
/// If it is tidally locked, this direction will face towards the primary. Ex: Interloper uses `0, -1, 0`. Most planets
/// will want something like `-1, 0, 0`.
Expand All @@ -62,12 +68,6 @@ public class OrbitModule : IOrbitalParameters
/// </summary>
public bool dottedOrbitLine;

/// <summary>
/// Is the body meant to stay in one place without moving? If staticPosition is not set, the initial position
/// will be determined using its orbital parameters.
/// </summary>
public bool isStatic;

/// <summary>
/// Colour of the orbit-line in the map view.
/// </summary>
Expand All @@ -78,6 +78,16 @@ public class OrbitModule : IOrbitalParameters
/// </summary>
public bool trackingOrbitLine;

/// <summary>
/// If the camera is farther than this distance the orbit line will fade out. Leave empty to not have it fade out.
/// </summary>
public float orbitLineFadeEndDistance = -1f;

/// <summary>
/// If the camera is closer than this distance the orbit line will fade out. Leave empty to not have it fade out.
/// </summary>
public float orbitLineFadeStartDistance = -1f;

/// <summary>
/// The semi-major axis of the ellipse that is the body's orbit. For a circular orbit this is the radius.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion NewHorizons/Handlers/PlanetCreationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ private static GameObject SharedGenerateBody(NewHorizonsBody body, GameObject go

if (body.Config.Water != null)
{
WaterBuilder.Make(go, sector, rb, body.Config.Water);
WaterBuilder.Make(go, sector, rb, body.Config);
}

if (body.Config.Sand != null)
Expand Down
14 changes: 9 additions & 5 deletions NewHorizons/Handlers/PlanetDestructionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using NewHorizons.Components;

namespace NewHorizons.Handlers
{
Expand Down Expand Up @@ -66,17 +67,20 @@ public static void RemoveSolarSystem()
}
}

foreach (var proxyBody in GameObject.FindObjectsOfType<ProxyBody>())
{
toDisable.Add(proxyBody.gameObject);
}

Delay.FireInNUpdates(() =>
{
foreach (var gameObject in toDisable)
{
gameObject.SetActive(false);
}
// Kill all non nh proxies
foreach (var proxy in GameObject.FindObjectsOfType<ProxyBody>())
{
if (proxy is not NHProxy)
{
proxy.gameObject.SetActive(false);
}
}
GameObject.FindObjectOfType<SunProxy>().gameObject.SetActive(false);
// force call update here to make it switch to an active star. idk why we didnt have to do this before
Expand Down
Loading

0 comments on commit 3ed6ba8

Please sign in to comment.