1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 21:02:55 +08:00

Merge pull request #15223 from peppy/api-beatmap-set-is-i-beatmap-set

Implement `IBeatmapInfo`/`IBeatmapSetInfo` from API beatmap types
This commit is contained in:
Dean Herbert 2021-10-21 20:33:26 +09:00 committed by GitHub
commit 02d1cf31cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 84 additions and 46 deletions

View File

@ -83,9 +83,9 @@ namespace osu.Game.Beatmaps
if (res != null)
{
beatmapInfo.Status = res.Status;
beatmapInfo.BeatmapSet.Status = res.BeatmapSet.Status;
beatmapInfo.BeatmapSet.Status = res.BeatmapSet?.Status ?? BeatmapSetOnlineStatus.None;
beatmapInfo.BeatmapSet.OnlineBeatmapSetID = res.OnlineBeatmapSetID;
beatmapInfo.OnlineBeatmapID = res.OnlineBeatmapID;
beatmapInfo.OnlineBeatmapID = res.OnlineID;
if (beatmapInfo.Metadata != null)
beatmapInfo.Metadata.AuthorID = res.AuthorID;
@ -93,7 +93,7 @@ namespace osu.Game.Beatmaps
if (beatmapInfo.BeatmapSet.Metadata != null)
beatmapInfo.BeatmapSet.Metadata.AuthorID = res.AuthorID;
logForModel(set, $"Online retrieval mapped {beatmapInfo} to {res.OnlineBeatmapSetID} / {res.OnlineBeatmapID}.");
logForModel(set, $"Online retrieval mapped {beatmapInfo} to {res.OnlineBeatmapSetID} / {res.OnlineID}.");
}
}
catch (Exception e)

View File

