1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-19 01:42:54 +08:00
osu-lazer/osu.Game.Tests/Visual/Gameplay/TestSceneBreakTracker.cs

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

199 lines
6.2 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
2022-06-17 15:37:17 +08:00
#nullable disable
using System.Collections.Generic;
2019-07-27 20:51:14 +08:00
using System.Linq;
2018-03-02 14:34:31 +08:00
using NUnit.Framework;
using osu.Framework.Graphics;
2019-07-27 20:51:14 +08:00
using osu.Framework.Timing;
2019-03-25 00:02:36 +08:00
using osu.Game.Beatmaps.Timing;
using osu.Game.Screens.Play;
2018-04-13 17:19:50 +08:00
2019-03-25 00:02:36 +08:00
namespace osu.Game.Tests.Visual.Gameplay
{
2018-03-02 14:34:31 +08:00
[TestFixture]
public class TestSceneBreakTracker : OsuTestScene
{
private readonly BreakOverlay breakOverlay;
private readonly TestBreakTracker breakTracker;
2019-07-27 20:51:14 +08:00
private readonly IReadOnlyList<BreakPeriod> testBreaks = new List<BreakPeriod>
{
new BreakPeriod(1000, 5000),
new BreakPeriod(6000, 13500),
2019-07-27 20:51:14 +08:00
};
2018-04-13 17:19:50 +08:00
public TestSceneBreakTracker()
{
AddRange(new Drawable[]
{
breakTracker = new TestBreakTracker(),
2020-03-28 11:18:28 +08:00
breakOverlay = new BreakOverlay(true, null)
{
ProcessCustomClock = false,
}
});
}
protected override void Update()
{
base.Update();
breakOverlay.Clock = breakTracker.Clock;
2019-07-27 20:51:14 +08:00
}
2019-07-25 21:24:05 +08:00
2019-07-27 20:51:14 +08:00
[Test]
public void TestShowBreaks()
{
2019-07-30 17:31:57 +08:00
setClock(false);
2018-04-13 17:19:50 +08:00
2019-07-27 20:51:14 +08:00
addShowBreakStep(2);
addShowBreakStep(5);
addShowBreakStep(15);
}
2018-04-13 17:19:50 +08:00
2019-07-27 20:51:14 +08:00
[Test]
public void TestNoEffectsBreak()
{
var shortBreak = new BreakPeriod(0, 500);
2019-07-27 20:51:14 +08:00
2019-07-30 17:31:57 +08:00
setClock(true);
loadBreaksStep("short break", new[] { shortBreak });
2019-07-27 20:51:14 +08:00
addBreakSeeks(shortBreak, false);
}
2018-04-13 17:19:50 +08:00
2019-07-27 20:51:14 +08:00
[Test]
public void TestMultipleBreaks()
{
2019-07-30 17:31:57 +08:00
setClock(true);
loadBreaksStep("multiple breaks", testBreaks);
2019-07-27 20:51:14 +08:00
foreach (var b in testBreaks)
addBreakSeeks(b, false);
}
2018-04-13 17:19:50 +08:00
2019-07-27 20:51:14 +08:00
[Test]
public void TestRewindBreaks()
{
2019-07-30 17:31:57 +08:00
setClock(true);
loadBreaksStep("multiple breaks", testBreaks);
2019-07-27 20:51:14 +08:00
foreach (var b in testBreaks.Reverse())
addBreakSeeks(b, true);
}
[Test]
public void TestSkipBreaks()
{
2019-07-30 17:31:57 +08:00
setClock(true);
loadBreaksStep("multiple breaks", testBreaks);
2019-07-27 20:51:14 +08:00
seekAndAssertBreak("seek to break start", testBreaks[1].StartTime, true);
seekAndAssertBreak("seek to break middle", testBreaks[1].StartTime + testBreaks[1].Duration / 2, true);
seekAndAssertBreak("seek to break end", testBreaks[1].EndTime, false);
seekAndAssertBreak("seek to break after end", testBreaks[1].EndTime + 500, false);
2019-07-27 20:51:14 +08:00
}
[TestCase(true)]
[TestCase(false)]
public void TestBeforeGameplayStart(bool withBreaks)
{
setClock(true);
if (withBreaks)
loadBreaksStep("multiple breaks", testBreaks);
seekAndAssertBreak("seek to break intro time", -100, true);
seekAndAssertBreak("seek to break intro time", 0, false);
}
2019-07-27 20:51:14 +08:00
private void addShowBreakStep(double seconds)
{
AddStep($"show '{seconds}s' break", () =>
{
breakOverlay.Breaks = breakTracker.Breaks = new List<BreakPeriod>
{
new BreakPeriod(Clock.CurrentTime, Clock.CurrentTime + seconds * 1000)
};
2019-07-27 20:51:14 +08:00
});
}
2018-04-13 17:19:50 +08:00
2019-07-30 17:31:57 +08:00
private void setClock(bool useManual)
{
AddStep($"set {(useManual ? "manual" : "realtime")} clock", () => breakTracker.SwitchClock(useManual));
2019-07-27 20:51:14 +08:00
}
2018-04-13 17:19:50 +08:00
private void loadBreaksStep(string breakDescription, IReadOnlyList<BreakPeriod> breaks)
{
AddStep($"load {breakDescription}", () => breakOverlay.Breaks = breakTracker.Breaks = breaks);
2019-07-30 17:31:57 +08:00
seekAndAssertBreak("seek back to 0", 0, false);
}
2019-07-27 20:51:14 +08:00
private void addBreakSeeks(BreakPeriod b, bool isReversed)
{
if (isReversed)
{
2019-07-30 17:31:57 +08:00
seekAndAssertBreak("seek to break after end", b.EndTime + 500, false);
seekAndAssertBreak("seek to break end", b.EndTime, false);
seekAndAssertBreak("seek to break middle", b.StartTime + b.Duration / 2, b.HasEffect);
seekAndAssertBreak("seek to break start", b.StartTime, b.HasEffect);
2019-07-27 20:51:14 +08:00
}
else
{
2019-07-30 17:31:57 +08:00
seekAndAssertBreak("seek to break start", b.StartTime, b.HasEffect);
seekAndAssertBreak("seek to break middle", b.StartTime + b.Duration / 2, b.HasEffect);
seekAndAssertBreak("seek to break end", b.EndTime, false);
seekAndAssertBreak("seek to break after end", b.EndTime + 500, false);
2019-07-27 20:51:14 +08:00
}
}
2019-07-30 17:31:57 +08:00
private void seekAndAssertBreak(string seekStepDescription, double time, bool shouldBeBreak)
2019-07-27 20:51:14 +08:00
{
AddStep(seekStepDescription, () => breakTracker.ManualClockTime = time);
2019-07-30 17:31:57 +08:00
AddAssert($"is{(!shouldBeBreak ? " not" : string.Empty)} break time", () =>
{
breakTracker.ProgressTime();
return breakTracker.IsBreakTime.Value == shouldBeBreak;
2019-07-30 17:31:57 +08:00
});
}
private class TestBreakTracker : BreakTracker
{
public readonly FramedClock FramedManualClock;
private readonly ManualClock manualClock;
2019-07-30 17:31:57 +08:00
private IFrameBasedClock originalClock;
public double ManualClockTime
{
get => manualClock.CurrentTime;
set => manualClock.CurrentTime = value;
}
public TestBreakTracker()
{
FramedManualClock = new FramedClock(manualClock = new ManualClock());
2019-07-30 17:31:57 +08:00
ProcessCustomClock = false;
}
public void ProgressTime()
{
FramedManualClock.ProcessFrame();
2019-07-30 17:31:57 +08:00
Update();
}
public void SwitchClock(bool setManual) => Clock = setManual ? FramedManualClock : originalClock;
protected override void LoadComplete()
{
base.LoadComplete();
2019-07-30 17:31:57 +08:00
originalClock = Clock;
}
}
}
}