Skip to content

Commit 9322f4e

Browse files
committed
Add title as fallback for certain sorting modes
1 parent 39912e0 commit 9322f4e

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

osu.Game.Tests/Visual/SongSelect/BeatmapCarouselFilterSortingTest.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,38 @@ public async Task TestSortingDateSubmitted()
9090
Assert.That(results.TakeWhile(b => b.BeatmapSet!.DateSubmitted != null).Count(), Is.EqualTo(30), () => "non-missing dates should be at the start");
9191
}
9292

93+
[Test]
94+
public async Task TestSortByBpmUsesTitleAsTiebreaker()
95+
{
96+
List<BeatmapSetInfo> beatmapSets = [];
97+
98+
// 2 sets with same BPM but different titles
99+
const int diff_count = 1;
100+
{
101+
var set = TestResources.CreateTestBeatmapSetInfo(diff_count);
102+
set.Beatmaps.ForEach(b =>
103+
{
104+
b.BPM = 175;
105+
b.Metadata.Title = "ZZZ";
106+
});
107+
beatmapSets.Add(set);
108+
}
109+
{
110+
var set = TestResources.CreateTestBeatmapSetInfo(diff_count);
111+
set.Beatmaps.ForEach(b =>
112+
{
113+
b.BPM = 175;
114+
b.Metadata.Title = "AAA";
115+
});
116+
beatmapSets.Add(set);
117+
}
118+
119+
var results = (await runSorting(SortMode.BPM, beatmapSets)).ToList();
120+
121+
Assert.AreEqual("AAA", results[0].Metadata.Title);
122+
Assert.AreEqual("ZZZ", results[1].Metadata.Title);
123+
}
124+
93125
[Test]
94126
public async Task TestSortByArtistUsesTitleAsTiebreaker()
95127
{

osu.Game/Screens/Select/BeatmapCarouselFilterSorting.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,17 @@ private static int compare(BeatmapInfo a, BeatmapInfo b, SortMode sort, bool agg
115115
throw new ArgumentOutOfRangeException();
116116
}
117117

118+
// For certain sort modes, use title comparison as a fallback
119+
// To begin with, I've only added the mode that concerns *me* but I'm sure there are more that could make use of this logic, down for you to decide which to add.
120+
if (comparison == 0 && new List<SortMode> { SortMode.BPM }.Contains(sort))
121+
{
122+
// Review: I'm not sure whether to duplicate the comparing logic for titles or introduce a recursive call.
123+
// We have the certainty that we won't go in an infinite recursion since the list in the if's condition excludes the mode that we're recursing on.
124+
125+
// comparison = OrdinalSortByCaseStringComparer.DEFAULT.Compare(a.BeatmapSet!.Metadata.Title, b.BeatmapSet!.Metadata.Title);
126+
comparison = compare(a, b, SortMode.Title, aggregate);
127+
}
128+
118129
// If the initial sort could not differentiate, attempt to use DateAdded to order sets in a stable fashion.
119130
// The directionality of this matches the current SortMode.DateAdded, but we may want to reconsider if that becomes a user decision (ie. asc / desc).
120131
if (comparison == 0)

0 commit comments

Comments
 (0)