2021-06-11 04:59:59 +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-25 14:22:34 +08:00
|
|
|
using System;
|
2021-06-11 04:59:59 +08:00
|
|
|
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;
|
2021-06-28 16:29:43 +08:00
|
|
|
using osu.Framework.Testing;
|
2021-06-11 04:59:59 +08:00
|
|
|
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
|
|
|
|
{
|
2021-06-28 16:29:43 +08:00
|
|
|
[HeadlessTest]
|
2021-06-11 04:59:59 +08:00
|
|
|
public partial class TestSceneRulesetSkinProvidingContainer : OsuTestScene
|
|
|
|
{
|
|
|
|
private SkinRequester requester;
|
|
|
|
|
|
|
|
protected override Ruleset CreateRuleset() => new TestSceneRulesetDependencies.TestRuleset();
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestRulesetResources()
|
|
|
|
{
|
2021-06-28 16:16:26 +08:00
|
|
|
setupProviderStep();
|
|
|
|
|
2021-06-11 04:59:59 +08:00
|
|
|
AddAssert("ruleset texture retrieved via skin", () => requester.GetTexture("test-image") != null);
|
|
|
|
AddAssert("ruleset sample retrieved via skin", () => requester.GetSample(new SampleInfo("test-sample")) != null);
|
|
|
|
}
|
|
|
|
|
2021-06-25 14:22:34 +08:00
|
|
|
[Test]
|
|
|
|
public void TestEarlyAddedSkinRequester()
|
|
|
|
{
|
2021-06-25 15:55:23 +08:00
|
|
|
Texture textureOnLoad = null;
|
2021-06-25 14:22:34 +08:00
|
|
|
|
|
|
|
AddStep("setup provider", () =>
|
|
|
|
{
|
2024-02-14 16:13:44 +08:00
|
|
|
requester = new SkinRequester();
|
2021-06-28 16:16:26 +08:00
|
|
|
requester.OnLoadAsync += () => textureOnLoad = requester.GetTexture("test-image");
|
2021-06-25 14:22:34 +08:00
|
|
|
|
2024-02-14 16:13:44 +08:00
|
|
|
Child = new RulesetSkinProvidingContainer(Ruleset.Value.CreateInstance(), Beatmap.Value.Beatmap, Beatmap.Value.Skin)
|
|
|
|
{
|
2024-02-15 17:33:48 +08:00
|
|
|
Child = requester
|
2024-02-14 16:13:44 +08:00
|
|
|
};
|
2021-06-25 14:22:34 +08:00
|
|
|
});
|
|
|
|
|
2021-06-25 15:55:23 +08:00
|
|
|
AddAssert("requester got correct initial texture", () => textureOnLoad != null);
|
2021-06-25 14:22:34 +08:00
|
|
|
}
|
|
|
|
|
2021-06-28 16:16:26 +08:00
|
|
|
private void setupProviderStep()
|
|
|
|
{
|
|
|
|
AddStep("setup provider", () =>
|
|
|
|
{
|
|
|
|
Child = new RulesetSkinProvidingContainer(Ruleset.Value.CreateInstance(), Beatmap.Value.Beatmap, Beatmap.Value.Skin)
|
|
|
|
.WithChild(requester = new SkinRequester());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-06-11 04:59:59 +08:00
|
|
|
private partial class SkinRequester : Drawable, ISkin
|
|
|
|
{
|
|
|
|
private ISkinSource skin;
|
|
|
|
|
2021-06-25 15:40:07 +08:00
|
|
|
public event Action OnLoadAsync;
|
2021-06-25 14:22:34 +08:00
|
|
|
|
2021-06-11 04:59:59 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(ISkinSource skin)
|
|
|
|
{
|
|
|
|
this.skin = skin;
|
2021-06-25 14:22:34 +08:00
|
|
|
|
2021-06-25 15:40:07 +08:00
|
|
|
OnLoadAsync?.Invoke();
|
2021-06-11 04:59:59 +08:00
|
|
|
}
|
|
|
|
|
2022-11-09 15:04:56 +08:00
|
|
|
public Drawable GetDrawableComponent(ISkinComponentLookup lookup) => skin.GetDrawableComponent(lookup);
|
2021-06-11 04:59:59 +08:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|