1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 15:47:26 +08:00

Merge pull request #19939 from smoogipoo/maximum-statistics-2

Add `maximum_statistics` to `ScoreInfo`
This commit is contained in:
Salman Ahmed 2022-08-25 09:45:33 +03:00 committed by GitHub
commit bb0701c457
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 7 deletions

View File

@ -69,8 +69,9 @@ namespace osu.Game.Database
/// 21 2022-07-27 Migrate collections to realm (BeatmapCollection).
/// 22 2022-07-31 Added ModPreset.
/// 23 2022-08-01 Added LastLocalUpdate to BeatmapInfo.
/// 24 2022-08-22 Added MaximumStatistics to ScoreInfo.
/// </summary>
private const int schema_version = 23;
private const int schema_version = 24;
/// <summary>
/// Lock object which is held during <see cref="BlockAllOperations"/> sections, blocking realm retrieval during blocking periods.

View File

@ -74,6 +74,9 @@ namespace osu.Game.Online.API.Requests.Responses
[JsonProperty("statistics")]
public Dictionary<HitResult, int> Statistics { get; set; } = new Dictionary<HitResult, int>();
[JsonProperty("maximum_statistics")]
public Dictionary<HitResult, int> MaximumStatistics { get; set; } = new Dictionary<HitResult, int>();
#region osu-web API additions (not stored to database).
[JsonProperty("id")]
@ -153,6 +156,7 @@ namespace osu.Game.Online.API.Requests.Responses
MaxCombo = MaxCombo,
Rank = Rank,
Statistics = Statistics,
MaximumStatistics = MaximumStatistics,
Date = EndedAt,
Hash = HasReplay ? "online" : string.Empty, // TODO: temporary?
Mods = mods,
@ -174,6 +178,7 @@ namespace osu.Game.Online.API.Requests.Responses
Passed = score.Passed,
Mods = score.APIMods,
Statistics = score.Statistics.Where(kvp => kvp.Value != 0).ToDictionary(kvp => kvp.Key, kvp => kvp.Value),
MaximumStatistics = score.MaximumStatistics.Where(kvp => kvp.Value != 0).ToDictionary(kvp => kvp.Key, kvp => kvp.Value),
};
public long OnlineID => ID ?? -1;

View File

@ -128,8 +128,7 @@ namespace osu.Game.Rulesets.Scoring
private bool beatmapApplied;
private readonly Dictionary<HitResult, int> scoreResultCounts = new Dictionary<HitResult, int>();
private Dictionary<HitResult, int>? maximumResultCounts;
private readonly Dictionary<HitResult, int> maximumResultCounts = new Dictionary<HitResult, int>();
private readonly List<HitEvent> hitEvents = new List<HitEvent>();
private HitObject? lastHitObject;
@ -405,8 +404,6 @@ namespace osu.Game.Rulesets.Scoring
return ScoreRank.D;
}
public int GetStatistic(HitResult result) => scoreResultCounts.GetValueOrDefault(result);
/// <summary>
/// Resets this ScoreProcessor to a default state.
/// </summary>
@ -421,7 +418,9 @@ namespace osu.Game.Rulesets.Scoring
if (storeResults)
{
maximumScoringValues = currentScoringValues;
maximumResultCounts = new Dictionary<HitResult, int>(scoreResultCounts);
maximumResultCounts.Clear();
maximumResultCounts.AddRange(scoreResultCounts);
}
scoreResultCounts.Clear();
@ -449,7 +448,10 @@ namespace osu.Game.Rulesets.Scoring
score.HitEvents = hitEvents;
foreach (var result in HitResultExtensions.ALL_TYPES)
score.Statistics[result] = GetStatistic(result);
score.Statistics[result] = scoreResultCounts.GetValueOrDefault(result);
foreach (var result in HitResultExtensions.ALL_TYPES)
score.MaximumStatistics[result] = maximumResultCounts.GetValueOrDefault(result);
// Populate total score after everything else.
score.TotalScore = (long)Math.Round(ComputeFinalScore(ScoringMode.Standardised, score));

View File

@ -73,6 +73,9 @@ namespace osu.Game.Scoring
if (string.IsNullOrEmpty(model.StatisticsJson))
model.StatisticsJson = JsonConvert.SerializeObject(model.Statistics);
if (string.IsNullOrEmpty(model.MaximumStatisticsJson))
model.MaximumStatisticsJson = JsonConvert.SerializeObject(model.MaximumStatistics);
}
protected override void PostImport(ScoreInfo model, Realm realm, bool batchImport)

View File

@ -63,6 +63,9 @@ namespace osu.Game.Scoring
[MapTo("Statistics")]
public string StatisticsJson { get; set; } = string.Empty;
[MapTo("MaximumStatistics")]
public string MaximumStatisticsJson { get; set; } = string.Empty;
public ScoreInfo(BeatmapInfo? beatmap = null, RulesetInfo? ruleset = null, RealmUser? realmUser = null)
{
Ruleset = ruleset ?? new RulesetInfo();
@ -133,6 +136,7 @@ namespace osu.Game.Scoring
var clone = (ScoreInfo)this.Detach().MemberwiseClone();
clone.Statistics = new Dictionary<HitResult, int>(clone.Statistics);
clone.MaximumStatistics = new Dictionary<HitResult, int>(clone.MaximumStatistics);
clone.RealmUser = new RealmUser
{
OnlineID = RealmUser.OnlineID,
@ -181,6 +185,24 @@ namespace osu.Game.Scoring
set => statistics = value;
}
private Dictionary<HitResult, int>? maximumStatistics;
[Ignored]
public Dictionary<HitResult, int> MaximumStatistics
{
get
{
if (maximumStatistics != null)
return maximumStatistics;
if (!string.IsNullOrEmpty(MaximumStatisticsJson))
maximumStatistics = JsonConvert.DeserializeObject<Dictionary<HitResult, int>>(MaximumStatisticsJson);
return maximumStatistics ??= new Dictionary<HitResult, int>();
}
set => maximumStatistics = value;
}
private Mod[]? mods;
[Ignored]