1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 15:47:26 +08:00

Fix unable to copy playlist rooms without first opening

This commit is contained in:
Dan Balasescu 2022-03-09 15:38:00 +09:00
parent affcf5180b
commit b07a1e8d09
3 changed files with 41 additions and 19 deletions

View File

@ -10,12 +10,11 @@ using osu.Game.IO.Serialization.Converters;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Multiplayer;
using osu.Game.Online.Rooms.RoomStatuses;
using osu.Game.Utils;
namespace osu.Game.Online.Rooms
{
[JsonObject(MemberSerialization.OptIn)]
public class Room : IDeepCloneable<Room>
public class Room
{
[Cached]
[JsonProperty("id")]
@ -153,22 +152,6 @@ namespace osu.Game.Online.Rooms
Password.BindValueChanged(p => HasPassword.Value = !string.IsNullOrEmpty(p.NewValue));
}
/// <summary>
/// Create a copy of this room without online information.
/// Should be used to create a local copy of a room for submitting in the future.
/// </summary>
public Room DeepClone()
{
var copy = new Room();
copy.CopyFrom(this);
// ID must be unset as we use this as a marker for whether this is a client-side (not-yet-created) room or not.
copy.RoomID.Value = null;
return copy;
}
public void CopyFrom(Room other)
{
RoomID.Value = other.RoomID.Value;

View File

@ -128,7 +128,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
{
new OsuMenuItem("Create copy", MenuItemType.Standard, () =>
{
lounge?.Open(Room.DeepClone());
lounge?.OpenCopy(Room);
})
};

View File

@ -20,6 +20,7 @@ using osu.Framework.Threading;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Input;
using osu.Game.Online.API;
using osu.Game.Online.Rooms;
using osu.Game.Overlays;
using osu.Game.Rulesets;
@ -63,6 +64,9 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
[Resolved]
private IBindable<RulesetInfo> ruleset { get; set; }
[Resolved]
private IAPIProvider api { get; set; }
[CanBeNull]
private IDisposable joiningRoomOperation { get; set; }
@ -310,6 +314,41 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
});
});
/// <summary>
/// Copies a room and opens it as a fresh (not-yet-created) one.
/// </summary>
/// <param name="room">The room to copy.</param>
public void OpenCopy(Room room)
{
Debug.Assert(room.RoomID.Value != null);
if (joiningRoomOperation != null)
return;
joiningRoomOperation = ongoingOperationTracker?.BeginOperation();
var req = new GetRoomRequest(room.RoomID.Value.Value);
req.Success += r =>
{
// ID must be unset as we use this as a marker for whether this is a client-side (not-yet-created) room or not.
r.RoomID.Value = null;
Open(r);
joiningRoomOperation?.Dispose();
joiningRoomOperation = null;
};
req.Failure += _ =>
{
joiningRoomOperation?.Dispose();
joiningRoomOperation = null;
};
api.Queue(req);
}
/// <summary>
/// Push a room as a new subscreen.
/// </summary>