2019-07-29 11:52:42 +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.Linq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
2020-12-15 14:22:14 +08:00
|
|
|
using osu.Framework.Testing;
|
2020-12-15 14:27:26 +08:00
|
|
|
using osu.Game.Screens.Play.HUD;
|
2019-07-29 11:52:42 +08:00
|
|
|
using osu.Game.Users;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Gameplay
|
|
|
|
{
|
|
|
|
[TestFixture]
|
2020-12-15 14:27:26 +08:00
|
|
|
public class TestSceneGameplayLeaderboard : OsuTestScene
|
2019-07-29 11:52:42 +08:00
|
|
|
{
|
2020-12-15 14:27:26 +08:00
|
|
|
private readonly TestGameplayLeaderboard leaderboard;
|
2019-07-29 11:52:42 +08:00
|
|
|
|
2020-12-15 14:27:26 +08:00
|
|
|
private readonly BindableDouble playerScore = new BindableDouble();
|
|
|
|
|
|
|
|
public TestSceneGameplayLeaderboard()
|
2019-07-29 11:52:42 +08:00
|
|
|
{
|
2020-12-15 14:27:26 +08:00
|
|
|
Add(leaderboard = new TestGameplayLeaderboard
|
2019-07-29 11:52:42 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Scale = new Vector2(2),
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-12-15 14:22:14 +08:00
|
|
|
[SetUpSteps]
|
|
|
|
public void SetUpSteps()
|
2019-08-04 23:28:40 +08:00
|
|
|
{
|
2020-12-15 14:22:14 +08:00
|
|
|
AddStep("reset leaderboard", () =>
|
|
|
|
{
|
2020-12-15 14:27:26 +08:00
|
|
|
leaderboard.Clear();
|
2020-12-15 14:22:14 +08:00
|
|
|
playerScore.Value = 1222333;
|
|
|
|
});
|
|
|
|
|
2020-12-15 14:44:43 +08:00
|
|
|
AddStep("add player user", () => leaderboard.AddPlayer(playerScore, new User { Username = "You" }));
|
2020-12-15 14:22:14 +08:00
|
|
|
AddSliderStep("set player score", 50, 5000000, 1222333, v => playerScore.Value = v);
|
2019-08-04 23:28:40 +08:00
|
|
|
}
|
2019-07-30 17:37:01 +08:00
|
|
|
|
2019-07-29 11:52:42 +08:00
|
|
|
[Test]
|
|
|
|
public void TestPlayerScore()
|
|
|
|
{
|
|
|
|
var player2Score = new BindableDouble(1234567);
|
|
|
|
var player3Score = new BindableDouble(1111111);
|
|
|
|
|
2020-12-15 14:44:43 +08:00
|
|
|
AddStep("add player 2", () => leaderboard.AddPlayer(player2Score, new User { Username = "Player 2" }));
|
|
|
|
AddStep("add player 3", () => leaderboard.AddPlayer(player3Score, new User { Username = "Player 3" }));
|
2019-07-29 11:52:42 +08:00
|
|
|
|
|
|
|
AddAssert("is player 2 position #1", () => leaderboard.CheckPositionByUsername("Player 2", 1));
|
|
|
|
AddAssert("is player position #2", () => leaderboard.CheckPositionByUsername("You", 2));
|
|
|
|
AddAssert("is player 3 position #3", () => leaderboard.CheckPositionByUsername("Player 3", 3));
|
|
|
|
|
|
|
|
AddStep("set score above player 3", () => player2Score.Value = playerScore.Value - 500);
|
|
|
|
AddAssert("is player position #1", () => leaderboard.CheckPositionByUsername("You", 1));
|
|
|
|
AddAssert("is player 2 position #2", () => leaderboard.CheckPositionByUsername("Player 2", 2));
|
|
|
|
AddAssert("is player 3 position #3", () => leaderboard.CheckPositionByUsername("Player 3", 3));
|
|
|
|
|
|
|
|
AddStep("set score below players", () => player2Score.Value = playerScore.Value - 123456);
|
|
|
|
AddAssert("is player position #1", () => leaderboard.CheckPositionByUsername("You", 1));
|
|
|
|
AddAssert("is player 3 position #2", () => leaderboard.CheckPositionByUsername("Player 3", 2));
|
|
|
|
AddAssert("is player 2 position #3", () => leaderboard.CheckPositionByUsername("Player 2", 3));
|
|
|
|
}
|
|
|
|
|
2020-12-15 14:27:26 +08:00
|
|
|
private class TestGameplayLeaderboard : GameplayLeaderboard
|
2019-07-29 11:52:42 +08:00
|
|
|
{
|
2020-12-15 14:27:26 +08:00
|
|
|
public bool CheckPositionByUsername(string username, int? expectedPosition)
|
2019-07-29 11:52:42 +08:00
|
|
|
{
|
2020-12-15 14:27:26 +08:00
|
|
|
var scoreItem = this.FirstOrDefault(i => i.User.Username == username);
|
2019-07-29 11:52:42 +08:00
|
|
|
|
2020-12-15 14:27:26 +08:00
|
|
|
return scoreItem != null && scoreItem.ScorePosition == expectedPosition;
|
2019-07-29 11:52:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|