-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
APIBeatmap.cs
134 lines (94 loc) · 4.07 KB
/
APIBeatmap.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// 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.
using System;
using Newtonsoft.Json;
using osu.Game.Beatmaps;
using osu.Game.Extensions;
using osu.Game.Rulesets;
#nullable enable
namespace osu.Game.Online.API.Requests.Responses
{
public class APIBeatmap : IBeatmapInfo, IBeatmapOnlineInfo
{
[JsonProperty(@"id")]
public int OnlineID { get; set; }
[JsonProperty(@"beatmapset_id")]
public int OnlineBeatmapSetID { get; set; }
[JsonProperty(@"status")]
public BeatmapOnlineStatus Status { get; set; }
[JsonProperty("checksum")]
public string Checksum { get; set; } = string.Empty;
[JsonProperty(@"user_id")]
public int AuthorID { get; set; }
[JsonProperty(@"beatmapset")]
public APIBeatmapSet? BeatmapSet { get; set; }
[JsonProperty(@"playcount")]
public int PlayCount { get; set; }
[JsonProperty(@"passcount")]
public int PassCount { get; set; }
[JsonProperty(@"mode_int")]
public int RulesetID { get; set; }
[JsonProperty(@"difficulty_rating")]
public double StarRating { get; set; }
[JsonProperty(@"drain")]
public float DrainRate { get; set; }
[JsonProperty(@"cs")]
public float CircleSize { get; set; }
[JsonProperty(@"ar")]
public float ApproachRate { get; set; }
[JsonProperty(@"accuracy")]
public float OverallDifficulty { get; set; }
[JsonIgnore]
public double Length { get; set; }
[JsonProperty(@"total_length")]
private double lengthInSeconds
{
get => TimeSpan.FromMilliseconds(Length).TotalSeconds;
set => Length = TimeSpan.FromSeconds(value).TotalMilliseconds;
}
[JsonProperty(@"count_circles")]
public int CircleCount { get; set; }
[JsonProperty(@"count_sliders")]
public int SliderCount { get; set; }
[JsonProperty(@"version")]
public string DifficultyName { get; set; } = string.Empty;
[JsonProperty(@"failtimes")]
public APIFailTimes? FailTimes { get; set; }
[JsonProperty(@"max_combo")]
public int? MaxCombo { get; set; }
public double BPM { get; set; }
#region Implementation of IBeatmapInfo
public IBeatmapMetadataInfo Metadata => (BeatmapSet as IBeatmapSetInfo)?.Metadata ?? new BeatmapMetadata();
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 APIRuleset { OnlineID = RulesetID };
[JsonIgnore]
public string Hash => throw new NotImplementedException();
#endregion
public bool Equals(IBeatmapInfo? other) => other is APIBeatmap b && this.MatchesOnlineID(b);
private class APIRuleset : IRulesetInfo
{
public int OnlineID { get; set; } = -1;
public string Name => $@"{nameof(APIRuleset)} (ID: {OnlineID})";
public string ShortName => nameof(APIRuleset);
public string InstantiationInfo => string.Empty;
public Ruleset CreateInstance() => throw new NotImplementedException();
public bool Equals(IRulesetInfo? other) => other is APIRuleset r && this.MatchesOnlineID(r);
public int CompareTo(IRulesetInfo other)
{
if (!(other is APIRuleset ruleset))
throw new ArgumentException($@"Object is not of type {nameof(APIRuleset)}.", nameof(other));
return OnlineID.CompareTo(ruleset.OnlineID);
}
// ReSharper disable once NonReadonlyMemberInGetHashCode
public override int GetHashCode() => OnlineID;
}
}
}