mirror of
https://github.com/osukey/osukey.git
synced 2025-07-04 01:40:02 +09:00
Reorganise API requests and response classes
They were previously breaking the two-class-per-file rule.
This commit is contained in:
@ -2,20 +2,15 @@
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Users;
|
||||
using osu.Game.Rulesets.Replays;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
using osu.Game.Screens.Select.Leaderboards;
|
||||
using osu.Framework.IO.Network;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
|
||||
namespace osu.Game.Online.API.Requests
|
||||
{
|
||||
public class GetScoresRequest : APIRequest<GetScoresResponse>
|
||||
public class GetScoresRequest : APIRequest<APIScores>
|
||||
{
|
||||
private readonly BeatmapInfo beatmap;
|
||||
private readonly LeaderboardScope scope;
|
||||
@ -36,9 +31,9 @@ namespace osu.Game.Online.API.Requests
|
||||
Success += onSuccess;
|
||||
}
|
||||
|
||||
private void onSuccess(GetScoresResponse r)
|
||||
private void onSuccess(APIScores r)
|
||||
{
|
||||
foreach (OnlineScore score in r.Scores)
|
||||
foreach (APIScore score in r.Scores)
|
||||
score.ApplyBeatmap(beatmap);
|
||||
}
|
||||
|
||||
@ -55,112 +50,4 @@ namespace osu.Game.Online.API.Requests
|
||||
|
||||
protected override string Target => $@"beatmaps/{beatmap.OnlineBeatmapID}/scores";
|
||||
}
|
||||
|
||||
public class GetScoresResponse
|
||||
{
|
||||
[JsonProperty(@"scores")]
|
||||
public IEnumerable<OnlineScore> Scores;
|
||||
}
|
||||
|
||||
public class OnlineScore : Score
|
||||
{
|
||||
[JsonProperty(@"score")]
|
||||
private double totalScore
|
||||
{
|
||||
set { TotalScore = value; }
|
||||
}
|
||||
|
||||
[JsonProperty(@"max_combo")]
|
||||
private int maxCombo
|
||||
{
|
||||
set { MaxCombo = value; }
|
||||
}
|
||||
|
||||
[JsonProperty(@"user")]
|
||||
private User user
|
||||
{
|
||||
set { User = value; }
|
||||
}
|
||||
|
||||
[JsonProperty(@"replay_data")]
|
||||
private Replay replay
|
||||
{
|
||||
set { Replay = value; }
|
||||
}
|
||||
|
||||
[JsonProperty(@"mode_int")]
|
||||
public int OnlineRulesetID { get; set; }
|
||||
|
||||
[JsonProperty(@"score_id")]
|
||||
private long onlineScoreID
|
||||
{
|
||||
set { OnlineScoreID = value; }
|
||||
}
|
||||
|
||||
[JsonProperty(@"created_at")]
|
||||
private DateTimeOffset date
|
||||
{
|
||||
set { Date = value; }
|
||||
}
|
||||
|
||||
[JsonProperty(@"beatmap")]
|
||||
private BeatmapInfo beatmap
|
||||
{
|
||||
set { Beatmap = value; }
|
||||
}
|
||||
|
||||
[JsonProperty(@"beatmapset")]
|
||||
private BeatmapMetadata metadata
|
||||
{
|
||||
set { Beatmap.Metadata = value; }
|
||||
}
|
||||
|
||||
[JsonProperty(@"statistics")]
|
||||
private Dictionary<string, object> jsonStats
|
||||
{
|
||||
set
|
||||
{
|
||||
foreach (var kvp in value)
|
||||
{
|
||||
HitResult newKey;
|
||||
switch (kvp.Key)
|
||||
{
|
||||
case @"count_300":
|
||||
newKey = HitResult.Great;
|
||||
break;
|
||||
case @"count_100":
|
||||
newKey = HitResult.Good;
|
||||
break;
|
||||
case @"count_50":
|
||||
newKey = HitResult.Meh;
|
||||
break;
|
||||
case @"count_miss":
|
||||
newKey = HitResult.Miss;
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
|
||||
Statistics.Add(newKey, kvp.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[JsonProperty(@"mods")]
|
||||
private string[] modStrings { get; set; }
|
||||
|
||||
public void ApplyBeatmap(BeatmapInfo beatmap)
|
||||
{
|
||||
Beatmap = beatmap;
|
||||
ApplyRuleset(beatmap.Ruleset);
|
||||
}
|
||||
|
||||
public void ApplyRuleset(RulesetInfo ruleset)
|
||||
{
|
||||
Ruleset = ruleset;
|
||||
|
||||
// Evaluate the mod string
|
||||
Mods = Ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user