1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 12:57:36 +08:00

Merge pull request #17161 from smoogipoo/fix-listing-score-conversion

Fix scores not being recalculated in beatmap overlay
This commit is contained in:
Dean Herbert 2022-03-09 13:32:45 +09:00 committed by GitHub
commit affcf5180b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 60 deletions

View File

@ -33,16 +33,25 @@ namespace osu.Game.Tests.Visual.Playlists
private TestResultsScreen resultsScreen; private TestResultsScreen resultsScreen;
private int currentScoreId; private int lowestScoreId; // Score ID of the lowest score in the list.
private int highestScoreId; // Score ID of the highest score in the list.
private bool requestComplete; private bool requestComplete;
private int totalCount; private int totalCount;
private ScoreInfo userScore;
[SetUp] [SetUp]
public void Setup() => Schedule(() => public void Setup() => Schedule(() =>
{ {
currentScoreId = 1; lowestScoreId = 1;
highestScoreId = 1;
requestComplete = false; requestComplete = false;
totalCount = 0; totalCount = 0;
userScore = TestResources.CreateTestScoreInfo();
userScore.TotalScore = 0;
userScore.Statistics = new Dictionary<HitResult, int>();
bindHandler(); bindHandler();
// beatmap is required to be an actual beatmap so the scores can get their scores correctly calculated for standardised scoring. // beatmap is required to be an actual beatmap so the scores can get their scores correctly calculated for standardised scoring.
@ -53,15 +62,7 @@ namespace osu.Game.Tests.Visual.Playlists
[Test] [Test]
public void TestShowWithUserScore() public void TestShowWithUserScore()
{ {
ScoreInfo userScore = null; AddStep("bind user score info handler", () => bindHandler(userScore: userScore));
AddStep("bind user score info handler", () =>
{
userScore = TestResources.CreateTestScoreInfo();
userScore.OnlineID = currentScoreId++;
bindHandler(userScore: userScore);
});
createResults(() => userScore); createResults(() => userScore);
@ -81,15 +82,7 @@ namespace osu.Game.Tests.Visual.Playlists
[Test] [Test]
public void TestShowUserScoreWithDelay() public void TestShowUserScoreWithDelay()
{ {
ScoreInfo userScore = null; AddStep("bind user score info handler", () => bindHandler(true, userScore));
AddStep("bind user score info handler", () =>
{
userScore = TestResources.CreateTestScoreInfo();
userScore.OnlineID = currentScoreId++;
bindHandler(true, userScore);
});
createResults(() => userScore); createResults(() => userScore);
@ -124,7 +117,7 @@ namespace osu.Game.Tests.Visual.Playlists
AddAssert("right loading spinner shown", () => resultsScreen.RightSpinner.State.Value == Visibility.Visible); AddAssert("right loading spinner shown", () => resultsScreen.RightSpinner.State.Value == Visibility.Visible);
waitForDisplay(); waitForDisplay();
AddAssert($"count increased by {scores_per_result}", () => this.ChildrenOfType<ScorePanel>().Count() == beforePanelCount + scores_per_result); AddAssert($"count increased by {scores_per_result}", () => this.ChildrenOfType<ScorePanel>().Count() >= beforePanelCount + scores_per_result);
AddAssert("right loading spinner hidden", () => resultsScreen.RightSpinner.State.Value == Visibility.Hidden); AddAssert("right loading spinner hidden", () => resultsScreen.RightSpinner.State.Value == Visibility.Hidden);
} }
} }
@ -132,15 +125,7 @@ namespace osu.Game.Tests.Visual.Playlists
[Test] [Test]
public void TestFetchWhenScrolledToTheLeft() public void TestFetchWhenScrolledToTheLeft()
{ {
ScoreInfo userScore = null; AddStep("bind user score info handler", () => bindHandler(userScore: userScore));
AddStep("bind user score info handler", () =>
{
userScore = TestResources.CreateTestScoreInfo();
userScore.OnlineID = currentScoreId++;
bindHandler(userScore: userScore);
});
createResults(() => userScore); createResults(() => userScore);
@ -156,7 +141,7 @@ namespace osu.Game.Tests.Visual.Playlists
AddAssert("left loading spinner shown", () => resultsScreen.LeftSpinner.State.Value == Visibility.Visible); AddAssert("left loading spinner shown", () => resultsScreen.LeftSpinner.State.Value == Visibility.Visible);
waitForDisplay(); waitForDisplay();
AddAssert($"count increased by {scores_per_result}", () => this.ChildrenOfType<ScorePanel>().Count() == beforePanelCount + scores_per_result); AddAssert($"count increased by {scores_per_result}", () => this.ChildrenOfType<ScorePanel>().Count() >= beforePanelCount + scores_per_result);
AddAssert("left loading spinner hidden", () => resultsScreen.LeftSpinner.State.Value == Visibility.Hidden); AddAssert("left loading spinner hidden", () => resultsScreen.LeftSpinner.State.Value == Visibility.Hidden);
} }
} }
@ -245,16 +230,13 @@ namespace osu.Game.Tests.Visual.Playlists
{ {
var multiplayerUserScore = new MultiplayerScore var multiplayerUserScore = new MultiplayerScore
{ {
ID = (int)(userScore.OnlineID > 0 ? userScore.OnlineID : currentScoreId++), ID = highestScoreId,
Accuracy = userScore.Accuracy, Accuracy = userScore.Accuracy,
EndedAt = userScore.Date,
Passed = userScore.Passed, Passed = userScore.Passed,
Rank = userScore.Rank, Rank = userScore.Rank,
Position = real_user_position, Position = real_user_position,
MaxCombo = userScore.MaxCombo, MaxCombo = userScore.MaxCombo,
TotalScore = userScore.TotalScore,
User = userScore.User, User = userScore.User,
Statistics = userScore.Statistics,
ScoresAround = new MultiplayerScoresAround ScoresAround = new MultiplayerScoresAround
{ {
Higher = new MultiplayerScores(), Higher = new MultiplayerScores(),
@ -268,38 +250,32 @@ namespace osu.Game.Tests.Visual.Playlists
{ {
multiplayerUserScore.ScoresAround.Lower.Scores.Add(new MultiplayerScore multiplayerUserScore.ScoresAround.Lower.Scores.Add(new MultiplayerScore
{ {
ID = currentScoreId++, ID = --highestScoreId,
Accuracy = userScore.Accuracy, Accuracy = userScore.Accuracy,
EndedAt = userScore.Date,
Passed = true, Passed = true,
Rank = userScore.Rank, Rank = userScore.Rank,
MaxCombo = userScore.MaxCombo, MaxCombo = userScore.MaxCombo,
TotalScore = userScore.TotalScore - i,
User = new APIUser User = new APIUser
{ {
Id = 2, Id = 2,
Username = $"peppy{i}", Username = $"peppy{i}",
CoverUrl = "https://osu.ppy.sh/images/headers/profile-covers/c3.jpg", CoverUrl = "https://osu.ppy.sh/images/headers/profile-covers/c3.jpg",
}, },
Statistics = userScore.Statistics
}); });
multiplayerUserScore.ScoresAround.Higher.Scores.Add(new MultiplayerScore multiplayerUserScore.ScoresAround.Higher.Scores.Add(new MultiplayerScore
{ {
ID = currentScoreId++, ID = ++lowestScoreId,
Accuracy = userScore.Accuracy, Accuracy = userScore.Accuracy,
EndedAt = userScore.Date,
Passed = true, Passed = true,
Rank = userScore.Rank, Rank = userScore.Rank,
MaxCombo = userScore.MaxCombo, MaxCombo = userScore.MaxCombo,
TotalScore = userScore.TotalScore + i,
User = new APIUser User = new APIUser
{ {
Id = 2, Id = 2,
Username = $"peppy{i}", Username = $"peppy{i}",
CoverUrl = "https://osu.ppy.sh/images/headers/profile-covers/c3.jpg", CoverUrl = "https://osu.ppy.sh/images/headers/profile-covers/c3.jpg",
}, },
Statistics = userScore.Statistics
}); });
totalCount += 2; totalCount += 2;
@ -315,33 +291,23 @@ namespace osu.Game.Tests.Visual.Playlists
{ {
var result = new IndexedMultiplayerScores(); var result = new IndexedMultiplayerScores();
long startTotalScore = req.Cursor?.Properties["total_score"].ToObject<long>() ?? 1000000;
string sort = req.IndexParams?.Properties["sort"].ToObject<string>() ?? "score_desc"; string sort = req.IndexParams?.Properties["sort"].ToObject<string>() ?? "score_desc";
for (int i = 1; i <= scores_per_result; i++) for (int i = 1; i <= scores_per_result; i++)
{ {
result.Scores.Add(new MultiplayerScore result.Scores.Add(new MultiplayerScore
{ {
ID = currentScoreId++, ID = sort == "score_asc" ? --highestScoreId : ++lowestScoreId,
Accuracy = 1, Accuracy = 1,
EndedAt = DateTimeOffset.Now,
Passed = true, Passed = true,
Rank = ScoreRank.X, Rank = ScoreRank.X,
MaxCombo = 1000, MaxCombo = 1000,
TotalScore = startTotalScore + (sort == "score_asc" ? i : -i),
User = new APIUser User = new APIUser
{ {
Id = 2, Id = 2,
Username = $"peppy{i}", Username = $"peppy{i}",
CoverUrl = "https://osu.ppy.sh/images/headers/profile-covers/c3.jpg", CoverUrl = "https://osu.ppy.sh/images/headers/profile-covers/c3.jpg",
}, },
Statistics = new Dictionary<HitResult, int>
{
{ HitResult.Miss, 1 },
{ HitResult.Meh, 50 },
{ HitResult.Good, 100 },
{ HitResult.Great, 300 }
}
}); });
totalCount++; totalCount++;
@ -367,7 +333,7 @@ namespace osu.Game.Tests.Visual.Playlists
{ {
Properties = new Dictionary<string, JToken> Properties = new Dictionary<string, JToken>
{ {
{ "sort", JToken.FromObject(scores.Scores[^1].TotalScore > scores.Scores[^2].TotalScore ? "score_asc" : "score_desc") } { "sort", JToken.FromObject(scores.Scores[^1].ID > scores.Scores[^2].ID ? "score_asc" : "score_desc") }
} }
}; };
} }

View File

@ -2,12 +2,14 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Framework.Utils; using osu.Framework.Utils;
using osu.Game.Models; using osu.Game.Models;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Game.Screens.Ranking; using osu.Game.Screens.Ranking;
using osu.Game.Tests.Resources; using osu.Game.Tests.Resources;
@ -208,13 +210,19 @@ namespace osu.Game.Tests.Visual.Ranking
public void TestKeyboardNavigation() public void TestKeyboardNavigation()
{ {
var lowestScore = TestResources.CreateTestScoreInfo(); var lowestScore = TestResources.CreateTestScoreInfo();
lowestScore.MaxCombo = 100; lowestScore.OnlineID = 3;
lowestScore.TotalScore = 0;
lowestScore.Statistics = new Dictionary<HitResult, int>();
var middleScore = TestResources.CreateTestScoreInfo(); var middleScore = TestResources.CreateTestScoreInfo();
middleScore.MaxCombo = 200; middleScore.OnlineID = 2;
middleScore.TotalScore = 0;
middleScore.Statistics = new Dictionary<HitResult, int>();
var highestScore = TestResources.CreateTestScoreInfo(); var highestScore = TestResources.CreateTestScoreInfo();
highestScore.MaxCombo = 300; highestScore.OnlineID = 1;
highestScore.TotalScore = 0;
highestScore.Statistics = new Dictionary<HitResult, int>();
createListStep(() => new ScorePanelList()); createListStep(() => new ScorePanelList());

View File

@ -79,7 +79,8 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
var beatmapInfo = new BeatmapInfo var beatmapInfo = new BeatmapInfo
{ {
MaxCombo = apiBeatmap.MaxCombo, MaxCombo = apiBeatmap.MaxCombo,
Status = apiBeatmap.Status Status = apiBeatmap.Status,
MD5Hash = apiBeatmap.MD5Hash
}; };
scoreManager.OrderByTotalScoreAsync(value.Scores.Select(s => s.CreateScoreInfo(rulesets, beatmapInfo)).ToArray(), loadCancellationSource.Token) scoreManager.OrderByTotalScoreAsync(value.Scores.Select(s => s.CreateScoreInfo(rulesets, beatmapInfo)).ToArray(), loadCancellationSource.Token)

View File

@ -132,7 +132,7 @@ namespace osu.Game.Scoring
public async Task<long> GetTotalScoreAsync([NotNull] ScoreInfo score, ScoringMode mode = ScoringMode.Standardised, CancellationToken cancellationToken = default) public async Task<long> GetTotalScoreAsync([NotNull] ScoreInfo score, ScoringMode mode = ScoringMode.Standardised, CancellationToken cancellationToken = default)
{ {
// TODO: This is required for playlist aggregate scores. They should likely not be getting here in the first place. // TODO: This is required for playlist aggregate scores. They should likely not be getting here in the first place.
if (string.IsNullOrEmpty(score.BeatmapInfo.Hash)) if (string.IsNullOrEmpty(score.BeatmapInfo.MD5Hash))
return score.TotalScore; return score.TotalScore;
int beatmapMaxCombo; int beatmapMaxCombo;