1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 13:22:57 +08:00
osu-lazer/osu.Game.Rulesets.Osu.Tests/TestSceneSkinFallbacks.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

194 lines
6.8 KiB
C#
Raw Normal View History

2019-08-30 13:44:36 +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.
using System;
using System.Collections.Generic;
2019-08-30 13:44:36 +08:00
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
2019-08-30 13:44:36 +08:00
using osu.Framework.Graphics;
2020-07-17 15:54:30 +08:00
using osu.Framework.Graphics.OpenGL.Textures;
2019-08-30 13:44:36 +08:00
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Framework.Timing;
using osu.Game.Audio;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Graphics;
2019-11-25 10:30:55 +08:00
using osu.Game.Graphics.Sprites;
2019-08-30 13:44:36 +08:00
using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Rulesets.Osu.Skinning.Default;
2019-08-30 13:44:36 +08:00
using osu.Game.Skinning;
2019-11-21 17:50:54 +08:00
using osu.Game.Storyboards;
using osu.Game.Tests.Visual;
2019-08-30 13:44:36 +08:00
namespace osu.Game.Rulesets.Osu.Tests
{
[TestFixture]
public class TestSceneSkinFallbacks : TestSceneOsuPlayer
2019-08-30 13:44:36 +08:00
{
private readonly TestSource testUserSkin;
private readonly TestSource testBeatmapSkin;
2019-08-30 13:44:36 +08:00
public TestSceneSkinFallbacks()
{
testUserSkin = new TestSource("user");
testBeatmapSkin = new TestSource("beatmap");
2019-08-30 13:44:36 +08:00
}
[Test]
public void TestBeatmapSkinDefault()
{
AddStep("enable user provider", () => testUserSkin.Enabled = true);
AddStep("enable beatmap skin", () => LocalConfig.SetValue(OsuSetting.BeatmapSkins, true));
2019-08-30 13:44:36 +08:00
checkNextHitObject("beatmap");
AddStep("disable beatmap skin", () => LocalConfig.SetValue(OsuSetting.BeatmapSkins, false));
2019-08-30 13:44:36 +08:00
checkNextHitObject("user");
AddStep("disable user provider", () => testUserSkin.Enabled = false);
checkNextHitObject(null);
}
[Test]
public void TestBeatmapColourDefault()
{
AddStep("enable user provider", () => testUserSkin.Enabled = true);
AddStep("enable beatmap skin", () => LocalConfig.SetValue(OsuSetting.BeatmapSkins, true));
AddStep("enable beatmap colours", () => LocalConfig.SetValue(OsuSetting.BeatmapColours, true));
checkNextHitObject("beatmap");
AddStep("enable beatmap skin", () => LocalConfig.SetValue(OsuSetting.BeatmapSkins, true));
AddStep("disable beatmap colours", () => LocalConfig.SetValue(OsuSetting.BeatmapColours, false));
checkNextHitObject("beatmap");
AddStep("disable beatmap skin", () => LocalConfig.SetValue(OsuSetting.BeatmapSkins, false));
AddStep("enable beatmap colours", () => LocalConfig.SetValue(OsuSetting.BeatmapColours, true));
checkNextHitObject("user");
AddStep("disable beatmap skin", () => LocalConfig.SetValue(OsuSetting.BeatmapSkins, false));
AddStep("disable beatmap colours", () => LocalConfig.SetValue(OsuSetting.BeatmapColours, false));
checkNextHitObject("user");
AddStep("disable user provider", () => testUserSkin.Enabled = false);
checkNextHitObject(null);
}
2019-08-30 13:44:36 +08:00
private void checkNextHitObject(string skin) =>
AddUntilStep($"check skin from {skin}", () =>
{
var firstObject = Player.DrawableRuleset.Playfield.HitObjectContainer.AliveObjects.OfType<DrawableHitCircle>().FirstOrDefault();
2019-08-30 13:44:36 +08:00
if (firstObject == null)
return false;
var skinnable = firstObject.ApproachCircle;
2019-08-30 13:44:36 +08:00
if (skin == null && skinnable?.Drawable is DefaultApproachCircle)
2019-08-30 13:44:36 +08:00
// check for default skin provider
return true;
var text = skinnable?.Drawable as SpriteText;
return text?.Text == skin;
});
[Resolved]
private AudioManager audio { get; set; }
protected override TestPlayer CreatePlayer(Ruleset ruleset) => new SkinProvidingPlayer(testUserSkin);
2019-08-30 13:44:36 +08:00
2019-11-21 17:50:54 +08:00
protected override WorkingBeatmap CreateWorkingBeatmap(IBeatmap beatmap, Storyboard storyboard = null) => new CustomSkinWorkingBeatmap(beatmap, storyboard, Clock, audio, testBeatmapSkin);
2019-08-30 13:44:36 +08:00
public class CustomSkinWorkingBeatmap : ClockBackedTestWorkingBeatmap
{
private readonly ISkinSource skin;
2019-08-30 13:44:36 +08:00
public CustomSkinWorkingBeatmap(IBeatmap beatmap, Storyboard storyboard, IFrameBasedClock frameBasedClock, AudioManager audio, ISkinSource skin)
2019-11-21 17:50:54 +08:00
: base(beatmap, storyboard, frameBasedClock, audio)
2019-08-30 13:44:36 +08:00
{
this.skin = skin;
2019-08-30 13:44:36 +08:00
}
protected override ISkin GetSkin() => skin;
2019-08-30 13:44:36 +08:00
}
public class SkinProvidingPlayer : TestPlayer
{
private readonly TestSource userSkin;
public SkinProvidingPlayer(TestSource userSkin)
{
this.userSkin = userSkin;
}
private DependencyContainer dependencies;
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
dependencies.CacheAs<ISkinSource>(userSkin);
return dependencies;
}
}
2019-08-30 13:44:36 +08:00
public class TestSource : ISkinSource
{
private readonly string identifier;
public TestSource(string identifier)
{
this.identifier = identifier;
}
public Drawable GetDrawableComponent(ISkinComponent component)
2019-08-30 13:44:36 +08:00
{
if (!enabled) return null;
if (component is OsuSkinComponent osuComponent && osuComponent.Component == OsuSkinComponents.SliderBody)
return null;
2019-11-25 10:30:55 +08:00
return new OsuSpriteText
2019-08-30 13:44:36 +08:00
{
Text = identifier,
Font = OsuFont.Default.With(size: 30),
};
}
2020-07-17 15:54:30 +08:00
public Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) => null;
2019-08-30 13:44:36 +08:00
public ISample GetSample(ISampleInfo sampleInfo) => null;
2019-08-30 13:44:36 +08:00
public IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup) => null;
public ISkin FindProvider(Func<ISkin, bool> lookupFunction) => lookupFunction(this) ? this : null;
2019-08-30 13:44:36 +08:00
public IEnumerable<ISkin> AllSources => new[] { this };
2019-08-30 13:44:36 +08:00
public event Action SourceChanged;
private bool enabled = true;
public bool Enabled
{
get => enabled;
set
{
if (value == enabled)
return;
enabled = value;
SourceChanged?.Invoke();
}
}
}
}
}