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

Move CarouselBeatmap access to private, test using indices

This commit is contained in:
voidedWarranties 2020-02-15 17:51:55 -08:00
parent 8e1ecddb1d
commit 8c81f1e684
2 changed files with 38 additions and 12 deletions

View File

@ -466,36 +466,53 @@ namespace osu.Game.Tests.Visual.SongSelect
[Test]
public void TestDifficultyIconSelecting()
{
int? previousID = null;
addRulesetImportStep(0);
createSongSelect();
AddStep("Store current ID", () => previousID = songSelect.Carousel.SelectedBeatmap.ID);
DrawableCarouselBeatmapSet set = null;
AddStep("Find the DrawableCarouselBeatmapSet", () =>
{
set = songSelect.Carousel.ChildrenOfType<DrawableCarouselBeatmapSet>().First();
});
DrawableCarouselBeatmapSet.FilterableDifficultyIcon difficultyIcon = null;
AddStep("Find an icon", () =>
{
difficultyIcon = set.ChildrenOfType<DrawableCarouselBeatmapSet.FilterableDifficultyIcon>()
.First(icon => getDifficultyIconIndex(set, icon) != getCurrentBeatmapIndex());
});
AddStep("Click on a difficulty", () =>
{
InputManager.MoveMouseTo(songSelect.Carousel.ChildrenOfType<DrawableCarouselBeatmapSet.FilterableDifficultyIcon>()
.First(icon => icon.Item.Beatmap != songSelect.Carousel.SelectedBeatmap));
InputManager.MoveMouseTo(difficultyIcon);
InputManager.PressButton(MouseButton.Left);
InputManager.ReleaseButton(MouseButton.Left);
});
AddAssert("Selected beatmap changed", () => songSelect.Carousel.SelectedBeatmap.ID != previousID);
AddAssert("Selected beatmap correct", () => getCurrentBeatmapIndex() == getDifficultyIconIndex(set, difficultyIcon));
double? maxBPM = null;
AddStep("Filter some difficulties", () => songSelect.Carousel.Filter(new FilterCriteria
{
BPM = new FilterCriteria.OptionalRange<double>
{
Min = songSelect.Carousel.SelectedBeatmapSet.MaxBPM,
Min = maxBPM = songSelect.Carousel.SelectedBeatmapSet.MaxBPM,
IsLowerInclusive = true
}
}));
AddUntilStep("Wait for filter", () => songSelect.Carousel.ChildrenOfType<DrawableCarouselBeatmapSet.FilterableDifficultyIcon>().Any(icon => icon.Item.Filtered.Value));
DrawableCarouselBeatmapSet.FilterableDifficultyIcon filteredIcon = null;
AddStep("Get filtered icon", () =>
{
var filteredBeatmap = songSelect.Carousel.SelectedBeatmapSet.Beatmaps.Find(b => b.BPM < maxBPM);
int filteredBeatmapIndex = getBeatmapIndex(filteredBeatmap.BeatmapSet, filteredBeatmap);
filteredIcon = set.ChildrenOfType<DrawableCarouselBeatmapSet.FilterableDifficultyIcon>().ElementAt(filteredBeatmapIndex);
});
int? previousID = null;
AddStep("Store current ID", () => previousID = songSelect.Carousel.SelectedBeatmap.ID);
AddStep("Click on a filtered difficulty", () =>
{
InputManager.MoveMouseTo(songSelect.Carousel.ChildrenOfType<DrawableCarouselBeatmapSet.FilterableDifficultyIcon>()
.First(icon => icon.Item.Filtered.Value));
InputManager.MoveMouseTo(filteredIcon);
InputManager.PressButton(MouseButton.Left);
InputManager.ReleaseButton(MouseButton.Left);
@ -503,6 +520,15 @@ namespace osu.Game.Tests.Visual.SongSelect
AddAssert("Selected beatmap has not changed", () => songSelect.Carousel.SelectedBeatmap.ID == previousID);
}
private int getBeatmapIndex(BeatmapSetInfo set, BeatmapInfo info) => set.Beatmaps.FindIndex(b => b == info);
private int getCurrentBeatmapIndex() => getBeatmapIndex(songSelect.Carousel.SelectedBeatmapSet, songSelect.Carousel.SelectedBeatmap);
private int getDifficultyIconIndex(DrawableCarouselBeatmapSet set, DrawableCarouselBeatmapSet.FilterableDifficultyIcon icon)
{
return set.ChildrenOfType<DrawableCarouselBeatmapSet.FilterableDifficultyIcon>().ToList().FindIndex(i => i == icon);
}
private void addRulesetImportStep(int id) => AddStep($"import test map for ruleset {id}", () => importForRuleset(id));
private void importForRuleset(int id) => manager.Import(createTestBeatmapSet(getImportId(), rulesets.AvailableRulesets.Where(r => r.ID == id).ToArray())).Wait();

View File

@ -211,7 +211,7 @@ namespace osu.Game.Screens.Select.Carousel
{
private readonly BindableBool filtered = new BindableBool();
public readonly CarouselBeatmap Item;
private readonly CarouselBeatmap item;
public FilterableDifficultyIcon(CarouselBeatmap item)
: base(item.Beatmap)
@ -220,13 +220,13 @@ namespace osu.Game.Screens.Select.Carousel
filtered.ValueChanged += isFiltered => Schedule(() => this.FadeTo(isFiltered.NewValue ? 0.1f : 1, 100));
filtered.TriggerChange();
Item = item;
this.item = item;
}
protected override bool OnClick(ClickEvent e)
{
if (!filtered.Value)
Item.State.Value = CarouselItemState.Selected;
item.State.Value = CarouselItemState.Selected;
return true;
}