2020-09-04 15:23:34 +08: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;
|
2022-01-03 16:02:15 +08:00
|
|
|
using osu.Framework.Extensions;
|
2020-09-08 17:36:11 +08:00
|
|
|
using osu.Framework.Testing;
|
2020-09-04 15:23:34 +08:00
|
|
|
using osu.Game.Beatmaps;
|
2020-12-07 17:00:45 +08:00
|
|
|
using osu.Game.Database;
|
2020-09-04 15:23:34 +08:00
|
|
|
using osu.Game.Input.Bindings;
|
|
|
|
using osu.Game.Overlays;
|
|
|
|
using osu.Game.Tests.Resources;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Menus
|
|
|
|
{
|
|
|
|
public partial class TestSceneMusicActionHandling : OsuGameTestScene
|
|
|
|
{
|
2020-09-08 17:36:11 +08:00
|
|
|
private GlobalActionContainer globalActionContainer => Game.ChildrenOfType<GlobalActionContainer>().First();
|
|
|
|
|
2020-09-04 15:23:34 +08:00
|
|
|
[Test]
|
|
|
|
public void TestMusicPlayAction()
|
|
|
|
{
|
|
|
|
AddStep("ensure playing something", () => Game.MusicController.EnsurePlayingSomething());
|
2022-07-08 13:29:15 +08:00
|
|
|
AddUntilStep("music playing", () => Game.MusicController.IsPlaying);
|
2020-09-08 17:36:11 +08:00
|
|
|
AddStep("toggle playback", () => globalActionContainer.TriggerPressed(GlobalAction.MusicPlay));
|
2022-07-08 13:29:15 +08:00
|
|
|
AddUntilStep("music paused", () => !Game.MusicController.IsPlaying && Game.MusicController.UserPauseRequested);
|
2020-09-08 17:36:11 +08:00
|
|
|
AddStep("toggle playback", () => globalActionContainer.TriggerPressed(GlobalAction.MusicPlay));
|
2022-07-08 13:29:15 +08:00
|
|
|
AddUntilStep("music resumed", () => Game.MusicController.IsPlaying && !Game.MusicController.UserPauseRequested);
|
2020-09-04 15:23:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestMusicNavigationActions()
|
|
|
|
{
|
2024-07-19 13:33:58 +08:00
|
|
|
Queue<(IWorkingBeatmap working, TrackChangeDirection changeDirection)> trackChangeQueue = null!;
|
2020-09-04 15:23:34 +08:00
|
|
|
|
2024-09-18 19:51:45 +08:00
|
|
|
AddStep("disable shuffle", () => Game.MusicController.Shuffle.Value = false);
|
|
|
|
|
2020-09-04 15:23:34 +08:00
|
|
|
// ensure we have at least two beatmaps available to identify the direction the music controller navigated to.
|
2022-01-25 14:23:51 +08:00
|
|
|
AddRepeatStep("import beatmap", () => Game.BeatmapManager.Import(TestResources.CreateTestBeatmapSetInfo()), 5);
|
2020-09-04 15:23:34 +08:00
|
|
|
|
|
|
|
AddStep("import beatmap with track", () =>
|
|
|
|
{
|
2022-01-06 21:54:43 +08:00
|
|
|
var setWithTrack = Game.BeatmapManager.Import(new ImportTask(TestResources.GetTestBeatmapForImport())).GetResultSafely();
|
2022-01-10 13:36:21 +08:00
|
|
|
setWithTrack?.PerformRead(s =>
|
|
|
|
{
|
|
|
|
Beatmap.Value = Game.BeatmapManager.GetWorkingBeatmap(s.Beatmaps.First());
|
|
|
|
});
|
2020-09-04 15:23:34 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("bind to track change", () =>
|
|
|
|
{
|
2021-11-15 17:46:11 +08:00
|
|
|
trackChangeQueue = new Queue<(IWorkingBeatmap, TrackChangeDirection)>();
|
2020-09-05 21:40:26 +08:00
|
|
|
Game.MusicController.TrackChanged += (working, changeDirection) => trackChangeQueue.Enqueue((working, changeDirection));
|
2020-09-04 15:23:34 +08: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 17:36:11 +08:00
|
|
|
AddStep("press previous", () => globalActionContainer.TriggerPressed(GlobalAction.MusicPrev));
|
2020-09-04 15:23:34 +08:00
|
|
|
AddAssert("no track change", () => trackChangeQueue.Count == 0);
|
|
|
|
AddUntilStep("track restarted", () => Game.MusicController.CurrentTrack.CurrentTime < 5000);
|
|
|
|
|
2020-09-08 17:36:11 +08:00
|
|
|
AddStep("press previous", () => globalActionContainer.TriggerPressed(GlobalAction.MusicPrev));
|
2024-07-19 13:30:55 +08:00
|
|
|
AddUntilStep("track changed to previous", () =>
|
2020-09-04 15:23:34 +08:00
|
|
|
trackChangeQueue.Count == 1 &&
|
2020-09-05 21:40:26 +08:00
|
|
|
trackChangeQueue.Dequeue().changeDirection == TrackChangeDirection.Prev);
|
2020-09-04 15:23:34 +08:00
|
|
|
|
2020-09-08 17:36:11 +08:00
|
|
|
AddStep("press next", () => globalActionContainer.TriggerPressed(GlobalAction.MusicNext));
|
2024-07-19 13:30:55 +08:00
|
|
|
AddUntilStep("track changed to next", () =>
|
2020-09-04 15:23:34 +08:00
|
|
|
trackChangeQueue.Count == 1 &&
|
2024-07-19 13:30:55 +08:00
|
|
|
trackChangeQueue.Peek().changeDirection == TrackChangeDirection.Next);
|
|
|
|
|
|
|
|
AddUntilStep("wait until track switches", () => trackChangeQueue.Count == 2);
|
|
|
|
|
|
|
|
AddStep("press next", () => globalActionContainer.TriggerPressed(GlobalAction.MusicNext));
|
|
|
|
AddUntilStep("track changed to next", () =>
|
|
|
|
trackChangeQueue.Count == 3 &&
|
|
|
|
trackChangeQueue.Peek().changeDirection == TrackChangeDirection.Next);
|
|
|
|
AddAssert("track actually changed", () => !trackChangeQueue.First().working.BeatmapInfo.Equals(trackChangeQueue.Last().working.BeatmapInfo));
|
2020-09-04 15:23:34 +08:00
|
|
|
}
|
2024-10-11 18:28:02 +08:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestShuffleBackwards()
|
|
|
|
{
|
|
|
|
Queue<(IWorkingBeatmap working, TrackChangeDirection changeDirection)> trackChangeQueue = null!;
|
|
|
|
|
|
|
|
AddStep("enable shuffle", () => Game.MusicController.Shuffle.Value = true);
|
|
|
|
|
|
|
|
// ensure we have at least two beatmaps available to identify the direction the music controller navigated to.
|
|
|
|
AddRepeatStep("import beatmap", () => Game.BeatmapManager.Import(TestResources.CreateTestBeatmapSetInfo()), 5);
|
|
|
|
AddStep("ensure nonzero track duration", () => Game.Realm.Write(r =>
|
|
|
|
{
|
|
|
|
// this was already supposed to be non-zero (see innards of `TestResources.CreateTestBeatmapSetInfo()`),
|
|
|
|
// but the non-zero value is being overwritten *to* zero by `BeatmapUpdater`.
|
|
|
|
// do a bit of a hack to change it back again - otherwise tracks are going to switch instantly and we won't be able to assert anything sane anymore.
|
|
|
|
foreach (var beatmap in r.All<BeatmapInfo>().Where(b => b.Length == 0))
|
|
|
|
beatmap.Length = 60_000;
|
|
|
|
}));
|
|
|
|
|
|
|
|
AddStep("bind to track change", () =>
|
|
|
|
{
|
|
|
|
trackChangeQueue = new Queue<(IWorkingBeatmap, TrackChangeDirection)>();
|
|
|
|
Game.MusicController.TrackChanged += (working, changeDirection) => trackChangeQueue.Enqueue((working, changeDirection));
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("seek track to 6 second", () => Game.MusicController.SeekTo(6000));
|
|
|
|
AddUntilStep("wait for current time to update", () => Game.MusicController.CurrentTrack.CurrentTime > 5000);
|
|
|
|
|
|
|
|
AddStep("press previous", () => globalActionContainer.TriggerPressed(GlobalAction.MusicPrev));
|
|
|
|
AddAssert("no track change", () => trackChangeQueue.Count == 0);
|
|
|
|
AddUntilStep("track restarted", () => Game.MusicController.CurrentTrack.CurrentTime < 5000);
|
|
|
|
|
|
|
|
AddStep("press previous", () => globalActionContainer.TriggerPressed(GlobalAction.MusicPrev));
|
|
|
|
AddUntilStep("track changed", () => trackChangeQueue.Count == 1);
|
|
|
|
|
|
|
|
AddStep("press previous", () => globalActionContainer.TriggerPressed(GlobalAction.MusicPrev));
|
|
|
|
AddUntilStep("track changed", () => trackChangeQueue.Count == 2);
|
|
|
|
|
|
|
|
AddStep("press next", () => globalActionContainer.TriggerPressed(GlobalAction.MusicNext));
|
|
|
|
AddUntilStep("track changed", () =>
|
|
|
|
trackChangeQueue.Count == 3 && !trackChangeQueue.ElementAt(1).working.BeatmapInfo.Equals(trackChangeQueue.Last().working.BeatmapInfo));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestShuffleForwards()
|
|
|
|
{
|
|
|
|
Queue<(IWorkingBeatmap working, TrackChangeDirection changeDirection)> trackChangeQueue = null!;
|
|
|
|
|
|
|
|
AddStep("enable shuffle", () => Game.MusicController.Shuffle.Value = true);
|
|
|
|
|
|
|
|
// ensure we have at least two beatmaps available to identify the direction the music controller navigated to.
|
|
|
|
AddRepeatStep("import beatmap", () => Game.BeatmapManager.Import(TestResources.CreateTestBeatmapSetInfo()), 5);
|
|
|
|
AddStep("ensure nonzero track duration", () => Game.Realm.Write(r =>
|
|
|
|
{
|
|
|
|
// this was already supposed to be non-zero (see innards of `TestResources.CreateTestBeatmapSetInfo()`),
|
|
|
|
// but the non-zero value is being overwritten *to* zero by `BeatmapUpdater`.
|
|
|
|
// do a bit of a hack to change it back again - otherwise tracks are going to switch instantly and we won't be able to assert anything sane anymore.
|
|
|
|
foreach (var beatmap in r.All<BeatmapInfo>().Where(b => b.Length == 0))
|
|
|
|
beatmap.Length = 60_000;
|
|
|
|
}));
|
|
|
|
|
|
|
|
AddStep("bind to track change", () =>
|
|
|
|
{
|
|
|
|
trackChangeQueue = new Queue<(IWorkingBeatmap, TrackChangeDirection)>();
|
|
|
|
Game.MusicController.TrackChanged += (working, changeDirection) => trackChangeQueue.Enqueue((working, changeDirection));
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("press next", () => globalActionContainer.TriggerPressed(GlobalAction.MusicNext));
|
|
|
|
AddUntilStep("track changed", () => trackChangeQueue.Count == 1);
|
|
|
|
|
|
|
|
AddStep("press next", () => globalActionContainer.TriggerPressed(GlobalAction.MusicNext));
|
|
|
|
AddUntilStep("track changed", () => trackChangeQueue.Count == 2);
|
|
|
|
|
|
|
|
AddStep("press previous", () => globalActionContainer.TriggerPressed(GlobalAction.MusicPrev));
|
|
|
|
AddUntilStep("track changed", () =>
|
|
|
|
trackChangeQueue.Count == 3 && !trackChangeQueue.ElementAt(1).working.BeatmapInfo.Equals(trackChangeQueue.Last().working.BeatmapInfo));
|
|
|
|
}
|
2024-10-11 18:45:03 +08:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestShuffleBackAndForth()
|
|
|
|
{
|
|
|
|
Queue<(IWorkingBeatmap working, TrackChangeDirection changeDirection)> trackChangeQueue = null!;
|
|
|
|
|
|
|
|
AddStep("enable shuffle", () => Game.MusicController.Shuffle.Value = true);
|
|
|
|
|
|
|
|
// ensure we have at least two beatmaps available to identify the direction the music controller navigated to.
|
|
|
|
AddRepeatStep("import beatmap", () => Game.BeatmapManager.Import(TestResources.CreateTestBeatmapSetInfo()), 5);
|
|
|
|
AddStep("ensure nonzero track duration", () => Game.Realm.Write(r =>
|
|
|
|
{
|
|
|
|
// this was already supposed to be non-zero (see innards of `TestResources.CreateTestBeatmapSetInfo()`),
|
|
|
|
// but the non-zero value is being overwritten *to* zero by `BeatmapUpdater`.
|
|
|
|
// do a bit of a hack to change it back again - otherwise tracks are going to switch instantly and we won't be able to assert anything sane anymore.
|
|
|
|
foreach (var beatmap in r.All<BeatmapInfo>().Where(b => b.Length == 0))
|
|
|
|
beatmap.Length = 60_000;
|
|
|
|
}));
|
|
|
|
|
|
|
|
AddStep("bind to track change", () =>
|
|
|
|
{
|
|
|
|
trackChangeQueue = new Queue<(IWorkingBeatmap, TrackChangeDirection)>();
|
|
|
|
Game.MusicController.TrackChanged += (working, changeDirection) => trackChangeQueue.Enqueue((working, changeDirection));
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("press next", () => globalActionContainer.TriggerPressed(GlobalAction.MusicNext));
|
|
|
|
AddUntilStep("track changed", () => trackChangeQueue.Count == 1);
|
|
|
|
|
|
|
|
AddStep("press previous", () => globalActionContainer.TriggerPressed(GlobalAction.MusicPrev));
|
|
|
|
AddUntilStep("track changed", () =>
|
|
|
|
trackChangeQueue.Count == 2 && !trackChangeQueue.First().working.BeatmapInfo.Equals(trackChangeQueue.Last().working.BeatmapInfo));
|
|
|
|
}
|
2020-09-04 15:23:34 +08:00
|
|
|
}
|
|
|
|
}
|