1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 06:57:39 +08:00

Remove unnecessary skin requester and user-skin providing container

This commit is contained in:
Salman Ahmed 2019-12-21 12:53:05 +03:00
parent ff5e6c0dcf
commit a6632cf1ef

View File

@ -1,18 +1,14 @@
// 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 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 @@ namespace osu.Game.Rulesets.Osu.Tests
public void TestBeatmapComboColours()
{
ExposedPlayer player = null;
ISkin gameplaySkin = null;
IReadOnlyList<Color4> 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, IReadOnlyList<Color4>>(GlobalSkinConfiguration.ComboColours)?.Value);
AddAssert("is beatmap colours", () => colours.SequenceEqual(TestBeatmapSkin.Colours));
AddStep("retrieve combo colours", () => colours = player.BeatmapSkin.GetConfig<GlobalSkinConfiguration, IReadOnlyList<Color4>>(GlobalSkinConfiguration.ComboColours)?.Value);
AddAssert("is beatmap skin colours", () => colours.SequenceEqual(TestBeatmapSkin.Colours));
}
[Test]
public void TestEmptyBeatmapComboColours()
{
ExposedPlayer player = null;
ISkin gameplaySkin = null;
IReadOnlyList<Color4> 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, IReadOnlyList<Color4>>(GlobalSkinConfiguration.ComboColours)?.Value);
AddAssert("is default skin colours", () => colours.SequenceEqual(SkinConfiguration.DefaultComboColours));
AddStep("retrieve combo colours", () => colours = player.BeatmapSkin.GetConfig<GlobalSkinConfiguration, IReadOnlyList<Color4>>(GlobalSkinConfiguration.ComboColours)?.Value);
AddAssert("is default user skin colours", () => colours.SequenceEqual(SkinConfiguration.DefaultComboColours));
}
[Test]
public void TestEmptyBeatmapCustomSkinColours()
{
ExposedPlayer player = null;
ISkin gameplaySkin = null;
IReadOnlyList<Color4> 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, IReadOnlyList<Color4>>(GlobalSkinConfiguration.ComboColours)?.Value);
AddAssert("is custom skin colours", () => colours.SequenceEqual(TestSkin.Colours));
AddStep("retrieve combo colours", () => colours = player.BeatmapSkin.GetConfig<GlobalSkinConfiguration, IReadOnlyList<Color4>>(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<TValue> GetConfig<TLookup, TValue>(TLookup lookup) => skin.GetConfig<TLookup, TValue>(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<ScalingContainer>().First().OfType<BeatmapSkinProvidingContainer>().First();
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
dependencies.CacheAs<ISkinSource>(new TestSkin(userHasCustomColours));
return dependencies;
}
public BeatmapSkinProvidingContainer BeatmapSkin => GameplayClockContainer.OfType<ScalingContainer>().First().OfType<BeatmapSkinProvidingContainer>().First();
}
private class CustomSkinWorkingBeatmap : ClockBackedTestWorkingBeatmap
@ -154,7 +132,7 @@ namespace osu.Game.Rulesets.Osu.Tests
}
}
private class TestSkin : LegacySkin
private class TestSkin : LegacySkin, ISkinSource
{
public static Color4[] Colours { get; } =
{
@ -168,6 +146,12 @@ namespace osu.Game.Rulesets.Osu.Tests
if (hasCustomColours)
Configuration.AddComboColours(Colours);
}
public event Action SourceChanged
{
add { }
remove { }
}
}
}
}