mirror of
https://github.com/ppy/osu.git
synced 2025-01-18 10:43:22 +08:00
Access beatmap store via abstract base class
The intention here is to make things more testable going forward. Specifically, to remove the "back-door" entrance into `BeatmapCarousel` where `BeatmapSets` can be set by tests and bypas/block realm retrieval.
This commit is contained in:
parent
bab9b9c937
commit
c94b393e30
@ -49,17 +49,17 @@ namespace osu.Game.Tests.Visual.Background
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(GameHost host, AudioManager audio)
|
||||
{
|
||||
DetachedBeatmapStore detachedBeatmapStore;
|
||||
BeatmapStore beatmapStore;
|
||||
|
||||
Dependencies.Cache(rulesets = new RealmRulesetStore(Realm));
|
||||
Dependencies.Cache(manager = new BeatmapManager(LocalStorage, Realm, null, audio, Resources, host, Beatmap.Default));
|
||||
Dependencies.Cache(new OsuConfigManager(LocalStorage));
|
||||
Dependencies.Cache(detachedBeatmapStore = new DetachedBeatmapStore());
|
||||
Dependencies.Cache(beatmapStore = new RealmDetachedBeatmapStore());
|
||||
Dependencies.Cache(Realm);
|
||||
|
||||
manager.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();
|
||||
|
||||
Add(detachedBeatmapStore);
|
||||
Add(beatmapStore);
|
||||
|
||||
Beatmap.SetDefault();
|
||||
}
|
||||
|
@ -44,14 +44,14 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(GameHost host, AudioManager audio)
|
||||
{
|
||||
DetachedBeatmapStore detachedBeatmapStore;
|
||||
BeatmapStore beatmapStore;
|
||||
|
||||
Dependencies.Cache(new RealmRulesetStore(Realm));
|
||||
Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, Realm, null, audio, Resources, host, Beatmap.Default));
|
||||
Dependencies.Cache(detachedBeatmapStore = new DetachedBeatmapStore());
|
||||
Dependencies.Cache(beatmapStore = new RealmDetachedBeatmapStore());
|
||||
Dependencies.Cache(Realm);
|
||||
|
||||
Add(detachedBeatmapStore);
|
||||
Add(beatmapStore);
|
||||
}
|
||||
|
||||
public override void SetUpSteps()
|
||||
|
@ -66,14 +66,14 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(GameHost host, AudioManager audio)
|
||||
{
|
||||
DetachedBeatmapStore detachedBeatmapStore;
|
||||
BeatmapStore beatmapStore;
|
||||
|
||||
Dependencies.Cache(new RealmRulesetStore(Realm));
|
||||
Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, Realm, API, audio, Resources, host, Beatmap.Default));
|
||||
Dependencies.Cache(detachedBeatmapStore = new DetachedBeatmapStore());
|
||||
Dependencies.Cache(beatmapStore = new RealmDetachedBeatmapStore());
|
||||
Dependencies.Cache(Realm);
|
||||
|
||||
Add(detachedBeatmapStore);
|
||||
Add(beatmapStore);
|
||||
}
|
||||
|
||||
public override void SetUpSteps()
|
||||
|
@ -46,16 +46,16 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(GameHost host, AudioManager audio)
|
||||
{
|
||||
DetachedBeatmapStore detachedBeatmapStore;
|
||||
BeatmapStore beatmapStore;
|
||||
|
||||
Dependencies.Cache(rulesets = new RealmRulesetStore(Realm));
|
||||
Dependencies.Cache(manager = new BeatmapManager(LocalStorage, Realm, null, audio, Resources, host, Beatmap.Default));
|
||||
Dependencies.Cache(detachedBeatmapStore = new DetachedBeatmapStore());
|
||||
Dependencies.Cache(beatmapStore = new RealmDetachedBeatmapStore());
|
||||
Dependencies.Cache(Realm);
|
||||
|
||||
importedBeatmapSet = manager.Import(TestResources.CreateTestBeatmapSetInfo(8, rulesets.AvailableRulesets.ToArray()))!;
|
||||
|
||||
Add(detachedBeatmapStore);
|
||||
Add(beatmapStore);
|
||||
}
|
||||
|
||||
private void setUp()
|
||||
|
@ -31,18 +31,18 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(GameHost host, AudioManager audio)
|
||||
{
|
||||
DetachedBeatmapStore detachedBeatmapStore;
|
||||
BeatmapStore beatmapStore;
|
||||
|
||||
Dependencies.Cache(new RealmRulesetStore(Realm));
|
||||
Dependencies.Cache(manager = new BeatmapManager(LocalStorage, Realm, null, audio, Resources, host, Beatmap.Default));
|
||||
Dependencies.Cache(detachedBeatmapStore = new DetachedBeatmapStore());
|
||||
Dependencies.Cache(beatmapStore = new RealmDetachedBeatmapStore());
|
||||
Dependencies.Cache(Realm);
|
||||
|
||||
var beatmapSet = TestResources.CreateTestBeatmapSetInfo();
|
||||
|
||||
manager.Import(beatmapSet);
|
||||
|
||||
Add(detachedBeatmapStore);
|
||||
Add(beatmapStore);
|
||||
}
|
||||
|
||||
public override void SetUpSteps()
|
||||
|
@ -56,20 +56,20 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(GameHost host, AudioManager audio)
|
||||
{
|
||||
DetachedBeatmapStore detachedBeatmapStore;
|
||||
BeatmapStore beatmapStore;
|
||||
|
||||
// These DI caches are required to ensure for interactive runs this test scene doesn't nuke all user beatmaps in the local install.
|
||||
// At a point we have isolated interactive test runs enough, this can likely be removed.
|
||||
Dependencies.Cache(rulesets = new RealmRulesetStore(Realm));
|
||||
Dependencies.Cache(Realm);
|
||||
Dependencies.Cache(manager = new BeatmapManager(LocalStorage, Realm, null, audio, Resources, host, defaultBeatmap = Beatmap.Default));
|
||||
Dependencies.Cache(detachedBeatmapStore = new DetachedBeatmapStore());
|
||||
Dependencies.Cache(beatmapStore = new RealmDetachedBeatmapStore());
|
||||
|
||||
Dependencies.Cache(music = new MusicController());
|
||||
|
||||
// required to get bindables attached
|
||||
Add(music);
|
||||
Add(detachedBeatmapStore);
|
||||
Add(beatmapStore);
|
||||
|
||||
Dependencies.Cache(config = new OsuConfigManager(LocalStorage));
|
||||
}
|
||||
|
35
osu.Game/Database/BeatmapStore.cs
Normal file
35
osu.Game/Database/BeatmapStore.cs
Normal file
@ -0,0 +1,35 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Threading;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Beatmaps;
|
||||
|
||||
namespace osu.Game.Database
|
||||
{
|
||||
/// <summary>
|
||||
/// A store which contains a thread-safe representation of beatmaps available game-wide.
|
||||
/// This exposes changes to available beatmaps, such as post-import or deletion.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The main goal of classes which implement this interface should be to provide change
|
||||
/// tracking and thread safety in a performant way, rather than having to worry about such
|
||||
/// concerns at the point of usage.
|
||||
/// </remarks>
|
||||
public abstract partial class BeatmapStore : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Get all available beatmaps.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">A cancellation token which allows early abort from the operation.</param>
|
||||
/// <returns>A bindable list of all available beatmap sets.</returns>
|
||||
/// <remarks>
|
||||
/// This operation may block during the initial load process.
|
||||
///
|
||||
/// It is generally expected that once a beatmap store is in a good state, the overhead of this call
|
||||
/// should be negligible.
|
||||
/// </remarks>
|
||||
public abstract IBindableList<BeatmapSetInfo> GetBeatmaps(CancellationToken? cancellationToken);
|
||||
}
|
||||
}
|
@ -8,14 +8,13 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using Realms;
|
||||
|
||||
namespace osu.Game.Database
|
||||
{
|
||||
public partial class DetachedBeatmapStore : Component
|
||||
public partial class RealmDetachedBeatmapStore : BeatmapStore
|
||||
{
|
||||
private readonly ManualResetEventSlim loaded = new ManualResetEventSlim();
|
||||
|
||||
@ -28,7 +27,7 @@ namespace osu.Game.Database
|
||||
[Resolved]
|
||||
private RealmAccess realm { get; set; } = null!;
|
||||
|
||||
public IBindableList<BeatmapSetInfo> GetDetachedBeatmaps(CancellationToken? cancellationToken)
|
||||
public override IBindableList<BeatmapSetInfo> GetBeatmaps(CancellationToken? cancellationToken)
|
||||
{
|
||||
loaded.Wait(cancellationToken ?? CancellationToken.None);
|
||||
return detachedBeatmapSets.GetBoundCopy();
|
@ -1143,7 +1143,7 @@ namespace osu.Game
|
||||
loadComponentSingleFile(new MedalOverlay(), topMostOverlayContent.Add);
|
||||
|
||||
loadComponentSingleFile(new BackgroundDataStoreProcessor(), Add);
|
||||
loadComponentSingleFile(new DetachedBeatmapStore(), Add, true);
|
||||
loadComponentSingleFile<BeatmapStore>(new RealmDetachedBeatmapStore(), Add, true);
|
||||
|
||||
Add(externalLinkOpener = new ExternalLinkOpener());
|
||||
Add(new MusicKeyBindingHandler());
|
||||
|
@ -113,7 +113,7 @@ namespace osu.Game.Screens.Select
|
||||
private RealmAccess realm { get; set; } = null!;
|
||||
|
||||
[Resolved]
|
||||
private DetachedBeatmapStore? detachedBeatmapStore { get; set; }
|
||||
private BeatmapStore? beatmapStore { get; set; }
|
||||
|
||||
private IBindableList<BeatmapSetInfo>? detachedBeatmapSets;
|
||||
|
||||
@ -244,9 +244,9 @@ namespace osu.Game.Screens.Select
|
||||
|
||||
RightClickScrollingEnabled.BindValueChanged(enabled => Scroll.RightMouseScrollbar = enabled.NewValue, true);
|
||||
|
||||
if (detachedBeatmapStore != null && detachedBeatmapSets == null)
|
||||
if (beatmapStore != null && detachedBeatmapSets == null)
|
||||
{
|
||||
detachedBeatmapSets = detachedBeatmapStore.GetDetachedBeatmaps(cancellationToken);
|
||||
detachedBeatmapSets = beatmapStore.GetBeatmaps(cancellationToken);
|
||||
detachedBeatmapSets.BindCollectionChanged(beatmapSetsChanged);
|
||||
loadNewRoot();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user