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 NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -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 });
}
@ -46,7 +41,7 @@ namespace osu.Game.Rulesets.Catch.Tests
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
}

View File

@ -31,23 +31,12 @@ namespace osu.Game.Rulesets.Catch.Tests
[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(() =>
{
@ -56,13 +45,19 @@ namespace osu.Game.Rulesets.Catch.Tests
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]
@ -299,8 +294,8 @@ namespace osu.Game.Rulesets.Catch.Tests
{
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)
{
}
}

View File

@ -119,16 +119,16 @@ namespace osu.Game.Rulesets.Catch.Tests
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);

View File

@ -113,36 +113,45 @@ namespace osu.Game.Rulesets.Catch.Tests
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)
@ -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;
[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
@ -58,7 +56,7 @@ namespace osu.Game.Rulesets.Catch.UI
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.TopLeft,
MovableCatcher = Catcher
MovableCatcher = Catcher,
},
trailContainer,
HitObjectContainer,

View File

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