1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-18 15:32:55 +08:00
osu-lazer/osu.Game.Tests/Beatmaps/Formats/LegacyStoryboardDecoderTest.cs

107 lines
4.8 KiB
C#
Raw Normal View History

// 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.
2018-04-13 17:19:50 +08:00
using System.IO;
using System.Linq;
using NUnit.Framework;
2018-11-20 15:51:59 +08:00
using osuTK;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics;
using osu.Game.Beatmaps.Formats;
using osu.Game.Storyboards;
using osu.Game.Tests.Resources;
namespace osu.Game.Tests.Beatmaps.Formats
{
[TestFixture]
public class LegacyStoryboardDecoderTest
{
[Test]
public void TestDecodeStoryboardEvents()
{
var decoder = new LegacyStoryboardDecoder();
2019-04-01 11:44:46 +08:00
2019-01-28 17:19:57 +08:00
using (var resStream = TestResources.OpenResource("Himeringo - Yotsuya-san ni Yoroshiku (RLC) [Winber1's Extreme].osu"))
2018-04-13 17:19:50 +08:00
using (var stream = new StreamReader(resStream))
{
var storyboard = decoder.Decode(stream);
Assert.IsTrue(storyboard.HasDrawable);
Assert.AreEqual(4, storyboard.Layers.Count());
StoryboardLayer background = storyboard.Layers.FirstOrDefault(l => l.Depth == 3);
Assert.IsNotNull(background);
2019-03-26 15:14:20 +08:00
Assert.AreEqual(16, background.Elements.Count);
2018-04-13 17:19:50 +08:00
Assert.IsTrue(background.EnabledWhenFailing);
Assert.IsTrue(background.EnabledWhenPassing);
Assert.AreEqual("Background", background.Name);
StoryboardLayer fail = storyboard.Layers.FirstOrDefault(l => l.Depth == 2);
Assert.IsNotNull(fail);
2019-03-26 15:14:20 +08:00
Assert.AreEqual(0, fail.Elements.Count);
2018-04-13 17:19:50 +08:00
Assert.IsTrue(fail.EnabledWhenFailing);
Assert.IsFalse(fail.EnabledWhenPassing);
Assert.AreEqual("Fail", fail.Name);
StoryboardLayer pass = storyboard.Layers.FirstOrDefault(l => l.Depth == 1);
Assert.IsNotNull(pass);
2019-03-26 15:14:20 +08:00
Assert.AreEqual(0, pass.Elements.Count);
2018-04-13 17:19:50 +08:00
Assert.IsFalse(pass.EnabledWhenFailing);
Assert.IsTrue(pass.EnabledWhenPassing);
Assert.AreEqual("Pass", pass.Name);
StoryboardLayer foreground = storyboard.Layers.FirstOrDefault(l => l.Depth == 0);
Assert.IsNotNull(foreground);
2019-03-26 15:14:20 +08:00
Assert.AreEqual(151, foreground.Elements.Count);
2018-04-13 17:19:50 +08:00
Assert.IsTrue(foreground.EnabledWhenFailing);
Assert.IsTrue(foreground.EnabledWhenPassing);
Assert.AreEqual("Foreground", foreground.Name);
int spriteCount = background.Elements.Count(x => x.GetType() == typeof(StoryboardSprite));
int animationCount = background.Elements.Count(x => x.GetType() == typeof(StoryboardAnimation));
2019-08-23 20:18:56 +08:00
int sampleCount = background.Elements.Count(x => x.GetType() == typeof(StoryboardSampleInfo));
2018-04-13 17:19:50 +08:00
Assert.AreEqual(15, spriteCount);
Assert.AreEqual(1, animationCount);
Assert.AreEqual(0, sampleCount);
2019-03-26 15:14:20 +08:00
Assert.AreEqual(background.Elements.Count, spriteCount + animationCount + sampleCount);
2018-04-13 17:19:50 +08:00
var sprite = background.Elements.ElementAt(0) as StoryboardSprite;
Assert.NotNull(sprite);
Assert.IsTrue(sprite.HasCommands);
Assert.AreEqual(new Vector2(320, 240), sprite.InitialPosition);
Assert.IsTrue(sprite.IsDrawable);
Assert.AreEqual(Anchor.Centre, sprite.Origin);
2019-03-26 15:14:20 +08:00
Assert.AreEqual("SB/black.jpg", sprite.Path);
2018-04-13 17:19:50 +08:00
2019-03-26 15:14:20 +08:00
var animation = background.Elements.OfType<StoryboardAnimation>().First();
2018-04-13 17:19:50 +08:00
Assert.NotNull(animation);
Assert.AreEqual(141175, animation.EndTime);
Assert.AreEqual(10, animation.FrameCount);
Assert.AreEqual(30, animation.FrameDelay);
Assert.IsTrue(animation.HasCommands);
Assert.AreEqual(new Vector2(320, 240), animation.InitialPosition);
Assert.IsTrue(animation.IsDrawable);
Assert.AreEqual(AnimationLoopType.LoopForever, animation.LoopType);
Assert.AreEqual(Anchor.Centre, animation.Origin);
Assert.AreEqual("SB/red jitter/red_0000.jpg", animation.Path);
Assert.AreEqual(78993, animation.StartTime);
}
}
2018-08-14 17:15:09 +08:00
[Test]
public void TestDecodeVariableWithSuffix()
{
var decoder = new LegacyStoryboardDecoder();
2019-04-01 11:44:46 +08:00
2019-01-28 17:19:57 +08:00
using (var resStream = TestResources.OpenResource("variable-with-suffix.osb"))
2018-08-14 17:15:09 +08:00
using (var stream = new StreamReader(resStream))
{
var storyboard = decoder.Decode(stream);
StoryboardLayer background = storyboard.Layers.Single(l => l.Depth == 3);
Assert.AreEqual(123456, ((StoryboardSprite)background.Elements.Single()).InitialPosition.X);
}
}
2018-04-13 17:19:50 +08:00
}
}