1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 18:42:56 +08:00
osu-lazer/osu.Game.Tests/Visual/Editing/TestSceneEditorClock.cs

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

112 lines
4.3 KiB
C#
Raw Normal View History

2020-03-22 03:15:20 +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.
using NUnit.Framework;
2022-05-26 17:30:37 +08:00
using osu.Framework.Allocation;
2020-03-22 03:15:20 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Osu;
2022-05-26 17:30:37 +08:00
using osu.Game.Screens.Edit;
2020-03-22 03:15:20 +08:00
using osu.Game.Screens.Edit.Components;
2022-05-26 17:30:37 +08:00
using osu.Game.Tests.Beatmaps;
2020-03-22 03:15:20 +08:00
using osuTK;
2021-03-18 01:37:11 +08:00
namespace osu.Game.Tests.Visual.Editing
2020-03-22 03:15:20 +08:00
{
[TestFixture]
public partial class TestSceneEditorClock : EditorClockTestScene
{
2022-05-26 17:30:37 +08:00
[Cached]
private EditorBeatmap editorBeatmap = new EditorBeatmap(new TestBeatmap(new OsuRuleset().RulesetInfo));
2020-03-22 03:15:20 +08:00
public TestSceneEditorClock()
{
Add(new FillFlowContainer
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
new TimeInfoContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(200, 100)
},
new PlaybackControl
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(200, 100)
}
}
});
}
protected override void LoadComplete()
{
base.LoadComplete();
Beatmap.Value = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
// ensure that music controller does not change this beatmap due to it
// completing naturally as part of the test.
Beatmap.Disabled = true;
}
2020-03-22 03:15:20 +08:00
[Test]
public void TestStopAtTrackEnd()
{
AddStep("reset clock", () => EditorClock.Seek(0));
AddStep("start clock", () => EditorClock.Start());
AddAssert("clock running", () => EditorClock.IsRunning);
AddStep("seek near end", () => EditorClock.Seek(EditorClock.TrackLength - 250));
AddUntilStep("clock stops", () => !EditorClock.IsRunning);
AddUntilStep("clock stopped at end", () => EditorClock.CurrentTime - EditorClock.TotalAppliedOffset, () => Is.EqualTo(EditorClock.TrackLength));
AddStep("start clock again", () => EditorClock.Start());
AddAssert("clock looped to start", () => EditorClock.IsRunning && EditorClock.CurrentTime < 500);
}
[Test]
public void TestWrapWhenStoppedAtTrackEnd()
{
AddStep("reset clock", () => EditorClock.Seek(0));
AddStep("stop clock", () => EditorClock.Stop());
AddAssert("clock stopped", () => !EditorClock.IsRunning);
AddStep("seek exactly to end", () => EditorClock.Seek(EditorClock.TrackLength));
AddAssert("clock stopped at end", () => EditorClock.CurrentTime, () => Is.EqualTo(EditorClock.TrackLength));
AddStep("start clock again", () => EditorClock.Start());
AddAssert("clock looped to start", () => EditorClock.IsRunning && EditorClock.CurrentTime < 500);
2020-03-22 03:15:20 +08:00
}
2021-08-17 22:56:06 +08:00
[Test]
public void TestClampWhenSeekOutsideBeatmapBounds()
{
AddStep("stop clock", () => EditorClock.Stop());
2021-08-17 22:56:06 +08:00
AddStep("seek before start time", () => EditorClock.Seek(-1000));
AddAssert("time is clamped to 0", () => EditorClock.CurrentTime, () => Is.EqualTo(0));
2021-08-17 22:56:06 +08:00
AddStep("seek beyond track length", () => EditorClock.Seek(EditorClock.TrackLength + 1000));
AddAssert("time is clamped to track length", () => EditorClock.CurrentTime, () => Is.EqualTo(EditorClock.TrackLength));
2021-08-17 22:56:06 +08:00
AddStep("seek smoothly before start time", () => EditorClock.SeekSmoothlyTo(-1000));
AddUntilStep("time is clamped to 0", () => EditorClock.CurrentTime, () => Is.EqualTo(0));
2021-08-17 22:56:06 +08:00
AddStep("seek smoothly beyond track length", () => EditorClock.SeekSmoothlyTo(EditorClock.TrackLength + 1000));
AddUntilStep("time is clamped to track length", () => EditorClock.CurrentTime, () => Is.EqualTo(EditorClock.TrackLength));
2021-08-17 22:56:06 +08:00
}
protected override void Dispose(bool isDisposing)
{
Beatmap.Disabled = false;
base.Dispose(isDisposing);
}
2020-03-22 03:15:20 +08:00
}
}