mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 18:23:04 +08:00
Add test coverage of storyboard preferring skin when specified
This commit is contained in:
parent
773ec46989
commit
2f020f8682
@ -2,17 +2,23 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Framework.IO.Stores;
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
|
using osu.Game.Rulesets.Mods;
|
||||||
using osu.Game.Rulesets.Osu;
|
using osu.Game.Rulesets.Osu;
|
||||||
using osu.Game.Storyboards;
|
using osu.Game.Storyboards;
|
||||||
using osu.Game.Storyboards.Drawables;
|
using osu.Game.Storyboards.Drawables;
|
||||||
|
using osu.Game.Tests.Resources;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.Gameplay
|
namespace osu.Game.Tests.Visual.Gameplay
|
||||||
@ -21,17 +27,21 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
{
|
{
|
||||||
protected override Ruleset CreateRulesetForSkinProvider() => new OsuRuleset();
|
protected override Ruleset CreateRulesetForSkinProvider() => new OsuRuleset();
|
||||||
|
|
||||||
[Cached]
|
[Cached(typeof(Storyboard))]
|
||||||
private Storyboard storyboard { get; set; } = new Storyboard();
|
private TestStoryboard storyboard { get; set; } = new TestStoryboard();
|
||||||
|
|
||||||
private IEnumerable<DrawableStoryboardSprite> sprites => this.ChildrenOfType<DrawableStoryboardSprite>();
|
private IEnumerable<DrawableStoryboardSprite> sprites => this.ChildrenOfType<DrawableStoryboardSprite>();
|
||||||
|
|
||||||
|
private const string lookup_name = "hitcircleoverlay";
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestSkinSpriteDisallowedByDefault()
|
public void TestSkinSpriteDisallowedByDefault()
|
||||||
{
|
{
|
||||||
const string lookup_name = "hitcircleoverlay";
|
AddStep("disallow all lookups", () =>
|
||||||
|
{
|
||||||
AddStep("allow skin lookup", () => storyboard.UseSkinSprites = false);
|
storyboard.UseSkinSprites = false;
|
||||||
|
storyboard.AlwaysProvideTexture = false;
|
||||||
|
});
|
||||||
|
|
||||||
AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero)));
|
AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero)));
|
||||||
|
|
||||||
@ -40,11 +50,13 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestAllowLookupFromSkin()
|
public void TestLookupFromStoryboard()
|
||||||
{
|
{
|
||||||
const string lookup_name = "hitcircleoverlay";
|
AddStep("allow storyboard lookup", () =>
|
||||||
|
{
|
||||||
AddStep("allow skin lookup", () => storyboard.UseSkinSprites = true);
|
storyboard.UseSkinSprites = false;
|
||||||
|
storyboard.AlwaysProvideTexture = true;
|
||||||
|
});
|
||||||
|
|
||||||
AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero)));
|
AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero)));
|
||||||
|
|
||||||
@ -52,16 +64,54 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
AddAssert("sprite found texture", () =>
|
AddAssert("sprite found texture", () =>
|
||||||
sprites.Any(sprite => sprite.ChildrenOfType<Sprite>().All(s => s.Texture != null)));
|
sprites.Any(sprite => sprite.ChildrenOfType<Sprite>().All(s => s.Texture != null)));
|
||||||
|
|
||||||
AddAssert("skinnable sprite has correct size", () =>
|
assertStoryboardSourced();
|
||||||
sprites.Any(sprite => sprite.ChildrenOfType<Sprite>().All(s => s.Size == new Vector2(128))));
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestSkinLookupPreferredOverStoryboard()
|
||||||
|
{
|
||||||
|
AddStep("allow all lookups", () =>
|
||||||
|
{
|
||||||
|
storyboard.UseSkinSprites = true;
|
||||||
|
storyboard.AlwaysProvideTexture = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero)));
|
||||||
|
|
||||||
|
// Only checking for at least one sprite that succeeded, as not all skins in this test provide the hitcircleoverlay texture.
|
||||||
|
AddAssert("sprite found texture", () =>
|
||||||
|
sprites.Any(sprite => sprite.ChildrenOfType<Sprite>().All(s => s.Texture != null)));
|
||||||
|
|
||||||
|
assertSkinSourced();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestAllowLookupFromSkin()
|
||||||
|
{
|
||||||
|
AddStep("allow skin lookup", () =>
|
||||||
|
{
|
||||||
|
storyboard.UseSkinSprites = true;
|
||||||
|
storyboard.AlwaysProvideTexture = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero)));
|
||||||
|
|
||||||
|
// Only checking for at least one sprite that succeeded, as not all skins in this test provide the hitcircleoverlay texture.
|
||||||
|
AddAssert("sprite found texture", () =>
|
||||||
|
sprites.Any(sprite => sprite.ChildrenOfType<Sprite>().All(s => s.Texture != null)));
|
||||||
|
|
||||||
|
assertSkinSourced();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestFlippedSprite()
|
public void TestFlippedSprite()
|
||||||
{
|
{
|
||||||
const string lookup_name = "hitcircleoverlay";
|
AddStep("allow all lookups", () =>
|
||||||
|
{
|
||||||
|
storyboard.UseSkinSprites = true;
|
||||||
|
storyboard.AlwaysProvideTexture = true;
|
||||||
|
});
|
||||||
|
|
||||||
AddStep("allow skin lookup", () => storyboard.UseSkinSprites = true);
|
|
||||||
AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero)));
|
AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero)));
|
||||||
AddStep("flip sprites", () => sprites.ForEach(s =>
|
AddStep("flip sprites", () => sprites.ForEach(s =>
|
||||||
{
|
{
|
||||||
@ -74,9 +124,12 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestZeroScale()
|
public void TestZeroScale()
|
||||||
{
|
{
|
||||||
const string lookup_name = "hitcircleoverlay";
|
AddStep("allow all lookups", () =>
|
||||||
|
{
|
||||||
|
storyboard.UseSkinSprites = true;
|
||||||
|
storyboard.AlwaysProvideTexture = true;
|
||||||
|
});
|
||||||
|
|
||||||
AddStep("allow skin lookup", () => storyboard.UseSkinSprites = true);
|
|
||||||
AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero)));
|
AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero)));
|
||||||
AddAssert("sprites present", () => sprites.All(s => s.IsPresent));
|
AddAssert("sprites present", () => sprites.All(s => s.IsPresent));
|
||||||
AddStep("scale sprite", () => sprites.ForEach(s => s.VectorScale = new Vector2(0, 1)));
|
AddStep("scale sprite", () => sprites.ForEach(s => s.VectorScale = new Vector2(0, 1)));
|
||||||
@ -86,9 +139,12 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestNegativeScale()
|
public void TestNegativeScale()
|
||||||
{
|
{
|
||||||
const string lookup_name = "hitcircleoverlay";
|
AddStep("allow all lookups", () =>
|
||||||
|
{
|
||||||
|
storyboard.UseSkinSprites = true;
|
||||||
|
storyboard.AlwaysProvideTexture = true;
|
||||||
|
});
|
||||||
|
|
||||||
AddStep("allow skin lookup", () => storyboard.UseSkinSprites = true);
|
|
||||||
AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero)));
|
AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero)));
|
||||||
AddStep("scale sprite", () => sprites.ForEach(s => s.VectorScale = new Vector2(-1)));
|
AddStep("scale sprite", () => sprites.ForEach(s => s.VectorScale = new Vector2(-1)));
|
||||||
AddAssert("origin flipped", () => sprites.All(s => s.Origin == Anchor.BottomRight));
|
AddAssert("origin flipped", () => sprites.All(s => s.Origin == Anchor.BottomRight));
|
||||||
@ -97,9 +153,12 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestNegativeScaleWithFlippedSprite()
|
public void TestNegativeScaleWithFlippedSprite()
|
||||||
{
|
{
|
||||||
const string lookup_name = "hitcircleoverlay";
|
AddStep("allow all lookups", () =>
|
||||||
|
{
|
||||||
|
storyboard.UseSkinSprites = true;
|
||||||
|
storyboard.AlwaysProvideTexture = true;
|
||||||
|
});
|
||||||
|
|
||||||
AddStep("allow skin lookup", () => storyboard.UseSkinSprites = true);
|
|
||||||
AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero)));
|
AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero)));
|
||||||
AddStep("scale sprite", () => sprites.ForEach(s => s.VectorScale = new Vector2(-1)));
|
AddStep("scale sprite", () => sprites.ForEach(s => s.VectorScale = new Vector2(-1)));
|
||||||
AddAssert("origin flipped", () => sprites.All(s => s.Origin == Anchor.BottomRight));
|
AddAssert("origin flipped", () => sprites.All(s => s.Origin == Anchor.BottomRight));
|
||||||
@ -111,13 +170,78 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
AddAssert("origin back", () => sprites.All(s => s.Origin == Anchor.TopLeft));
|
AddAssert("origin back", () => sprites.All(s => s.Origin == Anchor.TopLeft));
|
||||||
}
|
}
|
||||||
|
|
||||||
private DrawableStoryboardSprite createSprite(string lookupName, Anchor origin, Vector2 initialPosition)
|
private DrawableStoryboard createSprite(string lookupName, Anchor origin, Vector2 initialPosition)
|
||||||
=> new DrawableStoryboardSprite(
|
{
|
||||||
new StoryboardSprite(lookupName, origin, initialPosition)
|
var layer = storyboard.GetLayer("Background");
|
||||||
).With(s =>
|
|
||||||
|
var sprite = new StoryboardSprite(lookupName, origin, initialPosition);
|
||||||
|
sprite.AddLoop(Time.Current, 100).Alpha.Add(Easing.None, 0, 10000, 1, 1);
|
||||||
|
|
||||||
|
layer.Elements.Clear();
|
||||||
|
layer.Add(sprite);
|
||||||
|
|
||||||
|
return storyboard.CreateDrawable();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertStoryboardSourced()
|
||||||
|
{
|
||||||
|
AddAssert("sprite came from storyboard", () =>
|
||||||
|
sprites.Any(sprite => sprite.ChildrenOfType<Sprite>().All(s => s.Size == new Vector2(200))));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertSkinSourced()
|
||||||
|
{
|
||||||
|
AddAssert("sprite came from skin", () =>
|
||||||
|
sprites.Any(sprite => sprite.ChildrenOfType<Sprite>().All(s => s.Size == new Vector2(128))));
|
||||||
|
}
|
||||||
|
|
||||||
|
private partial class TestStoryboard : Storyboard
|
||||||
|
{
|
||||||
|
public override DrawableStoryboard CreateDrawable(IReadOnlyList<Mod>? mods = null)
|
||||||
{
|
{
|
||||||
s.LifetimeStart = double.MinValue;
|
return new TestDrawableStoryboard(this, mods);
|
||||||
s.LifetimeEnd = double.MaxValue;
|
}
|
||||||
});
|
|
||||||
|
public bool AlwaysProvideTexture { get; set; }
|
||||||
|
|
||||||
|
public override string GetStoragePathFromStoryboardPath(string path) => AlwaysProvideTexture ? path : string.Empty;
|
||||||
|
|
||||||
|
private partial class TestDrawableStoryboard : DrawableStoryboard
|
||||||
|
{
|
||||||
|
private readonly bool alwaysProvideTexture;
|
||||||
|
|
||||||
|
public TestDrawableStoryboard(TestStoryboard storyboard, IReadOnlyList<Mod>? mods)
|
||||||
|
: base(storyboard, mods)
|
||||||
|
{
|
||||||
|
alwaysProvideTexture = storyboard.AlwaysProvideTexture;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override IResourceStore<byte[]> CreateResourceLookupStore() => alwaysProvideTexture
|
||||||
|
? new AlwaysReturnsTextureStore()
|
||||||
|
: new ResourceStore<byte[]>();
|
||||||
|
|
||||||
|
internal class AlwaysReturnsTextureStore : IResourceStore<byte[]>
|
||||||
|
{
|
||||||
|
private const string test_image = "Resources/Textures/test-image.png";
|
||||||
|
|
||||||
|
private readonly DllResourceStore store;
|
||||||
|
|
||||||
|
public AlwaysReturnsTextureStore()
|
||||||
|
{
|
||||||
|
store = TestResources.GetStore();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose() => store.Dispose();
|
||||||
|
|
||||||
|
public byte[] Get(string name) => store.Get(test_image);
|
||||||
|
|
||||||
|
public Task<byte[]> GetAsync(string name, CancellationToken cancellationToken = new CancellationToken()) => store.GetAsync(test_image, cancellationToken);
|
||||||
|
|
||||||
|
public Stream GetStream(string name) => store.GetStream(test_image);
|
||||||
|
|
||||||
|
public IEnumerable<string> GetAvailableResources() => store.GetAvailableResources();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user