1
0
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:
smoogipoo 2019-09-05 16:39:58 +09:00
parent c0bcbfd892
commit bda21998c4
4 changed files with 41 additions and 4 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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

View 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;
}
}