2021-06-09 15:13:00 +08:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2022-06-17 15:37:17 +08:00
#nullable disable
2021-06-09 15:13:00 +08:00
using System ;
using NUnit.Framework ;
using osu.Framework.Allocation ;
using osu.Framework.Audio.Sample ;
using osu.Framework.Bindables ;
using osu.Framework.Graphics ;
using osu.Framework.Graphics.Containers ;
using osu.Framework.Graphics.Textures ;
using osu.Framework.Testing ;
using osu.Game.Audio ;
using osu.Game.Configuration ;
using osu.Game.Rulesets.Osu ;
using osu.Game.Skinning ;
using osu.Game.Tests.Beatmaps ;
using osu.Game.Tests.Visual ;
namespace osu.Game.Tests.Skins
{
[TestFixture]
[HeadlessTest]
public class TestSceneBeatmapSkinLookupDisables : OsuTestScene
{
private UserSkinSource userSource ;
private BeatmapSkinSource beatmapSource ;
private SkinRequester requester ;
[Resolved]
private OsuConfigManager config { get ; set ; }
[SetUp]
public void SetUp ( ) = > Schedule ( ( ) = >
{
Add ( new SkinProvidingContainer ( userSource = new UserSkinSource ( ) )
. WithChild ( new BeatmapSkinProvidingContainer ( beatmapSource = new BeatmapSkinSource ( ) )
. WithChild ( requester = new SkinRequester ( ) ) ) ) ;
} ) ;
[TestCase(false)]
[TestCase(true)]
public void TestDrawableLookup ( bool allowBeatmapLookups )
{
AddStep ( $"Set beatmap skin enabled to {allowBeatmapLookups}" , ( ) = > config . SetValue ( OsuSetting . BeatmapSkins , allowBeatmapLookups ) ) ;
string expected = allowBeatmapLookups ? "beatmap" : "user" ;
2022-11-09 15:04:56 +08:00
AddAssert ( $"Check lookup is from {expected}" , ( ) = > requester . GetDrawableComponent ( new TestSkinComponentLookup ( ) ) ? . Name = = expected ) ;
2021-06-09 15:13:00 +08:00
}
[TestCase(false)]
[TestCase(true)]
public void TestProviderLookup ( bool allowBeatmapLookups )
{
AddStep ( $"Set beatmap skin enabled to {allowBeatmapLookups}" , ( ) = > config . SetValue ( OsuSetting . BeatmapSkins , allowBeatmapLookups ) ) ;
2022-06-24 13:48:43 +08:00
ISkin expected ( ) = > allowBeatmapLookups ? beatmapSource : userSource ;
2021-06-09 15:13:00 +08:00
2022-11-09 15:04:56 +08:00
AddAssert ( "Check lookup is from correct source" , ( ) = > requester . FindProvider ( s = > s . GetDrawableComponent ( new TestSkinComponentLookup ( ) ) ! = null ) = = expected ( ) ) ;
2021-06-09 15:13:00 +08:00
}
public class UserSkinSource : LegacySkin
{
public UserSkinSource ( )
: base ( new SkinInfo ( ) , null , null , string . Empty )
{
}
2022-11-09 15:04:56 +08:00
public override Drawable GetDrawableComponent ( ISkinComponentLookup lookup )
2021-06-09 15:13:00 +08:00
{
return new Container { Name = "user" } ;
}
}
public class BeatmapSkinSource : LegacyBeatmapSkin
{
public BeatmapSkinSource ( )
2022-03-22 18:23:22 +08:00
: base ( new TestBeatmap ( new OsuRuleset ( ) . RulesetInfo ) . BeatmapInfo , null )
2021-06-09 15:13:00 +08:00
{
}
2022-11-09 15:04:56 +08:00
public override Drawable GetDrawableComponent ( ISkinComponentLookup lookup )
2021-06-09 15:13:00 +08:00
{
return new Container { Name = "beatmap" } ;
}
}
public class SkinRequester : Drawable , ISkin
{
private ISkinSource skin ;
[BackgroundDependencyLoader]
private void load ( ISkinSource skin )
{
this . skin = skin ;
}
2022-11-09 15:04:56 +08:00
public Drawable GetDrawableComponent ( ISkinComponentLookup lookup ) = > skin . GetDrawableComponent ( lookup ) ;
2021-06-09 15:13:00 +08:00
public Texture GetTexture ( string componentName , WrapMode wrapModeS , WrapMode wrapModeT ) = > skin . GetTexture ( componentName , wrapModeS , wrapModeT ) ;
public ISample GetSample ( ISampleInfo sampleInfo ) = > skin . GetSample ( sampleInfo ) ;
public IBindable < TValue > GetConfig < TLookup , TValue > ( TLookup lookup ) = > skin . GetConfig < TLookup , TValue > ( lookup ) ;
public ISkin FindProvider ( Func < ISkin , bool > lookupFunction ) = > skin . FindProvider ( lookupFunction ) ;
}
2022-11-09 15:04:56 +08:00
private class TestSkinComponentLookup : ISkinComponentLookup
2021-06-09 15:13:00 +08:00
{
public string LookupName = > string . Empty ;
}
}
}