mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 13:37:25 +08:00
Merge pull request #29534 from bdach/fix-divisor-crash
Fix crash on attempting to edit particular beatmaps
This commit is contained in:
commit
5bb94000d3
@ -16,6 +16,7 @@ using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.Objects.Legacy;
|
||||
using osu.Game.Rulesets.Objects.Types;
|
||||
using osu.Game.Screens.Edit;
|
||||
|
||||
namespace osu.Game.Beatmaps.Formats
|
||||
{
|
||||
@ -336,7 +337,7 @@ namespace osu.Game.Beatmaps.Formats
|
||||
break;
|
||||
|
||||
case @"BeatDivisor":
|
||||
beatmap.BeatmapInfo.BeatDivisor = Parsing.ParseInt(pair.Value);
|
||||
beatmap.BeatmapInfo.BeatDivisor = Math.Clamp(Parsing.ParseInt(pair.Value), BindableBeatDivisor.MINIMUM_DIVISOR, BindableBeatDivisor.MAXIMUM_DIVISOR);
|
||||
break;
|
||||
|
||||
case @"GridSize":
|
||||
|
@ -16,6 +16,9 @@ namespace osu.Game.Screens.Edit
|
||||
{
|
||||
public static readonly int[] PREDEFINED_DIVISORS = { 1, 2, 3, 4, 6, 8, 12, 16 };
|
||||
|
||||
public const int MINIMUM_DIVISOR = 1;
|
||||
public const int MAXIMUM_DIVISOR = 64;
|
||||
|
||||
public Bindable<BeatDivisorPresetCollection> ValidDivisors { get; } = new Bindable<BeatDivisorPresetCollection>(BeatDivisorPresetCollection.COMMON);
|
||||
|
||||
public BindableBeatDivisor(int value = 1)
|
||||
@ -30,8 +33,12 @@ namespace osu.Game.Screens.Edit
|
||||
/// </summary>
|
||||
/// <param name="divisor">The intended divisor.</param>
|
||||
/// <param name="preferKnownPresets">Forces changing the valid divisors to a known preset.</param>
|
||||
public void SetArbitraryDivisor(int divisor, bool preferKnownPresets = false)
|
||||
/// <returns>Whether the divisor was successfully set.</returns>
|
||||
public bool SetArbitraryDivisor(int divisor, bool preferKnownPresets = false)
|
||||
{
|
||||
if (divisor < MINIMUM_DIVISOR || divisor > MAXIMUM_DIVISOR)
|
||||
return false;
|
||||
|
||||
// If the current valid divisor range doesn't contain the proposed value, attempt to find one which does.
|
||||
if (preferKnownPresets || !ValidDivisors.Value.Presets.Contains(divisor))
|
||||
{
|
||||
@ -44,6 +51,7 @@ namespace osu.Game.Screens.Edit
|
||||
}
|
||||
|
||||
Value = divisor;
|
||||
return true;
|
||||
}
|
||||
|
||||
private void updateBindableProperties()
|
||||
|
@ -330,14 +330,14 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
|
||||
private void setPresetsFromTextBoxEntry()
|
||||
{
|
||||
if (!int.TryParse(divisorTextBox.Text, out int divisor) || divisor < 1 || divisor > 64)
|
||||
if (!int.TryParse(divisorTextBox.Text, out int divisor) || !BeatDivisor.SetArbitraryDivisor(divisor))
|
||||
{
|
||||
// the text either didn't parse as a divisor, or the divisor was not set due to being out of range.
|
||||
// force a state update to reset the text box's value to the last sane value.
|
||||
updateState();
|
||||
return;
|
||||
}
|
||||
|
||||
BeatDivisor.SetArbitraryDivisor(divisor);
|
||||
|
||||
this.HidePopover();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user