1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 05:22:54 +08:00

Merge pull request #13860 from smoogipoo/fix-bindable-ctor

Fix DifficultyBindable not binding correctly and not having default ctor
This commit is contained in:
Dean Herbert 2021-07-13 13:42:44 +09:00 committed by GitHub
commit 5cff379cd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 12 deletions

View File

@ -52,7 +52,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.706.0" /> <PackageReference Include="ppy.osu.Game.Resources" Version="2021.706.0" />
<PackageReference Include="ppy.osu.Framework.Android" Version="2021.707.0" /> <PackageReference Include="ppy.osu.Framework.Android" Version="2021.713.0" />
</ItemGroup> </ItemGroup>
<ItemGroup Label="Transitive Dependencies"> <ItemGroup Label="Transitive Dependencies">
<!-- Realm needs to be directly referenced in all Xamarin projects, as it will not pull in its transitive dependencies otherwise. --> <!-- Realm needs to be directly referenced in all Xamarin projects, as it will not pull in its transitive dependencies otherwise. -->

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,33 @@ 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 override void UnbindFrom(IUnbindable them)
{
if (!(them is DifficultyBindable otherDifficultyBindable))
throw new InvalidOperationException($"Cannot unbind from a non-{nameof(DifficultyBindable)}.");
base.UnbindFrom(them);
CurrentNumber.UnbindFrom(otherDifficultyBindable.CurrentNumber);
ExtendedLimits.UnbindFrom(otherDifficultyBindable.ExtendedLimits);
}
public new DifficultyBindable GetBoundCopy() => new DifficultyBindable { BindTarget = this };
} }
} }

View File

@ -36,7 +36,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<PackageReference Include="Realm" Version="10.3.0" /> <PackageReference Include="Realm" Version="10.3.0" />
<PackageReference Include="ppy.osu.Framework" Version="2021.707.0" /> <PackageReference Include="ppy.osu.Framework" Version="2021.713.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.706.0" /> <PackageReference Include="ppy.osu.Game.Resources" Version="2021.706.0" />
<PackageReference Include="Sentry" Version="3.6.0" /> <PackageReference Include="Sentry" Version="3.6.0" />
<PackageReference Include="SharpCompress" Version="0.28.3" /> <PackageReference Include="SharpCompress" Version="0.28.3" />

View File

@ -70,7 +70,7 @@
<Reference Include="System.Net.Http" /> <Reference Include="System.Net.Http" />
</ItemGroup> </ItemGroup>
<ItemGroup Label="Package References"> <ItemGroup Label="Package References">
<PackageReference Include="ppy.osu.Framework.iOS" Version="2021.707.0" /> <PackageReference Include="ppy.osu.Framework.iOS" Version="2021.713.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.706.0" /> <PackageReference Include="ppy.osu.Game.Resources" Version="2021.706.0" />
</ItemGroup> </ItemGroup>
<!-- See https://github.com/dotnet/runtime/issues/35988 (can be removed after Xamarin uses net5.0 / net6.0) --> <!-- See https://github.com/dotnet/runtime/issues/35988 (can be removed after Xamarin uses net5.0 / net6.0) -->
@ -93,7 +93,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="ppy.osu.Framework" Version="2021.707.0" /> <PackageReference Include="ppy.osu.Framework" Version="2021.713.0" />
<PackageReference Include="SharpCompress" Version="0.28.3" /> <PackageReference Include="SharpCompress" Version="0.28.3" />
<PackageReference Include="NUnit" Version="3.13.2" /> <PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="SharpRaven" Version="2.4.0" /> <PackageReference Include="SharpRaven" Version="2.4.0" />