Skip to content

Commit

Permalink
Use more generic way to apply the value to the stage runner.
Browse files Browse the repository at this point in the history
  • Loading branch information
andy840119 committed Dec 7, 2024
1 parent a405a81 commit 2190387
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 24 deletions.
17 changes: 4 additions & 13 deletions osu.Game.Rulesets.Karaoke/Stages/Drawables/DrawableStage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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]
Expand Down Expand Up @@ -59,18 +58,10 @@ public void TriggerRecalculate(KaraokeBeatmap karaokeBeatmap, IReadOnlyList<Mod>
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<Lyric>();
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)
Expand Down
14 changes: 11 additions & 3 deletions osu.Game.Rulesets.Karaoke/Stages/Drawables/StageElementRunner.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
// Copyright (c) andy840119 <[email protected]>. 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<Mod> mods)
{
elementProvider = stageInfo.CreateStageElementProvider(scorable);
applyTransforms();
}

public override void TriggerUpdateCommand()
{
elementProvider = provider;
applyTransforms();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Mod> mods)
{
commandProvider = provider;
commandProvider = stageInfo.CreateHitObjectCommandProvider<Lyric>()!;
OnCommandUpdated?.Invoke();
}

public void TriggerUpdateCommand()
public override void TriggerUpdateCommand()
{
OnCommandUpdated?.Invoke();
}
Expand Down
13 changes: 10 additions & 3 deletions osu.Game.Rulesets.Karaoke/Stages/Drawables/StagePlayfieldRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Mod> mods)
{
commandProvider = stageInfo.CreatePlayfieldCommandProvider(scorable);
applyTransforms();
}

public override void TriggerUpdateCommand()
{
commandProvider = provider;
applyTransforms();
}

Expand Down
15 changes: 15 additions & 0 deletions osu.Game.Rulesets.Karaoke/Stages/Drawables/StageRunner.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) andy840119 <[email protected]>. 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<Mod> mods);

public abstract void TriggerUpdateCommand();
}

0 comments on commit 2190387

Please sign in to comment.