1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-17 20:03:20 +08:00
osu-lazer/osu.Game/Online/API/Requests/Responses/APIBeatmap.cs

136 lines
4.3 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2018-06-08 11:04:33 +08:00
using System;
2018-06-08 11:04:33 +08:00
using Newtonsoft.Json;
using osu.Game.Beatmaps;
using osu.Game.Rulesets;
2021-10-21 18:14:31 +08:00
#nullable enable
2018-06-08 11:04:33 +08:00
namespace osu.Game.Online.API.Requests.Responses
{
public class APIBeatmap : IBeatmapInfo
2018-06-08 11:04:33 +08:00
{
[JsonProperty(@"id")]
2021-10-21 18:14:31 +08:00
public int OnlineID { get; set; }
[JsonProperty(@"beatmapset_id")]
public int OnlineBeatmapSetID { get; set; }
2018-06-08 11:04:33 +08:00
[JsonProperty(@"status")]
public BeatmapSetOnlineStatus Status { get; set; }
2021-10-21 15:43:46 +08:00
[JsonProperty("checksum")]
2021-10-21 18:14:31 +08:00
public string Checksum { get; set; } = string.Empty;
2021-10-21 15:43:46 +08:00
[JsonProperty(@"user_id")]
public int AuthorID { get; set; }
[JsonProperty(@"beatmapset")]
2021-10-21 18:14:31 +08:00
public APIBeatmapSet? BeatmapSet { get; set; }
2018-06-08 11:04:33 +08:00
[JsonProperty(@"playcount")]
private int playCount { get; set; }
[JsonProperty(@"passcount")]
private int passCount { get; set; }
[JsonProperty(@"mode_int")]
2021-10-21 18:14:31 +08:00
public int RulesetID { get; set; }
2018-06-08 11:04:33 +08:00
[JsonProperty(@"difficulty_rating")]
2021-10-21 18:14:31 +08:00
public double StarRating { get; set; }
2018-06-08 11:04:33 +08:00
[JsonProperty(@"drain")]
private float drainRate { get; set; }
[JsonProperty(@"cs")]
private float circleSize { get; set; }
[JsonProperty(@"ar")]
private float approachRate { get; set; }
[JsonProperty(@"accuracy")]
private float overallDifficulty { get; set; }
public double Length => lengthInSeconds * 1000;
2018-06-08 11:04:33 +08:00
[JsonProperty(@"total_length")]
private double lengthInSeconds { get; set; }
2018-06-08 11:04:33 +08:00
[JsonProperty(@"count_circles")]
private int circleCount { get; set; }
[JsonProperty(@"count_sliders")]
private int sliderCount { get; set; }
[JsonProperty(@"version")]
2021-10-21 18:14:31 +08:00
public string DifficultyName { get; set; } = string.Empty;
2018-06-08 11:04:33 +08:00
2019-06-13 15:39:38 +08:00
[JsonProperty(@"failtimes")]
2021-10-21 18:14:31 +08:00
private BeatmapMetrics? metrics { get; set; }
2019-06-13 15:39:38 +08:00
2020-02-20 00:58:41 +08:00
[JsonProperty(@"max_combo")]
private int? maxCombo { get; set; }
2021-10-02 23:55:29 +08:00
public virtual BeatmapInfo ToBeatmapInfo(RulesetStore rulesets)
2018-06-08 11:04:33 +08:00
{
2018-12-14 14:03:49 +08:00
var set = BeatmapSet?.ToBeatmapSet(rulesets);
2018-06-08 11:04:33 +08:00
return new BeatmapInfo
{
Metadata = set?.Metadata ?? new BeatmapMetadata(),
2021-10-21 18:14:31 +08:00
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).
2021-10-21 18:14:31 +08:00
Length = TimeSpan.FromSeconds(Length).TotalMilliseconds,
Status = Status,
2021-10-21 15:43:46 +08:00
MD5Hash = Checksum,
BeatmapSet = set,
2019-06-13 15:39:38 +08:00
Metrics = metrics,
2020-02-20 00:58:41 +08:00
MaxCombo = maxCombo,
2018-06-08 11:04:33 +08:00
BaseDifficulty = new BeatmapDifficulty
{
DrainRate = drainRate,
CircleSize = circleSize,
ApproachRate = approachRate,
OverallDifficulty = overallDifficulty,
},
OnlineInfo = new BeatmapOnlineInfo
{
PlayCount = playCount,
PassCount = passCount,
CircleCount = circleCount,
SliderCount = sliderCount,
},
};
}
2021-10-21 18:14:31 +08:00
#region Implementation of IBeatmapInfo
public IBeatmapMetadataInfo Metadata => (BeatmapSet as IBeatmapSetInfo)?.Metadata ?? new BeatmapMetadata();
2021-10-21 18:14:31 +08:00
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
2018-06-08 11:04:33 +08:00
}
}