mirror of
https://github.com/osukey/osukey.git
synced 2025-08-08 09:03:50 +09:00
Better handle Statistics to avoid losing data
This commit is contained in:
@ -83,21 +83,22 @@ namespace osu.Game.Scoring
|
|||||||
|
|
||||||
public RulesetInfo Ruleset { get; set; } = null!;
|
public RulesetInfo Ruleset { get; set; } = null!;
|
||||||
|
|
||||||
|
private Dictionary<HitResult, int>? statistics;
|
||||||
|
|
||||||
[Ignored]
|
[Ignored]
|
||||||
public Dictionary<HitResult, int> Statistics
|
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
|
get
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(StatisticsJson))
|
if (statistics != null)
|
||||||
return new Dictionary<HitResult, int>();
|
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
|
set => statistics = value;
|
||||||
// ReSharper disable once ValueParameterNotUsed
|
|
||||||
set => JsonConvert.SerializeObject(StatisticsJson);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[MapTo("Statistics")]
|
[MapTo("Statistics")]
|
||||||
|
Reference in New Issue
Block a user