@ -5,7 +5,7 @@ using Newtonsoft.Json;
namespace osu.Game.Beatmaps
{
public class BeatmapSetOnlineAvailability
public struct BeatmapSetOnlineAvailability
{
[JsonProperty(@"download_disabled")]
public bool DownloadDisabled { get; set; }

View File

@ -5,7 +5,7 @@ using Newtonsoft.Json;
namespace osu.Game.Beatmaps
{
public class BeatmapSetOnlineCovers
public struct BeatmapSetOnlineCovers
{
public string CoverLowRes { get; set; }

View File

@ -3,7 +3,7 @@
namespace osu.Game.Beatmaps
{
public class BeatmapSetOnlineGenre
public struct BeatmapSetOnlineGenre
{
public int Id { get; set; }
public string Name { get; set; }

View File

@ -3,7 +3,7 @@
namespace osu.Game.Beatmaps
{
public class BeatmapSetOnlineLanguage
public struct BeatmapSetOnlineLanguage
{
public int Id { get; set; }
public string Name { get; set; }

View File

@ -3,6 +3,8 @@
using System;
#nullable enable
namespace osu.Game.Beatmaps
{
/// <summary>

View File

@ -6,12 +6,14 @@ using Newtonsoft.Json;
using osu.Game.Beatmaps;
using osu.Game.Rulesets;
#nullable enable
namespace osu.Game.Online.API.Requests.Responses
{
public class APIBeatmap : BeatmapMetadata
public class APIBeatmap : BeatmapMetadata, IBeatmapInfo
{
[JsonProperty(@"id")]
public int OnlineBeatmapID { get; set; }
public int OnlineID { get; set; }
[JsonProperty(@"beatmapset_id")]
public int OnlineBeatmapSetID { get; set; }
@ -20,10 +22,10 @@ namespace osu.Game.Online.API.Requests.Responses
public BeatmapSetOnlineStatus Status { get; set; }
[JsonProperty("checksum")]
public string Checksum { get; set; }
public string Checksum { get; set; } = string.Empty;
[JsonProperty(@"beatmapset")]
public APIBeatmapSet BeatmapSet { get; set; }
public APIBeatmapSet? BeatmapSet { get; set; }
[JsonProperty(@"playcount")]
private int playCount { get; set; }
@ -32,10 +34,10 @@ namespace osu.Game.Online.API.Requests.Responses
private int passCount { get; set; }
[JsonProperty(@"mode_int")]
private int ruleset { get; set; }
public int RulesetID { get; set; }
[JsonProperty(@"difficulty_rating")]
private double starDifficulty { get; set; }
public double StarRating { get; set; }
[JsonProperty(@"drain")]
private float drainRate { get; set; }
@ -50,7 +52,7 @@ namespace osu.Game.Online.API.Requests.Responses
private float overallDifficulty { get; set; }
[JsonProperty(@"total_length")]
private double length { get; set; }
public double Length { get; set; }
[JsonProperty(@"count_circles")]
private int circleCount { get; set; }
@ -59,10 +61,10 @@ namespace osu.Game.Online.API.Requests.Responses
private int sliderCount { get; set; }
[JsonProperty(@"version")]
private string version { get; set; }
public string DifficultyName { get; set; } = string.Empty;
[JsonProperty(@"failtimes")]
private BeatmapMetrics metrics { get; set; }
private BeatmapMetrics? metrics { get; set; }
[JsonProperty(@"max_combo")]
private int? maxCombo { get; set; }
@ -74,12 +76,12 @@ namespace osu.Game.Online.API.Requests.Responses
return new BeatmapInfo
{
Metadata = set?.Metadata ?? this,
Ruleset = rulesets.GetRuleset(ruleset),
StarDifficulty = starDifficulty,
OnlineBeatmapID = OnlineBeatmapID,
Version = version,
Ruleset = rulesets.GetRuleset(RulesetID),
StarDifficulty = StarRating,
OnlineBeatmapID = OnlineID,
Version = DifficultyName,
// this is actually an incorrect mapping (Length is calculated as drain length in lazer's import process, see BeatmapManager.calculateLength).
Length = TimeSpan.FromSeconds(length).TotalMilliseconds,
Length = TimeSpan.FromSeconds(Length).TotalMilliseconds,
Status = Status,
MD5Hash = Checksum,
BeatmapSet = set,
@ -101,5 +103,28 @@ namespace osu.Game.Online.API.Requests.Responses
},
};
}
#region Implementation of IBeatmapInfo
public IBeatmapMetadataInfo Metadata => this;
public IBeatmapDifficultyInfo Difficulty => new BeatmapDifficulty
{
DrainRate = drainRate,
CircleSize = circleSize,
ApproachRate = approachRate,
OverallDifficulty = overallDifficulty,
};
IBeatmapSetInfo? IBeatmapInfo.BeatmapSet => BeatmapSet;
public string MD5Hash => Checksum;
public IRulesetInfo Ruleset => new RulesetInfo { ID = RulesetID };
public double BPM => throw new NotImplementedException();
public string Hash => throw new NotImplementedException();
#endregion
}
}

View File

@ -6,29 +6,26 @@ using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Rulesets;
#nullable enable
namespace osu.Game.Online.API.Requests.Responses
{
public class APIBeatmapSet : BeatmapMetadata, IBeatmapSetOnlineInfo
public class APIBeatmapSet : BeatmapMetadata, IBeatmapSetOnlineInfo, IBeatmapSetInfo
{
[JsonProperty(@"covers")]
public BeatmapSetOnlineCovers Covers { get; set; }
private int? onlineBeatmapSetID;
[JsonProperty(@"id")]
public int? OnlineBeatmapSetID
{
get => onlineBeatmapSetID;
set => onlineBeatmapSetID = value > 0 ? value : null;
}
public int OnlineID { get; set; }
[JsonProperty(@"status")]
public BeatmapSetOnlineStatus Status { get; set; }
[JsonProperty(@"preview_url")]
public string Preview { get; set; }
public string Preview { get; set; } = string.Empty;
[JsonProperty(@"has_favourited")]
public bool HasFavourited { get; set; }
@ -61,7 +58,7 @@ namespace osu.Game.Online.API.Requests.Responses
public DateTimeOffset? LastUpdated { get; set; }
[JsonProperty(@"ratings")]
private int[] ratings { get; set; }
private int[] ratings { get; set; } = Array.Empty<int>();
[JsonProperty(@"track_id")]
public int? TrackId { get; set; }
@ -82,20 +79,20 @@ namespace osu.Game.Online.API.Requests.Responses
public BeatmapSetOnlineLanguage Language { get; set; }
[JsonProperty(@"beatmaps")]
private IEnumerable<APIBeatmap> beatmaps { get; set; }
private IEnumerable<APIBeatmap> beatmaps { get; set; } = Array.Empty<APIBeatmap>();
public virtual BeatmapSetInfo ToBeatmapSet(RulesetStore rulesets)
{
var beatmapSet = new BeatmapSetInfo
{
OnlineBeatmapSetID = OnlineBeatmapSetID,
OnlineBeatmapSetID = OnlineID,
Metadata = this,
Status = Status,
Metrics = ratings == null ? null : new BeatmapSetMetrics { Ratings = ratings },
Metrics = new BeatmapSetMetrics { Ratings = ratings },
OnlineInfo = this
};
beatmapSet.Beatmaps = beatmaps?.Select(b =>
beatmapSet.Beatmaps = beatmaps.Select(b =>
{
var beatmap = b.ToBeatmapInfo(rulesets);
beatmap.BeatmapSet = beatmapSet;
@ -105,5 +102,19 @@ namespace osu.Game.Online.API.Requests.Responses
return beatmapSet;
}
#region Implementation of IBeatmapSetInfo
IEnumerable<IBeatmapInfo> IBeatmapSetInfo.Beatmaps => beatmaps;
IBeatmapMetadataInfo IBeatmapSetInfo.Metadata => this;
DateTimeOffset IBeatmapSetInfo.DateAdded => throw new NotImplementedException();
IEnumerable<INamedFileUsage> IBeatmapSetInfo.Files => throw new NotImplementedException();
double IBeatmapSetInfo.MaxStarDifficulty => throw new NotImplementedException();
double IBeatmapSetInfo.MaxLength => throw new NotImplementedException();
double IBeatmapSetInfo.MaxBPM => throw new NotImplementedException();
#endregion
}
}

View File

@ -92,7 +92,7 @@ namespace osu.Game.Overlays.BeatmapListing.Panels
break;
default:
if (BeatmapSet.Value?.OnlineInfo?.Availability?.DownloadDisabled ?? false)
if (BeatmapSet.Value?.OnlineInfo?.Availability.DownloadDisabled ?? false)
{
button.Enabled.Value = false;
button.TooltipText = "this beatmap is currently not available for download.";

View File

@ -16,8 +16,8 @@ namespace osu.Game.Overlays.BeatmapSet
{
private BeatmapSetInfo beatmapSet;
private bool downloadDisabled => BeatmapSet?.OnlineInfo.Availability?.DownloadDisabled ?? false;
private bool hasExternalLink => !string.IsNullOrEmpty(BeatmapSet?.OnlineInfo.Availability?.ExternalLink);
private bool downloadDisabled => BeatmapSet?.OnlineInfo.Availability.DownloadDisabled ?? false;
private bool hasExternalLink => !string.IsNullOrEmpty(BeatmapSet?.OnlineInfo.Availability.ExternalLink);
private readonly LinkFlowContainer textContainer;

View File

@ -266,7 +266,7 @@ namespace osu.Game.Overlays.BeatmapSet
{
if (BeatmapSet.Value == null) return;
if ((BeatmapSet.Value.OnlineInfo.Availability?.DownloadDisabled ?? false) && State.Value != DownloadState.LocallyAvailable)
if (BeatmapSet.Value.OnlineInfo.Availability.DownloadDisabled && State.Value != DownloadState.LocallyAvailable)
{
downloadButtonsContainer.Clear();
return;

View File

@ -117,8 +117,8 @@ namespace osu.Game.Overlays.BeatmapSet
{
source.Text = b.NewValue?.Metadata.Source ?? string.Empty;
tags.Text = b.NewValue?.Metadata.Tags ?? string.Empty;
genre.Text = b.NewValue?.OnlineInfo?.Genre?.Name ?? string.Empty;
language.Text = b.NewValue?.OnlineInfo?.Language?.Name ?? string.Empty;
genre.Text = b.NewValue?.OnlineInfo?.Genre.Name ?? string.Empty;
language.Text = b.NewValue?.OnlineInfo?.Language.Name ?? string.Empty;
var setHasLeaderboard = b.NewValue?.OnlineInfo?.Status > 0;
successRate.Alpha = setHasLeaderboard ? 1 : 0;
notRankedPlaceholder.Alpha = setHasLeaderboard ? 0 : 1;

View File

@ -60,12 +60,12 @@ namespace osu.Game.Overlays.Profile.Sections.Beatmaps
protected override APIRequest<List<APIBeatmapSet>> CreateRequest() =>
new GetUserBeatmapsRequest(User.Value.Id, type, VisiblePages++, ItemsPerPage);
protected override Drawable CreateDrawableItem(APIBeatmapSet model) => !model.OnlineBeatmapSetID.HasValue
? null
: new GridBeatmapPanel(model.ToBeatmapSet(Rulesets))
protected override Drawable CreateDrawableItem(APIBeatmapSet model) => model.OnlineID > 0
? new GridBeatmapPanel(model.ToBeatmapSet(Rulesets))
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
};
}
: null;
}
}

View File

@ -61,7 +61,7 @@ namespace osu.Game.Screens.OnlinePlay.Components
{
var beatmap = playlistItem?.Beatmap.Value;
if (background?.BeatmapInfo?.BeatmapSet?.OnlineInfo?.Covers?.Cover == beatmap?.BeatmapSet?.OnlineInfo?.Covers?.Cover)
if (background?.BeatmapInfo?.BeatmapSet?.OnlineInfo?.Covers.Cover == beatmap?.BeatmapSet?.OnlineInfo?.Covers.Cover)
return;
cancellationSource?.Cancel();