mirror of
https://github.com/ppy/osu.git
synced 2025-02-16 05:03:02 +08:00
Merge branch 'master' into overlay-filter-rank
This commit is contained in:
commit
3356909026
@ -486,9 +486,6 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
AddAssert("Something is selected", () => carousel.SelectedBeatmapInfo != null);
|
AddAssert("Something is selected", () => carousel.SelectedBeatmapInfo != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Test sorting
|
|
||||||
/// </summary>
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestSorting()
|
public void TestSorting()
|
||||||
{
|
{
|
||||||
@ -517,6 +514,9 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
AddAssert($"Check {zzz_string} is at bottom", () => carousel.BeatmapSets.Last().Metadata.Artist == zzz_string);
|
AddAssert($"Check {zzz_string} is at bottom", () => carousel.BeatmapSets.Last().Metadata.Artist == zzz_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ensures stability is maintained on different sort modes for items with equal properties.
|
||||||
|
/// </summary>
|
||||||
[Test]
|
[Test]
|
||||||
public void TestSortingStability()
|
public void TestSortingStability()
|
||||||
{
|
{
|
||||||
@ -549,6 +549,53 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
AddAssert("Items reset to original order", () => carousel.BeatmapSets.Select((set, index) => set.OnlineID == idOffset + index).All(b => b));
|
AddAssert("Items reset to original order", () => carousel.BeatmapSets.Select((set, index) => set.OnlineID == idOffset + index).All(b => b));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ensures stability is maintained on different sort modes while a new item is added to the carousel.
|
||||||
|
/// </summary>
|
||||||
|
[Test]
|
||||||
|
public void TestSortingStabilityWithNewItems()
|
||||||
|
{
|
||||||
|
List<BeatmapSetInfo> sets = new List<BeatmapSetInfo>();
|
||||||
|
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
var set = TestResources.CreateTestBeatmapSetInfo(3);
|
||||||
|
|
||||||
|
// only need to set the first as they are a shared reference.
|
||||||
|
var beatmap = set.Beatmaps.First();
|
||||||
|
|
||||||
|
beatmap.Metadata.Artist = "same artist";
|
||||||
|
beatmap.Metadata.Title = "same title";
|
||||||
|
|
||||||
|
sets.Add(set);
|
||||||
|
}
|
||||||
|
|
||||||
|
int idOffset = sets.First().OnlineID;
|
||||||
|
|
||||||
|
loadBeatmaps(sets);
|
||||||
|
|
||||||
|
AddStep("Sort by artist", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Artist }, false));
|
||||||
|
AddAssert("Items remain in original order", () => carousel.BeatmapSets.Select((set, index) => set.OnlineID == idOffset + index).All(b => b));
|
||||||
|
|
||||||
|
AddStep("Add new item", () =>
|
||||||
|
{
|
||||||
|
var set = TestResources.CreateTestBeatmapSetInfo();
|
||||||
|
|
||||||
|
// only need to set the first as they are a shared reference.
|
||||||
|
var beatmap = set.Beatmaps.First();
|
||||||
|
|
||||||
|
beatmap.Metadata.Artist = "same artist";
|
||||||
|
beatmap.Metadata.Title = "same title";
|
||||||
|
|
||||||
|
carousel.UpdateBeatmapSet(set);
|
||||||
|
});
|
||||||
|
|
||||||
|
AddAssert("Items remain in original order", () => carousel.BeatmapSets.Select((set, index) => set.OnlineID == idOffset + index).All(b => b));
|
||||||
|
|
||||||
|
AddStep("Sort by title", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Title }, false));
|
||||||
|
AddAssert("Items remain in original order", () => carousel.BeatmapSets.Select((set, index) => set.OnlineID == idOffset + index).All(b => b));
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestSortingWithFiltered()
|
public void TestSortingWithFiltered()
|
||||||
{
|
{
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace osu.Game.Screens.Select.Carousel
|
namespace osu.Game.Screens.Select.Carousel
|
||||||
{
|
{
|
||||||
@ -15,7 +14,7 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
|
|
||||||
public IReadOnlyList<CarouselItem> Items => items;
|
public IReadOnlyList<CarouselItem> Items => items;
|
||||||
|
|
||||||
private List<CarouselItem> items = new List<CarouselItem>();
|
private readonly List<CarouselItem> items = new List<CarouselItem>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Used to assign a monotonically increasing ID to items as they are added. This member is
|
/// Used to assign a monotonically increasing ID to items as they are added. This member is
|
||||||
@ -24,9 +23,6 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
private ulong currentItemID;
|
private ulong currentItemID;
|
||||||
|
|
||||||
private Comparer<CarouselItem>? criteriaComparer;
|
private Comparer<CarouselItem>? criteriaComparer;
|
||||||
|
|
||||||
private static readonly Comparer<CarouselItem> item_id_comparer = Comparer<CarouselItem>.Create((x, y) => x.ItemID.CompareTo(y.ItemID));
|
|
||||||
|
|
||||||
private FilterCriteria? lastCriteria;
|
private FilterCriteria? lastCriteria;
|
||||||
|
|
||||||
protected int GetIndexOfItem(CarouselItem lastSelected) => items.IndexOf(lastSelected);
|
protected int GetIndexOfItem(CarouselItem lastSelected) => items.IndexOf(lastSelected);
|
||||||
@ -90,9 +86,16 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
|
|
||||||
items.ForEach(c => c.Filter(criteria));
|
items.ForEach(c => c.Filter(criteria));
|
||||||
|
|
||||||
// IEnumerable<T>.OrderBy() is used instead of List<T>.Sort() to ensure sorting stability
|
criteriaComparer = Comparer<CarouselItem>.Create((x, y) =>
|
||||||
criteriaComparer = Comparer<CarouselItem>.Create((x, y) => x.CompareTo(criteria, y));
|
{
|
||||||
items = items.OrderBy(c => c, criteriaComparer).ThenBy(c => c, item_id_comparer).ToList();
|
int comparison = x.CompareTo(criteria, y);
|
||||||
|
if (comparison != 0)
|
||||||
|
return comparison;
|
||||||
|
|
||||||
|
return x.ItemID.CompareTo(y.ItemID);
|
||||||
|
});
|
||||||
|
|
||||||
|
items.Sort(criteriaComparer);
|
||||||
|
|
||||||
lastCriteria = criteria;
|
lastCriteria = criteria;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user