1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 11:42:56 +08:00

Add testing and fix filtering only some difficulties

This commit is contained in:
Dean Herbert 2017-12-13 21:47:42 +09:00
parent 48f30d2bb5
commit 8646d5d1e0
2 changed files with 29 additions and 4 deletions

View File

@ -79,6 +79,8 @@ namespace osu.Game.Tests.Visual
AddUntilStep(() => carousel.Beatmaps.Any(), "Wait for load");
// test traversal
advanceSelection(direction: 1, diff: false);
checkSelected(1, 1);
@ -98,6 +100,8 @@ namespace osu.Game.Tests.Visual
advanceSelection(direction: -1, diff: true);
checkSelected(4, 3);
// test basic filtering
AddStep("Filter", () => carousel.Filter(new FilterCriteria { SearchText = "set #3" }, false));
checkVisibleItemCount(diff: false, count: 1);
checkVisibleItemCount(diff: true, count: 3);
@ -111,7 +115,13 @@ namespace osu.Game.Tests.Visual
checkVisibleItemCount(diff: false, count: 4);
checkVisibleItemCount(diff: true, count: 3);
setSelected(1, diff: 2);
// test filtering some difficulties (and keeping current beatmap set selected).
setSelected(1, 2);
AddStep("Filter some difficulties", () => carousel.Filter(new FilterCriteria { SearchText = "Normal" }, false));
checkSelected(1, 1);
AddStep("Un-filter", () => carousel.Filter(new FilterCriteria(), false));
checkSelected(1, 1);
}
private BeatmapSetInfo createTestBeatmapSet(int i)

View File

@ -94,6 +94,7 @@ namespace osu.Game.Screens.Select
private readonly Stack<CarouselBeatmap> randomSelectedBeatmaps = new Stack<CarouselBeatmap>();
private CarouselBeatmap selectedBeatmap;
private CarouselBeatmapSet selectedBeatmapSet => carouselSets.FirstOrDefault(s => s.State == CarouselItemState.Selected);
public BeatmapCarousel()
{
@ -291,14 +292,28 @@ namespace osu.Game.Screens.Select
{
FilterTask = null;
var lastSet = selectedBeatmapSet;
var lastBeatmap = selectedBeatmap;
carouselSets.ForEach(s => s.Filter(criteria));
yPositionsCache.Invalidate();
if (selectedBeatmap?.Visible != true)
SelectNext();
else
if (selectedBeatmap?.Filtered == false)
select(selectedBeatmap);
else if (lastBeatmap != null && !lastSet.Filtered)
{
var searchable = lastSet.Beatmaps.AsEnumerable();
// search forwards first then backwards if nothing found.
var nextAvailable =
searchable.SkipWhile(b => b != lastBeatmap).FirstOrDefault(b => !b.Filtered) ??
searchable.Reverse().SkipWhile(b => b != lastBeatmap).FirstOrDefault(b => !b.Filtered);
select(nextAvailable);
}
else
SelectNext();
};
FilterTask?.Cancel();