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;
|
2019-07-25 13:24:05 +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]
|
2019-05-14 19:37:25 +00:00
|
|
|
|
public class TestSceneBreakOverlay : 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),
|
|
|
|
|
};
|
|
|
|
|
|
2019-07-27 12:51:14 +00:00
|
|
|
|
private readonly BreakOverlay breakOverlay, manualBreakOverlay;
|
|
|
|
|
private readonly ManualClock manualClock = new ManualClock();
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2019-05-14 19:37:25 +00:00
|
|
|
|
public TestSceneBreakOverlay()
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-07-27 12:51:14 +00:00
|
|
|
|
Add(breakOverlay = new BreakOverlay(true));
|
|
|
|
|
Add(manualBreakOverlay = new BreakOverlay(true)
|
2019-07-25 13:24:05 +00:00
|
|
|
|
{
|
2019-07-27 12:51:14 +00:00
|
|
|
|
Alpha = 0,
|
|
|
|
|
Clock = new FramedClock(manualClock),
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-07-25 13:24:05 +00:00
|
|
|
|
|
2019-07-27 12:51:14 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestShowBreaks()
|
|
|
|
|
{
|
|
|
|
|
loadClockStep(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 };
|
|
|
|
|
|
|
|
|
|
loadClockStep(true);
|
|
|
|
|
AddStep("start short break", () => manualBreakOverlay.Breaks = new[] { shortBreak });
|
|
|
|
|
|
|
|
|
|
seekBreakStep("seek back to 0", 0, false);
|
|
|
|
|
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-27 12:51:14 +00:00
|
|
|
|
loadClockStep(true);
|
|
|
|
|
AddStep("start multiple breaks", () => manualBreakOverlay.Breaks = testBreaks);
|
|
|
|
|
|
|
|
|
|
seekBreakStep("seek back to 0", 0, false);
|
|
|
|
|
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()
|
|
|
|
|
{
|
|
|
|
|
loadClockStep(true);
|
|
|
|
|
AddStep("start multiple breaks in rewind", () => manualBreakOverlay.Breaks = testBreaks);
|
|
|
|
|
|
|
|
|
|
seekBreakStep("seek back to 0", 0, false);
|
|
|
|
|
foreach (var b in testBreaks.Reverse())
|
|
|
|
|
addBreakSeeks(b, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestSkipBreaks()
|
|
|
|
|
{
|
|
|
|
|
loadClockStep(true);
|
|
|
|
|
AddStep("start multiple breaks with skipping", () => manualBreakOverlay.Breaks = testBreaks);
|
|
|
|
|
|
|
|
|
|
var b = testBreaks.Last();
|
|
|
|
|
seekBreakStep("seek back to 0", 0, false);
|
|
|
|
|
addBreakSeeks(b, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addShowBreakStep(double seconds)
|
|
|
|
|
{
|
|
|
|
|
AddStep($"show '{seconds}s' break", () => breakOverlay.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-27 12:51:14 +00:00
|
|
|
|
private void loadClockStep(bool loadManual)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-07-27 12:51:14 +00:00
|
|
|
|
AddStep($"load {(loadManual ? "manual" : "normal")} clock", () =>
|
|
|
|
|
{
|
|
|
|
|
breakOverlay.FadeTo(loadManual ? 0 : 1);
|
|
|
|
|
manualBreakOverlay.FadeTo(loadManual ? 1 : 0);
|
|
|
|
|
});
|
|
|
|
|
}
|
2018-04-13 09:19:50 +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-27 12:51:14 +00:00
|
|
|
|
seekBreakStep("seek to break after end", b.EndTime + 500, false);
|
|
|
|
|
seekBreakStep("seek to break end", b.EndTime, false);
|
|
|
|
|
seekBreakStep("seek to break middle", b.StartTime + b.Duration / 2, b.HasEffect);
|
|
|
|
|
seekBreakStep("seek to break start", b.StartTime, b.HasEffect);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
seekBreakStep("seek to break start", b.StartTime, b.HasEffect);
|
|
|
|
|
seekBreakStep("seek to break middle", b.StartTime + b.Duration / 2, b.HasEffect);
|
|
|
|
|
seekBreakStep("seek to break end", b.EndTime, false);
|
|
|
|
|
seekBreakStep("seek to break after end", b.EndTime + 500, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void seekBreakStep(string seekStepDescription, double time, bool onBreak)
|
|
|
|
|
{
|
|
|
|
|
AddStep(seekStepDescription, () => manualClock.CurrentTime = time);
|
|
|
|
|
AddAssert($"is{(!onBreak ? " not " : " ")}break time", () => manualBreakOverlay.IsBreakTime.Value == onBreak);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|