mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 20:03:22 +08:00
Add test coverage and simplify break time updating
This commit is contained in:
parent
a453129d44
commit
77ce9642ba
@ -95,6 +95,19 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
seekAndAssertBreak("seek to break after end", testBreaks[1].EndTime + 500, false);
|
||||
}
|
||||
|
||||
[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);
|
||||
}
|
||||
|
||||
private void addShowBreakStep(double seconds)
|
||||
{
|
||||
AddStep($"show '{seconds}s' break", () => breakOverlay.Breaks = new List<BreakPeriod>
|
||||
|
@ -140,27 +140,34 @@ namespace osu.Game.Screens.Play
|
||||
updateBreakTimeBindable();
|
||||
}
|
||||
|
||||
private void updateBreakTimeBindable()
|
||||
private void updateBreakTimeBindable() =>
|
||||
isBreakTime.Value = getCurrentBreak()?.HasEffect == true
|
||||
|| Clock.CurrentTime < gameplayStartTime
|
||||
|| scoreProcessor?.HasCompleted == true;
|
||||
|
||||
private BreakPeriod getCurrentBreak()
|
||||
{
|
||||
if (breaks == null || breaks.Count == 0)
|
||||
return;
|
||||
|
||||
var time = Clock.CurrentTime;
|
||||
|
||||
if (time > breaks[CurrentBreakIndex].EndTime)
|
||||
if (breaks?.Count > 0)
|
||||
{
|
||||
while (time > breaks[CurrentBreakIndex].EndTime && CurrentBreakIndex < breaks.Count - 1)
|
||||
CurrentBreakIndex++;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (time < breaks[CurrentBreakIndex].StartTime && CurrentBreakIndex > 0)
|
||||
CurrentBreakIndex--;
|
||||
var time = Clock.CurrentTime;
|
||||
|
||||
if (time > breaks[CurrentBreakIndex].EndTime)
|
||||
{
|
||||
while (time > breaks[CurrentBreakIndex].EndTime && CurrentBreakIndex < breaks.Count - 1)
|
||||
CurrentBreakIndex++;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (time < breaks[CurrentBreakIndex].StartTime && CurrentBreakIndex > 0)
|
||||
CurrentBreakIndex--;
|
||||
}
|
||||
|
||||
var closest = breaks[CurrentBreakIndex];
|
||||
|
||||
return closest.Contains(time) ? closest : null;
|
||||
}
|
||||
|
||||
var currentBreak = breaks[CurrentBreakIndex];
|
||||
|
||||
isBreakTime.Value = (currentBreak.HasEffect && currentBreak.Contains(time)) || (time < gameplayStartTime || scoreProcessor?.HasCompleted == true);
|
||||
return null;
|
||||
}
|
||||
|
||||
private void initializeBreaks()
|
||||
|
Loading…
Reference in New Issue
Block a user