1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-26 18:52:55 +08:00

Fix incorrect DifficultyBindable binding implementation

This commit is contained in:
smoogipoo 2021-07-12 16:52:57 +09:00
parent d5d7dd0e74
commit 242982730f

View File

@ -71,6 +71,12 @@ namespace osu.Game.Rulesets.Mods
} }
public DifficultyBindable() public DifficultyBindable()
: this(null)
{
}
public DifficultyBindable(float? defaultValue = null)
: base(defaultValue)
{ {
ExtendedLimits.BindValueChanged(_ => updateMaxValue()); ExtendedLimits.BindValueChanged(_ => updateMaxValue());
} }
@ -93,15 +99,22 @@ namespace osu.Game.Rulesets.Mods
CurrentNumber.MaxValue = ExtendedLimits.Value && extendedMaxValue != null ? extendedMaxValue.Value : maxValue; CurrentNumber.MaxValue = ExtendedLimits.Value && extendedMaxValue != null ? extendedMaxValue.Value : maxValue;
} }
public new DifficultyBindable GetBoundCopy() => new DifficultyBindable public override void BindTo(Bindable<float?> them)
{ {
BindTarget = this, if (!(them is DifficultyBindable otherDifficultyBindable))
CurrentNumber = { BindTarget = CurrentNumber }, throw new InvalidOperationException($"Cannot bind to a non-{nameof(DifficultyBindable)}.");
ExtendedLimits = { BindTarget = ExtendedLimits },
ReadCurrentFromDifficulty = ReadCurrentFromDifficulty, base.BindTo(them);
CurrentNumber.BindTarget = otherDifficultyBindable.CurrentNumber;
ExtendedLimits.BindTarget = otherDifficultyBindable.ExtendedLimits;
ReadCurrentFromDifficulty = otherDifficultyBindable.ReadCurrentFromDifficulty;
// the following is only safe as long as these values are effectively constants. // the following is only safe as long as these values are effectively constants.
MaxValue = maxValue, MaxValue = otherDifficultyBindable.maxValue;
ExtendedMaxValue = extendedMaxValue ExtendedMaxValue = otherDifficultyBindable.extendedMaxValue;
}; }
public new DifficultyBindable GetBoundCopy() => new DifficultyBindable { BindTarget = this };
} }
} }