Merge branch 'dev' into what-if-more-frames

This commit is contained in:
Nick 2023-07-18 10:21:50 -04:00 committed by GitHub
commit 71ae25ae2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 192 additions and 34 deletions

View File

@ -7,6 +7,7 @@ using System.Linq;
using NewHorizons.Components.Stars; using NewHorizons.Components.Stars;
using NewHorizons.Utility.OuterWilds; using NewHorizons.Utility.OuterWilds;
using NewHorizons.Utility.Files; using NewHorizons.Utility.Files;
using NewHorizons.Utility.OWML;
namespace NewHorizons.Builder.Body namespace NewHorizons.Builder.Body
{ {
@ -348,28 +349,42 @@ namespace NewHorizons.Builder.Body
solarFlareEmitter.name = "SolarFlareEmitter"; solarFlareEmitter.name = "SolarFlareEmitter";
solarFlareEmitter.SetActive(true); solarFlareEmitter.SetActive(true);
var emitter = solarFlareEmitter.GetComponent<SolarFlareEmitter>();
if (starModule.solarFlareSettings != null)
{
emitter._minTimeBetweenFlares = starModule.solarFlareSettings.minTimeBetweenFlares;
emitter._maxTimeBetweenFlares = starModule.solarFlareSettings.maxTimeBetweenFlares;
emitter._lifeLength = starModule.solarFlareSettings.lifeLength;
}
if (starModule.tint != null) if (starModule.tint != null)
{ {
var flareTint = starModule.tint.ToColor(); emitter.tint = starModule.tint.ToColor();
var emitter = solarFlareEmitter.GetComponent<SolarFlareEmitter>(); }
emitter.tint = flareTint;
var material = new Material(_flareMaterial); var material = new Material(_flareMaterial);
// Since the star isn't awake yet the controllers haven't been made // Since the star isn't awake yet the controllers haven't been made
foreach (var prefab in new GameObject[] { emitter.domePrefab, emitter.loopPrefab, emitter.streamerPrefab }) foreach (var prefab in new GameObject[] { emitter.domePrefab, emitter.loopPrefab, emitter.streamerPrefab })
{
var controller = prefab.GetComponent<SolarFlareController>();
// controller._meshRenderer doesn't exist yet since Awake hasn't been called
if (starModule.tint != null)
{ {
var controller = prefab.GetComponent<SolarFlareController>();
// controller._meshRenderer doesn't exist yet since Awake hasn't been called
controller.GetComponent<MeshRenderer>().sharedMaterial = material; controller.GetComponent<MeshRenderer>().sharedMaterial = material;
controller._color = Color.white; controller._color = Color.white;
controller._tint = flareTint; controller._tint = starModule.tint.ToColor();
}
if (starModule.solarFlareSettings != null)
{
controller._scaleFactor = Vector3.one * starModule.solarFlareSettings.scaleFactor;
} }
} }
starGO.transform.position = rootObject.transform.position; starGO.transform.position = rootObject.transform.position;
starGO.transform.localScale = starModule.size * Vector3.one; starGO.transform.localScale = starModule.size * Vector3.one;
TessellatedSphereRenderer surface = sunSurface.GetComponent<TessellatedSphereRenderer>(); var surface = sunSurface.GetComponent<TessellatedSphereRenderer>();
if (starModule.tint != null) if (starModule.tint != null)
{ {

View File

@ -24,10 +24,12 @@ namespace NewHorizons.Builder.Orbital
initialMotion._initAngularSpeed = orbit.siderealPeriod == 0 ? 0f : 2f * Mathf.PI / (orbit.siderealPeriod * 60f); initialMotion._initAngularSpeed = orbit.siderealPeriod == 0 ? 0f : 2f * Mathf.PI / (orbit.siderealPeriod * 60f);
var rotationAxis = Quaternion.AngleAxis(orbit.axialTilt, Vector3.right) * Vector3.up; var rotationAxis = Quaternion.AngleAxis(orbit.axialTilt, Vector3.right) * Vector3.up;
// For things with children this is broken // For stock planets with unsuspended rigidbody children this is broken
// For planets with rafts this is broken
if (AstroObjectLocator.GetChildren(secondaryBody).Length == 0) if (AstroObjectLocator.GetChildren(secondaryBody).Length == 0)
{ {
secondaryBody.transform.rotation = Quaternion.FromToRotation(Vector3.up, rotationAxis); secondaryBody.transform.rotation = Quaternion.FromToRotation(Vector3.up, rotationAxis);
secondaryBody.transform.Rotate(rotationAxis, orbit.initialRotation);
} }
if (!orbit.isStatic && primaryBody != null) if (!orbit.isStatic && primaryBody != null)

View File

@ -134,9 +134,18 @@ namespace NewHorizons.Components.ShipLog
} }
else else
{ {
var path = Path.Combine("planets", uniqueID + ".png"); var mod = Main.SystemDict[uniqueID].Mod;
var path = Path.Combine("systems", uniqueID + ".png");
// Else check the old location
if (!File.Exists(Path.Combine(mod.ModHelper.Manifest.ModFolderPath, path)))
{
path = Path.Combine("planets", uniqueID + ".png");
}
NHLogger.LogVerbose($"ShipLogStarChartManager - Trying to load {path}"); NHLogger.LogVerbose($"ShipLogStarChartManager - Trying to load {path}");
texture = ImageUtilities.GetTexture(Main.SystemDict[uniqueID].Mod, path); texture = ImageUtilities.GetTexture(mod, path);
} }
} }
catch (Exception) { } catch (Exception) { }

