2020-09-04 07:23:34 +00:00
|
|
|
// 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 System.Linq;
|
|
|
|
using NUnit.Framework;
|
2020-09-08 09:36:11 +00:00
|
|
|
using osu.Framework.Testing;
|
2020-09-04 07:23:34 +00:00
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Input.Bindings;
|
|
|
|
using osu.Game.Overlays;
|
|
|
|
using osu.Game.Tests.Resources;
|
|
|
|
using osu.Game.Tests.Visual.Navigation;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Menus
|
|
|
|
{
|
|
|
|
public class TestSceneMusicActionHandling : OsuGameTestScene
|
|
|
|
{
|
2020-09-08 09:36:11 +00:00
|
|
|
private GlobalActionContainer globalActionContainer => Game.ChildrenOfType<GlobalActionContainer>().First();
|
|
|
|
|
2020-09-04 07:23:34 +00:00
|
|
|
[Test]
|
|
|
|
public void TestMusicPlayAction()
|
|
|
|
{
|
|
|
|
AddStep("ensure playing something", () => Game.MusicController.EnsurePlayingSomething());
|
2020-09-08 09:36:11 +00:00
|
|
|
AddStep("toggle playback", () => globalActionContainer.TriggerPressed(GlobalAction.MusicPlay));
|
2020-09-04 07:23:34 +00:00
|
|
|
AddAssert("music paused", () => !Game.MusicController.IsPlaying && Game.MusicController.IsUserPaused);
|
2020-09-08 09:36:11 +00:00
|
|
|
AddStep("toggle playback", () => globalActionContainer.TriggerPressed(GlobalAction.MusicPlay));
|
2020-09-04 07:23:34 +00:00
|
|
|
AddAssert("music resumed", () => Game.MusicController.IsPlaying && !Game.MusicController.IsUserPaused);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestMusicNavigationActions()
|
|
|
|
{
|
|
|
|
int importId = 0;
|
2020-09-05 13:40:26 +00:00
|
|
|
Queue<(WorkingBeatmap working, TrackChangeDirection changeDirection)> trackChangeQueue = null;
|
2020-09-04 07:23:34 +00:00
|
|
|
|
|
|
|
// ensure we have at least two beatmaps available to identify the direction the music controller navigated to.
|
|
|
|
AddRepeatStep("import beatmap", () => Game.BeatmapManager.Import(new BeatmapSetInfo
|
|
|
|
{
|
|
|
|
Beatmaps = new List<BeatmapInfo>
|
|
|
|
{
|
|
|
|
new BeatmapInfo
|
|
|
|
{
|
|
|
|
BaseDifficulty = new BeatmapDifficulty(),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Metadata = new BeatmapMetadata
|
|
|
|
{
|
|
|
|
Artist = $"a test map {importId++}",
|
|
|
|
Title = "title",
|
|
|
|
}
|
|
|
|
}).Wait(), 5);
|
|
|
|
|
|
|
|
AddStep("import beatmap with track", () =>
|
|
|
|
{
|
|
|
|
var setWithTrack = Game.BeatmapManager.Import(TestResources.GetTestBeatmapForImport()).Result;
|
|
|
|
Beatmap.Value = Game.BeatmapManager.GetWorkingBeatmap(setWithTrack.Beatmaps.First());
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("bind to track change", () =>
|
|
|
|
{
|
2020-09-05 13:40:26 +00:00
|
|
|
trackChangeQueue = new Queue<(WorkingBeatmap, TrackChangeDirection)>();
|
|
|
|
Game.MusicController.TrackChanged += (working, changeDirection) => trackChangeQueue.Enqueue((working, changeDirection));
|
2020-09-04 07:23:34 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("seek track to 6 second", () => Game.MusicController.SeekTo(6000));
|
|
|
|
AddUntilStep("wait for current time to update", () => Game.MusicController.CurrentTrack.CurrentTime > 5000);
|
|
|
|
|
2020-09-08 09:36:11 +00:00
|
|
|
AddStep("press previous", () => globalActionContainer.TriggerPressed(GlobalAction.MusicPrev));
|
2020-09-04 07:23:34 +00:00
|
|
|
AddAssert("no track change", () => trackChangeQueue.Count == 0);
|
|
|
|
AddUntilStep("track restarted", () => Game.MusicController.CurrentTrack.CurrentTime < 5000);
|
|
|
|
|
2020-09-08 09:36:11 +00:00
|
|
|
AddStep("press previous", () => globalActionContainer.TriggerPressed(GlobalAction.MusicPrev));
|
2020-09-04 07:23:34 +00:00
|
|
|
AddAssert("track changed to previous", () =>
|
|
|
|
trackChangeQueue.Count == 1 &&
|
2020-09-05 13:40:26 +00:00
|
|
|
trackChangeQueue.Dequeue().changeDirection == TrackChangeDirection.Prev);
|
2020-09-04 07:23:34 +00:00
|
|
|
|
2020-09-08 09:36:11 +00:00
|
|
|
AddStep("press next", () => globalActionContainer.TriggerPressed(GlobalAction.MusicNext));
|
2020-09-04 07:23:34 +00:00
|
|
|
AddAssert("track changed to next", () =>
|
|
|
|
trackChangeQueue.Count == 1 &&
|
2020-09-05 13:40:26 +00:00
|
|
|
trackChangeQueue.Dequeue().changeDirection == TrackChangeDirection.Next);
|
2020-09-04 07:23:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|