1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-26 19:32:55 +08:00

Created base class for testing beatmap colours.

This commit is contained in:
Mysfit 2021-01-15 23:46:46 -05:00
parent 0c01a3a685
commit 112967c1e8
3 changed files with 245 additions and 271 deletions

View File

@ -2,13 +2,10 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio; using osu.Framework.Audio;
using osu.Framework.Bindables;
using osu.Framework.IO.Stores;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.ControlPoints;
@ -17,179 +14,114 @@ using osu.Game.Rulesets.Catch.Objects;
using osu.Game.Rulesets.Catch.Skinning; using osu.Game.Rulesets.Catch.Skinning;
using osu.Game.Rulesets.Catch.UI; using osu.Game.Rulesets.Catch.UI;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using osu.Game.Screens.Play;
using osu.Game.Skinning; using osu.Game.Skinning;
using osu.Game.Tests.Visual; using osu.Game.Tests.Beatmaps;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
namespace osu.Game.Rulesets.Catch.Tests namespace osu.Game.Rulesets.Catch.Tests
{ {
public class TestSceneLegacyBeatmapSkin : ScreenTestScene public class TestSceneLegacyBeatmapSkin : LegacyBeatmapSkinColourTest
{ {
[Resolved] [Resolved]
private AudioManager audio { get; set; } private AudioManager audio { get; set; }
private readonly Bindable<bool> beatmapSkins = new Bindable<bool>();
private readonly Bindable<bool> beatmapColours = new Bindable<bool>();
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuConfigManager config) private void load(OsuConfigManager config)
{ {
config.BindWith(OsuSetting.BeatmapSkins, beatmapSkins); config.BindWith(OsuSetting.BeatmapSkins, BeatmapSkins);
config.BindWith(OsuSetting.BeatmapColours, beatmapColours); config.BindWith(OsuSetting.BeatmapColours, BeatmapColours);
} }
[TestCase(true, true)] [TestCase(true, true)]
[TestCase(true, false)] [TestCase(true, false)]
[TestCase(false, true)] [TestCase(false, true)]
[TestCase(false, false)] [TestCase(false, false)]
public void TestBeatmapComboColours(bool userHasCustomColours, bool useBeatmapSkin) public override void TestBeatmapComboColours(bool userHasCustomColours, bool useBeatmapSkin)
{ {
ExposedPlayer player = null; TestBeatmap = new CatchCustomSkinWorkingBeatmap(audio, true);
base.TestBeatmapComboColours(userHasCustomColours, useBeatmapSkin);
configureSettings(useBeatmapSkin, true); AddAssert("is beatmap skin colours", () => TestPlayer.UsableComboColours.SequenceEqual(TestBeatmapSkin.Colours));
AddStep("load coloured beatmap", () => player = loadBeatmap(userHasCustomColours, true));
AddUntilStep("wait for player", () => player.IsLoaded);
AddAssert("is beatmap skin colours", () => player.UsableComboColours.SequenceEqual(TestBeatmapSkin.Colours));
} }
[TestCase(true)] [TestCase(true)]
[TestCase(false)] [TestCase(false)]
public void TestBeatmapComboColoursOverride(bool useBeatmapSkin) public override void TestBeatmapComboColoursOverride(bool useBeatmapSkin)
{ {
ExposedPlayer player = null; TestBeatmap = new CatchCustomSkinWorkingBeatmap(audio, true);
base.TestBeatmapComboColoursOverride(useBeatmapSkin);
configureSettings(useBeatmapSkin, false); AddAssert("is user custom skin colours", () => TestPlayer.UsableComboColours.SequenceEqual(TestSkin.Colours));
AddStep("load coloured beatmap", () => player = loadBeatmap(true, true));
AddUntilStep("wait for player", () => player.IsLoaded);
AddAssert("is user custom skin colours", () => player.UsableComboColours.SequenceEqual(TestSkin.Colours));
} }
[TestCase(true)] [TestCase(true)]
[TestCase(false)] [TestCase(false)]
public void TestBeatmapComboColoursOverrideWithDefaultColours(bool useBeatmapSkin) public override void TestBeatmapComboColoursOverrideWithDefaultColours(bool useBeatmapSkin)
{ {
ExposedPlayer player = null; TestBeatmap = new CatchCustomSkinWorkingBeatmap(audio, true);
base.TestBeatmapComboColoursOverrideWithDefaultColours(useBeatmapSkin);
configureSettings(useBeatmapSkin, false); AddAssert("is default user skin colours", () => TestPlayer.UsableComboColours.SequenceEqual(SkinConfiguration.DefaultComboColours));
AddStep("load coloured beatmap", () => player = loadBeatmap(false, true));
AddUntilStep("wait for player", () => player.IsLoaded);
AddAssert("is default user skin colours", () => player.UsableComboColours.SequenceEqual(SkinConfiguration.DefaultComboColours));
} }
[TestCase(true, true)] [TestCase(true, true)]
[TestCase(false, true)] [TestCase(false, true)]
[TestCase(true, false)] [TestCase(true, false)]
[TestCase(false, false)] [TestCase(false, false)]
public void TestBeatmapNoComboColours(bool useBeatmapSkin, bool useBeatmapColour) public override void TestBeatmapNoComboColours(bool useBeatmapSkin, bool useBeatmapColour)
{ {
ExposedPlayer player = null; TestBeatmap = new CatchCustomSkinWorkingBeatmap(audio, false);
base.TestBeatmapNoComboColours(useBeatmapSkin, useBeatmapColour);
configureSettings(useBeatmapSkin, useBeatmapColour); AddAssert("is default user skin colours", () => TestPlayer.UsableComboColours.SequenceEqual(SkinConfiguration.DefaultComboColours));
AddStep("load no-colour beatmap", () => player = loadBeatmap(false, false));
AddUntilStep("wait for player", () => player.IsLoaded);
AddAssert("is default user skin colours", () => player.UsableComboColours.SequenceEqual(SkinConfiguration.DefaultComboColours));
} }
[TestCase(true, true)] [TestCase(true, true)]
[TestCase(false, true)] [TestCase(false, true)]
[TestCase(true, false)] [TestCase(true, false)]
[TestCase(false, false)] [TestCase(false, false)]
public void TestBeatmapNoComboColoursSkinOverride(bool useBeatmapSkin, bool useBeatmapColour) public override void TestBeatmapNoComboColoursSkinOverride(bool useBeatmapSkin, bool useBeatmapColour)
{ {
ExposedPlayer player = null; TestBeatmap = new CatchCustomSkinWorkingBeatmap(audio, false);
base.TestBeatmapNoComboColoursSkinOverride(useBeatmapSkin, useBeatmapColour);
configureSettings(useBeatmapSkin, useBeatmapColour); AddAssert("is custom user skin colours", () => TestPlayer.UsableComboColours.SequenceEqual(TestSkin.Colours));
AddStep("load custom-skin colour", () => player = loadBeatmap(true, false));
AddUntilStep("wait for player", () => player.IsLoaded);
AddAssert("is custom user skin colours", () => player.UsableComboColours.SequenceEqual(TestSkin.Colours));
} }
[TestCase(true)] [TestCase(true)]
[TestCase(false)] [TestCase(false)]
public void TestBeatmapHyperDashColours(bool useBeatmapSkin) public void TestBeatmapHyperDashColours(bool useBeatmapSkin)
{ {
ExposedPlayer player = null; TestBeatmap = new CatchCustomSkinWorkingBeatmap(audio, true);
ConfigureTest(useBeatmapSkin, true, true);
configureSettings(useBeatmapSkin, true); AddAssert("is custom hyper dash colours", () => ((CatchExposedPlayer)TestPlayer).UsableHyperDashColour == CatchTestBeatmapSkin.HYPER_DASH_COLOUR);
AddStep("load custom-skin colour", () => player = loadBeatmap(true, true)); AddAssert("is custom hyper dash after image colours", () => ((CatchExposedPlayer)TestPlayer).UsableHyperDashAfterImageColour == CatchTestBeatmapSkin.HYPER_DASH_AFTER_IMAGE_COLOUR);
AddUntilStep("wait for player", () => player.IsLoaded); AddAssert("is custom hyper dash fruit colours", () => ((CatchExposedPlayer)TestPlayer).UsableHyperDashFruitColour == CatchTestBeatmapSkin.HYPER_DASH_FRUIT_COLOUR);
AddAssert("is custom hyper dash colours", () => player.UsableHyperDashColour == TestBeatmapSkin.HYPER_DASH_COLOUR);
AddAssert("is custom hyper dash after image colours", () => player.UsableHyperDashAfterImageColour == TestBeatmapSkin.HYPER_DASH_AFTER_IMAGE_COLOUR);
AddAssert("is custom hyper dash fruit colours", () => player.UsableHyperDashFruitColour == TestBeatmapSkin.HYPER_DASH_FRUIT_COLOUR);
} }
[TestCase(true)] [TestCase(true)]
[TestCase(false)] [TestCase(false)]
public void TestBeatmapHyperDashColoursOverride(bool useBeatmapSkin) public void TestBeatmapHyperDashColoursOverride(bool useBeatmapSkin)
{ {
ExposedPlayer player = null; TestBeatmap = new CatchCustomSkinWorkingBeatmap(audio, true);
ConfigureTest(useBeatmapSkin, false, true);
configureSettings(useBeatmapSkin, false); AddAssert("is custom hyper dash colours", () => ((CatchExposedPlayer)TestPlayer).UsableHyperDashColour == CatchTestSkin.HYPER_DASH_COLOUR);
AddStep("load custom-skin colour", () => player = loadBeatmap(true, true)); AddAssert("is custom hyper dash after image colours", () => ((CatchExposedPlayer)TestPlayer).UsableHyperDashAfterImageColour == CatchTestSkin.HYPER_DASH_AFTER_IMAGE_COLOUR);
AddUntilStep("wait for player", () => player.IsLoaded); AddAssert("is custom hyper dash fruit colours", () => ((CatchExposedPlayer)TestPlayer).UsableHyperDashFruitColour == CatchTestSkin.HYPER_DASH_FRUIT_COLOUR);
AddAssert("is custom hyper dash colours", () => player.UsableHyperDashColour == TestSkin.HYPER_DASH_COLOUR);
AddAssert("is custom hyper dash after image colours", () => player.UsableHyperDashAfterImageColour == TestSkin.HYPER_DASH_AFTER_IMAGE_COLOUR);
AddAssert("is custom hyper dash fruit colours", () => player.UsableHyperDashFruitColour == TestSkin.HYPER_DASH_FRUIT_COLOUR);
} }
private ExposedPlayer loadBeatmap(bool userHasCustomColours, bool beatmapHasColours) protected override ExposedPlayer CreateTestPlayer(bool userHasCustomColours) => new CatchExposedPlayer(userHasCustomColours);
private class CatchExposedPlayer : ExposedPlayer
{ {
ExposedPlayer player; public CatchExposedPlayer(bool userHasCustomColours)
: base(userHasCustomColours)
Beatmap.Value = new CustomSkinWorkingBeatmap(audio, beatmapHasColours);
LoadScreen(player = new ExposedPlayer(userHasCustomColours));
return player;
}
private void configureSettings(bool beatmapSkins, bool beatmapColours)
{
AddStep($"{(beatmapSkins ? "enable" : "disable")} beatmap skins", () =>
{ {
this.beatmapSkins.Value = beatmapSkins;
});
AddStep($"{(beatmapColours ? "enable" : "disable")} beatmap colours", () =>
{
this.beatmapColours.Value = beatmapColours;
});
}
private class ExposedPlayer : Player
{
private readonly bool userHasCustomColours;
public ExposedPlayer(bool userHasCustomColours)
: base(new PlayerConfiguration
{
AllowPause = false,
ShowResults = false,
})
{
this.userHasCustomColours = userHasCustomColours;
} }
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{ {
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
dependencies.CacheAs<ISkinSource>(new TestSkin(userHasCustomColours)); dependencies.CacheAs<ISkinSource>(new CatchTestSkin(UserHasCustomColours));
return dependencies; return dependencies;
} }
public IReadOnlyList<Color4> UsableComboColours =>
GameplayClockContainer.ChildrenOfType<BeatmapSkinProvidingContainer>()
.First()
.GetConfig<GlobalSkinColours, IReadOnlyList<Color4>>(GlobalSkinColours.ComboColours)?.Value;
public Color4 UsableHyperDashColour => public Color4 UsableHyperDashColour =>
GameplayClockContainer.ChildrenOfType<BeatmapSkinProvidingContainer>() GameplayClockContainer.ChildrenOfType<BeatmapSkinProvidingContainer>()
.First() .First()
@ -223,17 +155,14 @@ namespace osu.Game.Rulesets.Catch.Tests
} }
} }
private class CustomSkinWorkingBeatmap : ClockBackedTestWorkingBeatmap private class CatchCustomSkinWorkingBeatmap : CustomSkinWorkingBeatmap
{ {
private readonly bool hasColours; public CatchCustomSkinWorkingBeatmap(AudioManager audio, bool hasColours)
: base(createBeatmap(new CatchRuleset().RulesetInfo), audio, hasColours)
public CustomSkinWorkingBeatmap(AudioManager audio, bool hasColours)
: base(createBeatmap(new CatchRuleset().RulesetInfo), null, null, audio)
{ {
this.hasColours = hasColours;
} }
protected override ISkin GetSkin() => new TestBeatmapSkin(BeatmapInfo, hasColours); protected override ISkin GetSkin() => new CatchTestBeatmapSkin(BeatmapInfo, HasColours);
private static IBeatmap createBeatmap(RulesetInfo ruleset) private static IBeatmap createBeatmap(RulesetInfo ruleset)
{ {
@ -297,26 +226,19 @@ namespace osu.Game.Rulesets.Catch.Tests
} }
} }
private class TestBeatmapSkin : LegacyBeatmapSkin private class CatchTestBeatmapSkin : TestBeatmapSkin
{ {
public static Color4[] Colours { get; } =
{
new Color4(50, 100, 150, 255),
new Color4(40, 80, 120, 255),
};
public static readonly Color4 HYPER_DASH_COLOUR = Color4.DarkBlue; public static readonly Color4 HYPER_DASH_COLOUR = Color4.DarkBlue;
public static readonly Color4 HYPER_DASH_AFTER_IMAGE_COLOUR = Color4.DarkCyan; public static readonly Color4 HYPER_DASH_AFTER_IMAGE_COLOUR = Color4.DarkCyan;
public static readonly Color4 HYPER_DASH_FRUIT_COLOUR = Color4.DarkGoldenrod; public static readonly Color4 HYPER_DASH_FRUIT_COLOUR = Color4.DarkGoldenrod;
public TestBeatmapSkin(BeatmapInfo beatmap, bool hasColours) public CatchTestBeatmapSkin(BeatmapInfo beatmap, bool hasColours)
: base(beatmap, new ResourceStore<byte[]>(), null) : base(beatmap, hasColours)
{ {
if (hasColours) if (hasColours)
{ {
Configuration.AddComboColours(Colours);
Configuration.CustomColours.Add(CatchSkinColour.HyperDash.ToString(), HYPER_DASH_COLOUR); Configuration.CustomColours.Add(CatchSkinColour.HyperDash.ToString(), HYPER_DASH_COLOUR);
Configuration.CustomColours.Add(CatchSkinColour.HyperDashAfterImage.ToString(), HYPER_DASH_AFTER_IMAGE_COLOUR); Configuration.CustomColours.Add(CatchSkinColour.HyperDashAfterImage.ToString(), HYPER_DASH_AFTER_IMAGE_COLOUR);
Configuration.CustomColours.Add(CatchSkinColour.HyperDashFruit.ToString(), HYPER_DASH_FRUIT_COLOUR); Configuration.CustomColours.Add(CatchSkinColour.HyperDashFruit.ToString(), HYPER_DASH_FRUIT_COLOUR);
@ -324,37 +246,24 @@ namespace osu.Game.Rulesets.Catch.Tests
} }
} }
private class TestSkin : LegacySkin, ISkinSource private class CatchTestSkin : TestSkin
{ {
public static Color4[] Colours { get; } =
{
new Color4(150, 100, 50, 255),
new Color4(20, 20, 20, 255),
};
public static readonly Color4 HYPER_DASH_COLOUR = Color4.LightBlue; public static readonly Color4 HYPER_DASH_COLOUR = Color4.LightBlue;
public static readonly Color4 HYPER_DASH_AFTER_IMAGE_COLOUR = Color4.LightCoral; public static readonly Color4 HYPER_DASH_AFTER_IMAGE_COLOUR = Color4.LightCoral;
public static readonly Color4 HYPER_DASH_FRUIT_COLOUR = Color4.LightCyan; public static readonly Color4 HYPER_DASH_FRUIT_COLOUR = Color4.LightCyan;
public TestSkin(bool hasCustomColours) public CatchTestSkin(bool hasCustomColours)
: base(new SkinInfo(), new ResourceStore<byte[]>(), null, string.Empty) : base(hasCustomColours)
{ {
if (hasCustomColours) if (hasCustomColours)
{ {
Configuration.AddComboColours(Colours);
Configuration.CustomColours.Add(CatchSkinColour.HyperDash.ToString(), HYPER_DASH_COLOUR); Configuration.CustomColours.Add(CatchSkinColour.HyperDash.ToString(), HYPER_DASH_COLOUR);
Configuration.CustomColours.Add(CatchSkinColour.HyperDashAfterImage.ToString(), HYPER_DASH_AFTER_IMAGE_COLOUR); Configuration.CustomColours.Add(CatchSkinColour.HyperDashAfterImage.ToString(), HYPER_DASH_AFTER_IMAGE_COLOUR);
Configuration.CustomColours.Add(CatchSkinColour.HyperDashFruit.ToString(), HYPER_DASH_FRUIT_COLOUR); Configuration.CustomColours.Add(CatchSkinColour.HyperDashFruit.ToString(), HYPER_DASH_FRUIT_COLOUR);
} }
} }
public event Action SourceChanged
{
add { }
remove { }
}
} }
} }
} }

