1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 06:07:28 +08:00
osu-lazer/osu.Game.Tests/Visual/Gameplay/TestSceneStoryboard.cs

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

120 lines
3.6 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
2018-03-02 14:34:31 +08:00
using NUnit.Framework;
2017-09-08 05:55:05 +08:00
using osu.Framework.Allocation;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables;
2017-09-08 05:55:05 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Formats;
using osu.Game.IO;
2017-09-08 05:55:05 +08:00
using osu.Game.Overlays;
using osu.Game.Storyboards;
2017-09-08 05:55:05 +08:00
using osu.Game.Storyboards.Drawables;
using osu.Game.Tests.Resources;
2018-11-20 15:51:59 +08:00
using osuTK.Graphics;
2018-04-13 17:19:50 +08:00
2019-03-25 00:02:36 +08:00
namespace osu.Game.Tests.Visual.Gameplay
2017-09-08 05:55:05 +08:00
{
2018-03-02 14:34:31 +08:00
[TestFixture]
public partial class TestSceneStoryboard : OsuTestScene
2017-09-08 05:55:05 +08:00
{
2022-09-07 14:30:48 +08:00
private Container<DrawableStoryboard> storyboardContainer = null!;
private DrawableStoryboard? storyboard;
2018-04-13 17:19:50 +08:00
[Test]
public void TestStoryboard()
{
AddStep("Restart", restart);
AddToggleStep("Passing", passing =>
{
if (storyboard != null) storyboard.Passing = passing;
});
}
[Test]
public void TestStoryboardMissingVideo()
{
2022-09-07 14:30:48 +08:00
AddStep("Load storyboard with missing video", () => loadStoryboard("storyboard_no_video.osu"));
}
[BackgroundDependencyLoader]
private void load()
2017-09-08 05:55:05 +08:00
{
Clock = new FramedClock();
2018-04-13 17:19:50 +08:00
AddRange(new Drawable[]
2017-09-08 05:55:05 +08:00
{
new Container
2017-09-08 05:55:05 +08:00
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
2017-09-08 05:55:05 +08:00
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black,
},
storyboardContainer = new Container<DrawableStoryboard>
{
RelativeSizeAxes = Axes.Both,
},
2017-09-08 05:55:05 +08:00
},
},
new NowPlayingOverlay
{
Origin = Anchor.TopRight,
Anchor = Anchor.TopRight,
State = { Value = Visibility.Visible },
}
2017-09-08 05:55:05 +08:00
});
2018-04-13 17:19:50 +08:00
Beatmap.BindValueChanged(beatmapChanged, true);
2017-09-08 05:55:05 +08:00
}
2018-04-13 17:19:50 +08:00
2022-09-07 14:30:48 +08:00
private void beatmapChanged(ValueChangedEvent<WorkingBeatmap> e) => loadStoryboard(e.NewValue.Storyboard);
2018-04-13 17:19:50 +08:00
2017-09-08 05:55:05 +08:00
private void restart()
{
var track = Beatmap.Value.Track;
track.Reset();
2022-09-07 14:30:48 +08:00
loadStoryboard(Beatmap.Value.Storyboard);
track.Start();
2017-09-08 05:55:05 +08:00
}
2018-04-13 17:19:50 +08:00
2022-09-07 14:30:48 +08:00
private void loadStoryboard(Storyboard toLoad)
2017-09-08 05:55:05 +08:00
{
if (storyboard != null)
storyboardContainer.Remove(storyboard, true);
2018-04-13 17:19:50 +08:00
2017-09-08 05:55:05 +08:00
var decoupledClock = new DecoupleableInterpolatingFramedClock { IsCoupled = true };
storyboardContainer.Clock = decoupledClock;
2018-04-13 17:19:50 +08:00
2022-09-07 14:30:48 +08:00
storyboard = toLoad.CreateDrawable(SelectedMods.Value);
2017-09-08 05:55:05 +08:00
storyboard.Passing = false;
2018-04-13 17:19:50 +08:00
2017-09-15 20:15:26 +08:00
storyboardContainer.Add(storyboard);
2022-09-07 14:30:48 +08:00
decoupledClock.ChangeSource(Beatmap.Value.Track);
2017-09-08 05:55:05 +08:00
}
2022-09-07 14:30:48 +08:00
private void loadStoryboard(string filename)
{
2022-09-07 14:30:48 +08:00
Storyboard loaded;
2022-09-07 14:30:48 +08:00
using (var str = TestResources.OpenResource(filename))
using (var bfr = new LineBufferedReader(str))
{
var decoder = new LegacyStoryboardDecoder();
2022-09-07 14:30:48 +08:00
loaded = decoder.Decode(bfr);
}
2022-09-07 14:30:48 +08:00
loadStoryboard(loaded);
}
2017-09-08 05:55:05 +08:00
}
}