View File

@ -1,5 +1,6 @@
using NewHorizons.External.SerializableEnums; using NewHorizons.External.SerializableEnums;
using NewHorizons.Handlers; using NewHorizons.Handlers;
using NewHorizons.Utility;
using NewHorizons.Utility.OWML; using NewHorizons.Utility.OWML;
using System.Collections; using System.Collections;
using UnityEngine; using UnityEngine;
@ -28,7 +29,7 @@ namespace NewHorizons.Components.Volumes
if (hitObj.CompareTag("PlayerDetector") && enabled) if (hitObj.CompareTag("PlayerDetector") && enabled)
{ {
// Have to run it off the mod behaviour since the game over controller disables everything // Have to run it off the mod behaviour since the game over controller disables everything
Main.Instance.StartCoroutine(GameOver()); Delay.StartCoroutine(GameOver());
} }
} }

View File

@ -34,6 +34,12 @@ namespace NewHorizons.External.Modules
/// </summary> /// </summary>
public float siderealPeriod; public float siderealPeriod;
/// <summary>
/// Offsets the planet's starting sidereal rotation. In degrees.
/// </summary>
[Range(0f, 360f)]
public float initialRotation;
/// <summary> /// <summary>
/// Should the body always have one side facing its primary? /// Should the body always have one side facing its primary?
/// </summary> /// </summary>

View File

@ -104,6 +104,39 @@ namespace NewHorizons.External.Modules.VariableSize
/// The type of stellar remnant your star will leave behind. /// The type of stellar remnant your star will leave behind.
/// </summary> /// </summary>
[DefaultValue("default")] public StellarRemnantType stellarRemnantType = StellarRemnantType.Default; [DefaultValue("default")] public StellarRemnantType stellarRemnantType = StellarRemnantType.Default;
/// <summary>
/// Allows overriding solar flare graphical settings.
/// </summary>
public SolarFlareModule solarFlareSettings;
[JsonObject]
public class SolarFlareModule
{
/// <summary>
/// Size multiuplier for solar flares. Defaults to 1.
/// </summary>
[DefaultValue(1)]
public float scaleFactor = 1f;
/// <summary>
/// How long a solar flare is visible for. Defaults to 15.
/// </summary>
[DefaultValue(15f)]
public float lifeLength = 15f;
/// <summary>
/// Solar flares are emitted randomly. This is the minimum ammount of time between solar flares.
/// </summary>
[DefaultValue(5f)]
public float minTimeBetweenFlares = 5f;
/// <summary>
/// Solar flares are emitted randomly. This is the maximum ammount of time between solar flares.
/// </summary>
[DefaultValue(30f)]
public float maxTimeBetweenFlares = 30f;
}
} }
[JsonConverter(typeof(StringEnumConverter))] [JsonConverter(typeof(StringEnumConverter))]

