1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 15:43:22 +08:00

Standardise naming and enable NRT

This commit is contained in:
Dean Herbert 2022-07-12 16:59:56 +09:00
parent 1bef2d7b39
commit 900e0ace8e

View File

@ -1,10 +1,8 @@
// 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.
#nullable disable
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
@ -17,54 +15,73 @@ using osu.Game.Scoring;
namespace osu.Game.Online.API.Requests.Responses
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
[Serializable]
public class SoloScoreInfo : IHasOnlineID<long>
{
[JsonIgnore]
public long id { get; set; }
[JsonProperty(" ")]
public long ID { get; set; }
public int user_id { get; set; }
[JsonProperty("beatmap_id")]
public int BeatmapID { get; set; }
public int beatmap_id { get; set; }
[JsonProperty("ruleset_id")]
public int RulesetID { get; set; }
public int ruleset_id { get; set; }
[JsonProperty("build_id")]
public int? BuildID { get; set; }
public int? build_id { get; set; }
[JsonProperty("passed")]
public bool Passed { get; set; }
public bool passed { get; set; }
[JsonProperty("total_score")]
public int TotalScore { get; set; }
public int total_score { get; set; }
[JsonProperty("accuracy")]
public double Accuracy { get; set; }
public double accuracy { get; set; }
[JsonProperty("user_id")]
public int UserID { get; set; }
public APIUser user { get; set; }
/// <summary>
/// User may be provided via an osu-web response, but will not be present from raw database json.
/// </summary>
[JsonProperty("user")]
public APIUser? User { get; set; }
// TODO: probably want to update this column to match user stats (short)?
public int max_combo { get; set; }
[JsonProperty("max_combo")]
public int MaxCombo { get; set; }
[JsonConverter(typeof(StringEnumConverter))]
public ScoreRank rank { get; set; }
[JsonProperty("rank")]
public ScoreRank Rank { get; set; }
public DateTimeOffset? started_at { get; set; }
[JsonProperty("started_at")]
public DateTimeOffset? StartedAt { get; set; }
public DateTimeOffset? ended_at { get; set; }
[JsonProperty("ended_at")]
public DateTimeOffset? EndedAt { get; set; }
public List<APIMod> mods { get; set; } = new List<APIMod>();
[JsonProperty("mods")]
public List<APIMod> Mods { get; set; } = new List<APIMod>();
[JsonIgnore]
[JsonProperty("created_at")]
public DateTimeOffset CreatedAt { get; set; }
[JsonIgnore]
[JsonProperty("updated_at")]
public DateTimeOffset UpdatedAt { get; set; }
[JsonIgnore]
[JsonProperty("deleted_at")]
public DateTimeOffset? DeletedAt { get; set; }
[JsonProperty("statistics")]
public Dictionary<HitResult, int> Statistics { get; set; } = new Dictionary<HitResult, int>();
public override string ToString() => $"score_id: {id} user_id: {user_id}";
[JsonIgnore]
public DateTimeOffset created_at { get; set; }
[JsonIgnore]
public DateTimeOffset updated_at { get; set; }
[JsonIgnore]
public DateTimeOffset? deleted_at { get; set; }
public override string ToString() => $"score_id: {ID} user_id: {UserID}";
/// <summary>
/// Create a <see cref="ScoreInfo"/> from an API score instance.
@ -72,53 +89,54 @@ namespace osu.Game.Online.API.Requests.Responses
/// <param name="rulesets">A ruleset store, used to populate a ruleset instance in the returned score.</param>
/// <param name="beatmap">An optional beatmap, copied into the returned score (for cases where the API does not populate the beatmap).</param>
/// <returns></returns>
public ScoreInfo CreateScoreInfo(RulesetStore rulesets, BeatmapInfo beatmap = null)
public ScoreInfo CreateScoreInfo(RulesetStore rulesets, BeatmapInfo? beatmap = null)
{
var ruleset = rulesets.GetRuleset(ruleset_id) ?? throw new InvalidOperationException($"Ruleset with ID of {ruleset_id} not found locally");
var ruleset = rulesets.GetRuleset(RulesetID) ?? throw new InvalidOperationException($"Ruleset with ID of {RulesetID} not found locally");
var rulesetInstance = ruleset.CreateInstance();
var modInstances = mods.Select(apiMod => rulesetInstance.CreateModFromAcronym(apiMod.Acronym)).Where(m => m != null).ToArray();
var modInstances = Mods.Select(apiMod => rulesetInstance.CreateModFromAcronym(apiMod.Acronym)).Where(m => m != null).ToArray();
// all API scores provided by this class are considered to be legacy.
modInstances = modInstances.Append(rulesetInstance.CreateMod<ModClassic>()).ToArray();
var scoreInfo = new ScoreInfo
{
User = user ?? new APIUser { Id = user_id },
BeatmapInfo = beatmap ?? new BeatmapInfo { OnlineID = beatmap_id },
Passed = passed,
TotalScore = total_score,
Accuracy = accuracy,
MaxCombo = max_combo,
Rank = rank,
Statistics = Statistics,
OnlineID = OnlineID,
Date = ended_at ?? DateTimeOffset.Now,
// PP =
Hash = "online", // TODO: temporary?
User = User ?? new APIUser { Id = UserID },
BeatmapInfo = beatmap ?? new BeatmapInfo { OnlineID = BeatmapID },
Ruleset = ruleset,
Passed = Passed,
TotalScore = TotalScore,
Accuracy = Accuracy,
MaxCombo = MaxCombo,
Rank = Rank,
Statistics = Statistics,
Date = EndedAt ?? DateTimeOffset.Now,
Hash = "online", // TODO: temporary?
Mods = modInstances,
};
return scoreInfo;
}
public ScoreInfo CreateScoreInfo(Mod[] mods) => new ScoreInfo
public ScoreInfo ToScoreInfo(Mod[] mods) => new ScoreInfo
{
OnlineID = id,
User = new APIUser { Id = user_id },
BeatmapInfo = new BeatmapInfo { OnlineID = beatmap_id },
Ruleset = new RulesetInfo { OnlineID = ruleset_id },
Passed = passed,
TotalScore = total_score,
Accuracy = accuracy,
MaxCombo = max_combo,
Rank = rank,
OnlineID = ID,
User = new APIUser { Id = UserID },
BeatmapInfo = new BeatmapInfo { OnlineID = BeatmapID },
Ruleset = new RulesetInfo { OnlineID = RulesetID },
Passed = Passed,
TotalScore = TotalScore,
Accuracy = Accuracy,
MaxCombo = MaxCombo,
Rank = Rank,
Statistics = Statistics,
Date = EndedAt ?? DateTimeOffset.Now,
Hash = "online", // TODO: temporary?
Mods = mods,
Statistics = Statistics
};
public long OnlineID => id;
public long OnlineID => ID;
}
}