1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 02:07:34 +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 scoreInfo = ToScoreInfo(mods);
var scoreInfo = ToScoreInfo(mods, beatmap);
scoreInfo.Ruleset = ruleset;
if (beatmap != null) scoreInfo.BeatmapInfo = beatmap;
return scoreInfo;
}
@ -166,25 +164,47 @@ namespace osu.Game.Online.API.Requests.Responses
/// Create a <see cref="ScoreInfo"/> from an API score instance.
/// </summary>
/// <param name="mods">The mod instances, resolved from a ruleset.</param>
/// <returns></returns>
public ScoreInfo ToScoreInfo(Mod[] mods) => new ScoreInfo
/// <param name="beatmap">The object to populate the scores' beatmap with.
///<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)
{
OnlineID = OnlineID,
User = User ?? new APIUser { Id = UserID },
BeatmapInfo = new BeatmapInfo { OnlineID = BeatmapID },
Ruleset = new RulesetInfo { OnlineID = RulesetID },
Passed = Passed,
TotalScore = TotalScore,
Accuracy = Accuracy,
MaxCombo = MaxCombo,
Rank = Rank,
Statistics = Statistics,
MaximumStatistics = MaximumStatistics,
Date = EndedAt,
Hash = HasReplay ? "online" : string.Empty, // TODO: temporary?
Mods = mods,
PP = PP,
};
var score = new ScoreInfo
{
OnlineID = OnlineID,
User = User ?? new APIUser { Id = UserID },
BeatmapInfo = new BeatmapInfo { OnlineID = BeatmapID },
Ruleset = new RulesetInfo { OnlineID = RulesetID },
Passed = Passed,
TotalScore = TotalScore,
Accuracy = Accuracy,
MaxCombo = MaxCombo,
Rank = Rank,
Statistics = Statistics,
MaximumStatistics = MaximumStatistics,
Date = EndedAt,
Hash = HasReplay ? "online" : string.Empty, // TODO: temporary?
Mods = mods,
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>
/// Creates a <see cref="SoloScoreInfo"/> from a local score for score submission.