2022-01-25 16:31:05 +08: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.
2022-06-17 15:37:17 +08:00
#nullable disable
2023-05-01 23:13:09 +08:00
using System ;
2022-01-25 16:31:05 +08:00
using System.Linq ;
2023-05-01 23:13:09 +08:00
using JetBrains.Annotations ;
2022-01-25 16:31:05 +08:00
using osu.Framework.Input ;
using osu.Framework.Testing ;
2023-05-01 23:13:09 +08:00
using osu.Game.Beatmaps ;
2022-01-25 16:31:05 +08:00
using osu.Game.Rulesets.Edit ;
using osu.Game.Screens.Edit ;
using osu.Game.Screens.Edit.Setup ;
using osu.Game.Screens.Menu ;
using osu.Game.Screens.Select ;
using osuTK.Input ;
namespace osu.Game.Tests.Visual
{
/// <summary>
/// Tests the general expected flow of creating a new beatmap, saving it, then loading it back from song select.
/// </summary>
2022-01-26 22:04:28 +08:00
public abstract partial class EditorSavingTestScene : OsuGameTestScene
2022-01-25 16:31:05 +08:00
{
protected Editor Editor = > Game . ChildrenOfType < Editor > ( ) . FirstOrDefault ( ) ;
protected EditorBeatmap EditorBeatmap = > ( EditorBeatmap ) Editor . Dependencies . Get ( typeof ( EditorBeatmap ) ) ;
2023-05-01 23:13:09 +08:00
[CanBeNull]
protected Func < WorkingBeatmap > CreateInitialBeatmap { get ; set ; }
2022-01-25 16:31:05 +08:00
[SetUpSteps]
public override void SetUpSteps ( )
{
base . SetUpSteps ( ) ;
2023-05-01 23:13:09 +08:00
if ( CreateInitialBeatmap = = null )
AddStep ( "set default beatmap" , ( ) = > Game . Beatmap . SetDefault ( ) ) ;
else
{
AddStep ( "set test beatmap" , ( ) = > Game . Beatmap . Value = CreateInitialBeatmap ? . Invoke ( ) ) ;
}
2022-01-25 16:31:05 +08:00
PushAndConfirm ( ( ) = > new EditorLoader ( ) ) ;
AddUntilStep ( "wait for editor load" , ( ) = > Editor ? . IsLoaded = = true ) ;
2023-05-01 23:13:09 +08:00
if ( CreateInitialBeatmap = = null )
AddUntilStep ( "wait for metadata screen load" , ( ) = > Editor . ChildrenOfType < MetadataSection > ( ) . FirstOrDefault ( ) ? . IsLoaded = = true ) ;
2022-01-25 16:31:05 +08:00
// We intentionally switch away from the metadata screen, else there is a feedback loop with the textbox handling which causes metadata changes below to get overwritten.
AddStep ( "Enter compose mode" , ( ) = > InputManager . Key ( Key . F1 ) ) ;
AddUntilStep ( "Wait for compose mode load" , ( ) = > Editor . ChildrenOfType < HitObjectComposer > ( ) . FirstOrDefault ( ) ? . IsLoaded = = true ) ;
}
protected void SaveEditor ( )
{
AddStep ( "Save" , ( ) = > InputManager . Keys ( PlatformAction . Save ) ) ;
}
protected void ReloadEditorToSameBeatmap ( )
{
2023-05-01 23:13:09 +08:00
Guid beatmapSetGuid = Guid . Empty ;
Guid beatmapGuid = Guid . Empty ;
AddStep ( "Store beatmap GUIDs" , ( ) = >
{
beatmapSetGuid = EditorBeatmap . BeatmapInfo . BeatmapSet ! . ID ;
beatmapGuid = EditorBeatmap . BeatmapInfo . ID ;
} ) ;
2022-01-25 16:31:05 +08:00
AddStep ( "Exit" , ( ) = > InputManager . Key ( Key . Escape ) ) ;
AddUntilStep ( "Wait for main menu" , ( ) = > Game . ScreenStack . CurrentScreen is MainMenu ) ;
SongSelect songSelect = null ;
PushAndConfirm ( ( ) = > songSelect = new PlaySongSelect ( ) ) ;
AddUntilStep ( "wait for carousel load" , ( ) = > songSelect . BeatmapSetsLoaded ) ;
2023-05-01 23:13:09 +08:00
AddStep ( "Present same beatmap" , ( ) = > Game . PresentBeatmap ( Game . BeatmapManager . QueryBeatmapSet ( set = > set . ID = = beatmapSetGuid ) ! . Value , beatmap = > beatmap . ID = = beatmapGuid ) ) ;
AddUntilStep ( "Wait for beatmap selected" , ( ) = > Game . Beatmap . Value . BeatmapInfo . ID = = beatmapGuid ) ;
2022-01-25 16:31:05 +08:00
AddStep ( "Open options" , ( ) = > InputManager . Key ( Key . F3 ) ) ;
AddStep ( "Enter editor" , ( ) = > InputManager . Key ( Key . Number5 ) ) ;
AddUntilStep ( "Wait for editor load" , ( ) = > Editor ! = null ) ;
}
}
}