<commit_before>// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Linq;
using Humanizer;
using NUnit.Framework;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Osu.Edit.Blueprints.HitCircles.Components;
using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders;
using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Tests.Visual;
using osuTK;
using osuTK.Input;

namespace osu.Game.Rulesets.Osu.Tests.Editor
{
    public class TestSceneSliderControlPointPiece : SelectionBlueprintTestScene
    {
        private Slider slider;
        private DrawableSlider drawableObject;

        [SetUp]
        public void Setup() => Schedule(() =>
        {
            Clear();

            slider = new Slider
            {
                Position = new Vector2(256, 192),
                Path = new SliderPath(new[]
                {
                    new PathControlPoint(Vector2.Zero, PathType.PerfectCurve),
                    new PathControlPoint(new Vector2(150, 150)),
                    new PathControlPoint(new Vector2(300, 0), PathType.PerfectCurve),
                    new PathControlPoint(new Vector2(400, 0)),
                    new PathControlPoint(new Vector2(400, 150))
                })
            };

            slider.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty { CircleSize = 2 });

            Add(drawableObject = new DrawableSlider(slider));
            AddBlueprint(new TestSliderBlueprint(slider), drawableObject);
        });

        [Test]
        public void TestSelection()
        {
            moveMouseToControlPoint(0);
            AddStep("click left mouse", () => InputManager.Click(MouseButton.Left));
            assertSelectionCount(1);
            assertSelected(0);

            AddStep("click right mouse", () => InputManager.Click(MouseButton.Right));
            assertSelectionCount(1);
            assertSelected(0);

            moveMouseToControlPoint(3);
            AddStep("click left mouse", () => InputManager.Click(MouseButton.Left));
            assertSelectionCount(1);
            assertSelected(3);

            AddStep("press control", () => InputManager.PressKey(Key.ControlLeft));
            moveMouseToControlPoint(2);
            AddStep("click left mouse", () => InputManager.Click(MouseButton.Left));
            assertSelectionCount(2);
            assertSelected(2);
            assertSelected(3);

            moveMouseToControlPoint(0);
            AddStep("click left mouse", () => InputManager.Click(MouseButton.Left));
            assertSelectionCount(3);
            assertSelected(0);
            assertSelected(2);
            assertSelected(3);

            AddStep("click right mouse", () => InputManager.Click(MouseButton.Right));
            assertSelectionCount(3);
            assertSelected(0);
            assertSelected(2);
            assertSelected(3);

            AddStep("release control", () => InputManager.ReleaseKey(Key.ControlLeft));
            AddStep("click left mouse", () => InputManager.Click(MouseButton.Left));
            assertSelectionCount(1);
            assertSelected(0);

            AddStep("move mouse to new point position", () =>
            {
                Vector2 position = slider.Position + (slider.Path.ControlPoints[2].Position + slider.Path.ControlPoints[3].Position) / 2;
                InputManager.MoveMouseTo(drawableObject.Parent.ToScreenSpace(position));
            });
            AddStep("ctrl+click to create new point", () =>
            {
                InputManager.PressKey(Key.ControlLeft);
                InputManager.Click(MouseButton.Left);
                InputManager.ReleaseKey(Key.ControlLeft);
            });
            AddAssert("slider has 6 control points", () => slider.Path.ControlPoints.Count == 6);
            assertSelectionCount(1);
            assertSelected(3);

            void assertSelectionCount(int count) =>
                AddAssert($"{count} control point pieces selected", () => this.ChildrenOfType<PathControlPointPiece>().Count(piece => piece.IsSelected.Value) == count);

            void assertSelected(int index) =>
                AddAssert($"{(index + 1).ToOrdinalWords()} control point piece selected",
                    () => this.ChildrenOfType<PathControlPointPiece>().Single(piece => piece.ControlPoint == slider.Path.ControlPoints[index]).IsSelected.Value);
        }

        [Test]
        public void TestDragControlPoint()<commit_msg>Rewrite test to check selection state during and after new control point placement<commit_after>// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Linq;
using Humanizer;
using NUnit.Framework;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Osu.Edit.Blueprints.HitCircles.Components;
using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders;
using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Tests.Visual;
using osuTK;
using osuTK.Input;

namespace osu.Game.Rulesets.Osu.Tests.Editor
{
    public class TestSceneSliderControlPointPiece : SelectionBlueprintTestScene
    {
        private Slider slider;
        private DrawableSlider drawableObject;

