1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 11:42:54 +08:00

Merge pull request #28058 from frenzibyte/export-score-rank

Preserve score rank on lazer scores during encode/decode
This commit is contained in:
Bartłomiej Dach 2024-05-02 08:44:10 +02:00 committed by GitHub
commit 555305bf7f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 29 additions and 2 deletions

View File

@ -352,6 +352,7 @@ namespace osu.Game.Tests.Beatmaps.Formats
[HitResult.Great] = 200, [HitResult.Great] = 200,
[HitResult.LargeTickHit] = 1, [HitResult.LargeTickHit] = 1,
}; };
scoreInfo.Rank = ScoreRank.A;
var beatmap = new TestBeatmap(ruleset); var beatmap = new TestBeatmap(ruleset);
var score = new Score var score = new Score

View File

@ -20,7 +20,7 @@ namespace osu.Game.Tests.Beatmaps.Formats
[TestCase(1, 3)] [TestCase(1, 3)]
[TestCase(1, 0)] [TestCase(1, 0)]
[TestCase(0, 3)] [TestCase(0, 3)]
public void CatchMergesFruitAndDropletMisses(int missCount, int largeTickMissCount) public void TestCatchMergesFruitAndDropletMisses(int missCount, int largeTickMissCount)
{ {
var ruleset = new CatchRuleset().RulesetInfo; var ruleset = new CatchRuleset().RulesetInfo;
var scoreInfo = TestResources.CreateTestScoreInfo(ruleset); var scoreInfo = TestResources.CreateTestScoreInfo(ruleset);
@ -41,7 +41,22 @@ namespace osu.Game.Tests.Beatmaps.Formats
} }
[Test] [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 ruleset = new OsuRuleset().RulesetInfo;
var scoreInfo = TestResources.CreateTestScoreInfo(ruleset); var scoreInfo = TestResources.CreateTestScoreInfo(ruleset);

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
@ -38,6 +39,10 @@ namespace osu.Game.Scoring.Legacy
[JsonProperty("client_version")] [JsonProperty("client_version")]
public string ClientVersion = string.Empty; public string ClientVersion = string.Empty;
[JsonProperty("rank")]
[JsonConverter(typeof(StringEnumConverter))]
public ScoreRank? Rank;
public static LegacyReplaySoloScoreInfo FromScore(ScoreInfo score) => new LegacyReplaySoloScoreInfo public static LegacyReplaySoloScoreInfo FromScore(ScoreInfo score) => new LegacyReplaySoloScoreInfo
{ {
OnlineID = score.OnlineID, OnlineID = score.OnlineID,
@ -45,6 +50,7 @@ namespace osu.Game.Scoring.Legacy
Statistics = score.Statistics.Where(kvp => kvp.Value != 0).ToDictionary(), Statistics = score.Statistics.Where(kvp => kvp.Value != 0).ToDictionary(),
MaximumStatistics = score.MaximumStatistics.Where(kvp => kvp.Value != 0).ToDictionary(), MaximumStatistics = score.MaximumStatistics.Where(kvp => kvp.Value != 0).ToDictionary(),
ClientVersion = score.ClientVersion, ClientVersion = score.ClientVersion,
Rank = score.Rank,
}; };
} }
} }

View File

@ -40,6 +40,7 @@ namespace osu.Game.Scoring.Legacy
}; };
WorkingBeatmap workingBeatmap; WorkingBeatmap workingBeatmap;
ScoreRank? decodedRank = null;
using (SerializationReader sr = new SerializationReader(stream)) using (SerializationReader sr = new SerializationReader(stream))
{ {
@ -129,6 +130,7 @@ namespace osu.Game.Scoring.Legacy
score.ScoreInfo.MaximumStatistics = readScore.MaximumStatistics; score.ScoreInfo.MaximumStatistics = readScore.MaximumStatistics;
score.ScoreInfo.Mods = readScore.Mods.Select(m => m.ToMod(currentRuleset)).ToArray(); score.ScoreInfo.Mods = readScore.Mods.Select(m => m.ToMod(currentRuleset)).ToArray();
score.ScoreInfo.ClientVersion = readScore.ClientVersion; score.ScoreInfo.ClientVersion = readScore.ClientVersion;
decodedRank = readScore.Rank;
}); });
} }
} }
@ -140,6 +142,9 @@ namespace osu.Game.Scoring.Legacy
StandardisedScoreMigrationTools.UpdateFromLegacy(score.ScoreInfo, workingBeatmap); 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. // 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. // if not, the clone operation in GetPlayableBeatmap will cause a dereference and subsequent database exception.
score.ScoreInfo.BeatmapInfo = workingBeatmap.BeatmapInfo; score.ScoreInfo.BeatmapInfo = workingBeatmap.BeatmapInfo;