Skip to content

Commit

Permalink
Pass DroppedObjectContainer via constructor instead of DI
Browse files Browse the repository at this point in the history
It is now just one level deep, so it is not beneficial to use DI here.
This effectively reverts ae09c23.
  • Loading branch information
ekrctb committed Jul 19, 2021
1 parent 50f9e5f commit b88ee3c
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
Expand All @@ -24,16 +23,12 @@ namespace osu.Game.Rulesets.Catch.Tests
{
public class TestSceneCatchSkinConfiguration : OsuTestScene
{
[Cached]
private readonly DroppedObjectContainer droppedObjectContainer;

private Catcher catcher;

private readonly Container container;

public TestSceneCatchSkinConfiguration()
{
Add(droppedObjectContainer = new DroppedObjectContainer());
Add(container = new Container { RelativeSizeAxes = Axes.Both });
}

Expand All @@ -46,7 +41,7 @@ public void TestCatcherPlateFlipping(bool flip)
var skin = new TestSkin { FlipCatcherPlate = flip };
container.Child = new SkinProvidingContainer(skin)
{
Child = catcher = new Catcher(new Container())
Child = catcher = new Catcher(new Container(), new DroppedObjectContainer())
{
Anchor = Anchor.Centre
}
Expand Down
35 changes: 15 additions & 20 deletions osu.Game.Rulesets.Catch.Tests/TestSceneCatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,12 @@ public class TestSceneCatcher : OsuTestScene
[Resolved]
private OsuConfigManager config { get; set; }

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

private readonly Container trailContainer;
private DroppedObjectContainer droppedObjectContainer;

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 @@ -56,13 +45,19 @@ public void SetUp() => Schedule(() =>
CircleSize = 0,
};

if (catcher != null)
Remove(catcher);
trailContainer = new Container();
droppedObjectContainer = new DroppedObjectContainer();

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

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

public TestCatcher(Container trailsTarget, BeatmapDifficulty difficulty)
: base(trailsTarget, difficulty)
public TestCatcher(Container trailsTarget, DroppedObjectContainer droppedObjectTarget, BeatmapDifficulty difficulty)
: base(trailsTarget, droppedObjectTarget, difficulty)
{
}
}
Expand Down
10 changes: 5 additions & 5 deletions osu.Game.Rulesets.Catch.Tests/TestSceneCatcherArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,16 @@ private void load(RulesetStore rulesets)

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

public TestCatcherArea(BeatmapDifficulty beatmapDifficulty)
{
MovableCatcher = new Catcher(this, beatmapDifficulty)
var droppedObjectContainer = new DroppedObjectContainer();

Add(droppedObjectContainer);

MovableCatcher = new Catcher(this, droppedObjectContainer, beatmapDifficulty)
{
X = CatchPlayfield.CENTER_X
};
AddInternal(droppedObjectContainer = new DroppedObjectContainer());
}

public void ToggleHyperDash(bool status) => MovableCatcher.SetHyperDashState(status ? 2 : 1);
Expand Down
43 changes: 18 additions & 25 deletions osu.Game.Rulesets.Catch.Tests/TestSceneHyperDashColouring.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,36 +113,45 @@ public void TestFruitColourFallback()

private void checkHyperDashCatcherColour(ISkin skin, Color4 expectedCatcherColour, Color4? expectedEndGlowColour = null)
{
CatcherArea catcherArea = null;
Container trailsContainer = null;
Catcher catcher = null;
CatcherTrailDisplay trails = null;

AddStep("create hyper-dashing catcher", () =>
{
Child = setupSkinHierarchy(catcherArea = new TestCatcherArea
trailsContainer = new Container();
Child = setupSkinHierarchy(new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre
Children = new Drawable[]
{
catcher = new Catcher(trailsContainer, new DroppedObjectContainer())
{
Scale = new Vector2(4)
},
trailsContainer
}
}, skin);
});

AddStep("get trails container", () =>
{
trails = catcherArea.OfType<CatcherTrailDisplay>().Single();
catcherArea.MovableCatcher.SetHyperDashState(2);
trails = trailsContainer.OfType<CatcherTrailDisplay>().Single();
catcher.SetHyperDashState(2);
});

AddUntilStep("catcher colour is correct", () => catcherArea.MovableCatcher.Colour == expectedCatcherColour);
AddUntilStep("catcher colour is correct", () => catcher.Colour == expectedCatcherColour);

AddAssert("catcher trails colours are correct", () => trails.HyperDashTrailsColour == expectedCatcherColour);
AddAssert("catcher end-glow colours are correct", () => trails.EndGlowSpritesColour == (expectedEndGlowColour ?? expectedCatcherColour));

AddStep("finish hyper-dashing", () =>
{
catcherArea.MovableCatcher.SetHyperDashState();
catcherArea.MovableCatcher.FinishTransforms();
catcher.SetHyperDashState();
catcher.FinishTransforms();
});

AddAssert("catcher colour returned to white", () => catcherArea.MovableCatcher.Colour == Color4.White);
AddAssert("catcher colour returned to white", () => catcher.Colour == Color4.White);
}

private void checkHyperDashFruitColour(ISkin skin, Color4 expectedColour)
Expand Down Expand Up @@ -205,21 +214,5 @@ public TestSkin()
{
}
}

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

public TestCatcherArea()
{
MovableCatcher = new Catcher(this, new BeatmapDifficulty())
{
X = CatchPlayfield.CENTER_X,
Scale = new Vector2(4)
};
AddInternal(droppedObjectContainer = new DroppedObjectContainer());
}
}
}
}
10 changes: 4 additions & 6 deletions osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,19 @@ public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) =>

internal readonly CatcherArea CatcherArea;

[Cached]
private readonly DroppedObjectContainer droppedObjectContainer;

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

Catcher = new Catcher(trailContainer, difficulty)
Catcher = new Catcher(trailContainer, droppedObjectContainer, difficulty)
{
X = CENTER_X
};

InternalChildren = new[]
{
droppedObjectContainer = new DroppedObjectContainer(),
droppedObjectContainer,
Catcher.CreateProxiedContent(),
HitObjectContainer.CreateProxy(),
// This ordering (`CatcherArea` before `HitObjectContainer`) is important to
Expand All @@ -58,7 +56,7 @@ public CatchPlayfield(BeatmapDifficulty difficulty)
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.TopLeft,
MovableCatcher = Catcher
MovableCatcher = Catcher,
},
trailContainer,
HitObjectContainer,
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 @@ -74,8 +74,7 @@ public class Catcher : SkinReloadableDrawable
/// <summary>
/// Contains objects dropped from the plate.
/// </summary>
[Resolved]
private DroppedObjectContainer droppedObjectTarget { get; set; }
private readonly DroppedObjectContainer droppedObjectTarget;

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

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

Origin = Anchor.TopCentre;

Expand Down

0 comments on commit b88ee3c

Please sign in to comment.