2020-04-15 17:19:17 +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-04-15 17:19:17 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2022-07-01 08:10:04 +00:00
|
|
|
using System.Diagnostics;
|
2020-04-15 17:19:17 +00:00
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
2022-06-08 14:44:57 +00:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
2020-04-15 17:19:17 +00:00
|
|
|
using osu.Framework.Testing;
|
|
|
|
using osu.Game.Beatmaps;
|
2021-11-15 09:06:56 +00:00
|
|
|
using osu.Game.Extensions;
|
2020-04-15 17:19:17 +00:00
|
|
|
using osu.Game.Rulesets;
|
2020-05-01 14:59:45 +00:00
|
|
|
using osu.Game.Rulesets.Catch;
|
|
|
|
using osu.Game.Rulesets.Mania;
|
|
|
|
using osu.Game.Rulesets.Osu;
|
|
|
|
using osu.Game.Rulesets.Taiko;
|
2021-11-24 09:29:33 +00:00
|
|
|
using osu.Game.Tests.Resources;
|
2020-04-15 17:19:17 +00:00
|
|
|
using osu.Game.Users;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.SongSelect
|
|
|
|
{
|
|
|
|
public partial class TestSceneBeatmapRecommendations : OsuGameTestScene
|
|
|
|
{
|
2022-06-08 14:44:57 +00:00
|
|
|
[Resolved]
|
|
|
|
private IRulesetStore rulesetStore { get; set; }
|
|
|
|
|
2020-04-15 17:19:17 +00:00
|
|
|
[SetUpSteps]
|
2020-05-01 14:59:45 +00:00
|
|
|
public override void SetUpSteps()
|
2020-04-15 17:19:17 +00:00
|
|
|
{
|
2020-05-01 14:59:45 +00:00
|
|
|
base.SetUpSteps();
|
|
|
|
|
2022-06-08 14:44:57 +00:00
|
|
|
AddStep("populate ruleset statistics", () =>
|
2020-04-25 07:21:01 +00:00
|
|
|
{
|
2022-06-08 14:44:57 +00:00
|
|
|
Dictionary<string, UserStatistics> rulesetStatistics = new Dictionary<string, UserStatistics>();
|
|
|
|
|
|
|
|
rulesetStore.AvailableRulesets.Where(ruleset => ruleset.IsLegacyRuleset()).ForEach(rulesetInfo =>
|
2020-04-25 07:21:01 +00:00
|
|
|
{
|
2022-06-08 14:44:57 +00:00
|
|
|
rulesetStatistics[rulesetInfo.ShortName] = new UserStatistics
|
2020-04-25 07:21:01 +00:00
|
|
|
{
|
2022-06-08 14:44:57 +00:00
|
|
|
PP = getNecessaryPP(rulesetInfo.OnlineID)
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
API.LocalUser.Value.RulesetsStatistics = rulesetStatistics;
|
|
|
|
});
|
2020-04-25 07:21:01 +00:00
|
|
|
|
|
|
|
decimal getNecessaryPP(int? rulesetID)
|
|
|
|
{
|
|
|
|
switch (rulesetID)
|
|
|
|
{
|
|
|
|
case 0:
|
2020-05-01 16:46:49 +00:00
|
|
|
return 336; // recommended star rating of 2
|
2020-04-25 07:21:01 +00:00
|
|
|
|
|
|
|
case 1:
|
2020-05-01 16:46:49 +00:00
|
|
|
return 928; // SR 3
|
2020-04-25 07:21:01 +00:00
|
|
|
|
|
|
|
case 2:
|
2020-05-01 16:46:49 +00:00
|
|
|
return 1905; // SR 4
|
2020-04-25 07:21:01 +00:00
|
|
|
|
|
|
|
case 3:
|
2020-05-01 16:46:49 +00:00
|
|
|
return 3329; // SR 5
|
2020-04-25 07:21:01 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2020-04-15 17:19:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestPresentedBeatmapIsRecommended()
|
|
|
|
{
|
2020-05-01 14:59:45 +00:00
|
|
|
List<BeatmapSetInfo> beatmapSets = null;
|
|
|
|
const int import_count = 5;
|
2020-04-17 16:55:51 +00:00
|
|
|
|
2020-05-01 14:59:45 +00:00
|
|
|
AddStep("import 5 maps", () =>
|
2020-04-17 16:55:51 +00:00
|
|
|
{
|
2020-05-01 14:59:45 +00:00
|
|
|
beatmapSets = new List<BeatmapSetInfo>();
|
2020-04-15 17:19:17 +00:00
|
|
|
|
2020-05-01 14:59:45 +00:00
|
|
|
for (int i = 0; i < import_count; ++i)
|
|
|
|
{
|
2021-11-24 09:29:33 +00:00
|
|
|
beatmapSets.Add(importBeatmapSet(Enumerable.Repeat(new OsuRuleset().RulesetInfo, 5)));
|
2020-05-01 14:59:45 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
AddAssert("all sets imported", () => ensureAllBeatmapSetsImported(beatmapSets));
|
|
|
|
|
|
|
|
presentAndConfirm(() => beatmapSets[3], 2);
|
2020-04-15 17:19:17 +00:00
|
|
|
}
|
|
|
|
|
2020-12-03 18:07:42 +00:00
|
|
|
[Test]
|
|
|
|
public void TestCurrentRulesetIsRecommended()
|
|
|
|
{
|
|
|
|
BeatmapSetInfo catchSet = null, mixedSet = null;
|
|
|
|
|
2021-11-24 09:29:33 +00:00
|
|
|
AddStep("create catch beatmapset", () => catchSet = importBeatmapSet(new[] { new CatchRuleset().RulesetInfo }));
|
|
|
|
AddStep("create mixed beatmapset", () => mixedSet = importBeatmapSet(new[] { new TaikoRuleset().RulesetInfo, new CatchRuleset().RulesetInfo, new ManiaRuleset().RulesetInfo }));
|
2020-12-03 18:07:42 +00:00
|
|
|
|
|
|
|
AddAssert("all sets imported", () => ensureAllBeatmapSetsImported(new[] { catchSet, mixedSet }));
|
|
|
|
|
|
|
|
// Switch to catch
|
|
|
|
presentAndConfirm(() => catchSet, 1);
|
|
|
|
|
2022-01-10 07:34:16 +00:00
|
|
|
AddAssert("game-wide ruleset changed", () => Game.Ruleset.Value.Equals(catchSet.Beatmaps.First().Ruleset));
|
|
|
|
|
2020-12-03 18:07:42 +00:00
|
|
|
// Present mixed difficulty set, expect current ruleset to be selected
|
|
|
|
presentAndConfirm(() => mixedSet, 2);
|
|
|
|
}
|
|
|
|
|
2020-04-17 16:55:51 +00:00
|
|
|
[Test]
|
|
|
|
public void TestBestRulesetIsRecommended()
|
2020-04-15 17:19:17 +00:00
|
|
|
{
|
2020-05-01 14:59:45 +00:00
|
|
|
BeatmapSetInfo osuSet = null, mixedSet = null;
|
|
|
|
|
2021-11-24 09:29:33 +00:00
|
|
|
AddStep("create osu! beatmapset", () => osuSet = importBeatmapSet(new[] { new OsuRuleset().RulesetInfo }));
|
|
|
|
AddStep("create mixed beatmapset", () => mixedSet = importBeatmapSet(new[] { new TaikoRuleset().RulesetInfo, new CatchRuleset().RulesetInfo, new ManiaRuleset().RulesetInfo }));
|
2020-04-15 17:19:17 +00:00
|
|
|
|
2020-05-01 14:59:45 +00:00
|
|
|
AddAssert("all sets imported", () => ensureAllBeatmapSetsImported(new[] { osuSet, mixedSet }));
|
2020-04-17 16:55:51 +00:00
|
|
|
|
|
|
|
// Make sure we are on standard ruleset
|
2020-05-01 14:59:45 +00:00
|
|
|
presentAndConfirm(() => osuSet, 1);
|
2020-04-17 16:55:51 +00:00
|
|
|
|
|
|
|
// Present mixed difficulty set, expect ruleset with highest star difficulty
|
2020-05-01 14:59:45 +00:00
|
|
|
presentAndConfirm(() => mixedSet, 3);
|
2020-04-17 16:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestSecondBestRulesetIsRecommended()
|
|
|
|
{
|
2020-05-01 14:59:45 +00:00
|
|
|
BeatmapSetInfo osuSet = null, mixedSet = null;
|
2020-04-17 16:55:51 +00:00
|
|
|
|
2021-11-24 09:29:33 +00:00
|
|
|
AddStep("create osu! beatmapset", () => osuSet = importBeatmapSet(new[] { new OsuRuleset().RulesetInfo }));
|
|
|
|
AddStep("create mixed beatmapset", () => mixedSet = importBeatmapSet(new[] { new TaikoRuleset().RulesetInfo, new CatchRuleset().RulesetInfo, new TaikoRuleset().RulesetInfo }));
|
2020-05-01 14:59:45 +00:00
|
|
|
|
|
|
|
AddAssert("all sets imported", () => ensureAllBeatmapSetsImported(new[] { osuSet, mixedSet }));
|
2020-04-17 16:55:51 +00:00
|
|
|
|
|
|
|
// Make sure we are on standard ruleset
|
2020-05-01 14:59:45 +00:00
|
|
|
presentAndConfirm(() => osuSet, 1);
|
2020-04-15 17:19:17 +00:00
|
|
|
|
2020-04-25 07:37:18 +00:00
|
|
|
// Present mixed difficulty set, expect ruleset with second highest star difficulty
|
2020-05-01 14:59:45 +00:00
|
|
|
presentAndConfirm(() => mixedSet, 2);
|
2020-04-15 17:19:17 +00:00
|
|
|
}
|
|
|
|
|
2020-05-01 16:08:56 +00:00
|
|
|
[Test]
|
|
|
|
public void TestCorrectStarRatingIsUsed()
|
|
|
|
{
|
|
|
|
BeatmapSetInfo osuSet = null, maniaSet = null;
|
|
|
|
|
2021-11-24 09:29:33 +00:00
|
|
|
AddStep("create osu! beatmapset", () => osuSet = importBeatmapSet(new[] { new OsuRuleset().RulesetInfo }));
|
|
|
|
AddStep("create mania beatmapset", () => maniaSet = importBeatmapSet(Enumerable.Repeat(new ManiaRuleset().RulesetInfo, 10)));
|
2020-05-01 16:08:56 +00:00
|
|
|
|
|
|
|
AddAssert("all sets imported", () => ensureAllBeatmapSetsImported(new[] { osuSet, maniaSet }));
|
|
|
|
|
|
|
|
// Make sure we are on standard ruleset
|
|
|
|
presentAndConfirm(() => osuSet, 1);
|
|
|
|
|
|
|
|
// Present mania set, expect the difficulty that matches recommended mania star rating
|
|
|
|
presentAndConfirm(() => maniaSet, 5);
|
|
|
|
}
|
|
|
|
|
2021-11-24 09:29:33 +00:00
|
|
|
private BeatmapSetInfo importBeatmapSet(IEnumerable<RulesetInfo> difficultyRulesets)
|
2020-04-15 17:19:17 +00:00
|
|
|
{
|
2021-11-24 09:29:33 +00:00
|
|
|
var rulesets = difficultyRulesets.ToArray();
|
2020-04-15 17:19:17 +00:00
|
|
|
|
2021-11-24 09:29:33 +00:00
|
|
|
var beatmapSet = TestResources.CreateTestBeatmapSetInfo(rulesets.Length, rulesets);
|
2020-04-15 17:19:17 +00:00
|
|
|
|
2022-07-01 08:10:04 +00:00
|
|
|
var importedBeatmapSet = Game.BeatmapManager.Import(beatmapSet);
|
|
|
|
|
|
|
|
Debug.Assert(importedBeatmapSet != null);
|
|
|
|
|
|
|
|
importedBeatmapSet.PerformWrite(s =>
|
2021-11-24 04:25:26 +00:00
|
|
|
{
|
2022-07-01 08:10:04 +00:00
|
|
|
for (int i = 0; i < rulesets.Length; i++)
|
|
|
|
{
|
|
|
|
var beatmap = s.Beatmaps[i];
|
2021-11-24 09:29:33 +00:00
|
|
|
|
2022-07-01 08:10:04 +00:00
|
|
|
beatmap.StarRating = i + 1;
|
|
|
|
beatmap.DifficultyName = $"SR{i + 1}";
|
|
|
|
}
|
|
|
|
});
|
2021-11-24 04:25:26 +00:00
|
|
|
|
2022-07-01 08:10:04 +00:00
|
|
|
return importedBeatmapSet.Value;
|
2020-04-15 17:19:17 +00:00
|
|
|
}
|
|
|
|
|
2020-05-01 14:59:45 +00:00
|
|
|
private bool ensureAllBeatmapSetsImported(IEnumerable<BeatmapSetInfo> beatmapSets) => beatmapSets.All(set => set != null);
|
|
|
|
|
2020-04-25 07:36:19 +00:00
|
|
|
private void presentAndConfirm(Func<BeatmapSetInfo> getImport, int expectedDiff)
|
2020-04-15 17:19:17 +00:00
|
|
|
{
|
|
|
|
AddStep("present beatmap", () => Game.PresentBeatmap(getImport()));
|
|
|
|
|
|
|
|
AddUntilStep("wait for song select", () => Game.ScreenStack.CurrentScreen is Screens.Select.SongSelect);
|
2021-11-15 09:06:56 +00:00
|
|
|
AddUntilStep("recommended beatmap displayed", () => Game.Beatmap.Value.BeatmapInfo.MatchesOnlineID(getImport().Beatmaps[expectedDiff - 1]));
|
2020-04-15 17:19:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|