1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 10:33:30 +08:00

Merge pull request #1819 from LittleEndu/fix-randomizer

Don't allow randomizer to select invisible maps
This commit is contained in:
Dean Herbert 2018-01-09 12:52:25 +09:00 committed by GitHub
commit bb57d33239
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 75 additions and 17 deletions

View File

@ -128,6 +128,20 @@ namespace osu.Game.Tests.Visual
selectedSets.Pop();
});
private bool selectedBeatmapVisible()
{
var currentlySelected = carousel.Items.FirstOrDefault(s => s.Item is CarouselBeatmap && s.Item.State == CarouselItemState.Selected);
if (currentlySelected == null)
return true;
return currentlySelected.Item.Visible;
}
private void checkInvisibleDifficultiesUnselectable()
{
nextRandom();
AddAssert("Selection is visible", selectedBeatmapVisible);
}
/// <summary>
/// Test keyboard traversal
/// </summary>
@ -222,6 +236,15 @@ namespace osu.Game.Tests.Visual
nextRandom();
AddAssert("ensure repeat", () => selectedSets.Contains(carousel.SelectedBeatmapSet));
AddStep("Add set with 100 difficulties", () => carousel.UpdateBeatmapSet(createTestBeatmapSetWithManyDifficulties(set_count + 1)));
AddStep("Filter Extra", () => carousel.Filter(new FilterCriteria { SearchText = "Extra 10" }, false));
checkInvisibleDifficultiesUnselectable();
checkInvisibleDifficultiesUnselectable();
checkInvisibleDifficultiesUnselectable();
checkInvisibleDifficultiesUnselectable();
checkInvisibleDifficultiesUnselectable();
AddStep("Un-filter", () => carousel.Filter(new FilterCriteria(), false));
}
/// <summary>
@ -330,26 +353,26 @@ namespace osu.Game.Tests.Visual
}
}
private BeatmapSetInfo createTestBeatmapSet(int i)
private BeatmapSetInfo createTestBeatmapSet(int id)
{
return new BeatmapSetInfo
{
ID = i,
OnlineBeatmapSetID = i,
ID = id,
OnlineBeatmapSetID = id,
Hash = new MemoryStream(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString())).ComputeMD5Hash(),
Metadata = new BeatmapMetadata
{
OnlineBeatmapSetID = i,
OnlineBeatmapSetID = id,
// Create random metadata, then we can check if sorting works based on these
Artist = $"peppy{i.ToString().PadLeft(6, '0')}",
Title = $"test set #{i}!",
AuthorString = string.Concat(Enumerable.Repeat((char)('z' - Math.Min(25, i - 1)), 5))
Artist = $"peppy{id.ToString().PadLeft(6, '0')}",
Title = $"test set #{id}!",
AuthorString = string.Concat(Enumerable.Repeat((char)('z' - Math.Min(25, id - 1)), 5))
},
Beatmaps = new List<BeatmapInfo>(new[]
{
new BeatmapInfo
{
OnlineBeatmapID = i * 10,
OnlineBeatmapID = id * 10,
Path = "normal.osu",
Version = "Normal",
StarDifficulty = 2,
@ -360,7 +383,7 @@ namespace osu.Game.Tests.Visual
},
new BeatmapInfo
{
OnlineBeatmapID = i * 10 + 1,
OnlineBeatmapID = id * 10 + 1,
Path = "hard.osu",
Version = "Hard",
StarDifficulty = 5,
@ -371,7 +394,7 @@ namespace osu.Game.Tests.Visual
},
new BeatmapInfo
{
OnlineBeatmapID = i * 10 + 2,
OnlineBeatmapID = id * 10 + 2,
Path = "insane.osu",
Version = "Insane",
StarDifficulty = 6,
@ -384,6 +407,40 @@ namespace osu.Game.Tests.Visual
};
}
private BeatmapSetInfo createTestBeatmapSetWithManyDifficulties(int id)
{
var toReturn = new BeatmapSetInfo
{
ID = id,
OnlineBeatmapSetID = id,
Hash = new MemoryStream(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString())).ComputeMD5Hash(),
Metadata = new BeatmapMetadata
{
OnlineBeatmapSetID = id,
// Create random metadata, then we can check if sorting works based on these
Artist = $"peppy{id.ToString().PadLeft(6, '0')}",
Title = $"test set #{id}!",
AuthorString = string.Concat(Enumerable.Repeat((char)('z' - Math.Min(25, id - 1)), 5))
},
Beatmaps = new List<BeatmapInfo>(),
};
for (int b = 1; b < 101; b++)
{
toReturn.Beatmaps.Add(new BeatmapInfo
{
OnlineBeatmapID = b * 10,
Path = $"extra{b}.osu",
Version = $"Extra {b}",
StarDifficulty = 2,
BaseDifficulty = new BeatmapDifficulty
{
OverallDifficulty = 3.5f,
}
});
}
return toReturn;
}
private class TestBeatmapCarousel : BeatmapCarousel
{
public new List<DrawableCarouselItem> Items => base.Items;

View File

@ -235,8 +235,8 @@ namespace osu.Game.Screens.Select
/// <returns>True if a selection could be made, else False.</returns>
public bool SelectNextRandom()
{
var visible = beatmapSets.Where(s => !s.Filtered).ToList();
if (!visible.Any())
var visibleSets = beatmapSets.Where(s => !s.Filtered).ToList();
if (!visibleSets.Any())
return false;
if (selectedBeatmap != null)
@ -253,20 +253,21 @@ namespace osu.Game.Screens.Select
if (RandomAlgorithm == RandomSelectAlgorithm.RandomPermutation)
{
var notYetVisitedSets = visible.Except(previouslyVisitedRandomSets).ToList();
var notYetVisitedSets = visibleSets.Except(previouslyVisitedRandomSets).ToList();
if (!notYetVisitedSets.Any())
{
previouslyVisitedRandomSets.Clear();
notYetVisitedSets = visible;
previouslyVisitedRandomSets.RemoveAll(s => visibleSets.Contains(s));
notYetVisitedSets = visibleSets;
}
set = notYetVisitedSets.ElementAt(RNG.Next(notYetVisitedSets.Count));
previouslyVisitedRandomSets.Add(set);
}
else
set = visible.ElementAt(RNG.Next(visible.Count));
set = visibleSets.ElementAt(RNG.Next(visibleSets.Count));
select(set.Beatmaps.Skip(RNG.Next(set.Beatmaps.Count())).FirstOrDefault());
var visibleBeatmaps = set.Beatmaps.Where(s => !s.Filtered).ToList();
select(visibleBeatmaps[RNG.Next(visibleBeatmaps.Count)]);
return true;
}