mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 15:33:05 +08:00
Merge pull request #8881 from peppy/schedule-music-controller-operations
Avoid calls on MusicController executing before it may have finished loading
This commit is contained in:
commit
0ffd9da6a9
@ -1,12 +1,15 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Osu;
|
||||
|
||||
namespace osu.Game.Tests.Visual.UserInterface
|
||||
@ -21,9 +24,14 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
|
||||
private NowPlayingOverlay nowPlayingOverlay;
|
||||
|
||||
private RulesetStore rulesets;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
private void load(AudioManager audio, GameHost host)
|
||||
{
|
||||
Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
|
||||
Dependencies.Cache(manager = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, host, Beatmap.Default));
|
||||
|
||||
Beatmap.Value = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
|
||||
|
||||
nowPlayingOverlay = new NowPlayingOverlay
|
||||
@ -44,21 +52,43 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
AddStep(@"hide", () => nowPlayingOverlay.Hide());
|
||||
}
|
||||
|
||||
private BeatmapManager manager { get; set; }
|
||||
|
||||
private int importId;
|
||||
|
||||
[Test]
|
||||
public void TestPrevTrackBehavior()
|
||||
{
|
||||
AddStep(@"Play track", () =>
|
||||
// ensure we have at least two beatmaps available.
|
||||
AddRepeatStep("import beatmap", () => manager.Import(new BeatmapSetInfo
|
||||
{
|
||||
musicController.NextTrack();
|
||||
currentBeatmap = Beatmap.Value;
|
||||
});
|
||||
Beatmaps = new List<BeatmapInfo>
|
||||
{
|
||||
new BeatmapInfo
|
||||
{
|
||||
BaseDifficulty = new BeatmapDifficulty(),
|
||||
}
|
||||
},
|
||||
Metadata = new BeatmapMetadata
|
||||
{
|
||||
Artist = $"a test map {importId++}",
|
||||
Title = "title",
|
||||
}
|
||||
}).Wait(), 5);
|
||||
|
||||
AddStep(@"Next track", () => musicController.NextTrack());
|
||||
AddStep("Store track", () => currentBeatmap = Beatmap.Value);
|
||||
|
||||
AddStep(@"Seek track to 6 second", () => musicController.SeekTo(6000));
|
||||
AddUntilStep(@"Wait for current time to update", () => currentBeatmap.Track.CurrentTime > 5000);
|
||||
AddAssert(@"Check action is restart track", () => musicController.PreviousTrack() == PreviousTrackResult.Restart);
|
||||
AddUntilStep("Wait for current time to update", () => Precision.AlmostEquals(currentBeatmap.Track.CurrentTime, 0));
|
||||
AddAssert(@"Check track didn't change", () => currentBeatmap == Beatmap.Value);
|
||||
AddAssert(@"Check action is not restart", () => musicController.PreviousTrack() != PreviousTrackResult.Restart);
|
||||
|
||||
AddStep(@"Set previous", () => musicController.PreviousTrack());
|
||||
|
||||
AddAssert(@"Check beatmap didn't change", () => currentBeatmap == Beatmap.Value);
|
||||
AddUntilStep("Wait for current time to update", () => currentBeatmap.Track.CurrentTime < 5000);
|
||||
|
||||
AddStep(@"Set previous", () => musicController.PreviousTrack());
|
||||
AddAssert(@"Check beatmap did change", () => currentBeatmap != Beatmap.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -172,10 +172,15 @@ namespace osu.Game.Overlays
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Play the previous track or restart the current track if it's current time below <see cref="restart_cutoff_point"/>
|
||||
/// Play the previous track or restart the current track if it's current time below <see cref="restart_cutoff_point"/>.
|
||||
/// </summary>
|
||||
/// <returns>The <see cref="PreviousTrackResult"/> that indicate the decided action</returns>
|
||||
public PreviousTrackResult PreviousTrack()
|
||||
public void PreviousTrack() => Schedule(() => prev());
|
||||
|
||||
/// <summary>
|
||||
/// Play the previous track or restart the current track if it's current time below <see cref="restart_cutoff_point"/>.
|
||||
/// </summary>
|
||||
/// <returns>The <see cref="PreviousTrackResult"/> that indicate the decided action.</returns>
|
||||
private PreviousTrackResult prev()
|
||||
{
|
||||
var currentTrackPosition = current?.Track.CurrentTime;
|
||||
|
||||
@ -204,8 +209,7 @@ namespace osu.Game.Overlays
|
||||
/// <summary>
|
||||
/// Play the next random or playlist track.
|
||||
/// </summary>
|
||||
/// <returns>Whether the operation was successful.</returns>
|
||||
public bool NextTrack() => next();
|
||||
public void NextTrack() => Schedule(() => next());
|
||||
|
||||
private bool next(bool instant = false)
|
||||
{
|
||||
@ -319,13 +323,13 @@ namespace osu.Game.Overlays
|
||||
return true;
|
||||
|
||||
case GlobalAction.MusicNext:
|
||||
if (NextTrack())
|
||||
if (next())
|
||||
onScreenDisplay?.Display(new MusicControllerToast("Next track"));
|
||||
|
||||
return true;
|
||||
|
||||
case GlobalAction.MusicPrev:
|
||||
switch (PreviousTrack())
|
||||
switch (prev())
|
||||
{
|
||||
case PreviousTrackResult.Restart:
|
||||
onScreenDisplay?.Display(new MusicControllerToast("Restart track"));
|
||||
|
Loading…
Reference in New Issue
Block a user