diff --git a/osu.Game.Rulesets.Taiko/Skinning/Legacy/LegacyTaikoScroller.cs b/osu.Game.Rulesets.Taiko/Skinning/Legacy/LegacyTaikoScroller.cs index 2964473f8903..030ec9190e48 100644 --- a/osu.Game.Rulesets.Taiko/Skinning/Legacy/LegacyTaikoScroller.cs +++ b/osu.Game.Rulesets.Taiko/Skinning/Legacy/LegacyTaikoScroller.cs @@ -17,7 +17,7 @@ namespace osu.Game.Rulesets.Taiko.Skinning.Legacy { public partial class LegacyTaikoScroller : CompositeDrawable { - public Bindable LastResult = new Bindable(); + public Bindable LastResult = new Bindable(); public LegacyTaikoScroller() { diff --git a/osu.Game/Graphics/UserInterface/DrawableStatefulMenuItem.cs b/osu.Game/Graphics/UserInterface/DrawableStatefulMenuItem.cs index 4206f77c9865..f917203b6b0f 100644 --- a/osu.Game/Graphics/UserInterface/DrawableStatefulMenuItem.cs +++ b/osu.Game/Graphics/UserInterface/DrawableStatefulMenuItem.cs @@ -37,7 +37,7 @@ protected override bool OnMouseDown(MouseDownEvent e) private partial class ToggleTextContainer : TextContainer { private readonly StatefulMenuItem menuItem; - private readonly Bindable state; + private readonly Bindable state; private readonly SpriteIcon stateIcon; public ToggleTextContainer(StatefulMenuItem menuItem) @@ -61,7 +61,7 @@ protected override void LoadComplete() state.BindValueChanged(updateState, true); } - private void updateState(ValueChangedEvent state) + private void updateState(ValueChangedEvent state) { var icon = menuItem.GetIconForState(state.NewValue); diff --git a/osu.Game/Graphics/UserInterface/StatefulMenuItem.cs b/osu.Game/Graphics/UserInterface/StatefulMenuItem.cs index 85efd75a60f3..c3d8877ede53 100644 --- a/osu.Game/Graphics/UserInterface/StatefulMenuItem.cs +++ b/osu.Game/Graphics/UserInterface/StatefulMenuItem.cs @@ -2,7 +2,9 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Diagnostics; using osu.Framework.Bindables; +using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics.Sprites; using osu.Framework.Localisation; @@ -16,7 +18,7 @@ public abstract class StatefulMenuItem : OsuMenuItem /// /// The current state that should be displayed. /// - public readonly Bindable State = new Bindable(); + public readonly Bindable State = new Bindable(); /// /// Creates a new . @@ -24,7 +26,7 @@ public abstract class StatefulMenuItem : OsuMenuItem /// The text to display. /// A function that mutates a state to another state after this is pressed. /// The type of action which this performs. - protected StatefulMenuItem(LocalisableString text, Func changeStateFunc, MenuItemType type = MenuItemType.Standard) + protected StatefulMenuItem(LocalisableString text, Func changeStateFunc, MenuItemType type = MenuItemType.Standard) : this(text, changeStateFunc, type, null) { } @@ -36,7 +38,7 @@ protected StatefulMenuItem(LocalisableString text, Func changeSt /// A function that mutates a state to another state after this is pressed. /// The type of action which this performs. /// A delegate to be invoked when this is pressed. - protected StatefulMenuItem(LocalisableString text, Func? changeStateFunc, MenuItemType type, Action? action) + protected StatefulMenuItem(LocalisableString text, Func? changeStateFunc, MenuItemType type, Action? action) : base(text, type) { Action.Value = () => @@ -51,7 +53,7 @@ protected StatefulMenuItem(LocalisableString text, Func? changeS /// /// The state to retrieve the relevant icon for. /// The icon to be displayed for . - public abstract IconUsage? GetIconForState(object state); + public abstract IconUsage? GetIconForState(object? state); } public abstract class StatefulMenuItem : StatefulMenuItem @@ -81,20 +83,21 @@ protected StatefulMenuItem(LocalisableString text, Func? changeStateFunc, /// The type of action which this performs. /// A delegate to be invoked when this is pressed. protected StatefulMenuItem(LocalisableString text, Func? changeStateFunc, MenuItemType type, Action? action) - : base(text, o => changeStateFunc?.Invoke((T)o) ?? o, type, o => action?.Invoke((T)o)) + : base(text, o => changeStateFunc?.Invoke((T)o.AsNonNull()) ?? o, type, o => action?.Invoke((T)o.AsNonNull())) { base.State.BindValueChanged(state => { if (state.NewValue == null) base.State.Value = default(T); + Debug.Assert(base.State.Value != null); State.Value = (T)base.State.Value; }, true); State.BindValueChanged(state => base.State.Value = state.NewValue); } - public sealed override IconUsage? GetIconForState(object state) => GetIconForState((T)state); + public sealed override IconUsage? GetIconForState(object? state) => GetIconForState((T)state!); /// /// Retrieves the icon to be displayed for a state. diff --git a/osu.Game/Overlays/Chat/ChatTextBar.cs b/osu.Game/Overlays/Chat/ChatTextBar.cs index 0a42363279d8..980a27807436 100644 --- a/osu.Game/Overlays/Chat/ChatTextBar.cs +++ b/osu.Game/Overlays/Chat/ChatTextBar.cs @@ -32,7 +32,7 @@ public partial class ChatTextBar : Container public void TextBoxKillFocus() => chatTextBox.KillFocus(); [Resolved] - private Bindable currentChannel { get; set; } = null!; + private Bindable currentChannel { get; set; } = null!; private Container chattingTextContainer = null!; private OsuSpriteText chattingText = null!; @@ -138,7 +138,7 @@ protected override void LoadComplete() currentChannel.BindValueChanged(change => { - Channel newChannel = change.NewValue; + Channel? newChannel = change.NewValue; switch (newChannel?.Type) { diff --git a/osu.Game/Overlays/Settings/Sections/Graphics/LayoutSettings.cs b/osu.Game/Overlays/Settings/Sections/Graphics/LayoutSettings.cs index f40a4c941fa2..2408f3cd35b6 100644 --- a/osu.Game/Overlays/Settings/Sections/Graphics/LayoutSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Graphics/LayoutSettings.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Drawing; using System.Linq; using osu.Framework; @@ -200,11 +201,7 @@ protected override void LoadComplete() currentDisplay.BindValueChanged(display => Schedule(() => { - if (display.NewValue == null) - { - resolutions.Clear(); - return; - } + Debug.Assert(display.NewValue != null); resolutions.ReplaceRange(1, resolutions.Count - 1, display.NewValue.DisplayModes .Where(m => m.Size.Width >= 800 && m.Size.Height >= 600) diff --git a/osu.Game/Screens/Edit/Components/BottomBarContainer.cs b/osu.Game/Screens/Edit/Components/BottomBarContainer.cs index da71457004ac..73cd4dfecb24 100644 --- a/osu.Game/Screens/Edit/Components/BottomBarContainer.cs +++ b/osu.Game/Screens/Edit/Components/BottomBarContainer.cs @@ -18,7 +18,7 @@ public partial class BottomBarContainer : Container protected readonly IBindable Beatmap = new Bindable(); - protected readonly IBindable Track = new Bindable(); + protected readonly IBindable Track = new Bindable(); public readonly Drawable Background; private readonly Container content; diff --git a/osu.Game/Screens/Edit/Setup/ColoursSection.cs b/osu.Game/Screens/Edit/Setup/ColoursSection.cs index 8de7f86523a7..f6c61daa69b4 100644 --- a/osu.Game/Screens/Edit/Setup/ColoursSection.cs +++ b/osu.Game/Screens/Edit/Setup/ColoursSection.cs @@ -66,7 +66,7 @@ protected override void LoadComplete() syncingColours = true; comboColours.Colours.Clear(); - comboColours.Colours.AddRange(Beatmap.BeatmapSkin?.ComboColours); + comboColours.Colours.AddRange(Beatmap.BeatmapSkin?.ComboColours ?? []); syncingColours = false; }); diff --git a/osu.Game/Screens/Edit/Timing/EffectSection.cs b/osu.Game/Screens/Edit/Timing/EffectSection.cs index f9ef46023266..34478958a31f 100644 --- a/osu.Game/Screens/Edit/Timing/EffectSection.cs +++ b/osu.Game/Screens/Edit/Timing/EffectSection.cs @@ -81,9 +81,9 @@ private void updateControlPointFromSlider(ValueChangedEvent scrollSpeed) effectPoint.ScrollSpeedBindable.Value = scrollSpeed.NewValue; } - protected override EffectControlPoint CreatePoint() + protected override EffectControlPoint CreatePointFrom(double time) { - var reference = Beatmap.ControlPointInfo.EffectPointAt(SelectedGroup.Value.Time); + var reference = Beatmap.ControlPointInfo.EffectPointAt(time); return new EffectControlPoint { diff --git a/osu.Game/Screens/Edit/Timing/GroupSection.cs b/osu.Game/Screens/Edit/Timing/GroupSection.cs index 13e802a8e46d..551922e05b0a 100644 --- a/osu.Game/Screens/Edit/Timing/GroupSection.cs +++ b/osu.Game/Screens/Edit/Timing/GroupSection.cs @@ -21,7 +21,7 @@ internal partial class GroupSection : CompositeDrawable private OsuButton button = null!; [Resolved] - protected Bindable SelectedGroup { get; private set; } = null!; + protected Bindable SelectedGroup { get; private set; } = null!; [Resolved] protected EditorBeatmap Beatmap { get; private set; } = null!; diff --git a/osu.Game/Screens/Edit/Timing/Section.cs b/osu.Game/Screens/Edit/Timing/Section.cs index ba3874dcee91..a1b0fa416ea9 100644 --- a/osu.Game/Screens/Edit/Timing/Section.cs +++ b/osu.Game/Screens/Edit/Timing/Section.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System.Diagnostics; using System.Linq; using osu.Framework.Allocation; using osu.Framework.Bindables; @@ -30,7 +31,7 @@ internal abstract partial class Section : CompositeDrawable protected EditorBeatmap Beatmap { get; private set; } = null!; [Resolved] - protected Bindable SelectedGroup { get; private set; } = null!; + protected Bindable SelectedGroup { get; private set; } = null!; [Resolved] protected IEditorChangeHandler? ChangeHandler { get; private set; } @@ -103,12 +104,13 @@ protected override void LoadComplete() } if (ControlPoint.Value == null) - SelectedGroup.Value.Add(ControlPoint.Value = CreatePoint()); + SelectedGroup.Value.Add(ControlPoint.Value = CreatePointFrom(SelectedGroup.Value.Time)); } else { if (ControlPoint.Value != null) { + Debug.Assert(SelectedGroup.Value != null); SelectedGroup.Value.Remove(ControlPoint.Value); ControlPoint.Value = null; } @@ -128,6 +130,6 @@ protected override void LoadComplete() protected abstract void OnControlPointChanged(ValueChangedEvent point); - protected abstract T CreatePoint(); + protected abstract T CreatePointFrom(double time); } } diff --git a/osu.Game/Screens/Edit/Timing/TapTimingControl.cs b/osu.Game/Screens/Edit/Timing/TapTimingControl.cs index f105c0072631..ffe7a439b56d 100644 --- a/osu.Game/Screens/Edit/Timing/TapTimingControl.cs +++ b/osu.Game/Screens/Edit/Timing/TapTimingControl.cs @@ -31,7 +31,7 @@ public partial class TapTimingControl : CompositeDrawable private OsuConfigManager configManager { get; set; } = null!; [Resolved] - private Bindable selectedGroup { get; set; } = null!; + private Bindable selectedGroup { get; set; } = null!; private readonly BindableBool isHandlingTapping = new BindableBool(); diff --git a/osu.Game/Screens/Edit/Timing/TimingSection.cs b/osu.Game/Screens/Edit/Timing/TimingSection.cs index ae1ac02dd647..c02b51ad473c 100644 --- a/osu.Game/Screens/Edit/Timing/TimingSection.cs +++ b/osu.Game/Screens/Edit/Timing/TimingSection.cs @@ -83,9 +83,9 @@ protected override void OnControlPointChanged(ValueChangedEvent ruleset { get; set; } = null!; + private IBindable ruleset { get; set; } = null!; [Resolved] private IBindable> mods { get; set; } = null!; @@ -186,6 +186,7 @@ private void subscribeToLocalScores(BeatmapInfo beatmapInfo, CancellationToken c scoreSubscription?.Dispose(); scoreSubscription = null; + Debug.Assert(ruleset.Value != null); scoreSubscription = realm.RegisterForNotifications(r => r.All().Filter($"{nameof(ScoreInfo.BeatmapInfo)}.{nameof(BeatmapInfo.ID)} == $0" + $" AND {nameof(ScoreInfo.BeatmapInfo)}.{nameof(BeatmapInfo.Hash)} == {nameof(ScoreInfo.BeatmapHash)}" diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index 9f7a2c02ff1a..e30ef761cde9 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -135,7 +135,7 @@ public abstract partial class SongSelect : ScreenWithBeatmapBackground, IKeyBind private FooterButtonOptions beatmapOptionsButton = null!; - private readonly Bindable decoupledRuleset = new Bindable(); + private readonly Bindable decoupledRuleset = new Bindable(); private double audioFeedbackLastPlaybackTime; @@ -426,7 +426,7 @@ protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnl dependencies.CacheAs(this); dependencies.CacheAs(decoupledRuleset); - dependencies.CacheAs>(decoupledRuleset); + dependencies.CacheAs>(decoupledRuleset); return dependencies; } @@ -994,7 +994,7 @@ private void bindBindables() selectedMods.BindValueChanged(_ => { - if (decoupledRuleset.Value.Equals(rulesetNoDebounce)) + if (decoupledRuleset.Value?.Equals(rulesetNoDebounce) ?? false) advancedStats.Mods.Value = selectedMods.Value; }, true); diff --git a/osu.Game/Skinning/SkinnableSprite.cs b/osu.Game/Skinning/SkinnableSprite.cs index 9effb483c430..a3b207a29a2e 100644 --- a/osu.Game/Skinning/SkinnableSprite.cs +++ b/osu.Game/Skinning/SkinnableSprite.cs @@ -48,7 +48,7 @@ public SkinnableSprite() SpriteName.BindValueChanged(name => { - ((SpriteComponentLookup)ComponentLookup).LookupName = name.NewValue ?? string.Empty; + ((SpriteComponentLookup)ComponentLookup).LookupName = name.NewValue; if (IsLoaded) SkinChanged(CurrentSkin); });