mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 17:07:38 +08:00
Add playlist item change event
This commit is contained in:
parent
4e6a02bde9
commit
ec02e16c81
@ -118,5 +118,11 @@ namespace osu.Game.Online.Multiplayer
|
||||
/// </summary>
|
||||
/// <param name="item">The removed item.</param>
|
||||
Task PlaylistItemRemoved(APIPlaylistItem item);
|
||||
|
||||
/// <summary>
|
||||
/// Signals that an item has been changed in the playlist.
|
||||
/// </summary>
|
||||
/// <param name="item">The changed item.</param>
|
||||
Task PlaylistItemChanged(APIPlaylistItem item);
|
||||
}
|
||||
}
|
||||
|
@ -577,12 +577,7 @@ namespace osu.Game.Online.Multiplayer
|
||||
if (Room == null)
|
||||
return;
|
||||
|
||||
var set = await GetOnlineBeatmapSet(item.BeatmapID).ConfigureAwait(false);
|
||||
|
||||
var beatmap = set.Beatmaps.Single(b => b.OnlineBeatmapID == item.BeatmapID);
|
||||
beatmap.MD5Hash = item.BeatmapChecksum;
|
||||
|
||||
var ruleset = Rulesets.GetRuleset(item.RulesetID);
|
||||
var playlistItem = await createPlaylistItem(item).ConfigureAwait(false);
|
||||
|
||||
await scheduleAsync(() =>
|
||||
{
|
||||
@ -591,18 +586,6 @@ namespace osu.Game.Online.Multiplayer
|
||||
|
||||
Debug.Assert(APIRoom != null);
|
||||
|
||||
var playlistItem = new PlaylistItem
|
||||
{
|
||||
ID = item.ID,
|
||||
Beatmap = { Value = beatmap },
|
||||
Ruleset = { Value = ruleset },
|
||||
};
|
||||
|
||||
var rulesetInstance = ruleset.CreateInstance();
|
||||
|
||||
playlistItem.RequiredMods.AddRange(item.RequiredMods.Select(m => m.ToMod(rulesetInstance)));
|
||||
playlistItem.AllowedMods.AddRange(item.AllowedMods.Select(m => m.ToMod(rulesetInstance)));
|
||||
|
||||
APIRoom.Playlist.Add(playlistItem);
|
||||
RoomUpdated?.Invoke();
|
||||
}).ConfigureAwait(false);
|
||||
@ -625,6 +608,26 @@ namespace osu.Game.Online.Multiplayer
|
||||
});
|
||||
}
|
||||
|
||||
public async Task PlaylistItemChanged(APIPlaylistItem item)
|
||||
{
|
||||
if (Room == null)
|
||||
return;
|
||||
|
||||
var playlistItem = await createPlaylistItem(item).ConfigureAwait(false);
|
||||
|
||||
await scheduleAsync(() =>
|
||||
{
|
||||
if (Room == null)
|
||||
return;
|
||||
|
||||
Debug.Assert(APIRoom != null);
|
||||
|
||||
int index = APIRoom.Playlist.Where(p => p.ID == item.ID).Select((_, i) => i).Single();
|
||||
APIRoom.Playlist.RemoveAt(index);
|
||||
APIRoom.Playlist.Insert(index, playlistItem);
|
||||
}).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Populates the <see cref="User"/> for a given <see cref="MultiplayerRoomUser"/>.
|
||||
/// </summary>
|
||||
@ -663,6 +666,29 @@ namespace osu.Game.Online.Multiplayer
|
||||
/// <returns>The <see cref="BeatmapSetInfo"/> retrieval task.</returns>
|
||||
protected abstract Task<BeatmapSetInfo> GetOnlineBeatmapSet(int beatmapId, CancellationToken cancellationToken = default);
|
||||
|
||||
private async Task<PlaylistItem> createPlaylistItem(APIPlaylistItem item)
|
||||
{
|
||||
var set = await GetOnlineBeatmapSet(item.BeatmapID).ConfigureAwait(false);
|
||||
|
||||
var beatmap = set.Beatmaps.Single(b => b.OnlineBeatmapID == item.BeatmapID);
|
||||
beatmap.MD5Hash = item.BeatmapChecksum;
|
||||
|
||||
var ruleset = Rulesets.GetRuleset(item.RulesetID);
|
||||
var rulesetInstance = ruleset.CreateInstance();
|
||||
|
||||
var playlistItem = new PlaylistItem
|
||||
{
|
||||
ID = item.ID,
|
||||
Beatmap = { Value = beatmap },
|
||||
Ruleset = { Value = ruleset },
|
||||
};
|
||||
|
||||
playlistItem.RequiredMods.AddRange(item.RequiredMods.Select(m => m.ToMod(rulesetInstance)));
|
||||
playlistItem.AllowedMods.AddRange(item.AllowedMods.Select(m => m.ToMod(rulesetInstance)));
|
||||
|
||||
return playlistItem;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// For the provided user ID, update whether the user is included in <see cref="CurrentMatchPlayingUserIds"/>.
|
||||
/// </summary>
|
||||
|
Loading…
Reference in New Issue
Block a user