mirror of
https://github.com/ppy/osu.git
synced 2025-01-27 10:23:03 +08:00
Merge pull request #23937 from peppy/order-by-total-score-extension
Move `OrderByTotalScore()` to an extension method
This commit is contained in:
commit
2976145150
@ -47,9 +47,6 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private RulesetStore rulesets { get; set; }
|
private RulesetStore rulesets { get; set; }
|
||||||
|
|
||||||
[Resolved]
|
|
||||||
private ScoreManager scoreManager { get; set; }
|
|
||||||
|
|
||||||
private GetScoresRequest getScoresRequest;
|
private GetScoresRequest getScoresRequest;
|
||||||
|
|
||||||
private CancellationTokenSource loadCancellationSource;
|
private CancellationTokenSource loadCancellationSource;
|
||||||
@ -85,7 +82,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
|
|||||||
MD5Hash = apiBeatmap.MD5Hash
|
MD5Hash = apiBeatmap.MD5Hash
|
||||||
};
|
};
|
||||||
|
|
||||||
var scores = scoreManager.OrderByTotalScore(value.Scores.Select(s => s.ToScoreInfo(rulesets, beatmapInfo))).ToArray();
|
var scores = value.Scores.Select(s => s.ToScoreInfo(rulesets, beatmapInfo)).OrderByTotalScore().ToArray();
|
||||||
var topScore = scores.First();
|
var topScore = scores.First();
|
||||||
|
|
||||||
scoreTable.DisplayScores(scores, apiBeatmap.Status.GrantsPerformancePoints());
|
scoreTable.DisplayScores(scores, apiBeatmap.Status.GrantsPerformancePoints());
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
#nullable disable
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Rulesets.Scoring;
|
||||||
|
|
||||||
namespace osu.Game.Scoring
|
namespace osu.Game.Scoring
|
||||||
{
|
{
|
||||||
@ -13,5 +14,23 @@ namespace osu.Game.Scoring
|
|||||||
/// A user-presentable display title representing this score.
|
/// A user-presentable display title representing this score.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string GetDisplayTitle(this IScoreInfo scoreInfo) => $"{scoreInfo.User.Username} playing {scoreInfo.Beatmap.GetDisplayTitle()}";
|
public static string GetDisplayTitle(this IScoreInfo scoreInfo) => $"{scoreInfo.User.Username} playing {scoreInfo.Beatmap.GetDisplayTitle()}";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Orders an array of <see cref="ScoreInfo"/>s by total score.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="scores">The array of <see cref="ScoreInfo"/>s to reorder.</param>
|
||||||
|
/// <returns>The given <paramref name="scores"/> ordered by decreasing total score.</returns>
|
||||||
|
public static IEnumerable<ScoreInfo> OrderByTotalScore(this IEnumerable<ScoreInfo> scores)
|
||||||
|
=> scores.OrderByDescending(s => s.TotalScore)
|
||||||
|
.ThenBy(s => s.OnlineID)
|
||||||
|
// Local scores may not have an online ID. Fall back to date in these cases.
|
||||||
|
.ThenBy(s => s.Date);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieves the maximum achievable combo for the provided score.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="score">The <see cref="ScoreInfo"/> to compute the maximum achievable combo for.</param>
|
||||||
|
/// <returns>The maximum achievable combo.</returns>
|
||||||
|
public static int GetMaximumAchievableCombo(this ScoreInfo score) => score.MaximumStatistics.Where(kvp => kvp.Key.AffectsCombo()).Sum(kvp => kvp.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,17 +69,6 @@ namespace osu.Game.Scoring
|
|||||||
return Realm.Run(r => r.All<ScoreInfo>().FirstOrDefault(query)?.Detach());
|
return Realm.Run(r => r.All<ScoreInfo>().FirstOrDefault(query)?.Detach());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Orders an array of <see cref="ScoreInfo"/>s by total score.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="scores">The array of <see cref="ScoreInfo"/>s to reorder.</param>
|
|
||||||
/// <returns>The given <paramref name="scores"/> ordered by decreasing total score.</returns>
|
|
||||||
public IEnumerable<ScoreInfo> OrderByTotalScore(IEnumerable<ScoreInfo> scores)
|
|
||||||
=> scores.OrderByDescending(s => s.TotalScore)
|
|
||||||
.ThenBy(s => s.OnlineID)
|
|
||||||
// Local scores may not have an online ID. Fall back to date in these cases.
|
|
||||||
.ThenBy(s => s.Date);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieves a bindable that represents the total score of a <see cref="ScoreInfo"/>.
|
/// Retrieves a bindable that represents the total score of a <see cref="ScoreInfo"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -100,13 +89,6 @@ namespace osu.Game.Scoring
|
|||||||
/// <returns>The bindable containing the formatted total score string.</returns>
|
/// <returns>The bindable containing the formatted total score string.</returns>
|
||||||
public Bindable<string> GetBindableTotalScoreString([NotNull] ScoreInfo score) => new TotalScoreStringBindable(GetBindableTotalScore(score));
|
public Bindable<string> GetBindableTotalScoreString([NotNull] ScoreInfo score) => new TotalScoreStringBindable(GetBindableTotalScore(score));
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Retrieves the maximum achievable combo for the provided score.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="score">The <see cref="ScoreInfo"/> to compute the maximum achievable combo for.</param>
|
|
||||||
/// <returns>The maximum achievable combo.</returns>
|
|
||||||
public int GetMaximumAchievableCombo([NotNull] ScoreInfo score) => score.MaximumStatistics.Where(kvp => kvp.Key.AffectsCombo()).Sum(kvp => kvp.Value);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides the total score of a <see cref="ScoreInfo"/>. Responds to changes in the currently-selected <see cref="ScoringMode"/>.
|
/// Provides the total score of a <see cref="ScoreInfo"/>. Responds to changes in the currently-selected <see cref="ScoringMode"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -182,7 +182,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
|||||||
/// <param name="pivot">An optional pivot around which the scores were retrieved.</param>
|
/// <param name="pivot">An optional pivot around which the scores were retrieved.</param>
|
||||||
private void performSuccessCallback([NotNull] Action<IEnumerable<ScoreInfo>> callback, [NotNull] List<MultiplayerScore> scores, [CanBeNull] MultiplayerScores pivot = null) => Schedule(() =>
|
private void performSuccessCallback([NotNull] Action<IEnumerable<ScoreInfo>> callback, [NotNull] List<MultiplayerScore> scores, [CanBeNull] MultiplayerScores pivot = null) => Schedule(() =>
|
||||||
{
|
{
|
||||||
var scoreInfos = scoreManager.OrderByTotalScore(scores.Select(s => s.CreateScoreInfo(scoreManager, rulesets, playlistItem, Beatmap.Value.BeatmapInfo))).ToArray();
|
var scoreInfos = scores.Select(s => s.CreateScoreInfo(scoreManager, rulesets, playlistItem, Beatmap.Value.BeatmapInfo)).OrderByTotalScore().ToArray();
|
||||||
|
|
||||||
// Select a score if we don't already have one selected.
|
// Select a score if we don't already have one selected.
|
||||||
// Note: This is done before the callback so that the panel list centres on the selected score before panels are added (eliminating initial scroll).
|
// Note: This is done before the callback so that the panel list centres on the selected score before panels are added (eliminating initial scroll).
|
||||||
|
@ -73,7 +73,7 @@ namespace osu.Game.Screens.Ranking.Expanded
|
|||||||
var topStatistics = new List<StatisticDisplay>
|
var topStatistics = new List<StatisticDisplay>
|
||||||
{
|
{
|
||||||
new AccuracyStatistic(score.Accuracy),
|
new AccuracyStatistic(score.Accuracy),
|
||||||
new ComboStatistic(score.MaxCombo, scoreManager.GetMaximumAchievableCombo(score)),
|
new ComboStatistic(score.MaxCombo, score.GetMaximumAchievableCombo()),
|
||||||
new PerformanceStatistic(score),
|
new PerformanceStatistic(score),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -29,9 +29,6 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private RealmAccess realm { get; set; } = null!;
|
private RealmAccess realm { get; set; } = null!;
|
||||||
|
|
||||||
[Resolved]
|
|
||||||
private ScoreManager scoreManager { get; set; } = null!;
|
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private IAPIProvider api { get; set; } = null!;
|
private IAPIProvider api { get; set; } = null!;
|
||||||
|
|
||||||
@ -78,7 +75,7 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
if (changes?.HasCollectionChanges() == false)
|
if (changes?.HasCollectionChanges() == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ScoreInfo? topScore = scoreManager.OrderByTotalScore(sender.Detach()).FirstOrDefault();
|
ScoreInfo? topScore = sender.Detach().OrderByTotalScore().FirstOrDefault();
|
||||||
|
|
||||||
updateable.Rank = topScore?.Rank;
|
updateable.Rank = topScore?.Rank;
|
||||||
updateable.Alpha = topScore != null ? 1 : 0;
|
updateable.Alpha = topScore != null ? 1 : 0;
|
||||||
|
@ -67,9 +67,6 @@ namespace osu.Game.Screens.Select.Leaderboards
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Resolved]
|
|
||||||
private ScoreManager scoreManager { get; set; } = null!;
|
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private IBindable<RulesetInfo> ruleset { get; set; } = null!;
|
private IBindable<RulesetInfo> ruleset { get; set; } = null!;
|
||||||
|
|
||||||
@ -164,7 +161,7 @@ namespace osu.Game.Screens.Select.Leaderboards
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
SetScores(
|
SetScores(
|
||||||
scoreManager.OrderByTotalScore(response.Scores.Select(s => s.ToScoreInfo(rulesets, fetchBeatmapInfo))),
|
response.Scores.Select(s => s.ToScoreInfo(rulesets, fetchBeatmapInfo)).OrderByTotalScore(),
|
||||||
response.UserScore?.CreateScoreInfo(rulesets, fetchBeatmapInfo)
|
response.UserScore?.CreateScoreInfo(rulesets, fetchBeatmapInfo)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -222,7 +219,7 @@ namespace osu.Game.Screens.Select.Leaderboards
|
|||||||
scores = scores.Where(s => selectedMods.SetEquals(s.Mods.Select(m => m.Acronym)));
|
scores = scores.Where(s => selectedMods.SetEquals(s.Mods.Select(m => m.Acronym)));
|
||||||
}
|
}
|
||||||
|
|
||||||
scores = scoreManager.OrderByTotalScore(scores.Detach());
|
scores = scores.Detach().OrderByTotalScore();
|
||||||
|
|
||||||
SetScores(scores);
|
SetScores(scores);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user