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

APIBeatmap implements IBeatmapInfo

This commit is contained in:
Dean Herbert 2021-10-21 19:14:31 +09:00
parent 40a176e86e
commit 0fe0b5dc09
2 changed files with 42 additions and 17 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

@ -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
}
}