// 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.Allocation; using osu.Framework.Bindables; using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.UI; using osu.Game.Scoring; using osu.Game.Screens.Play; namespace osu.Game.Tests.Visual { /// /// A player that exposes many components that would otherwise not be available, for testing purposes. /// public class TestReplayPlayer : ReplayPlayer { protected override bool PauseOnFocusLost { get; } public new DrawableRuleset DrawableRuleset => base.DrawableRuleset; /// /// Mods from *player* (not OsuScreen). /// public new Bindable> Mods => base.Mods; public new HUDOverlay HUDOverlay => base.HUDOverlay; public new GameplayClockContainer GameplayClockContainer => base.GameplayClockContainer; public new ScoreProcessor ScoreProcessor => base.ScoreProcessor; public new HealthProcessor HealthProcessor => base.HealthProcessor; public new bool PauseCooldownActive => base.PauseCooldownActive; public readonly List Results = new List(); /// /// Instantiate a replay player that renders an autoplay mod. /// public TestReplayPlayer(bool allowPause = true, bool showResults = true, bool pauseOnFocusLost = false) : base((beatmap, mods) => mods.OfType().First().CreateReplayScore(beatmap, mods), new PlayerConfiguration { AllowPause = allowPause, ShowResults = showResults }) { PauseOnFocusLost = pauseOnFocusLost; } /// /// Instantiate a replay player that renders the provided replay. /// public TestReplayPlayer(Score score, bool allowPause = true, bool showResults = true, bool pauseOnFocusLost = false) : base(score, new PlayerConfiguration { AllowPause = allowPause, ShowResults = showResults }) { PauseOnFocusLost = pauseOnFocusLost; } [BackgroundDependencyLoader] private void load() { ScoreProcessor.NewJudgement += r => Results.Add(r); } } }