mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 09:27:29 +08:00
Merge pull request #9168 from Game4all/fix-ruleset-no-autoplay
Fix crash after using Ctrl+Enter when current ruleset doesn't have an autoplay mod
This commit is contained in:
commit
5740fc2bd0
@ -19,7 +19,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
{
|
||||
var beatmap = Beatmap.Value.GetPlayableBeatmap(ruleset.RulesetInfo, Array.Empty<Mod>());
|
||||
|
||||
return new ScoreAccessibleReplayPlayer(ruleset.GetAutoplayMod().CreateReplayScore(beatmap));
|
||||
return new ScoreAccessibleReplayPlayer(ruleset.GetAutoplayMod()?.CreateReplayScore(beatmap));
|
||||
}
|
||||
|
||||
protected override void AddCheckSteps()
|
||||
|
@ -22,6 +22,7 @@ using osu.Game.Rulesets.Scoring;
|
||||
using osu.Game.Scoring;
|
||||
using osu.Game.Skinning;
|
||||
using osu.Game.Users;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace osu.Game.Rulesets
|
||||
{
|
||||
@ -100,7 +101,8 @@ namespace osu.Game.Rulesets
|
||||
return value;
|
||||
}
|
||||
|
||||
public ModAutoplay GetAutoplayMod() => GetAllMods().OfType<ModAutoplay>().First();
|
||||
[CanBeNull]
|
||||
public ModAutoplay GetAutoplayMod() => GetAllMods().OfType<ModAutoplay>().FirstOrDefault();
|
||||
|
||||
public virtual ISkin CreateLegacySkinProvider(ISkinSource source, IBeatmap beatmap) => null;
|
||||
|
||||
|
@ -7,6 +7,8 @@ using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.Notifications;
|
||||
using osu.Game.Scoring;
|
||||
using osu.Game.Screens.Play;
|
||||
using osu.Game.Screens.Ranking;
|
||||
@ -20,6 +22,9 @@ namespace osu.Game.Screens.Select
|
||||
private bool removeAutoModOnResume;
|
||||
private OsuScreen player;
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
private NotificationOverlay notifications { get; set; }
|
||||
|
||||
public override bool AllowExternalScreenChange => true;
|
||||
|
||||
protected override UserActivity InitialActivity => new UserActivity.ChoosingBeatmap();
|
||||
@ -49,8 +54,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,10 +86,19 @@ 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 (autoType == null)
|
||||
{
|
||||
notifications?.Post(new SimpleNotification
|
||||
{
|
||||
Text = "The current ruleset doesn't have an autoplay mod avalaible!"
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mods.All(m => m.GetType() != autoType))
|
||||
{
|
||||
Mods.Value = mods.Append(auto).ToArray();
|
||||
|
Loading…
Reference in New Issue
Block a user