1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 12:57:36 +08:00
osu-lazer/osu.Game.Tests/Visual/Navigation/TestScenePresentBeatmap.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

206 lines
8.0 KiB
C#
Raw Normal View History

2020-01-29 13:23:31 +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.
2022-06-17 15:37:17 +08:00
#nullable disable
2020-01-29 13:23:31 +08:00
using System;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Screens;
using osu.Framework.Testing;
2020-01-29 13:23:31 +08:00
using osu.Game.Beatmaps;
2022-11-25 19:06:36 +08:00
using osu.Game.Configuration;
using osu.Game.Extensions;
2020-01-29 13:23:31 +08:00
using osu.Game.Rulesets;
2022-11-25 19:06:36 +08:00
using osu.Game.Rulesets.Catch;
2020-01-29 13:23:31 +08:00
using osu.Game.Rulesets.Mania;
using osu.Game.Rulesets.Osu;
using osu.Game.Screens.Menu;
using osu.Game.Screens.Select;
2020-01-29 13:23:31 +08:00
namespace osu.Game.Tests.Visual.Navigation
{
public partial class TestScenePresentBeatmap : OsuGameTestScene
{
[Test]
public void TestFromMainMenu()
{
var firstImport = importBeatmap(1);
var secondImport = importBeatmap(3);
2020-01-29 13:23:31 +08:00
2020-04-13 01:04:25 +08:00
presentAndConfirm(firstImport);
returnToMenu();
presentAndConfirm(secondImport);
2020-04-13 01:04:25 +08:00
returnToMenu();
presentSecondDifficultyAndConfirm(firstImport, 1);
returnToMenu();
presentSecondDifficultyAndConfirm(secondImport, 3);
2020-01-29 13:23:31 +08:00
}
[Test]
public void TestFromMainMenuDifferentRuleset()
{
var firstImport = importBeatmap(1);
var secondImport = importBeatmap(3, new ManiaRuleset().RulesetInfo);
2020-01-29 13:23:31 +08:00
2020-04-13 01:04:25 +08:00
presentAndConfirm(firstImport);
returnToMenu();
presentAndConfirm(secondImport);
2020-04-13 01:04:25 +08:00
returnToMenu();
presentSecondDifficultyAndConfirm(firstImport, 1);
returnToMenu();
presentSecondDifficultyAndConfirm(secondImport, 3);
2020-01-29 13:23:31 +08:00
}
[Test]
public void TestFromSongSelect()
{
var firstImport = importBeatmap(1);
presentAndConfirm(firstImport);
var secondImport = importBeatmap(3);
confirmBeatmapInSongSelect(secondImport);
presentAndConfirm(secondImport);
2020-04-13 01:04:25 +08:00
// Test presenting same beatmap more than once
presentAndConfirm(secondImport);
2020-04-13 01:04:25 +08:00
presentSecondDifficultyAndConfirm(firstImport, 1);
presentSecondDifficultyAndConfirm(secondImport, 3);
// Test presenting same beatmap more than once
presentSecondDifficultyAndConfirm(secondImport, 3);
2020-01-29 13:23:31 +08:00
}
[Test]
2022-11-25 19:06:36 +08:00
public void TestFromSongSelectDifferentRulesetWithConvertDisallowed()
2020-01-29 13:23:31 +08:00
{
2022-11-25 19:06:36 +08:00
AddStep("Set converts disallowed", () => Game.LocalConfig.SetValue(OsuSetting.ShowConvertedBeatmaps, false));
2020-01-29 13:23:31 +08:00
2022-11-25 19:06:36 +08:00
var osuImport = importBeatmap(1);
presentAndConfirm(osuImport);
2020-04-13 01:04:25 +08:00
2022-11-25 19:06:36 +08:00
var maniaImport = importBeatmap(2, new ManiaRuleset().RulesetInfo);
confirmBeatmapInSongSelect(maniaImport);
presentAndConfirm(maniaImport);
var catchImport = importBeatmap(3, new CatchRuleset().RulesetInfo);
confirmBeatmapInSongSelect(catchImport);
presentAndConfirm(catchImport);
// Ruleset is always changed.
presentSecondDifficultyAndConfirm(maniaImport, 2);
presentSecondDifficultyAndConfirm(osuImport, 1);
presentSecondDifficultyAndConfirm(catchImport, 3);
}
[Test]
public void TestFromSongSelectDifferentRulesetWithConvertAllowed()
{
AddStep("Set converts allowed", () => Game.LocalConfig.SetValue(OsuSetting.ShowConvertedBeatmaps, true));
var osuImport = importBeatmap(1);
presentAndConfirm(osuImport);
var maniaImport = importBeatmap(2, new ManiaRuleset().RulesetInfo);
confirmBeatmapInSongSelect(maniaImport);
presentAndConfirm(maniaImport);
var catchImport = importBeatmap(3, new CatchRuleset().RulesetInfo);
confirmBeatmapInSongSelect(catchImport);
presentAndConfirm(catchImport);
// force ruleset to osu!mania
presentSecondDifficultyAndConfirm(maniaImport, 2);
// ruleset is not changed as we can convert osu! beatmap.
presentSecondDifficultyAndConfirm(osuImport, 1, expectedRulesetOnlineID: 3);
// ruleset is changed as we cannot convert.
presentSecondDifficultyAndConfirm(catchImport, 3);
2020-04-13 01:04:25 +08:00
}
private void returnToMenu()
{
// 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-13 01:04:25 +08:00
AddStep("return to menu", () => Game.ScreenStack.CurrentScreen.Exit());
AddUntilStep("wait for menu", () => Game.ScreenStack.CurrentScreen is MainMenu);
2020-01-29 13:23:31 +08: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 22:30:40 +08:00
Author = { Username = "SomeAuthor" },
2020-01-29 13:23:31 +08:00
Title = $"import {i}"
};
imported = Game.BeatmapManager.Import(new BeatmapSetInfo
{
Hash = Guid.NewGuid().ToString(),
2022-11-25 19:06:36 +08:00
OnlineID = i * 1024,
Beatmaps =
2020-01-29 13:23:31 +08:00
{
new BeatmapInfo
{
2022-11-25 19:06:36 +08:00
OnlineID = i * 1024 + 1,
2020-01-29 13:23:31 +08:00
Metadata = metadata,
Difficulty = new BeatmapDifficulty(),
2020-01-29 13:23:31 +08:00
Ruleset = ruleset ?? new OsuRuleset().RulesetInfo
},
2020-04-13 01:04:25 +08:00
new BeatmapInfo
{
2022-11-25 19:06:36 +08:00
OnlineID = i * 1024 + 2,
2020-04-13 01:04:25 +08:00
Metadata = metadata,
Difficulty = new BeatmapDifficulty(),
2020-04-13 01:04:25 +08:00
Ruleset = ruleset ?? new OsuRuleset().RulesetInfo
},
2020-01-29 13:23:31 +08:00
}
})?.Value;
2020-01-29 13:23:31 +08:00
});
AddAssert($"import {i} succeeded", () => imported != null);
return () => imported;
}
private void confirmBeatmapInSongSelect(Func<BeatmapSetInfo> getImport)
{
AddUntilStep("beatmap in song select", () =>
{
var songSelect = (Screens.Select.SongSelect)Game.ScreenStack.CurrentScreen;
return songSelect.ChildrenOfType<BeatmapCarousel>().Single().BeatmapSets.Any(b => b.MatchesOnlineID(getImport()));
});
}
2020-01-29 13:23:31 +08:00
private void presentAndConfirm(Func<BeatmapSetInfo> getImport)
{
AddStep("present beatmap", () => Game.PresentBeatmap(getImport()));
AddUntilStep("wait for song select", () => Game.ScreenStack.CurrentScreen is Screens.Select.SongSelect songSelect && songSelect.IsLoaded);
AddUntilStep("correct beatmap displayed", () => Game.Beatmap.Value.BeatmapSetInfo.OnlineID, () => Is.EqualTo(getImport().OnlineID));
AddAssert("correct ruleset selected", () => Game.Ruleset.Value, () => Is.EqualTo(getImport().Beatmaps.First().Ruleset));
2020-01-29 13:23:31 +08:00
}
2020-04-13 01:04:25 +08:00
2022-11-25 19:06:36 +08:00
private void presentSecondDifficultyAndConfirm(Func<BeatmapSetInfo> getImport, int importedID, int? expectedRulesetOnlineID = null)
2020-04-13 01:04:25 +08:00
{
2022-11-25 19:06:36 +08:00
Predicate<BeatmapInfo> pred = b => b.OnlineID == importedID * 1024 + 2;
2020-04-13 01:04:25 +08:00
AddStep("present difficulty", () => Game.PresentBeatmap(getImport(), pred));
AddUntilStep("wait for song select", () => Game.ScreenStack.CurrentScreen is Screens.Select.SongSelect songSelect && songSelect.IsLoaded);
2022-11-25 19:06:36 +08:00
AddUntilStep("correct beatmap displayed", () => Game.Beatmap.Value.BeatmapInfo.OnlineID, () => Is.EqualTo(importedID * 1024 + 2));
AddAssert("correct ruleset selected", () => Game.Ruleset.Value.OnlineID, () => Is.EqualTo(expectedRulesetOnlineID ?? getImport().Beatmaps.First().Ruleset.OnlineID));
2020-04-13 01:04:25 +08:00
}
2020-01-29 13:23:31 +08:00
}
}