Skip to content

Commit

Permalink
Merge pull request #1387 from andy840119/add-scoring-property-in-the-…
Browse files Browse the repository at this point in the history
…karaoke-beatmap

Add scoring property in the karaoke beatmap.
  • Loading branch information
andy840119 authored Jun 15, 2022
2 parents 31373e3 + dc54cbb commit c0e4761
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,24 @@ public void TestImport()
Assert.AreEqual(karaokeBeatmap.HitObjects.Count, 2);
});
}

[Test]
public void TestSetScorable()
{
SetUpKaraokeBeatmap(karaokeBeatmap =>
{
karaokeBeatmap.Scorable = true;
});

TriggerHandlerChanged(c =>
{
c.SetScorable(false);
});

AssertKaraokeBeatmap(karaokeBeatmap =>
{
Assert.AreEqual(karaokeBeatmap.Scorable, false);
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ public abstract class KaraokeSkinnableColumnTestScene : KaraokeSkinnableTestScen
[Cached(typeof(INotePositionInfo))]
private readonly PreviewNotePositionInfo notePositionInfo = new();

protected override Ruleset CreateRulesetForSkinProvider() => new KaraokeRuleset();

protected KaraokeSkinnableColumnTestScene()
{
scrollingInfo.Direction.Value = ScrollingDirection.Left;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// See the LICENCE file in the repository root for full licence text.

using osu.Game.Beatmaps;
using osu.Game.Rulesets.Karaoke.Beatmaps;
using osu.Game.Rulesets.Karaoke.Tests.Beatmaps;
using osu.Game.Tests.Visual;

namespace osu.Game.Rulesets.Karaoke.Tests.Skinning
{
public abstract class KaraokeSkinnableTestScene : SkinnableTestScene
{
protected override Ruleset CreateRulesetForSkinProvider() => new KaraokeRuleset();
protected override IBeatmap CreateBeatmap(RulesetInfo ruleset) => new TestKaraokeBeatmap(ruleset);

protected override IBeatmap CreateBeatmapForSkinProvider() => new KaraokeBeatmap();
protected override Ruleset CreateRulesetForSkinProvider() => new KaraokeRuleset();
}
}
6 changes: 3 additions & 3 deletions osu.Game.Rulesets.Karaoke/Beatmaps/KaraokeBeatmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class KaraokeBeatmap : Beatmap<KaraokeHitObject>

public List<Singer> Singers { get; set; } = new();

public bool Scorable { get; set; }

public int TotalColumns { get; set; } = 9;

public override IEnumerable<BeatmapStatistic> GetStatistics()
Expand All @@ -40,9 +42,7 @@ public override IEnumerable<BeatmapStatistic> GetStatistics()
},
};

bool scorable = this.IsScorable();

if (scorable)
if (Scorable)
{
int notes = HitObjects.Count(s => s is Note { Display: true });
defaultStatistic.Add(new BeatmapStatistic
Expand Down
13 changes: 11 additions & 2 deletions osu.Game.Rulesets.Karaoke/Beatmaps/KaraokeBeatmapExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,22 @@
using System.Linq;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Karaoke.Beatmaps.Metadatas;
using osu.Game.Rulesets.Karaoke.Objects;

namespace osu.Game.Rulesets.Karaoke.Beatmaps
{
public static class KaraokeBeatmapExtension
{
public static bool IsScorable(this IBeatmap beatmap) => beatmap?.HitObjects.OfType<Note>().Any(x => x.Display) ?? false;
public static bool IsScorable(this IBeatmap beatmap)
{
if (beatmap is not KaraokeBeatmap karaokeBeatmap)
{
// we should throw invalidate exception here but it will cause test case failed.
// because beatmap in the working beatmap in test case not always be karaoke beatmap class.
return false;
}

return karaokeBeatmap.Scorable;
}

public static List<CultureInfo> AvailableTranslates(this IBeatmap beatmap) => (beatmap as KaraokeBeatmap)?.AvailableTranslates ?? new List<CultureInfo>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Karaoke.Beatmaps;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Screens.Edit;

Expand All @@ -15,6 +16,8 @@ public class BeatmapChangeHandler : Component, IBeatmapChangeHandler
[Resolved]
private EditorBeatmap beatmap { get; set; }

private KaraokeBeatmap karaokeBeatmap => beatmap.PlayableBeatmap as KaraokeBeatmap;

public void Import(IBeatmap newBeatmap)
{
beatmap.BeginChange();
Expand All @@ -35,5 +38,14 @@ public void Import(IBeatmap newBeatmap)

beatmap.EndChange();
}

public void SetScorable(bool scorable)
{
beatmap.BeginChange();

karaokeBeatmap.Scorable = scorable;

beatmap.EndChange();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ namespace osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers
public interface IBeatmapChangeHandler
{
void Import(IBeatmap newBeatmap);

void SetScorable(bool scorable);
}
}

0 comments on commit c0e4761

Please sign in to comment.