Skip to content

Commit

Permalink
Resolve DroppedObjectContainer via DI
Browse files Browse the repository at this point in the history
  • Loading branch information
ekrctb committed Jun 24, 2021
1 parent 16d5893 commit ae09c23
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 34 deletions.
38 changes: 22 additions & 16 deletions osu.Game.Rulesets.Catch.Tests/TestSceneCatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Game.Rulesets.Catch.UI;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Catch.UI;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
using osu.Framework.Utils;
Expand All @@ -31,10 +31,23 @@ public class TestSceneCatcher : OsuTestScene
[Resolved]
private OsuConfigManager config { get; set; }

private DroppedObjectContainer droppedObjectContainer;
[Cached]
private readonly DroppedObjectContainer droppedObjectContainer;

private readonly Container trailContainer;

private TestCatcher catcher;

public TestSceneCatcher()
{
Add(trailContainer = new Container
{
Anchor = Anchor.Centre,
Depth = -1
});
Add(droppedObjectContainer = new DroppedObjectContainer());
}

[SetUp]
public void SetUp() => Schedule(() =>
{
Expand All @@ -43,20 +56,13 @@ public void SetUp() => Schedule(() =>
CircleSize = 0,
};

var trailContainer = new Container();
droppedObjectContainer = new DroppedObjectContainer();
catcher = new TestCatcher(trailContainer, droppedObjectContainer, difficulty);
if (catcher != null)
Remove(catcher);

Child = new Container
Add(catcher = new TestCatcher(trailContainer, difficulty)
{
Anchor = Anchor.Centre,
Children = new Drawable[]
{
trailContainer,
droppedObjectContainer,
catcher
}
};
Anchor = Anchor.Centre
});
});

[Test]
Expand Down Expand Up @@ -293,8 +299,8 @@ public class TestCatcher : Catcher
{
public IEnumerable<CaughtObject> CaughtObjects => this.ChildrenOfType<CaughtObject>();

public TestCatcher(Container trailsTarget, DroppedObjectContainer droppedObjectTarget, BeatmapDifficulty difficulty)
: base(trailsTarget, droppedObjectTarget, difficulty)
public TestCatcher(Container trailsTarget, BeatmapDifficulty difficulty)
: base(trailsTarget, difficulty)
{
}
}
Expand Down
13 changes: 7 additions & 6 deletions osu.Game.Rulesets.Catch.Tests/TestSceneCatcherArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,12 @@ private void createCatcher(float size)

SetContents(_ =>
{
var droppedObjectContainer = new DroppedObjectContainer();

return new CatchInputManager(catchRuleset)
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
droppedObjectContainer,
new TestCatcherArea(droppedObjectContainer, beatmapDifficulty)
new TestCatcherArea(beatmapDifficulty)
{
Anchor = Anchor.Centre,
Origin = Anchor.TopCentre,
Expand All @@ -122,9 +119,13 @@ private void load(RulesetStore rulesets)

private class TestCatcherArea : CatcherArea
{
public TestCatcherArea(DroppedObjectContainer droppedObjectContainer, BeatmapDifficulty beatmapDifficulty)
: base(droppedObjectContainer, beatmapDifficulty)
[Cached]
private readonly DroppedObjectContainer droppedObjectContainer;

public TestCatcherArea(BeatmapDifficulty beatmapDifficulty)
: base(beatmapDifficulty)
{
AddInternal(droppedObjectContainer = new DroppedObjectContainer());
}

public void ToggleHyperDash(bool status) => MovableCatcher.SetHyperDashState(status ? 2 : 1);
Expand Down
18 changes: 15 additions & 3 deletions osu.Game.Rulesets.Catch.Tests/TestSceneHyperDashColouring.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,10 @@ private void checkHyperDashCatcherColour(ISkin skin, Color4 expectedCatcherColou

AddStep("create hyper-dashing catcher", () =>
{
Child = setupSkinHierarchy(catcherArea = new CatcherArea(new DroppedObjectContainer())
Child = setupSkinHierarchy(catcherArea = new TestCatcherArea
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(4f),
Origin = Anchor.Centre
}, skin);
});

Expand Down Expand Up @@ -206,5 +205,18 @@ public TestSkin()
{
}
}

private class TestCatcherArea : CatcherArea
{
[Cached]
private readonly DroppedObjectContainer droppedObjectContainer;

public TestCatcherArea()
{
Scale = new Vector2(4f);

AddInternal(droppedObjectContainer = new DroppedObjectContainer());
}
}
}
}
9 changes: 5 additions & 4 deletions osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class CatchPlayfield : ScrollingPlayfield
/// </summary>
public const float CENTER_X = WIDTH / 2;

[Cached]
private readonly DroppedObjectContainer droppedObjectContainer;

internal readonly CatcherArea CatcherArea;

public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) =>
Expand All @@ -34,17 +37,15 @@ public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) =>

public CatchPlayfield(BeatmapDifficulty difficulty)
{
var droppedObjectContainer = new DroppedObjectContainer();

CatcherArea = new CatcherArea(droppedObjectContainer, difficulty)
CatcherArea = new CatcherArea(difficulty)
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.TopLeft,
};

InternalChildren = new[]
{
droppedObjectContainer,
droppedObjectContainer = new DroppedObjectContainer(),
CatcherArea.MovableCatcher.CreateProxiedContent(),
HitObjectContainer.CreateProxy(),
// This ordering (`CatcherArea` before `HitObjectContainer`) is important to
Expand Down
6 changes: 3 additions & 3 deletions osu.Game.Rulesets.Catch/UI/Catcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public class Catcher : SkinReloadableDrawable
/// <summary>
/// Contains objects dropped from the plate.
/// </summary>
private readonly DroppedObjectContainer droppedObjectTarget;
[Resolved]
private DroppedObjectContainer droppedObjectTarget { get; set; }

public CatcherAnimationState CurrentState
{
Expand Down Expand Up @@ -134,10 +135,9 @@ public Direction VisualDirection
private readonly DrawablePool<CaughtBanana> caughtBananaPool;
private readonly DrawablePool<CaughtDroplet> caughtDropletPool;

public Catcher([NotNull] Container trailsTarget, [NotNull] DroppedObjectContainer droppedObjectTarget, BeatmapDifficulty difficulty = null)
public Catcher([NotNull] Container trailsTarget, BeatmapDifficulty difficulty = null)
{
this.trailsTarget = trailsTarget;
this.droppedObjectTarget = droppedObjectTarget;

Origin = Anchor.TopCentre;

Expand Down
4 changes: 2 additions & 2 deletions osu.Game.Rulesets.Catch/UI/CatcherArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class CatcherArea : Container, IKeyBindingHandler<CatchAction>
/// </summary>
private int currentDirection;

public CatcherArea(DroppedObjectContainer droppedObjectContainer, BeatmapDifficulty difficulty = null)
public CatcherArea(BeatmapDifficulty difficulty = null)
{
Size = new Vector2(CatchPlayfield.WIDTH, CATCHER_SIZE);
Children = new Drawable[]
Expand All @@ -44,7 +44,7 @@ public CatcherArea(DroppedObjectContainer droppedObjectContainer, BeatmapDifficu
Margin = new MarginPadding { Bottom = 350f },
X = CatchPlayfield.CENTER_X
},
MovableCatcher = new Catcher(this, droppedObjectContainer, difficulty) { X = CatchPlayfield.CENTER_X },
MovableCatcher = new Catcher(this, difficulty) { X = CatchPlayfield.CENTER_X },
};
}

Expand Down

0 comments on commit ae09c23

Please sign in to comment.