1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 16:43:00 +08:00

Allow PlayerTestScene to import the beatmap it's using

This commit is contained in:
Dean Herbert 2022-07-07 16:42:36 +09:00
parent f88e2aa025
commit 1a41d3ef20

View File

@ -4,12 +4,15 @@
#nullable disable
using System;
using System.Diagnostics;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Database;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
@ -22,6 +25,11 @@ namespace osu.Game.Tests.Visual
/// </summary>
protected virtual bool HasCustomSteps => false;
/// <summary>
/// WARNING: ONLY WORKS IF RUN HEADLESS because reasons.
/// </summary>
protected virtual bool ImportBeatmapToDatabase => false;
protected TestPlayer Player;
protected OsuConfigManager LocalConfig;
@ -49,7 +57,7 @@ namespace osu.Game.Tests.Visual
action?.Invoke();
AddStep(CreatePlayerRuleset().Description, LoadPlayer);
AddStep($"Load player for {CreatePlayerRuleset().Description}", LoadPlayer);
AddUntilStep("player loaded", () => Player.IsLoaded && Player.Alpha == 1);
}
@ -57,6 +65,9 @@ namespace osu.Game.Tests.Visual
protected virtual bool Autoplay => false;
[Resolved]
private BeatmapManager beatmaps { get; set; }
protected void LoadPlayer()
{
var ruleset = CreatePlayerRuleset();
@ -64,6 +75,20 @@ namespace osu.Game.Tests.Visual
var beatmap = CreateBeatmap(ruleset.RulesetInfo);
if (ImportBeatmapToDatabase)
{
Debug.Assert(beatmap.BeatmapInfo.BeatmapSet != null);
var imported = beatmaps.Import(beatmap.BeatmapInfo.BeatmapSet);
Debug.Assert(imported != null);
beatmap.BeatmapInfo = null;
beatmap.Difficulty = null;
beatmap.BeatmapInfo = imported.Value.Detach().Beatmaps.First();
}
Beatmap.Value = CreateWorkingBeatmap(beatmap);
SelectedMods.Value = Array.Empty<Mod>();