Fix incorrect `DifficultyBindable` logic

This commit is contained in:
Bartłomiej Dach 2024-07-30 08:17:35 +02:00
parent ae38e66036
commit 6813f5ee0a
No known key found for this signature in database
1 changed files with 13 additions and 2 deletions

View File

@ -38,6 +38,7 @@ public float Precision
public float MinValue
{
get => minValue;
set
{
if (value == minValue)
@ -52,6 +53,7 @@ public float MinValue
public float MaxValue
{
get => maxValue;
set
{
if (value == maxValue)
@ -69,6 +71,7 @@ public float MaxValue
/// </summary>
public float? ExtendedMinValue
{
get => extendedMinValue;
set
{
if (value == extendedMinValue)
@ -86,6 +89,7 @@ public float? ExtendedMinValue
/// </summary>
public float? ExtendedMaxValue
{
get => extendedMaxValue;
set
{
if (value == extendedMaxValue)
@ -114,9 +118,14 @@ public override float? Value
{
// Ensure that in the case serialisation runs in the wrong order (and limit extensions aren't applied yet) the deserialised value is still propagated.
if (value != null)
CurrentNumber.MaxValue = MathF.Max(CurrentNumber.MaxValue, value.Value);
{
CurrentNumber.MinValue = Math.Clamp(MathF.Min(CurrentNumber.MinValue, value.Value), ExtendedMinValue ?? MinValue, MinValue);
CurrentNumber.MaxValue = Math.Clamp(MathF.Max(CurrentNumber.MaxValue, value.Value), MaxValue, ExtendedMaxValue ?? MaxValue);
base.Value = value;
base.Value = Math.Clamp(value.Value, CurrentNumber.MinValue, CurrentNumber.MaxValue);
}
else
base.Value = value;
}
}
@ -138,6 +147,8 @@ public override void CopyTo(Bindable<float?> them)
// the following max value copies are only safe as long as these values are effectively constants.
otherDifficultyBindable.MaxValue = maxValue;
otherDifficultyBindable.ExtendedMaxValue = extendedMaxValue;
otherDifficultyBindable.MinValue = minValue;
otherDifficultyBindable.ExtendedMinValue = extendedMinValue;
}
public override void BindTo(Bindable<float?> them)