Skip to content

Commit

Permalink
Merge pull request #30937 from frenzibyte/fix-quick-restart-not-savin…
Browse files Browse the repository at this point in the history
…g-score

Fix score no longer being saved when quick-restarting after pass
  • Loading branch information
peppy authored Dec 5, 2024
2 parents 72aa652 + fa87df6 commit 791416c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion osu.Game.Tests/Visual/Mods/TestSceneModFailCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public partial class TestSceneModFailCondition : ModTestScene
protected override TestPlayer CreateModPlayer(Ruleset ruleset)
{
var player = base.CreateModPlayer(ruleset);
player.RestartRequested = _ => restartRequested = true;
player.PrepareLoaderForRestart = _ => restartRequested = true;
return player;
}

Expand Down
17 changes: 9 additions & 8 deletions osu.Game/Screens/Play/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public abstract partial class Player : ScreenWithBeatmapBackground, ISamplePlayb
/// </summary>
protected virtual bool PauseOnFocusLost => true;

public Action<bool> RestartRequested;
public Action<bool> PrepareLoaderForRestart;

private bool isRestarting;
private bool skipExitTransition;
Expand Down Expand Up @@ -646,7 +646,6 @@ protected bool PerformExit(bool skipTransition = false)
// import current score if possible.
prepareAndImportScoreAsync();

// Screen may not be current if a restart has been performed.
if (this.IsCurrentScreen())
{
skipExitTransition = skipTransition;
Expand All @@ -657,6 +656,12 @@ protected bool PerformExit(bool skipTransition = false)
// - the pause / fail dialog was requested but couldn't be displayed due to the type or state of this Player instance.
this.Exit();
}
else
{
// May be restarting from results screen.
if (this.GetChildScreen() != null)
this.MakeCurrent();
}

return true;
}
Expand Down Expand Up @@ -719,12 +724,8 @@ public bool Restart(bool quickRestart = false)
// stopping here is to ensure music doesn't become audible after exiting back to PlayerLoader.
musicController.Stop();

if (RestartRequested != null)
{
skipExitTransition = quickRestart;
RestartRequested?.Invoke(quickRestart);
return true;
}
skipExitTransition = quickRestart;
PrepareLoaderForRestart?.Invoke(quickRestart);

return PerformExit(quickRestart);
}
Expand Down
6 changes: 2 additions & 4 deletions osu.Game/Screens/Play/PlayerLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ private void prepareNewPlayer()
CurrentPlayer = createPlayer();
CurrentPlayer.Configuration.AutomaticallySkipIntro |= quickRestart;
CurrentPlayer.RestartCount = restartCount++;
CurrentPlayer.RestartRequested = restartRequested;
CurrentPlayer.PrepareLoaderForRestart = prepareForRestart;

LoadTask = LoadComponentAsync(CurrentPlayer, _ =>
{
Expand All @@ -470,13 +470,11 @@ protected virtual void OnPlayerLoaded()
{
}

private void restartRequested(bool quickRestartRequested)
private void prepareForRestart(bool quickRestartRequested)
{
quickRestart = quickRestartRequested;
hideOverlays = true;
ValidForResume = true;

this.MakeCurrent();
}

private void contentIn(double delayBeforeSideDisplays = 0)
Expand Down

0 comments on commit 791416c

Please sign in to comment.