mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 15:07:44 +08:00
Separate editing and adding playlist items
This commit is contained in:
parent
88670c3b01
commit
de0f37b08d
@ -83,6 +83,12 @@ namespace osu.Game.Online.Multiplayer
|
||||
/// <param name="item">The item to add.</param>
|
||||
Task AddPlaylistItem(MultiplayerPlaylistItem item);
|
||||
|
||||
/// <summary>
|
||||
/// Edits an existing playlist item with new values.
|
||||
/// </summary>
|
||||
/// <param name="item">The item to edit, containing new properties. Must have an ID.</param>
|
||||
Task EditPlaylistItem(MultiplayerPlaylistItem item);
|
||||
|
||||
/// <summary>
|
||||
/// Removes an item from the playlist.
|
||||
/// </summary>
|
||||
|
@ -335,6 +335,8 @@ namespace osu.Game.Online.Multiplayer
|
||||
|
||||
public abstract Task AddPlaylistItem(MultiplayerPlaylistItem item);
|
||||
|
||||
public abstract Task EditPlaylistItem(MultiplayerPlaylistItem item);
|
||||
|
||||
public abstract Task RemovePlaylistItem(long playlistItemId);
|
||||
|
||||
Task IMultiplayerClient.RoomStateChanged(MultiplayerRoomState state)
|
||||
|
@ -162,6 +162,14 @@ namespace osu.Game.Online.Multiplayer
|
||||
return connection.InvokeAsync(nameof(IMultiplayerServer.AddPlaylistItem), item);
|
||||
}
|
||||
|
||||
public override Task EditPlaylistItem(MultiplayerPlaylistItem item)
|
||||
{
|
||||
if (!IsConnected.Value)
|
||||
return Task.CompletedTask;
|
||||
|
||||
return connection.InvokeAsync(nameof(IMultiplayerServer.EditPlaylistItem), item);
|
||||
}
|
||||
|
||||
public override Task RemovePlaylistItem(long playlistItemId)
|
||||
{
|
||||
if (!IsConnected.Value)
|
||||
|
@ -4,6 +4,7 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Logging;
|
||||
@ -64,7 +65,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
{
|
||||
loadingLayer.Show();
|
||||
|
||||
client.AddPlaylistItem(new MultiplayerPlaylistItem
|
||||
var multiplayerItem = new MultiplayerPlaylistItem
|
||||
{
|
||||
ID = itemToEdit?.ID ?? 0,
|
||||
BeatmapID = item.BeatmapID,
|
||||
@ -72,7 +73,11 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
RulesetID = item.RulesetID,
|
||||
RequiredMods = item.RequiredMods.Select(m => new APIMod(m)).ToArray(),
|
||||
AllowedMods = item.AllowedMods.Select(m => new APIMod(m)).ToArray()
|
||||
}).ContinueWith(t =>
|
||||
};
|
||||
|
||||
Task task = itemToEdit != null ? client.EditPlaylistItem(multiplayerItem) : client.AddPlaylistItem(multiplayerItem);
|
||||
|
||||
task.ContinueWith(t =>
|
||||
{
|
||||
Schedule(() =>
|
||||
{
|
||||
|
@ -309,20 +309,25 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
Debug.Assert(APIRoom != null);
|
||||
Debug.Assert(currentItem != null);
|
||||
|
||||
bool isNewAddition = item.ID == 0;
|
||||
|
||||
if (Room.Settings.QueueMode == QueueMode.HostOnly && Room.Host?.UserID != LocalUser?.UserID)
|
||||
throw new InvalidOperationException("Local user is not the room host.");
|
||||
|
||||
item.OwnerID = userId;
|
||||
|
||||
if (isNewAddition)
|
||||
{
|
||||
await addItem(item).ConfigureAwait(false);
|
||||
await updateCurrentItem(Room).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
|
||||
public override Task AddPlaylistItem(MultiplayerPlaylistItem item) => AddUserPlaylistItem(api.LocalUser.Value.OnlineID, item);
|
||||
|
||||
public async Task EditUserPlaylistItem(int userId, MultiplayerPlaylistItem item)
|
||||
{
|
||||
Debug.Assert(Room != null);
|
||||
Debug.Assert(APIRoom != null);
|
||||
Debug.Assert(currentItem != null);
|
||||
|
||||
item.OwnerID = userId;
|
||||
|
||||
var existingItem = serverSidePlaylist.SingleOrDefault(i => i.ID == item.ID);
|
||||
|
||||
if (existingItem == null)
|
||||
@ -338,20 +343,17 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
item.PlaylistOrder = existingItem.PlaylistOrder;
|
||||
|
||||
serverSidePlaylist[serverSidePlaylist.IndexOf(existingItem)] = item;
|
||||
|
||||
await ((IMultiplayerClient)this).PlaylistItemChanged(item).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
public override Task AddPlaylistItem(MultiplayerPlaylistItem item) => AddUserPlaylistItem(api.LocalUser.Value.OnlineID, item);
|
||||
public override Task EditPlaylistItem(MultiplayerPlaylistItem item) => EditUserPlaylistItem(api.LocalUser.Value.OnlineID, item);
|
||||
|
||||
public async Task RemoveUserPlaylistItem(int userId, long playlistItemId)
|
||||
{
|
||||
Debug.Assert(Room != null);
|
||||
Debug.Assert(APIRoom != null);
|
||||
|
||||
if (Room.Settings.QueueMode == QueueMode.HostOnly)
|
||||
throw new InvalidOperationException("Items cannot be removed in host-only mode.");
|
||||
|
||||
var item = serverSidePlaylist.Find(i => i.ID == playlistItemId);
|
||||
|
||||
if (item == null)
|
||||
|
Loading…
Reference in New Issue
Block a user