1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 03:25:11 +08:00

Rewrite implementation to avoid duplicated LINQ returns

This commit is contained in:
Dean Herbert 2022-10-25 12:48:17 +09:00
parent b95091fbb0
commit 2456a18bc1

View File

@ -115,26 +115,24 @@ namespace osu.Game.Screens.Select.Carousel
protected virtual CarouselItem GetNextToSelect()
{
int forwardsIndex = lastSelectedIndex;
bool hasForwards;
int backwardsIndex = lastSelectedIndex;
bool hasBackwards;
while (true)
while ((hasBackwards = backwardsIndex >= 0) | (hasForwards = forwardsIndex < Items.Count))
{
// check if a direction has been exhausted and an item (or null) from the other direction should be returned
if (forwardsIndex >= Items.Count)
return Items.Reverse().Skip(Items.Count - backwardsIndex - 1).FirstOrDefault(item => !item.Filtered.Value);
if (backwardsIndex < 0)
return Items.Skip(forwardsIndex).FirstOrDefault(item => !item.Filtered.Value);
// check if an unfiltered item has been reached
if (!Items[forwardsIndex].Filtered.Value)
if (hasForwards && !Items[forwardsIndex].Filtered.Value)
return Items[forwardsIndex];
if (!Items[backwardsIndex].Filtered.Value)
if (hasBackwards && !Items[backwardsIndex].Filtered.Value)
return Items[backwardsIndex];
// increment the indices
forwardsIndex++;
backwardsIndex--;
}
return null;
}
protected virtual void PerformSelection()