1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 18:27:31 +08:00
osu-lazer/osu.Game.Tests/NonVisual/Skinning/LegacySkinAnimationTest.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

95 lines
3.4 KiB
C#
Raw Normal View History

2020-11-22 02:51:27 +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.
2022-06-17 15:37:17 +08:00
#nullable disable
2020-11-22 02:51:27 +08:00
using System;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Animations;
2022-08-02 18:50:57 +08:00
using osu.Framework.Graphics.Rendering;
2020-11-22 02:51:27 +08:00
using osu.Framework.Graphics.Textures;
using osu.Framework.Testing;
using osu.Framework.Timing;
using osu.Game.Audio;
using osu.Game.Skinning;
using osu.Game.Tests.Visual;
namespace osu.Game.Tests.NonVisual.Skinning
{
[HeadlessTest]
public partial class LegacySkinAnimationTest : OsuTestScene
{
private const string animation_name = "animation";
private const int frame_count = 6;
2022-08-02 18:50:57 +08:00
[Resolved]
private IRenderer renderer { get; set; }
2020-11-22 02:51:27 +08:00
[Cached(typeof(IAnimationTimeReference))]
private TestAnimationTimeReference animationTimeReference = new TestAnimationTimeReference();
private TextureAnimation animation;
[Test]
public void TestAnimationTimeReferenceChange()
{
2022-08-02 18:50:57 +08:00
AddStep("get animation", () =>
{
ISkin skin = new TestSkin(renderer);
Add(animation = (TextureAnimation)skin.GetAnimation(animation_name, true, false));
});
2020-11-22 02:51:27 +08:00
AddAssert("frame count correct", () => animation.FrameCount == frame_count);
assertPlaybackPosition(0);
AddStep("set start time to 1000", () => animationTimeReference.AnimationStartTime.Value = 1000);
assertPlaybackPosition(0);
2020-11-22 02:51:27 +08:00
AddStep("set current time to 500", () => animationTimeReference.ManualClock.CurrentTime = 500);
assertPlaybackPosition(0);
2020-11-22 02:51:27 +08:00
}
private void assertPlaybackPosition(double expectedPosition)
=> AddAssert($"playback position is {expectedPosition}", () => animation.PlaybackPosition == expectedPosition);
private class TestSkin : ISkin
{
private static readonly string[] lookup_names = Enumerable.Range(0, frame_count).Select(frame => $"{animation_name}-{frame}").ToArray();
2022-08-02 18:50:57 +08:00
private readonly IRenderer renderer;
public TestSkin(IRenderer renderer)
{
this.renderer = renderer;
}
2020-11-22 02:51:27 +08:00
public Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT)
{
2022-08-02 18:50:57 +08:00
return lookup_names.Contains(componentName) ? renderer.WhitePixel : null;
2020-11-22 02:51:27 +08:00
}
public Drawable GetDrawableComponent(ISkinComponentLookup lookup) => throw new NotSupportedException();
public ISample GetSample(ISampleInfo sampleInfo) => throw new NotSupportedException();
2020-11-22 02:51:27 +08:00
public IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup) => throw new NotSupportedException();
}
private class TestAnimationTimeReference : IAnimationTimeReference
{
public ManualClock ManualClock { get; }
public IFrameBasedClock Clock { get; }
public Bindable<double> AnimationStartTime { get; } = new BindableDouble();
2020-11-22 02:51:27 +08:00
public TestAnimationTimeReference()
{
ManualClock = new ManualClock();
Clock = new FramedClock(ManualClock);
}
}
}
}