1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-18 10:13:21 +08:00
osu-lazer/osu.Game.Rulesets.Osu.Tests/SkinnableTestScene.cs

72 lines
3.0 KiB
C#
Raw Normal View History

2019-07-26 18:29:06 +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;
2019-08-20 16:39:16 +08:00
using System.Text.RegularExpressions;
2019-07-26 18:29:06 +08:00
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2019-08-20 16:39:16 +08:00
using osu.Framework.Graphics.Textures;
2019-07-26 18:29:06 +08:00
using osu.Framework.IO.Stores;
using osu.Game.Skinning;
using osu.Game.Tests.Visual;
namespace osu.Game.Rulesets.Osu.Tests
{
public abstract class SkinnableTestScene : OsuGridTestScene
{
private Skin metricsSkin;
private Skin defaultSkin;
private Skin specialSkin;
2019-07-30 20:53:28 +08:00
protected SkinnableTestScene()
: base(2, 2)
{
}
2019-07-26 18:29:06 +08:00
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
2019-08-20 16:39:16 +08:00
var dllStore = new DllResourceStore("osu.Game.Rulesets.Osu.Tests.dll");
2019-07-26 18:29:06 +08:00
2019-08-20 16:39:16 +08:00
metricsSkin = new TestLegacySkin(new SkinInfo(), new NamespacedResourceStore<byte[]>(dllStore, "Resources/metrics_skin"), audio, true);
defaultSkin = new TestLegacySkin(new SkinInfo(), new NamespacedResourceStore<byte[]>(dllStore, "Resources/default_skin"), audio, false);
specialSkin = new TestLegacySkin(new SkinInfo(), new NamespacedResourceStore<byte[]>(dllStore, "Resources/special_skin"), audio, true);
2019-07-26 18:29:06 +08:00
}
public void SetContents(Func<Drawable> creationFunction)
{
Cell(0).Child = new LocalSkinOverrideContainer(null) { RelativeSizeAxes = Axes.Both }.WithChild(creationFunction());
Cell(1).Child = new LocalSkinOverrideContainer(metricsSkin) { RelativeSizeAxes = Axes.Both }.WithChild(creationFunction());
Cell(2).Child = new LocalSkinOverrideContainer(defaultSkin) { RelativeSizeAxes = Axes.Both }.WithChild(creationFunction());
Cell(3).Child = new LocalSkinOverrideContainer(specialSkin) { RelativeSizeAxes = Axes.Both }.WithChild(creationFunction());
}
2019-08-20 16:39:16 +08:00
private class TestLegacySkin : LegacySkin
2019-07-26 18:29:06 +08:00
{
2019-08-20 16:39:16 +08:00
private readonly bool extrapolateAnimations;
2019-07-30 20:53:28 +08:00
2019-08-20 16:39:16 +08:00
public TestLegacySkin(SkinInfo skin, IResourceStore<byte[]> storage, AudioManager audioManager, bool extrapolateAnimations)
: base(skin, storage, audioManager, "skin.ini")
{
this.extrapolateAnimations = extrapolateAnimations;
}
2019-07-30 20:53:28 +08:00
2019-08-20 16:39:16 +08:00
public override Texture GetTexture(string componentName)
{
// extrapolate frames to test longer animations
if (extrapolateAnimations)
{
var match = Regex.Match(componentName, "-([0-9]*)");
2019-07-30 20:53:28 +08:00
if (match.Length > 0 && int.TryParse(match.Groups[1].Value, out var number) && number < 60)
return base.GetTexture(componentName.Replace($"-{number}", $"-{number % 2}"));
2019-08-20 16:39:16 +08:00
}
2019-07-30 20:53:28 +08:00
2019-08-20 16:39:16 +08:00
return base.GetTexture(componentName);
2019-07-30 20:53:28 +08:00
}
2019-07-26 18:29:06 +08:00
}
}
}