2020-04-09 20:56:36 +08:00
|
|
|
// 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 NUnit.Framework;
|
2020-06-04 05:47:10 +08:00
|
|
|
using osu.Game.Rulesets;
|
2020-04-09 20:56:36 +08:00
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
using osu.Game.Rulesets.Osu;
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
|
|
|
|
2020-04-23 16:07:55 +08:00
|
|
|
namespace osu.Game.Tests.Visual.Editing
|
2020-04-09 20:56:36 +08:00
|
|
|
{
|
2020-04-22 18:49:21 +08:00
|
|
|
public class TestSceneEditorChangeStates : EditorTestScene
|
2020-04-09 20:56:36 +08:00
|
|
|
{
|
2020-06-04 05:47:10 +08:00
|
|
|
protected override Ruleset CreateEditorRuleset() => new OsuRuleset();
|
|
|
|
|
2020-09-11 19:27:04 +08:00
|
|
|
[Test]
|
|
|
|
public void TestSelectedObjects()
|
|
|
|
{
|
|
|
|
HitCircle obj = null;
|
2020-09-14 14:27:08 +08:00
|
|
|
AddStep("add hitobject", () => EditorBeatmap.Add(obj = new HitCircle { StartTime = 1000 }));
|
|
|
|
AddStep("select hitobject", () => EditorBeatmap.SelectedHitObjects.Add(obj));
|
|
|
|
AddAssert("confirm 1 selected", () => EditorBeatmap.SelectedHitObjects.Count == 1);
|
|
|
|
AddStep("deselect hitobject", () => EditorBeatmap.SelectedHitObjects.Remove(obj));
|
|
|
|
AddAssert("confirm 0 selected", () => EditorBeatmap.SelectedHitObjects.Count == 0);
|
2020-09-11 19:27:04 +08:00
|
|
|
}
|
|
|
|
|
2020-04-09 20:56:36 +08:00
|
|
|
[Test]
|
|
|
|
public void TestUndoFromInitialState()
|
|
|
|
{
|
|
|
|
int hitObjectCount = 0;
|
|
|
|
|
2020-09-14 14:27:08 +08:00
|
|
|
AddStep("get initial state", () => hitObjectCount = EditorBeatmap.HitObjects.Count);
|
2020-04-09 20:56:36 +08:00
|
|
|
|
|
|
|
addUndoSteps();
|
|
|
|
|
2020-09-14 14:27:08 +08:00
|
|
|
AddAssert("no change occurred", () => hitObjectCount == EditorBeatmap.HitObjects.Count);
|
2020-09-09 18:57:28 +08:00
|
|
|
AddAssert("no unsaved changes", () => !Editor.HasUnsavedChanges);
|
2020-04-09 20:56:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestRedoFromInitialState()
|
|
|
|
{
|
|
|
|
int hitObjectCount = 0;
|
|
|
|
|
2020-09-14 14:27:08 +08:00
|
|
|
AddStep("get initial state", () => hitObjectCount = EditorBeatmap.HitObjects.Count);
|
2020-04-09 20:56:36 +08:00
|
|
|
|
|
|
|
addRedoSteps();
|
|
|
|
|
2020-09-14 14:27:08 +08:00
|
|
|
AddAssert("no change occurred", () => hitObjectCount == EditorBeatmap.HitObjects.Count);
|
2020-09-09 18:57:28 +08:00
|
|
|
AddAssert("no unsaved changes", () => !Editor.HasUnsavedChanges);
|
2020-04-09 20:56:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestAddObjectAndUndo()
|
|
|
|
{
|
|
|
|
HitObject addedObject = null;
|
|
|
|
HitObject removedObject = null;
|
|
|
|
HitObject expectedObject = null;
|
|
|
|
|
|
|
|
AddStep("bind removal", () =>
|
|
|
|
{
|
2020-09-14 14:27:08 +08:00
|
|
|
EditorBeatmap.HitObjectAdded += h => addedObject = h;
|
|
|
|
EditorBeatmap.HitObjectRemoved += h => removedObject = h;
|
2020-04-09 20:56:36 +08:00
|
|
|
});
|
|
|
|
|
2020-09-14 14:27:08 +08:00
|
|
|
AddStep("add hitobject", () => EditorBeatmap.Add(expectedObject = new HitCircle { StartTime = 1000 }));
|
2020-04-09 20:56:36 +08:00
|
|
|
AddAssert("hitobject added", () => addedObject == expectedObject);
|
2020-09-09 18:57:28 +08:00
|
|
|
AddAssert("unsaved changes", () => Editor.HasUnsavedChanges);
|
2020-04-09 20:56:36 +08:00
|
|
|
|
|
|
|
addUndoSteps();
|
|
|
|
AddAssert("hitobject removed", () => removedObject == expectedObject);
|
2020-09-09 18:57:28 +08:00
|
|
|
AddAssert("no unsaved changes", () => !Editor.HasUnsavedChanges);
|
2020-04-09 20:56:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestAddObjectThenUndoThenRedo()
|
|
|
|
{
|
|
|
|
HitObject addedObject = null;
|
|
|
|
HitObject removedObject = null;
|
|
|
|
HitObject expectedObject = null;
|
|
|
|
|
|
|
|
AddStep("bind removal", () =>
|
|
|
|
{
|
2020-09-14 14:27:08 +08:00
|
|
|
EditorBeatmap.HitObjectAdded += h => addedObject = h;
|
|
|
|
EditorBeatmap.HitObjectRemoved += h => removedObject = h;
|
2020-04-09 20:56:36 +08:00
|
|
|
});
|
|
|
|
|
2020-09-14 14:27:08 +08:00
|
|
|
AddStep("add hitobject", () => EditorBeatmap.Add(expectedObject = new HitCircle { StartTime = 1000 }));
|
2020-04-09 20:56:36 +08:00
|
|
|
addUndoSteps();
|
|
|
|
|
|
|
|
AddStep("reset variables", () =>
|
|
|
|
{
|
|
|
|
addedObject = null;
|
|
|
|
removedObject = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
addRedoSteps();
|
|
|
|
AddAssert("hitobject added", () => addedObject.StartTime == expectedObject.StartTime); // Can't compare via equality (new hitobject instance)
|
|
|
|
AddAssert("no hitobject removed", () => removedObject == null);
|
2020-09-09 18:57:28 +08:00
|
|
|
AddAssert("unsaved changes", () => Editor.HasUnsavedChanges);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestAddObjectThenSaveHasNoUnsavedChanges()
|
|
|
|
{
|
2020-09-14 14:27:08 +08:00
|
|
|
AddStep("add hitobject", () => EditorBeatmap.Add(new HitCircle { StartTime = 1000 }));
|
2020-09-09 18:57:28 +08:00
|
|
|
|
|
|
|
AddAssert("unsaved changes", () => Editor.HasUnsavedChanges);
|
|
|
|
AddStep("save changes", () => Editor.Save());
|
|
|
|
AddAssert("no unsaved changes", () => !Editor.HasUnsavedChanges);
|
2020-04-09 20:56:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestRemoveObjectThenUndo()
|
|
|
|
{
|
|
|
|
HitObject addedObject = null;
|
|
|
|
HitObject removedObject = null;
|
|
|
|
HitObject expectedObject = null;
|
|
|
|
|
|
|
|
AddStep("bind removal", () =>
|
|
|
|
{
|
2020-09-14 14:27:08 +08:00
|
|
|
EditorBeatmap.HitObjectAdded += h => addedObject = h;
|
|
|
|
EditorBeatmap.HitObjectRemoved += h => removedObject = h;
|
2020-04-09 20:56:36 +08:00
|
|
|
});
|
|
|
|
|
2020-09-14 14:27:08 +08:00
|
|
|
AddStep("add hitobject", () => EditorBeatmap.Add(expectedObject = new HitCircle { StartTime = 1000 }));
|
|
|
|
AddStep("remove object", () => EditorBeatmap.Remove(expectedObject));
|
2020-04-09 20:56:36 +08:00
|
|
|
AddStep("reset variables", () =>
|
|
|
|
{
|
|
|
|
addedObject = null;
|
|
|
|
removedObject = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
addUndoSteps();
|
|
|
|
AddAssert("hitobject added", () => addedObject.StartTime == expectedObject.StartTime); // Can't compare via equality (new hitobject instance)
|
|
|
|
AddAssert("no hitobject removed", () => removedObject == null);
|
2020-09-09 18:57:28 +08:00
|
|
|
AddAssert("unsaved changes", () => Editor.HasUnsavedChanges); // 2 steps performed, 1 undone
|
2020-04-09 20:56:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestRemoveObjectThenUndoThenRedo()
|
|
|
|
{
|
|
|
|
HitObject addedObject = null;
|
|
|
|
HitObject removedObject = null;
|
|
|
|
HitObject expectedObject = null;
|
|
|
|
|
|
|
|
AddStep("bind removal", () =>
|
|
|
|
{
|
2020-09-14 14:27:08 +08:00
|
|
|
EditorBeatmap.HitObjectAdded += h => addedObject = h;
|
|
|
|
EditorBeatmap.HitObjectRemoved += h => removedObject = h;
|
2020-04-09 20:56:36 +08:00
|
|
|
});
|
|
|
|
|
2020-09-14 14:27:08 +08:00
|
|
|
AddStep("add hitobject", () => EditorBeatmap.Add(expectedObject = new HitCircle { StartTime = 1000 }));
|
|
|
|
AddStep("remove object", () => EditorBeatmap.Remove(expectedObject));
|
2020-04-09 20:56:36 +08:00
|
|
|
addUndoSteps();
|
|
|
|
|
|
|
|
AddStep("reset variables", () =>
|
|
|
|
{
|
|
|
|
addedObject = null;
|
|
|
|
removedObject = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
addRedoSteps();
|
|
|
|
AddAssert("hitobject removed", () => removedObject.StartTime == expectedObject.StartTime); // Can't compare via equality (new hitobject instance after undo)
|
|
|
|
AddAssert("no hitobject added", () => addedObject == null);
|
2020-09-09 18:57:28 +08:00
|
|
|
AddAssert("no changes", () => !Editor.HasUnsavedChanges); // end result is empty beatmap, matching original state
|
2020-04-09 20:56:36 +08:00
|
|
|
}
|
|
|
|
|
2020-09-09 18:57:28 +08:00
|
|
|
private void addUndoSteps() => AddStep("undo", () => Editor.Undo());
|
2020-04-09 20:56:36 +08:00
|
|
|
|
2020-09-09 18:57:28 +08:00
|
|
|
private void addRedoSteps() => AddStep("redo", () => Editor.Redo());
|
2020-04-09 20:56:36 +08:00
|
|
|
}
|
|
|
|
}
|