mirror of
https://github.com/ppy/osu.git
synced 2026-06-01 21:00:33 +08:00
remove using cache, improve tests, and revert loading
This commit is contained in:
@@ -4,12 +4,14 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Collections;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Overlays;
|
||||
@@ -17,14 +19,17 @@ using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Osu;
|
||||
using osu.Game.Screens.OnlinePlay.Playlists;
|
||||
using osuTK;
|
||||
using osuTK.Input;
|
||||
using SharpCompress;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Playlists
|
||||
{
|
||||
public partial class TestSceneAddPlaylistToCollectionButton : OsuTestScene
|
||||
public partial class TestSceneAddPlaylistToCollectionButton : OsuManualInputManagerTestScene
|
||||
{
|
||||
private BeatmapManager manager = null!;
|
||||
private BeatmapSetInfo importedBeatmap = null!;
|
||||
private Room room = null!;
|
||||
private AddPlaylistToCollectionButton button = null!;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(GameHost host, AudioManager audio)
|
||||
@@ -32,6 +37,8 @@ namespace osu.Game.Tests.Visual.Playlists
|
||||
Dependencies.Cache(new RealmRulesetStore(Realm));
|
||||
Dependencies.Cache(manager = new BeatmapManager(LocalStorage, Realm, API, audio, Resources, host, Beatmap.Default));
|
||||
Dependencies.Cache(Realm);
|
||||
|
||||
Add(notificationOverlay);
|
||||
}
|
||||
|
||||
[Cached(typeof(INotificationOverlay))]
|
||||
@@ -44,25 +51,37 @@ namespace osu.Game.Tests.Visual.Playlists
|
||||
[SetUpSteps]
|
||||
public void SetUpSteps()
|
||||
{
|
||||
AddStep("clear realm", () => Realm.Realm.Write(() => Realm.Realm.RemoveAll<BeatmapCollection>()));
|
||||
|
||||
AddStep("clear notifications", () => notificationOverlay.AllNotifications.Empty());
|
||||
|
||||
importBeatmap();
|
||||
|
||||
setupRoom();
|
||||
|
||||
AddStep("create button", () =>
|
||||
{
|
||||
AddRange(new Drawable[]
|
||||
Add(button = new AddPlaylistToCollectionButton(room)
|
||||
{
|
||||
notificationOverlay,
|
||||
new AddPlaylistToCollectionButton(room)
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Size = new Vector2(300, 40),
|
||||
}
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Size = new Vector2(300, 40),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestButtonFlow()
|
||||
{
|
||||
AddStep("move mouse to button", () => InputManager.MoveMouseTo(button));
|
||||
|
||||
AddStep("click button", () => InputManager.Click(MouseButton.Left));
|
||||
|
||||
AddAssert("notification shown", () => notificationOverlay.AllNotifications.FirstOrDefault(n => n.Text.ToString().StartsWith("Created", StringComparison.Ordinal)) != null);
|
||||
|
||||
AddAssert("realm is updated", () => Realm.Realm.All<BeatmapCollection>().FirstOrDefault(c => c.Name == room.Name) != null);
|
||||
}
|
||||
|
||||
private void importBeatmap() => AddStep("import beatmap", () =>
|
||||
{
|
||||
var beatmap = CreateBeatmap(new OsuRuleset().RulesetInfo);
|
||||
|
||||
@@ -2,17 +2,15 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Collections;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Graphics.UserInterfaceV2;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.Notifications;
|
||||
using Realms;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
{
|
||||
@@ -20,14 +18,9 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
{
|
||||
private readonly Room room;
|
||||
|
||||
private LoadingLayer loading = null!;
|
||||
|
||||
[Resolved]
|
||||
private RealmAccess realmAccess { get; set; } = null!;
|
||||
|
||||
[Resolved]
|
||||
private BeatmapLookupCache beatmapLookupCache { get; set; } = null!;
|
||||
|
||||
[Resolved(canBeNull: true)]
|
||||
private INotificationOverlay? notifications { get; set; }
|
||||
|
||||
@@ -38,12 +31,8 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
private void load()
|
||||
{
|
||||
BackgroundColour = colours.Gray5;
|
||||
|
||||
Add(loading = new LoadingLayer(true, false));
|
||||
|
||||
Action = () =>
|
||||
{
|
||||
int[] ids = room.Playlist.Select(item => item.Beatmap.OnlineID).Where(onlineId => onlineId > 0).ToArray();
|
||||
@@ -54,34 +43,27 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
return;
|
||||
}
|
||||
|
||||
Enabled.Value = false;
|
||||
loading.Show();
|
||||
beatmapLookupCache.GetBeatmapsAsync(ids).ContinueWith(task => Schedule(() =>
|
||||
string filter = string.Join(" OR ", ids.Select(id => $"(OnlineID == {id})"));
|
||||
var beatmaps = realmAccess.Realm.All<BeatmapInfo>().Filter(filter).ToList();
|
||||
|
||||
var collection = realmAccess.Realm.All<BeatmapCollection>().FirstOrDefault(c => c.Name == room.Name);
|
||||
|
||||
if (collection == null)
|
||||
{
|
||||
var beatmaps = task.GetResultSafely().Where(item => item?.BeatmapSet != null).ToList();
|
||||
|
||||
var collection = realmAccess.Realm.All<BeatmapCollection>().FirstOrDefault(c => c.Name == room.Name);
|
||||
|
||||
if (collection == null)
|
||||
collection = new BeatmapCollection(room.Name, beatmaps.Select(i => i.MD5Hash).Distinct().ToList());
|
||||
realmAccess.Realm.Write(() => realmAccess.Realm.Add(collection));
|
||||
notifications?.Post(new SimpleNotification { Text = $"Created new collection: {room.Name}" });
|
||||
}
|
||||
else
|
||||
{
|
||||
collection.ToLive(realmAccess).PerformWrite(c =>
|
||||
{
|
||||
collection = new BeatmapCollection(room.Name, beatmaps.Select(i => i!.MD5Hash).Distinct().ToList());
|
||||
realmAccess.Realm.Write(() => realmAccess.Realm.Add(collection));
|
||||
notifications?.Post(new SimpleNotification { Text = $"Created new collection: {room.Name}" });
|
||||
}
|
||||
else
|
||||
{
|
||||
collection.ToLive(realmAccess).PerformWrite(c =>
|
||||
{
|
||||
beatmaps = beatmaps.Where(i => !c.BeatmapMD5Hashes.Contains(i!.MD5Hash)).ToList();
|
||||
foreach (var item in beatmaps)
|
||||
c.BeatmapMD5Hashes.Add(item!.MD5Hash);
|
||||
notifications?.Post(new SimpleNotification { Text = $"Updated collection: {room.Name}" });
|
||||
});
|
||||
}
|
||||
|
||||
loading.Hide();
|
||||
Enabled.Value = true;
|
||||
}), TaskContinuationOptions.OnlyOnRanToCompletion);
|
||||
beatmaps = beatmaps.Where(i => !c.BeatmapMD5Hashes.Contains(i.MD5Hash)).ToList();
|
||||
foreach (var item in beatmaps)
|
||||
c.BeatmapMD5Hashes.Add(item.MD5Hash);
|
||||
notifications?.Post(new SimpleNotification { Text = $"Updated collection: {room.Name}" });
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user