1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 04:22:54 +08:00
osu-lazer/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapLeaderboard.cs

404 lines
14 KiB
C#
Raw Normal View History

// 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.
2018-04-13 17:19:50 +08:00
2018-06-28 12:04:39 +08:00
using System;
2021-06-14 14:06:33 +08:00
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
2021-06-14 14:06:33 +08:00
using osu.Framework.Audio;
2019-03-25 00:02:36 +08:00
using osu.Framework.Graphics;
2021-06-14 14:06:33 +08:00
using osu.Framework.Platform;
using osu.Framework.Testing;
2018-04-13 17:19:50 +08:00
using osu.Game.Beatmaps;
using osu.Game.Online.Leaderboards;
using osu.Game.Overlays;
2021-06-14 14:06:33 +08:00
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
2019-09-19 14:23:37 +08:00
using osu.Game.Rulesets.Osu.Mods;
2018-11-28 15:12:57 +08:00
using osu.Game.Scoring;
2019-03-25 00:02:36 +08:00
using osu.Game.Screens.Select.Leaderboards;
2021-06-14 14:06:33 +08:00
using osu.Game.Tests.Resources;
2019-03-25 00:02:36 +08:00
using osu.Game.Users;
using osuTK;
2018-04-13 17:19:50 +08:00
2019-03-25 00:02:36 +08:00
namespace osu.Game.Tests.Visual.SongSelect
2018-04-13 17:19:50 +08:00
{
2019-09-19 12:19:48 +08:00
public class TestSceneBeatmapLeaderboard : OsuTestScene
2018-04-13 17:19:50 +08:00
{
private readonly FailableLeaderboard leaderboard;
[Cached]
2019-12-20 13:57:14 +08:00
private readonly DialogOverlay dialogOverlay;
2021-06-14 14:06:33 +08:00
private ScoreManager scoreManager;
private RulesetStore rulesetStore;
private BeatmapManager beatmapManager;
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
dependencies.Cache(rulesetStore = new RulesetStore(ContextFactory));
dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, ContextFactory, rulesetStore, null, dependencies.Get<AudioManager>(), Resources, dependencies.Get<GameHost>(), Beatmap.Default));
dependencies.Cache(scoreManager = new ScoreManager(rulesetStore, () => beatmapManager, LocalStorage, null, ContextFactory));
return dependencies;
}
2019-09-19 12:19:48 +08:00
public TestSceneBeatmapLeaderboard()
2018-04-13 17:19:50 +08:00
{
2021-06-14 14:06:33 +08:00
AddRange(new Drawable[]
{
2021-06-14 14:06:33 +08:00
dialogOverlay = new DialogOverlay
{
Depth = -1
},
leaderboard = new FailableLeaderboard
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Size = new Vector2(550f, 450f),
Scope = BeatmapLeaderboardScope.Global,
}
});
2021-06-14 14:06:33 +08:00
}
[Test]
public void TestLocalScoresDisplay()
{
BeatmapInfo beatmapInfo = null;
AddStep(@"Set scope", () => leaderboard.Scope = BeatmapLeaderboardScope.Local);
2021-06-14 14:06:33 +08:00
AddStep(@"Set beatmap", () =>
2018-04-13 17:19:50 +08:00
{
2021-06-14 14:06:33 +08:00
beatmapManager.Import(TestResources.GetQuickTestBeatmapForImport()).Wait();
beatmapInfo = beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps.First();
leaderboard.Beatmap = beatmapInfo;
});
2021-06-14 14:06:33 +08:00
clearScores();
checkCount(0);
loadMoreScores(() => beatmapInfo);
checkCount(10);
loadMoreScores(() => beatmapInfo);
checkCount(20);
clearScores();
checkCount(0);
}
2018-04-13 17:19:50 +08:00
[Test]
2021-06-14 14:06:33 +08:00
public void TestGlobalScoresDisplay()
{
2021-06-14 14:06:33 +08:00
AddStep(@"Set scope", () => leaderboard.Scope = BeatmapLeaderboardScope.Global);
AddStep(@"New Scores", () => leaderboard.Scores = generateSampleScores(null));
}
[Test]
public void TestPersonalBest()
{
2019-09-19 14:23:37 +08:00
AddStep(@"Show personal best", showPersonalBest);
AddStep("null personal best position", showPersonalBestWithNullPosition);
}
[Test]
public void TestPlaceholderStates()
{
2018-04-13 17:19:50 +08:00
AddStep(@"Empty Scores", () => leaderboard.SetRetrievalState(PlaceholderState.NoScores));
AddStep(@"Network failure", () => leaderboard.SetRetrievalState(PlaceholderState.NetworkFailure));
AddStep(@"No supporter", () => leaderboard.SetRetrievalState(PlaceholderState.NotSupporter));
AddStep(@"Not logged in", () => leaderboard.SetRetrievalState(PlaceholderState.NotLoggedIn));
AddStep(@"Unavailable", () => leaderboard.SetRetrievalState(PlaceholderState.Unavailable));
AddStep(@"None selected", () => leaderboard.SetRetrievalState(PlaceholderState.NoneSelected));
}
[Test]
public void TestBeatmapStates()
{
2019-07-07 12:06:31 +08:00
foreach (BeatmapSetOnlineStatus status in Enum.GetValues(typeof(BeatmapSetOnlineStatus)))
AddStep($"{status} beatmap", () => showBeatmapWithStatus(status));
2020-02-20 13:51:25 +08:00
}
private void showPersonalBestWithNullPosition()
{
leaderboard.TopScore = new ScoreInfo
2020-02-20 13:51:25 +08:00
{
Rank = ScoreRank.XH,
Accuracy = 1,
MaxCombo = 244,
TotalScore = 1707827,
Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock() },
User = new User
2020-02-20 13:51:25 +08:00
{
Id = 6602580,
Username = @"waaiiru",
Country = new Country
2020-02-20 13:51:25 +08:00
{
FullName = @"Spain",
FlagName = @"ES",
2020-02-20 13:51:25 +08:00
},
},
2020-02-20 13:51:25 +08:00
};
2018-04-13 17:19:50 +08:00
}
2019-09-19 14:23:37 +08:00
private void showPersonalBest()
{
leaderboard.TopScore = new ScoreInfo
2019-09-19 14:23:37 +08:00
{
Position = 999,
Rank = ScoreRank.XH,
Accuracy = 1,
MaxCombo = 244,
TotalScore = 1707827,
Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
User = new User
2019-09-19 14:23:37 +08:00
{
Id = 6602580,
Username = @"waaiiru",
Country = new Country
2019-09-19 14:23:37 +08:00
{
FullName = @"Spain",
FlagName = @"ES",
2019-09-19 14:23:37 +08:00
},
},
2019-09-19 14:23:37 +08:00
};
}
2021-06-14 14:06:33 +08:00
private void loadMoreScores(Func<BeatmapInfo> beatmapInfo)
2018-04-13 17:19:50 +08:00
{
2021-06-14 14:06:33 +08:00
AddStep(@"Load new scores via manager", () =>
{
foreach (var score in generateSampleScores(beatmapInfo()))
scoreManager.Import(score).Wait();
});
}
private void clearScores()
{
AddStep("Clear all scores", () => scoreManager.Delete(scoreManager.GetAllUsableScores()));
}
private void checkCount(int expected) =>
AddUntilStep("Correct count displayed", () => leaderboard.ChildrenOfType<LeaderboardScore>().Count() == expected);
private static ScoreInfo[] generateSampleScores(BeatmapInfo beatmap)
{
return new[]
2018-04-13 17:19:50 +08:00
{
2018-11-28 17:33:01 +08:00
new ScoreInfo
2018-04-13 17:19:50 +08:00
{
Rank = ScoreRank.XH,
Accuracy = 1,
MaxCombo = 244,
TotalScore = 1707827,
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
2021-06-14 14:06:33 +08:00
Beatmap = beatmap,
2018-04-13 17:19:50 +08:00
User = new User
{
Id = 6602580,
Username = @"waaiiru",
Country = new Country
{
FullName = @"Spain",
FlagName = @"ES",
},
},
},
2018-11-28 17:33:01 +08:00
new ScoreInfo
2018-04-13 17:19:50 +08:00
{
Rank = ScoreRank.X,
Accuracy = 1,
MaxCombo = 244,
TotalScore = 1707827,
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
2021-06-14 14:06:33 +08:00
Beatmap = beatmap,
2018-04-13 17:19:50 +08:00
User = new User
{
Id = 4608074,
Username = @"Skycries",
Country = new Country
{
FullName = @"Brazil",
FlagName = @"BR",
},
},
},
2018-11-28 17:33:01 +08:00
new ScoreInfo
2018-04-13 17:19:50 +08:00
{
Rank = ScoreRank.SH,
Accuracy = 1,
MaxCombo = 244,
TotalScore = 1707827,
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
2021-06-14 14:06:33 +08:00
Beatmap = beatmap,
2018-04-13 17:19:50 +08:00
User = new User
{
Id = 1014222,
Username = @"eLy",
Country = new Country
{
FullName = @"Japan",
FlagName = @"JP",
},
},
},
2018-11-28 17:33:01 +08:00
new ScoreInfo
2018-04-13 17:19:50 +08:00
{
Rank = ScoreRank.S,
Accuracy = 1,
MaxCombo = 244,
TotalScore = 1707827,
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
2021-06-14 14:06:33 +08:00
Beatmap = beatmap,
2018-04-13 17:19:50 +08:00
User = new User
{
Id = 1541390,
Username = @"Toukai",
Country = new Country
{
FullName = @"Canada",
FlagName = @"CA",
},
},
},
2018-11-28 17:33:01 +08:00
new ScoreInfo
2018-04-13 17:19:50 +08:00
{
Rank = ScoreRank.A,
Accuracy = 1,
MaxCombo = 244,
TotalScore = 1707827,
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
2021-06-14 14:06:33 +08:00
Beatmap = beatmap,
2018-04-13 17:19:50 +08:00
User = new User
{
Id = 2243452,
Username = @"Satoruu",
Country = new Country
{
FullName = @"Venezuela",
FlagName = @"VE",
},
},
},
2018-11-28 17:33:01 +08:00
new ScoreInfo
2018-04-13 17:19:50 +08:00
{
Rank = ScoreRank.B,
Accuracy = 0.9826,
MaxCombo = 244,
TotalScore = 1707827,
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
2021-06-14 14:06:33 +08:00
Beatmap = beatmap,
2018-04-13 17:19:50 +08:00
User = new User
{
Id = 2705430,
Username = @"Mooha",
Country = new Country
{
FullName = @"France",
FlagName = @"FR",
},
},
},
2018-11-28 17:33:01 +08:00
new ScoreInfo
2018-04-13 17:19:50 +08:00
{
Rank = ScoreRank.C,
Accuracy = 0.9654,
MaxCombo = 244,
TotalScore = 1707827,
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
2021-06-14 14:06:33 +08:00
Beatmap = beatmap,
2018-04-13 17:19:50 +08:00
User = new User
{
Id = 7151382,
Username = @"Mayuri Hana",
Country = new Country
{
FullName = @"Thailand",
FlagName = @"TH",
},
},
},
2018-11-28 17:33:01 +08:00
new ScoreInfo
2018-04-13 17:19:50 +08:00
{
2019-06-09 00:34:03 +08:00
Rank = ScoreRank.D,
2018-04-13 17:19:50 +08:00
Accuracy = 0.6025,
MaxCombo = 244,
TotalScore = 1707827,
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
2021-06-14 14:06:33 +08:00
Beatmap = beatmap,
2018-04-13 17:19:50 +08:00
User = new User
{
Id = 2051389,
Username = @"FunOrange",
Country = new Country
{
FullName = @"Canada",
FlagName = @"CA",
},
},
},
2018-11-28 17:33:01 +08:00
new ScoreInfo
2018-04-13 17:19:50 +08:00
{
2019-06-09 00:34:03 +08:00
Rank = ScoreRank.D,
2018-04-13 17:19:50 +08:00
Accuracy = 0.5140,
MaxCombo = 244,
TotalScore = 1707827,
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
2021-06-14 14:06:33 +08:00
Beatmap = beatmap,
2018-04-13 17:19:50 +08:00
User = new User
{
Id = 6169483,
Username = @"-Hebel-",
Country = new Country
{
FullName = @"Mexico",
FlagName = @"MX",
},
},
},
2018-11-28 17:33:01 +08:00
new ScoreInfo
2018-04-13 17:19:50 +08:00
{
2019-06-09 00:34:03 +08:00
Rank = ScoreRank.D,
2018-04-13 17:19:50 +08:00
Accuracy = 0.4222,
MaxCombo = 244,
TotalScore = 1707827,
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
2021-06-14 14:06:33 +08:00
Beatmap = beatmap,
2018-04-13 17:19:50 +08:00
User = new User
{
Id = 6702666,
Username = @"prhtnsm",
Country = new Country
{
FullName = @"Germany",
FlagName = @"DE",
},
},
},
};
}
2019-07-07 12:06:31 +08:00
private void showBeatmapWithStatus(BeatmapSetOnlineStatus status)
2018-04-13 17:19:50 +08:00
{
leaderboard.Beatmap = new BeatmapInfo
{
OnlineBeatmapID = 1113057,
2019-07-07 12:06:31 +08:00
Status = status,
2019-07-05 12:25:10 +08:00
};
}
private class FailableLeaderboard : BeatmapLeaderboard
2018-04-13 17:19:50 +08:00
{
public void SetRetrievalState(PlaceholderState state)
{
PlaceholderState = state;
}
}
}
}