View File

@ -1,3 +1,4 @@
using NewHorizons.Utility.OWML;
using System; using System;
using System.Collections; using System.Collections;
using UnityEngine; using UnityEngine;
@ -6,7 +7,7 @@ namespace NewHorizons.Handlers
{ {
public static class FadeHandler public static class FadeHandler
{ {
public static void FadeOut(float length) => Main.Instance.StartCoroutine(FadeOutCoroutine(length)); public static void FadeOut(float length) => Delay.StartCoroutine(FadeOutCoroutine(length));
private static IEnumerator FadeOutCoroutine(float length) private static IEnumerator FadeOutCoroutine(float length)
{ {
@ -24,7 +25,7 @@ namespace NewHorizons.Handlers
yield return new WaitForEndOfFrame(); yield return new WaitForEndOfFrame();
} }
public static void FadeThen(float length, Action action) => Main.Instance.StartCoroutine(FadeThenCoroutine(length, action)); public static void FadeThen(float length, Action action) => Delay.StartCoroutine(FadeThenCoroutine(length, action));
private static IEnumerator FadeThenCoroutine(float length, Action action) private static IEnumerator FadeThenCoroutine(float length, Action action)
{ {

View File

@ -349,6 +349,13 @@ namespace NewHorizons.Handlers
BrambleDimensionBuilder.Make(body, go, ao, sector, owRigidBody); BrambleDimensionBuilder.Make(body, go, ao, sector, owRigidBody);
go = SharedGenerateBody(body, go, sector, owRigidBody); go = SharedGenerateBody(body, go, sector, owRigidBody);
// Not included in SharedGenerate to not mess up gravity on base game planets
if (body.Config.Base.surfaceGravity != 0)
{
GravityBuilder.Make(go, ao, owRigidBody, body.Config);
}
body.Object = go; body.Object = go;
AstroObjectLocator.RegisterCustomAstroObject(ao); AstroObjectLocator.RegisterCustomAstroObject(ao);

View File

@ -41,7 +41,7 @@ namespace NewHorizons.Handlers
if (matchInitialMotion != null) UnityEngine.Object.Destroy(matchInitialMotion); if (matchInitialMotion != null) UnityEngine.Object.Destroy(matchInitialMotion);
// Arbitrary number, depending on the machine some people die, some people fall through the floor, its very inconsistent // Arbitrary number, depending on the machine some people die, some people fall through the floor, its very inconsistent
Main.Instance.StartCoroutine(SpawnCoroutine(10)); Delay.StartCoroutine(SpawnCoroutine(10));
} }
} }

View File

@ -230,6 +230,7 @@ namespace NewHorizons
NHLogger.LogWarning("Couldn't find planets folder"); NHLogger.LogWarning("Couldn't find planets folder");
} }
// Call this from the menu since we hadn't hooked onto the event yet
Delay.FireOnNextUpdate(() => OnSceneLoaded(SceneManager.GetActiveScene(), LoadSceneMode.Single)); Delay.FireOnNextUpdate(() => OnSceneLoaded(SceneManager.GetActiveScene(), LoadSceneMode.Single));
Delay.FireOnNextUpdate(() => _firstLoad = false); Delay.FireOnNextUpdate(() => _firstLoad = false);
Instance.ModHelper.Menus.PauseMenu.OnInit += DebugReload.InitializePauseMenu; Instance.ModHelper.Menus.PauseMenu.OnInit += DebugReload.InitializePauseMenu;
@ -545,6 +546,9 @@ namespace NewHorizons
{ {
NHLogger.LogError($"Exception thrown when invoking star system loaded event with parameter [{Instance.CurrentStarSystem}]:\n{e}"); NHLogger.LogError($"Exception thrown when invoking star system loaded event with parameter [{Instance.CurrentStarSystem}]:\n{e}");
} }
// Wait for player to be awake and also for frames to pass
Delay.RunWhenAndInNUpdates(() => OnSystemReady(DidWarpFromShip, DidWarpFromVessel), () => _playerAwake && PlayerSpawned, 30);
} }
else else
{ {
@ -560,29 +564,33 @@ namespace NewHorizons
_currentStarSystem = _defaultStarSystem; _currentStarSystem = _defaultStarSystem;
} }
} }
// Wait for player to be awake and also for frames to pass
Delay.RunWhenAndInNUpdates(() => OnSystemReady(DidWarpFromShip, DidWarpFromVessel), () => _playerAwake && PlayerSpawned, 30);
} }
// Had a bunch of separate unity things firing stuff when the system is ready so I moved it all to here // Had a bunch of separate unity things firing stuff when the system is ready so I moved it all to here
private void OnSystemReady(bool shouldWarpInFromShip, bool shouldWarpInFromVessel) private void OnSystemReady(bool shouldWarpInFromShip, bool shouldWarpInFromVessel)
{ {
IsSystemReady = true; if (IsSystemReady)
{
NHLogger.LogWarning("OnSystemReady was called twice.");
}
else
{
IsSystemReady = true;
// ShipWarpController will handle the invulnerability otherwise // ShipWarpController will handle the invulnerability otherwise
if (!shouldWarpInFromShip) if (!shouldWarpInFromShip)
Delay.FireOnNextUpdate(() => InvulnerabilityHandler.MakeInvulnerable(false)); Delay.FireOnNextUpdate(() => InvulnerabilityHandler.MakeInvulnerable(false));
Locator.GetPlayerBody().gameObject.AddComponent<DebugRaycaster>(); Locator.GetPlayerBody().gameObject.AddComponent<DebugRaycaster>();
Locator.GetPlayerBody().gameObject.AddComponent<DebugPropPlacer>(); Locator.GetPlayerBody().gameObject.AddComponent<DebugPropPlacer>();
Locator.GetPlayerBody().gameObject.AddComponent<DebugMenu>(); Locator.GetPlayerBody().gameObject.AddComponent<DebugMenu>();
PlayerSpawnHandler.OnSystemReady(shouldWarpInFromShip, shouldWarpInFromVessel); PlayerSpawnHandler.OnSystemReady(shouldWarpInFromShip, shouldWarpInFromVessel);
VesselCoordinatePromptHandler.RegisterPrompts(SystemDict.Where(system => system.Value.Config.Vessel?.coords != null).Select(x => x.Value).ToList()); VesselCoordinatePromptHandler.RegisterPrompts(SystemDict.Where(system => system.Value.Config.Vessel?.coords != null).Select(x => x.Value).ToList());
CloakHandler.OnSystemReady(); CloakHandler.OnSystemReady();
}
} }
public void EnableWarpDrive() public void EnableWarpDrive()

