mirror of
https://github.com/ppy/osu
synced 2024-12-14 02:46:27 +00:00
Better handle Statistics to avoid losing data
This commit is contained in:
parent
76670a8faa
commit
13401a8846
@ -83,21 +83,22 @@ namespace osu.Game.Scoring
|
||||
|
||||
public RulesetInfo Ruleset { get; set; } = null!;
|
||||
|
||||
private Dictionary<HitResult, int>? statistics;
|
||||
|
||||
[Ignored]
|
||||
public Dictionary<HitResult, int> Statistics
|
||||
{
|
||||
// TODO: this is dangerous. a get operation may then modify the dictionary, which would be a fresh copy that is not persisted with the model.
|
||||
// this is already the case in multiple locations.
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(StatisticsJson))
|
||||
return new Dictionary<HitResult, int>();
|
||||
if (statistics != null)
|
||||
return statistics;
|
||||
|
||||
return JsonConvert.DeserializeObject<Dictionary<HitResult, int>>(StatisticsJson) ?? new Dictionary<HitResult, int>();
|
||||
if (!string.IsNullOrEmpty(StatisticsJson))
|
||||
statistics = JsonConvert.DeserializeObject<Dictionary<HitResult, int>>(StatisticsJson);
|
||||
|
||||
return statistics ??= new Dictionary<HitResult, int>();
|
||||
}
|
||||
// .. todo
|
||||
// ReSharper disable once ValueParameterNotUsed
|
||||
set => JsonConvert.SerializeObject(StatisticsJson);
|
||||
set => statistics = value;
|
||||
}
|
||||
|
||||
[MapTo("Statistics")]
|
||||
|
Loading…
Reference in New Issue
Block a user