Loop track even if shuffling if there is only one available

Co-authored-by: Dean Herbert <pe@ppy.sh>
This commit is contained in:
Bartłomiej Dach 2024-10-14 15:28:32 +02:00
parent 17aed26f85
commit 8cec318c1f
No known key found for this signature in database
1 changed files with 14 additions and 6 deletions

View File

@ -376,11 +376,19 @@ private bool next(bool allowProtectedTracks)
{ {
Live<BeatmapSetInfo> result; Live<BeatmapSetInfo> result;
var possibleSets = getBeatmapSets().Where(s => !s.Value.Equals(current?.BeatmapSetInfo) && (!s.Value.Protected || allowProtectedTracks)).ToArray(); var possibleSets = getBeatmapSets().Where(s => !s.Value.Protected || allowProtectedTracks).ToList();
if (possibleSets.Length == 0) if (possibleSets.Count == 0)
return null; return null;
// if there is only one possible set left, play it, even if it is the same as the current track.
// looping is preferable over playing nothing.
if (possibleSets.Count == 1)
return possibleSets.Single();
// now that we actually know there is a choice, do not allow the current track to be played again.
possibleSets.RemoveAll(s => s.Value.Equals(current?.BeatmapSetInfo));
// condition below checks if the signs of `randomHistoryDirection` and `direction` are opposite and not zero. // condition below checks if the signs of `randomHistoryDirection` and `direction` are opposite and not zero.
// if that is the case, it means that the user had previously chosen next track `randomHistoryDirection` times and wants to go back, // if that is the case, it means that the user had previously chosen next track `randomHistoryDirection` times and wants to go back,
// or that the user had previously chosen previous track `randomHistoryDirection` times and wants to go forward. // or that the user had previously chosen previous track `randomHistoryDirection` times and wants to go forward.
@ -410,20 +418,20 @@ private bool next(bool allowProtectedTracks)
switch (randomSelectAlgorithm.Value) switch (randomSelectAlgorithm.Value)
{ {
case RandomSelectAlgorithm.Random: case RandomSelectAlgorithm.Random:
result = possibleSets[RNG.Next(possibleSets.Length)]; result = possibleSets[RNG.Next(possibleSets.Count)];
break; break;
case RandomSelectAlgorithm.RandomPermutation: case RandomSelectAlgorithm.RandomPermutation:
var notYetPlayedSets = possibleSets.Except(previousRandomSets).ToArray(); var notYetPlayedSets = possibleSets.Except(previousRandomSets).ToList();
if (notYetPlayedSets.Length == 0) if (notYetPlayedSets.Count == 0)
{ {
notYetPlayedSets = possibleSets; notYetPlayedSets = possibleSets;
previousRandomSets.Clear(); previousRandomSets.Clear();
randomHistoryDirection = 0; randomHistoryDirection = 0;
} }
result = notYetPlayedSets[RNG.Next(notYetPlayedSets.Length)]; result = notYetPlayedSets[RNG.Next(notYetPlayedSets.Count)];
break; break;
default: default: