-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
173 additions
and
2 deletions.
There are no files selected for viewing
168 changes: 168 additions & 0 deletions
168
osu.Game.Tests/Editing/TestSceneHitObjectContainerEventQueue.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
// 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 NUnit.Framework; | ||
using osu.Framework.Graphics; | ||
using osu.Game.Rulesets.Objects; | ||
using osu.Game.Rulesets.Objects.Drawables; | ||
using osu.Game.Rulesets.UI; | ||
using osu.Game.Screens.Edit.Compose; | ||
using osu.Game.Tests.Visual; | ||
|
||
namespace osu.Game.Tests.Editing | ||
{ | ||
public class TestSceneHitObjectContainerEventQueue : OsuTestScene | ||
{ | ||
private readonly TestHitObject testObj = new TestHitObject(); | ||
|
||
private TestPlayfield playfield1; | ||
private TestPlayfield playfield2; | ||
private TestDrawable intermediateDrawable; | ||
private HitObjectContainerEventQueue eventQueue; | ||
|
||
private HitObject beganUsage; | ||
private HitObject finishedUsage; | ||
private HitObject transferredUsage; | ||
|
||
[SetUp] | ||
public void Setup() => Schedule(() => | ||
{ | ||
reset(); | ||
|
||
if (eventQueue != null) | ||
{ | ||
eventQueue.HitObjectUsageBegan -= onHitObjectUsageBegan; | ||
eventQueue.HitObjectUsageFinished -= onHitObjectUsageFinished; | ||
eventQueue.HitObjectUsageTransferred -= onHitObjectUsageTransferred; | ||
} | ||
|
||
var topPlayfield = new TestPlayfield(); | ||
topPlayfield.AddNested(playfield1 = new TestPlayfield()); | ||
topPlayfield.AddNested(playfield2 = new TestPlayfield()); | ||
|
||
eventQueue = new HitObjectContainerEventQueue(topPlayfield); | ||
eventQueue.HitObjectUsageBegan += onHitObjectUsageBegan; | ||
eventQueue.HitObjectUsageFinished += onHitObjectUsageFinished; | ||
eventQueue.HitObjectUsageTransferred += onHitObjectUsageTransferred; | ||
|
||
Children = new Drawable[] | ||
{ | ||
topPlayfield, | ||
intermediateDrawable = new TestDrawable(), | ||
eventQueue | ||
}; | ||
}); | ||
|
||
private void onHitObjectUsageBegan(HitObject obj) => beganUsage = obj; | ||
|
||
private void onHitObjectUsageFinished(HitObject obj) => finishedUsage = obj; | ||
|
||
private void onHitObjectUsageTransferred(HitObject obj, DrawableHitObject drawableObj) => transferredUsage = obj; | ||
|
||
[Test] | ||
public void TestUsageBeganAfterAdd() | ||
{ | ||
AddStep("add hitobject", () => playfield1.Add(testObj)); | ||
addCheckStep(began: true); | ||
} | ||
|
||
[Test] | ||
public void TestUsageFinishedAfterRemove() | ||
{ | ||
AddStep("add hitobject", () => playfield1.Add(testObj)); | ||
addResetStep(); | ||
AddStep("remove hitobject", () => playfield1.Remove(testObj)); | ||
addCheckStep(finished: true); | ||
} | ||
|
||
[Test] | ||
public void TestUsageTransferredWhenMovedBetweenPlayfields() | ||
{ | ||
AddStep("add hitobject", () => playfield1.Add(testObj)); | ||
addResetStep(); | ||
AddStep("transfer hitobject to other playfield", () => | ||
{ | ||
playfield1.Remove(testObj); | ||
playfield2.Add(testObj); | ||
}); | ||
|
||
addCheckStep(transferred: true); | ||
} | ||
|
||
[Test] | ||
public void TestRemoveImmediatelyAfterUsageBegan() | ||
{ | ||
AddStep("add hitobject and schedule removal", () => | ||
{ | ||
playfield1.Add(testObj); | ||
intermediateDrawable.Schedule(() => playfield1.Remove(testObj)); | ||
}); | ||
|
||
addCheckStep(); | ||
} | ||
|
||
[Test] | ||
public void TestRemoveImmediatelyAfterTransferred() | ||
{ | ||
AddStep("add hitobject", () => playfield1.Add(testObj)); | ||
addResetStep(); | ||
AddStep("transfer hitobject to other playfield and schedule removal", () => | ||
{ | ||
playfield1.Remove(testObj); | ||
playfield2.Add(testObj); | ||
intermediateDrawable.Schedule(() => playfield2.Remove(testObj)); | ||
}); | ||
|
||
addCheckStep(finished: true); | ||
} | ||
|
||
private void addResetStep() => AddStep("reset", reset); | ||
|
||
private void reset() | ||
{ | ||
beganUsage = null; | ||
finishedUsage = null; | ||
transferredUsage = null; | ||
} | ||
|
||
private void addCheckStep(bool began = false, bool finished = false, bool transferred = false) | ||
=> AddAssert($"began = {began}, finished = {finished}, transferred = {transferred}", | ||
() => (beganUsage == testObj) == began && (finishedUsage == testObj) == finished && (transferredUsage == testObj) == transferred); | ||
|
||
private class TestPlayfield : Playfield | ||
{ | ||
public TestPlayfield() | ||
{ | ||
RegisterPool<TestHitObject, TestDrawableHitObject>(1); | ||
} | ||
|
||
public new void AddNested(Playfield playfield) | ||
{ | ||
AddInternal(playfield); | ||
base.AddNested(playfield); | ||
} | ||
|
||
protected override HitObjectLifetimeEntry CreateLifetimeEntry(HitObject hitObject) | ||
{ | ||
var entry = base.CreateLifetimeEntry(hitObject); | ||
entry.KeepAlive = true; | ||
return entry; | ||
} | ||
} | ||
|
||
private class TestHitObject : HitObject | ||
{ | ||
public override string ToString() => "TestHitObject"; | ||
} | ||
|
||
private class TestDrawableHitObject : DrawableHitObject | ||
{ | ||
} | ||
|
||
private class TestDrawable : Drawable | ||
{ | ||
public new void Schedule(Action action) => base.Schedule(action); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters