Simplify logic and add test coverage for remaining case

This commit is contained in:
Dean Herbert 2019-10-10 20:12:47 +09:00
parent a819a64036
commit 5eba33e876
3 changed files with 13 additions and 10 deletions

View File

@ -92,8 +92,9 @@ namespace osu.Game.Tests.Visual.Menus
exitViaEscapeAndConfirm();
}
[Test]
public void TestSongContinuesAfterExitPlayer()
[TestCase(true)]
[TestCase(false)]
public void TestSongContinuesAfterExitPlayer(bool withUserPause)
{
Player player = null;
@ -106,6 +107,9 @@ namespace osu.Game.Tests.Visual.Menus
AddUntilStep("wait for selected", () => !game.Beatmap.IsDefault);
if (withUserPause)
AddStep("pause", () => game.Dependencies.Get<MusicController>().Stop());
AddStep("press enter", () => pressAndRelease(Key.Enter));
AddUntilStep("wait for player", () => (player = game.ScreenStack.CurrentScreen as Player) != null);

View File

@ -129,11 +129,9 @@ namespace osu.Game.Overlays
{
var track = current?.Track;
if (track.IsRunning)
{
IsUserPaused = true;
IsUserPaused = true;
if (track?.IsRunning == true)
track.Stop();
}
}
/// <summary>

View File

@ -490,7 +490,9 @@ namespace osu.Game.Screens.Select
if (Beatmap != null && !Beatmap.Value.BeatmapSetInfo.DeletePending)
{
UpdateBeatmap(Beatmap.Value);
ensurePlayingSelected(false);
// restart playback on returning to song select, regardless.
music?.Play();
}
base.OnResuming(last);
@ -587,8 +589,7 @@ namespace osu.Game.Screens.Select
/// Ensures some music is playing for the current track.
/// Will resume playback from a manual user pause if the track has changed.
/// </summary>
/// <param name="fromPreviewPoint">Whether to restart from the preview point, rather than resuming from previous location.</param>
private void ensurePlayingSelected(bool fromPreviewPoint = true)
private void ensurePlayingSelected()
{
Track track = Beatmap.Value.Track;
@ -597,7 +598,7 @@ namespace osu.Game.Screens.Select
track.RestartPoint = Beatmap.Value.Metadata.PreviewTime;
if (!track.IsRunning && (music?.IsUserPaused != true || isNewTrack))
music?.Play(fromPreviewPoint);
music?.Play(true);
lastTrack.SetTarget(track);
}