// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using System.Linq; using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Graphics; using osu.Framework.Testing; using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.UI; using osu.Game.Screens.Play; using osu.Game.Screens.Play.HUD; using osu.Game.Skinning; namespace osu.Game.Tests.Visual.Gameplay { [TestFixture] public partial class TestSceneSongProgress : SkinnableHUDComponentTestScene { private GameplayClockContainer gameplayClockContainer = null!; private const double skip_target_time = -2000; [BackgroundDependencyLoader] private void load() { Beatmap.Value = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo); FrameStabilityContainer frameStabilityContainer; Add(gameplayClockContainer = new MasterGameplayClockContainer(Beatmap.Value, skip_target_time) { Child = frameStabilityContainer = new FrameStabilityContainer { MaxCatchUpFrames = 1 } }); Dependencies.CacheAs(frameStabilityContainer); } [SetUpSteps] public void SetupSteps() { AddStep("reset clock", () => gameplayClockContainer.Reset()); AddStep("set hit objects", () => this.ChildrenOfType().ForEach(progress => progress.Objects = Beatmap.Value.Beatmap.HitObjects)); AddStep("hook seeking", () => { applyToDefaultProgress(d => d.ChildrenOfType().Single().OnSeek += t => gameplayClockContainer.Seek(t)); applyToArgonProgress(d => d.ChildrenOfType().Single().OnSeek += t => gameplayClockContainer.Seek(t)); }); AddStep("seek to intro", () => gameplayClockContainer.Seek(skip_target_time)); AddStep("start", gameplayClockContainer.Start); } [Test] public void TestBasic() { AddToggleStep("toggle seeking", b => { applyToDefaultProgress(s => s.Interactive.Value = b); applyToArgonProgress(s => s.Interactive.Value = b); }); AddToggleStep("toggle graph", b => { applyToDefaultProgress(s => s.ShowGraph.Value = b); applyToArgonProgress(s => s.ShowGraph.Value = b); }); AddStep("stop", gameplayClockContainer.Stop); } private void applyToArgonProgress(Action action) => this.ChildrenOfType().ForEach(action); private void applyToDefaultProgress(Action action) => this.ChildrenOfType().ForEach(action); protected override Drawable CreateDefaultImplementation() => new DefaultSongProgress(); protected override Drawable CreateArgonImplementation() => new ArgonSongProgress(); protected override Drawable CreateLegacyImplementation() => new LegacySongProgress(); } }