From 1d479c2e8b5627a5fd8894d219cbd436898bd1d9 Mon Sep 17 00:00:00 2001 From: TaterToes Date: Thu, 10 Oct 2024 15:55:03 -0400 Subject: [PATCH] make autoplay path when going backwards in replay --- .../Screens/Edit/GameplayTest/EditorPlayer.cs | 50 ++++++++++++++----- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/osu.Game/Screens/Edit/GameplayTest/EditorPlayer.cs b/osu.Game/Screens/Edit/GameplayTest/EditorPlayer.cs index 4377cc6219..d3634f98ad 100644 --- a/osu.Game/Screens/Edit/GameplayTest/EditorPlayer.cs +++ b/osu.Game/Screens/Edit/GameplayTest/EditorPlayer.cs @@ -173,27 +173,53 @@ namespace osu.Game.Screens.Edit.GameplayTest { } + private double previousAutoTime = 0; + + public void SetupAutoplay() + { + var autoplay = Ruleset.Value.CreateInstance().GetAutoplayMod(); + if (autoplay == null) + return; + + // stores time when autoplay starts + previousAutoTime = GameplayClockContainer.CurrentTime; + + var score = autoplay.CreateScoreFromReplayData(GameplayState.Beatmap, new[] { autoplay }); + + // remove past frames to prevent replay frame handler from seeking back to start in an attempt to play back the entirety of the replay. + score.Replay.Frames.RemoveAll(f => f.Time <= GameplayClockContainer.CurrentTime); + + DrawableRuleset.SetReplayScore(score); + + // Without this schedule, the `GlobalCursorDisplay.Update()` machinery will fade the gameplay cursor out, but we still want it to show. + Schedule(() => DrawableRuleset.Cursor?.Show()); + } + private void toggleAutoplay() { if (DrawableRuleset.ReplayScore == null) { - var autoplay = Ruleset.Value.CreateInstance().GetAutoplayMod(); - if (autoplay == null) - return; - - var score = autoplay.CreateScoreFromReplayData(GameplayState.Beatmap, [autoplay]); - - // remove past frames to prevent replay frame handler from seeking back to start in an attempt to play back the entirety of the replay. - score.Replay.Frames.RemoveAll(f => f.Time <= GameplayClockContainer.CurrentTime); - - DrawableRuleset.SetReplayScore(score); - // Without this schedule, the `GlobalCursorDisplay.Update()` machinery will fade the gameplay cursor out, but we still want it to show. - Schedule(() => DrawableRuleset.Cursor?.Show()); + SetupAutoplay(); } else DrawableRuleset.SetReplayScore(null); } + protected override void Update() + { + if (DrawableRuleset.ReplayScore != null) + { + // compare currentTime with previousTime + if (GameplayClockContainer.CurrentTime != previousAutoTime) + { + if (GameplayClockContainer.CurrentTime < previousAutoTime) + { + SetupAutoplay(); + } + } + } + } + private void toggleQuickPause() { if (GameplayClockContainer.IsPaused.Value)