2020-01-29 05:23:31 +00: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.
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2020-01-29 05:23:31 +00:00
|
|
|
using System;
|
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Screens;
|
|
|
|
using osu.Game.Beatmaps;
|
2021-11-15 09:46:11 +00:00
|
|
|
using osu.Game.Extensions;
|
2020-01-29 05:23:31 +00:00
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using osu.Game.Rulesets.Mania;
|
|
|
|
using osu.Game.Rulesets.Osu;
|
|
|
|
using osu.Game.Screens.Menu;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Navigation
|
|
|
|
{
|
|
|
|
public class TestScenePresentBeatmap : OsuGameTestScene
|
|
|
|
{
|
|
|
|
[Test]
|
|
|
|
public void TestFromMainMenu()
|
|
|
|
{
|
|
|
|
var firstImport = importBeatmap(1);
|
2021-12-10 05:15:00 +00:00
|
|
|
var secondImport = importBeatmap(3);
|
2020-01-29 05:23:31 +00:00
|
|
|
|
2020-04-12 17:04:25 +00:00
|
|
|
presentAndConfirm(firstImport);
|
|
|
|
returnToMenu();
|
2021-12-10 05:15:00 +00:00
|
|
|
presentAndConfirm(secondImport);
|
2020-04-12 17:04:25 +00:00
|
|
|
returnToMenu();
|
|
|
|
presentSecondDifficultyAndConfirm(firstImport, 1);
|
|
|
|
returnToMenu();
|
2021-12-10 05:15:00 +00:00
|
|
|
presentSecondDifficultyAndConfirm(secondImport, 3);
|
2020-01-29 05:23:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestFromMainMenuDifferentRuleset()
|
|
|
|
{
|
|
|
|
var firstImport = importBeatmap(1);
|
2021-12-10 05:15:00 +00:00
|
|
|
var secondImport = importBeatmap(3, new ManiaRuleset().RulesetInfo);
|
2020-01-29 05:23:31 +00:00
|
|
|
|
2020-04-12 17:04:25 +00:00
|
|
|
presentAndConfirm(firstImport);
|
|
|
|
returnToMenu();
|
2021-12-10 05:15:00 +00:00
|
|
|
presentAndConfirm(secondImport);
|
2020-04-12 17:04:25 +00:00
|
|
|
returnToMenu();
|
|
|
|
presentSecondDifficultyAndConfirm(firstImport, 1);
|
|
|
|
returnToMenu();
|
2021-12-10 05:15:00 +00:00
|
|
|
presentSecondDifficultyAndConfirm(secondImport, 3);
|
2020-01-29 05:23:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestFromSongSelect()
|
|
|
|
{
|
|
|
|
var firstImport = importBeatmap(1);
|
|
|
|
presentAndConfirm(firstImport);
|
|
|
|
|
2021-12-10 05:15:00 +00:00
|
|
|
var secondImport = importBeatmap(3);
|
|
|
|
presentAndConfirm(secondImport);
|
2020-04-12 17:04:25 +00:00
|
|
|
|
2020-04-25 07:50:00 +00:00
|
|
|
// Test presenting same beatmap more than once
|
2021-12-10 05:15:00 +00:00
|
|
|
presentAndConfirm(secondImport);
|
2020-04-25 07:50:00 +00:00
|
|
|
|
2020-04-12 17:04:25 +00:00
|
|
|
presentSecondDifficultyAndConfirm(firstImport, 1);
|
2021-12-10 05:15:00 +00:00
|
|
|
presentSecondDifficultyAndConfirm(secondImport, 3);
|
2020-04-25 07:50:00 +00:00
|
|
|
|
|
|
|
// Test presenting same beatmap more than once
|
2021-12-10 05:15:00 +00:00
|
|
|
presentSecondDifficultyAndConfirm(secondImport, 3);
|
2020-01-29 05:23:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestFromSongSelectDifferentRuleset()
|
|
|
|
{
|
|
|
|
var firstImport = importBeatmap(1);
|
|
|
|
presentAndConfirm(firstImport);
|
|
|
|
|
2021-12-10 05:15:00 +00:00
|
|
|
var secondImport = importBeatmap(3, new ManiaRuleset().RulesetInfo);
|
|
|
|
presentAndConfirm(secondImport);
|
2020-04-12 17:04:25 +00:00
|
|
|
|
|
|
|
presentSecondDifficultyAndConfirm(firstImport, 1);
|
2021-12-10 05:15:00 +00:00
|
|
|
presentSecondDifficultyAndConfirm(secondImport, 3);
|
2020-04-12 17:04:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void returnToMenu()
|
|
|
|
{
|
2020-09-15 11:17:59 +00:00
|
|
|
// if we don't pause, there's a chance the track may change at the main menu out of our control (due to reaching the end of the track).
|
|
|
|
AddStep("pause audio", () =>
|
|
|
|
{
|
|
|
|
if (Game.MusicController.IsPlaying)
|
|
|
|
Game.MusicController.TogglePause();
|
|
|
|
});
|
|
|
|
|
2020-04-12 17:04:25 +00:00
|
|
|
AddStep("return to menu", () => Game.ScreenStack.CurrentScreen.Exit());
|
|
|
|
AddUntilStep("wait for menu", () => Game.ScreenStack.CurrentScreen is MainMenu);
|
2020-01-29 05:23:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private Func<BeatmapSetInfo> importBeatmap(int i, RulesetInfo ruleset = null)
|
|
|
|
{
|
|
|
|
BeatmapSetInfo imported = null;
|
|
|
|
AddStep($"import beatmap {i}", () =>
|
|
|
|
{
|
|
|
|
var metadata = new BeatmapMetadata
|
|
|
|
{
|
|
|
|
Artist = "SomeArtist",
|
2022-01-18 14:30:40 +00:00
|
|
|
Author = { Username = "SomeAuthor" },
|
2020-01-29 05:23:31 +00:00
|
|
|
Title = $"import {i}"
|
|
|
|
};
|
|
|
|
|
|
|
|
imported = Game.BeatmapManager.Import(new BeatmapSetInfo
|
|
|
|
{
|
|
|
|
Hash = Guid.NewGuid().ToString(),
|
2021-11-12 08:50:31 +00:00
|
|
|
OnlineID = i,
|
2021-11-24 04:25:26 +00:00
|
|
|
Beatmaps =
|
2020-01-29 05:23:31 +00:00
|
|
|
{
|
|
|
|
new BeatmapInfo
|
|
|
|
{
|
2021-11-12 08:45:05 +00:00
|
|
|
OnlineID = i * 1024,
|
2020-01-29 05:23:31 +00:00
|
|
|
Metadata = metadata,
|
2022-01-18 13:57:39 +00:00
|
|
|
Difficulty = new BeatmapDifficulty(),
|
2020-01-29 05:23:31 +00:00
|
|
|
Ruleset = ruleset ?? new OsuRuleset().RulesetInfo
|
|
|
|
},
|
2020-04-12 17:04:25 +00:00
|
|
|
new BeatmapInfo
|
|
|
|
{
|
2021-11-12 08:45:05 +00:00
|
|
|
OnlineID = i * 2048,
|
2020-04-12 17:04:25 +00:00
|
|
|
Metadata = metadata,
|
2022-01-18 13:57:39 +00:00
|
|
|
Difficulty = new BeatmapDifficulty(),
|
2020-04-12 17:04:25 +00:00
|
|
|
Ruleset = ruleset ?? new OsuRuleset().RulesetInfo
|
|
|
|
},
|
2020-01-29 05:23:31 +00:00
|
|
|
}
|
2022-01-25 06:23:51 +00:00
|
|
|
})?.Value;
|
2020-01-29 05:23:31 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
AddAssert($"import {i} succeeded", () => imported != null);
|
|
|
|
|
|
|
|
return () => imported;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void presentAndConfirm(Func<BeatmapSetInfo> getImport)
|
|
|
|
{
|
|
|
|
AddStep("present beatmap", () => Game.PresentBeatmap(getImport()));
|
|
|
|
|
|
|
|
AddUntilStep("wait for song select", () => Game.ScreenStack.CurrentScreen is Screens.Select.SongSelect);
|
2021-11-15 09:46:11 +00:00
|
|
|
AddUntilStep("correct beatmap displayed", () => Game.Beatmap.Value.BeatmapSetInfo.MatchesOnlineID(getImport()));
|
2021-11-24 03:49:57 +00:00
|
|
|
AddAssert("correct ruleset selected", () => Game.Ruleset.Value.Equals(getImport().Beatmaps.First().Ruleset));
|
2020-01-29 05:23:31 +00:00
|
|
|
}
|
2020-04-12 17:04:25 +00:00
|
|
|
|
|
|
|
private void presentSecondDifficultyAndConfirm(Func<BeatmapSetInfo> getImport, int importedID)
|
|
|
|
{
|
2021-11-12 08:45:05 +00:00
|
|
|
Predicate<BeatmapInfo> pred = b => b.OnlineID == importedID * 2048;
|
2020-04-12 17:04:25 +00:00
|
|
|
AddStep("present difficulty", () => Game.PresentBeatmap(getImport(), pred));
|
|
|
|
|
|
|
|
AddUntilStep("wait for song select", () => Game.ScreenStack.CurrentScreen is Screens.Select.SongSelect);
|
2021-11-12 08:45:05 +00:00
|
|
|
AddUntilStep("correct beatmap displayed", () => Game.Beatmap.Value.BeatmapInfo.OnlineID == importedID * 2048);
|
2021-11-24 03:49:57 +00:00
|
|
|
AddAssert("correct ruleset selected", () => Game.Ruleset.Value.Equals(getImport().Beatmaps.First().Ruleset));
|
2020-04-12 17:04:25 +00:00
|
|
|
}
|
2020-01-29 05:23:31 +00:00
|
|
|
}
|
|
|
|
}
|