diff --git a/osu.Game.Rulesets.Osu.Tests/TestSceneLegacyBeatmapSkin.cs b/osu.Game.Rulesets.Osu.Tests/TestSceneLegacyBeatmapSkin.cs index 8ad66d833f..c26afefc41 100644 --- a/osu.Game.Rulesets.Osu.Tests/TestSceneLegacyBeatmapSkin.cs +++ b/osu.Game.Rulesets.Osu.Tests/TestSceneLegacyBeatmapSkin.cs @@ -1,18 +1,14 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using System.Collections.Generic; using System.Linq; using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Audio; -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.IO.Stores; -using osu.Game.Audio; using osu.Game.Beatmaps; using osu.Game.Graphics.Containers; using osu.Game.Rulesets.Osu.Objects; @@ -34,87 +30,69 @@ public class TestSceneLegacyBeatmapSkin : OsuTestScene public void TestBeatmapComboColours() { ExposedPlayer player = null; - ISkin gameplaySkin = null; IReadOnlyList colours = null; AddStep("load beatmap", () => player = loadBeatmap(false, true)); AddUntilStep("wait for player", () => player.IsLoaded); - AddStep("attach skin requester", () => gameplaySkin = addSkinRequester(player)); - AddStep("retrieve combo colours", () => colours = gameplaySkin.GetConfig>(GlobalSkinConfiguration.ComboColours)?.Value); - AddAssert("is beatmap colours", () => colours.SequenceEqual(TestBeatmapSkin.Colours)); + AddStep("retrieve combo colours", () => colours = player.BeatmapSkin.GetConfig>(GlobalSkinConfiguration.ComboColours)?.Value); + AddAssert("is beatmap skin colours", () => colours.SequenceEqual(TestBeatmapSkin.Colours)); } [Test] public void TestEmptyBeatmapComboColours() { ExposedPlayer player = null; - ISkin gameplaySkin = null; IReadOnlyList colours = null; AddStep("load no-colour beatmap", () => player = loadBeatmap(false, false)); AddUntilStep("wait for player", () => player.IsLoaded); - AddStep("attach skin requester", () => gameplaySkin = addSkinRequester(player)); - AddStep("retrieve combo colours", () => colours = gameplaySkin.GetConfig>(GlobalSkinConfiguration.ComboColours)?.Value); - AddAssert("is default skin colours", () => colours.SequenceEqual(SkinConfiguration.DefaultComboColours)); + AddStep("retrieve combo colours", () => colours = player.BeatmapSkin.GetConfig>(GlobalSkinConfiguration.ComboColours)?.Value); + AddAssert("is default user skin colours", () => colours.SequenceEqual(SkinConfiguration.DefaultComboColours)); } [Test] public void TestEmptyBeatmapCustomSkinColours() { ExposedPlayer player = null; - ISkin gameplaySkin = null; IReadOnlyList colours = null; AddStep("load no-colour beatmap", () => player = loadBeatmap(true, false)); AddUntilStep("wait for player", () => player.IsLoaded); - AddStep("attach skin requester", () => gameplaySkin = addSkinRequester(player)); - AddStep("retrieve combo colours", () => colours = gameplaySkin.GetConfig>(GlobalSkinConfiguration.ComboColours)?.Value); - AddAssert("is custom skin colours", () => colours.SequenceEqual(TestSkin.Colours)); + AddStep("retrieve combo colours", () => colours = player.BeatmapSkin.GetConfig>(GlobalSkinConfiguration.ComboColours)?.Value); + AddAssert("is custom user skin colours", () => colours.SequenceEqual(TestSkin.Colours)); } - private ExposedPlayer loadBeatmap(bool skinHasCustomColours, bool beatmapHasCustomColours) + private ExposedPlayer loadBeatmap(bool userHasCustomColours, bool beatmapHasColours) { ExposedPlayer player; - Beatmap.Value = new CustomSkinWorkingBeatmap(audio, beatmapHasCustomColours); - Child = new SkinProvidingContainer(new TestSkin(skinHasCustomColours)) - .WithChild(new OsuScreenStack(player = new ExposedPlayer()) { RelativeSizeAxes = Axes.Both }); + Beatmap.Value = new CustomSkinWorkingBeatmap(audio, beatmapHasColours); + Child = new OsuScreenStack(player = new ExposedPlayer(userHasCustomColours)) { RelativeSizeAxes = Axes.Both }; return player; } - private ISkin addSkinRequester(ExposedPlayer player) - { - SkinRequester skin; - player.BeatmapSkinContainer.Add(skin = new SkinRequester()); - return skin; - } - - private class SkinRequester : Component, ISkin - { - [Resolved] - private ISkinSource skin { get; set; } - - public Drawable GetDrawableComponent(ISkinComponent component) => skin.GetDrawableComponent(component); - - public Texture GetTexture(string componentName) => skin.GetTexture(componentName); - - public SampleChannel GetSample(ISampleInfo sampleInfo) => skin.GetSample(sampleInfo); - - public IBindable GetConfig(TLookup lookup) => skin.GetConfig(lookup); - } - private class ExposedPlayer : Player { - public ExposedPlayer() + private readonly bool userHasCustomColours; + + public ExposedPlayer(bool userHasCustomColours) : base(false, false) { + this.userHasCustomColours = userHasCustomColours; } - public BeatmapSkinProvidingContainer BeatmapSkinContainer => GameplayClockContainer.OfType().First().OfType().First(); + protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) + { + var dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); + dependencies.CacheAs(new TestSkin(userHasCustomColours)); + return dependencies; + } + + public BeatmapSkinProvidingContainer BeatmapSkin => GameplayClockContainer.OfType().First().OfType().First(); } private class CustomSkinWorkingBeatmap : ClockBackedTestWorkingBeatmap @@ -154,7 +132,7 @@ public TestBeatmapSkin(BeatmapInfo beatmap, bool hasColours) } } - private class TestSkin : LegacySkin + private class TestSkin : LegacySkin, ISkinSource { public static Color4[] Colours { get; } = { @@ -168,6 +146,12 @@ public TestSkin(bool hasCustomColours) if (hasCustomColours) Configuration.AddComboColours(Colours); } + + public event Action SourceChanged + { + add { } + remove { } + } } } }