1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 08:32:57 +08:00

Add basic skinning test

This commit is contained in:
Dean Herbert 2019-07-26 19:29:06 +09:00
parent 85e6ac156f
commit c514cbe2b7
14 changed files with 92 additions and 28 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 256 KiB

View File

@ -0,0 +1,66 @@
// 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.IO;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
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 static Skin getSkinFromResources(SkinManager skins, string name)
{
using (var storage = new DllResourceStore("osu.Game.Rulesets.Osu.Tests.dll"))
{
var tempName = Path.GetTempFileName();
File.Delete(tempName);
Directory.CreateDirectory(tempName);
var files = storage.GetAvailableResources().Where(f => f.StartsWith($"Resources/{name}"));
foreach (var file in files)
using (var stream = storage.GetStream(file))
using (var newFile = File.Create(Path.Combine(tempName, Path.GetFileName(file))))
stream.CopyTo(newFile);
return skins.GetSkin(skins.Import(tempName).Result);
}
}
private Skin metricsSkin;
private Skin defaultSkin;
private Skin specialSkin;
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
var skins = new SkinManager(LocalStorage, ContextFactory, null, audio);
metricsSkin = getSkinFromResources(skins, "metrics_skin");
defaultSkin = getSkinFromResources(skins, "default_skin");
specialSkin = getSkinFromResources(skins, "special_skin");
}
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());
}
protected SkinnableTestScene()
: base(2, 2)
{
}
}
}

View File

@ -7,7 +7,6 @@ using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Tests.Visual;
using osuTK;
using System.Collections.Generic;
using System;
@ -19,37 +18,32 @@ using osu.Game.Rulesets.Scoring;
namespace osu.Game.Rulesets.Osu.Tests
{
[TestFixture]
public class TestSceneHitCircle : OsuTestScene
public class TestSceneHitCircle : SkinnableTestScene
{
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(DrawableHitCircle)
};
private readonly Container content;
protected override Container<Drawable> Content => content;
private int depthIndex;
public TestSceneHitCircle()
{
base.Content.Add(content = new OsuInputManager(new RulesetInfo { ID = 0 }));
AddStep("Miss Big Single", () => testSingle(2));
AddStep("Miss Medium Single", () => testSingle(5));
AddStep("Miss Small Single", () => testSingle(7));
AddStep("Hit Big Single", () => testSingle(2, true));
AddStep("Hit Medium Single", () => testSingle(5, true));
AddStep("Hit Small Single", () => testSingle(7, true));
AddStep("Miss Big Stream", () => testStream(2));
AddStep("Miss Medium Stream", () => testStream(5));
AddStep("Miss Small Stream", () => testStream(7));
AddStep("Hit Big Stream", () => testStream(2, true));
AddStep("Hit Medium Stream", () => testStream(5, true));
AddStep("Hit Small Stream", () => testStream(7, true));
AddStep("Miss Big Single", () => SetContents(() => testSingle(2)));
AddStep("Miss Medium Single", () => SetContents(() => testSingle(5)));
AddStep("Miss Small Single", () => SetContents(() => testSingle(7)));
AddStep("Hit Big Single", () => SetContents(() => testSingle(2, true)));
AddStep("Hit Medium Single", () => SetContents(() => testSingle(5, true)));
AddStep("Hit Small Single", () => SetContents(() => testSingle(7, true)));
AddStep("Miss Big Stream", () => SetContents(() => testStream(2)));
AddStep("Miss Medium Stream", () => SetContents(() => testStream(5)));
AddStep("Miss Small Stream", () => SetContents(() => testStream(7)));
AddStep("Hit Big Stream", () => SetContents(() => testStream(2, true)));
AddStep("Hit Medium Stream", () => SetContents(() => testStream(5, true)));
AddStep("Hit Small Stream", () => SetContents(() => testStream(7, true)));
}
private void testSingle(float circleSize, bool auto = false, double timeOffset = 0, Vector2? positionOffset = null)
private Drawable testSingle(float circleSize, bool auto = false, double timeOffset = 0, Vector2? positionOffset = null)
{
positionOffset = positionOffset ?? Vector2.Zero;
@ -70,18 +64,22 @@ namespace osu.Game.Rulesets.Osu.Tests
foreach (var mod in Mods.Value.OfType<IApplicableToDrawableHitObjects>())
mod.ApplyToDrawableHitObjects(new[] { drawable });
Add(drawable);
return drawable;
}
private void testStream(float circleSize, bool auto = false)
private Drawable testStream(float circleSize, bool auto = false)
{
var container = new Container { RelativeSizeAxes = Axes.Both };
Vector2 pos = new Vector2(-250, 0);
for (int i = 0; i <= 1000; i += 100)
{
testSingle(circleSize, auto, i, pos);
container.Add(testSingle(circleSize, auto, i, pos));
pos.X += 50;
}
return container;
}
protected class TestDrawableHitCircle : DrawableHitCircle

View File

@ -45,7 +45,7 @@ namespace osu.Game.Skinning
CurrentSkinInfo.Value = SkinInfo.Default;
};
CurrentSkinInfo.ValueChanged += skin => CurrentSkin.Value = getSkin(skin.NewValue);
CurrentSkinInfo.ValueChanged += skin => CurrentSkin.Value = GetSkin(skin.NewValue);
CurrentSkin.ValueChanged += skin =>
{
if (skin.NewValue.SkinInfo != CurrentSkinInfo.Value)
@ -80,7 +80,7 @@ namespace osu.Game.Skinning
{
await base.Populate(model, archive, cancellationToken);
Skin reference = getSkin(model);
Skin reference = GetSkin(model);
if (!string.IsNullOrEmpty(reference.Configuration.SkinInfo.Name))
{
@ -99,7 +99,7 @@ namespace osu.Game.Skinning
/// </summary>
/// <param name="skinInfo">The skin to lookup.</param>
/// <returns>A <see cref="Skin"/> instance correlating to the provided <see cref="SkinInfo"/>.</returns>
private Skin getSkin(SkinInfo skinInfo)
public Skin GetSkin(SkinInfo skinInfo)
{
if (skinInfo == SkinInfo.Default)
return new DefaultSkin();

View File

@ -5,7 +5,7 @@ using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
namespace osu.Game.Tests.Visual.UserInterface
namespace osu.Game.Tests.Visual
{
/// <summary>
/// An abstract test case which exposes small cells arranged in a grid.

View File

@ -35,7 +35,7 @@
<DefineConstants></DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodesignKey>iPhone Distribution</CodesignKey>
<CodesignKey>iPhone Developer</CodesignKey>
<MtouchUseLlvm>true</MtouchUseLlvm>
<MtouchFloat32>true</MtouchFloat32>
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>