2020-09-14 14:27:16 +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
2020-09-14 14:27:16 +08:00
using System.Linq ;
using NUnit.Framework ;
2021-04-18 19:18:30 +08:00
using osu.Framework.Testing ;
2020-09-14 14:27:16 +08:00
using osu.Game.Beatmaps ;
using osu.Game.Rulesets ;
2021-04-18 19:18:30 +08:00
using osu.Game.Rulesets.Edit ;
2020-09-14 16:43:27 +08:00
using osu.Game.Rulesets.Objects ;
using osu.Game.Rulesets.Objects.Types ;
2020-09-14 14:27:16 +08:00
using osu.Game.Rulesets.Osu ;
using osu.Game.Rulesets.Osu.Objects ;
2021-04-18 19:18:30 +08:00
using osu.Game.Screens.Edit.Compose.Components ;
using osu.Game.Screens.Edit.Compose.Components.Timeline ;
2020-09-14 14:27:16 +08:00
using osu.Game.Tests.Beatmaps ;
2020-09-14 16:43:27 +08:00
using osuTK ;
2020-09-14 14:27:16 +08:00
namespace osu.Game.Tests.Visual.Editing
{
2022-11-24 13:32:20 +08:00
public partial class TestSceneEditorClipboard : EditorTestScene
2020-09-14 14:27:16 +08:00
{
protected override Ruleset CreateEditorRuleset ( ) = > new OsuRuleset ( ) ;
protected override IBeatmap CreateBeatmap ( RulesetInfo ruleset ) = > new TestBeatmap ( ruleset , false ) ;
[Test]
public void TestCutRemovesObjects ( )
{
var addedObject = new HitCircle { StartTime = 1000 } ;
AddStep ( "add hitobject" , ( ) = > EditorBeatmap . Add ( addedObject ) ) ;
AddStep ( "select added object" , ( ) = > EditorBeatmap . SelectedHitObjects . Add ( addedObject ) ) ;
AddStep ( "cut hitobject" , ( ) = > Editor . Cut ( ) ) ;
AddAssert ( "no hitobjects in beatmap" , ( ) = > EditorBeatmap . HitObjects . Count = = 0 ) ;
}
[TestCase(1000)]
[TestCase(2000)]
public void TestCutPaste ( double newTime )
{
var addedObject = new HitCircle { StartTime = 1000 } ;
AddStep ( "add hitobject" , ( ) = > EditorBeatmap . Add ( addedObject ) ) ;
AddStep ( "select added object" , ( ) = > EditorBeatmap . SelectedHitObjects . Add ( addedObject ) ) ;
AddStep ( "cut hitobject" , ( ) = > Editor . Cut ( ) ) ;
AddStep ( "move forward in time" , ( ) = > EditorClock . Seek ( newTime ) ) ;
AddStep ( "paste hitobject" , ( ) = > Editor . Paste ( ) ) ;
AddAssert ( "is one object" , ( ) = > EditorBeatmap . HitObjects . Count = = 1 ) ;
AddAssert ( "new object selected" , ( ) = > EditorBeatmap . SelectedHitObjects . Single ( ) . StartTime = = newTime ) ;
}
2020-09-14 16:43:27 +08:00
[Test]
public void TestCutPasteSlider ( )
{
var addedObject = new Slider
{
StartTime = 1000 ,
Path = new SliderPath
{
ControlPoints =
{
new PathControlPoint ( ) ,
new PathControlPoint ( new Vector2 ( 100 , 0 ) , PathType . Bezier )
}
}
} ;
AddStep ( "add hitobject" , ( ) = > EditorBeatmap . Add ( addedObject ) ) ;
AddStep ( "select added object" , ( ) = > EditorBeatmap . SelectedHitObjects . Add ( addedObject ) ) ;
AddStep ( "cut hitobject" , ( ) = > Editor . Cut ( ) ) ;
AddStep ( "paste hitobject" , ( ) = > Editor . Paste ( ) ) ;
AddAssert ( "is one object" , ( ) = > EditorBeatmap . HitObjects . Count = = 1 ) ;
2022-01-12 04:21:04 +08:00
Slider slider = null ;
AddStep ( "retrieve slider" , ( ) = > slider = ( Slider ) EditorBeatmap . HitObjects . Single ( ) ) ;
2020-09-14 16:43:27 +08:00
AddAssert ( "path matches" , ( ) = >
{
2022-01-12 04:21:04 +08:00
var path = slider . Path ;
2020-09-14 16:43:27 +08:00
return path . ControlPoints . Count = = 2 & & path . ControlPoints . SequenceEqual ( addedObject . Path . ControlPoints ) ;
} ) ;
}
2020-09-14 16:48:29 +08:00
[Test]
public void TestCutPasteSpinner ( )
{
var addedObject = new Spinner
{
StartTime = 1000 ,
Duration = 5000
} ;
AddStep ( "add hitobject" , ( ) = > EditorBeatmap . Add ( addedObject ) ) ;
AddStep ( "select added object" , ( ) = > EditorBeatmap . SelectedHitObjects . Add ( addedObject ) ) ;
AddStep ( "cut hitobject" , ( ) = > Editor . Cut ( ) ) ;
AddStep ( "paste hitobject" , ( ) = > Editor . Paste ( ) ) ;
AddAssert ( "is one object" , ( ) = > EditorBeatmap . HitObjects . Count = = 1 ) ;
AddAssert ( "duration matches" , ( ) = > ( ( Spinner ) EditorBeatmap . HitObjects . Single ( ) ) . Duration = = 5000 ) ;
}
2021-04-18 19:18:30 +08:00
[TestCase(false)]
[TestCase(true)]
public void TestCopyPaste ( bool deselectAfterCopy )
2020-09-14 14:27:16 +08:00
{
var addedObject = new HitCircle { StartTime = 1000 } ;
AddStep ( "add hitobject" , ( ) = > EditorBeatmap . Add ( addedObject ) ) ;
AddStep ( "select added object" , ( ) = > EditorBeatmap . SelectedHitObjects . Add ( addedObject ) ) ;
AddStep ( "copy hitobject" , ( ) = > Editor . Copy ( ) ) ;
AddStep ( "move forward in time" , ( ) = > EditorClock . Seek ( 2000 ) ) ;
2021-04-18 19:18:30 +08:00
if ( deselectAfterCopy )
{
AddStep ( "deselect" , ( ) = > EditorBeatmap . SelectedHitObjects . Clear ( ) ) ;
2021-05-03 16:34:34 +08:00
AddUntilStep ( "timeline selection box is not visible" , ( ) = > Editor . ChildrenOfType < Timeline > ( ) . First ( ) . ChildrenOfType < SelectionBox > ( ) . First ( ) . Alpha = = 0 ) ;
AddUntilStep ( "composer selection box is not visible" , ( ) = > Editor . ChildrenOfType < HitObjectComposer > ( ) . First ( ) . ChildrenOfType < SelectionBox > ( ) . First ( ) . Alpha = = 0 ) ;
2021-04-18 19:18:30 +08:00
}
2020-09-14 14:27:16 +08:00
AddStep ( "paste hitobject" , ( ) = > Editor . Paste ( ) ) ;
AddAssert ( "are two objects" , ( ) = > EditorBeatmap . HitObjects . Count = = 2 ) ;
AddAssert ( "new object selected" , ( ) = > EditorBeatmap . SelectedHitObjects . Single ( ) . StartTime = = 2000 ) ;
2021-04-18 19:18:30 +08:00
2021-04-27 14:40:35 +08:00
AddUntilStep ( "timeline selection box is visible" , ( ) = > Editor . ChildrenOfType < Timeline > ( ) . First ( ) . ChildrenOfType < EditorSelectionHandler > ( ) . First ( ) . Alpha > 0 ) ;
AddUntilStep ( "composer selection box is visible" , ( ) = > Editor . ChildrenOfType < HitObjectComposer > ( ) . First ( ) . ChildrenOfType < EditorSelectionHandler > ( ) . First ( ) . Alpha > 0 ) ;
2020-09-14 14:27:16 +08:00
}
2022-10-25 10:38:58 +08:00
[Test]
public void TestClone ( )
{
var addedObject = new HitCircle { StartTime = 1000 } ;
AddStep ( "add hitobject" , ( ) = > EditorBeatmap . Add ( addedObject ) ) ;
AddStep ( "select added object" , ( ) = > EditorBeatmap . SelectedHitObjects . Add ( addedObject ) ) ;
AddAssert ( "is one object" , ( ) = > EditorBeatmap . HitObjects . Count = = 1 ) ;
2022-10-25 10:43:23 +08:00
AddStep ( "clone" , ( ) = > Editor . Clone ( ) ) ;
2022-10-25 10:38:58 +08:00
AddAssert ( "is two objects" , ( ) = > EditorBeatmap . HitObjects . Count = = 2 ) ;
2022-10-25 10:43:23 +08:00
AddStep ( "clone" , ( ) = > Editor . Clone ( ) ) ;
2022-10-25 10:38:58 +08:00
AddAssert ( "is three objects" , ( ) = > EditorBeatmap . HitObjects . Count = = 3 ) ;
}
2020-09-14 14:27:16 +08:00
[Test]
public void TestCutNothing ( )
{
AddStep ( "cut hitobject" , ( ) = > Editor . Cut ( ) ) ;
AddAssert ( "are no objects" , ( ) = > EditorBeatmap . HitObjects . Count = = 0 ) ;
}
[Test]
public void TestCopyNothing ( )
{
AddStep ( "copy hitobject" , ( ) = > Editor . Copy ( ) ) ;
AddAssert ( "are no objects" , ( ) = > EditorBeatmap . HitObjects . Count = = 0 ) ;
}
[Test]
public void TestPasteNothing ( )
{
AddStep ( "paste hitobject" , ( ) = > Editor . Paste ( ) ) ;
AddAssert ( "are no objects" , ( ) = > EditorBeatmap . HitObjects . Count = = 0 ) ;
}
2022-10-25 10:38:58 +08:00
[Test]
public void TestCloneNothing ( )
{
// Add arbitrary object and copy to clipboard.
// This is tested to ensure that clone doesn't incorrectly read from the clipboard when no selection is made.
var addedObject = new HitCircle { StartTime = 1000 } ;
AddStep ( "add hitobject" , ( ) = > EditorBeatmap . Add ( addedObject ) ) ;
AddStep ( "select added object" , ( ) = > EditorBeatmap . SelectedHitObjects . Add ( addedObject ) ) ;
AddStep ( "copy hitobject" , ( ) = > Editor . Copy ( ) ) ;
AddStep ( "deselect all objects" , ( ) = > EditorBeatmap . SelectedHitObjects . Clear ( ) ) ;
AddAssert ( "is one object" , ( ) = > EditorBeatmap . HitObjects . Count = = 1 ) ;
2022-10-25 10:43:23 +08:00
AddStep ( "clone" , ( ) = > Editor . Clone ( ) ) ;
2022-10-25 10:38:58 +08:00
AddAssert ( "still one object" , ( ) = > EditorBeatmap . HitObjects . Count = = 1 ) ;
}
2020-09-14 14:27:16 +08:00
}
}