mirror of
https://github.com/ppy/osu
synced 2025-01-19 20:40:52 +00:00
Implement score interfaces
This commit is contained in:
parent
49b5de64be
commit
1944c255a7
@ -134,7 +134,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
{
|
{
|
||||||
return new APIScoreInfo
|
return new APIScoreInfo
|
||||||
{
|
{
|
||||||
OnlineScoreID = 2553163309,
|
OnlineID = 2553163309,
|
||||||
OnlineRulesetID = 0,
|
OnlineRulesetID = 0,
|
||||||
Replay = replayAvailable,
|
Replay = replayAvailable,
|
||||||
User = new User
|
User = new User
|
||||||
|
@ -38,20 +38,20 @@ namespace osu.Game.Online.API.Requests
|
|||||||
|
|
||||||
private void onSuccess(APIScoresCollection r)
|
private void onSuccess(APIScoresCollection r)
|
||||||
{
|
{
|
||||||
Debug.Assert(ruleset.ID != null, "ruleset.ID != null");
|
Debug.Assert(ruleset.OnlineID >= 0);
|
||||||
|
|
||||||
foreach (APIScoreInfo score in r.Scores)
|
foreach (APIScoreInfo score in r.Scores)
|
||||||
{
|
{
|
||||||
score.BeatmapInfo = beatmapInfo;
|
score.Beatmap = beatmapInfo;
|
||||||
score.OnlineRulesetID = ruleset.ID.Value;
|
score.OnlineRulesetID = ruleset.OnlineID;
|
||||||
}
|
}
|
||||||
|
|
||||||
var userScore = r.UserScore;
|
var userScore = r.UserScore;
|
||||||
|
|
||||||
if (userScore != null)
|
if (userScore != null)
|
||||||
{
|
{
|
||||||
userScore.Score.BeatmapInfo = beatmapInfo;
|
userScore.Score.Beatmap = beatmapInfo;
|
||||||
userScore.Score.OnlineRulesetID = ruleset.ID.Value;
|
userScore.Score.OnlineRulesetID = ruleset.OnlineID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,14 +9,71 @@ using Newtonsoft.Json.Converters;
|
|||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
|
using osu.Game.Rulesets.Scoring;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
using osu.Game.Scoring.Legacy;
|
using osu.Game.Scoring.Legacy;
|
||||||
using osu.Game.Users;
|
using osu.Game.Users;
|
||||||
|
|
||||||
namespace osu.Game.Online.API.Requests.Responses
|
namespace osu.Game.Online.API.Requests.Responses
|
||||||
{
|
{
|
||||||
public class APIScoreInfo
|
public class APIScoreInfo : IScoreInfo
|
||||||
{
|
{
|
||||||
|
[JsonProperty(@"score")]
|
||||||
|
public long TotalScore { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty(@"max_combo")]
|
||||||
|
public int MaxCombo { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty(@"user")]
|
||||||
|
public User User { get; set; }
|
||||||
|
|
||||||
|
public bool HasReplay { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty(@"id")]
|
||||||
|
public long OnlineID { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty(@"replay")]
|
||||||
|
public bool Replay { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty(@"created_at")]
|
||||||
|
public DateTimeOffset Date { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty(@"beatmap")]
|
||||||
|
public IBeatmapInfo Beatmap { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("accuracy")]
|
||||||
|
public double Accuracy { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty(@"pp")]
|
||||||
|
public double? PP { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty(@"beatmapset")]
|
||||||
|
public APIBeatmapSet BeatmapSet
|
||||||
|
{
|
||||||
|
set
|
||||||
|
{
|
||||||
|
// in the deserialisation case we need to ferry this data across.
|
||||||
|
if (Beatmap is APIBeatmap apiBeatmap)
|
||||||
|
apiBeatmap.BeatmapSet = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[JsonProperty("statistics")]
|
||||||
|
public Dictionary<string, int> Statistics { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty(@"mode_int")]
|
||||||
|
public int OnlineRulesetID { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty(@"mods")]
|
||||||
|
public string[] Mods { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("rank")]
|
||||||
|
[JsonConverter(typeof(StringEnumConverter))]
|
||||||
|
public ScoreRank Rank { get; set; }
|
||||||
|
|
||||||
|
IBeatmapInfo IScoreInfo.Beatmap => Beatmap;
|
||||||
|
|
||||||
|
// TODO: nuke
|
||||||
public ScoreInfo CreateScoreInfo(RulesetStore rulesets)
|
public ScoreInfo CreateScoreInfo(RulesetStore rulesets)
|
||||||
{
|
{
|
||||||
var ruleset = rulesets.GetRuleset(OnlineRulesetID);
|
var ruleset = rulesets.GetRuleset(OnlineRulesetID);
|
||||||
@ -34,10 +91,10 @@ namespace osu.Game.Online.API.Requests.Responses
|
|||||||
MaxCombo = MaxCombo,
|
MaxCombo = MaxCombo,
|
||||||
User = User,
|
User = User,
|
||||||
Accuracy = Accuracy,
|
Accuracy = Accuracy,
|
||||||
OnlineScoreID = OnlineScoreID,
|
OnlineScoreID = OnlineID,
|
||||||
Date = Date,
|
Date = Date,
|
||||||
PP = PP,
|
PP = PP,
|
||||||
BeatmapInfo = BeatmapInfo,
|
BeatmapInfo = Beatmap.ToBeatmapInfo(rulesets),
|
||||||
RulesetID = OnlineRulesetID,
|
RulesetID = OnlineRulesetID,
|
||||||
Hash = Replay ? "online" : string.Empty, // todo: temporary?
|
Hash = Replay ? "online" : string.Empty, // todo: temporary?
|
||||||
Rank = Rank,
|
Rank = Rank,
|
||||||
@ -81,57 +138,19 @@ namespace osu.Game.Online.API.Requests.Responses
|
|||||||
return scoreInfo;
|
return scoreInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonProperty(@"score")]
|
|
||||||
public int TotalScore { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty(@"max_combo")]
|
|
||||||
public int MaxCombo { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty(@"user")]
|
|
||||||
public User User { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty(@"id")]
|
|
||||||
public long OnlineScoreID { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty(@"replay")]
|
|
||||||
public bool Replay { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty(@"created_at")]
|
|
||||||
public DateTimeOffset Date { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty(@"beatmap")]
|
|
||||||
public BeatmapInfo BeatmapInfo { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty("accuracy")]
|
|
||||||
public double Accuracy { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty(@"pp")]
|
|
||||||
public double? PP { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty(@"beatmapset")]
|
[JsonProperty(@"beatmapset")]
|
||||||
public BeatmapMetadata Metadata
|
public APIBeatmapSet Metadata
|
||||||
{
|
{
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
// extract the set ID to its correct place.
|
// in the deserialisation case we need to ferry this data across.
|
||||||
BeatmapInfo.BeatmapSet = new BeatmapSetInfo { OnlineBeatmapSetID = value.ID };
|
if (Beatmap is APIBeatmap apiBeatmap)
|
||||||
value.ID = 0;
|
apiBeatmap.BeatmapSet = value;
|
||||||
|
|
||||||
BeatmapInfo.Metadata = value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonProperty(@"statistics")]
|
public IRulesetInfo Ruleset => new RulesetInfo { ID = OnlineRulesetID };
|
||||||
public Dictionary<string, int> Statistics { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty(@"mode_int")]
|
Dictionary<HitResult, int> IScoreInfo.Statistics => new Dictionary<HitResult, int>(); // TODO: implement... maybe. hitresults have weird mappings per ruleset it would seem.
|
||||||
public int OnlineRulesetID { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty(@"mods")]
|
|
||||||
public string[] Mods { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty("rank")]
|
|
||||||
[JsonConverter(typeof(StringEnumConverter))]
|
|
||||||
public ScoreRank Rank { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ namespace osu.Game.Online.API.Requests.Responses
|
|||||||
public APIScoreInfo Score;
|
public APIScoreInfo Score;
|
||||||
|
|
||||||
public ScoreInfo CreateScoreInfo(RulesetStore rulesets)
|
public ScoreInfo CreateScoreInfo(RulesetStore rulesets)
|
||||||
|
|
||||||
{
|
{
|
||||||
var score = Score.CreateScoreInfo(rulesets);
|
var score = Score.CreateScoreInfo(rulesets);
|
||||||
score.Position = Position;
|
score.Position = Position;
|
||||||
|
@ -5,38 +5,37 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
|
using osu.Game.Rulesets;
|
||||||
|
using osu.Game.Rulesets.Scoring;
|
||||||
using osu.Game.Users;
|
using osu.Game.Users;
|
||||||
|
|
||||||
namespace osu.Game.Scoring
|
namespace osu.Game.Scoring
|
||||||
{
|
{
|
||||||
public interface IScoreInfo : IHasOnlineID<long>
|
public interface IScoreInfo : IHasOnlineID<long>
|
||||||
{
|
{
|
||||||
int TotalScore { get; set; }
|
User User { get; }
|
||||||
|
|
||||||
int MaxCombo { get; set; }
|
long TotalScore { get; }
|
||||||
|
|
||||||
User User { get; set; }
|
int MaxCombo { get; }
|
||||||
|
|
||||||
long OnlineScoreID { get; set; }
|
double Accuracy { get; }
|
||||||
|
|
||||||
bool Replay { get; set; }
|
bool HasReplay { get; }
|
||||||
|
|
||||||
DateTimeOffset Date { get; set; }
|
DateTimeOffset Date { get; }
|
||||||
|
|
||||||
BeatmapInfo BeatmapInfo { get; set; }
|
double? PP { get; }
|
||||||
|
|
||||||
double Accuracy { get; set; }
|
IBeatmapInfo Beatmap { get; }
|
||||||
|
|
||||||
double? PP { get; set; }
|
Dictionary<HitResult, int> Statistics { get; }
|
||||||
|
|
||||||
BeatmapMetadata Metadata { get; set; }
|
IRulesetInfo Ruleset { get; }
|
||||||
|
|
||||||
Dictionary<string, int> Statistics { get; set; }
|
public ScoreRank Rank { get; }
|
||||||
|
|
||||||
int OnlineRulesetID { get; set; }
|
// Mods is currently missing from this interface as the `IMod` class has properties which can't be fulfilled by `APIMod`,
|
||||||
|
// but also doesn't expose `Settings`. We can consider how to implement this in the future if required.
|
||||||
string[] Mods { get; set; }
|
|
||||||
|
|
||||||
public ScoreRank Rank { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,7 @@ namespace osu.Game.Scoring
|
|||||||
public RulesetInfo Ruleset { get; set; }
|
public RulesetInfo Ruleset { get; set; }
|
||||||
|
|
||||||
private APIMod[] localAPIMods;
|
private APIMod[] localAPIMods;
|
||||||
|
|
||||||
private Mod[] mods;
|
private Mod[] mods;
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
@ -160,7 +161,7 @@ namespace osu.Game.Scoring
|
|||||||
public DateTimeOffset Date { get; set; }
|
public DateTimeOffset Date { get; set; }
|
||||||
|
|
||||||
[JsonProperty("statistics")]
|
[JsonProperty("statistics")]
|
||||||
public Dictionary<HitResult, int> Statistics = new Dictionary<HitResult, int>();
|
public Dictionary<HitResult, int> Statistics { get; set; } = new Dictionary<HitResult, int>();
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
[Column("Statistics")]
|
[Column("Statistics")]
|
||||||
@ -273,5 +274,9 @@ namespace osu.Game.Scoring
|
|||||||
}
|
}
|
||||||
|
|
||||||
public long OnlineID => OnlineScoreID ?? -1;
|
public long OnlineID => OnlineScoreID ?? -1;
|
||||||
|
|
||||||
|
IBeatmapInfo IScoreInfo.Beatmap => BeatmapInfo;
|
||||||
|
IRulesetInfo IScoreInfo.Ruleset => Ruleset;
|
||||||
|
bool IScoreInfo.HasReplay => Files.Any();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ namespace osu.Game.Screens.Ranking
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
getScoreRequest = new GetScoresRequest(Score.BeatmapInfo, Score.Ruleset);
|
getScoreRequest = new GetScoresRequest(Score.BeatmapInfo, Score.Ruleset);
|
||||||
getScoreRequest.Success += r => scoresCallback?.Invoke(r.Scores.Where(s => s.OnlineScoreID != Score.OnlineScoreID).Select(s => s.CreateScoreInfo(rulesets)));
|
getScoreRequest.Success += r => scoresCallback?.Invoke(r.Scores.Where(s => s.OnlineID != Score.OnlineScoreID).Select(s => s.CreateScoreInfo(rulesets)));
|
||||||
return getScoreRequest;
|
return getScoreRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user