Make GameplayLeaderboardScore a model class

This commit is contained in:
Salman Ahmed
2020-12-18 03:34:33 +03:00
parent 0faf3fdfd3
commit a8abefcd66
3 changed files with 17 additions and 49 deletions

View File

@ -2,11 +2,8 @@
// See the LICENCE file in the repository root for full licence text.
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Users;
using osuTK;
namespace osu.Game.Screens.Play.HUD
@ -25,44 +22,12 @@ namespace osu.Game.Screens.Play.HUD
LayoutEasing = Easing.OutQuint;
}
/// <summary>
/// Adds a player to the leaderboard.
/// </summary>
/// <param name="totalScore">A bindable of the player's total score.</param>
/// <param name="accuracy">A bindable of the player's accuracy.</param>
/// <param name="combo">A bindable of the player's current combo.</param>
/// <param name="user">The player.</param>
public void AddPlayer([NotNull] IBindableNumber<double> totalScore,
[NotNull] IBindableNumber<double> accuracy,
[NotNull] IBindableNumber<int> combo,
[NotNull] User user)
public override void Add(GameplayLeaderboardScore drawable)
{
AddPlayer(totalScore, accuracy, combo, user, false);
base.Add(drawable);
drawable?.TotalScore.BindValueChanged(_ => updateScores(), true);
}
/// <summary>
/// Adds a player to the leaderboard.
/// </summary>
/// <param name="totalScore">A bindable of the player's total score.</param>
/// <param name="accuracy">A bindable of the player's accuracy.</param>
/// <param name="combo">A bindable of the player's current combo.</param>
/// <param name="user">The player.</param>
/// <param name="localUser">Whether the provided <paramref name="user"/> is the local user.</param>
protected void AddPlayer([NotNull] IBindableNumber<double> totalScore,
[NotNull] IBindableNumber<double> accuracy,
[NotNull] IBindableNumber<int> combo,
[NotNull] User user, bool localUser) => Schedule(() =>
{
Add(new GameplayLeaderboardScore(user, localUser)
{
TotalScore = { BindTarget = totalScore },
Accuracy = { BindTarget = accuracy },
Combo = { BindTarget = combo },
});
totalScore.BindValueChanged(_ => updateScores(), true);
});
private void updateScores()
{
var orderedByScore = this.OrderByDescending(i => i.TotalScore.Value).ToList();