1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-19 07:23:22 +08:00
osu-lazer/osu.Game/Screens/Play/BreakTracker.cs

64 lines
1.8 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.
2022-06-17 15:37:17 +08:00
#nullable disable
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Beatmaps.Timing;
using osu.Game.Rulesets.Scoring;
using osu.Game.Utils;
namespace osu.Game.Screens.Play
{
public class BreakTracker : Component
{
private readonly ScoreProcessor scoreProcessor;
private readonly double gameplayStartTime;
2020-05-02 07:33:33 +08:00
private PeriodTracker breaks;
/// <summary>
/// Whether the gameplay is currently in a break.
/// </summary>
public IBindable<bool> IsBreakTime => isBreakTime;
private readonly BindableBool isBreakTime = new BindableBool(true);
public IReadOnlyList<BreakPeriod> Breaks
{
set
{
2020-05-02 07:33:33 +08:00
breaks = new PeriodTracker(value.Where(b => b.HasEffect)
.Select(b => new Period(b.StartTime, b.EndTime - BreakOverlay.BREAK_FADE_DURATION)));
2021-02-07 01:54:13 +08:00
if (IsLoaded)
updateBreakTime();
}
}
public BreakTracker(double gameplayStartTime = 0, ScoreProcessor scoreProcessor = null)
{
this.gameplayStartTime = gameplayStartTime;
this.scoreProcessor = scoreProcessor;
}
protected override void Update()
{
base.Update();
updateBreakTime();
}
private void updateBreakTime()
{
double time = Clock.CurrentTime;
2020-05-02 07:33:33 +08:00
isBreakTime.Value = breaks?.IsInAny(time) == true
|| time < gameplayStartTime
|| scoreProcessor?.HasCompleted.Value == true;
}
}
}