1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 08:12:56 +08:00

Remove manual dependencies in TestSceneMultiplayerGameplayLeaderboard

This commit is contained in:
smoogipoo 2021-06-25 15:30:23 +09:00
parent 81a812e216
commit d6ab08c958

View File

@ -7,7 +7,6 @@ using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Framework.Utils; using osu.Framework.Utils;
using osu.Game.Configuration; using osu.Game.Configuration;
@ -20,6 +19,7 @@ using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Game.Screens.Play.HUD; using osu.Game.Screens.Play.HUD;
using osu.Game.Tests.Visual.Online; using osu.Game.Tests.Visual.Online;
using osu.Game.Tests.Visual.OnlinePlay;
using osu.Game.Tests.Visual.Spectator; using osu.Game.Tests.Visual.Spectator;
namespace osu.Game.Tests.Visual.Multiplayer namespace osu.Game.Tests.Visual.Multiplayer
@ -28,28 +28,15 @@ namespace osu.Game.Tests.Visual.Multiplayer
{ {
private const int users = 16; private const int users = 16;
[Cached(typeof(SpectatorClient))] public TestMultiplayerSpectatorClient SpectatorClient => RoomDependencies?.SpectatorClient;
private TestMultiplayerSpectatorClient spectatorClient = new TestMultiplayerSpectatorClient();
[Cached(typeof(UserLookupCache))] public UserLookupCache LookupCache => RoomDependencies?.LookupCache;
private UserLookupCache lookupCache = new TestSceneCurrentlyPlayingDisplay.TestUserLookupCache();
protected new TestDependencies RoomDependencies => (TestDependencies)base.RoomDependencies;
private MultiplayerGameplayLeaderboard leaderboard; private MultiplayerGameplayLeaderboard leaderboard;
protected override Container<Drawable> Content { get; } = new Container { RelativeSizeAxes = Axes.Both };
private OsuConfigManager config; private OsuConfigManager config;
public TestSceneMultiplayerGameplayLeaderboard()
{
base.Content.Children = new Drawable[]
{
spectatorClient,
lookupCache,
Content
};
}
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
@ -59,7 +46,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
[SetUpSteps] [SetUpSteps]
public override void SetUpSteps() public override void SetUpSteps()
{ {
AddStep("set local user", () => ((DummyAPIAccess)API).LocalUser.Value = lookupCache.GetUserAsync(1).Result); AddStep("set local user", () => ((DummyAPIAccess)API).LocalUser.Value = LookupCache.GetUserAsync(1).Result);
AddStep("create leaderboard", () => AddStep("create leaderboard", () =>
{ {
@ -71,12 +58,12 @@ namespace osu.Game.Tests.Visual.Multiplayer
var playable = Beatmap.Value.GetPlayableBeatmap(Ruleset.Value); var playable = Beatmap.Value.GetPlayableBeatmap(Ruleset.Value);
for (int i = 0; i < users; i++) for (int i = 0; i < users; i++)
spectatorClient.StartPlay(i, Beatmap.Value.BeatmapInfo.OnlineBeatmapID ?? 0); SpectatorClient.StartPlay(i, Beatmap.Value.BeatmapInfo.OnlineBeatmapID ?? 0);
spectatorClient.Schedule(() => SpectatorClient.Schedule(() =>
{ {
Client.CurrentMatchPlayingUserIds.Clear(); Client.CurrentMatchPlayingUserIds.Clear();
Client.CurrentMatchPlayingUserIds.AddRange(spectatorClient.PlayingUsers); Client.CurrentMatchPlayingUserIds.AddRange(SpectatorClient.PlayingUsers);
}); });
Children = new Drawable[] Children = new Drawable[]
@ -86,7 +73,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
scoreProcessor.ApplyBeatmap(playable); scoreProcessor.ApplyBeatmap(playable);
LoadComponentAsync(leaderboard = new MultiplayerGameplayLeaderboard(scoreProcessor, spectatorClient.PlayingUsers.ToArray()) LoadComponentAsync(leaderboard = new MultiplayerGameplayLeaderboard(scoreProcessor, SpectatorClient.PlayingUsers.ToArray())
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
@ -100,7 +87,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
[Test] [Test]
public void TestScoreUpdates() public void TestScoreUpdates()
{ {
AddRepeatStep("update state", () => spectatorClient.RandomlyUpdateState(), 100); AddRepeatStep("update state", () => SpectatorClient.RandomlyUpdateState(), 100);
AddToggleStep("switch compact mode", expanded => leaderboard.Expanded.Value = expanded); AddToggleStep("switch compact mode", expanded => leaderboard.Expanded.Value = expanded);
} }
@ -113,11 +100,25 @@ namespace osu.Game.Tests.Visual.Multiplayer
[Test] [Test]
public void TestChangeScoringMode() public void TestChangeScoringMode()
{ {
AddRepeatStep("update state", () => spectatorClient.RandomlyUpdateState(), 5); AddRepeatStep("update state", () => SpectatorClient.RandomlyUpdateState(), 5);
AddStep("change to classic", () => config.SetValue(OsuSetting.ScoreDisplayMode, ScoringMode.Classic)); AddStep("change to classic", () => config.SetValue(OsuSetting.ScoreDisplayMode, ScoringMode.Classic));
AddStep("change to standardised", () => config.SetValue(OsuSetting.ScoreDisplayMode, ScoringMode.Standardised)); AddStep("change to standardised", () => config.SetValue(OsuSetting.ScoreDisplayMode, ScoringMode.Standardised));
} }
protected override RoomTestDependencies CreateRoomDependencies() => new TestDependencies();
protected class TestDependencies : MultiplayerRoomTestDependencies
{
public readonly TestMultiplayerSpectatorClient SpectatorClient = new TestMultiplayerSpectatorClient();
public readonly UserLookupCache LookupCache = new TestSceneCurrentlyPlayingDisplay.TestUserLookupCache();
public TestDependencies()
{
CacheAs<SpectatorClient>(SpectatorClient);
CacheAs(LookupCache);
}
}
public class TestMultiplayerSpectatorClient : TestSpectatorClient public class TestMultiplayerSpectatorClient : TestSpectatorClient
{ {
private readonly Dictionary<int, FrameHeader> lastHeaders = new Dictionary<int, FrameHeader>(); private readonly Dictionary<int, FrameHeader> lastHeaders = new Dictionary<int, FrameHeader>();