2020-10-20 20:42:47 +00: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.
|
|
|
|
|
2022-03-14 00:46:05 +00:00
|
|
|
using System.Collections.Generic;
|
2023-09-19 10:44:41 +00:00
|
|
|
using System.IO;
|
2020-10-20 20:42:47 +00:00
|
|
|
using System.Linq;
|
2023-09-19 10:44:41 +00:00
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
2020-10-20 20:42:47 +00:00
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
2022-03-14 00:35:23 +00:00
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
2020-10-20 20:42:47 +00:00
|
|
|
using osu.Framework.Graphics;
|
2024-04-22 15:04:56 +00:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2022-04-07 08:51:10 +00:00
|
|
|
using osu.Framework.Graphics.Sprites;
|
2023-09-19 10:44:41 +00:00
|
|
|
using osu.Framework.IO.Stores;
|
2020-10-20 20:42:47 +00:00
|
|
|
using osu.Framework.Testing;
|
|
|
|
using osu.Game.Rulesets;
|
2023-09-19 10:44:41 +00:00
|
|
|
using osu.Game.Rulesets.Mods;
|
2020-10-20 20:42:47 +00:00
|
|
|
using osu.Game.Rulesets.Osu;
|
|
|
|
using osu.Game.Storyboards;
|
|
|
|
using osu.Game.Storyboards.Drawables;
|
2023-09-19 10:44:41 +00:00
|
|
|
using osu.Game.Tests.Resources;
|
2020-10-20 20:42:47 +00:00
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Gameplay
|
|
|
|
{
|
|
|
|
public partial class TestSceneDrawableStoryboardSprite : SkinnableTestScene
|
|
|
|
{
|
|
|
|
protected override Ruleset CreateRulesetForSkinProvider() => new OsuRuleset();
|
|
|
|
|
2023-09-19 10:44:41 +00:00
|
|
|
[Cached(typeof(Storyboard))]
|
|
|
|
private TestStoryboard storyboard { get; set; } = new TestStoryboard();
|
2020-10-20 20:42:47 +00:00
|
|
|
|
2022-03-14 00:46:05 +00:00
|
|
|
private IEnumerable<DrawableStoryboardSprite> sprites => this.ChildrenOfType<DrawableStoryboardSprite>();
|
|
|
|
|
2023-09-19 10:44:41 +00:00
|
|
|
private const string lookup_name = "hitcircleoverlay";
|
|
|
|
|
2020-10-20 20:42:47 +00:00
|
|
|
[Test]
|
|
|
|
public void TestSkinSpriteDisallowedByDefault()
|
|
|
|
{
|
2023-09-19 10:44:41 +00:00
|
|
|
AddStep("disallow all lookups", () =>
|
|
|
|
{
|
|
|
|
storyboard.UseSkinSprites = false;
|
2024-04-22 15:04:56 +00:00
|
|
|
storyboard.ProvideResources = false;
|
2023-09-19 10:44:41 +00:00
|
|
|
});
|
2020-10-20 20:42:47 +00:00
|
|
|
|
2021-06-02 07:04:53 +00:00
|
|
|
AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero)));
|
2020-10-20 20:42:47 +00:00
|
|
|
|
2022-04-07 08:51:10 +00:00
|
|
|
AddAssert("sprite didn't find texture", () =>
|
|
|
|
sprites.All(sprite => sprite.ChildrenOfType<Sprite>().All(s => s.Texture == null)));
|
2020-10-20 20:42:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2023-09-19 10:44:41 +00:00
|
|
|
public void TestLookupFromStoryboard()
|
|
|
|
{
|
|
|
|
AddStep("allow storyboard lookup", () =>
|
|
|
|
{
|
|
|
|
storyboard.UseSkinSprites = false;
|
2024-04-22 15:04:56 +00:00
|
|
|
storyboard.ProvideResources = true;
|
2023-09-19 10:44:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
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)));
|
|
|
|
|
|
|
|
assertStoryboardSourced();
|
|
|
|
}
|
|
|
|
|
2024-04-22 15:04:56 +00:00
|
|
|
[TestCase(false)]
|
|
|
|
[TestCase(true)]
|
|
|
|
public void TestVideo(bool scaleTransformProvided)
|
|
|
|
{
|
|
|
|
AddStep("allow storyboard lookup", () =>
|
|
|
|
{
|
|
|
|
storyboard.ProvideResources = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("create video", () => SetContents(_ =>
|
|
|
|
{
|
|
|
|
var layer = storyboard.GetLayer("Video");
|
|
|
|
|
|
|
|
var sprite = new StoryboardVideo("Videos/test-video.mp4", Time.Current);
|
|
|
|
|
|
|
|
if (scaleTransformProvided)
|
2024-04-23 11:21:55 +00:00
|
|
|
{
|
2024-05-01 20:57:21 +00:00
|
|
|
sprite.Commands.AddScale(Easing.None, Time.Current, Time.Current + 1000, 1, 2);
|
|
|
|
sprite.Commands.AddScale(Easing.None, Time.Current + 1000, Time.Current + 2000, 2, 1);
|
2024-04-23 11:21:55 +00:00
|
|
|
}
|
2024-04-22 15:04:56 +00:00
|
|
|
|
|
|
|
layer.Elements.Clear();
|
|
|
|
layer.Add(sprite);
|
|
|
|
|
|
|
|
return new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
storyboard.CreateDrawable()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2023-09-19 10:44:41 +00:00
|
|
|
[Test]
|
|
|
|
public void TestSkinLookupPreferredOverStoryboard()
|
2020-10-20 20:42:47 +00:00
|
|
|
{
|
2023-09-19 10:44:41 +00:00
|
|
|
AddStep("allow all lookups", () =>
|
|
|
|
{
|
|
|
|
storyboard.UseSkinSprites = true;
|
2024-04-22 15:04:56 +00:00
|
|
|
storyboard.ProvideResources = true;
|
2023-09-19 10:44:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
2020-10-20 20:42:47 +00:00
|
|
|
|
2023-09-19 10:44:41 +00:00
|
|
|
[Test]
|
|
|
|
public void TestAllowLookupFromSkin()
|
|
|
|
{
|
|
|
|
AddStep("allow skin lookup", () =>
|
|
|
|
{
|
|
|
|
storyboard.UseSkinSprites = true;
|
2024-04-22 15:04:56 +00:00
|
|
|
storyboard.ProvideResources = false;
|
2023-09-19 10:44:41 +00:00
|
|
|
});
|
2020-10-20 20:42:47 +00:00
|
|
|
|
2022-03-14 00:46:05 +00:00
|
|
|
AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero)));
|
2020-10-20 20:42:47 +00:00
|
|
|
|
2022-04-07 08:51:10 +00:00
|
|
|
// 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)));
|
2022-03-14 00:46:05 +00:00
|
|
|
|
2023-09-19 10:44:41 +00:00
|
|
|
assertSkinSourced();
|
2020-10-20 20:42:47 +00:00
|
|
|
}
|
|
|
|
|
2022-03-14 00:35:23 +00:00
|
|
|
[Test]
|
|
|
|
public void TestFlippedSprite()
|
|
|
|
{
|
2023-09-19 10:44:41 +00:00
|
|
|
AddStep("allow all lookups", () =>
|
|
|
|
{
|
|
|
|
storyboard.UseSkinSprites = true;
|
2024-04-22 15:04:56 +00:00
|
|
|
storyboard.ProvideResources = true;
|
2023-09-19 10:44:41 +00:00
|
|
|
});
|
2022-03-14 00:35:23 +00:00
|
|
|
|
|
|
|
AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero)));
|
|
|
|
AddStep("flip sprites", () => sprites.ForEach(s =>
|
|
|
|
{
|
|
|
|
s.FlipH = true;
|
|
|
|
s.FlipV = true;
|
|
|
|
}));
|
|
|
|
AddAssert("origin flipped", () => sprites.All(s => s.Origin == Anchor.BottomRight));
|
|
|
|
}
|
|
|
|
|
2022-09-07 06:37:22 +00:00
|
|
|
[Test]
|
|
|
|
public void TestZeroScale()
|
|
|
|
{
|
2023-09-19 10:44:41 +00:00
|
|
|
AddStep("allow all lookups", () =>
|
|
|
|
{
|
|
|
|
storyboard.UseSkinSprites = true;
|
2024-04-22 15:04:56 +00:00
|
|
|
storyboard.ProvideResources = true;
|
2023-09-19 10:44:41 +00:00
|
|
|
});
|
2022-09-07 06:37:22 +00:00
|
|
|
|
|
|
|
AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero)));
|
2022-09-08 04:43:37 +00:00
|
|
|
AddAssert("sprites present", () => sprites.All(s => s.IsPresent));
|
2022-09-07 06:37:22 +00:00
|
|
|
AddStep("scale sprite", () => sprites.ForEach(s => s.VectorScale = new Vector2(0, 1)));
|
2022-09-08 10:42:09 +00:00
|
|
|
AddAssert("sprites not present", () => sprites.All(s => !s.IsPresent));
|
2022-09-07 06:37:22 +00:00
|
|
|
}
|
|
|
|
|
2022-03-14 00:35:23 +00:00
|
|
|
[Test]
|
|
|
|
public void TestNegativeScale()
|
|
|
|
{
|
2023-09-19 10:44:41 +00:00
|
|
|
AddStep("allow all lookups", () =>
|
|
|
|
{
|
|
|
|
storyboard.UseSkinSprites = true;
|
2024-04-22 15:04:56 +00:00
|
|
|
storyboard.ProvideResources = true;
|
2023-09-19 10:44:41 +00:00
|
|
|
});
|
2022-03-14 00:35:23 +00:00
|
|
|
|
|
|
|
AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero)));
|
|
|
|
AddStep("scale sprite", () => sprites.ForEach(s => s.VectorScale = new Vector2(-1)));
|
|
|
|
AddAssert("origin flipped", () => sprites.All(s => s.Origin == Anchor.BottomRight));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestNegativeScaleWithFlippedSprite()
|
|
|
|
{
|
2023-09-19 10:44:41 +00:00
|
|
|
AddStep("allow all lookups", () =>
|
|
|
|
{
|
|
|
|
storyboard.UseSkinSprites = true;
|
2024-04-22 15:04:56 +00:00
|
|
|
storyboard.ProvideResources = true;
|
2023-09-19 10:44:41 +00:00
|
|
|
});
|
2022-03-14 00:35:23 +00:00
|
|
|
|
|
|
|
AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero)));
|
|
|
|
AddStep("scale sprite", () => sprites.ForEach(s => s.VectorScale = new Vector2(-1)));
|
|
|
|
AddAssert("origin flipped", () => sprites.All(s => s.Origin == Anchor.BottomRight));
|
|
|
|
AddStep("flip sprites", () => sprites.ForEach(s =>
|
|
|
|
{
|
|
|
|
s.FlipH = true;
|
|
|
|
s.FlipV = true;
|
|
|
|
}));
|
|
|
|
AddAssert("origin back", () => sprites.All(s => s.Origin == Anchor.TopLeft));
|
|
|
|
}
|
|
|
|
|
2024-04-22 15:04:56 +00:00
|
|
|
private Drawable createSprite(string lookupName, Anchor origin, Vector2 initialPosition)
|
2023-09-19 10:44:41 +00:00
|
|
|
{
|
|
|
|
var layer = storyboard.GetLayer("Background");
|
|
|
|
|
|
|
|
var sprite = new StoryboardSprite(lookupName, origin, initialPosition);
|
2024-03-06 16:39:28 +00:00
|
|
|
var loop = sprite.AddLoopingGroup(Time.Current, 100);
|
2024-03-08 18:33:46 +00:00
|
|
|
loop.AddAlpha(Easing.None, 0, 10000, 1, 1);
|
2023-09-19 10:44:41 +00:00
|
|
|
|
|
|
|
layer.Elements.Clear();
|
|
|
|
layer.Add(sprite);
|
|
|
|
|
2024-04-22 15:04:56 +00:00
|
|
|
return new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
storyboard.CreateDrawable()
|
|
|
|
}
|
|
|
|
};
|
2023-09-19 10:44:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2020-10-20 20:42:47 +00:00
|
|
|
{
|
2023-09-19 10:44:41 +00:00
|
|
|
return new TestDrawableStoryboard(this, mods);
|
|
|
|
}
|
|
|
|
|
2024-04-22 15:04:56 +00:00
|
|
|
public bool ProvideResources { get; set; }
|
2023-09-19 10:44:41 +00:00
|
|
|
|
2024-04-22 15:04:56 +00:00
|
|
|
public override string GetStoragePathFromStoryboardPath(string path) => ProvideResources ? path : string.Empty;
|
2023-09-19 10:44:41 +00:00
|
|
|
|
|
|
|
private partial class TestDrawableStoryboard : DrawableStoryboard
|
|
|
|
{
|
2024-04-22 15:04:56 +00:00
|
|
|
private readonly bool provideResources;
|
2023-09-19 10:44:41 +00:00
|
|
|
|
|
|
|
public TestDrawableStoryboard(TestStoryboard storyboard, IReadOnlyList<Mod>? mods)
|
|
|
|
: base(storyboard, mods)
|
|
|
|
{
|
2024-04-22 15:04:56 +00:00
|
|
|
provideResources = storyboard.ProvideResources;
|
2023-09-19 10:44:41 +00:00
|
|
|
}
|
|
|
|
|
2024-04-22 15:04:56 +00:00
|
|
|
protected override IResourceStore<byte[]> CreateResourceLookupStore() => provideResources
|
|
|
|
? new ResourcesTextureStore()
|
2023-09-19 10:44:41 +00:00
|
|
|
: new ResourceStore<byte[]>();
|
|
|
|
|
2024-04-22 15:04:56 +00:00
|
|
|
internal class ResourcesTextureStore : IResourceStore<byte[]>
|
2023-09-19 10:44:41 +00:00
|
|
|
{
|
|
|
|
private readonly DllResourceStore store;
|
|
|
|
|
2024-04-22 15:04:56 +00:00
|
|
|
public ResourcesTextureStore()
|
2023-09-19 10:44:41 +00:00
|
|
|
{
|
|
|
|
store = TestResources.GetStore();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Dispose() => store.Dispose();
|
|
|
|
|
2024-04-22 15:04:56 +00:00
|
|
|
public byte[] Get(string name) => store.Get(map(name));
|
2023-09-19 10:44:41 +00:00
|
|
|
|
2024-04-22 15:04:56 +00:00
|
|
|
public Task<byte[]> GetAsync(string name, CancellationToken cancellationToken = new CancellationToken()) => store.GetAsync(map(name), cancellationToken);
|
2023-09-19 10:44:41 +00:00
|
|
|
|
2024-04-22 15:04:56 +00:00
|
|
|
public Stream GetStream(string name) => store.GetStream(map(name));
|
|
|
|
|
|
|
|
private string map(string name)
|
|
|
|
{
|
|
|
|
switch (name)
|
|
|
|
{
|
|
|
|
case lookup_name:
|
|
|
|
return "Resources/Textures/test-image.png";
|
|
|
|
|
|
|
|
default:
|
|
|
|
return $"Resources/{name}";
|
|
|
|
}
|
|
|
|
}
|
2023-09-19 10:44:41 +00:00
|
|
|
|
|
|
|
public IEnumerable<string> GetAvailableResources() => store.GetAvailableResources();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-20 20:42:47 +00:00
|
|
|
}
|
|
|
|
}
|