From aeb55ee25da10960e7aa98f60ea7a7d0438299c6 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Wed, 12 Mar 2025 17:07:23 +0900 Subject: [PATCH] Don't use `is` for null-checks --- .../Playlists/PlaylistsRoomSubScreen.cs | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomSubScreen.cs b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomSubScreen.cs index f8dd9cd3d9..31d5c7ea33 100644 --- a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomSubScreen.cs +++ b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomSubScreen.cs @@ -526,19 +526,19 @@ namespace osu.Game.Screens.OnlinePlay.Playlists /// /// Responds to changes in to validate the user style and update the global gameplay state. /// - private void onSelectedItemChanged(ValueChangedEvent e) + private void onSelectedItemChanged(ValueChangedEvent item) { - if (e.NewValue is not PlaylistItem item) + if (item.NewValue == null) return; // Always resetting the user beatmap style when a new item is selected is most intuitive. UserBeatmap.Value = null; - if (item.Freestyle) + if (item.NewValue.Freestyle) { // If freestyle is active, attempt to preserve the user ruleset style but only if the online item is from the osu! ruleset // (i.e. the beatmap is generally always convertible to the current ruleset, excluding custom rulesets). - if (item.RulesetID > 0) + if (item.NewValue.RulesetID > 0) UserRuleset.Value = null; } else @@ -554,9 +554,11 @@ namespace osu.Game.Screens.OnlinePlay.Playlists /// private Mod[] listAllowedMods() { - if (SelectedItem.Value is not PlaylistItem item) + if (SelectedItem.Value == null) return []; + PlaylistItem item = SelectedItem.Value; + RulesetInfo gameplayRuleset = UserRuleset.Value ?? rulesets.GetRuleset(item.RulesetID)!; Ruleset rulesetInstance = gameplayRuleset.CreateInstance(); @@ -580,9 +582,11 @@ namespace osu.Game.Screens.OnlinePlay.Playlists /// private void updateGameplayState() { - if (!this.IsCurrentScreen() || SelectedItem.Value is not PlaylistItem item) + if (!this.IsCurrentScreen() || SelectedItem.Value == null) return; + PlaylistItem item = SelectedItem.Value; + IBeatmapInfo gameplayBeatmap = UserBeatmap.Value ?? item.Beatmap; RulesetInfo gameplayRuleset = UserRuleset.Value ?? rulesets.GetRuleset(item.RulesetID)!; Ruleset rulesetInstance = gameplayRuleset.CreateInstance(); @@ -638,9 +642,11 @@ namespace osu.Game.Screens.OnlinePlay.Playlists /// private void startPlay() { - if (!this.IsCurrentScreen() || SelectedItem.Value is not PlaylistItem item) + if (!this.IsCurrentScreen() || SelectedItem.Value == null) return; + PlaylistItem item = SelectedItem.Value; + // Required for validation inside the player. RulesetInfo gameplayRuleset = UserRuleset.Value ?? rulesets.GetRuleset(item.RulesetID)!; IBeatmapInfo gameplayBeatmap = UserBeatmap.Value ?? item.Beatmap; @@ -661,7 +667,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists /// private void showUserModSelect() { - if (!this.IsCurrentScreen() || SelectedItem.Value is not PlaylistItem) + if (!this.IsCurrentScreen() || SelectedItem.Value == null) return; userModsSelectOverlay.Show(); @@ -672,10 +678,10 @@ namespace osu.Game.Screens.OnlinePlay.Playlists /// private void showUserStyleSelect() { - if (!this.IsCurrentScreen() || SelectedItem.Value is not PlaylistItem item) + if (!this.IsCurrentScreen() || SelectedItem.Value == null) return; - this.Push(new PlaylistsRoomFreestyleSelect(room, item) + this.Push(new PlaylistsRoomFreestyleSelect(room, SelectedItem.Value) { Beatmap = { BindTarget = UserBeatmap }, Ruleset = { BindTarget = UserRuleset }