Skip to content

Commit

Permalink
Implement StopTime, SlowTime mod compat (#760)
Browse files Browse the repository at this point in the history
## Improvements

- StopTime and SlowTime mods will now effect the time loop in new
systems
  • Loading branch information
MegaPiggy authored Jan 2, 2024
2 parents 1f53e46 + cb2d83e commit 02b4c2b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
5 changes: 4 additions & 1 deletion NewHorizons/Handlers/SystemCreationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using NewHorizons.Utility.OuterWilds;
using UnityEngine;
using Object = UnityEngine.Object;
using NewHorizons.OtherMods;

namespace NewHorizons.Handlers
{
public static class SystemCreationHandler
Expand All @@ -31,7 +33,8 @@ public static void LoadSystem(NewHorizonsSystem system)
// 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<TimeLoopController>();
Expand Down
6 changes: 6 additions & 0 deletions NewHorizons/OtherMods/OtherModUtil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace NewHorizons.OtherMods;

public static class OtherModUtil
{
public static bool IsEnabled(string modName) => Main.Instance.ModHelper.Interaction.ModExists(modName);
}
13 changes: 12 additions & 1 deletion NewHorizons/Utility/OuterWilds/TimeLoopUtilities.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
using NewHorizons.OtherMods;
using UnityEngine;

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;
Expand Down

0 comments on commit 02b4c2b

Please sign in to comment.