View File

@ -1,168 +1,113 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio; using osu.Framework.Audio;
using osu.Framework.Bindables;
using osu.Framework.IO.Stores;
using osu.Framework.Testing;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Screens.Play;
using osu.Game.Skinning; using osu.Game.Skinning;
using osu.Game.Tests.Visual; using osu.Game.Tests.Beatmaps;
using osuTK; using osuTK;
using osuTK.Graphics;
namespace osu.Game.Rulesets.Osu.Tests namespace osu.Game.Rulesets.Osu.Tests
{ {
public class TestSceneLegacyBeatmapSkin : ScreenTestScene public class TestSceneLegacyBeatmapSkin : LegacyBeatmapSkinColourTest
{ {
[Resolved] [Resolved]
private AudioManager audio { get; set; } private AudioManager audio { get; set; }
private readonly Bindable<bool> beatmapSkins = new Bindable<bool>();
private readonly Bindable<bool> beatmapColours = new Bindable<bool>();
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuConfigManager config) private void load(OsuConfigManager config)
{ {
config.BindWith(OsuSetting.BeatmapSkins, beatmapSkins); config.BindWith(OsuSetting.BeatmapSkins, BeatmapSkins);
config.BindWith(OsuSetting.BeatmapColours, beatmapColours); config.BindWith(OsuSetting.BeatmapColours, BeatmapColours);
} }
[TestCase(true, true)] [TestCase(true, true)]
[TestCase(true, false)] [TestCase(true, false)]
[TestCase(false, true)] [TestCase(false, true)]
[TestCase(false, false)] [TestCase(false, false)]
public void TestBeatmapComboColours(bool userHasCustomColours, bool useBeatmapSkin) public override void TestBeatmapComboColours(bool userHasCustomColours, bool useBeatmapSkin)
{ {
ExposedPlayer player = null; TestBeatmap = new OsuCustomSkinWorkingBeatmap(audio, true);
base.TestBeatmapComboColours(userHasCustomColours, useBeatmapSkin);
configureSettings(useBeatmapSkin, true); AddAssert("is beatmap skin colours", () => TestPlayer.UsableComboColours.SequenceEqual(TestBeatmapSkin.Colours));
AddStep("load coloured beatmap", () => player = loadBeatmap(userHasCustomColours, true));
AddUntilStep("wait for player", () => player.IsLoaded);
AddAssert("is beatmap skin colours", () => player.UsableComboColours.SequenceEqual(TestBeatmapSkin.Colours));
} }
[TestCase(true)] [TestCase(true)]
[TestCase(false)] [TestCase(false)]
public void TestBeatmapComboColoursOverride(bool useBeatmapSkin) public override void TestBeatmapComboColoursOverride(bool useBeatmapSkin)
{ {
ExposedPlayer player = null; TestBeatmap = new OsuCustomSkinWorkingBeatmap(audio, true);
base.TestBeatmapComboColoursOverride(useBeatmapSkin);
configureSettings(useBeatmapSkin, false); AddAssert("is user custom skin colours", () => TestPlayer.UsableComboColours.SequenceEqual(TestSkin.Colours));
AddStep("load coloured beatmap", () => player = loadBeatmap(true, true));
AddUntilStep("wait for player", () => player.IsLoaded);
AddAssert("is user custom skin colours", () => player.UsableComboColours.SequenceEqual(TestSkin.Colours));
} }
[TestCase(true)] [TestCase(true)]
[TestCase(false)] [TestCase(false)]
public void TestBeatmapComboColoursOverrideWithDefaultColours(bool useBeatmapSkin) public override void TestBeatmapComboColoursOverrideWithDefaultColours(bool useBeatmapSkin)
{ {
ExposedPlayer player = null; TestBeatmap = new OsuCustomSkinWorkingBeatmap(audio, true);
base.TestBeatmapComboColoursOverrideWithDefaultColours(useBeatmapSkin);
configureSettings(useBeatmapSkin, false); AddAssert("is default user skin colours", () => TestPlayer.UsableComboColours.SequenceEqual(SkinConfiguration.DefaultComboColours));
AddStep("load coloured beatmap", () => player = loadBeatmap(false, true));
AddUntilStep("wait for player", () => player.IsLoaded);
AddAssert("is default user skin colours", () => player.UsableComboColours.SequenceEqual(SkinConfiguration.DefaultComboColours));
} }
[TestCase(true, true)] [TestCase(true, true)]
[TestCase(false, true)] [TestCase(false, true)]
[TestCase(true, false)] [TestCase(true, false)]
[TestCase(false, false)] [TestCase(false, false)]
public void TestBeatmapNoComboColours(bool useBeatmapSkin, bool useBeatmapColour) public override void TestBeatmapNoComboColours(bool useBeatmapSkin, bool useBeatmapColour)
{ {
ExposedPlayer player = null; TestBeatmap = new OsuCustomSkinWorkingBeatmap(audio, false);
base.TestBeatmapNoComboColours(useBeatmapSkin, useBeatmapColour);
configureSettings(useBeatmapSkin, useBeatmapColour); AddAssert("is default user skin colours", () => TestPlayer.UsableComboColours.SequenceEqual(SkinConfiguration.DefaultComboColours));
AddStep("load no-colour beatmap", () => player = loadBeatmap(false, false));
AddUntilStep("wait for player", () => player.IsLoaded);
AddAssert("is default user skin colours", () => player.UsableComboColours.SequenceEqual(SkinConfiguration.DefaultComboColours));
} }
[TestCase(true, true)] [TestCase(true, true)]
[TestCase(false, true)] [TestCase(false, true)]
[TestCase(true, false)] [TestCase(true, false)]
[TestCase(false, false)] [TestCase(false, false)]
public void TestBeatmapNoComboColoursSkinOverride(bool useBeatmapSkin, bool useBeatmapColour) public override void TestBeatmapNoComboColoursSkinOverride(bool useBeatmapSkin, bool useBeatmapColour)
{ {
ExposedPlayer player = null; TestBeatmap = new OsuCustomSkinWorkingBeatmap(audio, false);
base.TestBeatmapNoComboColoursSkinOverride(useBeatmapSkin, useBeatmapColour);
configureSettings(useBeatmapSkin, useBeatmapColour); AddAssert("is custom user skin colours", () => TestPlayer.UsableComboColours.SequenceEqual(TestSkin.Colours));
AddStep("load custom-skin colour", () => player = loadBeatmap(true, false));
AddUntilStep("wait for player", () => player.IsLoaded);
AddAssert("is custom user skin colours", () => player.UsableComboColours.SequenceEqual(TestSkin.Colours));
} }
private ExposedPlayer loadBeatmap(bool userHasCustomColours, bool beatmapHasColours) protected override ExposedPlayer CreateTestPlayer(bool userHasCustomColours) => new OsuExposedPlayer(userHasCustomColours);
private class OsuExposedPlayer : ExposedPlayer
{ {
ExposedPlayer player; public OsuExposedPlayer(bool userHasCustomColours)
: base(userHasCustomColours)
Beatmap.Value = new CustomSkinWorkingBeatmap(audio, beatmapHasColours);
LoadScreen(player = new ExposedPlayer(userHasCustomColours));
return player;
}
private void configureSettings(bool beatmapSkins, bool beatmapColours)
{
AddStep($"{(beatmapSkins ? "enable" : "disable")} beatmap skins", () =>
{ {
this.beatmapSkins.Value = beatmapSkins;
});
AddStep($"{(beatmapColours ? "enable" : "disable")} beatmap colours", () =>
{
this.beatmapColours.Value = beatmapColours;
});
}
private class ExposedPlayer : Player
{
private readonly bool userHasCustomColours;
public ExposedPlayer(bool userHasCustomColours)
: base(new PlayerConfiguration
{
AllowPause = false,
ShowResults = false,
})
{
this.userHasCustomColours = userHasCustomColours;
} }
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{ {
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
dependencies.CacheAs<ISkinSource>(new TestSkin(userHasCustomColours)); dependencies.CacheAs<ISkinSource>(new OsuTestSkin(UserHasCustomColours));
return dependencies; return dependencies;
} }
public IReadOnlyList<Color4> UsableComboColours =>
GameplayClockContainer.ChildrenOfType<BeatmapSkinProvidingContainer>()
.First()
.GetConfig<GlobalSkinColours, IReadOnlyList<Color4>>(GlobalSkinColours.ComboColours)?.Value;
} }
private class CustomSkinWorkingBeatmap : ClockBackedTestWorkingBeatmap private class OsuCustomSkinWorkingBeatmap : CustomSkinWorkingBeatmap
{ {
private readonly bool hasColours; private readonly bool hasColours;
public CustomSkinWorkingBeatmap(AudioManager audio, bool hasColours) public OsuCustomSkinWorkingBeatmap(AudioManager audio, bool hasColours)
: base(new Beatmap : base(createBeatmap(), audio, hasColours)
{
this.hasColours = hasColours;
}
protected override ISkin GetSkin() => new OsuTestBeatmapSkin(BeatmapInfo, hasColours);
private static IBeatmap createBeatmap() =>
new Beatmap
{ {
BeatmapInfo = BeatmapInfo =
{ {
@ -170,49 +115,22 @@ namespace osu.Game.Rulesets.Osu.Tests
Ruleset = new OsuRuleset().RulesetInfo, Ruleset = new OsuRuleset().RulesetInfo,
}, },
HitObjects = { new HitCircle { Position = new Vector2(256, 192) } } HitObjects = { new HitCircle { Position = new Vector2(256, 192) } }
}, null, null, audio) };
{
this.hasColours = hasColours;
}
protected override ISkin GetSkin() => new TestBeatmapSkin(BeatmapInfo, hasColours);
} }
private class TestBeatmapSkin : LegacyBeatmapSkin private class OsuTestBeatmapSkin : TestBeatmapSkin
{ {
public static Color4[] Colours { get; } = public OsuTestBeatmapSkin(BeatmapInfo beatmap, bool hasColours)
: base(beatmap, hasColours)
{ {
new Color4(50, 100, 150, 255),
new Color4(40, 80, 120, 255),
};
public TestBeatmapSkin(BeatmapInfo beatmap, bool hasColours)
: base(beatmap, new ResourceStore<byte[]>(), null)
{
if (hasColours)
Configuration.AddComboColours(Colours);
} }
} }
private class TestSkin : LegacySkin, ISkinSource private class OsuTestSkin : TestSkin
{ {
public static Color4[] Colours { get; } = public OsuTestSkin(bool hasCustomColours)
: base(hasCustomColours)
{ {
new Color4(150, 100, 50, 255),
new Color4(20, 20, 20, 255),
};
public TestSkin(bool hasCustomColours)
: base(new SkinInfo(), null, null, string.Empty)
{
if (hasCustomColours)
Configuration.AddComboColours(Colours);
}
public event Action SourceChanged
{
add { }
remove { }
} }
} }
} }

View File

@ -0,0 +1,147 @@
// 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 osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Bindables;
using osu.Framework.IO.Stores;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Screens.Play;
using osu.Game.Skinning;
using osu.Game.Tests.Visual;
using osuTK.Graphics;
namespace osu.Game.Tests.Beatmaps
{
public class LegacyBeatmapSkinColourTest : ScreenTestScene
{
protected readonly Bindable<bool> BeatmapSkins = new Bindable<bool>();
protected readonly Bindable<bool> BeatmapColours = new Bindable<bool>();
protected ExposedPlayer TestPlayer;
protected WorkingBeatmap TestBeatmap;
public virtual void TestBeatmapComboColours(bool userHasCustomColours, bool useBeatmapSkin) => ConfigureTest(useBeatmapSkin, true, userHasCustomColours);
public virtual void TestBeatmapComboColoursOverride(bool useBeatmapSkin) => ConfigureTest(useBeatmapSkin, false, true);
public virtual void TestBeatmapComboColoursOverrideWithDefaultColours(bool useBeatmapSkin) => ConfigureTest(useBeatmapSkin, false, false);
public virtual void TestBeatmapNoComboColours(bool useBeatmapSkin, bool useBeatmapColour) => ConfigureTest(useBeatmapSkin, useBeatmapColour, false);
public virtual void TestBeatmapNoComboColoursSkinOverride(bool useBeatmapSkin, bool useBeatmapColour) => ConfigureTest(useBeatmapSkin, useBeatmapColour, true);
protected virtual void ConfigureTest(bool useBeatmapSkin, bool useBeatmapColours, bool userHasCustomColours)
{
configureSettings(useBeatmapSkin, useBeatmapColours);
AddStep($"load {(((CustomSkinWorkingBeatmap)TestBeatmap).HasColours ? "coloured " : "")} beatmap", () => TestPlayer = LoadBeatmap(userHasCustomColours));
AddUntilStep("wait for player load", () => TestPlayer.IsLoaded);
}
private void configureSettings(bool beatmapSkins, bool beatmapColours)
{
AddStep($"{(beatmapSkins ? "enable" : "disable")} beatmap skins", () =>
{
BeatmapSkins.Value = beatmapSkins;
});
AddStep($"{(beatmapColours ? "enable" : "disable")} beatmap colours", () =>
{
BeatmapColours.Value = beatmapColours;
});
}
protected virtual ExposedPlayer LoadBeatmap(bool userHasCustomColours)
{
ExposedPlayer player;
Beatmap.Value = TestBeatmap;
LoadScreen(player = CreateTestPlayer(userHasCustomColours));
return player;
}
protected virtual ExposedPlayer CreateTestPlayer(bool userHasCustomColours) => new ExposedPlayer(userHasCustomColours);
protected class ExposedPlayer : Player
{
protected readonly bool UserHasCustomColours;
public ExposedPlayer(bool userHasCustomColours)
: base(new PlayerConfiguration
{
AllowPause = false,
ShowResults = false,
})
{
UserHasCustomColours = userHasCustomColours;
}
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
dependencies.CacheAs<ISkinSource>(new TestSkin(UserHasCustomColours));
return dependencies;
}
public IReadOnlyList<Color4> UsableComboColours =>
GameplayClockContainer.ChildrenOfType<BeatmapSkinProvidingContainer>()
.First()
.GetConfig<GlobalSkinColours, IReadOnlyList<Color4>>(GlobalSkinColours.ComboColours)?.Value;
}
protected class CustomSkinWorkingBeatmap : ClockBackedTestWorkingBeatmap
{
public readonly bool HasColours;
public CustomSkinWorkingBeatmap(IBeatmap beatmap, AudioManager audio, bool hasColours)
: base(beatmap, null, null, audio)
{
HasColours = hasColours;
}
protected override ISkin GetSkin() => new TestBeatmapSkin(BeatmapInfo, HasColours);
}
protected class TestBeatmapSkin : LegacyBeatmapSkin
{
public static Color4[] Colours { get; } =
{
new Color4(50, 100, 150, 255),
new Color4(40, 80, 120, 255),
};
public TestBeatmapSkin(BeatmapInfo beatmap, bool hasColours)
: base(beatmap, new ResourceStore<byte[]>(), null)
{
if (hasColours)
Configuration.AddComboColours(Colours);
}
}
protected class TestSkin : LegacySkin, ISkinSource
{
public static Color4[] Colours { get; } =
{
new Color4(150, 100, 50, 255),
new Color4(20, 20, 20, 255),
};
public TestSkin(bool hasCustomColours)
: base(new SkinInfo(), new ResourceStore<byte[]>(), null, string.Empty)
{
if (hasCustomColours)
Configuration.AddComboColours(Colours);
}
public event Action SourceChanged
{
add { }
remove { }
}
}
}
}