1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-07 23:03:21 +08:00

Add AddHitObjectCommand and RemoveHitObjectCommand

This commit is contained in:
Marvin Schürz 2024-10-08 20:29:27 +02:00
parent 867e986240
commit fe9e84b47d
3 changed files with 54 additions and 2 deletions

View File

@ -27,6 +27,7 @@ using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.UI;
using osu.Game.Rulesets.UI.Scrolling;
using osu.Game.Screens.Edit;
using osu.Game.Screens.Edit.Commands;
using osu.Game.Screens.Edit.Components.RadioButtons;
using osu.Game.Screens.Edit.Components.TernaryButtons;
using osu.Game.Screens.Edit.Compose;
@ -483,20 +484,23 @@ namespace osu.Game.Rulesets.Edit
EditorBeatmap.PlacementObject.Value = hitObject;
}
[Resolved(canBeNull: true)]
private EditorCommandHandler commandHandler { get; set; }
public void EndPlacement(HitObject hitObject, bool commit)
{
EditorBeatmap.PlacementObject.Value = null;
if (commit)
{
EditorBeatmap.Add(hitObject);
commandHandler.SafeSubmit(new AddHitObjectCommand(EditorBeatmap, hitObject), true);
if (autoSeekOnPlacement.Value && EditorClock.CurrentTime < hitObject.StartTime)
EditorClock.SeekSmoothlyTo(hitObject.StartTime);
}
}
public void Delete(HitObject hitObject) => EditorBeatmap.Remove(hitObject);
public void Delete(HitObject hitObject) => commandHandler.SafeSubmit(new RemoveHitObjectCommand(EditorBeatmap, hitObject));
#endregion

View File

@ -0,0 +1,24 @@
// 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.Game.Rulesets.Objects;
namespace osu.Game.Screens.Edit.Commands
{
public class AddHitObjectCommand : IEditorCommand
{
public EditorBeatmap Beatmap;
public HitObject HitObject;
public AddHitObjectCommand(EditorBeatmap beatmap, HitObject hitObject)
{
Beatmap = beatmap;
HitObject = hitObject;
}
public void Apply() => Beatmap.Add(HitObject);
public IEditorCommand CreateUndo() => new RemoveHitObjectCommand(Beatmap, HitObject);
}
}

View File

@ -0,0 +1,24 @@
// 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.Game.Rulesets.Objects;
namespace osu.Game.Screens.Edit.Commands
{
public class RemoveHitObjectCommand : IEditorCommand
{
public EditorBeatmap Beatmap;
public HitObject HitObject;
public RemoveHitObjectCommand(EditorBeatmap beatmap, HitObject hitObject)
{
Beatmap = beatmap;
HitObject = hitObject;
}
public void Apply() => Beatmap.Remove(HitObject);
public IEditorCommand CreateUndo() => new AddHitObjectCommand(Beatmap, HitObject);
}
}