mirror of
https://github.com/ppy/osu.git
synced 2024-12-05 10:33:22 +08:00
Update more commands to extends PropertyChangeCommand
This commit is contained in:
parent
be90c47614
commit
5518db962f
@ -51,7 +51,9 @@ namespace osu.Game.Screens.Edit.Commands
|
||||
|
||||
public IEditorCommand CreateUndo() => CreateInstance(Target, ReadValue(Target));
|
||||
|
||||
public bool IsRedundant => EqualityComparer<TValue>.Default.Equals(Value, ReadValue(Target));
|
||||
public bool IsRedundant => ValueEquals(Value, ReadValue(Target));
|
||||
|
||||
protected virtual bool ValueEquals(TValue a, TValue b) => EqualityComparer<TValue>.Default.Equals(a, b);
|
||||
|
||||
public IEditorCommand? MergeWith(IEditorCommand previous)
|
||||
{
|
||||
|
@ -1,6 +1,7 @@
|
||||
// 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;
|
||||
|
||||
namespace osu.Game.Screens.Edit.Commands
|
||||
@ -17,5 +18,7 @@ namespace osu.Game.Screens.Edit.Commands
|
||||
protected override void WriteValue(SliderPath target, double? value) => target.ExpectedDistance.Value = value;
|
||||
|
||||
protected override SetExpectedDistanceCommand CreateInstance(SliderPath target, double? value) => new SetExpectedDistanceCommand(target, value);
|
||||
|
||||
protected override bool ValueEquals(double? a, double? b) => a != null && b != null ? Precision.AlmostEquals(a.Value, b.Value) : a == b;
|
||||
}
|
||||
}
|
||||
|
@ -1,30 +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.Framework.Utils;
|
||||
using osu.Game.Rulesets.Objects.Types;
|
||||
|
||||
namespace osu.Game.Screens.Edit.Commands
|
||||
{
|
||||
public class SetSliderVelocityMultiplierCommand : IEditorCommand
|
||||
public class SetSliderVelocityMultiplierCommand : PropertyChangeCommand<IHasSliderVelocity, double>
|
||||
{
|
||||
public readonly IHasSliderVelocity Target;
|
||||
|
||||
public readonly double SliderVelocityMultiplier;
|
||||
|
||||
public SetSliderVelocityMultiplierCommand(IHasSliderVelocity target, double sliderVelocityMultiplier)
|
||||
public SetSliderVelocityMultiplierCommand(IHasSliderVelocity target, double value)
|
||||
: base(target, value)
|
||||
{
|
||||
Target = target;
|
||||
SliderVelocityMultiplier = sliderVelocityMultiplier;
|
||||
}
|
||||
|
||||
public void Apply()
|
||||
{
|
||||
Target.SliderVelocityMultiplier = SliderVelocityMultiplier;
|
||||
}
|
||||
protected override double ReadValue(IHasSliderVelocity target) => target.SliderVelocityMultiplier;
|
||||
|
||||
public IEditorCommand CreateUndo()
|
||||
{
|
||||
return new SetSliderVelocityMultiplierCommand(Target, Target.SliderVelocityMultiplier);
|
||||
}
|
||||
protected override void WriteValue(IHasSliderVelocity target, double value) => target.SliderVelocityMultiplier = value;
|
||||
|
||||
protected override SetSliderVelocityMultiplierCommand CreateInstance(IHasSliderVelocity target, double value) => new SetSliderVelocityMultiplierCommand(target, value);
|
||||
|
||||
protected override bool ValueEquals(double a, double b) => Precision.AlmostEquals(a, b);
|
||||
}
|
||||
}
|
||||
|
@ -1,27 +1,21 @@
|
||||
// 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;
|
||||
|
||||
namespace osu.Game.Screens.Edit.Commands
|
||||
{
|
||||
public class SetStartTimeCommand : IEditorCommand
|
||||
public class SetStartTimeCommand : PropertyChangeCommand<HitObject, double>
|
||||
{
|
||||
public readonly HitObject Target;
|
||||
|
||||
public readonly double StartTime;
|
||||
|
||||
public SetStartTimeCommand(HitObject target, double startTime)
|
||||
public SetStartTimeCommand(HitObject target, double value)
|
||||
: base(target, value)
|
||||
{
|
||||
Target = target;
|
||||
StartTime = startTime;
|
||||
}
|
||||
|
||||
public void Apply() => Target.StartTime = StartTime;
|
||||
protected override double ReadValue(HitObject target) => target.StartTime;
|
||||
|
||||
public IEditorCommand CreateUndo() => new SetStartTimeCommand(Target, Target.StartTime);
|
||||
protected override void WriteValue(HitObject target, double value) => target.StartTime = value;
|
||||
|
||||
public bool IsRedundant => Precision.AlmostEquals(StartTime, Target.StartTime);
|
||||
protected override SetStartTimeCommand CreateInstance(HitObject target, double value) => new SetStartTimeCommand(target, value);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user