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

86 lines
3.3 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-12-12 21:27:11 +08:00
private Skin oldSkin;
2019-07-26 18:29:06 +08:00
2019-07-30 20:53:28 +08:00
protected SkinnableTestScene()
2019-12-12 21:27:11 +08:00
: base(2, 3)
2019-07-30 20:53:28 +08:00
{
}
2019-07-26 18:29:06 +08:00
[BackgroundDependencyLoader]
private void load(AudioManager audio, SkinManager skinManager)
2019-07-26 18:29:06 +08:00
{
var dllStore = new DllResourceStore(typeof(SkinnableTestScene).Assembly);
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 = skinManager.GetSkin(DefaultLegacySkin.Info);
2019-08-20 16:39:16 +08:00
specialSkin = new TestLegacySkin(new SkinInfo(), new NamespacedResourceStore<byte[]>(dllStore, "Resources/special_skin"), audio, true);
2019-12-12 21:27:11 +08:00
oldSkin = new TestLegacySkin(new SkinInfo(), new NamespacedResourceStore<byte[]>(dllStore, "Resources/old_skin"), audio, true);
2019-07-26 18:29:06 +08:00
}
public void SetContents(Func<Drawable> creationFunction)
{
2019-08-26 11:31:51 +08:00
Cell(0).Child = createProvider(null, creationFunction);
Cell(1).Child = createProvider(metricsSkin, creationFunction);
Cell(2).Child = createProvider(defaultSkin, creationFunction);
Cell(3).Child = createProvider(specialSkin, creationFunction);
2019-12-12 21:27:11 +08:00
Cell(4).Child = createProvider(oldSkin, creationFunction);
2019-08-26 11:31:51 +08:00
}
private Drawable createProvider(Skin skin, Func<Drawable> creationFunction)
{
var mainProvider = new SkinProvidingContainer(skin);
2019-08-26 11:31:51 +08:00
return mainProvider
.WithChild(new SkinProvidingContainer(Ruleset.Value.CreateInstance().CreateLegacySkinProvider(mainProvider))
{
Child = creationFunction()
});
2019-07-26 18:29:06 +08:00
}
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
}
}
}