1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 20:07:25 +08:00

Pass DroppedObjectContainer via constructor instead of DI

It is now just one level deep, so it is not beneficial to use DI here.
This effectively reverts ae09c23e.
This commit is contained in:
ekrctb 2021-07-19 20:11:49 +09:00
parent 50f9e5f362
commit b88ee3c1a1
6 changed files with 46 additions and 65 deletions

View File

@ -3,7 +3,6 @@
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -24,16 +23,12 @@ namespace osu.Game.Rulesets.Catch.Tests
{ {
public class TestSceneCatchSkinConfiguration : OsuTestScene public class TestSceneCatchSkinConfiguration : OsuTestScene
{ {
[Cached]
private readonly DroppedObjectContainer droppedObjectContainer;
private Catcher catcher; private Catcher catcher;
private readonly Container container; private readonly Container container;
public TestSceneCatchSkinConfiguration() public TestSceneCatchSkinConfiguration()
{ {
Add(droppedObjectContainer = new DroppedObjectContainer());
Add(container = new Container { RelativeSizeAxes = Axes.Both }); Add(container = new Container { RelativeSizeAxes = Axes.Both });
} }
@ -46,7 +41,7 @@ namespace osu.Game.Rulesets.Catch.Tests
var skin = new TestSkin { FlipCatcherPlate = flip }; var skin = new TestSkin { FlipCatcherPlate = flip };
container.Child = new SkinProvidingContainer(skin) container.Child = new SkinProvidingContainer(skin)
{ {
Child = catcher = new Catcher(new Container()) Child = catcher = new Catcher(new Container(), new DroppedObjectContainer())
{ {
Anchor = Anchor.Centre Anchor = Anchor.Centre
} }

View File

@ -31,23 +31,12 @@ namespace osu.Game.Rulesets.Catch.Tests
[Resolved] [Resolved]
private OsuConfigManager config { get; set; } private OsuConfigManager config { get; set; }
[Cached] private Container trailContainer;
private readonly DroppedObjectContainer droppedObjectContainer;
private readonly Container trailContainer; private DroppedObjectContainer droppedObjectContainer;
private TestCatcher catcher; private TestCatcher catcher;
public TestSceneCatcher()
{
Add(trailContainer = new Container
{
Anchor = Anchor.Centre,
Depth = -1
});
Add(droppedObjectContainer = new DroppedObjectContainer());
}
[SetUp] [SetUp]
public void SetUp() => Schedule(() => public void SetUp() => Schedule(() =>
{ {
@ -56,13 +45,19 @@ namespace osu.Game.Rulesets.Catch.Tests
CircleSize = 0, CircleSize = 0,
}; };
if (catcher != null) trailContainer = new Container();
Remove(catcher); 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] [Test]
@ -299,8 +294,8 @@ namespace osu.Game.Rulesets.Catch.Tests
{ {
public IEnumerable<CaughtObject> CaughtObjects => this.ChildrenOfType<CaughtObject>(); public IEnumerable<CaughtObject> CaughtObjects => this.ChildrenOfType<CaughtObject>();
public TestCatcher(Container trailsTarget, BeatmapDifficulty difficulty) public TestCatcher(Container trailsTarget, DroppedObjectContainer droppedObjectTarget, BeatmapDifficulty difficulty)
: base(trailsTarget, difficulty) : base(trailsTarget, droppedObjectTarget, difficulty)
{ {
} }
} }

View File

@ -119,16 +119,16 @@ namespace osu.Game.Rulesets.Catch.Tests
private class TestCatcherArea : CatcherArea private class TestCatcherArea : CatcherArea
{ {
[Cached]
private readonly DroppedObjectContainer droppedObjectContainer;
public TestCatcherArea(BeatmapDifficulty beatmapDifficulty) 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 X = CatchPlayfield.CENTER_X
}; };
AddInternal(droppedObjectContainer = new DroppedObjectContainer());
} }
public void ToggleHyperDash(bool status) => MovableCatcher.SetHyperDashState(status ? 2 : 1); public void ToggleHyperDash(bool status) => MovableCatcher.SetHyperDashState(status ? 2 : 1);

View File

@ -113,36 +113,45 @@ namespace osu.Game.Rulesets.Catch.Tests
private void checkHyperDashCatcherColour(ISkin skin, Color4 expectedCatcherColour, Color4? expectedEndGlowColour = null) private void checkHyperDashCatcherColour(ISkin skin, Color4 expectedCatcherColour, Color4? expectedEndGlowColour = null)
{ {
CatcherArea catcherArea = null; Container trailsContainer = null;
Catcher catcher = null;
CatcherTrailDisplay trails = null; CatcherTrailDisplay trails = null;
AddStep("create hyper-dashing catcher", () => AddStep("create hyper-dashing catcher", () =>
{ {
Child = setupSkinHierarchy(catcherArea = new TestCatcherArea trailsContainer = new Container();
Child = setupSkinHierarchy(new Container
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre Children = new Drawable[]
{
catcher = new Catcher(trailsContainer, new DroppedObjectContainer())
{
Scale = new Vector2(4)
},
trailsContainer
}
}, skin); }, skin);
}); });
AddStep("get trails container", () => AddStep("get trails container", () =>
{ {
trails = catcherArea.OfType<CatcherTrailDisplay>().Single(); trails = trailsContainer.OfType<CatcherTrailDisplay>().Single();
catcherArea.MovableCatcher.SetHyperDashState(2); 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 trails colours are correct", () => trails.HyperDashTrailsColour == expectedCatcherColour);
AddAssert("catcher end-glow colours are correct", () => trails.EndGlowSpritesColour == (expectedEndGlowColour ?? expectedCatcherColour)); AddAssert("catcher end-glow colours are correct", () => trails.EndGlowSpritesColour == (expectedEndGlowColour ?? expectedCatcherColour));
AddStep("finish hyper-dashing", () => AddStep("finish hyper-dashing", () =>
{ {
catcherArea.MovableCatcher.SetHyperDashState(); catcher.SetHyperDashState();
catcherArea.MovableCatcher.FinishTransforms(); 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) private void checkHyperDashFruitColour(ISkin skin, Color4 expectedColour)
@ -205,21 +214,5 @@ namespace osu.Game.Rulesets.Catch.Tests
{ {
} }
} }
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());
}
}
} }
} }

View File

@ -35,21 +35,19 @@ namespace osu.Game.Rulesets.Catch.UI
internal readonly CatcherArea CatcherArea; internal readonly CatcherArea CatcherArea;
[Cached]
private readonly DroppedObjectContainer droppedObjectContainer;
public CatchPlayfield(BeatmapDifficulty difficulty) public CatchPlayfield(BeatmapDifficulty difficulty)
{ {
var trailContainer = new Container(); var trailContainer = new Container();
var droppedObjectContainer = new DroppedObjectContainer();
Catcher = new Catcher(trailContainer, difficulty) Catcher = new Catcher(trailContainer, droppedObjectContainer, difficulty)
{ {
X = CENTER_X X = CENTER_X
}; };
InternalChildren = new[] InternalChildren = new[]
{ {
droppedObjectContainer = new DroppedObjectContainer(), droppedObjectContainer,
Catcher.CreateProxiedContent(), Catcher.CreateProxiedContent(),
HitObjectContainer.CreateProxy(), HitObjectContainer.CreateProxy(),
// This ordering (`CatcherArea` before `HitObjectContainer`) is important to // This ordering (`CatcherArea` before `HitObjectContainer`) is important to
@ -58,7 +56,7 @@ namespace osu.Game.Rulesets.Catch.UI
{ {
Anchor = Anchor.BottomLeft, Anchor = Anchor.BottomLeft,
Origin = Anchor.TopLeft, Origin = Anchor.TopLeft,
MovableCatcher = Catcher MovableCatcher = Catcher,
}, },
trailContainer, trailContainer,
HitObjectContainer, HitObjectContainer,

View File

@ -74,8 +74,7 @@ namespace osu.Game.Rulesets.Catch.UI
/// <summary> /// <summary>
/// Contains objects dropped from the plate. /// Contains objects dropped from the plate.
/// </summary> /// </summary>
[Resolved] private readonly DroppedObjectContainer droppedObjectTarget;
private DroppedObjectContainer droppedObjectTarget { get; set; }
public CatcherAnimationState CurrentState public CatcherAnimationState CurrentState
{ {
@ -134,9 +133,10 @@ namespace osu.Game.Rulesets.Catch.UI
private readonly DrawablePool<CaughtBanana> caughtBananaPool; private readonly DrawablePool<CaughtBanana> caughtBananaPool;
private readonly DrawablePool<CaughtDroplet> caughtDropletPool; 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.trailsTarget = trailsTarget;
this.droppedObjectTarget = droppedObjectTarget;
Origin = Anchor.TopCentre; Origin = Anchor.TopCentre;