From a405a8141a705897c0fc63e6f8f7596262f7492d Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 7 Dec 2024 14:39:04 +0800 Subject: [PATCH 1/2] Just expose the command update event in the hit-object command runner is enough. --- .../Stages/Drawables/IStageHitObjectRunner.cs | 2 -- .../Stages/Drawables/StageHitObjectRunner.cs | 4 +--- osu.Game.Rulesets.Karaoke/UI/LyricPlayfield.cs | 1 - 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Stages/Drawables/IStageHitObjectRunner.cs b/osu.Game.Rulesets.Karaoke/Stages/Drawables/IStageHitObjectRunner.cs index e53594d42..10b413336 100644 --- a/osu.Game.Rulesets.Karaoke/Stages/Drawables/IStageHitObjectRunner.cs +++ b/osu.Game.Rulesets.Karaoke/Stages/Drawables/IStageHitObjectRunner.cs @@ -11,8 +11,6 @@ namespace osu.Game.Rulesets.Karaoke.Stages.Drawables; public interface IStageHitObjectRunner { - event Action? OnStageChanged; - event Action? OnCommandUpdated; /// diff --git a/osu.Game.Rulesets.Karaoke/Stages/Drawables/StageHitObjectRunner.cs b/osu.Game.Rulesets.Karaoke/Stages/Drawables/StageHitObjectRunner.cs index bc50072c5..3ec958865 100644 --- a/osu.Game.Rulesets.Karaoke/Stages/Drawables/StageHitObjectRunner.cs +++ b/osu.Game.Rulesets.Karaoke/Stages/Drawables/StageHitObjectRunner.cs @@ -13,8 +13,6 @@ namespace osu.Game.Rulesets.Karaoke.Stages.Drawables; public partial class StageHitObjectRunner : Component, IStageHitObjectRunner { - public event Action? OnStageChanged; - public event Action? OnCommandUpdated; private IHitObjectCommandProvider commandProvider = null!; @@ -22,7 +20,7 @@ public partial class StageHitObjectRunner : Component, IStageHitObjectRunner public void UpdateCommandGenerator(IHitObjectCommandProvider provider) { commandProvider = provider; - OnStageChanged?.Invoke(); + OnCommandUpdated?.Invoke(); } public void TriggerUpdateCommand() diff --git a/osu.Game.Rulesets.Karaoke/UI/LyricPlayfield.cs b/osu.Game.Rulesets.Karaoke/UI/LyricPlayfield.cs index fbd5b844c..6ac69c570 100644 --- a/osu.Game.Rulesets.Karaoke/UI/LyricPlayfield.cs +++ b/osu.Game.Rulesets.Karaoke/UI/LyricPlayfield.cs @@ -80,7 +80,6 @@ public LyricHitObjectLifetimeEntry(HitObject hitObject, IStageHitObjectRunner? r // Manually set to reduce the number of future alive objects to a bare minimum. updateLifetime(); - stageRunner.OnStageChanged += updateLifetime; stageRunner.OnCommandUpdated += updateLifetime; } From 2190387b68bdc54a4644773767a5ad3736841bec Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 7 Dec 2024 15:04:03 +0800 Subject: [PATCH 2/2] 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(); +}