mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 10:03:05 +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>
|
/// <param name="item">The item to add.</param>
|
||||||
Task AddPlaylistItem(MultiplayerPlaylistItem item);
|
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>
|
/// <summary>
|
||||||
/// Removes an item from the playlist.
|
/// Removes an item from the playlist.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -335,6 +335,8 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
|
|
||||||
public abstract Task AddPlaylistItem(MultiplayerPlaylistItem item);
|
public abstract Task AddPlaylistItem(MultiplayerPlaylistItem item);
|
||||||
|
|
||||||
|
public abstract Task EditPlaylistItem(MultiplayerPlaylistItem item);
|
||||||
|
|
||||||
public abstract Task RemovePlaylistItem(long playlistItemId);
|
public abstract Task RemovePlaylistItem(long playlistItemId);
|
||||||
|
|
||||||
Task IMultiplayerClient.RoomStateChanged(MultiplayerRoomState state)
|
Task IMultiplayerClient.RoomStateChanged(MultiplayerRoomState state)
|
||||||
|
@ -162,6 +162,14 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
return connection.InvokeAsync(nameof(IMultiplayerServer.AddPlaylistItem), item);
|
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)
|
public override Task RemovePlaylistItem(long playlistItemId)
|
||||||
{
|
{
|
||||||
if (!IsConnected.Value)
|
if (!IsConnected.Value)
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
@ -64,7 +65,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
{
|
{
|
||||||
loadingLayer.Show();
|
loadingLayer.Show();
|
||||||
|
|
||||||
client.AddPlaylistItem(new MultiplayerPlaylistItem
|
var multiplayerItem = new MultiplayerPlaylistItem
|
||||||
{
|
{
|
||||||
ID = itemToEdit?.ID ?? 0,
|
ID = itemToEdit?.ID ?? 0,
|
||||||
BeatmapID = item.BeatmapID,
|
BeatmapID = item.BeatmapID,
|
||||||
@ -72,7 +73,11 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
RulesetID = item.RulesetID,
|
RulesetID = item.RulesetID,
|
||||||
RequiredMods = item.RequiredMods.Select(m => new APIMod(m)).ToArray(),
|
RequiredMods = item.RequiredMods.Select(m => new APIMod(m)).ToArray(),
|
||||||
AllowedMods = item.AllowedMods.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(() =>
|
Schedule(() =>
|
||||||
{
|
{
|
||||||
|
@ -309,20 +309,25 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
Debug.Assert(APIRoom != null);
|
Debug.Assert(APIRoom != null);
|
||||||
Debug.Assert(currentItem != null);
|
Debug.Assert(currentItem != null);
|
||||||
|
|
||||||
bool isNewAddition = item.ID == 0;
|
|
||||||
|
|
||||||
if (Room.Settings.QueueMode == QueueMode.HostOnly && Room.Host?.UserID != LocalUser?.UserID)
|
if (Room.Settings.QueueMode == QueueMode.HostOnly && Room.Host?.UserID != LocalUser?.UserID)
|
||||||
throw new InvalidOperationException("Local user is not the room host.");
|
throw new InvalidOperationException("Local user is not the room host.");
|
||||||
|
|
||||||
item.OwnerID = userId;
|
item.OwnerID = userId;
|
||||||
|
|
||||||
if (isNewAddition)
|
|
||||||
{
|
|
||||||
await addItem(item).ConfigureAwait(false);
|
await addItem(item).ConfigureAwait(false);
|
||||||
await updateCurrentItem(Room).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);
|
var existingItem = serverSidePlaylist.SingleOrDefault(i => i.ID == item.ID);
|
||||||
|
|
||||||
if (existingItem == null)
|
if (existingItem == null)
|
||||||
@ -338,20 +343,17 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
item.PlaylistOrder = existingItem.PlaylistOrder;
|
item.PlaylistOrder = existingItem.PlaylistOrder;
|
||||||
|
|
||||||
serverSidePlaylist[serverSidePlaylist.IndexOf(existingItem)] = item;
|
serverSidePlaylist[serverSidePlaylist.IndexOf(existingItem)] = item;
|
||||||
|
|
||||||
await ((IMultiplayerClient)this).PlaylistItemChanged(item).ConfigureAwait(false);
|
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)
|
public async Task RemoveUserPlaylistItem(int userId, long playlistItemId)
|
||||||
{
|
{
|
||||||
Debug.Assert(Room != null);
|
Debug.Assert(Room != null);
|
||||||
Debug.Assert(APIRoom != 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);
|
var item = serverSidePlaylist.Find(i => i.ID == playlistItemId);
|
||||||
|
|
||||||
if (item == null)
|
if (item == null)
|
||||||
|
Loading…
Reference in New Issue
Block a user