1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 15:57:51 +08:00
osu-lazer/osu.Game.Tests/Visual/Gameplay/TestSceneSoloGameplayLeaderboard.cs

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

125 lines
5.6 KiB
C#
Raw Normal View History

2022-09-10 06:12:57 +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.
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
2022-09-10 06:12:57 +08:00
using osu.Framework.Graphics;
using osu.Framework.Testing;
2022-09-10 06:12:57 +08:00
using osu.Framework.Utils;
2022-09-26 21:11:48 +08:00
using osu.Game.Configuration;
2022-09-10 06:12:57 +08:00
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
using osu.Game.Screens.Play.HUD;
2022-11-17 20:28:04 +08:00
using osu.Game.Screens.Select;
2023-05-25 15:38:22 +08:00
using osu.Game.Tests.Gameplay;
2022-09-10 06:12:57 +08:00
namespace osu.Game.Tests.Visual.Gameplay
{
public partial class TestSceneSoloGameplayLeaderboard : OsuTestScene
2022-09-10 06:12:57 +08:00
{
2023-05-25 15:38:22 +08:00
[Cached(typeof(ScoreProcessor))]
private readonly ScoreProcessor scoreProcessor = TestGameplayState.Create(new OsuRuleset()).ScoreProcessor;
2022-09-10 06:12:57 +08:00
private readonly BindableList<ScoreInfo> scores = new BindableList<ScoreInfo>();
2022-09-10 06:12:57 +08:00
2022-09-26 21:26:13 +08:00
private readonly Bindable<bool> configVisibility = new Bindable<bool>();
2022-11-17 20:28:04 +08:00
private readonly Bindable<PlayBeatmapDetailArea.TabType> beatmapTabType = new Bindable<PlayBeatmapDetailArea.TabType>();
2022-09-26 21:11:48 +08:00
2022-09-27 13:46:35 +08:00
private SoloGameplayLeaderboard leaderboard = null!;
2022-09-26 21:11:48 +08:00
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
{
config.BindWith(OsuSetting.GameplayLeaderboard, configVisibility);
2022-11-17 20:28:04 +08:00
config.BindWith(OsuSetting.BeatmapDetailTab, beatmapTabType);
2022-09-26 21:11:48 +08:00
}
[SetUpSteps]
public void SetUpSteps()
2022-09-10 06:12:57 +08:00
{
AddStep("clear scores", () => scores.Clear());
2022-09-10 06:12:57 +08:00
AddStep("create component", () =>
2022-09-10 06:12:57 +08:00
{
var trackingUser = new APIUser
{
Username = "local user",
Id = 2,
};
2022-09-27 13:46:35 +08:00
Child = leaderboard = new SoloGameplayLeaderboard(trackingUser)
{
Scores = { BindTarget = scores },
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2022-09-27 13:46:35 +08:00
AlwaysVisible = { Value = false },
Expanded = { Value = true },
};
});
2022-09-10 06:12:57 +08:00
AddStep("add scores", () => scores.AddRange(createSampleScores()));
}
2022-09-10 06:12:57 +08:00
[Test]
public void TestLocalUser()
{
AddSliderStep("score", 0, 1000000, 500000, v => scoreProcessor.TotalScore.Value = v);
AddSliderStep("accuracy", 0f, 1f, 0.5f, v => scoreProcessor.Accuracy.Value = v);
AddSliderStep("combo", 0, 10000, 0, v => scoreProcessor.HighestCombo.Value = v);
AddStep("toggle expanded", () => leaderboard.Expanded.Value = !leaderboard.Expanded.Value);
2022-09-10 06:12:57 +08:00
}
[TestCase(PlayBeatmapDetailArea.TabType.Local, 51)]
[TestCase(PlayBeatmapDetailArea.TabType.Global, null)]
[TestCase(PlayBeatmapDetailArea.TabType.Country, null)]
[TestCase(PlayBeatmapDetailArea.TabType.Friends, null)]
public void TestTrackedScorePosition(PlayBeatmapDetailArea.TabType tabType, int? expectedOverflowIndex)
2022-11-17 20:28:04 +08:00
{
AddStep($"change TabType to {tabType}", () => beatmapTabType.Value = tabType);
AddUntilStep("tracked player is #50", () => leaderboard.TrackedScore?.ScorePosition, () => Is.EqualTo(50));
2022-11-17 20:28:04 +08:00
AddStep("add one more score", () => scores.Add(new ScoreInfo { User = new APIUser { Username = "New player 1" }, TotalScore = RNG.Next(600000, 1000000) }));
AddUntilStep("wait for sort", () => leaderboard.ChildrenOfType<GameplayLeaderboardScore>().First().ScorePosition != null);
if (expectedOverflowIndex == null)
2022-11-18 20:13:21 +08:00
AddUntilStep("tracked player has null position", () => leaderboard.TrackedScore?.ScorePosition, () => Is.Null);
else
AddUntilStep($"tracked player is #{expectedOverflowIndex}", () => leaderboard.TrackedScore?.ScorePosition, () => Is.EqualTo(expectedOverflowIndex));
2022-11-17 20:28:04 +08:00
}
2022-09-26 21:11:48 +08:00
[Test]
public void TestVisibility()
{
2022-09-27 13:46:35 +08:00
AddStep("set config visible true", () => configVisibility.Value = true);
AddUntilStep("leaderboard visible", () => leaderboard.Alpha == 1);
2022-09-26 21:11:48 +08:00
2022-09-27 13:46:35 +08:00
AddStep("set config visible false", () => configVisibility.Value = false);
AddUntilStep("leaderboard not visible", () => leaderboard.Alpha == 0);
AddStep("set always visible", () => leaderboard.AlwaysVisible.Value = true);
AddUntilStep("leaderboard visible", () => leaderboard.Alpha == 1);
AddStep("set config visible true", () => configVisibility.Value = true);
AddAssert("leaderboard still visible", () => leaderboard.Alpha == 1);
2022-09-26 21:11:48 +08:00
}
2022-11-18 04:42:15 +08:00
private static List<ScoreInfo> createSampleScores()
2022-09-10 06:12:57 +08:00
{
return new[]
{
new ScoreInfo { User = new APIUser { Username = @"peppy" }, TotalScore = RNG.Next(500000, 1000000) },
new ScoreInfo { User = new APIUser { Username = @"smoogipoo" }, TotalScore = RNG.Next(500000, 1000000) },
new ScoreInfo { User = new APIUser { Username = @"spaceman_atlas" }, TotalScore = RNG.Next(500000, 1000000) },
new ScoreInfo { User = new APIUser { Username = @"frenzibyte" }, TotalScore = RNG.Next(500000, 1000000) },
new ScoreInfo { User = new APIUser { Username = @"Susko3" }, TotalScore = RNG.Next(500000, 1000000) },
2022-11-18 04:42:15 +08:00
}.Concat(Enumerable.Range(0, 44).Select(i => new ScoreInfo { User = new APIUser { Username = $"User {i + 1}" }, TotalScore = 1000000 - i * 10000 })).ToList();
2022-09-10 06:12:57 +08:00
}
}
}