View File

@ -1034,6 +1034,13 @@
"description": "Rotation period in minutes.", "description": "Rotation period in minutes.",
"format": "float" "format": "float"
}, },
"initialRotation": {
"type": "number",
"description": "Offsets the planet's starting sidereal rotation. In degrees.",
"format": "float",
"maximum": 360.0,
"minimum": 0.0
},
"isTidallyLocked": { "isTidallyLocked": {
"type": "boolean", "type": "boolean",
"description": "Should the body always have one side facing its primary?" "description": "Should the body always have one side facing its primary?"
@ -3228,6 +3235,10 @@
"description": "The type of stellar remnant your star will leave behind.", "description": "The type of stellar remnant your star will leave behind.",
"default": "default", "default": "default",
"$ref": "#/definitions/StellarRemnantType" "$ref": "#/definitions/StellarRemnantType"
},
"solarFlareSettings": {
"description": "Allows overriding solar flare graphical settings.",
"$ref": "#/definitions/SolarFlareModule"
} }
} }
}, },
@ -3267,6 +3278,36 @@
"custom" "custom"
] ]
}, },
"SolarFlareModule": {
"type": "object",
"additionalProperties": false,
"properties": {
"scaleFactor": {
"type": "number",
"description": "Size multiuplier for solar flares. Defaults to 1.",
"format": "float",
"default": 1
},
"lifeLength": {
"type": "number",
"description": "How long a solar flare is visible for. Defaults to 15.",
"format": "float",
"default": 15.0
},
"minTimeBetweenFlares": {
"type": "number",
"description": "Solar flares are emitted randomly. This is the minimum ammount of time between solar flares.",
"format": "float",
"default": 5.0
},
"maxTimeBetweenFlares": {
"type": "number",
"description": "Solar flares are emitted randomly. This is the maximum ammount of time between solar flares.",
"format": "float",
"default": 30.0
}
}
},
"WaterModule": { "WaterModule": {
"type": "object", "type": "object",
"additionalProperties": false, "additionalProperties": false,

View File

@ -1,15 +1,49 @@
using System; using System;
using System.Collections; using System.Collections;
using UnityEngine; using UnityEngine;
using UnityEngine.SceneManagement;
namespace NewHorizons.Utility.OWML namespace NewHorizons.Utility.OWML
{ {
public static class Delay public static class Delay
{ {
public static void RunWhen(Func<bool> predicate, Action action) => Main.Instance.ModHelper.Events.Unity.RunWhen(predicate, action); #region OnSceneUnloaded
public static void FireInNUpdates(Action action, int n) => Main.Instance.ModHelper.Events.Unity.FireInNUpdates(action, n); static Delay() => SceneManager.sceneUnloaded += OnSceneUnloaded;
public static void FireOnNextUpdate(Action action) => Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(action);
public static void RunWhenAndInNUpdates(Action action, Func<bool> predicate, int n) => Main.Instance.StartCoroutine(RunWhenOrInNUpdatesCoroutine(action, predicate, n)); private static void OnSceneUnloaded(Scene _) => Main.Instance.StopAllCoroutines();
#endregion
#region public methods
public static void StartCoroutine(IEnumerator coroutine) => Main.Instance.StartCoroutine(coroutine);
public static void RunWhen(Func<bool> predicate, Action action) => StartCoroutine(RunWhenCoroutine(action, predicate));
public static void FireInNUpdates(Action action, int n) => StartCoroutine(FireInNUpdatesCoroutine(action, n));
public static void FireOnNextUpdate(Action action) => FireInNUpdates(action, 1);
public static void RunWhenAndInNUpdates(Action action, Func<bool> predicate, int n) => Delay.StartCoroutine(RunWhenOrInNUpdatesCoroutine(action, predicate, n));
#endregion
#region Coroutines
private static IEnumerator RunWhenCoroutine(Action action, Func<bool> predicate)
{
while (!predicate.Invoke())
{
yield return new WaitForEndOfFrame();
}
action.Invoke();
}
private static IEnumerator FireInNUpdatesCoroutine(Action action, int n)
{
for (int i = 0; i < n; i++)
{
yield return new WaitForEndOfFrame();
}
action?.Invoke();
}
private static IEnumerator RunWhenOrInNUpdatesCoroutine(Action action, Func<bool> predicate, int n) private static IEnumerator RunWhenOrInNUpdatesCoroutine(Action action, Func<bool> predicate, int n)
{ {
@ -24,5 +58,6 @@ namespace NewHorizons.Utility.OWML
action.Invoke(); action.Invoke();
} }
#endregion
} }
} }