1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 21:43:21 +08:00
osu-lazer/osu.Game.Tests/Visual/TestCaseStoryboard.cs

92 lines
2.9 KiB
C#
Raw Normal View History

2018-01-05 19:21:19 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
2017-09-08 05:55:05 +08:00
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2018-03-02 14:34:31 +08:00
using NUnit.Framework;
2017-09-08 05:55:05 +08:00
using osu.Framework.Allocation;
using osu.Framework.Configuration;
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.Overlays;
using osu.Game.Storyboards.Drawables;
2017-09-18 21:32:49 +08:00
using OpenTK.Graphics;
2017-09-08 05:55:05 +08:00
2017-09-18 21:32:49 +08:00
namespace osu.Game.Tests.Visual
2017-09-08 05:55:05 +08:00
{
2018-03-02 14:34:31 +08:00
[TestFixture]
2017-12-20 20:47:45 +08:00
public class TestCaseStoryboard : OsuTestCase
2017-09-08 05:55:05 +08:00
{
private readonly Bindable<WorkingBeatmap> beatmapBacking = new Bindable<WorkingBeatmap>();
2017-09-13 17:22:24 +08:00
private readonly Container<DrawableStoryboard> storyboardContainer;
private DrawableStoryboard storyboard;
2017-09-08 05:55:05 +08:00
public TestCaseStoryboard()
{
Clock = new FramedClock();
Add(new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black,
},
2017-09-13 17:22:24 +08:00
storyboardContainer = new Container<DrawableStoryboard>
2017-09-08 05:55:05 +08:00
{
RelativeSizeAxes = Axes.Both,
},
},
});
2017-09-08 19:04:53 +08:00
Add(new MusicController
2017-09-08 05:55:05 +08:00
{
Origin = Anchor.TopRight,
Anchor = Anchor.TopRight,
State = Visibility.Visible,
});
AddStep("Restart", restart);
AddToggleStep("Passing", passing => { if (storyboard != null) storyboard.Passing = passing; });
}
[BackgroundDependencyLoader]
private void load(OsuGameBase game)
{
beatmapBacking.BindTo(game.Beatmap);
beatmapBacking.ValueChanged += beatmapChanged;
}
private void beatmapChanged(WorkingBeatmap working)
=> loadStoryboard(working);
private void restart()
{
var track = beatmapBacking.Value.Track;
track.Reset();
loadStoryboard(beatmapBacking.Value);
track.Start();
}
private void loadStoryboard(WorkingBeatmap working)
{
if (storyboard != null)
storyboardContainer.Remove(storyboard);
var decoupledClock = new DecoupleableInterpolatingFramedClock { IsCoupled = true };
storyboardContainer.Clock = decoupledClock;
storyboard = working.Storyboard.CreateDrawable(beatmapBacking);
2017-09-08 05:55:05 +08:00
storyboard.Passing = false;
2017-09-15 20:15:26 +08:00
storyboardContainer.Add(storyboard);
decoupledClock.ChangeSource(working.Track);
2017-09-08 05:55:05 +08:00
}
}
}