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

Compare commits

...

17 Commits

Author SHA1 Message Date
Dean Herbert
12d44b6335
Merge pull request #8481 from LittleEndu/rewrite-select-next
Rewrite beatmap carousel's select next logic to not use drawables
2020-03-30 01:21:31 +09:00
Endrik
f4c8b6d219
Fix copy paste oversight 2020-03-29 18:55:47 +03:00
Dean Herbert
bac5f79731
Merge branch 'master' into rewrite-select-next 2020-03-30 00:08:06 +09:00
Dean Herbert
b47a532df3 Adjust code formatting slightly 2020-03-30 00:07:48 +09:00
Dean Herbert
a72f0f57f6 Refactor tests for readability 2020-03-30 00:05:07 +09:00
Dean Herbert
07c7233b3d Change int div comments 2020-03-29 23:46:28 +09:00
Endrik Tombak
8cab303611 Cover skipDifficulties = false in tests 2020-03-28 21:02:55 +02:00
Endrik Tombak
b4f0500706 Invert logic 2020-03-28 20:21:21 +02:00
Endrik
2c27894527
Use All instead of ToList Any
Co-Authored-By: Bartłomiej Dach <dach.bartlomiej@gmail.com>
2020-03-28 19:58:33 +02:00
Endrik Tombak
87854fc4fa Rename variable 2020-03-28 13:23:31 +02:00
Endrik Tombak
63f6269eb0 Test both ways 2020-03-28 13:10:20 +02:00
Endrik Tombak
659865b457 Use understandable set id 2020-03-28 13:08:06 +02:00
Endrik Tombak
0a69647efe Merge remote-tracking branch 'origin/traversal-is-broken' into rewrite-select-next 2020-03-28 13:06:37 +02:00
Endrik Tombak
6a0c5c87aa Use already existing variable 2020-03-28 13:06:03 +02:00
Endrik Tombak
fc3f9ff6fa Don't use drawables for select next 2020-03-28 12:54:48 +02:00
Endrik Tombak
e707adb773 Increase amount of test sets 2020-03-26 21:16:10 +02:00
Endrik Tombak
902734b75e Add failing test 2020-03-26 20:32:43 +02:00
2 changed files with 99 additions and 32 deletions

View File

@ -83,6 +83,82 @@ namespace osu.Game.Tests.Visual.SongSelect
waitForSelection(set_count, 3);
}
[TestCase(true)]
[TestCase(false)]
public void TestTraversalBeyondVisible(bool forwards)
{
var sets = new List<BeatmapSetInfo>();
const int total_set_count = 200;
for (int i = 0; i < total_set_count; i++)
sets.Add(createTestBeatmapSet(i + 1));
loadBeatmaps(sets);
for (int i = 1; i < total_set_count; i += i)
selectNextAndAssert(i);
void selectNextAndAssert(int amount)
{
setSelected(forwards ? 1 : total_set_count, 1);
AddStep($"{(forwards ? "Next" : "Previous")} beatmap {amount} times", () =>
{
for (int i = 0; i < amount; i++)
{
carousel.SelectNext(forwards ? 1 : -1);
}
});
waitForSelection(forwards ? amount + 1 : total_set_count - amount);
}
}
[Test]
public void TestTraversalBeyondVisibleDifficulties()
{
var sets = new List<BeatmapSetInfo>();
const int total_set_count = 20;
for (int i = 0; i < total_set_count; i++)
sets.Add(createTestBeatmapSet(i + 1));
loadBeatmaps(sets);
// Selects next set once, difficulty index doesn't change
selectNextAndAssert(3, true, 2, 1);
// Selects next set 16 times (50 \ 3 == 16), difficulty index changes twice (50 % 3 == 2)
selectNextAndAssert(50, true, 17, 3);
// Travels around the carousel thrice (200 \ 60 == 3)
// continues to select 20 times (200 \ 60 == 20)
// selects next set 6 times (20 \ 3 == 6)
// difficulty index changes twice (20 % 3 == 2)
selectNextAndAssert(200, true, 7, 3);
// All same but in reverse
selectNextAndAssert(3, false, 19, 3);
selectNextAndAssert(50, false, 4, 1);
selectNextAndAssert(200, false, 14, 1);
void selectNextAndAssert(int amount, bool forwards, int expectedSet, int expectedDiff)
{
// Select very first or very last difficulty
setSelected(forwards ? 1 : 20, forwards ? 1 : 3);
AddStep($"{(forwards ? "Next" : "Previous")} difficulty {amount} times", () =>
{
for (int i = 0; i < amount; i++)
carousel.SelectNext(forwards ? 1 : -1, false);
});
waitForSelection(expectedSet, expectedDiff);
}
}
/// <summary>
/// Test filtering
/// </summary>

View File

@ -253,46 +253,37 @@ namespace osu.Game.Screens.Select
/// <param name="skipDifficulties">Whether to skip individual difficulties and only increment over full groups.</param>
public void SelectNext(int direction = 1, bool skipDifficulties = true)
{
var visibleItems = Items.Where(s => !s.Item.Filtered.Value).ToList();
if (!visibleItems.Any())
if (beatmapSets.All(s => s.Filtered.Value))
return;
DrawableCarouselItem drawable = null;
if (skipDifficulties)
selectNextSet(direction, true);
else
selectNextDifficulty(direction);
}
if (selectedBeatmap != null && (drawable = selectedBeatmap.Drawables.FirstOrDefault()) == null)
// if the selected beatmap isn't present yet, we can't correctly change selection.
// we can fix this by changing this method to not reference drawables / Items in the first place.
return;
private void selectNextSet(int direction, bool skipDifficulties)
{
var unfilteredSets = beatmapSets.Where(s => !s.Filtered.Value).ToList();
int originalIndex = visibleItems.IndexOf(drawable);
int currentIndex = originalIndex;
var nextSet = unfilteredSets[(unfilteredSets.IndexOf(selectedBeatmapSet) + direction + unfilteredSets.Count) % unfilteredSets.Count];
// local function to increment the index in the required direction, wrapping over extremities.
int incrementIndex() => currentIndex = (currentIndex + direction + visibleItems.Count) % visibleItems.Count;
if (skipDifficulties)
select(nextSet);
else
select(direction > 0 ? nextSet.Beatmaps.First(b => !b.Filtered.Value) : nextSet.Beatmaps.Last(b => !b.Filtered.Value));
}
while (incrementIndex() != originalIndex)
{
var item = visibleItems[currentIndex].Item;
private void selectNextDifficulty(int direction)
{
var unfilteredDifficulties = selectedBeatmapSet.Children.Where(s => !s.Filtered.Value).ToList();
if (item.Filtered.Value || item.State.Value == CarouselItemState.Selected) continue;
int index = unfilteredDifficulties.IndexOf(selectedBeatmap);
switch (item)
{
case CarouselBeatmap beatmap:
if (skipDifficulties) continue;
select(beatmap);
return;
case CarouselBeatmapSet set:
if (skipDifficulties)
select(set);
else
select(direction > 0 ? set.Beatmaps.First(b => !b.Filtered.Value) : set.Beatmaps.Last(b => !b.Filtered.Value));
return;
}
}
if (index + direction < 0 || index + direction >= unfilteredDifficulties.Count)
selectNextSet(direction, false);
else
select(unfilteredDifficulties[index + direction]);
}
/// <summary>