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

Rename class, add commenting and avoid firing requests to create rooms for testing purposes

This commit is contained in:
Dean Herbert 2021-07-26 15:47:13 +09:00
parent 488dd3ea52
commit 888954747c
7 changed files with 36 additions and 21 deletions

View File

@ -140,7 +140,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{ {
AddStep("create room", () => AddStep("create room", () =>
{ {
API.Queue(new CreateRoomRequest(new Room multiplayerScreen.RoomManager.AddRoom(new Room
{ {
Name = { Value = "Test Room" }, Name = { Value = "Test Room" },
Playlist = Playlist =
@ -151,7 +151,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
Ruleset = { Value = new OsuRuleset().RulesetInfo }, Ruleset = { Value = new OsuRuleset().RulesetInfo },
} }
} }
})); });
}); });
AddStep("refresh rooms", () => multiplayerScreen.RoomManager.Filter.Value = new FilterCriteria()); AddStep("refresh rooms", () => multiplayerScreen.RoomManager.Filter.Value = new FilterCriteria());
@ -187,7 +187,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{ {
AddStep("create room", () => AddStep("create room", () =>
{ {
API.Queue(new CreateRoomRequest(new Room multiplayerScreen.RoomManager.AddRoom(new Room
{ {
Name = { Value = "Test Room" }, Name = { Value = "Test Room" },
Password = { Value = "password" }, Password = { Value = "password" },
@ -199,7 +199,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
Ruleset = { Value = new OsuRuleset().RulesetInfo }, Ruleset = { Value = new OsuRuleset().RulesetInfo },
} }
} }
})); });
}); });
AddStep("refresh rooms", () => multiplayerScreen.RoomManager.Filter.Value = new FilterCriteria()); AddStep("refresh rooms", () => multiplayerScreen.RoomManager.Filter.Value = new FilterCriteria());
@ -433,9 +433,9 @@ namespace osu.Game.Tests.Visual.Multiplayer
private class TestMultiplayer : Screens.OnlinePlay.Multiplayer.Multiplayer private class TestMultiplayer : Screens.OnlinePlay.Multiplayer.Multiplayer
{ {
public new TestMultiplayerRoomManager RoomManager { get; private set; } public new TestRequestHandlingMultiplayerRoomManager RoomManager { get; private set; }
protected override RoomManager CreateRoomManager() => RoomManager = new TestMultiplayerRoomManager(); protected override RoomManager CreateRoomManager() => RoomManager = new TestRequestHandlingMultiplayerRoomManager();
} }
} }
} }

View File

@ -353,10 +353,10 @@ namespace osu.Game.Tests.Visual.Navigation
public TestMultiplayer() public TestMultiplayer()
{ {
Client = new TestMultiplayerClient((TestMultiplayerRoomManager)RoomManager); Client = new TestMultiplayerClient((TestRequestHandlingMultiplayerRoomManager)RoomManager);
} }
protected override RoomManager CreateRoomManager() => new TestMultiplayerRoomManager(); protected override RoomManager CreateRoomManager() => new TestRequestHandlingMultiplayerRoomManager();
} }
} }
} }

View File

@ -22,7 +22,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
/// <summary> /// <summary>
/// The cached <see cref="IRoomManager"/>. /// The cached <see cref="IRoomManager"/>.
/// </summary> /// </summary>
new TestMultiplayerRoomManager RoomManager { get; } new TestRequestHandlingMultiplayerRoomManager RoomManager { get; }
/// <summary> /// <summary>
/// The cached <see cref="UserLookupCache"/>. /// The cached <see cref="UserLookupCache"/>.

View File

@ -18,7 +18,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
public const int PLAYER_2_ID = 56; public const int PLAYER_2_ID = 56;
public TestMultiplayerClient Client => OnlinePlayDependencies.Client; public TestMultiplayerClient Client => OnlinePlayDependencies.Client;
public new TestMultiplayerRoomManager RoomManager => OnlinePlayDependencies.RoomManager; public new TestRequestHandlingMultiplayerRoomManager RoomManager => OnlinePlayDependencies.RoomManager;
public TestUserLookupCache LookupCache => OnlinePlayDependencies?.LookupCache; public TestUserLookupCache LookupCache => OnlinePlayDependencies?.LookupCache;
public TestSpectatorClient SpectatorClient => OnlinePlayDependencies?.SpectatorClient; public TestSpectatorClient SpectatorClient => OnlinePlayDependencies?.SpectatorClient;

View File

