// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. 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; private readonly PeriodTracker tracker = new PeriodTracker(); /// /// Whether the gameplay is currently in a break. /// public IBindable IsBreakTime => isBreakTime; private readonly BindableBool isBreakTime = new BindableBool(); public IReadOnlyList Breaks { set { isBreakTime.Value = false; tracker.Periods = value?.Where(b => b.HasEffect) .Select(b => new Period(b.StartTime, b.EndTime - BreakOverlay.BREAK_FADE_DURATION)); } } public BreakTracker(double gameplayStartTime = 0, ScoreProcessor scoreProcessor = null) { this.gameplayStartTime = gameplayStartTime; this.scoreProcessor = scoreProcessor; } protected override void Update() { base.Update(); var time = Clock.CurrentTime; isBreakTime.Value = tracker.IsInAny(time) || time < gameplayStartTime || scoreProcessor?.HasCompleted.Value == true; } } }