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.
2022-06-17 15:37:17 +08:00
#nullable disable
2021-10-06 11:41:17 +08:00
using System.Linq ;
using NUnit.Framework ;
2022-01-25 16:43:05 +08:00
using osu.Framework.Allocation ;
2022-07-11 17:29:56 +08:00
using osu.Framework.Graphics ;
2022-01-26 06:20:33 +08:00
using osu.Framework.Screens ;
2021-10-06 11:41:17 +08:00
using osu.Framework.Testing ;
2022-01-25 16:31:05 +08:00
using osu.Framework.Utils ;
2022-06-24 20:02:29 +08:00
using osu.Game.Beatmaps ;
2021-10-06 11:41:17 +08:00
using osu.Game.Beatmaps.ControlPoints ;
2022-07-11 17:29:56 +08:00
using osu.Game.Overlays ;
2021-10-06 11:41:17 +08:00
using osu.Game.Screens.Edit ;
2022-01-25 16:31:05 +08:00
using osu.Game.Screens.Edit.Compose.Components.Timeline ;
2022-01-26 06:20:33 +08:00
using osu.Game.Screens.Select ;
2021-10-06 11:41:17 +08:00
using osuTK.Input ;
namespace osu.Game.Tests.Visual.Editing
{
2022-01-25 16:31:05 +08:00
public partial class TestSceneEditorSaving : EditorSavingTestScene
2021-10-06 11:41:17 +08:00
{
2022-03-22 14:28:31 +08:00
[Test]
public void TestCantExitWithoutSaving ( )
{
2022-07-11 17:29:56 +08:00
AddUntilStep ( "Wait for dialog overlay load" , ( ) = > ( ( Drawable ) Game . Dependencies . Get < IDialogOverlay > ( ) ) . IsLoaded ) ;
2022-03-22 14:28:31 +08:00
AddRepeatStep ( "Exit" , ( ) = > InputManager . Key ( Key . Escape ) , 10 ) ;
2022-07-10 03:10:18 +08:00
AddAssert ( "Sample playback disabled" , ( ) = > Editor . SamplePlaybackDisabled . Value ) ;
2022-03-22 14:28:31 +08:00
AddAssert ( "Editor is still active screen" , ( ) = > Game . ScreenStack . CurrentScreen is Editor ) ;
}
2021-10-06 11:41:17 +08:00
[Test]
2022-01-25 16:31:05 +08:00
public void TestMetadata ( )
2021-10-06 11:41:17 +08:00
{
2022-01-25 16:31:05 +08:00
AddStep ( "Set artist and title" , ( ) = >
{
EditorBeatmap . BeatmapInfo . Metadata . Artist = "artist" ;
EditorBeatmap . BeatmapInfo . Metadata . Title = "title" ;
} ) ;
AddStep ( "Set author" , ( ) = > EditorBeatmap . BeatmapInfo . Metadata . Author . Username = "author" ) ;
AddStep ( "Set difficulty name" , ( ) = > EditorBeatmap . BeatmapInfo . DifficultyName = "difficulty" ) ;
2021-10-06 11:41:17 +08:00
2022-01-25 16:31:05 +08:00
SaveEditor ( ) ;
2021-10-06 11:41:17 +08:00
2022-07-08 01:31:33 +08:00
AddAssert ( "Hash updated" , ( ) = > ! string . IsNullOrEmpty ( EditorBeatmap . BeatmapInfo . BeatmapSet ? . Hash ) ) ;
2022-01-25 16:31:05 +08:00
AddAssert ( "Beatmap has correct metadata" , ( ) = > EditorBeatmap . BeatmapInfo . Metadata . Artist = = "artist" & & EditorBeatmap . BeatmapInfo . Metadata . Title = = "title" ) ;
AddAssert ( "Beatmap has correct author" , ( ) = > EditorBeatmap . BeatmapInfo . Metadata . Author . Username = = "author" ) ;
AddAssert ( "Beatmap has correct difficulty name" , ( ) = > EditorBeatmap . BeatmapInfo . DifficultyName = = "difficulty" ) ;
AddAssert ( "Beatmap has correct .osu file path" , ( ) = > EditorBeatmap . BeatmapInfo . Path = = "artist - title (author) [difficulty].osu" ) ;
2021-10-06 11:41:17 +08:00
2022-01-25 16:31:05 +08:00
ReloadEditorToSameBeatmap ( ) ;
2021-10-14 21:12:38 +08:00
2022-01-25 16:31:05 +08:00
AddAssert ( "Beatmap still has correct metadata" , ( ) = > EditorBeatmap . BeatmapInfo . Metadata . Artist = = "artist" & & EditorBeatmap . BeatmapInfo . Metadata . Title = = "title" ) ;
AddAssert ( "Beatmap still has correct author" , ( ) = > EditorBeatmap . BeatmapInfo . Metadata . Author . Username = = "author" ) ;
AddAssert ( "Beatmap still has correct difficulty name" , ( ) = > EditorBeatmap . BeatmapInfo . DifficultyName = = "difficulty" ) ;
AddAssert ( "Beatmap still has correct .osu file path" , ( ) = > EditorBeatmap . BeatmapInfo . Path = = "artist - title (author) [difficulty].osu" ) ;
}
2021-10-15 10:14:03 +08:00
2022-01-25 16:31:05 +08:00
[Test]
public void TestConfiguration ( )
{
double originalTimelineZoom = 0 ;
double changedTimelineZoom = 0 ;
2021-10-15 10:14:03 +08:00
2022-02-22 14:40:30 +08:00
AddUntilStep ( "wait for timeline load" , ( ) = > Editor . ChildrenOfType < Timeline > ( ) . SingleOrDefault ( ) ? . IsLoaded = = true ) ;
2022-01-25 16:31:05 +08:00
AddStep ( "Set beat divisor" , ( ) = > Editor . Dependencies . Get < BindableBeatDivisor > ( ) . Value = 16 ) ;
AddStep ( "Set timeline zoom" , ( ) = >
2021-10-14 13:40:20 +08:00
{
2022-01-25 16:31:05 +08:00
originalTimelineZoom = EditorBeatmap . BeatmapInfo . TimelineZoom ;
var timeline = Editor . ChildrenOfType < Timeline > ( ) . Single ( ) ;
InputManager . MoveMouseTo ( timeline ) ;
InputManager . PressKey ( Key . AltLeft ) ;
InputManager . ScrollVerticalBy ( 15f ) ;
InputManager . ReleaseKey ( Key . AltLeft ) ;
2021-10-14 13:40:20 +08:00
} ) ;
2021-10-09 22:12:08 +08:00
2022-01-25 16:31:05 +08:00
AddAssert ( "Ensure timeline zoom changed" , ( ) = >
{
changedTimelineZoom = EditorBeatmap . BeatmapInfo . TimelineZoom ;
return ! Precision . AlmostEquals ( changedTimelineZoom , originalTimelineZoom ) ;
} ) ;
2021-10-06 11:41:17 +08:00
2022-01-25 16:31:05 +08:00
SaveEditor ( ) ;
2021-10-06 11:41:17 +08:00
2022-01-25 16:31:05 +08:00
AddAssert ( "Beatmap has correct beat divisor" , ( ) = > EditorBeatmap . BeatmapInfo . BeatDivisor = = 16 ) ;
AddAssert ( "Beatmap has correct timeline zoom" , ( ) = > EditorBeatmap . BeatmapInfo . TimelineZoom = = changedTimelineZoom ) ;
2021-10-12 18:40:35 +08:00
2022-01-25 16:31:05 +08:00
ReloadEditorToSameBeatmap ( ) ;
2021-10-26 15:06:02 +08:00
2022-01-25 16:31:05 +08:00
AddAssert ( "Beatmap still has correct beat divisor" , ( ) = > EditorBeatmap . BeatmapInfo . BeatDivisor = = 16 ) ;
AddAssert ( "Beatmap still has correct timeline zoom" , ( ) = > EditorBeatmap . BeatmapInfo . TimelineZoom = = changedTimelineZoom ) ;
}
2021-10-12 18:40:35 +08:00
2022-01-25 16:31:05 +08:00
[Test]
public void TestDifficulty ( )
{
AddStep ( "Set overall difficulty" , ( ) = > EditorBeatmap . Difficulty . OverallDifficulty = 7 ) ;
2021-10-14 13:40:20 +08:00
2022-01-25 16:31:05 +08:00
SaveEditor ( ) ;
2021-10-06 11:41:17 +08:00
2022-01-25 16:31:05 +08:00
AddAssert ( "Beatmap has correct overall difficulty" , ( ) = > EditorBeatmap . Difficulty . OverallDifficulty = = 7 ) ;
2021-10-06 11:41:17 +08:00
2022-01-25 16:31:05 +08:00
ReloadEditorToSameBeatmap ( ) ;
2021-11-25 20:11:13 +08:00
2022-01-25 16:31:05 +08:00
AddAssert ( "Beatmap still has correct overall difficulty" , ( ) = > EditorBeatmap . Difficulty . OverallDifficulty = = 7 ) ;
}
2021-10-06 11:41:17 +08:00
2022-01-25 16:31:05 +08:00
[Test]
public void TestHitObjectPlacement ( )
{
AddStep ( "Add timing point" , ( ) = > EditorBeatmap . ControlPointInfo . Add ( 500 , 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-06 11:41:17 +08:00
2022-01-25 16:31:05 +08:00
SaveEditor ( ) ;
2021-10-14 13:40:20 +08:00
2022-01-25 16:31:05 +08:00
AddAssert ( "Beatmap has correct timing point" , ( ) = > EditorBeatmap . ControlPointInfo . TimingPoints . Single ( ) . Time = = 500 ) ;
2021-10-14 13:40:20 +08:00
2022-01-25 16:31:05 +08:00
// After placement these must be non-default as defaults are read-only.
AddAssert ( "Placed object has non-default control points" , ( ) = >
2022-06-20 15:53:03 +08:00
! ReferenceEquals ( EditorBeatmap . HitObjects [ 0 ] . SampleControlPoint , SampleControlPoint . DEFAULT ) & &
! ReferenceEquals ( EditorBeatmap . HitObjects [ 0 ] . DifficultyControlPoint , DifficultyControlPoint . DEFAULT ) ) ;
2022-01-25 16:31:05 +08:00
ReloadEditorToSameBeatmap ( ) ;
AddAssert ( "Beatmap still has correct timing point" , ( ) = > EditorBeatmap . ControlPointInfo . TimingPoints . Single ( ) . Time = = 500 ) ;
// After placement these must be non-default as defaults are read-only.
AddAssert ( "Placed object still has non-default control points" , ( ) = >
2022-06-20 15:53:03 +08:00
! ReferenceEquals ( EditorBeatmap . HitObjects [ 0 ] . SampleControlPoint , SampleControlPoint . DEFAULT ) & &
! ReferenceEquals ( EditorBeatmap . HitObjects [ 0 ] . DifficultyControlPoint , DifficultyControlPoint . DEFAULT ) ) ;
2021-10-06 11:41:17 +08:00
}
2022-06-24 20:02:29 +08:00
[Test]
public void TestLengthAndStarRatingUpdated ( )
{
WorkingBeatmap working = null ;
double lastStarRating = 0 ;
double lastLength = 0 ;
AddStep ( "Add timing point" , ( ) = > EditorBeatmap . ControlPointInfo . Add ( 500 , 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 ) ) ;
AddAssert ( "One hitobject placed" , ( ) = > EditorBeatmap . HitObjects . Count = = 1 ) ;
SaveEditor ( ) ;
AddStep ( "Get working beatmap" , ( ) = > working = Game . BeatmapManager . GetWorkingBeatmap ( EditorBeatmap . BeatmapInfo , true ) ) ;
AddAssert ( "Beatmap length is zero" , ( ) = > working . BeatmapInfo . Length = = 0 ) ;
checkDifficultyIncreased ( ) ;
AddStep ( "Move forward" , ( ) = > InputManager . Key ( Key . Right ) ) ;
AddStep ( "Place another hitcircle" , ( ) = > InputManager . Click ( MouseButton . Left ) ) ;
AddAssert ( "Two hitobjects placed" , ( ) = > EditorBeatmap . HitObjects . Count = = 2 ) ;
SaveEditor ( ) ;
AddStep ( "Get working beatmap" , ( ) = > working = Game . BeatmapManager . GetWorkingBeatmap ( EditorBeatmap . BeatmapInfo , true ) ) ;
checkDifficultyIncreased ( ) ;
checkLengthIncreased ( ) ;
void checkLengthIncreased ( )
{
AddStep ( "Beatmap length increased" , ( ) = >
{
Assert . That ( working . BeatmapInfo . Length , Is . GreaterThan ( lastLength ) ) ;
lastLength = working . BeatmapInfo . Length ;
} ) ;
}
void checkDifficultyIncreased ( )
{
AddStep ( "Beatmap difficulty increased" , ( ) = >
{
Assert . That ( working . BeatmapInfo . StarRating , Is . GreaterThan ( lastStarRating ) ) ;
lastStarRating = working . BeatmapInfo . StarRating ;
} ) ;
}
}
2022-01-26 06:20:33 +08:00
[Test]
public void TestExitWithoutSaveFromExistingBeatmap ( )
{
const string tags_to_save = "these tags will be saved" ;
const string tags_to_discard = "these tags should be discarded" ;
AddStep ( "Set tags" , ( ) = > EditorBeatmap . BeatmapInfo . Metadata . Tags = tags_to_save ) ;
SaveEditor ( ) ;
AddAssert ( "Tags saved correctly" , ( ) = > EditorBeatmap . BeatmapInfo . Metadata . Tags = = tags_to_save ) ;
ReloadEditorToSameBeatmap ( ) ;
AddAssert ( "Tags saved correctly" , ( ) = > EditorBeatmap . BeatmapInfo . Metadata . Tags = = tags_to_save ) ;
AddStep ( "Set tags again" , ( ) = > EditorBeatmap . BeatmapInfo . Metadata . Tags = tags_to_discard ) ;
AddStep ( "Exit editor" , ( ) = > Editor . Exit ( ) ) ;
AddUntilStep ( "Wait for song select" , ( ) = > Game . ScreenStack . CurrentScreen is PlaySongSelect ) ;
AddAssert ( "Tags reverted correctly" , ( ) = > Game . Beatmap . Value . BeatmapInfo . Metadata . Tags = = tags_to_save ) ;
}
2021-10-06 11:41:17 +08:00
}
}