Merge branch 'master' into mod-using-reference-equality

This commit is contained in:
Salman Ahmed
2021-04-11 19:48:55 +03:00
committed by GitHub
987 changed files with 29392 additions and 7538 deletions

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Humanizer;
using MessagePack;
using Newtonsoft.Json;
using osu.Framework.Bindables;
using osu.Game.Configuration;
@ -13,16 +14,21 @@ using osu.Game.Rulesets.Mods;
namespace osu.Game.Online.API
{
[MessagePackObject]
public class APIMod : IMod, IEquatable<APIMod>
{
[JsonProperty("acronym")]
[Key(0)]
public string Acronym { get; set; }
[JsonProperty("settings")]
[Key(1)]
[MessagePackFormatter(typeof(ModSettingsDictionaryFormatter))]
public Dictionary<string, object> Settings { get; set; } = new Dictionary<string, object>();
[JsonConstructor]
private APIMod()
[SerializationConstructor]
public APIMod()
{
}
@ -31,7 +37,12 @@ namespace osu.Game.Online.API
Acronym = mod.Acronym;
foreach (var (_, property) in mod.GetSettingsSourceProperties())
Settings.Add(property.Name.Underscore(), property.GetValue(mod));
{
var bindable = (IBindable)property.GetValue(mod);
if (!bindable.IsDefault)
Settings.Add(property.Name.Underscore(), bindable);
}
}
public Mod ToMod(Ruleset ruleset)
@ -46,7 +57,7 @@ namespace osu.Game.Online.API
if (!Settings.TryGetValue(property.Name.Underscore(), out object settingValue))
continue;
((IBindable)property.GetValue(resultMod)).Parse(settingValue);
resultMod.CopyAdjustedSetting((IBindable)property.GetValue(resultMod), settingValue);
}
return resultMod;