2019-01-24 08:43:03 +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.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using NUnit.Framework;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Game.Beatmaps.Formats;
|
2019-09-09 22:43:30 +00:00
|
|
|
|
using osu.Game.IO;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
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 03:44:46 +00:00
|
|
|
|
|
2019-01-28 09:19:57 +00:00
|
|
|
|
using (var resStream = TestResources.OpenResource("Himeringo - Yotsuya-san ni Yoroshiku (RLC) [Winber1's Extreme].osu"))
|
2019-09-09 22:43:30 +00:00
|
|
|
|
using (var stream = new LineBufferedReader(resStream))
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
var storyboard = decoder.Decode(stream);
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(storyboard.HasDrawable);
|
2020-05-18 20:10:02 +00:00
|
|
|
|
Assert.AreEqual(6, storyboard.Layers.Count());
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
StoryboardLayer background = storyboard.Layers.FirstOrDefault(l => l.Depth == 3);
|
|
|
|
|
Assert.IsNotNull(background);
|
2019-03-26 07:14:20 +00:00
|
|
|
|
Assert.AreEqual(16, background.Elements.Count);
|
2020-03-25 02:08:08 +00:00
|
|
|
|
Assert.IsTrue(background.VisibleWhenFailing);
|
|
|
|
|
Assert.IsTrue(background.VisibleWhenPassing);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
Assert.AreEqual("Background", background.Name);
|
|
|
|
|
|
|
|
|
|
StoryboardLayer fail = storyboard.Layers.FirstOrDefault(l => l.Depth == 2);
|
|
|
|
|
Assert.IsNotNull(fail);
|
2019-03-26 07:14:20 +00:00
|
|
|
|
Assert.AreEqual(0, fail.Elements.Count);
|
2020-03-25 02:08:08 +00:00
|
|
|
|
Assert.IsTrue(fail.VisibleWhenFailing);
|
|
|
|
|
Assert.IsFalse(fail.VisibleWhenPassing);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
Assert.AreEqual("Fail", fail.Name);
|
|
|
|
|
|
|
|
|
|
StoryboardLayer pass = storyboard.Layers.FirstOrDefault(l => l.Depth == 1);
|
|
|
|
|
Assert.IsNotNull(pass);
|
2019-03-26 07:14:20 +00:00
|
|
|
|
Assert.AreEqual(0, pass.Elements.Count);
|
2020-03-25 02:08:08 +00:00
|
|
|
|
Assert.IsFalse(pass.VisibleWhenFailing);
|
|
|
|
|
Assert.IsTrue(pass.VisibleWhenPassing);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
Assert.AreEqual("Pass", pass.Name);
|
|
|
|
|
|
|
|
|
|
StoryboardLayer foreground = storyboard.Layers.FirstOrDefault(l => l.Depth == 0);
|
|
|
|
|
Assert.IsNotNull(foreground);
|
2019-03-26 07:14:20 +00:00
|
|
|
|
Assert.AreEqual(151, foreground.Elements.Count);
|
2020-03-25 02:08:08 +00:00
|
|
|
|
Assert.IsTrue(foreground.VisibleWhenFailing);
|
|
|
|
|
Assert.IsTrue(foreground.VisibleWhenPassing);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
Assert.AreEqual("Foreground", foreground.Name);
|
|
|
|
|
|
2020-05-18 20:10:02 +00:00
|
|
|
|
StoryboardLayer overlay = storyboard.Layers.FirstOrDefault(l => l.Depth == int.MinValue);
|
|
|
|
|
Assert.IsNotNull(overlay);
|
|
|
|
|
Assert.IsEmpty(overlay.Elements);
|
|
|
|
|
Assert.IsTrue(overlay.VisibleWhenFailing);
|
|
|
|
|
Assert.IsTrue(overlay.VisibleWhenPassing);
|
|
|
|
|
Assert.AreEqual("Overlay", overlay.Name);
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
int spriteCount = background.Elements.Count(x => x.GetType() == typeof(StoryboardSprite));
|
|
|
|
|
int animationCount = background.Elements.Count(x => x.GetType() == typeof(StoryboardAnimation));
|
2019-08-23 12:18:56 +00:00
|
|
|
|
int sampleCount = background.Elements.Count(x => x.GetType() == typeof(StoryboardSampleInfo));
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
Assert.AreEqual(15, spriteCount);
|
|
|
|
|
Assert.AreEqual(1, animationCount);
|
|
|
|
|
Assert.AreEqual(0, sampleCount);
|
2019-03-26 07:14:20 +00:00
|
|
|
|
Assert.AreEqual(background.Elements.Count, spriteCount + animationCount + sampleCount);
|
2018-04-13 09:19:50 +00: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-12-20 07:42:45 +00:00
|
|
|
|
Assert.AreEqual("SB/lyric/ja-21.png", sprite.Path);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-03-26 07:14:20 +00:00
|
|
|
|
var animation = background.Elements.OfType<StoryboardAnimation>().First();
|
2018-04-13 09:19:50 +00: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 09:15:09 +00:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestDecodeVariableWithSuffix()
|
|
|
|
|
{
|
|
|
|
|
var decoder = new LegacyStoryboardDecoder();
|
2019-04-01 03:44:46 +00:00
|
|
|
|
|
2019-01-28 09:19:57 +00:00
|
|
|
|
using (var resStream = TestResources.OpenResource("variable-with-suffix.osb"))
|
2019-09-09 22:43:30 +00:00
|
|
|
|
using (var stream = new LineBufferedReader(resStream))
|
2018-08-14 09:15:09 +00:00
|
|
|
|
{
|
|
|
|
|
var storyboard = decoder.Decode(stream);
|
|
|
|
|
|
|
|
|
|
StoryboardLayer background = storyboard.Layers.Single(l => l.Depth == 3);
|
2020-03-10 03:21:40 +00:00
|
|
|
|
Assert.AreEqual(3456, ((StoryboardSprite)background.Elements.Single()).InitialPosition.X);
|
2018-08-14 09:15:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|