1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 08:52:55 +08:00

Move SpectatorClient into multiplayer dependencies

This commit is contained in:
smoogipoo 2021-06-25 17:55:16 +09:00
parent 7aefbe3da1
commit c0d2b41d4c
7 changed files with 19 additions and 47 deletions

View File

@ -6,21 +6,14 @@ using System.Linq;
using NUnit.Framework;
using osu.Framework.Testing;
using osu.Framework.Timing;
using osu.Game.Online.Spectator;
using osu.Game.Rulesets.Osu.Scoring;
using osu.Game.Screens.OnlinePlay.Multiplayer.Spectate;
using osu.Game.Screens.Play.HUD;
using osu.Game.Tests.Visual.OnlinePlay;
using osu.Game.Tests.Visual.Spectator;
namespace osu.Game.Tests.Visual.Multiplayer
{
public class TestSceneMultiSpectatorLeaderboard : MultiplayerTestScene
{
public TestSpectatorClient SpectatorClient => RoomDependencies?.SpectatorClient;
protected new TestDependencies RoomDependencies => (TestDependencies)base.RoomDependencies;
private Dictionary<int, ManualClock> clocks;
private MultiSpectatorLeaderboard leaderboard;
@ -118,17 +111,5 @@ namespace osu.Game.Tests.Visual.Multiplayer
private void assertCombo(int userId, int expectedCombo)
=> AddUntilStep($"player {userId} has {expectedCombo} combo", () => this.ChildrenOfType<GameplayLeaderboardScore>().Single(s => s.User?.Id == userId).Combo.Value == expectedCombo);
protected override RoomTestDependencies CreateRoomDependencies() => new TestDependencies();
protected class TestDependencies : MultiplayerRoomTestDependencies
{
public readonly TestSpectatorClient SpectatorClient = new TestSpectatorClient();
public TestDependencies()
{
CacheAs<SpectatorClient>(SpectatorClient);
}
}
}
}

View File

@ -8,21 +8,14 @@ using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Online.Spectator;
using osu.Game.Screens.OnlinePlay.Multiplayer.Spectate;
using osu.Game.Screens.Play;
using osu.Game.Tests.Beatmaps.IO;
using osu.Game.Tests.Visual.OnlinePlay;
using osu.Game.Tests.Visual.Spectator;
namespace osu.Game.Tests.Visual.Multiplayer
{
public class TestSceneMultiSpectatorScreen : MultiplayerTestScene
{
public TestSpectatorClient SpectatorClient => RoomDependencies?.SpectatorClient;
protected new TestDependencies RoomDependencies => (TestDependencies)base.RoomDependencies;
[Resolved]
private OsuGameBase game { get; set; }
@ -279,17 +272,5 @@ namespace osu.Game.Tests.Visual.Multiplayer
private Player getPlayer(int userId) => getInstance(userId).ChildrenOfType<Player>().Single();
private PlayerArea getInstance(int userId) => spectatorScreen.ChildrenOfType<PlayerArea>().Single(p => p.UserId == userId);
protected override RoomTestDependencies CreateRoomDependencies() => new TestDependencies();
protected class TestDependencies : MultiplayerRoomTestDependencies
{
public readonly TestSpectatorClient SpectatorClient = new TestSpectatorClient();
public TestDependencies()
{
CacheAs<SpectatorClient>(SpectatorClient);
}
}
}
}

View File

@ -27,9 +27,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
private static IEnumerable<int> users => Enumerable.Range(0, 16);
public TestMultiplayerSpectatorClient SpectatorClient => RoomDependencies?.SpectatorClient;
protected new TestDependencies RoomDependencies => (TestDependencies)base.RoomDependencies;
public new TestMultiplayerSpectatorClient SpectatorClient => (TestMultiplayerSpectatorClient)RoomDependencies?.SpectatorClient;
private MultiplayerGameplayLeaderboard leaderboard;
private OsuConfigManager config;
@ -104,12 +102,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
protected class TestDependencies : MultiplayerRoomTestDependencies
{
public readonly TestMultiplayerSpectatorClient SpectatorClient = new TestMultiplayerSpectatorClient();
public TestDependencies()
{
CacheAs<SpectatorClient>(SpectatorClient);
}
protected override TestSpectatorClient CreateSpectatorClient() => new TestMultiplayerSpectatorClient();
}
public class TestMultiplayerSpectatorClient : TestSpectatorClient

View File

@ -148,6 +148,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
public TestDependencies()
{
// Need to set these values as early as possible.
RoomManager.TimeBetweenListingPolls.Value = 1;
RoomManager.TimeBetweenSelectionPolls.Value = 1;
}

View File

@ -5,6 +5,7 @@ using osu.Game.Database;
using osu.Game.Online.Multiplayer;
using osu.Game.Screens.OnlinePlay;
using osu.Game.Tests.Visual.OnlinePlay;
using osu.Game.Tests.Visual.Spectator;
namespace osu.Game.Tests.Visual.Multiplayer
{
@ -24,5 +25,10 @@ namespace osu.Game.Tests.Visual.Multiplayer
/// The cached <see cref="UserLookupCache"/>.
/// </summary>
TestUserLookupCache LookupCache { get; }
/// <summary>
/// The cached <see cref="osu.Game.Online.Spectator.SpectatorClient"/>.
/// </summary>
TestSpectatorClient SpectatorClient { get; }
}
}

View File

@ -3,8 +3,10 @@
using osu.Game.Database;
using osu.Game.Online.Multiplayer;
using osu.Game.Online.Spectator;
using osu.Game.Screens.OnlinePlay;
using osu.Game.Tests.Visual.OnlinePlay;
using osu.Game.Tests.Visual.Spectator;
namespace osu.Game.Tests.Visual.Multiplayer
{
@ -12,17 +14,23 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
public TestMultiplayerClient Client { get; }
public TestUserLookupCache LookupCache { get; }
public TestSpectatorClient SpectatorClient { get; }
public new TestMultiplayerRoomManager RoomManager => (TestMultiplayerRoomManager)base.RoomManager;
public MultiplayerRoomTestDependencies()
{
Client = new TestMultiplayerClient(RoomManager);
LookupCache = new TestUserLookupCache();
SpectatorClient = CreateSpectatorClient();
CacheAs<MultiplayerClient>(Client);
CacheAs<UserLookupCache>(LookupCache);
CacheAs<SpectatorClient>(SpectatorClient);
}
protected override IRoomManager CreateRoomManager() => new TestMultiplayerRoomManager();
protected virtual TestSpectatorClient CreateSpectatorClient() => new TestSpectatorClient();
}
}

View File

@ -5,6 +5,7 @@ using NUnit.Framework;
using osu.Game.Online.Rooms;
using osu.Game.Tests.Beatmaps;
using osu.Game.Tests.Visual.OnlinePlay;
using osu.Game.Tests.Visual.Spectator;
namespace osu.Game.Tests.Visual.Multiplayer
{
@ -16,6 +17,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
public TestMultiplayerClient Client => RoomDependencies.Client;
public new TestMultiplayerRoomManager RoomManager => RoomDependencies.RoomManager;
public TestUserLookupCache LookupCache => RoomDependencies?.LookupCache;
public TestSpectatorClient SpectatorClient => RoomDependencies?.SpectatorClient;
protected new MultiplayerRoomTestDependencies RoomDependencies => (MultiplayerRoomTestDependencies)base.RoomDependencies;