1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 07:42:57 +08:00

Allow LegacyScoreEncoder to be used without a beatmap if frames are already legacy frames

This commit is contained in:
Dean Herbert 2022-02-28 16:37:14 +09:00
parent 97de36d849
commit 2e96f74c94

View File

@ -5,9 +5,11 @@ using System;
using System.IO;
using System.Linq;
using System.Text;
using JetBrains.Annotations;
using osu.Framework.Extensions;
using osu.Game.Beatmaps;
using osu.Game.IO.Legacy;
using osu.Game.Replays.Legacy;
using osu.Game.Rulesets.Replays.Types;
using SharpCompress.Compressors.LZMA;
@ -29,12 +31,21 @@ namespace osu.Game.Scoring.Legacy
private readonly Score score;
private readonly IBeatmap beatmap;
public LegacyScoreEncoder(Score score, IBeatmap beatmap)
/// <summary>
/// Create a new score encoder for a specific score.
/// </summary>
/// <param name="score">The score to be encoded.</param>
/// <param name="beatmap">The beatmap used to convert frames for the score. May be null if the frames are already <see cref="LegacyReplayFrame"/>s.</param>
/// <exception cref="ArgumentException"></exception>
public LegacyScoreEncoder(Score score, [CanBeNull] IBeatmap beatmap)
{
this.score = score;
this.beatmap = beatmap;
if (score.ScoreInfo.BeatmapInfo.Ruleset.OnlineID < 0 || score.ScoreInfo.BeatmapInfo.Ruleset.OnlineID > 3)
if (beatmap == null && !score.Replay.Frames.All(f => f is LegacyReplayFrame))
throw new ArgumentException("Beatmap must be provided if frames are not already legacy frames.", nameof(beatmap));
if (score.ScoreInfo.Ruleset.OnlineID < 0 || score.ScoreInfo.Ruleset.OnlineID > 3)
throw new ArgumentException("Only scores in the osu, taiko, catch, or mania rulesets can be encoded to the legacy score format.", nameof(score));
}