From c1ac27d65894b4418c9d700ec87972728f0c26d9 Mon Sep 17 00:00:00 2001 From: Salman Alshamrani Date: Sun, 12 Jan 2025 22:56:28 -0500 Subject: [PATCH] Fix failing tests - Caches `DrawableRuleset` in editor compose screen for mania playfield adjustment container (because it's used to wrap the blueprint container as well) - Fixes `ManiaModWithPlayfieldCover` performing a no-longer-correct direct cast with a naive-but-working approach. --- .../Mods/ManiaModWithPlayfieldCover.cs | 4 ++-- .../Components/HitPositionPaddedContainer.cs | 10 +++++++++ .../UI/DrawableManiaRuleset.cs | 1 - .../UI/ManiaPlayfieldAdjustmentContainer.cs | 4 +++- .../Edit/DrawableEditorRulesetWrapper.cs | 22 +++++++++---------- osu.Game/Rulesets/Edit/HitObjectComposer.cs | 1 + 6 files changed, 27 insertions(+), 15 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModWithPlayfieldCover.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModWithPlayfieldCover.cs index 1bc16112c5..b6e6ee7481 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModWithPlayfieldCover.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModWithPlayfieldCover.cs @@ -5,9 +5,9 @@ using System; using System.Linq; using osu.Framework.Bindables; using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; using osu.Game.Rulesets.Mania.Objects; using osu.Game.Rulesets.Mania.UI; +using osu.Game.Rulesets.Mania.UI.Components; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.UI; @@ -35,7 +35,7 @@ namespace osu.Game.Rulesets.Mania.Mods foreach (Column column in maniaPlayfield.Stages.SelectMany(stage => stage.Columns)) { HitObjectContainer hoc = column.HitObjectContainer; - Container hocParent = (Container)hoc.Parent!; + ColumnHitObjectArea hocParent = (ColumnHitObjectArea)hoc.Parent!; hocParent.Remove(hoc, false); hocParent.Add(CreateCover(hoc).With(c => diff --git a/osu.Game.Rulesets.Mania/UI/Components/HitPositionPaddedContainer.cs b/osu.Game.Rulesets.Mania/UI/Components/HitPositionPaddedContainer.cs index f591102f6c..f550e3b241 100644 --- a/osu.Game.Rulesets.Mania/UI/Components/HitPositionPaddedContainer.cs +++ b/osu.Game.Rulesets.Mania/UI/Components/HitPositionPaddedContainer.cs @@ -19,6 +19,16 @@ namespace osu.Game.Rulesets.Mania.UI.Components InternalChild = child; } + internal void Add(Drawable drawable) + { + base.AddInternal(drawable); + } + + internal void Remove(Drawable drawable, bool disposeImmediately = true) + { + base.RemoveInternal(drawable, disposeImmediately); + } + [BackgroundDependencyLoader] private void load(IScrollingInfo scrollingInfo) { diff --git a/osu.Game.Rulesets.Mania/UI/DrawableManiaRuleset.cs b/osu.Game.Rulesets.Mania/UI/DrawableManiaRuleset.cs index d6794d0b4f..a186d9aa7d 100644 --- a/osu.Game.Rulesets.Mania/UI/DrawableManiaRuleset.cs +++ b/osu.Game.Rulesets.Mania/UI/DrawableManiaRuleset.cs @@ -32,7 +32,6 @@ using osu.Game.Skinning; namespace osu.Game.Rulesets.Mania.UI { - [Cached(typeof(DrawableManiaRuleset))] public partial class DrawableManiaRuleset : DrawableScrollingRuleset { /// diff --git a/osu.Game.Rulesets.Mania/UI/ManiaPlayfieldAdjustmentContainer.cs b/osu.Game.Rulesets.Mania/UI/ManiaPlayfieldAdjustmentContainer.cs index f7c4850a94..b0203643b0 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaPlayfieldAdjustmentContainer.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaPlayfieldAdjustmentContainer.cs @@ -31,7 +31,7 @@ namespace osu.Game.Rulesets.Mania.UI } [Resolved] - private DrawableManiaRuleset drawableManiaRuleset { get; set; } = null!; + private DrawableRuleset drawableRuleset { get; set; } = null!; protected override void Update() { @@ -40,6 +40,8 @@ namespace osu.Game.Rulesets.Mania.UI float aspectRatio = DrawWidth / DrawHeight; bool isPortrait = aspectRatio < 1f; + var drawableManiaRuleset = (DrawableManiaRuleset)drawableRuleset; + if (isPortrait && drawableManiaRuleset.Beatmap.Stages.Count == 1) { // Scale playfield up by 25% to become playable on mobile devices, diff --git a/osu.Game/Rulesets/Edit/DrawableEditorRulesetWrapper.cs b/osu.Game/Rulesets/Edit/DrawableEditorRulesetWrapper.cs index 174b278d89..573eb8c42f 100644 --- a/osu.Game/Rulesets/Edit/DrawableEditorRulesetWrapper.cs +++ b/osu.Game/Rulesets/Edit/DrawableEditorRulesetWrapper.cs @@ -19,16 +19,16 @@ namespace osu.Game.Rulesets.Edit internal partial class DrawableEditorRulesetWrapper : CompositeDrawable where TObject : HitObject { - public Playfield Playfield => drawableRuleset.Playfield; + public Playfield Playfield => DrawableRuleset.Playfield; - private readonly DrawableRuleset drawableRuleset; + public readonly DrawableRuleset DrawableRuleset; [Resolved] private EditorBeatmap beatmap { get; set; } = null!; public DrawableEditorRulesetWrapper(DrawableRuleset drawableRuleset) { - this.drawableRuleset = drawableRuleset; + DrawableRuleset = drawableRuleset; RelativeSizeAxes = Axes.Both; @@ -38,7 +38,7 @@ namespace osu.Game.Rulesets.Edit [BackgroundDependencyLoader] private void load() { - drawableRuleset.FrameStablePlayback = false; + DrawableRuleset.FrameStablePlayback = false; Playfield.DisplayJudgements.Value = false; } @@ -67,27 +67,27 @@ namespace osu.Game.Rulesets.Edit private void regenerateAutoplay() { - var autoplayMod = drawableRuleset.Mods.OfType().Single(); - drawableRuleset.SetReplayScore(autoplayMod.CreateScoreFromReplayData(drawableRuleset.Beatmap, drawableRuleset.Mods)); + var autoplayMod = DrawableRuleset.Mods.OfType().Single(); + DrawableRuleset.SetReplayScore(autoplayMod.CreateScoreFromReplayData(DrawableRuleset.Beatmap, DrawableRuleset.Mods)); } private void addHitObject(HitObject hitObject) { - drawableRuleset.AddHitObject((TObject)hitObject); - drawableRuleset.Playfield.PostProcess(); + DrawableRuleset.AddHitObject((TObject)hitObject); + DrawableRuleset.Playfield.PostProcess(); } private void removeHitObject(HitObject hitObject) { - drawableRuleset.RemoveHitObject((TObject)hitObject); - drawableRuleset.Playfield.PostProcess(); + DrawableRuleset.RemoveHitObject((TObject)hitObject); + DrawableRuleset.Playfield.PostProcess(); } public override bool PropagatePositionalInputSubTree => false; public override bool PropagateNonPositionalInputSubTree => false; - public PlayfieldAdjustmentContainer CreatePlayfieldAdjustmentContainer() => drawableRuleset.CreatePlayfieldAdjustmentContainer(); + public PlayfieldAdjustmentContainer CreatePlayfieldAdjustmentContainer() => DrawableRuleset.CreatePlayfieldAdjustmentContainer(); protected override void Dispose(bool isDisposing) { diff --git a/osu.Game/Rulesets/Edit/HitObjectComposer.cs b/osu.Game/Rulesets/Edit/HitObjectComposer.cs index 9f277b6190..8cc7072582 100644 --- a/osu.Game/Rulesets/Edit/HitObjectComposer.cs +++ b/osu.Game/Rulesets/Edit/HitObjectComposer.cs @@ -132,6 +132,7 @@ namespace osu.Game.Rulesets.Edit if (DrawableRuleset is IDrawableScrollingRuleset scrollingRuleset) dependencies.CacheAs(scrollingRuleset.ScrollingInfo); + dependencies.CacheAs(drawableRulesetWrapper.DrawableRuleset); dependencies.CacheAs(Playfield); InternalChildren = new[]