// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System.Collections.Generic; using System.Linq; using osu.Game.Online.Rooms; namespace osu.Game.Online.Multiplayer { public static class MultiplayerRoomExtensions { /// /// Returns all historical/expired items from the , in the order in which they were played. /// public static IEnumerable GetHistoricalItems(this MultiplayerRoom room) => room.Playlist.Where(item => item.Expired).OrderBy(item => item.PlayedAt); /// /// Returns all non-expired items from the , in the order in which they are to be played. /// public static IEnumerable GetUpcomingItems(this MultiplayerRoom room) => room.Playlist.Where(item => !item.Expired).OrderBy(item => item.PlaylistOrder); /// /// Returns the first non-expired in playlist order from the supplied , /// or the last-played if all items are expired, /// or if was empty. /// public static MultiplayerPlaylistItem? GetCurrentItem(this MultiplayerRoom room) { if (room.Playlist.Count == 0) return null; return room.Playlist.All(item => item.Expired) ? GetHistoricalItems(room).Last() : GetUpcomingItems(room).First(); } } }