1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-26 13:22:55 +08:00

Preserve score rank on encode/decode

This commit is contained in:
Salman Ahmed 2024-05-01 23:31:23 +03:00
parent eb45a406e1
commit 0106f1fe3e
2 changed files with 11 additions and 0 deletions

View File

@ -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,
};
}
}

View File

@ -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;