1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-05 09:42:54 +08:00
This commit is contained in:
OliBomby 2024-10-18 00:14:27 +02:00
parent 0ac520dec8
commit cb5be12f47
9 changed files with 26 additions and 15 deletions

View File

@ -5,7 +5,7 @@ using osu.Game.Rulesets.Objects;
namespace osu.Game.Screens.Edit.Changes
{
public class AddHitObjectChange : IRevertableChange
public class AddHitObjectChange : IRevertibleChange
{
public EditorBeatmap Beatmap;

View File

@ -6,7 +6,7 @@ namespace osu.Game.Screens.Edit.Changes
/// <summary>
/// Represents a change which can be undone.
/// </summary>
public interface IRevertableChange
public interface IRevertibleChange
{
/// <summary>
/// Applies this change to the current state.
@ -18,4 +18,15 @@ namespace osu.Game.Screens.Edit.Changes
/// </summary>
void Revert();
}
public static class IRevertibleChangeExtension
{
public static void Submit(this IRevertibleChange change, NewBeatmapEditorChangeHandler? changeHandler, bool commitImmediately = false)
{
if (changeHandler != null)
changeHandler.Submit(change, commitImmediately);
else
change.Apply();
}
}
}

View File

@ -6,7 +6,7 @@ using osu.Game.Rulesets.Objects;
namespace osu.Game.Screens.Edit.Changes
{
public class InsertPathControlPointChange : IRevertableChange
public class InsertPathControlPointChange : IRevertibleChange
{
public readonly IList<PathControlPoint> Target;

View File

@ -8,7 +8,7 @@ namespace osu.Game.Screens.Edit.Changes
/// </summary>
/// <typeparam name="TTarget">Type of the object owning the property</typeparam>
/// <typeparam name="TValue">Type of the property to update</typeparam>
public abstract class PropertyChange<TTarget, TValue> : IRevertableChange where TTarget : class
public abstract class PropertyChange<TTarget, TValue> : IRevertibleChange where TTarget : class
{
/// <summary>
/// Reads the current value of the property from the target.

View File

@ -9,7 +9,7 @@ namespace osu.Game.Screens.Edit.Changes
/// Queues the update of a <see cref="HitObject"/> in an <see cref="EditorBeatmap"/> for undo/redo.
/// The order of the updates in the transaction does not matter, because the updates are aggregated and applied on the next frame.
/// </summary>
public class QueueUpdateHitObject : IRevertableChange
public class QueueUpdateHitObject : IRevertibleChange
{
public EditorBeatmap? Beatmap;

View File

@ -5,7 +5,7 @@ using osu.Game.Rulesets.Objects;
namespace osu.Game.Screens.Edit.Changes
{
public class RemoveHitObjectChange : IRevertableChange
public class RemoveHitObjectChange : IRevertibleChange
{
public EditorBeatmap Beatmap;

View File

@ -6,7 +6,7 @@ using osu.Game.Rulesets.Objects;
namespace osu.Game.Screens.Edit.Changes
{
public class RemovePathControlPointChange : IRevertableChange
public class RemovePathControlPointChange : IRevertibleChange
{
public readonly IList<PathControlPoint> Target;

View File

@ -42,7 +42,7 @@ namespace osu.Game.Screens.Edit
/// </summary>
/// <param name="change">Change to be applied.</param>
/// <param name="commitImmediately">Whether to commit the current transaction and push it onto the undo stack immediately.</param>
public void Submit(IRevertableChange change, bool commitImmediately = false)
public void Submit(IRevertibleChange change, bool commitImmediately = false)
{
change.Apply();
record(change);
@ -56,7 +56,7 @@ namespace osu.Game.Screens.Edit
/// </summary>
/// <param name="changes">Changes to be applied.</param>
/// <param name="commitImmediately">Whether to commit the current transaction and push it onto the undo stack immediately.</param>
public void Submit(IEnumerable<IRevertableChange> changes, bool commitImmediately = false)
public void Submit(IEnumerable<IRevertibleChange> changes, bool commitImmediately = false)
{
foreach (var change in changes)
Submit(change);
@ -156,7 +156,7 @@ namespace osu.Game.Screens.Edit
CanRedo.Value = redoStack.Count > 0;
}
private void record(IRevertableChange change)
private void record(IRevertibleChange change)
{
currentTransaction.Add(change);
}
@ -165,18 +165,18 @@ namespace osu.Game.Screens.Edit
{
public Transaction()
{
undoChanges = new List<IRevertableChange>();
undoChanges = new List<IRevertibleChange>();
}
private readonly List<IRevertableChange> undoChanges;
private readonly List<IRevertibleChange> undoChanges;
/// <summary>
/// The changes to undo the given transaction.
/// Stored in reverse order of original changes to match execution order when undoing.
/// </summary>
public IReadOnlyList<IRevertableChange> UndoChanges => undoChanges;
public IReadOnlyList<IRevertibleChange> UndoChanges => undoChanges;
public void Add(IRevertableChange change)
public void Add(IRevertibleChange change)
{
undoChanges.Add(change);
}

View File

@ -7,7 +7,7 @@ namespace osu.Game.Screens.Edit
{
public static class NewBeatmapEditorChangeHandlerExtension
{
public static void SafeSubmit(this NewBeatmapEditorChangeHandler? manager, IRevertableChange command, bool commitImmediately = false)
public static void SafeSubmit(this NewBeatmapEditorChangeHandler? manager, IRevertibleChange command, bool commitImmediately = false)
{
if (manager != null)
manager.Submit(command, commitImmediately);