1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-01 01:12:54 +08:00

Assign clocks instead of creating 2 separate overlays

This commit is contained in:
iiSaLMaN 2019-07-28 09:27:02 +03:00
parent 37c3265942
commit c9e45f8cdc

View File

@ -20,9 +20,7 @@ namespace osu.Game.Tests.Visual.Gameplay
typeof(BreakOverlay), typeof(BreakOverlay),
}; };
private readonly ManualClock manualClock; private readonly TestBreakOverlay breakOverlay;
private readonly BreakOverlay breakOverlay;
private readonly TestBreakOverlay manualBreakOverlay;
private readonly IReadOnlyList<BreakPeriod> testBreaks = new List<BreakPeriod> private readonly IReadOnlyList<BreakPeriod> testBreaks = new List<BreakPeriod>
{ {
@ -40,12 +38,7 @@ namespace osu.Game.Tests.Visual.Gameplay
public TestSceneBreakOverlay() public TestSceneBreakOverlay()
{ {
Add(breakOverlay = new BreakOverlay(true)); Add(breakOverlay = new TestBreakOverlay(true));
Add(manualBreakOverlay = new TestBreakOverlay(true)
{
Alpha = 0,
Clock = new FramedClock(manualClock = new ManualClock()),
});
} }
[Test] [Test]
@ -112,16 +105,12 @@ namespace osu.Game.Tests.Visual.Gameplay
private void loadClockStep(bool loadManual) private void loadClockStep(bool loadManual)
{ {
AddStep($"load {(loadManual ? "manual" : "normal")} clock", () => AddStep($"load {(loadManual ? "manual" : "normal")} clock", () => breakOverlay.SwitchClock(loadManual));
{
breakOverlay.FadeTo(loadManual ? 0 : 1);
manualBreakOverlay.FadeTo(loadManual ? 1 : 0);
});
} }
private void loadBreaksStep(string breakDescription, IReadOnlyList<BreakPeriod> breaks) private void loadBreaksStep(string breakDescription, IReadOnlyList<BreakPeriod> breaks)
{ {
AddStep($"load {breakDescription}", () => manualBreakOverlay.Breaks = breaks); AddStep($"load {breakDescription}", () => breakOverlay.Breaks = breaks);
seekBreakStep("seek back to 0", 0, false); seekBreakStep("seek back to 0", 0, false);
} }
@ -145,12 +134,22 @@ namespace osu.Game.Tests.Visual.Gameplay
private void seekBreakStep(string seekStepDescription, double time, bool onBreak) private void seekBreakStep(string seekStepDescription, double time, bool onBreak)
{ {
AddStep(seekStepDescription, () => manualClock.CurrentTime = time); AddStep(seekStepDescription, () => breakOverlay.ManualClockTime = time);
AddAssert($"is{(!onBreak ? " not " : " ")}break time", () => manualBreakOverlay.IsBreakTime.Value == onBreak); AddAssert($"is{(!onBreak ? " not " : " ")}break time", () => breakOverlay.IsBreakTime.Value == onBreak);
} }
private class TestBreakOverlay : BreakOverlay private class TestBreakOverlay : BreakOverlay
{ {
private readonly FramedClock framedManualClock;
private readonly ManualClock manualClock;
private IFrameBasedClock normalClock;
public double ManualClockTime
{
get => manualClock.CurrentTime;
set => manualClock.CurrentTime = value;
}
public new IBindable<bool> IsBreakTime public new IBindable<bool> IsBreakTime
{ {
get get
@ -165,6 +164,15 @@ namespace osu.Game.Tests.Visual.Gameplay
public TestBreakOverlay(bool letterboxing) public TestBreakOverlay(bool letterboxing)
: base(letterboxing) : base(letterboxing)
{ {
framedManualClock = new FramedClock(manualClock = new ManualClock());
}
public void SwitchClock(bool setManual) => Clock = setManual ? framedManualClock : normalClock;
protected override void LoadComplete()
{
base.LoadComplete();
normalClock = Clock;
} }
} }
} }