Skip to content

Commit

Permalink
Add a slowdown option
Browse files Browse the repository at this point in the history
  • Loading branch information
psyGamer committed Aug 3, 2024
1 parent 827779f commit 96c4980
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Source/Data/Save.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public void ResetSpeedrunPracticeTime()

// If the Speedrun Timer should be paused when practice mode is enabled and the player is within range of a checkpoint
public bool SpeedrunPracticeTimerPauseNearCheckpoint { get; set; } = false;

public float SpeedrunSlowdownFactor { get; set; } = 0.5f;

/// <summary>
/// 0-10 Music volume level
Expand Down Expand Up @@ -194,6 +196,11 @@ public void ToggleSpeedrunPracticeTimerPauseNearCheckpoint()
{
SpeedrunPracticeTimerPauseNearCheckpoint = !SpeedrunPracticeTimerPauseNearCheckpoint;
}

public void SetSpeedrunSlowdownFactor(int value)
{
SpeedrunSlowdownFactor = value / 10.0f;
}

public TimeSpan GetCurrentDisplayTime()
{
Expand Down
9 changes: 8 additions & 1 deletion Source/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,18 @@ public void Goto(Transition next)
if (transition.StopMusic)
Music.Stop();
}


private float ellapsedTime = 0.0f;

public override void Update()
{
SpeedrunUtilsMod.Update();

ellapsedTime += SpeedrunUtilsMod.GameSpeed;
if (ellapsedTime < Time.Delta)
return;
ellapsedTime -= Time.Delta;

// update top scene
if (scenes.TryPeek(out var scene))
{
Expand Down
1 change: 1 addition & 0 deletions Source/Scenes/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public World(EntryInfo entry)
speedrunMenu.Add(new Menu.Toggle(Loc.Str("SpeedrunUtils_PracticeTimer"), Save.Instance.ToggleSpeedrunPracticeTime, () => Save.Instance.SpeedrunPracticeTimer));
speedrunMenu.Add(new Menu.Toggle(Loc.Str("SpeedrunUtils_PracticeTimer_PauseInMenu"), Save.Instance.ToggleSpeedrunPracticeTimerPauseInMenu, () => Save.Instance.SpeedrunPracticeTimerPauseInMenu));
speedrunMenu.Add(new Menu.Toggle(Loc.Str("SpeedrunUtils_PracticeTimer_PauseNearCheckpoint"), Save.Instance.ToggleSpeedrunPracticeTimerPauseNearCheckpoint, () => Save.Instance.SpeedrunPracticeTimerPauseNearCheckpoint));
speedrunMenu.Add(new Menu.Slider(Loc.Str("SpeedrunUtils_SlowdownFactor"), 1, 10, () => (int)(Save.Instance.SpeedrunSlowdownFactor * 10.0f), Save.Instance.SetSpeedrunSlowdownFactor));

pauseMenu.Title = Loc.Str("PauseTitle");
pauseMenu.Add(new Menu.Option(Loc.Str("PauseResume"), () => SetPaused(false)));
Expand Down
6 changes: 6 additions & 0 deletions Source/SpeedrunUtils/SpeedrunUtilsControls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public class SpeedrunUtilsControls
public static readonly VirtualButton SaveState = new("SaveState");
public static readonly VirtualButton LoadState = new("LoadState");
public static readonly VirtualButton ClearState = new("ClearState");
public static readonly VirtualButton ToggleSlowdown = new("ToggleSlowdown");

public static bool SlotChangeModDown => SlotChangeMod.Down || SlotChangeMod.Bindings.Count == 0;
private static readonly VirtualButton SlotChangeMod = new("SlotChangeMod");
Expand Down Expand Up @@ -40,6 +41,8 @@ public static void Load(ControlsConfig? config = null)
it.BindTo(LoadState);
foreach (var it in FindAction(config, "SpeedrunUtils_ClearState"))
it.BindTo(ClearState);
foreach (var it in FindAction(config, "SpeedrunUtils_ToggleSlowdown"))
it.BindTo(ToggleSlowdown);

foreach (var it in FindAction(config, "SpeedrunUtils_SlotChangeMod"))
it.BindTo(SlotChangeMod);
Expand All @@ -63,6 +66,9 @@ public static void Load(ControlsConfig? config = null)
new(Keys.F4),
new(Keys.F6),
],
["SpeedrunUtils_ToggleSlowdown"] = [
new (Keys.F3),
],

["SpeedrunUtils_SlotChangeMod"] = [
new (Keys.LeftControl),
Expand Down
8 changes: 8 additions & 0 deletions Source/SpeedrunUtils/SpeedrunUtilsMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public static class SpeedrunUtilsMod
private static bool loadQueued = false;
private static readonly SaveState?[] currentStates = new SaveState[MaxSaveStateSlots];

private static bool slowdown = false;
public static float GameSpeed => slowdown ? Time.Delta * Save.Instance.SpeedrunSlowdownFactor : Time.Delta;

public static void Load()
{
SaveState.Configure();
Expand Down Expand Up @@ -58,6 +61,11 @@ public static void Update()
toastTimer = ToastTime;
}

if (SpeedrunUtilsControls.ToggleSlowdown.ConsumePress())
{
slowdown = !slowdown;
}

// Switch between save-state slots
if (SpeedrunUtilsControls.SlotChangeModDown)
{
Expand Down

0 comments on commit 96c4980

Please sign in to comment.