@ -18,7 +18,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
public TestMultiplayerClient Client { get; } public TestMultiplayerClient Client { get; }
public TestUserLookupCache LookupCache { get; } public TestUserLookupCache LookupCache { get; }
public TestSpectatorClient SpectatorClient { get; } public TestSpectatorClient SpectatorClient { get; }
public new TestMultiplayerRoomManager RoomManager => (TestMultiplayerRoomManager)base.RoomManager; public new TestRequestHandlingMultiplayerRoomManager RoomManager => (TestRequestHandlingMultiplayerRoomManager)base.RoomManager;
public MultiplayerTestSceneDependencies() public MultiplayerTestSceneDependencies()
{ {
@ -31,7 +31,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
CacheAs<SpectatorClient>(SpectatorClient); CacheAs<SpectatorClient>(SpectatorClient);
} }
protected override IRoomManager CreateRoomManager() => new TestMultiplayerRoomManager(); protected override IRoomManager CreateRoomManager() => new TestRequestHandlingMultiplayerRoomManager();
protected virtual TestSpectatorClient CreateSpectatorClient() => new TestSpectatorClient(); protected virtual TestSpectatorClient CreateSpectatorClient() => new TestSpectatorClient();
} }

View File

@ -38,9 +38,9 @@ namespace osu.Game.Tests.Visual.Multiplayer
[Resolved] [Resolved]
private BeatmapManager beatmaps { get; set; } = null!; private BeatmapManager beatmaps { get; set; } = null!;
private readonly TestMultiplayerRoomManager roomManager; private readonly TestRequestHandlingMultiplayerRoomManager roomManager;
public TestMultiplayerClient(TestMultiplayerRoomManager roomManager) public TestMultiplayerClient(TestRequestHandlingMultiplayerRoomManager roomManager)
{ {
this.roomManager = roomManager; this.roomManager = roomManager;
} }

View File

@ -20,7 +20,11 @@ namespace osu.Game.Tests.Visual.Multiplayer
/// <summary> /// <summary>
/// A <see cref="RoomManager"/> for use in multiplayer test scenes. Should generally not be used by itself outside of a <see cref="MultiplayerTestScene"/>. /// A <see cref="RoomManager"/> for use in multiplayer test scenes. Should generally not be used by itself outside of a <see cref="MultiplayerTestScene"/>.
/// </summary> /// </summary>
public class TestMultiplayerRoomManager : MultiplayerRoomManager /// <remarks>
/// This implementation will pretend to be a server, handling room retrieval and manipulation requests
/// and returning a roughly expected state, without the need for a server to be running.
/// </remarks>
public class TestRequestHandlingMultiplayerRoomManager : MultiplayerRoomManager
{ {
[Resolved] [Resolved]
private IAPIProvider api { get; set; } private IAPIProvider api { get; set; }
@ -33,13 +37,16 @@ namespace osu.Game.Tests.Visual.Multiplayer
public new readonly List<Room> Rooms = new List<Room>(); public new readonly List<Room> Rooms = new List<Room>();
private int currentRoomId;
private int currentPlaylistItemId;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
int currentScoreId = 0; int currentScoreId = 0;
int currentRoomId = 0;
int currentPlaylistItemId = 0;
// Handling here is pretending to be a server, while also updating the local state to match
// how the server would eventually respond and update the RoomManager.
((DummyAPIAccess)api).HandleRequest = req => ((DummyAPIAccess)api).HandleRequest = req =>
{ {
switch (req) switch (req)
@ -48,19 +55,16 @@ namespace osu.Game.Tests.Visual.Multiplayer
var apiRoom = new Room(); var apiRoom = new Room();
apiRoom.CopyFrom(createRoomRequest.Room); apiRoom.CopyFrom(createRoomRequest.Room);
apiRoom.RoomID.Value ??= currentRoomId++;
// Passwords are explicitly not copied between rooms. // Passwords are explicitly not copied between rooms.
apiRoom.HasPassword.Value = !string.IsNullOrEmpty(createRoomRequest.Room.Password.Value); apiRoom.HasPassword.Value = !string.IsNullOrEmpty(createRoomRequest.Room.Password.Value);
apiRoom.Password.Value = createRoomRequest.Room.Password.Value; apiRoom.Password.Value = createRoomRequest.Room.Password.Value;
for (int i = 0; i < apiRoom.Playlist.Count; i++) AddRoom(apiRoom);
apiRoom.Playlist[i].ID = currentPlaylistItemId++;
var responseRoom = new APICreatedRoom(); var responseRoom = new APICreatedRoom();
responseRoom.CopyFrom(createResponseRoom(apiRoom, false)); responseRoom.CopyFrom(createResponseRoom(apiRoom, false));
Rooms.Add(apiRoom);
createRoomRequest.TriggerSuccess(responseRoom); createRoomRequest.TriggerSuccess(responseRoom);
return true; return true;
@ -128,6 +132,17 @@ namespace osu.Game.Tests.Visual.Multiplayer
}; };
} }
public void AddRoom(Room room)
{
room.RoomID.Value ??= currentRoomId++;
for (int i = 0; i < room.Playlist.Count; i++)
room.Playlist[i].ID = currentPlaylistItemId++;
Rooms.Add(room);
}
public new void RemoveRoom(Room room) => base.RemoveRoom(room);
private Room createResponseRoom(Room room, bool withParticipants) private Room createResponseRoom(Room room, bool withParticipants)
{ {
var responseRoom = new Room(); var responseRoom = new Room();