2021-10-06 11:41:17 +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.
using System.Linq ;
using NUnit.Framework ;
using osu.Framework.Input ;
using osu.Framework.Testing ;
using osu.Game.Beatmaps.ControlPoints ;
using osu.Game.Rulesets.Edit ;
using osu.Game.Screens.Edit ;
2021-10-14 21:12:38 +08:00
using osu.Game.Screens.Edit.Setup ;
2021-10-06 11:41:17 +08:00
using osu.Game.Screens.Menu ;
using osu.Game.Screens.Select ;
using osuTK.Input ;
namespace osu.Game.Tests.Visual.Editing
{
public class TestSceneEditorSaving : OsuGameTestScene
{
private Editor editor = > Game . ChildrenOfType < Editor > ( ) . FirstOrDefault ( ) ;
private EditorBeatmap editorBeatmap = > ( EditorBeatmap ) editor . Dependencies . Get ( typeof ( EditorBeatmap ) ) ;
/// <summary>
/// Tests the general expected flow of creating a new beatmap, saving it, then loading it back from song select.
/// </summary>
[Test]
public void TestNewBeatmapSaveThenLoad ( )
{
AddStep ( "set default beatmap" , ( ) = > Game . Beatmap . SetDefault ( ) ) ;
PushAndConfirm ( ( ) = > new EditorLoader ( ) ) ;
2021-10-14 13:40:20 +08:00
AddUntilStep ( "wait for editor load" , ( ) = > editor ? . IsLoaded = = true ) ;
2021-10-06 11:41:17 +08:00
2021-10-14 21:12:38 +08:00
AddUntilStep ( "wait for metadata screen load" , ( ) = > editor . ChildrenOfType < MetadataSection > ( ) . FirstOrDefault ( ) ? . IsLoaded = = true ) ;
2021-10-15 10:14:03 +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 ) ;
2021-10-09 22:12:08 +08:00
AddStep ( "Set overall difficulty" , ( ) = > editorBeatmap . Difficulty . OverallDifficulty = 7 ) ;
2021-10-14 13:40:20 +08:00
AddStep ( "Set artist and title" , ( ) = >
{
editorBeatmap . BeatmapInfo . Metadata . Artist = "artist" ;
editorBeatmap . BeatmapInfo . Metadata . Title = "title" ;
} ) ;
AddStep ( "Set difficulty name" , ( ) = > editorBeatmap . BeatmapInfo . Version = "difficulty" ) ;
2021-10-09 22:12:08 +08:00
2021-10-06 11:41:17 +08:00
AddStep ( "Add timing point" , ( ) = > editorBeatmap . ControlPointInfo . Add ( 0 , new TimingControlPoint ( ) ) ) ;
AddStep ( "Change to placement mode" , ( ) = > InputManager . Key ( Key . Number2 ) ) ;
AddStep ( "Move to playfield" , ( ) = > InputManager . MoveMouseTo ( Game . ScreenSpaceDrawQuad . Centre ) ) ;
AddStep ( "Place single hitcircle" , ( ) = > InputManager . Click ( MouseButton . Left ) ) ;
2021-10-14 13:40:20 +08:00
checkMutations ( ) ;
2021-10-12 18:40:35 +08:00
AddStep ( "Save" , ( ) = > InputManager . Keys ( PlatformAction . Save ) ) ;
2021-10-14 13:40:20 +08:00
checkMutations ( ) ;
2021-10-12 18:40:35 +08:00
AddStep ( "Exit" , ( ) = > InputManager . Key ( Key . Escape ) ) ;
2021-10-06 11:41:17 +08:00
AddUntilStep ( "Wait for main menu" , ( ) = > Game . ScreenStack . CurrentScreen is MainMenu ) ;
PushAndConfirm ( ( ) = > new PlaySongSelect ( ) ) ;
AddUntilStep ( "Wait for beatmap selected" , ( ) = > ! Game . Beatmap . IsDefault ) ;
AddStep ( "Open options" , ( ) = > InputManager . Key ( Key . F3 ) ) ;
AddStep ( "Enter editor" , ( ) = > InputManager . Key ( Key . Number5 ) ) ;
AddUntilStep ( "Wait for editor load" , ( ) = > editor ! = null ) ;
2021-10-14 13:40:20 +08:00
checkMutations ( ) ;
}
private void checkMutations ( )
{
2021-10-06 11:41:17 +08:00
AddAssert ( "Beatmap contains single hitcircle" , ( ) = > editorBeatmap . HitObjects . Count = = 1 ) ;
2021-10-09 22:12:08 +08:00
AddAssert ( "Beatmap has correct overall difficulty" , ( ) = > editorBeatmap . Difficulty . OverallDifficulty = = 7 ) ;
2021-10-14 13:40:20 +08:00
AddAssert ( "Beatmap has correct metadata" , ( ) = > editorBeatmap . BeatmapInfo . Metadata . Artist = = "artist" & & editorBeatmap . BeatmapInfo . Metadata . Title = = "title" ) ;
AddAssert ( "Beatmap has correct difficulty name" , ( ) = > editorBeatmap . BeatmapInfo . Version = = "difficulty" ) ;
2021-10-06 11:41:17 +08:00
}
}
}