Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use better way to provide stage command. #2309

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ namespace osu.Game.Rulesets.Karaoke.Stages.Drawables;

public interface IStageHitObjectRunner
{
event Action? OnStageChanged;

event Action? OnCommandUpdated;

/// <summary>
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,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<Mod> mods)
{
commandProvider = provider;
OnStageChanged?.Invoke();
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();
}
1 change: 0 additions & 1 deletion osu.Game.Rulesets.Karaoke/UI/LyricPlayfield.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down