1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 06:23:21 +08:00

Merge branch 'master' into skin-editor-ui

This commit is contained in:
Bartłomiej Dach 2022-03-02 21:01:03 +01:00 committed by GitHub
commit 7e90b4456d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 8 deletions

View File

@ -23,7 +23,7 @@ namespace osu.Game.Rulesets.Taiko.Mods
{
get
{
string scrollSpeed = ScrollSpeed.IsDefault ? string.Empty : $"Scroll x{ScrollSpeed.Value:N1}";
string scrollSpeed = ScrollSpeed.IsDefault ? string.Empty : $"Scroll x{ScrollSpeed.Value:N2}";
return string.Join(", ", new[]
{

View File

@ -8,9 +8,14 @@ using System.Text;
using osu.Framework.Extensions;
using osu.Game.Beatmaps;
using osu.Game.IO.Legacy;
using osu.Game.Replays.Legacy;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Replays;
using osu.Game.Rulesets.Replays.Types;
using SharpCompress.Compressors.LZMA;
#nullable enable
namespace osu.Game.Scoring.Legacy
{
public class LegacyScoreEncoder
@ -27,15 +32,24 @@ namespace osu.Game.Scoring.Legacy
public const int FIRST_LAZER_VERSION = 30000000;
private readonly Score score;
private readonly IBeatmap beatmap;
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, IBeatmap? beatmap)
{
this.score = score;
this.beatmap = beatmap;
if (score.ScoreInfo.BeatmapInfo.Ruleset.OnlineID < 0 || score.ScoreInfo.BeatmapInfo.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));
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 > ILegacyRuleset.MAX_LEGACY_RULESET_ID)
throw new ArgumentException(@"Only scores in the osu, taiko, catch, or mania rulesets can be encoded to the legacy score format.", nameof(score));
}
public void Encode(Stream stream)
@ -101,11 +115,13 @@ namespace osu.Game.Scoring.Legacy
{
int lastTime = 0;
foreach (var f in score.Replay.Frames.OfType<IConvertibleReplayFrame>().Select(f => f.ToLegacy(beatmap)))
foreach (var f in score.Replay.Frames)
{
var legacyFrame = getLegacyFrame(f);
// Rounding because stable could only parse integral values
int time = (int)Math.Round(f.Time);
replayData.Append(FormattableString.Invariant($"{time - lastTime}|{f.MouseX ?? 0}|{f.MouseY ?? 0}|{(int)f.ButtonState},"));
int time = (int)Math.Round(legacyFrame.Time);
replayData.Append(FormattableString.Invariant($"{time - lastTime}|{legacyFrame.MouseX ?? 0}|{legacyFrame.MouseY ?? 0}|{(int)legacyFrame.ButtonState},"));
lastTime = time;
}
}
@ -117,6 +133,21 @@ namespace osu.Game.Scoring.Legacy
}
}
private LegacyReplayFrame getLegacyFrame(ReplayFrame replayFrame)
{
switch (replayFrame)
{
case LegacyReplayFrame legacyFrame:
return legacyFrame;
case IConvertibleReplayFrame convertibleFrame:
return convertibleFrame.ToLegacy(beatmap);
default:
throw new ArgumentException(@"Frame could not be converted to legacy frames", nameof(replayFrame));
}
}
private string getHpGraphFormatted()
{
// todo: implement, maybe?