mirror of https://github.com/ppy/osu
Add event on EditorChangeHandler state change
This commit is contained in:
parent
e2934dff0e
commit
0cb3926e1d
|
@ -12,6 +12,14 @@ namespace osu.Game.Tests.Editing
|
|||
[TestFixture]
|
||||
public class EditorChangeHandlerTest
|
||||
{
|
||||
private int stateChangedFired;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
stateChangedFired = 0;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSaveRestoreState()
|
||||
{
|
||||
|
@ -23,6 +31,8 @@ public void TestSaveRestoreState()
|
|||
addArbitraryChange(beatmap);
|
||||
handler.SaveState();
|
||||
|
||||
Assert.That(stateChangedFired, Is.EqualTo(1));
|
||||
|
||||
Assert.That(handler.CanUndo.Value, Is.True);
|
||||
Assert.That(handler.CanRedo.Value, Is.False);
|
||||
|
||||
|
@ -30,6 +40,8 @@ public void TestSaveRestoreState()
|
|||
|
||||
Assert.That(handler.CanUndo.Value, Is.False);
|
||||
Assert.That(handler.CanRedo.Value, Is.True);
|
||||
|
||||
Assert.That(stateChangedFired, Is.EqualTo(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -45,6 +57,7 @@ public void TestSaveSameStateDoesNotSave()
|
|||
|
||||
Assert.That(handler.CanUndo.Value, Is.True);
|
||||
Assert.That(handler.CanRedo.Value, Is.False);
|
||||
Assert.That(stateChangedFired, Is.EqualTo(1));
|
||||
|
||||
string hash = handler.CurrentStateHash;
|
||||
|
||||
|
@ -52,6 +65,7 @@ public void TestSaveSameStateDoesNotSave()
|
|||
handler.SaveState();
|
||||
|
||||
Assert.That(hash, Is.EqualTo(handler.CurrentStateHash));
|
||||
Assert.That(stateChangedFired, Is.EqualTo(1));
|
||||
|
||||
handler.RestoreState(-1);
|
||||
|
||||
|
@ -60,6 +74,7 @@ public void TestSaveSameStateDoesNotSave()
|
|||
// we should only be able to restore once even though we saved twice.
|
||||
Assert.That(handler.CanUndo.Value, Is.False);
|
||||
Assert.That(handler.CanRedo.Value, Is.True);
|
||||
Assert.That(stateChangedFired, Is.EqualTo(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -71,6 +86,8 @@ public void TestMaxStatesSaved()
|
|||
|
||||
for (int i = 0; i < EditorChangeHandler.MAX_SAVED_STATES; i++)
|
||||
{
|
||||
Assert.That(stateChangedFired, Is.EqualTo(i));
|
||||
|
||||
addArbitraryChange(beatmap);
|
||||
handler.SaveState();
|
||||
}
|
||||
|
@ -114,7 +131,10 @@ public void TestMaxStatesExceeded()
|
|||
{
|
||||
var beatmap = new EditorBeatmap(new Beatmap());
|
||||
|
||||
return (new EditorChangeHandler(beatmap), beatmap);
|
||||
var changeHandler = new EditorChangeHandler(beatmap);
|
||||
|
||||
changeHandler.OnStateChange += () => stateChangedFired++;
|
||||
return (changeHandler, beatmap);
|
||||
}
|
||||
|
||||
private void addArbitraryChange(EditorBeatmap beatmap)
|
||||
|
|
|
@ -21,6 +21,8 @@ public class EditorChangeHandler : IEditorChangeHandler
|
|||
public readonly Bindable<bool> CanUndo = new Bindable<bool>();
|
||||
public readonly Bindable<bool> CanRedo = new Bindable<bool>();
|
||||
|
||||
public event Action OnStateChange;
|
||||
|
||||
private readonly LegacyEditorBeatmapPatcher patcher;
|
||||
private readonly List<byte[]> savedStates = new List<byte[]>();
|
||||
|
||||
|
@ -109,6 +111,8 @@ public void SaveState()
|
|||
savedStates.Add(newState);
|
||||
|
||||
currentState = savedStates.Count - 1;
|
||||
|
||||
OnStateChange?.Invoke();
|
||||
updateBindables();
|
||||
}
|
||||
}
|
||||
|
@ -136,6 +140,7 @@ public void RestoreState(int direction)
|
|||
|
||||
isRestoring = false;
|
||||
|
||||
OnStateChange?.Invoke();
|
||||
updateBindables();
|
||||
}
|
||||
|
||||
|
|
|
@ -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 System;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
|
||||
namespace osu.Game.Screens.Edit
|
||||
|
@ -10,6 +11,11 @@ namespace osu.Game.Screens.Edit
|
|||
/// </summary>
|
||||
public interface IEditorChangeHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Fired whenever a state change occurs.
|
||||
/// </summary>
|
||||
public event Action OnStateChange;
|
||||
|
||||
/// <summary>
|
||||
/// Begins a bulk state change event. <see cref="EndChange"/> should be invoked soon after.
|
||||
/// </summary>
|
||||
|
|
Loading…
Reference in New Issue