mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 15:07:44 +08:00
Add internal pathway for ensuring correct application of bindable mods
This commit is contained in:
parent
23e216fa0b
commit
29dbb1cc0d
@ -51,7 +51,7 @@ namespace osu.Game.Online.API
|
|||||||
if (!Settings.TryGetValue(property.Name.Underscore(), out object settingValue))
|
if (!Settings.TryGetValue(property.Name.Underscore(), out object settingValue))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
((IBindable)property.GetValue(resultMod)).Parse(settingValue);
|
resultMod.CopyAdjustedSetting((IBindable)property.GetValue(resultMod), settingValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
return resultMod;
|
return resultMod;
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
@ -134,19 +133,25 @@ namespace osu.Game.Rulesets.Mods
|
|||||||
// Copy bindable values across
|
// Copy bindable values across
|
||||||
foreach (var (_, prop) in this.GetSettingsSourceProperties())
|
foreach (var (_, prop) in this.GetSettingsSourceProperties())
|
||||||
{
|
{
|
||||||
var origBindable = prop.GetValue(this);
|
var origBindable = (IBindable)prop.GetValue(this);
|
||||||
var copyBindable = prop.GetValue(copy);
|
var copyBindable = (IBindable)prop.GetValue(copy);
|
||||||
|
|
||||||
// The bindables themselves are readonly, so the value must be transferred through the Bindable<T>.Value property.
|
// we only care about changes that have been made away from defaults.
|
||||||
var valueProperty = origBindable.GetType().GetProperty(nameof(Bindable<object>.Value), BindingFlags.Public | BindingFlags.Instance);
|
if (!origBindable.IsDefault)
|
||||||
Debug.Assert(valueProperty != null);
|
copy.CopyAdjustedSetting(copyBindable, origBindable);
|
||||||
|
|
||||||
valueProperty.SetValue(copyBindable, valueProperty.GetValue(origBindable));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// When creating copies or clones of a Mod, this method will be called to copy explicitly adjusted user settings.
|
||||||
|
/// The base implementation will transfer the value via <see cref="Bindable{T}.Parse"/> and should be called unless replaced with custom logic.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="bindable">The target bindable to apply the adjustment.</param>
|
||||||
|
/// <param name="value">The adjustment to apply.</param>
|
||||||
|
internal virtual void CopyAdjustedSetting(IBindable bindable, object value) => bindable.Parse(value);
|
||||||
|
|
||||||
public bool Equals(IMod other) => GetType() == other?.GetType();
|
public bool Equals(IMod other) => GetType() == other?.GetType();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,6 +114,12 @@ namespace osu.Game.Rulesets.Mods
|
|||||||
bindable.ValueChanged += _ => userChangedSettings[bindable] = !bindable.IsDefault;
|
bindable.ValueChanged += _ => userChangedSettings[bindable] = !bindable.IsDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal override void CopyAdjustedSetting(IBindable bindable, object value)
|
||||||
|
{
|
||||||
|
userChangedSettings[bindable] = true;
|
||||||
|
base.CopyAdjustedSetting(bindable, value);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Apply all custom settings to the provided beatmap.
|
/// Apply all custom settings to the provided beatmap.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user