mirror of
https://github.com/osukey/osukey.git
synced 2025-04-29 02:37:25 +09:00
Merge pull request #13658 from frenzibyte/fix-initial-ruleset-skin-loading
Fix `RulesetSkinProvidingContainer` being potentially late in setting up skin sources
This commit is contained in:
commit
a8597b6213
@ -0,0 +1,95 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
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;
|
||||||
|
|
||||||
|
protected override Ruleset CreateRuleset() => new TestSceneRulesetDependencies.TestRuleset();
|
||||||
|
|
||||||
|
[Cached(typeof(ISkinSource))]
|
||||||
|
private readonly ISkinSource testSource = new TestSkinProvider();
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestEarlyAddedSkinRequester()
|
||||||
|
{
|
||||||
|
Texture textureOnLoad = null;
|
||||||
|
|
||||||
|
AddStep("setup provider", () =>
|
||||||
|
{
|
||||||
|
var rulesetSkinProvider = new RulesetSkinProvidingContainer(Ruleset.Value.CreateInstance(), Beatmap.Value.Beatmap, Beatmap.Value.Skin);
|
||||||
|
|
||||||
|
rulesetSkinProvider.Add(requester = new SkinRequester());
|
||||||
|
|
||||||
|
requester.OnLoadAsync += () => textureOnLoad = requester.GetTexture(TestSkinProvider.TEXTURE_NAME);
|
||||||
|
|
||||||
|
Child = rulesetSkinProvider;
|
||||||
|
});
|
||||||
|
|
||||||
|
AddAssert("requester got correct initial texture", () => textureOnLoad != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class SkinRequester : Drawable, ISkin
|
||||||
|
{
|
||||||
|
private ISkinSource skin;
|
||||||
|
|
||||||
|
public event Action OnLoadAsync;
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(ISkinSource skin)
|
||||||
|
{
|
||||||
|
this.skin = skin;
|
||||||
|
|
||||||
|
OnLoadAsync?.Invoke();
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TestSkinProvider : ISkinSource
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
|
||||||
|
public event Action SourceChanged
|
||||||
|
{
|
||||||
|
add { }
|
||||||
|
remove { }
|
||||||
|
}
|
||||||
|
|
||||||
|
public ISkin FindProvider(Func<ISkin, bool> lookupFunction) => lookupFunction(this) ? this : null;
|
||||||
|
|
||||||
|
public IEnumerable<ISkin> AllSources => new[] { this };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -52,7 +52,7 @@ namespace osu.Game.Tests.Testing
|
|||||||
Dependencies.Get<TestRulesetConfigManager>() != null);
|
Dependencies.Get<TestRulesetConfigManager>() != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TestRuleset : Ruleset
|
public class TestRuleset : Ruleset
|
||||||
{
|
{
|
||||||
public override string Description => string.Empty;
|
public override string Description => string.Empty;
|
||||||
public override string ShortName => string.Empty;
|
public override string ShortName => string.Empty;
|
||||||
|
@ -42,27 +42,30 @@ namespace osu.Game.Skinning
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
[Resolved]
|
private ISkinSource parentSource;
|
||||||
private ISkinSource skinSource { get; set; }
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
||||||
private void load()
|
|
||||||
{
|
{
|
||||||
UpdateSkins();
|
parentSource = parent.Get<ISkinSource>();
|
||||||
skinSource.SourceChanged += OnSourceChanged;
|
parentSource.SourceChanged += OnSourceChanged;
|
||||||
|
|
||||||
|
// ensure sources are populated and ready for use before childrens' asynchronous load flow.
|
||||||
|
UpdateSkinSources();
|
||||||
|
|
||||||
|
return base.CreateChildDependencies(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnSourceChanged()
|
protected override void OnSourceChanged()
|
||||||
{
|
{
|
||||||
UpdateSkins();
|
UpdateSkinSources();
|
||||||
base.OnSourceChanged();
|
base.OnSourceChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void UpdateSkins()
|
protected virtual void UpdateSkinSources()
|
||||||
{
|
{
|
||||||
SkinSources.Clear();
|
SkinSources.Clear();
|
||||||
|
|
||||||
foreach (var skin in skinSource.AllSources)
|
foreach (var skin in parentSource.AllSources)
|
||||||
{
|
{
|
||||||
switch (skin)
|
switch (skin)
|
||||||
{
|
{
|
||||||
@ -93,8 +96,8 @@ namespace osu.Game.Skinning
|
|||||||
{
|
{
|
||||||
base.Dispose(isDisposing);
|
base.Dispose(isDisposing);
|
||||||
|
|
||||||
if (skinSource != null)
|
if (parentSource != null)
|
||||||
skinSource.SourceChanged -= OnSourceChanged;
|
parentSource.SourceChanged -= OnSourceChanged;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user