mirror of
https://github.com/ppy/osu.git
synced 2026-06-10 02:13:40 +08:00
Allow tests to accedss CarouselItems post filter operation
This commit is contained in:
@@ -4,9 +4,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.Extensions.ObjectExtensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
@@ -35,7 +37,7 @@ namespace osu.Game.Tests.Visual.SongSelectV2
|
||||
{
|
||||
protected readonly BindableList<BeatmapSetInfo> BeatmapSets = new BindableList<BeatmapSetInfo>();
|
||||
|
||||
protected BeatmapCarousel Carousel = null!;
|
||||
protected TestBeatmapCarousel Carousel = null!;
|
||||
|
||||
protected OsuScrollContainer<Drawable> Scroll => Carousel.ChildrenOfType<OsuScrollContainer<Drawable>>().Single();
|
||||
|
||||
@@ -100,7 +102,7 @@ namespace osu.Game.Tests.Visual.SongSelectV2
|
||||
},
|
||||
new Drawable[]
|
||||
{
|
||||
Carousel = new BeatmapCarousel
|
||||
Carousel = new TestBeatmapCarousel
|
||||
{
|
||||
NewItemsPresented = () => NewItemsPresentedInvocationCount++,
|
||||
BleedTop = 50,
|
||||
@@ -351,5 +353,21 @@ namespace osu.Game.Tests.Visual.SongSelectV2
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public class TestBeatmapCarousel : BeatmapCarousel
|
||||
{
|
||||
public IEnumerable<BeatmapInfo> PostFilterBeatmaps = null!;
|
||||
|
||||
protected override Task<IEnumerable<CarouselItem>> FilterAsync()
|
||||
{
|
||||
var filterAsync = base.FilterAsync();
|
||||
filterAsync.ContinueWith(result =>
|
||||
{
|
||||
if (result.IsCompletedSuccessfully)
|
||||
PostFilterBeatmaps = result.GetResultSafely().Select(i => i.Model).OfType<BeatmapInfo>();
|
||||
});
|
||||
return filterAsync;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ namespace osu.Game.Graphics.Carousel
|
||||
/// <summary>
|
||||
/// Queue an asynchronous filter operation.
|
||||
/// </summary>
|
||||
protected Task FilterAsync()
|
||||
protected virtual Task<IEnumerable<CarouselItem>> FilterAsync()
|
||||
{
|
||||
filterTask = performFilter();
|
||||
filterTask.FireAndForget();
|
||||
@@ -257,10 +257,10 @@ namespace osu.Game.Graphics.Carousel
|
||||
|
||||
private List<CarouselItem>? carouselItems;
|
||||
|
||||
private Task filterTask = Task.CompletedTask;
|
||||
private Task<IEnumerable<CarouselItem>> filterTask = Task.FromResult(Enumerable.Empty<CarouselItem>());
|
||||
private CancellationTokenSource cancellationSource = new CancellationTokenSource();
|
||||
|
||||
private async Task performFilter()
|
||||
private async Task<IEnumerable<CarouselItem>> performFilter()
|
||||
{
|
||||
Stopwatch stopwatch = Stopwatch.StartNew();
|
||||
var cts = new CancellationTokenSource();
|
||||
@@ -303,7 +303,7 @@ namespace osu.Game.Graphics.Carousel
|
||||
}, cts.Token).ConfigureAwait(false);
|
||||
|
||||
if (cts.Token.IsCancellationRequested)
|
||||
return;
|
||||
return Enumerable.Empty<CarouselItem>();
|
||||
|
||||
Schedule(() =>
|
||||
{
|
||||
@@ -319,6 +319,8 @@ namespace osu.Game.Graphics.Carousel
|
||||
NewItemsPresented?.Invoke();
|
||||
});
|
||||
|
||||
return items;
|
||||
|
||||
void log(string text) => Logger.Log($"Carousel[op {cts.GetHashCode().ToString()}] {stopwatch.ElapsedMilliseconds} ms: {text}");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user