mirror of
https://github.com/ppy/osu.git
synced 2025-02-05 11:42:55 +08:00
Don't serialise empty mod settings
This commit is contained in:
parent
55234e8069
commit
0de00e9b3f
@ -6,6 +6,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
@ -148,6 +149,16 @@ namespace osu.Game.Tests.Online
|
|||||||
Assert.That(apiMod.Settings["speed_change"], Is.EqualTo(1.01d));
|
Assert.That(apiMod.Settings["speed_change"], Is.EqualTo(1.01d));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestSerialisedModSettingPresence()
|
||||||
|
{
|
||||||
|
var mod = new TestMod();
|
||||||
|
|
||||||
|
mod.TestSetting.Value = mod.TestSetting.Default;
|
||||||
|
JObject serialised = JObject.Parse(JsonConvert.SerializeObject(new APIMod(mod)));
|
||||||
|
Assert.False(serialised.ContainsKey("settings"));
|
||||||
|
}
|
||||||
|
|
||||||
private class TestRuleset : Ruleset
|
private class TestRuleset : Ruleset
|
||||||
{
|
{
|
||||||
public override IEnumerable<Mod> GetModsFor(ModType type) => new Mod[]
|
public override IEnumerable<Mod> GetModsFor(ModType type) => new Mod[]
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using MessagePack;
|
using MessagePack;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
@ -23,7 +20,7 @@ namespace osu.Game.Online.API
|
|||||||
{
|
{
|
||||||
[JsonProperty("acronym")]
|
[JsonProperty("acronym")]
|
||||||
[Key(0)]
|
[Key(0)]
|
||||||
public string Acronym { get; set; }
|
public string Acronym { get; set; } = string.Empty;
|
||||||
|
|
||||||
[JsonProperty("settings")]
|
[JsonProperty("settings")]
|
||||||
[Key(1)]
|
[Key(1)]
|
||||||
@ -49,7 +46,7 @@ namespace osu.Game.Online.API
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Mod ToMod([NotNull] Ruleset ruleset)
|
public Mod ToMod(Ruleset ruleset)
|
||||||
{
|
{
|
||||||
Mod resultMod = ruleset.CreateModFromAcronym(Acronym);
|
Mod resultMod = ruleset.CreateModFromAcronym(Acronym);
|
||||||
|
|
||||||
@ -80,6 +77,8 @@ namespace osu.Game.Online.API
|
|||||||
return resultMod;
|
return resultMod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool ShouldSerializeSettings() => Settings.Count > 0;
|
||||||
|
|
||||||
public bool Equals(APIMod other)
|
public bool Equals(APIMod other)
|
||||||
{
|
{
|
||||||
if (ReferenceEquals(null, other)) return false;
|
if (ReferenceEquals(null, other)) return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user