        [SetUp]
        public void Setup() => Schedule(() =>
        {
            Clear();

            slider = new Slider
            {
                Position = new Vector2(256, 192),
                Path = new SliderPath(new[]
                {
                    new PathControlPoint(Vector2.Zero, PathType.PerfectCurve),
                    new PathControlPoint(new Vector2(150, 150)),
                    new PathControlPoint(new Vector2(300, 0), PathType.PerfectCurve),
                    new PathControlPoint(new Vector2(400, 0)),
                    new PathControlPoint(new Vector2(400, 150))
                })
            };

            slider.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty { CircleSize = 2 });

            Add(drawableObject = new DrawableSlider(slider));
            AddBlueprint(new TestSliderBlueprint(slider), drawableObject);
        });

        [Test]
        public void TestSelection()
        {
            moveMouseToControlPoint(0);
            AddStep("click left mouse", () => InputManager.Click(MouseButton.Left));
            assertSelectionCount(1);
            assertSelected(0);

            AddStep("click right mouse", () => InputManager.Click(MouseButton.Right));
            assertSelectionCount(1);
            assertSelected(0);

            moveMouseToControlPoint(3);
            AddStep("click left mouse", () => InputManager.Click(MouseButton.Left));
            assertSelectionCount(1);
            assertSelected(3);

            AddStep("press control", () => InputManager.PressKey(Key.ControlLeft));
            moveMouseToControlPoint(2);
            AddStep("click left mouse", () => InputManager.Click(MouseButton.Left));
            assertSelectionCount(2);
            assertSelected(2);
            assertSelected(3);

            moveMouseToControlPoint(0);
            AddStep("click left mouse", () => InputManager.Click(MouseButton.Left));
            assertSelectionCount(3);
            assertSelected(0);
            assertSelected(2);
            assertSelected(3);

            AddStep("click right mouse", () => InputManager.Click(MouseButton.Right));
            assertSelectionCount(3);
            assertSelected(0);
            assertSelected(2);
            assertSelected(3);

            AddStep("release control", () => InputManager.ReleaseKey(Key.ControlLeft));
            AddStep("click left mouse", () => InputManager.Click(MouseButton.Left));
            assertSelectionCount(1);
            assertSelected(0);

            AddStep("move mouse to new point position", () =>
            {
                Vector2 position = slider.Position + (slider.Path.ControlPoints[2].Position + slider.Path.ControlPoints[3].Position) / 2;
                InputManager.MoveMouseTo(drawableObject.Parent.ToScreenSpace(position));
            });
            AddStep("ctrl+click to create new point", () =>
            {
                InputManager.PressKey(Key.ControlLeft);
                InputManager.PressButton(MouseButton.Left);
            });
            AddAssert("slider has 6 control points", () => slider.Path.ControlPoints.Count == 6);
            assertSelectionCount(1);
            assertSelected(3);

            AddStep("release ctrl+click", () =>
            {
                InputManager.ReleaseButton(MouseButton.Left);
                InputManager.ReleaseKey(Key.ControlLeft);
            });
            assertSelectionCount(1);
            assertSelected(3);

            void assertSelectionCount(int count) =>
                AddAssert($"{count} control point pieces selected", () => this.ChildrenOfType<PathControlPointPiece>().Count(piece => piece.IsSelected.Value) == count);

            void assertSelected(int index) =>
                AddAssert($"{(index + 1).ToOrdinalWords()} control point piece selected",
                    () => this.ChildrenOfType<PathControlPointPiece>().Single(piece => piece.ControlPoint == slider.Path.ControlPoints[index]).IsSelected.Value);
        }

        [Test]
        public void TestDragControlPoint()
{'fraction_non_alphanumeric': 0.1124546553808948, 'fraction_numerical': 0.013301088270858524, 'mean_word_length': 2.342876389356686, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6962156', 'n_tokens_mistral': 2662, 'n_tokens_neox': 2521, 'n_words': 488}