mirror of
https://github.com/ppy/osu.git
synced 2024-12-13 04:23:21 +08:00
Merge pull request #28200 from Hecatia-Lapislazuli/max-cs-scaling
Enforce difficulty setting limits during decode
This commit is contained in:
commit
ae27fc6944
@ -1188,5 +1188,36 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
||||
Assert.That(beatmap.HitObjects[0].GetEndTime(), Is.EqualTo(3153));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestBeatmapDifficultyIsClamped()
|
||||
{
|
||||
var decoder = new LegacyBeatmapDecoder { ApplyOffsets = false };
|
||||
|
||||
using (var resStream = TestResources.OpenResource("out-of-range-difficulties.osu"))
|
||||
using (var stream = new LineBufferedReader(resStream))
|
||||
{
|
||||
var decoded = decoder.Decode(stream).Difficulty;
|
||||
Assert.That(decoded.DrainRate, Is.EqualTo(10));
|
||||
Assert.That(decoded.CircleSize, Is.EqualTo(10));
|
||||
Assert.That(decoded.OverallDifficulty, Is.EqualTo(10));
|
||||
Assert.That(decoded.ApproachRate, Is.EqualTo(10));
|
||||
Assert.That(decoded.SliderMultiplier, Is.EqualTo(3.6));
|
||||
Assert.That(decoded.SliderTickRate, Is.EqualTo(8));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestManiaBeatmapDifficultyCircleSizeClamp()
|
||||
{
|
||||
var decoder = new LegacyBeatmapDecoder { ApplyOffsets = false };
|
||||
|
||||
using (var resStream = TestResources.OpenResource("out-of-range-difficulties-mania.osu"))
|
||||
using (var stream = new LineBufferedReader(resStream))
|
||||
{
|
||||
var decoded = decoder.Decode(stream).Difficulty;
|
||||
Assert.That(decoded.CircleSize, Is.EqualTo(14));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,5 @@
|
||||
[General]
|
||||
Mode: 3
|
||||
|
||||
[Difficulty]
|
||||
CircleSize:14
|
10
osu.Game.Tests/Resources/out-of-range-difficulties.osu
Normal file
10
osu.Game.Tests/Resources/out-of-range-difficulties.osu
Normal file
@ -0,0 +1,10 @@
|
||||
[General]
|
||||
Mode: 0
|
||||
|
||||
[Difficulty]
|
||||
HPDrainRate:25
|
||||
CircleSize:25
|
||||
OverallDifficulty:25
|
||||
ApproachRate:30
|
||||
SliderMultiplier:30
|
||||
SliderTickRate:30
|
@ -85,6 +85,8 @@ namespace osu.Game.Beatmaps.Formats
|
||||
|
||||
base.ParseStreamInto(stream, beatmap);
|
||||
|
||||
applyDifficultyRestrictions(beatmap.Difficulty, beatmap);
|
||||
|
||||
flushPendingPoints();
|
||||
|
||||
// Objects may be out of order *only* if a user has manually edited an .osu file.
|
||||
@ -102,10 +104,30 @@ namespace osu.Game.Beatmaps.Formats
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensures that all <see cref="BeatmapDifficulty"/> settings are within the allowed ranges.
|
||||
/// See also: https://github.com/peppy/osu-stable-reference/blob/0e425c0d525ef21353c8293c235cc0621d28338b/osu!/GameplayElements/Beatmaps/Beatmap.cs#L567-L614
|
||||
/// </summary>
|
||||
private static void applyDifficultyRestrictions(BeatmapDifficulty difficulty, Beatmap beatmap)
|
||||
{
|
||||
difficulty.DrainRate = Math.Clamp(difficulty.DrainRate, 0, 10);
|
||||
|
||||
// mania uses "circle size" for key count, thus different allowable range
|
||||
difficulty.CircleSize = beatmap.BeatmapInfo.Ruleset.OnlineID != 3
|
||||
? Math.Clamp(difficulty.CircleSize, 0, 10)
|
||||
: Math.Clamp(difficulty.CircleSize, 1, 18);
|
||||
|
||||
difficulty.OverallDifficulty = Math.Clamp(difficulty.OverallDifficulty, 0, 10);
|
||||
difficulty.ApproachRate = Math.Clamp(difficulty.ApproachRate, 0, 10);
|
||||
|
||||
difficulty.SliderMultiplier = Math.Clamp(difficulty.SliderMultiplier, 0.4, 3.6);
|
||||
difficulty.SliderTickRate = Math.Clamp(difficulty.SliderTickRate, 0.5, 8);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processes the beatmap such that a new combo is started the first hitobject following each break.
|
||||
/// </summary>
|
||||
private void postProcessBreaks(Beatmap beatmap)
|
||||
private static void postProcessBreaks(Beatmap beatmap)
|
||||
{
|
||||
int currentBreak = 0;
|
||||
bool forceNewCombo = false;
|
||||
@ -161,7 +183,7 @@ namespace osu.Game.Beatmaps.Formats
|
||||
/// This method's intention is to restore those legacy defaults.
|
||||
/// See also: https://osu.ppy.sh/wiki/en/Client/File_formats/Osu_%28file_format%29
|
||||
/// </summary>
|
||||
private void applyLegacyDefaults(BeatmapInfo beatmapInfo)
|
||||
private static void applyLegacyDefaults(BeatmapInfo beatmapInfo)
|
||||
{
|
||||
beatmapInfo.WidescreenStoryboard = false;
|
||||
beatmapInfo.SamplesMatchPlaybackRate = false;
|
||||
@ -402,11 +424,11 @@ namespace osu.Game.Beatmaps.Formats
|
||||
break;
|
||||
|
||||
case @"SliderMultiplier":
|
||||
difficulty.SliderMultiplier = Math.Clamp(Parsing.ParseDouble(pair.Value), 0.4, 3.6);
|
||||
difficulty.SliderMultiplier = Parsing.ParseDouble(pair.Value);
|
||||
break;
|
||||
|
||||
case @"SliderTickRate":
|
||||
difficulty.SliderTickRate = Math.Clamp(Parsing.ParseDouble(pair.Value), 0.5, 8);
|
||||
difficulty.SliderTickRate = Parsing.ParseDouble(pair.Value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user