1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-05 10:33:22 +08:00

Add MoveXCommand and MoveYCommand

This commit is contained in:
Marvin Schürz 2024-10-08 21:22:05 +02:00
parent c50adc80b0
commit 1d953e0e6f
5 changed files with 87 additions and 1 deletions

View File

@ -8,7 +8,7 @@ namespace osu.Game.Rulesets.Objects.Types
/// <summary>
/// A HitObject that has a starting position that can be mutated.
/// </summary>
public interface IHasMutablePosition : IHasPosition
public interface IHasMutablePosition : IHasPosition, IHasMutableXPosition, IHasMutableYPosition
{
/// <summary>
/// The starting position of the HitObject.

View File

@ -0,0 +1,16 @@
// 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.
namespace osu.Game.Rulesets.Objects.Types
{
/// <summary>
/// A HitObject that has a starting X-position that can be mutated.
/// </summary>
public interface IHasMutableXPosition : IHasXPosition
{
/// <summary>
/// The starting X-position of this HitObject.
/// </summary>
new float X { get; set; }
}
}

View File

@ -0,0 +1,16 @@
// 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.
namespace osu.Game.Rulesets.Objects.Types
{
/// <summary>
/// A HitObject that has a starting Y-position that can be mutated.
/// </summary>
public interface IHasMutableYPosition : IHasYPosition
{
/// <summary>
/// The starting Y-position of this HitObject.
/// </summary>
new float Y { get; set; }
}
}

View File

@ -0,0 +1,27 @@
// 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 osu.Framework.Utils;
using osu.Game.Rulesets.Objects.Types;
namespace osu.Game.Screens.Edit.Commands
{
public class MoveXCommand : IEditorCommand
{
public readonly IHasMutablePosition Target;
public readonly float X;
public MoveXCommand(IHasMutablePosition target, float x)
{
Target = target;
X = x;
}
public void Apply() => Target.X = X;
public IEditorCommand CreateUndo() => new MoveXCommand(Target, Target.X);
public bool IsRedundant => Precision.AlmostEquals(X, Target.X);
}
}

View File

@ -0,0 +1,27 @@
// 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 osu.Framework.Utils;
using osu.Game.Rulesets.Objects.Types;
namespace osu.Game.Screens.Edit.Commands
{
public class MoveYCommand : IEditorCommand
{
public readonly IHasMutablePosition Target;
public readonly float Y;
public MoveYCommand(IHasMutablePosition target, float y)
{
Target = target;
Y = y;
}
public void Apply() => Target.Y = Y;
public IEditorCommand CreateUndo() => new MoveXCommand(Target, Target.Y);
public bool IsRedundant => Precision.AlmostEquals(Y, Target.Y);
}
}