2021-04-14 04:04:03 +00:00
// 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.
2021-04-19 03:26:50 +00:00
using System ;
2021-05-05 08:49:33 +00:00
using System.Linq ;
2021-04-14 04:04:03 +00:00
using System.Threading.Tasks ;
using NUnit.Framework ;
using osu.Framework.Graphics ;
2021-04-19 03:26:50 +00:00
using osu.Framework.Graphics.Containers ;
2021-04-14 04:04:03 +00:00
using osu.Framework.Screens ;
2021-04-16 04:59:10 +00:00
using osu.Framework.Testing ;
2021-04-14 04:04:03 +00:00
using osu.Game.Beatmaps ;
using osu.Game.Configuration ;
using osu.Game.Rulesets ;
2021-04-19 03:26:50 +00:00
using osu.Game.Rulesets.Judgements ;
2021-04-14 04:04:03 +00:00
using osu.Game.Rulesets.Osu ;
using osu.Game.Rulesets.Osu.Objects ;
2021-04-19 03:26:50 +00:00
using osu.Game.Rulesets.Scoring ;
2021-04-14 04:04:03 +00:00
using osu.Game.Scoring ;
2021-04-19 03:26:50 +00:00
using osu.Game.Screens.Play ;
2021-04-14 04:04:03 +00:00
using osu.Game.Screens.Ranking ;
using osu.Game.Storyboards ;
using osuTK ;
namespace osu.Game.Tests.Visual.Gameplay
{
public class TestSceneStoryboardWithOutro : PlayerTestScene
{
2021-04-19 03:26:50 +00:00
protected override bool HasCustomSteps = > true ;
2021-04-14 04:04:03 +00:00
protected new OutroPlayer Player = > ( OutroPlayer ) base . Player ;
2021-04-19 03:26:50 +00:00
private double currentStoryboardDuration ;
private bool showResults = true ;
private event Func < HealthProcessor , JudgementResult , bool > currentFailConditions ;
2021-04-14 04:04:03 +00:00
2021-04-16 04:59:10 +00:00
[SetUpSteps]
public override void SetUpSteps ( )
{
base . SetUpSteps ( ) ;
2021-04-17 17:57:32 +00:00
AddStep ( "enable storyboard" , ( ) = > LocalConfig . SetValue ( OsuSetting . ShowStoryboard , true ) ) ;
AddStep ( "set dim level to 0" , ( ) = > LocalConfig . SetValue < double > ( OsuSetting . DimLevel , 0 ) ) ;
2021-04-19 03:26:50 +00:00
AddStep ( "reset fail conditions" , ( ) = > currentFailConditions = ( _ , __ ) = > false ) ;
AddStep ( "set storyboard duration to 2s" , ( ) = > currentStoryboardDuration = 2000 ) ;
AddStep ( "set ShowResults = true" , ( ) = > showResults = true ) ;
2021-04-16 04:59:10 +00:00
}
2021-04-14 04:04:03 +00:00
[Test]
public void TestStoryboardSkipOutro ( )
{
2021-04-19 03:26:50 +00:00
CreateTest ( null ) ;
2021-04-14 04:04:03 +00:00
AddUntilStep ( "completion set by processor" , ( ) = > Player . ScoreProcessor . HasCompleted . Value ) ;
AddStep ( "skip outro" , ( ) = > InputManager . Key ( osuTK . Input . Key . Space ) ) ;
2022-01-01 06:31:50 +00:00
AddAssert ( "player is no longer current screen" , ( ) = > ! Player . IsCurrentScreen ( ) ) ;
2021-05-27 10:45:53 +00:00
AddUntilStep ( "wait for score shown" , ( ) = > Player . IsScoreShown ) ;
2021-04-14 04:04:03 +00:00
}
[Test]
public void TestStoryboardNoSkipOutro ( )
{
2021-04-19 03:26:50 +00:00
CreateTest ( null ) ;
AddUntilStep ( "storyboard ends" , ( ) = > Player . GameplayClockContainer . GameplayClock . CurrentTime > = currentStoryboardDuration ) ;
2021-04-16 04:59:10 +00:00
AddUntilStep ( "wait for score shown" , ( ) = > Player . IsScoreShown ) ;
2021-04-14 04:04:03 +00:00
}
[Test]
2021-06-17 09:11:15 +00:00
public void TestStoryboardExitDuringOutroStillExits ( )
2021-04-14 04:04:03 +00:00
{
2021-04-19 03:26:50 +00:00
CreateTest ( null ) ;
2021-04-14 04:04:03 +00:00
AddUntilStep ( "completion set by processor" , ( ) = > Player . ScoreProcessor . HasCompleted . Value ) ;
AddStep ( "exit via pause" , ( ) = > Player . ExitViaPause ( ) ) ;
2021-06-17 09:11:15 +00:00
AddAssert ( "player exited" , ( ) = > ! Player . IsCurrentScreen ( ) & & Player . GetChildScreen ( ) = = null ) ;
2021-04-14 04:04:03 +00:00
}
2021-04-18 01:49:29 +00:00
[TestCase(false)]
[TestCase(true)]
public void TestStoryboardToggle ( bool enabledAtBeginning )
{
2021-04-19 03:26:50 +00:00
CreateTest ( null ) ;
2021-04-18 01:49:29 +00:00
AddStep ( $"{(enabledAtBeginning ? " enable " : " disable ")} storyboard" , ( ) = > LocalConfig . SetValue ( OsuSetting . ShowStoryboard , enabledAtBeginning ) ) ;
2021-04-18 02:13:28 +00:00
AddStep ( "toggle storyboard" , ( ) = > LocalConfig . SetValue ( OsuSetting . ShowStoryboard , ! enabledAtBeginning ) ) ;
2021-04-18 01:49:29 +00:00
AddUntilStep ( "wait for score shown" , ( ) = > Player . IsScoreShown ) ;
}
2021-04-19 03:26:50 +00:00
[Test]
public void TestOutroEndsDuringFailAnimation ( )
{
CreateTest ( ( ) = >
{
AddStep ( "fail on first judgement" , ( ) = > currentFailConditions = ( _ , __ ) = > true ) ;
2021-10-13 04:47:49 +00:00
// Fail occurs at 164ms with the provided beatmap.
// Fail animation runs for 2.5s realtime but the gameplay time change is *variable* due to the frequency transform being applied, so we need a bit of lenience.
AddStep ( "set storyboard duration to 0.6s" , ( ) = > currentStoryboardDuration = 600 ) ;
2021-04-19 03:26:50 +00:00
} ) ;
2021-10-13 04:47:49 +00:00
2022-01-25 16:45:11 +00:00
AddUntilStep ( "wait for fail" , ( ) = > Player . GameplayState . HasFailed ) ;
2021-04-19 03:26:50 +00:00
AddUntilStep ( "storyboard ends" , ( ) = > Player . GameplayClockContainer . GameplayClock . CurrentTime > = currentStoryboardDuration ) ;
AddUntilStep ( "wait for fail overlay" , ( ) = > Player . FailOverlay . State . Value = = Visibility . Visible ) ;
}
[Test]
public void TestShowResultsFalse ( )
{
CreateTest ( ( ) = >
{
AddStep ( "set ShowResults = false" , ( ) = > showResults = false ) ;
} ) ;
AddUntilStep ( "storyboard ends" , ( ) = > Player . GameplayClockContainer . GameplayClock . CurrentTime > = currentStoryboardDuration ) ;
AddWaitStep ( "wait" , 10 ) ;
AddAssert ( "no score shown" , ( ) = > ! Player . IsScoreShown ) ;
}
[Test]
public void TestStoryboardEndsBeforeCompletion ( )
{
CreateTest ( ( ) = > AddStep ( "set storyboard duration to .1s" , ( ) = > currentStoryboardDuration = 100 ) ) ;
AddUntilStep ( "storyboard ends" , ( ) = > Player . GameplayClockContainer . GameplayClock . CurrentTime > = currentStoryboardDuration ) ;
AddUntilStep ( "completion set by processor" , ( ) = > Player . ScoreProcessor . HasCompleted . Value ) ;
AddUntilStep ( "wait for score shown" , ( ) = > Player . IsScoreShown ) ;
}
2021-05-05 02:23:36 +00:00
[Test]
public void TestStoryboardRewind ( )
{
2021-05-05 08:49:33 +00:00
SkipOverlay . FadeContainer fadeContainer ( ) = > Player . ChildrenOfType < SkipOverlay . FadeContainer > ( ) . First ( ) ;
2021-05-05 02:23:36 +00:00
CreateTest ( null ) ;
AddUntilStep ( "completion set by processor" , ( ) = > Player . ScoreProcessor . HasCompleted . Value ) ;
2021-05-05 08:49:33 +00:00
AddUntilStep ( "skip overlay content becomes visible" , ( ) = > fadeContainer ( ) . State = = Visibility . Visible ) ;
2021-05-05 02:23:36 +00:00
AddStep ( "rewind" , ( ) = > Player . GameplayClockContainer . Seek ( - 1000 ) ) ;
2021-05-05 08:49:33 +00:00
AddUntilStep ( "skip overlay content not visible" , ( ) = > fadeContainer ( ) . State = = Visibility . Hidden ) ;
AddUntilStep ( "skip overlay content becomes visible" , ( ) = > fadeContainer ( ) . State = = Visibility . Visible ) ;
2021-05-05 02:23:36 +00:00
AddUntilStep ( "storyboard ends" , ( ) = > Player . GameplayClockContainer . GameplayClock . CurrentTime > = currentStoryboardDuration ) ;
}
2021-05-08 00:59:20 +00:00
[Test]
public void TestPerformExitNoOutro ( )
{
CreateTest ( null ) ;
AddStep ( "disable storyboard" , ( ) = > LocalConfig . SetValue ( OsuSetting . ShowStoryboard , false ) ) ;
AddUntilStep ( "completion set by processor" , ( ) = > Player . ScoreProcessor . HasCompleted . Value ) ;
AddStep ( "exit via pause" , ( ) = > Player . ExitViaPause ( ) ) ;
2021-05-09 02:42:14 +00:00
AddAssert ( "player exited" , ( ) = > Stack . CurrentScreen = = null ) ;
2021-05-08 00:59:20 +00:00
}
2021-04-19 03:26:50 +00:00
protected override bool AllowFail = > true ;
2021-04-14 04:04:03 +00:00
protected override Ruleset CreatePlayerRuleset ( ) = > new OsuRuleset ( ) ;
2021-04-19 03:26:50 +00:00
protected override TestPlayer CreatePlayer ( Ruleset ruleset ) = > new OutroPlayer ( currentFailConditions , showResults ) ;
2021-04-14 04:04:03 +00:00
protected override IBeatmap CreateBeatmap ( RulesetInfo ruleset )
{
var beatmap = new Beatmap ( ) ;
beatmap . HitObjects . Add ( new HitCircle ( ) ) ;
return beatmap ;
}
2021-04-17 17:57:32 +00:00
protected override WorkingBeatmap CreateWorkingBeatmap ( IBeatmap beatmap , Storyboard storyboard = null )
{
2021-04-19 03:26:50 +00:00
return base . CreateWorkingBeatmap ( beatmap , createStoryboard ( currentStoryboardDuration ) ) ;
}
2021-04-17 17:57:32 +00:00
2021-04-19 03:26:50 +00:00
private Storyboard createStoryboard ( double duration )
{
var storyboard = new Storyboard ( ) ;
var sprite = new StoryboardSprite ( "unknown" , Anchor . TopLeft , Vector2 . Zero ) ;
sprite . TimelineGroup . Alpha . Add ( Easing . None , 0 , duration , 1 , 0 ) ;
storyboard . GetLayer ( "Background" ) . Add ( sprite ) ;
return storyboard ;
2021-04-17 17:57:32 +00:00
}
2021-04-14 04:04:03 +00:00
protected class OutroPlayer : TestPlayer
{
public void ExitViaPause ( ) = > PerformExit ( true ) ;
2021-04-19 03:26:50 +00:00
public new FailOverlay FailOverlay = > base . FailOverlay ;
2021-04-14 04:04:03 +00:00
public bool IsScoreShown = > ! this . IsCurrentScreen ( ) & & this . GetChildScreen ( ) is ResultsScreen ;
2021-04-19 03:26:50 +00:00
private event Func < HealthProcessor , JudgementResult , bool > failConditions ;
public OutroPlayer ( Func < HealthProcessor , JudgementResult , bool > failConditions , bool showResults = true )
: base ( false , showResults )
{
this . failConditions = failConditions ;
}
protected override void LoadComplete ( )
2021-04-14 04:04:03 +00:00
{
2021-04-19 03:26:50 +00:00
base . LoadComplete ( ) ;
HealthProcessor . FailConditions + = failConditions ;
2021-04-14 04:04:03 +00:00
}
protected override Task ImportScore ( Score score )
{
return Task . CompletedTask ;
}
}
}
}