From eb45a406e153e9f533f51efaa95d30bb5bc0abe8 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Wed, 1 May 2024 23:00:24 +0300 Subject: [PATCH 1/3] Add failing test case --- .../Formats/LegacyScoreEncoderTest.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/osu.Game.Tests/Beatmaps/Formats/LegacyScoreEncoderTest.cs b/osu.Game.Tests/Beatmaps/Formats/LegacyScoreEncoderTest.cs index 806f538249..1e57bd76cf 100644 --- a/osu.Game.Tests/Beatmaps/Formats/LegacyScoreEncoderTest.cs +++ b/osu.Game.Tests/Beatmaps/Formats/LegacyScoreEncoderTest.cs @@ -20,7 +20,7 @@ namespace osu.Game.Tests.Beatmaps.Formats [TestCase(1, 3)] [TestCase(1, 0)] [TestCase(0, 3)] - public void CatchMergesFruitAndDropletMisses(int missCount, int largeTickMissCount) + public void TestCatchMergesFruitAndDropletMisses(int missCount, int largeTickMissCount) { var ruleset = new CatchRuleset().RulesetInfo; var scoreInfo = TestResources.CreateTestScoreInfo(ruleset); @@ -41,7 +41,22 @@ namespace osu.Game.Tests.Beatmaps.Formats } [Test] - public void ScoreWithMissIsNotPerfect() + public void TestFailPreserved() + { + var ruleset = new OsuRuleset().RulesetInfo; + var scoreInfo = TestResources.CreateTestScoreInfo(); + var beatmap = new TestBeatmap(ruleset); + + scoreInfo.Rank = ScoreRank.F; + + var score = new Score { ScoreInfo = scoreInfo }; + var decodedAfterEncode = encodeThenDecode(LegacyBeatmapDecoder.LATEST_VERSION, score, beatmap); + + Assert.That(decodedAfterEncode.ScoreInfo.Rank, Is.EqualTo(ScoreRank.F)); + } + + [Test] + public void TestScoreWithMissIsNotPerfect() { var ruleset = new OsuRuleset().RulesetInfo; var scoreInfo = TestResources.CreateTestScoreInfo(ruleset); From 0106f1fe3ead4d5bdbef25c1e0262b3988131894 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Wed, 1 May 2024 23:31:23 +0300 Subject: [PATCH 2/3] Preserve score rank on encode/decode --- osu.Game/Scoring/Legacy/LegacyReplaySoloScoreInfo.cs | 6 ++++++ osu.Game/Scoring/Legacy/LegacyScoreDecoder.cs | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/osu.Game/Scoring/Legacy/LegacyReplaySoloScoreInfo.cs b/osu.Game/Scoring/Legacy/LegacyReplaySoloScoreInfo.cs index afdcef1d21..32c18b3af2 100644 --- a/osu.Game/Scoring/Legacy/LegacyReplaySoloScoreInfo.cs +++ b/osu.Game/Scoring/Legacy/LegacyReplaySoloScoreInfo.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; +using Newtonsoft.Json.Converters; using osu.Game.Online.API; using osu.Game.Online.API.Requests.Responses; using osu.Game.Rulesets.Scoring; @@ -38,6 +39,10 @@ namespace osu.Game.Scoring.Legacy [JsonProperty("client_version")] public string ClientVersion = string.Empty; + [JsonProperty("rank")] + [JsonConverter(typeof(StringEnumConverter))] + public ScoreRank? Rank; + public static LegacyReplaySoloScoreInfo FromScore(ScoreInfo score) => new LegacyReplaySoloScoreInfo { OnlineID = score.OnlineID, @@ -45,6 +50,7 @@ namespace osu.Game.Scoring.Legacy Statistics = score.Statistics.Where(kvp => kvp.Value != 0).ToDictionary(), MaximumStatistics = score.MaximumStatistics.Where(kvp => kvp.Value != 0).ToDictionary(), ClientVersion = score.ClientVersion, + Rank = score.Rank, }; } } diff --git a/osu.Game/Scoring/Legacy/LegacyScoreDecoder.cs b/osu.Game/Scoring/Legacy/LegacyScoreDecoder.cs index 65e2c02655..b0d7087ed1 100644 --- a/osu.Game/Scoring/Legacy/LegacyScoreDecoder.cs +++ b/osu.Game/Scoring/Legacy/LegacyScoreDecoder.cs @@ -40,6 +40,7 @@ namespace osu.Game.Scoring.Legacy }; WorkingBeatmap workingBeatmap; + ScoreRank? decodedRank = null; using (SerializationReader sr = new SerializationReader(stream)) { @@ -129,6 +130,7 @@ namespace osu.Game.Scoring.Legacy score.ScoreInfo.MaximumStatistics = readScore.MaximumStatistics; score.ScoreInfo.Mods = readScore.Mods.Select(m => m.ToMod(currentRuleset)).ToArray(); score.ScoreInfo.ClientVersion = readScore.ClientVersion; + decodedRank = readScore.Rank; }); } } @@ -140,6 +142,9 @@ namespace osu.Game.Scoring.Legacy StandardisedScoreMigrationTools.UpdateFromLegacy(score.ScoreInfo, workingBeatmap); + if (decodedRank != null) + score.ScoreInfo.Rank = decodedRank.Value; + // before returning for database import, we must restore the database-sourced BeatmapInfo. // if not, the clone operation in GetPlayableBeatmap will cause a dereference and subsequent database exception. score.ScoreInfo.BeatmapInfo = workingBeatmap.BeatmapInfo; From 1eac34667d8c91679889475d17c8030e3bb85171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Thu, 2 May 2024 08:02:55 +0200 Subject: [PATCH 3/3] Fix test failure --- osu.Game.Tests/Beatmaps/Formats/LegacyScoreDecoderTest.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/osu.Game.Tests/Beatmaps/Formats/LegacyScoreDecoderTest.cs b/osu.Game.Tests/Beatmaps/Formats/LegacyScoreDecoderTest.cs index 43e471320e..383c08c10f 100644 --- a/osu.Game.Tests/Beatmaps/Formats/LegacyScoreDecoderTest.cs +++ b/osu.Game.Tests/Beatmaps/Formats/LegacyScoreDecoderTest.cs @@ -352,6 +352,7 @@ namespace osu.Game.Tests.Beatmaps.Formats [HitResult.Great] = 200, [HitResult.LargeTickHit] = 1, }; + scoreInfo.Rank = ScoreRank.A; var beatmap = new TestBeatmap(ruleset); var score = new Score