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

Add support for persisting score's mods to realm

This commit is contained in:
Dean Herbert 2022-01-10 14:18:34 +09:00
parent af5d3af664
commit ae8f522c20

View File

@ -183,6 +183,10 @@ namespace osu.Game.Scoring
[Ignored]
public bool IsLegacyScore => Mods.OfType<ModClassic>().Any();
// Used for database serialisation/deserialisation.
[MapTo("Mods")]
public string ModsJson { get; set; } = string.Empty;
[Ignored]
public Mod[] Mods
{
@ -203,6 +207,7 @@ namespace osu.Game.Scoring
{
localAPIMods = null;
mods = value;
ModsJson = JsonConvert.SerializeObject(APIMods);
}
}
@ -212,13 +217,18 @@ namespace osu.Game.Scoring
{
get
{
if (localAPIMods != null)
return localAPIMods;
if (localAPIMods == null)
{
// prioritise reading from realm backing
if (!string.IsNullOrEmpty(ModsJson))
localAPIMods = JsonConvert.DeserializeObject<APIMod[]>(ModsJson);
if (mods == null)
return Array.Empty<APIMod>();
// then check mods set via Mods property.
if (mods != null)
localAPIMods = mods.Select(m => new APIMod(m)).ToArray();
}
return localAPIMods = mods.Select(m => new APIMod(m)).ToArray();
return localAPIMods ?? Array.Empty<APIMod>();
}
set
{
@ -226,6 +236,7 @@ namespace osu.Game.Scoring
// We potentially can't update this yet due to Ruleset being late-bound, so instead update on read as necessary.
mods = null;
ModsJson = JsonConvert.SerializeObject(APIMods);
}
}