mirror of
https://github.com/ppy/osu
synced 2025-02-04 04:11:54 +00:00
Add comprehensive skin fallback integration testing
This commit is contained in:
parent
4c2a6b755f
commit
01aede3e29
osu.Game.Rulesets.Osu.Tests
osu.Game
Beatmaps
Skinning
Tests/Visual
@ -1,7 +1,23 @@
|
||||
// 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.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Sample;
|
||||
using osu.Framework.Graphics;
|
||||
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;
|
||||
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
||||
using osu.Game.Screens.Play;
|
||||
using osu.Game.Skinning;
|
||||
using osu.Game.Tests.Visual;
|
||||
|
||||
namespace osu.Game.Rulesets.Osu.Tests
|
||||
@ -9,9 +25,133 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
[TestFixture]
|
||||
public class TestSceneOsuPlayer : PlayerTestScene
|
||||
{
|
||||
private readonly TestSource testUserSkin;
|
||||
private readonly TestSource testBeatmapSkin;
|
||||
|
||||
public TestSceneOsuPlayer()
|
||||
: base(new OsuRuleset())
|
||||
{
|
||||
testUserSkin = new TestSource("user");
|
||||
testBeatmapSkin = new TestSource("beatmap");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestBeatmapSkinDefault()
|
||||
{
|
||||
AddStep("enable user provider", () => testUserSkin.Enabled = true);
|
||||
|
||||
AddStep("enable beatmap skin", () => LocalConfig.Set<bool>(OsuSetting.BeatmapSkins, true));
|
||||
checkNextHitObject("beatmap");
|
||||
|
||||
AddStep("disable beatmap skin", () => LocalConfig.Set<bool>(OsuSetting.BeatmapSkins, false));
|
||||
checkNextHitObject("user");
|
||||
|
||||
AddStep("disable user provider", () => testUserSkin.Enabled = false);
|
||||
checkNextHitObject(null);
|
||||
}
|
||||
|
||||
private void checkNextHitObject(string skin) =>
|
||||
AddUntilStep($"check skin from {skin}", () =>
|
||||
{
|
||||
var firstObject = ((TestPlayer)Player).DrawableRuleset.Playfield.AllHitObjects.OfType<DrawableHitCircle>().FirstOrDefault();
|
||||
|
||||
if (firstObject == null)
|
||||
return false;
|
||||
|
||||
var skinnable = firstObject?.ApproachCircle.Child as SkinnableDrawable;
|
||||
|
||||
if (skin == null && skinnable?.Drawable is Sprite)
|
||||
// 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 Player CreatePlayer(Ruleset ruleset) => new SkinProvidingPlayer(testUserSkin);
|
||||
|
||||
protected override WorkingBeatmap CreateWorkingBeatmap(IBeatmap beatmap) => new CustomSkinWorkingBeatmap(beatmap, Clock, audio, testBeatmapSkin);
|
||||
|
||||
public class CustomSkinWorkingBeatmap : ClockBackedTestWorkingBeatmap
|
||||
{
|
||||
private readonly ISkinSource skin;
|
||||
|
||||
public CustomSkinWorkingBeatmap(IBeatmap beatmap, IFrameBasedClock frameBasedClock, AudioManager audio, ISkinSource skin)
|
||||
: base(beatmap, frameBasedClock, audio)
|
||||
{
|
||||
this.skin = skin;
|
||||
}
|
||||
|
||||
protected override ISkin GetSkin() => skin;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public class TestSource : ISkinSource
|
||||
{
|
||||
private readonly string identifier;
|
||||
|
||||
public TestSource(string identifier)
|
||||
{
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
public Drawable GetDrawableComponent(string componentName)
|
||||
{
|
||||
if (!enabled) return null;
|
||||
|
||||
return new SpriteText
|
||||
{
|
||||
Text = identifier,
|
||||
Font = OsuFont.Default.With(size: 30),
|
||||
};
|
||||
}
|
||||
|
||||
public Texture GetTexture(string componentName) => null;
|
||||
|
||||
public SampleChannel GetSample(ISampleInfo sampleInfo) => null;
|
||||
|
||||
public TValue GetValue<TConfiguration, TValue>(Func<TConfiguration, TValue> query) where TConfiguration : SkinConfiguration => default;
|
||||
|
||||
public event Action SourceChanged;
|
||||
|
||||
private bool enabled = true;
|
||||
|
||||
public bool Enabled
|
||||
{
|
||||
get => enabled;
|
||||
set
|
||||
{
|
||||
if (value == enabled)
|
||||
return;
|
||||
|
||||
enabled = value;
|
||||
SourceChanged?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ namespace osu.Game.Beatmaps
|
||||
return storyboard;
|
||||
}
|
||||
|
||||
protected override Skin GetSkin()
|
||||
protected override ISkin GetSkin()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -46,7 +46,7 @@ namespace osu.Game.Beatmaps
|
||||
background = new RecyclableLazy<Texture>(GetBackground, BackgroundStillValid);
|
||||
waveform = new RecyclableLazy<Waveform>(GetWaveform);
|
||||
storyboard = new RecyclableLazy<Storyboard>(GetStoryboard);
|
||||
skin = new RecyclableLazy<Skin>(GetSkin);
|
||||
skin = new RecyclableLazy<ISkin>(GetSkin);
|
||||
|
||||
total_count.Value++;
|
||||
}
|
||||
@ -214,10 +214,10 @@ namespace osu.Game.Beatmaps
|
||||
private readonly RecyclableLazy<Storyboard> storyboard;
|
||||
|
||||
public bool SkinLoaded => skin.IsResultAvailable;
|
||||
public Skin Skin => skin.Value;
|
||||
public ISkin Skin => skin.Value;
|
||||
|
||||
protected virtual Skin GetSkin() => new DefaultSkin();
|
||||
private readonly RecyclableLazy<Skin> skin;
|
||||
protected virtual ISkin GetSkin() => new DefaultSkin();
|
||||
private readonly RecyclableLazy<ISkin> skin;
|
||||
|
||||
/// <summary>
|
||||
/// Transfer pieces of a beatmap to a new one, where possible, to save on loading.
|
||||
|
@ -16,7 +16,7 @@ namespace osu.Game.Skinning
|
||||
/// <summary>
|
||||
/// The displayed component.
|
||||
/// </summary>
|
||||
protected Drawable Drawable { get; private set; }
|
||||
public Drawable Drawable { get; private set; }
|
||||
|
||||
private readonly string componentName;
|
||||
|
||||
|
@ -22,12 +22,13 @@ namespace osu.Game.Tests.Visual
|
||||
this.ruleset = ruleset;
|
||||
}
|
||||
|
||||
protected OsuConfigManager LocalConfig;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
OsuConfigManager manager;
|
||||
Dependencies.Cache(manager = new OsuConfigManager(LocalStorage));
|
||||
manager.GetBindable<double>(OsuSetting.DimLevel).Value = 1.0;
|
||||
Dependencies.Cache(LocalConfig = new OsuConfigManager(LocalStorage));
|
||||
LocalConfig.GetBindable<double>(OsuSetting.DimLevel).Value = 1.0;
|
||||
}
|
||||
|
||||
[SetUpSteps]
|
||||
|
@ -1,6 +1,7 @@
|
||||
// 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 osu.Game.Rulesets.UI;
|
||||
using osu.Game.Screens.Play;
|
||||
|
||||
namespace osu.Game.Tests.Visual
|
||||
@ -9,6 +10,8 @@ namespace osu.Game.Tests.Visual
|
||||
{
|
||||
protected override bool PauseOnFocusLost => false;
|
||||
|
||||
public new DrawableRuleset DrawableRuleset => base.DrawableRuleset;
|
||||
|
||||
public TestPlayer(bool allowPause = true, bool showResults = true)
|
||||
: base(allowPause, showResults)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user