Update behaviour to match server (removing playlist items) + tests

This commit is contained in:
Dan Balasescu 2021-11-11 23:39:15 +09:00
parent 07a7b4bcdc
commit 5c8c121446
2 changed files with 29 additions and 26 deletions

View File

@ -73,9 +73,9 @@ namespace osu.Game.Tests.Visual.Multiplayer.QueueingModes
RunGameplay();
AddStep("change queue mode", () => Client.ChangeSettings(queueMode: QueueModes.HostOnly));
AddAssert("playlist has 1 item", () => Client.APIRoom?.Playlist.Count == 1);
AddAssert("playlist item is the same as last selected", () => Client.APIRoom?.Playlist[0].Beatmap.Value.OnlineID == OtherBeatmap.OnlineID);
AddAssert("playlist item is not expired", () => Client.APIRoom?.Playlist[0].Expired == false);
AddAssert("playlist has 2 items", () => Client.APIRoom?.Playlist.Count == 2);
AddAssert("playlist item is the other beatmap", () => Client.CurrentMatchPlayingItem.Value?.BeatmapID == OtherBeatmap.OnlineID);
AddAssert("playlist item is not expired", () => Client.APIRoom?.Playlist[1].Expired == false);
}
private void addItem(Func<BeatmapInfo> beatmap)

View File

@ -209,29 +209,10 @@ namespace osu.Game.Tests.Visual.Multiplayer
Debug.Assert(Room != null);
Debug.Assert(APIRoom != null);
switch (Room.Settings.QueueMode, settings.QueueMode)
{
case (QueueModes.HostOnly, QueueModes.HostOnly):
break;
// Server is authoritative for the time being.
settings.PlaylistItemId = Room.Settings.PlaylistItemId;
// Host-only is incompatible with other queueing modes, so expire all non-expired items.
case (QueueModes.HostOnly, _):
case (_, QueueModes.HostOnly):
foreach (var playlistItem in APIRoom.Playlist.Where(i => !i.Expired).ToArray())
{
playlistItem.Expired = true;
await ((IMultiplayerClient)this).PlaylistItemChanged(new APIPlaylistItem(playlistItem)).ConfigureAwait(false);
}
break;
}
await ((IMultiplayerClient)this).SettingsChanged(settings).ConfigureAwait(false);
foreach (var user in Room.Users.Where(u => u.State == MultiplayerUserState.Ready))
ChangeUserState(user.UserID, MultiplayerUserState.Idle);
await changeMatchType(settings.MatchType).ConfigureAwait(false);
await changeSettings(settings).ConfigureAwait(false);
}
public override Task ChangeState(MultiplayerUserState newState)
@ -344,6 +325,28 @@ namespace osu.Game.Tests.Visual.Multiplayer
return Task.FromResult(apiSet);
}
private async Task changeSettings(MultiplayerRoomSettings settings)
{
Debug.Assert(Room != null);
Debug.Assert(APIRoom != null);
if (settings.QueueMode == QueueModes.HostOnly)
{
foreach (var playlistItem in APIRoom.Playlist.Where(i => !i.Expired && i.ID != Room.Settings.PlaylistItemId).ToArray())
{
APIRoom.Playlist.Remove(playlistItem);
await ((IMultiplayerClient)this).PlaylistItemRemoved(playlistItem.ID).ConfigureAwait(false);
}
}
await ((IMultiplayerClient)this).SettingsChanged(settings).ConfigureAwait(false);
foreach (var user in Room.Users.Where(u => u.State == MultiplayerUserState.Ready))
ChangeUserState(user.UserID, MultiplayerUserState.Idle);
await changeMatchType(settings.MatchType).ConfigureAwait(false);
}
private async Task changeMatchType(MatchType type)
{
Debug.Assert(Room != null);
@ -417,7 +420,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
if (nextId != Room.Settings.PlaylistItemId)
{
Room.Settings.PlaylistItemId = nextId;
await ChangeSettings(Room.Settings).ConfigureAwait(false);
await changeSettings(Room.Settings).ConfigureAwait(false);
}
}
}