Skip to content

Commit

Permalink
Fix Custom Speed Hotkey
Browse files Browse the repository at this point in the history
  • Loading branch information
doombubbles committed Oct 14, 2024
1 parent 6292398 commit adf8970
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 35 deletions.
57 changes: 24 additions & 33 deletions FasterForwardMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
using Il2CppAssets.Scripts.Unity.UI_New.InGame;
using Il2CppAssets.Scripts.Unity.UI_New.Popups;
using MelonLoader;
using Il2CppAssets.Scripts.Utils;
using BTD_Mod_Helper;
using BTD_Mod_Helper.Api.Helpers;
using BTD_Mod_Helper.Api.ModOptions;
using BTD_Mod_Helper.Extensions;
using FasterForward;
using Il2CppAssets.Scripts;
using UnityEngine;
using UnityEngine.PlayerLoop;
using UnityEngine.InputSystem.Utilities;

[assembly: MelonInfo(typeof(FasterForwardMod), ModHelperData.Name, ModHelperData.Version, ModHelperData.RepoOwner)]
[assembly: MelonGame("Ninja Kiwi", "BloonsTD6")]
Expand All @@ -19,8 +19,6 @@ namespace FasterForward;

public class FasterForwardMod : BloonsTD6Mod
{
private static int speed = 3;

private static readonly ModSettingHotkey Speed3 = new(KeyCode.F1)
{
displayName = "3x Speed (default) Hotkey"
Expand Down Expand Up @@ -48,59 +46,52 @@ public class FasterForwardMod : BloonsTD6Mod

public override void OnUpdate()
{
var lastSpeed = speed;

if (Speed3.JustPressed())
{
speed = 3;
SetSpeed(3);
}

if (Speed5.JustPressed())
{
speed = 5;
SetSpeed(5);
}

if (Speed10.JustPressed())
{
speed = 10;
SetSpeed(10);
}

if (Speed25.JustPressed())
{
speed = 25;
SetSpeed(25);
}

if (SpeedCustom.JustPressed() && InGame.instance != null)
{
PopupScreen.instance.ShowSetValuePopup("Custom Fast Forward Speed",
"Sets the Fast Forward speed to the specified value",
new Action<int>(i =>
{
if (i < 1)
{
i = 1;
}

if (i > 100)
{
i = 100;
}

speed = i;
Game.instance.ShowMessage(
"Fast Forward Speed is now " + speed + "x" + (speed == 3 ? " (Default)" : ""), 1f);
}), speed);
new Action<int>(s => SetSpeed(Mathf.Clamp(s, 1, 100))), (int) TimeHelper.OverrideFastForwardTimeScale);
}
}

if (InGame.instance == null || InGame.Bridge == null) return;
private static void SetSpeed(double speed)
{
if (NumberHelpers.Approximately(TimeHelper.OverrideFastForwardTimeScale, speed)) return;

if (speed != lastSpeed)
{
Game.instance.ShowMessage("Fast Forward Speed is now " + speed + "x" + (speed == 3 ? " (Default)" : ""),
1f);
TimeHelper.OverrideFastForwardTimeScale = speed;
TimeHelper.OverrideMaxSimulationStepsPerUpdate = speed;

TimeHelper.OverrideFastForwardTimeScale = speed;
TimeHelper.OverrideMaxSimulationStepsPerUpdate = speed;
var isDefault = NumberHelpers.Approximately(speed, Constants.fastForwardTimeScaleMultiplier);

var message = $"Fast Forward Speed is now {speed}x{(isDefault ? " (Default)" : "")}";

if (InGame.instance == null || InGame.Bridge == null)
{
ModHelper.Msg<FasterForwardMod>(message);
}
else
{
Game.instance.ShowMessage(message, 1f);
}
}
}
2 changes: 1 addition & 1 deletion LATEST.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- Fixed for BTD6 v35.0
- Fixed Custom Speed Hotkey
2 changes: 1 addition & 1 deletion ModHelperData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public static class ModHelperData
{
public const string WorksOnVersion = "45.0";
public const string Version = "1.1.3";
public const string Version = "1.1.4";
public const string RepoOwner = "doombubbles";
public const string RepoName = "faster-forward";
public const string Name = "Faster Forward";
Expand Down

0 comments on commit adf8970

Please sign in to comment.