From e081fa48a21d2b89ab9d956e62495b95f4ea9c1f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 17 Oct 2023 17:48:51 +0900 Subject: [PATCH] Fix various other inspections --- .../Editor/TestSceneObjectMerging.cs | 6 +++--- .../Editor/TestSceneSliderSplitting.cs | 2 +- .../Editing/TestSceneEditorBeatmapCreation.cs | 12 ++++++------ osu.Game.Tournament/Components/DateTextBox.cs | 2 +- osu.Game/Beatmaps/DummyWorkingBeatmap.cs | 14 ++++++++++---- osu.Game/Beatmaps/WorkingBeatmapCache.cs | 2 +- osu.Game/Graphics/Backgrounds/SkinBackground.cs | 2 +- osu.Game/Graphics/Containers/SectionsContainer.cs | 10 +++++----- osu.Game/Graphics/UserInterface/OsuSliderBar.cs | 2 +- osu.Game/IO/FileInfo.cs | 2 +- osu.Game/Online/API/Requests/Responses/APIUser.cs | 2 +- osu.Game/Online/Placeholders/MessagePlaceholder.cs | 2 +- osu.Game/Overlays/FullscreenOverlay.cs | 2 +- osu.Game/Rulesets/Objects/Legacy/ConvertSlider.cs | 5 +++-- .../Rulesets/UI/DrawableRulesetDependencies.cs | 2 +- .../Screens/Backgrounds/BackgroundScreenCustom.cs | 2 +- osu.Game/Screens/OsuScreen.cs | 4 ++-- osu.Game/Screens/Play/SkipOverlay.cs | 2 ++ osu.Game/Screens/Select/SongSelect.cs | 2 +- 19 files changed, 43 insertions(+), 34 deletions(-) diff --git a/osu.Game.Rulesets.Osu.Tests/Editor/TestSceneObjectMerging.cs b/osu.Game.Rulesets.Osu.Tests/Editor/TestSceneObjectMerging.cs index b05c755bfd..8d8386cae1 100644 --- a/osu.Game.Rulesets.Osu.Tests/Editor/TestSceneObjectMerging.cs +++ b/osu.Game.Rulesets.Osu.Tests/Editor/TestSceneObjectMerging.cs @@ -34,7 +34,7 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor }); moveMouseToHitObject(1); - AddAssert("merge option available", () => selectionHandler.ContextMenuItems.Any(o => o.Text.Value == "Merge selection")); + AddAssert("merge option available", () => selectionHandler.ContextMenuItems?.Any(o => o.Text.Value == "Merge selection") == true); mergeSelection(); @@ -198,7 +198,7 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor }); moveMouseToHitObject(1); - AddAssert("merge option not available", () => selectionHandler.ContextMenuItems.Length > 0 && selectionHandler.ContextMenuItems.All(o => o.Text.Value != "Merge selection")); + AddAssert("merge option not available", () => selectionHandler.ContextMenuItems?.Length > 0 && selectionHandler.ContextMenuItems.All(o => o.Text.Value != "Merge selection")); mergeSelection(); AddAssert("circles not merged", () => circle1 is not null && circle2 is not null && EditorBeatmap.HitObjects.Contains(circle1) && EditorBeatmap.HitObjects.Contains(circle2)); @@ -222,7 +222,7 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor }); moveMouseToHitObject(1); - AddAssert("merge option available", () => selectionHandler.ContextMenuItems.Any(o => o.Text.Value == "Merge selection")); + AddAssert("merge option available", () => selectionHandler.ContextMenuItems?.Any(o => o.Text.Value == "Merge selection") == true); mergeSelection(); diff --git a/osu.Game.Rulesets.Osu.Tests/Editor/TestSceneSliderSplitting.cs b/osu.Game.Rulesets.Osu.Tests/Editor/TestSceneSliderSplitting.cs index 60264572ab..ad37258c9b 100644 --- a/osu.Game.Rulesets.Osu.Tests/Editor/TestSceneSliderSplitting.cs +++ b/osu.Game.Rulesets.Osu.Tests/Editor/TestSceneSliderSplitting.cs @@ -241,7 +241,7 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor { if (visualiser is null) return; - MenuItem? item = visualiser.ContextMenuItems.FirstOrDefault(menuItem => menuItem.Text.Value == contextMenuText); + MenuItem? item = visualiser.ContextMenuItems?.FirstOrDefault(menuItem => menuItem.Text.Value == contextMenuText); item?.Action.Value?.Invoke(); }); diff --git a/osu.Game.Tests/Visual/Editing/TestSceneEditorBeatmapCreation.cs b/osu.Game.Tests/Visual/Editing/TestSceneEditorBeatmapCreation.cs index e6c3eea925..7a2ed23cae 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneEditorBeatmapCreation.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneEditorBeatmapCreation.cs @@ -182,7 +182,7 @@ namespace osu.Game.Tests.Visual.Editing if (sameRuleset) { AddUntilStep("wait for dialog", () => DialogOverlay.CurrentDialog is CreateNewDifficultyDialog); - AddStep("confirm creation with no objects", () => DialogOverlay.CurrentDialog.PerformOkAction()); + AddStep("confirm creation with no objects", () => DialogOverlay.CurrentDialog!.PerformOkAction()); } AddUntilStep("wait for created", () => @@ -269,7 +269,7 @@ namespace osu.Game.Tests.Visual.Editing AddStep("create new difficulty", () => Editor.CreateNewDifficulty(new OsuRuleset().RulesetInfo)); AddUntilStep("wait for dialog", () => DialogOverlay.CurrentDialog is CreateNewDifficultyDialog); - AddStep("confirm creation as a copy", () => DialogOverlay.CurrentDialog.Buttons.ElementAt(1).TriggerClick()); + AddStep("confirm creation as a copy", () => DialogOverlay.CurrentDialog!.Buttons.ElementAt(1).TriggerClick()); AddUntilStep("wait for created", () => { @@ -342,7 +342,7 @@ namespace osu.Game.Tests.Visual.Editing AddStep("create new difficulty", () => Editor.CreateNewDifficulty(new OsuRuleset().RulesetInfo)); AddUntilStep("wait for dialog", () => DialogOverlay.CurrentDialog is CreateNewDifficultyDialog); - AddStep("confirm creation as a copy", () => DialogOverlay.CurrentDialog.Buttons.ElementAt(1).TriggerClick()); + AddStep("confirm creation as a copy", () => DialogOverlay.CurrentDialog!.Buttons.ElementAt(1).TriggerClick()); AddUntilStep("wait for created", () => { @@ -380,7 +380,7 @@ namespace osu.Game.Tests.Visual.Editing AddStep("try to create new difficulty", () => Editor.CreateNewDifficulty(new OsuRuleset().RulesetInfo)); AddUntilStep("wait for dialog", () => DialogOverlay.CurrentDialog is CreateNewDifficultyDialog); - AddStep("confirm creation with no objects", () => DialogOverlay.CurrentDialog.PerformOkAction()); + AddStep("confirm creation with no objects", () => DialogOverlay.CurrentDialog!.PerformOkAction()); AddUntilStep("wait for created", () => { @@ -415,7 +415,7 @@ namespace osu.Game.Tests.Visual.Editing if (sameRuleset) { AddUntilStep("wait for dialog", () => DialogOverlay.CurrentDialog is CreateNewDifficultyDialog); - AddStep("confirm creation with no objects", () => DialogOverlay.CurrentDialog.PerformOkAction()); + AddStep("confirm creation with no objects", () => DialogOverlay.CurrentDialog!.PerformOkAction()); } AddUntilStep("wait for created", () => @@ -476,7 +476,7 @@ namespace osu.Game.Tests.Visual.Editing AddStep("exit", () => Editor.Exit()); AddUntilStep("wait for dialog", () => DialogOverlay.CurrentDialog is PromptForSaveDialog); - AddStep("attempt to save", () => DialogOverlay.CurrentDialog.PerformOkAction()); + AddStep("attempt to save", () => DialogOverlay.CurrentDialog!.PerformOkAction()); AddAssert("editor is still current", () => Editor.IsCurrentScreen()); } diff --git a/osu.Game.Tournament/Components/DateTextBox.cs b/osu.Game.Tournament/Components/DateTextBox.cs index 0993a4c05e..d87c091f77 100644 --- a/osu.Game.Tournament/Components/DateTextBox.cs +++ b/osu.Game.Tournament/Components/DateTextBox.cs @@ -15,7 +15,7 @@ namespace osu.Game.Tournament.Components public new Bindable? Current { get => current; - set => current.Current = value; + set => current.Current = value!; } public DateTextBox() diff --git a/osu.Game/Beatmaps/DummyWorkingBeatmap.cs b/osu.Game/Beatmaps/DummyWorkingBeatmap.cs index e2e541811d..d254945a51 100644 --- a/osu.Game/Beatmaps/DummyWorkingBeatmap.cs +++ b/osu.Game/Beatmaps/DummyWorkingBeatmap.cs @@ -70,9 +70,9 @@ namespace osu.Game.Beatmaps throw new NotImplementedException(); } - public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => new DummyBeatmapConverter { Beatmap = beatmap }; + public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => new DummyBeatmapConverter(beatmap); - public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => null; + public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => throw new NotImplementedException(); public override string Description => "dummy"; @@ -80,9 +80,15 @@ namespace osu.Game.Beatmaps private class DummyBeatmapConverter : IBeatmapConverter { - public event Action> ObjectConverted; + public IBeatmap Beatmap { get; } - public IBeatmap Beatmap { get; set; } + public DummyBeatmapConverter(IBeatmap beatmap) + { + Beatmap = beatmap; + } + + [CanBeNull] + public event Action> ObjectConverted; public bool CanConvert() => true; diff --git a/osu.Game/Beatmaps/WorkingBeatmapCache.cs b/osu.Game/Beatmaps/WorkingBeatmapCache.cs index 78eed626f2..2c500146c5 100644 --- a/osu.Game/Beatmaps/WorkingBeatmapCache.cs +++ b/osu.Game/Beatmaps/WorkingBeatmapCache.cs @@ -86,7 +86,7 @@ namespace osu.Game.Beatmaps public event Action OnInvalidated; - public virtual WorkingBeatmap GetWorkingBeatmap(BeatmapInfo beatmapInfo) + public virtual WorkingBeatmap GetWorkingBeatmap([CanBeNull] BeatmapInfo beatmapInfo) { if (beatmapInfo?.BeatmapSet == null) return DefaultBeatmap; diff --git a/osu.Game/Graphics/Backgrounds/SkinBackground.cs b/osu.Game/Graphics/Backgrounds/SkinBackground.cs index 17af5e6991..23806ae1d4 100644 --- a/osu.Game/Graphics/Backgrounds/SkinBackground.cs +++ b/osu.Game/Graphics/Backgrounds/SkinBackground.cs @@ -22,7 +22,7 @@ namespace osu.Game.Graphics.Backgrounds Sprite.Texture = skin.GetTexture("menu-background") ?? Sprite.Texture; } - public override bool Equals(Background other) + public override bool Equals(Background? other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; diff --git a/osu.Game/Graphics/Containers/SectionsContainer.cs b/osu.Game/Graphics/Containers/SectionsContainer.cs index 27ff6b851d..9f41c4eff2 100644 --- a/osu.Game/Graphics/Containers/SectionsContainer.cs +++ b/osu.Game/Graphics/Containers/SectionsContainer.cs @@ -119,11 +119,11 @@ namespace osu.Game.Graphics.Containers headerBackgroundContainer.Clear(); headerBackground = value; - if (value == null) return; - - headerBackgroundContainer.Add(headerBackground); - - lastKnownScroll = null; + if (headerBackground != null) + { + headerBackgroundContainer.Add(headerBackground); + lastKnownScroll = null; + } } } diff --git a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs index e5f5f97eb7..191a7ca246 100644 --- a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs +++ b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs @@ -62,7 +62,7 @@ namespace osu.Game.Graphics.UserInterface if (!PlaySamplesOnAdjust) return; - if (Clock == null || Clock.CurrentTime - lastSampleTime <= 30) + if (Clock.CurrentTime - lastSampleTime <= 30) return; if (value.Equals(lastSampleValue)) diff --git a/osu.Game/IO/FileInfo.cs b/osu.Game/IO/FileInfo.cs index 3d32e7fb6d..b8a7f363e0 100644 --- a/osu.Game/IO/FileInfo.cs +++ b/osu.Game/IO/FileInfo.cs @@ -13,7 +13,7 @@ namespace osu.Game.IO public bool IsManaged => ID > 0; - public string Hash { get; set; } + public string Hash { get; set; } = string.Empty; public int ReferenceCount { get; set; } } diff --git a/osu.Game/Online/API/Requests/Responses/APIUser.cs b/osu.Game/Online/API/Requests/Responses/APIUser.cs index e63395fe26..d9208d0662 100644 --- a/osu.Game/Online/API/Requests/Responses/APIUser.cs +++ b/osu.Game/Online/API/Requests/Responses/APIUser.cs @@ -29,7 +29,7 @@ namespace osu.Game.Online.API.Requests.Responses public DateTimeOffset JoinDate; [JsonProperty(@"username")] - public string Username { get; set; } + public string Username { get; set; } = string.Empty; [JsonProperty(@"previous_usernames")] public string[] PreviousUsernames; diff --git a/osu.Game/Online/Placeholders/MessagePlaceholder.cs b/osu.Game/Online/Placeholders/MessagePlaceholder.cs index bef889a576..b4a9c2086b 100644 --- a/osu.Game/Online/Placeholders/MessagePlaceholder.cs +++ b/osu.Game/Online/Placeholders/MessagePlaceholder.cs @@ -22,6 +22,6 @@ namespace osu.Game.Online.Placeholders AddText(this.message = message); } - public override bool Equals(Placeholder other) => (other as MessagePlaceholder)?.message == message; + public override bool Equals(Placeholder? other) => (other as MessagePlaceholder)?.message == message; } } diff --git a/osu.Game/Overlays/FullscreenOverlay.cs b/osu.Game/Overlays/FullscreenOverlay.cs index 7ae5167081..6ee045c492 100644 --- a/osu.Game/Overlays/FullscreenOverlay.cs +++ b/osu.Game/Overlays/FullscreenOverlay.cs @@ -17,7 +17,7 @@ namespace osu.Game.Overlays public abstract partial class FullscreenOverlay : WaveOverlayContainer, INamedOverlayComponent where T : OverlayHeader { - public virtual string IconTexture => Header.Title.IconTexture ?? string.Empty; + public virtual string IconTexture => Header.Title.IconTexture; public virtual LocalisableString Title => Header.Title.Title; public virtual LocalisableString Description => Header.Title.Description; diff --git a/osu.Game/Rulesets/Objects/Legacy/ConvertSlider.cs b/osu.Game/Rulesets/Objects/Legacy/ConvertSlider.cs index ab8fd2c662..683eefa8f4 100644 --- a/osu.Game/Rulesets/Objects/Legacy/ConvertSlider.cs +++ b/osu.Game/Rulesets/Objects/Legacy/ConvertSlider.cs @@ -23,11 +23,12 @@ namespace osu.Game.Rulesets.Objects.Legacy /// /// s don't need a curve since they're converted to ruleset-specific hitobjects. /// - public SliderPath Path { get; set; } + public SliderPath Path { get; set; } = null!; public double Distance => Path.Distance; - public IList> NodeSamples { get; set; } + public IList> NodeSamples { get; set; } = null!; + public int RepeatCount { get; set; } [JsonIgnore] diff --git a/osu.Game/Rulesets/UI/DrawableRulesetDependencies.cs b/osu.Game/Rulesets/UI/DrawableRulesetDependencies.cs index e34289c968..02c5bbb27e 100644 --- a/osu.Game/Rulesets/UI/DrawableRulesetDependencies.cs +++ b/osu.Game/Rulesets/UI/DrawableRulesetDependencies.cs @@ -186,7 +186,7 @@ namespace osu.Game.Rulesets.UI this.fallback = fallback; } - public override Texture Get(string name, WrapMode wrapModeS, WrapMode wrapModeT) + public override Texture? Get(string name, WrapMode wrapModeS, WrapMode wrapModeT) => primary.Get(name, wrapModeS, wrapModeT) ?? fallback.Get(name, wrapModeS, wrapModeT); protected override void Dispose(bool disposing) diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenCustom.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenCustom.cs index 14331c1978..3862e2a7e0 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenCustom.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenCustom.cs @@ -15,7 +15,7 @@ namespace osu.Game.Screens.Backgrounds AddInternal(new Background(textureName)); } - public override bool Equals(BackgroundScreen other) + public override bool Equals(BackgroundScreen? other) { if (other is BackgroundScreenCustom backgroundScreenCustom) return base.Equals(other) && textureName == backgroundScreenCustom.textureName; diff --git a/osu.Game/Screens/OsuScreen.cs b/osu.Game/Screens/OsuScreen.cs index 2dc9d5d49d..490a1ae6b8 100644 --- a/osu.Game/Screens/OsuScreen.cs +++ b/osu.Game/Screens/OsuScreen.cs @@ -89,9 +89,9 @@ namespace osu.Game.Screens public virtual bool? AllowGlobalTrackControl => null; - public Bindable Beatmap { get; private set; } + public Bindable Beatmap { get; private set; } = null!; - public Bindable Ruleset { get; private set; } + public Bindable Ruleset { get; private set; } = null!; public Bindable> Mods { get; private set; } diff --git a/osu.Game/Screens/Play/SkipOverlay.cs b/osu.Game/Screens/Play/SkipOverlay.cs index 7d69f0ca18..29b2e5229b 100644 --- a/osu.Game/Screens/Play/SkipOverlay.cs +++ b/osu.Game/Screens/Play/SkipOverlay.cs @@ -4,6 +4,7 @@ #nullable disable using System; +using JetBrains.Annotations; using osu.Framework; using osu.Framework.Allocation; using osu.Framework.Audio; @@ -211,6 +212,7 @@ namespace osu.Game.Screens.Play public partial class FadeContainer : Container, IStateful { + [CanBeNull] public event Action StateChanged; private Visibility state; diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index 2e457f827d..bac84b8134 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -647,7 +647,7 @@ namespace osu.Game.Screens.Select beginLooping(); - if (Beatmap != null && !Beatmap.Value.BeatmapSetInfo.DeletePending) + if (!Beatmap.Value.BeatmapSetInfo.DeletePending) { updateCarouselSelection();