-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2310 from andy840119/implement-stage-interface-fo…
…r-mod Define the interface for mod to modify the stage.
- Loading branch information
Showing
12 changed files
with
180 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using osu.Game.Rulesets.Karaoke.Stages.Infos; | ||
using osu.Game.Rulesets.Mods; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Mods; | ||
|
||
public interface IApplicableToStage : IApplicableMod | ||
{ | ||
bool CanApply(StageInfo stageInfo); | ||
} |
12 changes: 12 additions & 0 deletions
12
osu.Game.Rulesets.Karaoke/Mods/IApplicableToStageElement.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// 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; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Mods; | ||
|
||
public interface IApplicableToStageElement : IApplicableToStage | ||
{ | ||
IEnumerable<IStageElement> PostProcess(IEnumerable<IStageElement> stageElements); | ||
} |
17 changes: 17 additions & 0 deletions
17
osu.Game.Rulesets.Karaoke/Mods/IApplicableToStageHitObjectCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// 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.Commands; | ||
using osu.Game.Rulesets.Objects; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Mods; | ||
|
||
public interface IApplicableToStageHitObjectCommand : IApplicableToStage | ||
{ | ||
IEnumerable<IStageCommand> PostProcessInitialCommands(HitObject hitObject, IEnumerable<IStageCommand> commands); | ||
|
||
IEnumerable<IStageCommand> PostProcessStartTimeStateCommands(HitObject hitObject, IEnumerable<IStageCommand> commands); | ||
|
||
IEnumerable<IStageCommand> PostProcessHitStateCommands(HitObject hitObject, IEnumerable<IStageCommand> commands); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using osu.Game.Rulesets.Karaoke.Beatmaps; | ||
using osu.Game.Rulesets.Karaoke.Stages.Infos; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Mods; | ||
|
||
/// <summary> | ||
/// An interface for mods that prefer to use the type of <see cref="StageInfo"/>. | ||
/// Also, it can override the parameter of <see cref="StageInfo"/>. | ||
/// </summary> | ||
public interface IApplicableToStageInfo : IApplicableToStage | ||
{ | ||
StageInfo? CreateDefaultStageInfo(KaraokeBeatmap beatmap); | ||
|
||
void ApplyToStageInfo(StageInfo stageInfo); | ||
} |
13 changes: 13 additions & 0 deletions
13
osu.Game.Rulesets.Karaoke/Mods/IApplicableToStagePlayfieldCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// 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.Commands; | ||
using osu.Game.Rulesets.UI; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Mods; | ||
|
||
public interface IApplicableToStagePlayfieldCommand : IApplicableToStage | ||
{ | ||
IEnumerable<IStageCommand> PostProcessCommands(Playfield playfield, IEnumerable<IStageCommand> commands); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using osu.Framework.Graphics.Containers; | ||
using osu.Game.Rulesets.Karaoke.Mods; | ||
using osu.Game.Rulesets.Karaoke.Stages.Infos; | ||
using osu.Game.Rulesets.Mods; | ||
|
||
|
@@ -11,11 +14,13 @@ namespace osu.Game.Rulesets.Karaoke.Stages.Drawables; | |
public class StageElementRunner : StageRunner, IStageElementRunner | ||
{ | ||
private IStageElementProvider? elementProvider; | ||
private IList<IApplicableToStageElement>? stageMods; | ||
private Container? elementContainer; | ||
|
||
public override void OnStageInfoChanged(StageInfo stageInfo, bool scorable, IReadOnlyList<Mod> mods) | ||
{ | ||
elementProvider = stageInfo.CreateStageElementProvider(scorable); | ||
stageMods = mods.OfType<IApplicableToStageElement>().Where(x => x.CanApply(stageInfo)).ToList(); | ||
applyTransforms(); | ||
} | ||
|
||
|
@@ -32,12 +37,25 @@ public void UpdateStageElements(Container container) | |
|
||
private void applyTransforms() | ||
{ | ||
if (elementProvider == null || elementContainer == null) | ||
if (elementContainer == null) | ||
return; | ||
|
||
elementContainer.Clear(); | ||
|
||
foreach (var element in elementProvider.GetElements()) | ||
foreach (var element in getCommand()) | ||
elementContainer.Add(element.CreateDrawable()); | ||
} | ||
|
||
private IEnumerable<IStageElement> getCommand() | ||
{ | ||
if (elementProvider == null) | ||
return Array.Empty<IStageElement>(); | ||
|
||
var commands = elementProvider.GetElements(); | ||
|
||
if (stageMods == null) | ||
return commands; | ||
|
||
return stageMods.Aggregate(commands, (current, mod) => mod.PostProcess(current)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using osu.Game.Rulesets.Karaoke.Mods; | ||
using osu.Game.Rulesets.Karaoke.Stages.Commands; | ||
using osu.Game.Rulesets.Karaoke.Stages.Infos; | ||
using osu.Game.Rulesets.Karaoke.UI; | ||
|
@@ -14,11 +16,13 @@ namespace osu.Game.Rulesets.Karaoke.Stages.Drawables; | |
public class StagePlayfieldRunner : StageRunner, IStagePlayfieldRunner | ||
{ | ||
private IPlayfieldCommandProvider? commandProvider; | ||
private IList<IApplicableToStagePlayfieldCommand>? stageMods; | ||
private KaraokePlayfield? karaokePlayfield; | ||
|
||
public override void OnStageInfoChanged(StageInfo stageInfo, bool scorable, IReadOnlyList<Mod> mods) | ||
{ | ||
commandProvider = stageInfo.CreatePlayfieldCommandProvider(scorable); | ||
stageMods = mods.OfType<IApplicableToStagePlayfieldCommand>().Where(x => x.CanApply(stageInfo)).ToList(); | ||
applyTransforms(); | ||
} | ||
|
||
|
@@ -36,15 +40,29 @@ public void UpdatePlayfieldTransforms(KaraokePlayfield playfield) | |
|
||
private void applyTransforms() | ||
{ | ||
if (commandProvider == null || karaokePlayfield == null) | ||
if (karaokePlayfield == null) | ||
return; | ||
|
||
var lyricPlayfield = karaokePlayfield.LyricPlayfield; | ||
var notePlayfield = karaokePlayfield.NotePlayfield; | ||
|
||
applyTransforms(karaokePlayfield, commandProvider.GetCommands(karaokePlayfield)); | ||
applyTransforms(lyricPlayfield, commandProvider.GetCommands(lyricPlayfield)); | ||
applyTransforms(notePlayfield, commandProvider.GetCommands(notePlayfield)); | ||
applyTransforms(karaokePlayfield, getCommand(karaokePlayfield)); | ||
applyTransforms(lyricPlayfield, getCommand(lyricPlayfield)); | ||
applyTransforms(notePlayfield, getCommand(notePlayfield)); | ||
} | ||
|
||
private IEnumerable<IStageCommand> getCommand( | ||
Playfield playfield) | ||
{ | ||
if (commandProvider == null) | ||
return Array.Empty<IStageCommand>(); | ||
|
||
var commands = commandProvider.GetCommands(playfield); | ||
|
||
if (stageMods == null) | ||
return commands; | ||
|
||
return stageMods.Aggregate(commands, (current, mod) => mod.PostProcessCommands(playfield, current)); | ||
} | ||
|
||
private static void applyTransforms<TDrawable>(TDrawable drawable, IEnumerable<IStageCommand> commands) | ||
|