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/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/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 bc50072c5..233ab1a0c 100644 --- a/osu.Game.Rulesets.Karaoke/Stages/Drawables/StageHitObjectRunner.cs +++ b/osu.Game.Rulesets.Karaoke/Stages/Drawables/StageHitObjectRunner.cs @@ -4,28 +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? OnStageChanged; - 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; - OnStageChanged?.Invoke(); + 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(); +} 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; }