1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 16:27:26 +08:00

Populate beatmap ruleset in SoloScoreInfo.ToScoreInfo()

This commit is contained in:
Dan Balasescu 2022-10-28 14:42:42 +09:00
parent 51d8392e7f
commit b3219526a5

View File

@ -154,10 +154,8 @@ namespace osu.Game.Online.API.Requests.Responses
var mods = Mods.Select(apiMod => apiMod.ToMod(rulesetInstance)).ToArray(); var mods = Mods.Select(apiMod => apiMod.ToMod(rulesetInstance)).ToArray();
var scoreInfo = ToScoreInfo(mods); var scoreInfo = ToScoreInfo(mods, beatmap);
scoreInfo.Ruleset = ruleset; scoreInfo.Ruleset = ruleset;
if (beatmap != null) scoreInfo.BeatmapInfo = beatmap;
return scoreInfo; return scoreInfo;
} }
@ -166,8 +164,18 @@ namespace osu.Game.Online.API.Requests.Responses
/// Create a <see cref="ScoreInfo"/> from an API score instance. /// Create a <see cref="ScoreInfo"/> from an API score instance.
/// </summary> /// </summary>
/// <param name="mods">The mod instances, resolved from a ruleset.</param> /// <param name="mods">The mod instances, resolved from a ruleset.</param>
/// <returns></returns> /// <param name="beatmap">The object to populate the scores' beatmap with.
public ScoreInfo ToScoreInfo(Mod[] mods) => new ScoreInfo ///<list type="bullet">
/// <item>If this is a <see cref="BeatmapInfo"/> type, then the score will be fully populated with the given object.</item>
/// <item>Otherwise, if this is an <see cref="IBeatmapInfo"/> type (e.g. <see cref="APIBeatmap"/>), then only the beatmap ruleset will be populated.</item>
/// <item>Otherwise, if this is <c>null</c>, then the beatmap ruleset will not be populated.</item>
/// <item>The online beatmap ID is populated in all cases.</item>
/// </list>
/// </param>
/// <returns>The populated <see cref="ScoreInfo"/>.</returns>
public ScoreInfo ToScoreInfo(Mod[] mods, IBeatmapInfo? beatmap = null)
{
var score = new ScoreInfo
{ {
OnlineID = OnlineID, OnlineID = OnlineID,
User = User ?? new APIUser { Id = UserID }, User = User ?? new APIUser { Id = UserID },
@ -186,6 +194,18 @@ namespace osu.Game.Online.API.Requests.Responses
PP = PP, PP = PP,
}; };
if (beatmap is BeatmapInfo realmBeatmap)
score.BeatmapInfo = realmBeatmap;
else if (beatmap != null)
{
score.BeatmapInfo.Ruleset.OnlineID = beatmap.Ruleset.OnlineID;
score.BeatmapInfo.Ruleset.Name = beatmap.Ruleset.Name;
score.BeatmapInfo.Ruleset.ShortName = beatmap.Ruleset.ShortName;
}
return score;
}
/// <summary> /// <summary>
/// Creates a <see cref="SoloScoreInfo"/> from a local score for score submission. /// Creates a <see cref="SoloScoreInfo"/> from a local score for score submission.
/// </summary> /// </summary>