From cb2d83e026f5fee967f1883d389692d11c4f1429 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 23 Dec 2023 13:37:02 -0500 Subject: [PATCH] Implement StopTime, SlowTime mod compat --- NewHorizons/Handlers/SystemCreationHandler.cs | 5 ++++- NewHorizons/OtherMods/OtherModUtil.cs | 6 ++++++ NewHorizons/Utility/OuterWilds/TimeLoopUtilities.cs | 13 ++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 NewHorizons/OtherMods/OtherModUtil.cs diff --git a/NewHorizons/Handlers/SystemCreationHandler.cs b/NewHorizons/Handlers/SystemCreationHandler.cs index d0c576f9..debd14e7 100644 --- a/NewHorizons/Handlers/SystemCreationHandler.cs +++ b/NewHorizons/Handlers/SystemCreationHandler.cs @@ -7,6 +7,8 @@ using NewHorizons.Utility.OWML; using NewHorizons.Utility.OuterWilds; using UnityEngine; using Object = UnityEngine.Object; +using NewHorizons.OtherMods; + namespace NewHorizons.Handlers { public static class SystemCreationHandler @@ -31,7 +33,8 @@ namespace NewHorizons.Handlers // No time loop or travel audio at the eye if (Main.Instance.CurrentStarSystem == "EyeOfTheUniverse") return; - if (system.Config.enableTimeLoop) + // Small mod compat change for StopTime - do nothing if it's enabled + if (system.Config.enableTimeLoop && !OtherModUtil.IsEnabled("_nebula.StopTime")) { var timeLoopController = new GameObject("TimeLoopController"); timeLoopController.AddComponent(); diff --git a/NewHorizons/OtherMods/OtherModUtil.cs b/NewHorizons/OtherMods/OtherModUtil.cs new file mode 100644 index 00000000..6843158d --- /dev/null +++ b/NewHorizons/OtherMods/OtherModUtil.cs @@ -0,0 +1,6 @@ +namespace NewHorizons.OtherMods; + +public static class OtherModUtil +{ + public static bool IsEnabled(string modName) => Main.Instance.ModHelper.Interaction.ModExists(modName); +} diff --git a/NewHorizons/Utility/OuterWilds/TimeLoopUtilities.cs b/NewHorizons/Utility/OuterWilds/TimeLoopUtilities.cs index 4566487c..f9c40831 100644 --- a/NewHorizons/Utility/OuterWilds/TimeLoopUtilities.cs +++ b/NewHorizons/Utility/OuterWilds/TimeLoopUtilities.cs @@ -1,3 +1,4 @@ +using NewHorizons.OtherMods; using UnityEngine; namespace NewHorizons.Utility.OuterWilds @@ -5,7 +6,17 @@ namespace NewHorizons.Utility.OuterWilds public static class TimeLoopUtilities { public const float LOOP_DURATION_IN_SECONDS = TimeLoop.LOOP_DURATION_IN_MINUTES * 60; - public static void SetLoopDuration(float minutes) => TimeLoop._loopDuration = minutes * 60f; + public static void SetLoopDuration(float minutes) + { + TimeLoop._loopDuration = minutes * 60f; + + // If slow time mod is on give them at least an hour + // This won't slow down time based events like sand sizes but oh well + if (OtherModUtil.IsEnabled("dnlwtsn.SlowTime")) + { + TimeLoop._loopDuration = Mathf.Max(TimeLoop._loopDuration, 60f * 60f); + } + } public static void SetSecondsElapsed(float secondsElapsed) => TimeLoop._timeOffset = secondsElapsed - Time.timeSinceLevelLoad; public static void SetMinutesRemaining(float minutes) => TimeLoop.SetSecondsRemaining(minutes * 60); public static float GetMinutesRemaining() => TimeLoop.GetSecondsRemaining() / 60f;