mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 13:37:25 +08:00
Change API for retrieving playlist items on join
This commit is contained in:
parent
4aaf412ac9
commit
ce47f456ec
@ -77,6 +77,11 @@ namespace osu.Game.Online.Multiplayer
|
||||
/// <exception cref="InvalidStateException">If an attempt to start the game occurs when the game's (or users') state disallows it.</exception>
|
||||
Task StartMatch();
|
||||
|
||||
/// <summary>
|
||||
/// Requests for all playlist items of the room to be sent to the client.
|
||||
/// </summary>
|
||||
Task RequestAllPlaylistItems();
|
||||
|
||||
/// <summary>
|
||||
/// Adds an item to the playlist.
|
||||
/// </summary>
|
||||
|
@ -158,6 +158,8 @@ namespace osu.Game.Online.Multiplayer
|
||||
OnRoomJoined();
|
||||
}, cancellationSource.Token).ConfigureAwait(false);
|
||||
|
||||
await RequestAllPlaylistItems().ConfigureAwait(false);
|
||||
|
||||
// Update room settings.
|
||||
await updateLocalRoomSettings(joinedRoom.Settings, cancellationSource.Token).ConfigureAwait(false);
|
||||
}, cancellationSource.Token).ConfigureAwait(false);
|
||||
@ -305,6 +307,8 @@ namespace osu.Game.Online.Multiplayer
|
||||
|
||||
public abstract Task StartMatch();
|
||||
|
||||
public abstract Task RequestAllPlaylistItems();
|
||||
|
||||
public abstract Task AddPlaylistItem(APIPlaylistItem item);
|
||||
|
||||
public abstract Task RemovePlaylistItem(long playlistItemId);
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@ -151,6 +152,14 @@ namespace osu.Game.Online.Multiplayer
|
||||
return connection.InvokeAsync(nameof(IMultiplayerServer.StartMatch));
|
||||
}
|
||||
|
||||
public override Task RequestAllPlaylistItems()
|
||||
{
|
||||
if (!IsConnected.Value)
|
||||
return Task.FromResult(Array.Empty<APIPlaylistItem>());
|
||||
|
||||
return connection.InvokeAsync<APIPlaylistItem[]>(nameof(IMultiplayerServer.RequestAllPlaylistItems));
|
||||
}
|
||||
|
||||
public override Task AddPlaylistItem(APIPlaylistItem item)
|
||||
{
|
||||
if (!IsConnected.Value)
|
||||
|
@ -199,10 +199,6 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
|
||||
// emulate the server sending this after the join room. scheduler required to make sure the join room event is fired first (in Join).
|
||||
changeMatchType(Room.Settings.MatchType).Wait();
|
||||
|
||||
// emulate the server sending all playlist items after room join.
|
||||
var serverSideRoom = roomManager.ServerSideRooms.Single(r => r.RoomID.Value == APIRoom.RoomID.Value);
|
||||
Task.WhenAll(serverSideRoom.Playlist.Select(i => ((IMultiplayerClient)this).PlaylistItemAdded(new APIPlaylistItem(i)))).Wait();
|
||||
}
|
||||
|
||||
protected override Task LeaveRoomInternal() => Task.CompletedTask;
|
||||
@ -298,6 +294,12 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
return ((IMultiplayerClient)this).LoadRequested();
|
||||
}
|
||||
|
||||
public override async Task RequestAllPlaylistItems()
|
||||
{
|
||||
foreach (var item in playlistItems)
|
||||
await ((IMultiplayerClient)this).PlaylistItemAdded(item).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public override async Task AddPlaylistItem(APIPlaylistItem item)
|
||||
{
|
||||
Debug.Assert(Room != null);
|
||||
|
Loading…
Reference in New Issue
Block a user