From 5a078da4d9f16c510382d1134fb5a982700f5529 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 4 Nov 2021 16:44:05 +0900 Subject: [PATCH] Fix `APIBeatmapSet.Beatmaps` being `IEnumerable`, causing stupid issues --- osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapCard.cs | 4 ++-- .../Beatmaps/TestSceneDifficultySpectrumDisplay.cs | 2 +- .../Visual/Online/TestSceneBeatmapRulesetSelector.cs | 10 +++------- .../Visual/Online/TestSceneBeatmapSetOverlay.cs | 6 +++--- .../Visual/Online/TestSceneBeatmapSetOverlayDetails.cs | 3 +-- osu.Game.Tests/Visual/Online/TestSceneDirectPanel.cs | 4 ++-- .../Online/API/Requests/Responses/APIBeatmapSet.cs | 2 +- .../Overlays/BeatmapListing/Panels/BeatmapPanel.cs | 2 +- .../Tests/Visual/Multiplayer/TestMultiplayerClient.cs | 2 +- 9 files changed, 15 insertions(+), 20 deletions(-) diff --git a/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapCard.cs b/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapCard.cs index d1b21547dc..2aeb4ab4e2 100644 --- a/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapCard.cs +++ b/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapCard.cs @@ -91,7 +91,7 @@ private void load() HasVideo = true, HasStoryboard = true, Covers = new BeatmapSetOnlineCovers(), - Beatmaps = new List + Beatmaps = new[] { new APIBeatmap { @@ -128,7 +128,7 @@ private static APIBeatmapSet getManyDifficultiesBeatmapSet(int count) HasVideo = true, HasStoryboard = true, Covers = new BeatmapSetOnlineCovers(), - Beatmaps = beatmaps, + Beatmaps = beatmaps.ToArray(), }; } diff --git a/osu.Game.Tests/Visual/Beatmaps/TestSceneDifficultySpectrumDisplay.cs b/osu.Game.Tests/Visual/Beatmaps/TestSceneDifficultySpectrumDisplay.cs index 1f38b05879..4063fa1252 100644 --- a/osu.Game.Tests/Visual/Beatmaps/TestSceneDifficultySpectrumDisplay.cs +++ b/osu.Game.Tests/Visual/Beatmaps/TestSceneDifficultySpectrumDisplay.cs @@ -21,7 +21,7 @@ public class TestSceneDifficultySpectrumDisplay : OsuTestScene { RulesetID = difficulty.rulesetId, StarRating = difficulty.stars - }).ToList() + }).ToArray() }; [Test] diff --git a/osu.Game.Tests/Visual/Online/TestSceneBeatmapRulesetSelector.cs b/osu.Game.Tests/Visual/Online/TestSceneBeatmapRulesetSelector.cs index b880633559..90f3eb64e4 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneBeatmapRulesetSelector.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneBeatmapRulesetSelector.cs @@ -1,7 +1,6 @@ // 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 NUnit.Framework; using osu.Framework.Allocation; @@ -37,7 +36,7 @@ public void TestMultipleRulesetsBeatmapSet() { selector.BeatmapSet = new APIBeatmapSet { - Beatmaps = enabledRulesets.Select(r => new APIBeatmap { RulesetID = r.OnlineID }).ToList() + Beatmaps = enabledRulesets.Select(r => new APIBeatmap { RulesetID = r.OnlineID }).ToArray() }; }); @@ -55,7 +54,7 @@ public void TestSingleRulesetBeatmapSet() { selector.BeatmapSet = new APIBeatmapSet { - Beatmaps = new List + Beatmaps = new[] { new APIBeatmap { @@ -71,10 +70,7 @@ public void TestSingleRulesetBeatmapSet() [Test] public void TestEmptyBeatmapSet() { - AddStep("load empty beatmapset", () => selector.BeatmapSet = new APIBeatmapSet - { - Beatmaps = new List() - }); + AddStep("load empty beatmapset", () => selector.BeatmapSet = new APIBeatmapSet()); AddAssert("no ruleset selected", () => selector.SelectedTab == null); AddAssert("all rulesets disabled", () => selector.TabContainer.TabItems.All(t => !t.Enabled.Value)); diff --git a/osu.Game.Tests/Visual/Online/TestSceneBeatmapSetOverlay.cs b/osu.Game.Tests/Visual/Online/TestSceneBeatmapSetOverlay.cs index bae9af1897..63ce057667 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneBeatmapSetOverlay.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneBeatmapSetOverlay.cs @@ -71,7 +71,7 @@ public void TestLocalBeatmaps() Ratings = Enumerable.Range(0, 11).ToArray(), HasStoryboard = true, Covers = new BeatmapSetOnlineCovers(), - Beatmaps = new List + Beatmaps = new[] { new APIBeatmap { @@ -145,7 +145,7 @@ public void TestMultipleRulesets() var set = getBeatmapSet(); - set.Beatmaps = beatmaps; + set.Beatmaps = beatmaps.ToArray(); overlay.ShowBeatmapSet(set); }); @@ -211,7 +211,7 @@ private APIBeatmapSet createManyDifficultiesBeatmapSet() }); } - set.Beatmaps = beatmaps; + set.Beatmaps = beatmaps.ToArray(); return set; } diff --git a/osu.Game.Tests/Visual/Online/TestSceneBeatmapSetOverlayDetails.cs b/osu.Game.Tests/Visual/Online/TestSceneBeatmapSetOverlayDetails.cs index 491a2d5d90..9c0c67b1d8 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneBeatmapSetOverlayDetails.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneBeatmapSetOverlayDetails.cs @@ -1,7 +1,6 @@ // 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 NUnit.Framework; using osu.Framework.Allocation; @@ -46,7 +45,7 @@ public void TestMetrics() static APIBeatmapSet createSet() => new APIBeatmapSet { - Beatmaps = new List + Beatmaps = new[] { new APIBeatmap { diff --git a/osu.Game.Tests/Visual/Online/TestSceneDirectPanel.cs b/osu.Game.Tests/Visual/Online/TestSceneDirectPanel.cs index 9a3d998966..a3c8935fa8 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneDirectPanel.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneDirectPanel.cs @@ -90,7 +90,7 @@ private void load(RulesetStore rulesets) HasVideo = true, HasStoryboard = true, Covers = new BeatmapSetOnlineCovers(), - Beatmaps = new List + Beatmaps = new[] { new APIBeatmap { @@ -129,7 +129,7 @@ APIBeatmapSet getManyDifficultiesBeatmapSet() HasVideo = true, HasStoryboard = true, Covers = new BeatmapSetOnlineCovers(), - Beatmaps = beatmaps, + Beatmaps = beatmaps.ToArray(), }; } } diff --git a/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs b/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs index d8efa20b39..22cf6d25cd 100644 --- a/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs +++ b/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs @@ -119,7 +119,7 @@ public string AuthorString public string Tags { get; set; } = string.Empty; [JsonProperty(@"beatmaps")] - public IEnumerable Beatmaps { get; set; } = Array.Empty(); + public APIBeatmap[] Beatmaps { get; set; } = Array.Empty(); public virtual BeatmapSetInfo ToBeatmapSet(RulesetStore rulesets) { diff --git a/osu.Game/Overlays/BeatmapListing/Panels/BeatmapPanel.cs b/osu.Game/Overlays/BeatmapListing/Panels/BeatmapPanel.cs index 2fd05f6742..34086c214f 100644 --- a/osu.Game/Overlays/BeatmapListing/Panels/BeatmapPanel.cs +++ b/osu.Game/Overlays/BeatmapListing/Panels/BeatmapPanel.cs @@ -147,7 +147,7 @@ protected List GetDifficultyIcons(OsuColour colours) { var icons = new List(); - if (SetInfo.Beatmaps.Count() > maximum_difficulty_icons) + if (SetInfo.Beatmaps.Length > maximum_difficulty_icons) { foreach (var ruleset in SetInfo.Beatmaps.Select(b => b.Ruleset).Distinct()) icons.Add(new GroupedDifficultyIcon(SetInfo.Beatmaps.Where(b => b.RulesetID == ruleset.OnlineID).ToList(), ruleset, this is ListBeatmapPanel ? Color4.White : colours.Gray5)); diff --git a/osu.Game/Tests/Visual/Multiplayer/TestMultiplayerClient.cs b/osu.Game/Tests/Visual/Multiplayer/TestMultiplayerClient.cs index c690a621eb..70d907ba15 100644 --- a/osu.Game/Tests/Visual/Multiplayer/TestMultiplayerClient.cs +++ b/osu.Game/Tests/Visual/Multiplayer/TestMultiplayerClient.cs @@ -280,7 +280,7 @@ protected override Task GetOnlineBeatmapSet(int beatmapId, Cancel var apiSet = new APIBeatmapSet { OnlineID = set.OnlineID, - Beatmaps = set.Beatmaps.Select(b => new APIBeatmap { OnlineID = b.OnlineID }) + Beatmaps = set.Beatmaps.Select(b => new APIBeatmap { OnlineID = b.OnlineID }).ToArray(), }; return Task.FromResult(apiSet);