mirror of
https://github.com/osukey/osukey.git
synced 2025-08-08 00:53:56 +09:00
Add and use separate extensions for historical and upcoming playlist items
This commit is contained in:
@ -16,9 +16,12 @@ namespace osu.Game.Tests.OnlinePlay
|
|||||||
// mostly an extreme edge case, i.e. during room creation.
|
// mostly an extreme edge case, i.e. during room creation.
|
||||||
var items = Array.Empty<PlaylistItem>();
|
var items = Array.Empty<PlaylistItem>();
|
||||||
|
|
||||||
var currentItem = items.GetCurrentItem();
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
Assert.That(currentItem, Is.Null);
|
Assert.That(items.GetHistoricalItems(), Is.Empty);
|
||||||
|
Assert.That(items.GetCurrentItem(), Is.Null);
|
||||||
|
Assert.That(items.GetUpcomingItems(), Is.Empty);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -31,9 +34,12 @@ namespace osu.Game.Tests.OnlinePlay
|
|||||||
new PlaylistItem { ID = 3, BeatmapID = 1003, PlaylistOrder = 3 },
|
new PlaylistItem { ID = 3, BeatmapID = 1003, PlaylistOrder = 3 },
|
||||||
};
|
};
|
||||||
|
|
||||||
var currentItem = items.GetCurrentItem();
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
Assert.That(currentItem, Is.EqualTo(items[0]));
|
Assert.That(items.GetHistoricalItems(), Is.Empty);
|
||||||
|
Assert.That(items.GetCurrentItem(), Is.EqualTo(items[0]));
|
||||||
|
Assert.That(items.GetUpcomingItems(), Is.EquivalentTo(items));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -46,9 +52,12 @@ namespace osu.Game.Tests.OnlinePlay
|
|||||||
new PlaylistItem { ID = 3, BeatmapID = 1003, PlaylistOrder = 3 },
|
new PlaylistItem { ID = 3, BeatmapID = 1003, PlaylistOrder = 3 },
|
||||||
};
|
};
|
||||||
|
|
||||||
var currentItem = items.GetCurrentItem();
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
Assert.That(currentItem, Is.EqualTo(items[1]));
|
Assert.That(items.GetHistoricalItems(), Is.Empty);
|
||||||
|
Assert.That(items.GetCurrentItem(), Is.EqualTo(items[1]));
|
||||||
|
Assert.That(items.GetUpcomingItems(), Is.EquivalentTo(new[] { items[1], items[0], items[2] }));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -56,14 +65,17 @@ namespace osu.Game.Tests.OnlinePlay
|
|||||||
{
|
{
|
||||||
var items = new[]
|
var items = new[]
|
||||||
{
|
{
|
||||||
new PlaylistItem { ID = 2, BeatmapID = 1002, PlaylistOrder = 2, Expired = true },
|
new PlaylistItem { ID = 1, BeatmapID = 1001, Expired = true, PlayedAt = new DateTimeOffset(2021, 12, 21, 7, 55, 0, TimeSpan.Zero) },
|
||||||
new PlaylistItem { ID = 1, BeatmapID = 1001, PlaylistOrder = 1, Expired = true },
|
new PlaylistItem { ID = 2, BeatmapID = 1002, Expired = true, PlayedAt = new DateTimeOffset(2021, 12, 21, 7, 53, 0, TimeSpan.Zero) },
|
||||||
new PlaylistItem { ID = 3, BeatmapID = 1003, PlaylistOrder = 3 },
|
new PlaylistItem { ID = 3, BeatmapID = 1003, PlaylistOrder = 3 },
|
||||||
};
|
};
|
||||||
|
|
||||||
var currentItem = items.GetCurrentItem();
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
Assert.That(currentItem, Is.EqualTo(items[2]));
|
Assert.That(items.GetHistoricalItems(), Is.EquivalentTo(new[] { items[1], items[0] }));
|
||||||
|
Assert.That(items.GetCurrentItem(), Is.EqualTo(items[2]));
|
||||||
|
Assert.That(items.GetUpcomingItems(), Is.EquivalentTo(new[] { items[2] }));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -71,15 +83,18 @@ namespace osu.Game.Tests.OnlinePlay
|
|||||||
{
|
{
|
||||||
var items = new[]
|
var items = new[]
|
||||||
{
|
{
|
||||||
new PlaylistItem { ID = 2, BeatmapID = 1002, PlaylistOrder = 2, Expired = true },
|
new PlaylistItem { ID = 1, BeatmapID = 1001, Expired = true, PlayedAt = new DateTimeOffset(2021, 12, 21, 7, 55, 0, TimeSpan.Zero) },
|
||||||
new PlaylistItem { ID = 1, BeatmapID = 1001, PlaylistOrder = 1, Expired = true },
|
new PlaylistItem { ID = 2, BeatmapID = 1002, Expired = true, PlayedAt = new DateTimeOffset(2021, 12, 21, 7, 53, 0, TimeSpan.Zero) },
|
||||||
new PlaylistItem { ID = 3, BeatmapID = 1003, PlaylistOrder = 3, Expired = true },
|
new PlaylistItem { ID = 3, BeatmapID = 1002, Expired = true, PlayedAt = new DateTimeOffset(2021, 12, 21, 7, 57, 0, TimeSpan.Zero) },
|
||||||
};
|
};
|
||||||
|
|
||||||
var currentItem = items.GetCurrentItem();
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
// if all items are expired, the last-played item is expected to be returned.
|
Assert.That(items.GetHistoricalItems(), Is.EquivalentTo(new[] { items[1], items[0], items[2] }));
|
||||||
Assert.That(currentItem, Is.EqualTo(items[2]));
|
// if all items are expired, the last-played item is expected to be returned.
|
||||||
|
Assert.That(items.GetCurrentItem(), Is.EqualTo(items[2]));
|
||||||
|
Assert.That(items.GetUpcomingItems(), Is.Empty);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,18 @@ namespace osu.Game.Online.Rooms
|
|||||||
{
|
{
|
||||||
public static class PlaylistExtensions
|
public static class PlaylistExtensions
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Returns all historical/expired items from the <paramref name="playlist"/>, in the order in which they were played.
|
||||||
|
/// </summary>
|
||||||
|
public static IEnumerable<PlaylistItem> GetHistoricalItems(this IEnumerable<PlaylistItem> playlist)
|
||||||
|
=> playlist.Where(item => item.Expired).OrderBy(item => item.PlayedAt);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns all non-expired items from the <paramref name="playlist"/>, in the order in which they are to be played.
|
||||||
|
/// </summary>
|
||||||
|
public static IEnumerable<PlaylistItem> GetUpcomingItems(this IEnumerable<PlaylistItem> playlist)
|
||||||
|
=> playlist.Where(item => !item.Expired).OrderBy(item => item.PlaylistOrder);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the first non-expired <see cref="PlaylistItem"/> in playlist order from the supplied <paramref name="playlist"/>,
|
/// Returns the first non-expired <see cref="PlaylistItem"/> in playlist order from the supplied <paramref name="playlist"/>,
|
||||||
/// or the last-played <see cref="PlaylistItem"/> if all items are expired,
|
/// or the last-played <see cref="PlaylistItem"/> if all items are expired,
|
||||||
@ -24,8 +36,8 @@ namespace osu.Game.Online.Rooms
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
return playlist.All(item => item.Expired)
|
return playlist.All(item => item.Expired)
|
||||||
? playlist.OrderByDescending(item => item.PlaylistOrder).First()
|
? GetHistoricalItems(playlist).Last()
|
||||||
: playlist.OrderBy(item => item.PlaylistOrder).First(item => !item.Expired);
|
: GetUpcomingItems(playlist).First();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetTotalDuration(this BindableList<PlaylistItem> playlist) =>
|
public static string GetTotalDuration(this BindableList<PlaylistItem> playlist) =>
|
||||||
|
Reference in New Issue
Block a user