From 96c4980e7126f3a51d1f3b94e3c9dc47d6e035dc Mon Sep 17 00:00:00 2001 From: psyGamer Date: Sat, 3 Aug 2024 13:18:53 +0200 Subject: [PATCH] Add a slowdown option --- Source/Data/Save.cs | 7 +++++++ Source/Game.cs | 9 ++++++++- Source/Scenes/World.cs | 1 + Source/SpeedrunUtils/SpeedrunUtilsControls.cs | 6 ++++++ Source/SpeedrunUtils/SpeedrunUtilsMod.cs | 8 ++++++++ 5 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Source/Data/Save.cs b/Source/Data/Save.cs index 26d6d5e..4fe1387 100644 --- a/Source/Data/Save.cs +++ b/Source/Data/Save.cs @@ -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; /// /// 0-10 Music volume level @@ -194,6 +196,11 @@ public void ToggleSpeedrunPracticeTimerPauseNearCheckpoint() { SpeedrunPracticeTimerPauseNearCheckpoint = !SpeedrunPracticeTimerPauseNearCheckpoint; } + + public void SetSpeedrunSlowdownFactor(int value) + { + SpeedrunSlowdownFactor = value / 10.0f; + } public TimeSpan GetCurrentDisplayTime() { diff --git a/Source/Game.cs b/Source/Game.cs index 680c669..fdcc288 100644 --- a/Source/Game.cs +++ b/Source/Game.cs @@ -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)) { diff --git a/Source/Scenes/World.cs b/Source/Scenes/World.cs index 9fc94c0..c0d0703 100644 --- a/Source/Scenes/World.cs +++ b/Source/Scenes/World.cs @@ -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))); diff --git a/Source/SpeedrunUtils/SpeedrunUtilsControls.cs b/Source/SpeedrunUtils/SpeedrunUtilsControls.cs index c1d2219..519b59d 100644 --- a/Source/SpeedrunUtils/SpeedrunUtilsControls.cs +++ b/Source/SpeedrunUtils/SpeedrunUtilsControls.cs @@ -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"); @@ -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); @@ -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), diff --git a/Source/SpeedrunUtils/SpeedrunUtilsMod.cs b/Source/SpeedrunUtils/SpeedrunUtilsMod.cs index 92c1fbf..8e59d9d 100644 --- a/Source/SpeedrunUtils/SpeedrunUtilsMod.cs +++ b/Source/SpeedrunUtils/SpeedrunUtilsMod.cs @@ -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(); @@ -58,6 +61,11 @@ public static void Update() toastTimer = ToastTime; } + if (SpeedrunUtilsControls.ToggleSlowdown.ConsumePress()) + { + slowdown = !slowdown; + } + // Switch between save-state slots if (SpeedrunUtilsControls.SlotChangeModDown) {