1
0
mirror of https://github.com/ppy/osu.git synced 2026-05-23 17:00:40 +08:00

Various refactorings and cleanups

This commit is contained in:
Dan Balasescu
2025-01-25 19:27:21 +09:00
Unverified
parent e9d6411e61
commit ab4162e2aa
12 changed files with 34 additions and 55 deletions
@@ -40,7 +40,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
[Test]
public void TestJoinRoomWithoutPassword()
{
addRoom(false);
AddStep("add room", () => RoomManager.AddRooms(1, withPassword: false));
AddStep("select room", () => InputManager.Key(Key.Down));
AddStep("join room", () => InputManager.Key(Key.Enter));
@@ -50,7 +50,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
[Test]
public void TestPopoverHidesOnBackButton()
{
addRoom(true);
AddStep("add room", () => RoomManager.AddRooms(1, withPassword: true));
AddStep("select room", () => InputManager.Key(Key.Down));
AddStep("attempt join room", () => InputManager.Key(Key.Enter));
@@ -70,7 +70,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
[Test]
public void TestPopoverHidesOnLeavingScreen()
{
addRoom(true);
AddStep("add room", () => RoomManager.AddRooms(1, withPassword: true));
AddStep("select room", () => InputManager.Key(Key.Down));
AddStep("attempt join room", () => InputManager.Key(Key.Enter));
@@ -86,7 +86,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
DrawableLoungeRoom.PasswordEntryPopover? passwordEntryPopover = null;
addRoom(true);
AddStep("add room", () => RoomManager.AddRooms(1, withPassword: true));
AddStep("select room", () => InputManager.Key(Key.Down));
AddStep("attempt join room", () => InputManager.Key(Key.Enter));
AddUntilStep("password prompt appeared", () => (passwordEntryPopover = InputManager.ChildrenOfType<DrawableLoungeRoom.PasswordEntryPopover>().FirstOrDefault()) != null);
@@ -105,7 +105,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
DrawableLoungeRoom.PasswordEntryPopover? passwordEntryPopover = null;
addRoom(true);
AddStep("add room", () => RoomManager.AddRooms(1, withPassword: true));
AddStep("select room", () => InputManager.Key(Key.Down));
AddStep("attempt join room", () => InputManager.Key(Key.Enter));
AddUntilStep("password prompt appeared", () => (passwordEntryPopover = InputManager.ChildrenOfType<DrawableLoungeRoom.PasswordEntryPopover>().FirstOrDefault()) != null);
@@ -124,7 +124,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
DrawableLoungeRoom.PasswordEntryPopover? passwordEntryPopover = null;
addRoom(true);
AddStep("add room", () => RoomManager.AddRooms(1, withPassword: true));
AddStep("select room", () => InputManager.Key(Key.Down));
AddStep("attempt join room", () => InputManager.Key(Key.Enter));
AddUntilStep("password prompt appeared", () => (passwordEntryPopover = InputManager.ChildrenOfType<DrawableLoungeRoom.PasswordEntryPopover>().FirstOrDefault()) != null);
@@ -139,7 +139,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
DrawableLoungeRoom.PasswordEntryPopover? passwordEntryPopover = null;
addRoom(true);
AddStep("add room", () => RoomManager.AddRooms(1, withPassword: true));
AddStep("select room", () => InputManager.Key(Key.Down));
AddStep("attempt join room", () => InputManager.Key(Key.Enter));
AddUntilStep("password prompt appeared", () => (passwordEntryPopover = InputManager.ChildrenOfType<DrawableLoungeRoom.PasswordEntryPopover>().FirstOrDefault()) != null);
@@ -149,20 +149,6 @@ namespace osu.Game.Tests.Visual.Multiplayer
AddAssert("room joined", () => MultiplayerClient.RoomJoined);
}
private void addRoom(bool withPassword)
{
int initialRoomCount = 0;
AddStep("add room", () =>
{
initialRoomCount = roomsContainer.Rooms.Count;
RoomManager.AddRooms(1, withPassword: withPassword);
loungeScreen.RefreshRooms();
});
AddUntilStep("wait for room to appear", () => roomsContainer.Rooms.Count == initialRoomCount + 1);
}
protected override OnlinePlayTestSceneDependencies CreateOnlinePlayDependencies() => new MultiplayerTestSceneDependencies();
}
}
@@ -35,12 +35,7 @@ namespace osu.Game.Tests.Visual.Playlists
[Test]
public void TestManyRooms()
{
AddStep("add rooms", () =>
{
RoomManager.AddRooms(500);
loungeScreen.RefreshRooms();
});
AddStep("add rooms", () => RoomManager.AddRooms(500));
AddUntilStep("wait for rooms", () => roomsContainer.Rooms.Count == 500);
}
@@ -49,12 +44,7 @@ namespace osu.Game.Tests.Visual.Playlists
{
AddStep("reset mouse", () => InputManager.ReleaseButton(MouseButton.Left));
AddStep("add rooms", () =>
{
RoomManager.AddRooms(30);
loungeScreen.RefreshRooms();
});
AddStep("add rooms", () => RoomManager.AddRooms(30));
AddUntilStep("wait for rooms", () => roomsContainer.Rooms.Count == 30);
AddUntilStep("first room is not masked", () => checkRoomVisible(roomsContainer.Rooms[0]));
@@ -71,12 +61,7 @@ namespace osu.Game.Tests.Visual.Playlists
[Test]
public void TestScrollSelectedIntoView()
{
AddStep("add rooms", () =>
{
RoomManager.AddRooms(30);
loungeScreen.RefreshRooms();
});
AddStep("add rooms", () => RoomManager.AddRooms(30));
AddUntilStep("wait for rooms", () => roomsContainer.Rooms.Count == 30);
AddUntilStep("first room is not masked", () => checkRoomVisible(roomsContainer.Rooms[0]));
@@ -90,12 +75,7 @@ namespace osu.Game.Tests.Visual.Playlists
[Test]
public void TestEnteringRoomTakesLeaseOnSelection()
{
AddStep("add rooms", () =>
{
RoomManager.AddRooms(1);
loungeScreen.RefreshRooms();
});
AddStep("add rooms", () => RoomManager.AddRooms(1));
AddUntilStep("wait for rooms", () => roomsContainer.Rooms.Count == 1);
AddAssert("selected room is not disabled", () => !loungeScreen.SelectedRoom.Disabled);
@@ -10,6 +10,11 @@ namespace osu.Game.Online.Multiplayer
/// </summary>
public interface IMultiplayerLoungeServer
{
/// <summary>
/// Request to create a multiplayer room.
/// </summary>
/// <param name="room">The room to create.</param>
/// <returns>The created multiplayer room.</returns>
Task<MultiplayerRoom> CreateRoom(MultiplayerRoom room);
/// <summary>
@@ -168,7 +168,7 @@ namespace osu.Game.Online.Multiplayer
public async Task CreateRoom(Room room)
{
if (Room != null)
throw new InvalidOperationException("Cannot join a multiplayer room while already in one.");
throw new InvalidOperationException("Cannot create a multiplayer room while already in one.");
var cancellationSource = joinCancellationSource = new CancellationTokenSource();
await initRoom(room, r => CreateRoomInternal(new MultiplayerRoom(room)), cancellationSource.Token).ConfigureAwait(false);
@@ -212,6 +212,7 @@ namespace osu.Game.Online.Multiplayer
APIRoom.RoomID = joinedRoom.RoomID;
APIRoom.Playlist = joinedRoom.Playlist.Select(item => new PlaylistItem(item)).ToArray();
APIRoom.CurrentPlaylistItem = APIRoom.Playlist.Single(item => item.ID == joinedRoom.Settings.PlaylistItemId);
// The server will null out the end date upon the host joining the room, but the null value is never communicated to the client.
APIRoom.EndDate = null;
Debug.Assert(LocalUser != null);
@@ -15,6 +15,8 @@ namespace osu.Game.Online.Rooms
public CreateRoomRequest(Room room)
{
Room = room;
// Also copy back to the source model, since it is likely to have been stored elsewhere.
Success += r => Room.CopyFrom(r);
}
+2
View File
@@ -16,6 +16,8 @@ namespace osu.Game.Online.Rooms
{
Room = room;
Password = password;
// Also copy back to the source model, since it is likely to have been stored elsewhere.
Success += r => Room.CopyFrom(r);
}
@@ -162,7 +162,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
{
new OsuMenuItem("Create copy", MenuItemType.Standard, () =>
{
lounge?.Clone(Room);
lounge?.OpenCopy(Room);
})
};
@@ -18,10 +18,10 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
void Join(Room room, string? password, Action<Room>? onSuccess = null, Action<string>? onFailure = null);
/// <summary>
/// Clones the given room and opens it as a fresh (not-yet-created) one.
/// Copies the given room and opens it as a fresh (not-yet-created) one.
/// </summary>
/// <param name="room">The room to clone.</param>
void Clone(Room room);
/// <param name="room">The room to copy.</param>
void OpenCopy(Room room);
/// <summary>
/// Closes the given room.
@@ -309,7 +309,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
joiningRoomOperation = ongoingOperationTracker?.BeginOperation();
TryJoin(room, password, r =>
JoinInternal(room, password, r =>
{
Open(room);
joiningRoomOperation?.Dispose();
@@ -323,9 +323,9 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
});
});
protected abstract void TryJoin(Room room, string? password, Action<Room> onSuccess, Action<string> onFailure);
protected abstract void JoinInternal(Room room, string? password, Action<Room> onSuccess, Action<string> onFailure);
public void Clone(Room room)
public void OpenCopy(Room room)
{
Debug.Assert(room.RoomID != null);
@@ -353,6 +353,9 @@ namespace osu.Game.Screens.OnlinePlay.Match
return base.OnExiting(e);
}
/// <summary>
/// Parts from the current room.
/// </summary>
protected abstract void PartRoom();
private bool ensureExitConfirmed()
@@ -81,7 +81,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
protected override ListingPollingComponent CreatePollingComponent() => new MultiplayerListingPollingComponent();
protected override void TryJoin(Room room, string? password, Action<Room> onSuccess, Action<string> onFailure)
protected override void JoinInternal(Room room, string? password, Action<Room> onSuccess, Action<string> onFailure)
{
client.JoinRoom(room, password).ContinueWith(result =>
{
@@ -60,7 +60,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
return criteria;
}
protected override void TryJoin(Room room, string? password, Action<Room> onSuccess, Action<string> onFailure)
protected override void JoinInternal(Room room, string? password, Action<Room> onSuccess, Action<string> onFailure)
{
var joinRoomRequest = new JoinRoomRequest(room, password);