mirror of
https://github.com/ppy/osu.git
synced 2025-01-27 02:32:59 +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.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.Beatmaps;
|
||||
@ -148,6 +149,16 @@ namespace osu.Game.Tests.Online
|
||||
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
|
||||
{
|
||||
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.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
@ -23,7 +20,7 @@ namespace osu.Game.Online.API
|
||||
{
|
||||
[JsonProperty("acronym")]
|
||||
[Key(0)]
|
||||
public string Acronym { get; set; }
|
||||
public string Acronym { get; set; } = string.Empty;
|
||||
|
||||
[JsonProperty("settings")]
|
||||
[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);
|
||||
|
||||
@ -80,6 +77,8 @@ namespace osu.Game.Online.API
|
||||
return resultMod;
|
||||
}
|
||||
|
||||
public bool ShouldSerializeSettings() => Settings.Count > 0;
|
||||
|
||||
public bool Equals(APIMod other)
|
||||
{
|
||||
if (ReferenceEquals(null, other)) return false;
|
||||
|
Loading…
Reference in New Issue
Block a user