mirror of
https://github.com/ppy/osu
synced 2025-01-11 08:39:31 +00:00
Transfer flags indicating if settings were changed
This commit is contained in:
parent
9984c80c87
commit
303cc62ee7
@ -59,8 +59,8 @@ namespace osu.Game.Rulesets.Catch.Mods
|
||||
{
|
||||
base.ApplySettings(difficulty);
|
||||
|
||||
difficulty.CircleSize = CircleSize.Value;
|
||||
difficulty.ApproachRate = ApproachRate.Value;
|
||||
ApplySetting(CircleSize, cs => difficulty.CircleSize = cs);
|
||||
ApplySetting(ApproachRate, ar => difficulty.ApproachRate = ar);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -59,8 +59,8 @@ namespace osu.Game.Rulesets.Osu.Mods
|
||||
{
|
||||
base.ApplySettings(difficulty);
|
||||
|
||||
difficulty.CircleSize = CircleSize.Value;
|
||||
difficulty.ApproachRate = ApproachRate.Value;
|
||||
ApplySetting(CircleSize, cs => difficulty.CircleSize = cs);
|
||||
ApplySetting(ApproachRate, ar => difficulty.ApproachRate = ar);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -116,18 +116,30 @@ namespace osu.Game.Rulesets.Mods
|
||||
|
||||
internal override void CopyAdjustedSetting(IBindable target, object source)
|
||||
{
|
||||
userChangedSettings[target] = true;
|
||||
// if the value is non-bindable, it's presumably coming from an external source (like the API) - therefore presume it is not default.
|
||||
// if the value is bindable, defer to the source's IsDefault to be able to tell.
|
||||
userChangedSettings[target] = !(source is IBindable bindableSource) || !bindableSource.IsDefault;
|
||||
base.CopyAdjustedSetting(target, source);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies a setting from a configuration bindable using <paramref name="applyFunc"/>, if it has been changed by the user.
|
||||
/// </summary>
|
||||
protected void ApplySetting<T>(BindableNumber<T> setting, Action<T> applyFunc)
|
||||
where T : struct, IComparable<T>, IConvertible, IEquatable<T>
|
||||
{
|
||||
if (userChangedSettings.TryGetValue(setting, out bool userChangedSetting) && userChangedSetting)
|
||||
applyFunc.Invoke(setting.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply all custom settings to the provided beatmap.
|
||||
/// </summary>
|
||||
/// <param name="difficulty">The beatmap to have settings applied.</param>
|
||||
protected virtual void ApplySettings(BeatmapDifficulty difficulty)
|
||||
{
|
||||
difficulty.DrainRate = DrainRate.Value;
|
||||
difficulty.OverallDifficulty = OverallDifficulty.Value;
|
||||
ApplySetting(DrainRate, dr => difficulty.DrainRate = dr);
|
||||
ApplySetting(OverallDifficulty, od => difficulty.OverallDifficulty = od);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user