Skip to content

Commit

Permalink
Fix the test case failed.
Browse files Browse the repository at this point in the history
  • Loading branch information
andy840119 committed Jun 25, 2024
1 parent 96a8f1a commit 59b2a55
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions osu.Game.Rulesets.Karaoke/Beatmaps/KaraokeBeatmapProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) andy840119 <andy840119@gmail.com>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Linq;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Game.Beatmaps;
Expand All @@ -10,24 +11,37 @@
using osu.Game.Rulesets.Karaoke.Stages;
using osu.Game.Rulesets.Karaoke.Stages.Preview;
using osu.Game.Rulesets.Karaoke.Stages.Types;
using osu.Game.Screens.Edit;

namespace osu.Game.Rulesets.Karaoke.Beatmaps;

public class KaraokeBeatmapProcessor : BeatmapProcessor
{
public new KaraokeBeatmap Beatmap => (KaraokeBeatmap)base.Beatmap;

public KaraokeBeatmapProcessor(IBeatmap beatmap)
: base(beatmap)
{
}

public override void PreProcess()
{
applyStage(Beatmap);
var karaokeBeatmap = getKaraokeBeatmap(Beatmap);
applyStage(karaokeBeatmap);

base.PreProcess();
applyInvalidProperty(Beatmap);
applyInvalidProperty(karaokeBeatmap);

static KaraokeBeatmap getKaraokeBeatmap(IBeatmap beatmap)
{
// goes to there while parsing the beatmap.
if (beatmap is KaraokeBeatmap karaokeBeatmap)
return karaokeBeatmap;

// goes to there while editing the beatmap.
if (beatmap is EditorBeatmap editorBeatmap)
return getKaraokeBeatmap(editorBeatmap.PlayableBeatmap);

throw new InvalidCastException($"The beatmap is not a {nameof(KaraokeBeatmap)}");
}
}

private void applyStage(KaraokeBeatmap beatmap)
Expand All @@ -36,7 +50,7 @@ private void applyStage(KaraokeBeatmap beatmap)
// trying to load the first stage or create a default one.
if (beatmap.CurrentStageInfo == null)
{
beatmap.CurrentStageInfo = getWorkingStage() ?? createDefaultWorkingStage();
beatmap.CurrentStageInfo = getWorkingStage(beatmap) ?? createDefaultWorkingStage();

// should invalidate the working property here because the stage info is changed.
beatmap.HitObjects.OfType<Lyric>().ForEach(x =>
Expand All @@ -50,10 +64,10 @@ private void applyStage(KaraokeBeatmap beatmap)
if (beatmap.CurrentStageInfo is IHasCalculatedProperty calculatedProperty)
calculatedProperty.ValidateCalculatedProperty(beatmap);

StageInfo? getWorkingStage()
=> Beatmap.StageInfos.FirstOrDefault();
static StageInfo? getWorkingStage(KaraokeBeatmap beatmap)
=> beatmap.StageInfos.FirstOrDefault();

StageInfo createDefaultWorkingStage() => new PreviewStageInfo();
static StageInfo createDefaultWorkingStage() => new PreviewStageInfo();
}

private void applyInvalidProperty(KaraokeBeatmap beatmap)
Expand Down

0 comments on commit 59b2a55

Please sign in to comment.