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

199 lines
6.3 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
2019-07-25 21:24:05 +08:00
using System;
2018-04-13 17:19:50 +08:00
using System.Collections.Generic;
2019-07-27 20:51:14 +08:00
using System.Linq;
2018-04-13 17:19:50 +08:00
using NUnit.Framework;
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;
2018-04-13 17:19:50 +08:00
using osu.Game.Screens.Play;
2019-03-25 00:02:36 +08:00
namespace osu.Game.Tests.Visual.Gameplay
2018-04-13 17:19:50 +08:00
{
[TestFixture]
public class TestSceneBreakOverlay : OsuTestScene
2018-04-13 17:19:50 +08:00
{
2019-07-25 21:24:05 +08:00
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(BreakOverlay),
};
private readonly TestBreakOverlay breakOverlay;
2019-07-27 20:51:14 +08:00
private readonly IReadOnlyList<BreakPeriod> testBreaks = new List<BreakPeriod>
{
new BreakPeriod
{
StartTime = 1000,
EndTime = 5000,
},
new BreakPeriod
{
StartTime = 6000,
EndTime = 13500,
},
};
2018-04-13 17:19:50 +08:00
public TestSceneBreakOverlay()
2018-04-13 17:19:50 +08:00
{
Add(breakOverlay = new TestBreakOverlay(true));
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()
2018-04-13 17:19:50 +08:00
{
2019-07-27 20:51:14 +08:00
var shortBreak = new BreakPeriod { EndTime = 500 };
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()
2018-04-13 17:19:50 +08:00
{
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);
AddAssert("is skipped to break #2", () => breakOverlay.CurrentBreakIndex == 1);
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 = new List<BreakPeriod>
2018-04-13 17:19:50 +08:00
{
new BreakPeriod
{
2019-07-27 20:51:14 +08:00
StartTime = Clock.CurrentTime,
EndTime = Clock.CurrentTime + seconds * 1000,
2018-04-13 17:19:50 +08:00
}
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)
2018-04-13 17:19:50 +08:00
{
2019-07-30 17:31:57 +08:00
AddStep($"set {(useManual ? "manual" : "realtime")} clock", () => breakOverlay.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 = 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)
2018-04-13 17:19:50 +08:00
{
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, () => breakOverlay.ManualClockTime = time);
2019-07-30 17:31:57 +08:00
AddAssert($"is{(!shouldBeBreak ? " not" : string.Empty)} break time", () =>
{
breakOverlay.ProgressTime();
return breakOverlay.IsBreakTime.Value == shouldBeBreak;
});
2018-04-13 17:19:50 +08:00
}
private class TestBreakOverlay : BreakOverlay
{
private readonly FramedClock framedManualClock;
private readonly ManualClock manualClock;
2019-07-30 17:31:57 +08:00
private IFrameBasedClock originalClock;
2019-07-30 18:29:41 +08:00
public new int CurrentBreakIndex => base.CurrentBreakIndex;
public double ManualClockTime
{
get => manualClock.CurrentTime;
set => manualClock.CurrentTime = value;
}
public TestBreakOverlay(bool letterboxing)
: base(letterboxing)
{
framedManualClock = new FramedClock(manualClock = new ManualClock());
2019-07-30 17:31:57 +08:00
ProcessCustomClock = false;
}
public void ProgressTime()
{
framedManualClock.ProcessFrame();
Update();
}
2019-07-30 17:31:57 +08:00
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;
}
}
2018-04-13 17:19:50 +08:00
}
}