1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-23 20:07:26 +08:00
osu-lazer/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapMetadataDisplay.cs

95 lines
3.2 KiB
C#
Raw Normal View History

2021-05-08 16:46:42 +08:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
2021-05-09 02:20:17 +08:00
using osu.Game.Rulesets;
2021-05-08 16:46:42 +08:00
using osu.Game.Rulesets.Mods;
using osu.Game.Screens.Play;
using osuTK;
namespace osu.Game.Tests.Visual.SongSelect
{
public class TestSceneBeatmapMetadataDisplay : OsuTestScene
{
private BeatmapMetadataDisplay display;
[Resolved]
private BeatmapManager manager { get; set; }
2021-05-09 02:20:17 +08:00
[Resolved]
private RulesetStore rulesets { get; set; }
protected override void LoadComplete()
{
base.LoadComplete();
foreach (var ruleset in rulesets.AvailableRulesets)
AddStep($"switch to {ruleset.Name}", () => Ruleset.Value = ruleset);
}
private void createTest(Func<WorkingBeatmap> getBeatmap)
2021-05-08 16:46:42 +08:00
{
AddStep("setup display", () => Child = display = new BeatmapMetadataDisplay(getBeatmap(), new Bindable<IReadOnlyList<Mod>>(getRandomMods()), Empty())
2021-05-08 16:46:42 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(1.5f),
Alpha = 0f,
2021-05-08 16:46:42 +08:00
});
AddStep("fade in", () => display.FadeIn(400, Easing.OutQuint));
2021-05-08 16:46:42 +08:00
AddToggleStep("trigger loading", v => display.Loading = v);
}
[Test]
public void TestLocal([Values("Beatmap", "Some long title and stuff")]
string title,
[Values("Trial", "Some1's very hardest difficulty")]
string version)
{
2021-05-09 02:20:17 +08:00
createTest(() => CreateWorkingBeatmap(new Beatmap
2021-05-08 16:46:42 +08:00
{
BeatmapInfo =
{
Metadata = new BeatmapMetadata
{
Title = title,
},
Version = version,
StarDifficulty = RNG.NextDouble(0, 10),
}
}));
}
[Test]
public void TestRandomFromDatabase()
{
2021-05-09 02:20:17 +08:00
createTest(() =>
2021-05-08 16:46:42 +08:00
{
var allBeatmapSets = manager.GetAllUsableBeatmapSets(IncludedDetails.Minimal);
2021-05-08 18:03:50 +08:00
if (allBeatmapSets.Count == 0)
return manager.DefaultBeatmap;
2021-05-08 16:46:42 +08:00
var randomBeatmapSet = allBeatmapSets[RNG.Next(0, allBeatmapSets.Count - 1)];
var randomBeatmap = randomBeatmapSet.Beatmaps[RNG.Next(0, randomBeatmapSet.Beatmaps.Count - 1)];
return manager.GetWorkingBeatmap(randomBeatmap);
});
}
private IReadOnlyList<Mod> getRandomMods() => Ruleset.Value.CreateInstance()
.GetAllMods()
.OrderBy(_ => RNG.Next())
.Take(5)
.ToList();
2021-05-08 16:46:42 +08:00
}
}