mirror of
https://github.com/ppy/osu.git
synced 2025-01-26 12:25:04 +08:00
Tidy up test beatmap loading
This commit is contained in:
parent
853023dfba
commit
e04b5bb3f2
@ -6,6 +6,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||
@ -1268,26 +1269,23 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
}
|
||||
}
|
||||
|
||||
createCarousel(beatmapSets, c =>
|
||||
createCarousel(beatmapSets, initialCriteria, c =>
|
||||
{
|
||||
carouselAdjust?.Invoke(c);
|
||||
|
||||
carousel.Filter(initialCriteria?.Invoke() ?? new FilterCriteria());
|
||||
carousel.BeatmapSetsChanged = () => changed = true;
|
||||
carousel.BeatmapSets = beatmapSets;
|
||||
carouselAdjust?.Invoke(c);
|
||||
});
|
||||
|
||||
AddUntilStep("Wait for load", () => changed);
|
||||
}
|
||||
|
||||
private void createCarousel(List<BeatmapSetInfo> beatmapSets, Action<BeatmapCarousel> carouselAdjust = null, Container target = null)
|
||||
private void createCarousel(List<BeatmapSetInfo> beatmapSets, [CanBeNull] Func<FilterCriteria> initialCriteria = null, Action<BeatmapCarousel> carouselAdjust = null, Container target = null)
|
||||
{
|
||||
AddStep("Create carousel", () =>
|
||||
{
|
||||
selectedSets.Clear();
|
||||
eagerSelectedIDs.Clear();
|
||||
|
||||
carousel = new TestBeatmapCarousel
|
||||
carousel = new TestBeatmapCarousel(initialCriteria?.Invoke() ?? new FilterCriteria())
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
};
|
||||
@ -1389,8 +1387,8 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
|
||||
private partial class TestBeatmapCarousel : BeatmapCarousel
|
||||
{
|
||||
public TestBeatmapCarousel()
|
||||
: base(new FilterCriteria())
|
||||
public TestBeatmapCarousel(FilterCriteria criteria)
|
||||
: base(criteria)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -130,18 +130,22 @@ namespace osu.Game.Screens.Select
|
||||
get => beatmapSets.Select(g => g.BeatmapSet);
|
||||
set
|
||||
{
|
||||
if (LoadState != LoadState.NotLoaded)
|
||||
throw new InvalidOperationException("If not using a realm source, beatmap sets must be set before load.");
|
||||
|
||||
loadedTestBeatmaps = true;
|
||||
Schedule(() => loadBeatmapSets(value));
|
||||
detachedBeatmapSets = new BindableList<BeatmapSetInfo>(value);
|
||||
Schedule(loadNewRoot);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadBeatmapSets(IEnumerable<BeatmapSetInfo> beatmapSets)
|
||||
private void loadNewRoot()
|
||||
{
|
||||
// Ensure no changes are made to the list while we are initialising items.
|
||||
// We'll catch up on changes via subscriptions anyway.
|
||||
beatmapSets = beatmapSets.ToArray();
|
||||
BeatmapSetInfo[] loadableSets = detachedBeatmapSets.ToArray();
|
||||
|
||||
if (selectedBeatmapSet != null && !beatmapSets.Contains(selectedBeatmapSet.BeatmapSet))
|
||||
if (selectedBeatmapSet != null && !loadableSets.Contains(selectedBeatmapSet.BeatmapSet))
|
||||
selectedBeatmapSet = null;
|
||||
|
||||
var selectedBeatmapBefore = selectedBeatmap?.BeatmapInfo;
|
||||
@ -150,7 +154,7 @@ namespace osu.Game.Screens.Select
|
||||
|
||||
if (beatmapsSplitOut)
|
||||
{
|
||||
var carouselBeatmapSets = beatmapSets.SelectMany(s => s.Beatmaps).Select(b =>
|
||||
var carouselBeatmapSets = loadableSets.SelectMany(s => s.Beatmaps).Select(b =>
|
||||
{
|
||||
return createCarouselSet(new BeatmapSetInfo(new[] { b })
|
||||
{
|
||||
@ -164,7 +168,7 @@ namespace osu.Game.Screens.Select
|
||||
}
|
||||
else
|
||||
{
|
||||
var carouselBeatmapSets = beatmapSets.Select(createCarouselSet).OfType<CarouselBeatmapSet>();
|
||||
var carouselBeatmapSets = loadableSets.Select(createCarouselSet).OfType<CarouselBeatmapSet>();
|
||||
|
||||
newRoot.AddItems(carouselBeatmapSets);
|
||||
}
|
||||
@ -259,7 +263,7 @@ namespace osu.Game.Screens.Select
|
||||
// thread. If we attempt to detach beatmaps in this callback the game will fall over (it takes time).
|
||||
detachedBeatmapSets = detachedBeatmapStore.GetDetachedBeatmaps(cancellationToken);
|
||||
detachedBeatmapSets.BindCollectionChanged(beatmapSetsChanged);
|
||||
loadBeatmapSets(detachedBeatmapSets);
|
||||
loadNewRoot();
|
||||
}
|
||||
}
|
||||
|
||||
@ -309,8 +313,7 @@ namespace osu.Game.Screens.Select
|
||||
case NotifyCollectionChangedAction.Reset:
|
||||
setsRequiringRemoval.Clear();
|
||||
setsRequiringUpdate.Clear();
|
||||
|
||||
loadBeatmapSets(detachedBeatmapSets);
|
||||
loadNewRoot();
|
||||
break;
|
||||
}
|
||||
|
||||
@ -733,7 +736,7 @@ namespace osu.Game.Screens.Select
|
||||
if (activeCriteria.SplitOutDifficulties != beatmapsSplitOut)
|
||||
{
|
||||
beatmapsSplitOut = activeCriteria.SplitOutDifficulties;
|
||||
loadBeatmapSets(detachedBeatmapSets);
|
||||
loadNewRoot();
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user