1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 14:17:26 +08:00

Fix crashing if selected ruleset doesn't have an autoplay mod.

This commit is contained in:
Lucas A 2020-06-01 17:41:04 +02:00
parent efbc02b521
commit e9b09373e7
2 changed files with 15 additions and 9 deletions

View File

@ -100,7 +100,7 @@ namespace osu.Game.Rulesets
return value;
}
public ModAutoplay GetAutoplayMod() => GetAllMods().OfType<ModAutoplay>().First();
public ModAutoplay GetAutoplayMod() => GetAllMods().OfType<ModAutoplay>().FirstOrDefault();
public virtual ISkin CreateLegacySkinProvider(ISkinSource source, IBeatmap beatmap) => null;

View File

@ -49,8 +49,11 @@ namespace osu.Game.Screens.Select
if (removeAutoModOnResume)
{
var autoType = Ruleset.Value.CreateInstance().GetAutoplayMod().GetType();
ModSelect.DeselectTypes(new[] { autoType }, true);
var autoType = Ruleset.Value.CreateInstance().GetAutoplayMod()?.GetType();
if (autoType != null)
ModSelect.DeselectTypes(new[] { autoType }, true);
removeAutoModOnResume = false;
}
}
@ -78,14 +81,17 @@ namespace osu.Game.Screens.Select
if (GetContainingInputManager().CurrentState?.Keyboard.ControlPressed == true)
{
var auto = Ruleset.Value.CreateInstance().GetAutoplayMod();
var autoType = auto.GetType();
var autoType = auto?.GetType();
var mods = Mods.Value;
if (mods.All(m => m.GetType() != autoType))
if (autoType != null)
{
Mods.Value = mods.Append(auto).ToArray();
removeAutoModOnResume = true;
var mods = Mods.Value;
if (mods.All(m => m.GetType() != autoType))
{
Mods.Value = mods.Append(auto).ToArray();
removeAutoModOnResume = true;
}
}
}