2021-06-25 09:22:34 +03:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2021-06-25 11:16:26 +03:00
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2021-06-25 09:22:34 +03: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.OpenGL.Textures;
|
|
|
|
using osu.Framework.Graphics.Textures;
|
|
|
|
using osu.Game.Audio;
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using osu.Game.Skinning;
|
|
|
|
using osu.Game.Tests.Testing;
|
|
|
|
using osu.Game.Tests.Visual;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Rulesets
|
|
|
|
{
|
|
|
|
public class TestSceneRulesetSkinProvidingContainer : OsuTestScene
|
|
|
|
{
|
|
|
|
private SkinRequester requester;
|
|
|
|
|
2021-06-25 12:00:46 +03:00
|
|
|
[Cached(typeof(ISkin))]
|
|
|
|
private readonly TestSkinProvider testSkin = new TestSkinProvider();
|
|
|
|
|
2021-06-25 10:55:23 +03:00
|
|
|
protected override Ruleset CreateRuleset() => new TestSceneRulesetDependencies.TestRuleset();
|
2021-06-25 09:22:34 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestEarlyAddedSkinRequester()
|
|
|
|
{
|
2021-06-25 10:55:23 +03:00
|
|
|
Texture textureOnLoad = null;
|
2021-06-25 09:22:34 +03:00
|
|
|
|
|
|
|
AddStep("setup provider", () =>
|
|
|
|
{
|
|
|
|
var rulesetSkinProvider = new RulesetSkinProvidingContainer(Ruleset.Value.CreateInstance(), Beatmap.Value.Beatmap, Beatmap.Value.Skin);
|
|
|
|
|
|
|
|
rulesetSkinProvider.Add(requester = new SkinRequester());
|
|
|
|
|
2021-06-25 12:00:46 +03:00
|
|
|
requester.OnLoadAsync += () => textureOnLoad = requester.GetTexture(TestSkinProvider.TEXTURE_NAME);
|
2021-06-25 09:22:34 +03:00
|
|
|
|
|
|
|
Child = rulesetSkinProvider;
|
|
|
|
});
|
|
|
|
|
2021-06-25 10:55:23 +03:00
|
|
|
AddAssert("requester got correct initial texture", () => textureOnLoad != null);
|
2021-06-25 09:22:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private class SkinRequester : Drawable, ISkin
|
|
|
|
{
|
|
|
|
private ISkinSource skin;
|
|
|
|
|
2021-06-25 10:40:07 +03:00
|
|
|
public event Action OnLoadAsync;
|
2021-06-25 09:22:34 +03:00
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(ISkinSource skin)
|
|
|
|
{
|
|
|
|
this.skin = skin;
|
|
|
|
|
2021-06-25 10:40:07 +03:00
|
|
|
OnLoadAsync?.Invoke();
|
2021-06-25 09:22:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public Drawable GetDrawableComponent(ISkinComponent component) => skin.GetDrawableComponent(component);
|
|
|
|
|
|
|
|
public Texture GetTexture(string componentName, WrapMode wrapModeS = default, WrapMode wrapModeT = default) => skin.GetTexture(componentName);
|
|
|
|
|
|
|
|
public ISample GetSample(ISampleInfo sampleInfo) => skin.GetSample(sampleInfo);
|
|
|
|
|
|
|
|
public IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup) => skin.GetConfig<TLookup, TValue>(lookup);
|
|
|
|
}
|
2021-06-25 12:00:46 +03:00
|
|
|
|
|
|
|
private class TestSkinProvider : ISkin
|
|
|
|
{
|
|
|
|
public const string TEXTURE_NAME = "some-texture";
|
|
|
|
|
|
|
|
public Drawable GetDrawableComponent(ISkinComponent component) => throw new NotImplementedException();
|
|
|
|
|
|
|
|
public Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) => componentName == TEXTURE_NAME ? Texture.WhitePixel : null;
|
|
|
|
|
|
|
|
public ISample GetSample(ISampleInfo sampleInfo) => throw new NotImplementedException();
|
|
|
|
|
|
|
|
public IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup) => throw new NotImplementedException();
|
|
|
|
}
|
2021-06-25 09:22:34 +03:00
|
|
|
}
|
|
|
|
}
|