Skip to content

Commit

Permalink
Merge pull request #164 from andy840119/slave/beatmap-statistic
Browse files Browse the repository at this point in the history
Display singer and note.
  • Loading branch information
andy840119 authored Sep 11, 2020
2 parents fba2779 + 5e96ed1 commit 79504f7
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Formats;
using osu.Game.IO;
using osu.Game.Rulesets.Karaoke.Tests.Resources;
using osu.Game.Screens.Select;
using osu.Game.Tests.Visual;
using osuTK;

namespace osu.Game.Rulesets.Karaoke.Tests.Beatmaps
{
[TestFixture]
public class TestSceneBeatmapInfoWedge : OsuTestScene
{
private TestBeatmapInfoWedge infoWedge;
protected override void LoadComplete()
{
base.LoadComplete();

Add(infoWedge = new TestBeatmapInfoWedge
{
Size = new Vector2(0.5f, 245),
RelativeSizeAxes = Axes.X,
Margin = new MarginPadding { Top = 20 }
});

AddStep("show", () =>
{
infoWedge.Show();
infoWedge.Beatmap = Beatmap.Value;
});
}

[TestCase("karaoke-file-samples")]
[TestCase("karaoke-file-samples-without-note")]
[TestCase("karaoke-note-samples")]
[TestCase("karaoke-style-samples")]
[TestCase("karaoke-translate-samples")]
public void TestNullBeatmap(string fileName)
{
using (var resStream = TestResources.OpenBeatmapResource(fileName))
using (var stream = new LineBufferedReader(resStream))
{
var decoder = Decoder.GetDecoder<Beatmap>(stream);
var beatmap = decoder.Decode(stream);
selectBeatmap(beatmap, fileName);
}
}

private void selectBeatmap(IBeatmap b, string fileName)
{
BeatmapInfoWedge.BufferedWedgeInfo infoBefore = null;

AddStep($"select {b?.Metadata.Title ?? fileName} beatmap", () =>
{
infoBefore = infoWedge.Info;
infoWedge.Beatmap = Beatmap.Value = b == null ? Beatmap.Default : CreateWorkingBeatmap(b);
});

AddUntilStep("wait for async load", () => infoWedge.Info != infoBefore);
}

private class TestBeatmapInfoWedge : BeatmapInfoWedge
{
public new BufferedWedgeInfo Info => base.Info;
}
}
}
22 changes: 20 additions & 2 deletions osu.Game.Rulesets.Karaoke/Beatmaps/KaraokeBeatmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,35 @@ public class KaraokeBeatmap : Beatmap<KaraokeHitObject>
{
public override IEnumerable<BeatmapStatistic> GetStatistics()
{
int singers = 1;
int lyrics = HitObjects.Count(s => s is LyricLine);

return new[]
var defaultStatistic = new List<BeatmapStatistic>
{
new BeatmapStatistic
{
Name = @"Singer",
Content = singers.ToString(),
CreateIcon = () => new SpriteIcon { Icon = FontAwesome.Solid.User }
},
new BeatmapStatistic
{
Name = @"Lyric",
Content = lyrics.ToString(),
Icon = FontAwesome.Regular.Circle
CreateIcon = () => new SpriteIcon { Icon = FontAwesome.Solid.AlignLeft }
},
};

int notes = HitObjects.Count(s => s is Note note && note.Display);
if (notes > 0)
defaultStatistic.Add(new BeatmapStatistic
{
Name = @"Note",
Content = notes.ToString(),
CreateIcon = () => new SpriteIcon { Icon = FontAwesome.Solid.Music }
});

return defaultStatistic.ToArray();
}
}
}

0 comments on commit 79504f7

Please sign in to comment.