mirror of
https://github.com/ppy/osu.git
synced 2025-03-15 15:27:20 +08:00
Add helper method to make direct casts be used
This commit is contained in:
parent
c0bcbfd892
commit
bda21998c4
@ -111,7 +111,7 @@ namespace osu.Game.Rulesets.Osu.Skinning
|
||||
{
|
||||
case OsuSkinConfiguration.SliderPathRadius:
|
||||
if (hasHitCircle.Value)
|
||||
return new BindableFloat(legacy_circle_radius) as Bindable<TValue>;
|
||||
return SkinUtils.As<TValue>(new BindableFloat(legacy_circle_radius));
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -95,6 +95,25 @@ namespace osu.Game.Tests.Skins
|
||||
AddAssert("Check combo colours", () => requester.GetConfig<GlobalSkinConfiguration, List<Color4>>(GlobalSkinConfiguration.ComboColours)?.Value?.Count > 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestWrongColourType()
|
||||
{
|
||||
AddStep("Add config colour", () => { source1.Configuration.CustomColours["Lookup"] = Color4.Red; });
|
||||
|
||||
AddAssert("perform incorrect lookup", () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
requester.GetConfig<SkinCustomColourLookup, int>(new SkinCustomColourLookup("Lookup"));
|
||||
return false;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public enum LookupType
|
||||
{
|
||||
Test
|
||||
|
@ -62,16 +62,16 @@ namespace osu.Game.Skinning
|
||||
switch (global)
|
||||
{
|
||||
case GlobalSkinConfiguration.ComboColours:
|
||||
return new Bindable<List<Color4>>(Configuration.ComboColours) as IBindable<TValue>;
|
||||
return SkinUtils.As<TValue>(new Bindable<List<Color4>>(Configuration.ComboColours));
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case GlobalSkinColour colour:
|
||||
return getCustomColour(colour.ToString()) as IBindable<TValue>;
|
||||
return SkinUtils.As<TValue>(getCustomColour(colour.ToString()));
|
||||
|
||||
case SkinCustomColourLookup customColour:
|
||||
return getCustomColour(customColour.Lookup.ToString()) as IBindable<TValue>;
|
||||
return SkinUtils.As<TValue>(getCustomColour(customColour.Lookup.ToString()));
|
||||
|
||||
default:
|
||||
try
|
||||
|
18
osu.Game/Skinning/SkinUtils.cs
Normal file
18
osu.Game/Skinning/SkinUtils.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using osu.Framework.Bindables;
|
||||
|
||||
namespace osu.Game.Skinning
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains helper methods to assist in implementing <see cref="ISkin"/>s.
|
||||
/// </summary>
|
||||
public static class SkinUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts an <see cref="object"/> to a <see cref="Bindable{TValue}"/>. Used for returning configuration values of specific types.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <typeparam name="TValue">The type of value <paramref name="value"/>, and the type of the resulting bindable.</typeparam>
|
||||
/// <returns>The resulting bindable.</returns>
|
||||
public static Bindable<TValue> As<TValue>(object value) => (Bindable<TValue>)value;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user