From 2190387b68bdc54a4644773767a5ad3736841bec Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 7 Dec 2024 15:04:03 +0800 Subject: [PATCH] Use more generic way to apply the value to the stage runner. --- .../Stages/Drawables/DrawableStage.cs | 17 ++++------------- .../Stages/Drawables/StageElementRunner.cs | 14 +++++++++++--- .../Stages/Drawables/StageHitObjectRunner.cs | 12 +++++++----- .../Stages/Drawables/StagePlayfieldRunner.cs | 13 ++++++++++--- .../Stages/Drawables/StageRunner.cs | 15 +++++++++++++++ 5 files changed, 47 insertions(+), 24 deletions(-) create mode 100644 osu.Game.Rulesets.Karaoke/Stages/Drawables/StageRunner.cs diff --git a/osu.Game.Rulesets.Karaoke/Stages/Drawables/DrawableStage.cs b/osu.Game.Rulesets.Karaoke/Stages/Drawables/DrawableStage.cs index cd2133e2e..e5b302963 100644 --- a/osu.Game.Rulesets.Karaoke/Stages/Drawables/DrawableStage.cs +++ b/osu.Game.Rulesets.Karaoke/Stages/Drawables/DrawableStage.cs @@ -5,13 +5,11 @@ using System.Collections.Generic; using System.Linq; using osu.Framework.Allocation; -using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Beatmaps; using osu.Game.Rulesets.Karaoke.Beatmaps; using osu.Game.Rulesets.Karaoke.Mods; -using osu.Game.Rulesets.Karaoke.Objects; using osu.Game.Rulesets.Karaoke.Stages.Infos; using osu.Game.Rulesets.Karaoke.Stages.Infos.Preview; using osu.Game.Rulesets.Karaoke.Stages.Infos.Types; @@ -31,6 +29,7 @@ public partial class DrawableStage : Container [Cached(typeof(IStagePlayfieldRunner))] private readonly StagePlayfieldRunner stagePlayfieldRunner = new(); + [Cached(typeof(IStageElementRunner))] private readonly StageElementRunner stageElementRunner = new(); [BackgroundDependencyLoader] @@ -59,18 +58,10 @@ public void TriggerRecalculate(KaraokeBeatmap karaokeBeatmap, IReadOnlyList calculatedProperty.ValidateCalculatedProperty(karaokeBeatmap); bool scorable = karaokeBeatmap.IsScorable(); - var playfieldCommandProvider = stageInfo.CreatePlayfieldCommandProvider(scorable); - stagePlayfieldRunner.UpdateCommandGenerator(playfieldCommandProvider); - var stageElementProvider = stageInfo.CreateStageElementProvider(scorable); - - if (stageElementProvider != null) - stageElementRunner.UpdateCommandGenerator(stageElementProvider); - - // todo: should handle the note case. - var lyricCommandProvider = stageInfo.CreateHitObjectCommandProvider(); - if (lyricCommandProvider != null) - stageRunner.UpdateCommandGenerator(lyricCommandProvider); + stageRunner.OnStageInfoChanged(stageInfo, scorable, mods); + stagePlayfieldRunner.OnStageInfoChanged(stageInfo, scorable, mods); + stageElementRunner.OnStageInfoChanged(stageInfo, scorable, mods); } public override void Add(Drawable drawable) diff --git a/osu.Game.Rulesets.Karaoke/Stages/Drawables/StageElementRunner.cs b/osu.Game.Rulesets.Karaoke/Stages/Drawables/StageElementRunner.cs index c3dd3cc2a..3700788b7 100644 --- a/osu.Game.Rulesets.Karaoke/Stages/Drawables/StageElementRunner.cs +++ b/osu.Game.Rulesets.Karaoke/Stages/Drawables/StageElementRunner.cs @@ -1,18 +1,26 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. +using System.Collections.Generic; using osu.Framework.Graphics.Containers; +using osu.Game.Rulesets.Karaoke.Stages.Infos; +using osu.Game.Rulesets.Mods; namespace osu.Game.Rulesets.Karaoke.Stages.Drawables; -public class StageElementRunner : IStageElementRunner +public class StageElementRunner : StageRunner, IStageElementRunner { private IStageElementProvider? elementProvider; private Container? elementContainer; - public void UpdateCommandGenerator(IStageElementProvider provider) + public override void OnStageInfoChanged(StageInfo stageInfo, bool scorable, IReadOnlyList mods) + { + elementProvider = stageInfo.CreateStageElementProvider(scorable); + applyTransforms(); + } + + public override void TriggerUpdateCommand() { - elementProvider = provider; applyTransforms(); } diff --git a/osu.Game.Rulesets.Karaoke/Stages/Drawables/StageHitObjectRunner.cs b/osu.Game.Rulesets.Karaoke/Stages/Drawables/StageHitObjectRunner.cs index 3ec958865..233ab1a0c 100644 --- a/osu.Game.Rulesets.Karaoke/Stages/Drawables/StageHitObjectRunner.cs +++ b/osu.Game.Rulesets.Karaoke/Stages/Drawables/StageHitObjectRunner.cs @@ -4,26 +4,28 @@ using System; using System.Collections.Generic; using System.Linq; -using osu.Framework.Graphics; +using osu.Game.Rulesets.Karaoke.Objects; using osu.Game.Rulesets.Karaoke.Stages.Commands; +using osu.Game.Rulesets.Karaoke.Stages.Infos; +using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects.Drawables; namespace osu.Game.Rulesets.Karaoke.Stages.Drawables; -public partial class StageHitObjectRunner : Component, IStageHitObjectRunner +public class StageHitObjectRunner : StageRunner, IStageHitObjectRunner { public event Action? OnCommandUpdated; private IHitObjectCommandProvider commandProvider = null!; - public void UpdateCommandGenerator(IHitObjectCommandProvider provider) + public override void OnStageInfoChanged(StageInfo stageInfo, bool scorable, IReadOnlyList mods) { - commandProvider = provider; + commandProvider = stageInfo.CreateHitObjectCommandProvider()!; OnCommandUpdated?.Invoke(); } - public void TriggerUpdateCommand() + public override void TriggerUpdateCommand() { OnCommandUpdated?.Invoke(); } diff --git a/osu.Game.Rulesets.Karaoke/Stages/Drawables/StagePlayfieldRunner.cs b/osu.Game.Rulesets.Karaoke/Stages/Drawables/StagePlayfieldRunner.cs index d14e56b72..15bcf2529 100644 --- a/osu.Game.Rulesets.Karaoke/Stages/Drawables/StagePlayfieldRunner.cs +++ b/osu.Game.Rulesets.Karaoke/Stages/Drawables/StagePlayfieldRunner.cs @@ -4,19 +4,26 @@ using System.Collections.Generic; using System.Linq; using osu.Game.Rulesets.Karaoke.Stages.Commands; +using osu.Game.Rulesets.Karaoke.Stages.Infos; using osu.Game.Rulesets.Karaoke.UI; +using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.UI; namespace osu.Game.Rulesets.Karaoke.Stages.Drawables; -public class StagePlayfieldRunner : IStagePlayfieldRunner +public class StagePlayfieldRunner : StageRunner, IStagePlayfieldRunner { private IPlayfieldCommandProvider? commandProvider; private KaraokePlayfield? karaokePlayfield; - public void UpdateCommandGenerator(IPlayfieldCommandProvider provider) + public override void OnStageInfoChanged(StageInfo stageInfo, bool scorable, IReadOnlyList mods) + { + commandProvider = stageInfo.CreatePlayfieldCommandProvider(scorable); + applyTransforms(); + } + + public override void TriggerUpdateCommand() { - commandProvider = provider; applyTransforms(); } diff --git a/osu.Game.Rulesets.Karaoke/Stages/Drawables/StageRunner.cs b/osu.Game.Rulesets.Karaoke/Stages/Drawables/StageRunner.cs new file mode 100644 index 000000000..301c23507 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/Stages/Drawables/StageRunner.cs @@ -0,0 +1,15 @@ +// Copyright (c) andy840119 . Licensed under the GPL Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Collections.Generic; +using osu.Game.Rulesets.Karaoke.Stages.Infos; +using osu.Game.Rulesets.Mods; + +namespace osu.Game.Rulesets.Karaoke.Stages.Drawables; + +public abstract partial class StageRunner +{ + public abstract void OnStageInfoChanged(StageInfo stageInfo, bool scorable, IReadOnlyList mods); + + public abstract void TriggerUpdateCommand(); +}