From 583bb53f53c268b69c23ead81c67fded43569f96 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 13 Jun 2019 16:57:19 +0900 Subject: [PATCH] Remove GetBeatmapDetailsRequest --- .../API/Requests/GetBeatmapDetailsRequest.cs | 20 ----------- .../Requests/Responses/APIBeatmapMetrics.cs | 33 ------------------- osu.Game/Screens/Select/BeatmapDetails.cs | 30 ++++++++++------- 3 files changed, 18 insertions(+), 65 deletions(-) delete mode 100644 osu.Game/Online/API/Requests/GetBeatmapDetailsRequest.cs delete mode 100644 osu.Game/Online/API/Requests/Responses/APIBeatmapMetrics.cs diff --git a/osu.Game/Online/API/Requests/GetBeatmapDetailsRequest.cs b/osu.Game/Online/API/Requests/GetBeatmapDetailsRequest.cs deleted file mode 100644 index ed5efa2849..0000000000 --- a/osu.Game/Online/API/Requests/GetBeatmapDetailsRequest.cs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -using osu.Game.Beatmaps; -using osu.Game.Online.API.Requests.Responses; - -namespace osu.Game.Online.API.Requests -{ - public class GetBeatmapDetailsRequest : APIRequest - { - private readonly BeatmapInfo beatmap; - - public GetBeatmapDetailsRequest(BeatmapInfo beatmap) - { - this.beatmap = beatmap; - } - - protected override string Target => $@"beatmaps/{beatmap.OnlineBeatmapID}"; - } -} diff --git a/osu.Game/Online/API/Requests/Responses/APIBeatmapMetrics.cs b/osu.Game/Online/API/Requests/Responses/APIBeatmapMetrics.cs deleted file mode 100644 index 32a036b7c2..0000000000 --- a/osu.Game/Online/API/Requests/Responses/APIBeatmapMetrics.cs +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -using System; -using Newtonsoft.Json; -using osu.Game.Beatmaps; - -namespace osu.Game.Online.API.Requests.Responses -{ - public class APIBeatmapMetrics : BeatmapMetrics - { - //the online API returns some metrics as a nested object. - [JsonProperty(@"failtimes")] - private BeatmapMetrics failTimes - { - set - { - Fails = value.Fails; - Retries = value.Retries; - } - } - - public int[] Ratings { get; set; } = Array.Empty(); - - //and other metrics in the beatmap set. - // Todo: What - [JsonProperty(@"beatmapset")] - private BeatmapSetMetrics beatmapSet - { - set => Ratings = value.Ratings; - } - } -} diff --git a/osu.Game/Screens/Select/BeatmapDetails.cs b/osu.Game/Screens/Select/BeatmapDetails.cs index 83f9e5b063..1b4608b0fd 100644 --- a/osu.Game/Screens/Select/BeatmapDetails.cs +++ b/osu.Game/Screens/Select/BeatmapDetails.cs @@ -10,7 +10,6 @@ using osu.Game.Graphics.Sprites; using osu.Game.Graphics.UserInterface; using System.Linq; using osu.Game.Online.API; -using osu.Game.Online.API.Requests; using osu.Framework.Threading; using osu.Framework.Graphics.Shapes; using osu.Framework.Extensions.Color4Extensions; @@ -18,7 +17,8 @@ using osu.Game.Screens.Select.Details; using osu.Game.Beatmaps; using osu.Game.Graphics; using osu.Game.Graphics.Containers; -using osu.Game.Online.API.Requests.Responses; +using osu.Game.Online.API.Requests; +using osu.Game.Rulesets; namespace osu.Game.Screens.Select { @@ -41,6 +41,9 @@ namespace osu.Game.Screens.Select private ScheduledDelegate pendingBeatmapSwitch; + [Resolved] + private RulesetStore rulesets { get; set; } + private BeatmapInfo beatmap; public BeatmapInfo Beatmap @@ -182,10 +185,9 @@ namespace osu.Game.Screens.Select tags.Text = Beatmap?.Metadata?.Tags; // metrics may have been previously fetched - // Todo: if (Beatmap?.BeatmapSet?.Metrics != null) { - updateMetrics(new APIBeatmapMetrics { Ratings = Beatmap.BeatmapSet.Metrics.Ratings }); + updateMetrics(Beatmap); return; } @@ -193,15 +195,19 @@ namespace osu.Game.Screens.Select if (Beatmap?.OnlineBeatmapID != null) { var requestedBeatmap = Beatmap; - var lookup = new GetBeatmapDetailsRequest(requestedBeatmap); + var lookup = new GetBeatmapRequest(requestedBeatmap); lookup.Success += res => { if (beatmap != requestedBeatmap) //the beatmap has been changed since we started the lookup. return; - requestedBeatmap.Metrics = res; - Schedule(() => updateMetrics(res)); + var b = res.ToBeatmap(rulesets); + + requestedBeatmap.BeatmapSet.Metrics = b.BeatmapSet.Metrics; + requestedBeatmap.Metrics = b.Metrics; + + Schedule(() => updateMetrics(requestedBeatmap)); }; lookup.Failure += e => Schedule(() => updateMetrics()); api.Queue(lookup); @@ -212,14 +218,14 @@ namespace osu.Game.Screens.Select updateMetrics(); } - private void updateMetrics(APIBeatmapMetrics metrics = null) + private void updateMetrics(BeatmapInfo beatmap = null) { - var hasRatings = metrics?.Ratings?.Any() ?? false; - var hasRetriesFails = (metrics?.Retries?.Any() ?? false) && (metrics.Fails?.Any() ?? false); + var hasRatings = beatmap?.BeatmapSet?.Metrics?.Ratings?.Any() ?? false; + var hasRetriesFails = (beatmap?.Metrics?.Retries?.Any() ?? false) && (beatmap.Metrics.Fails?.Any() ?? false); if (hasRatings) { - ratings.Metrics = new BeatmapSetMetrics { Ratings = metrics.Ratings }; + ratings.Metrics = beatmap.BeatmapSet.Metrics; ratingsContainer.FadeIn(transition_duration); } else @@ -230,7 +236,7 @@ namespace osu.Game.Screens.Select if (hasRetriesFails) { - failRetryGraph.Metrics = metrics; + failRetryGraph.Metrics = beatmap.Metrics; failRetryContainer.FadeIn(transition_duration); } else