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