mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 11:35:35 +08:00
Add very basic error handling on ChangeSettings calls
This commit is contained in:
parent
2d7174d99c
commit
12876d7fb6
@ -127,10 +127,10 @@ namespace osu.Game.Online.RealtimeMultiplayer
|
||||
/// </remarks>
|
||||
/// <param name="name">The new room name, if any.</param>
|
||||
/// <param name="item">The new room playlist item, if any.</param>
|
||||
public void ChangeSettings(Optional<string> name = default, Optional<PlaylistItem> item = default)
|
||||
public Task ChangeSettings(Optional<string> name = default, Optional<PlaylistItem> item = default)
|
||||
{
|
||||
if (Room == null)
|
||||
return;
|
||||
throw new InvalidOperationException("Must be joined to a match to change settings.");
|
||||
|
||||
// A dummy playlist item filled with the current room settings (except mods).
|
||||
var existingPlaylistItem = new PlaylistItem
|
||||
@ -146,7 +146,7 @@ namespace osu.Game.Online.RealtimeMultiplayer
|
||||
RulesetID = Room.Settings.RulesetID
|
||||
};
|
||||
|
||||
ChangeSettings(new MultiplayerRoomSettings
|
||||
return ChangeSettings(new MultiplayerRoomSettings
|
||||
{
|
||||
Name = name.GetOr(Room.Settings.Name),
|
||||
BeatmapID = item.GetOr(existingPlaylistItem).BeatmapID,
|
||||
|
@ -294,8 +294,13 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer.Match
|
||||
// Otherwise, update the room directly in preparation for it to be submitted to the API on match creation.
|
||||
if (client.Room != null)
|
||||
{
|
||||
client.ChangeSettings(name: NameField.Text);
|
||||
onSuccess(currentRoom.Value);
|
||||
client.ChangeSettings(name: NameField.Text).ContinueWith(t => Schedule(() =>
|
||||
{
|
||||
if (t.IsCompletedSuccessfully)
|
||||
onSuccess(currentRoom.Value);
|
||||
else
|
||||
onError(t.Exception?.Message ?? "Error changing settings.");
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -6,6 +6,7 @@ using Humanizer;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Online.RealtimeMultiplayer;
|
||||
@ -43,14 +44,22 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer
|
||||
// If the client is already in a room, update via the client.
|
||||
// Otherwise, update the playlist directly in preparation for it to be submitted to the API on match creation.
|
||||
if (client.Room != null)
|
||||
client.ChangeSettings(item: item);
|
||||
{
|
||||
client.ChangeSettings(item: item).ContinueWith(t => Schedule(() =>
|
||||
{
|
||||
if (t.IsCompletedSuccessfully)
|
||||
this.Exit();
|
||||
else
|
||||
Logger.Log($"Could not use current beatmap ({t.Exception?.Message})", level: LogLevel.Important);
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
playlist.Clear();
|
||||
playlist.Add(item);
|
||||
this.Exit();
|
||||
}
|
||||
|
||||
this.Exit();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user