remove unnecessary usages of nullable forgiveness, add asserts for debugging

This commit is contained in:
mk56-spn
2023-01-09 18:36:55 +01:00
parent a32c4a64e7
commit 69260ca3c3
7 changed files with 31 additions and 17 deletions

View File

@ -1069,7 +1069,7 @@ namespace osu.Game.Tests.Visual.SongSelect
return Precision.AlmostEquals( return Precision.AlmostEquals(
carousel.ScreenSpaceDrawQuad.Centre, carousel.ScreenSpaceDrawQuad.Centre,
carousel.Items carousel.Items
.First(i => i.Item!.State.Value == CarouselItemState.Selected) .First(i => i.Item?.State.Value == CarouselItemState.Selected)
.ScreenSpaceDrawQuad.Centre, 100); .ScreenSpaceDrawQuad.Centre, 100);
}); });
} }

View File

@ -770,7 +770,9 @@ namespace osu.Game.Screens.Select
{ {
updateItem(item); updateItem(item);
if (item.Item!.Visible) Debug.Assert(item.Item != null);
if (item.Item.Visible)
{ {
bool isSelected = item.Item.State.Value == CarouselItemState.Selected; bool isSelected = item.Item.State.Value == CarouselItemState.Selected;

View File

@ -10,7 +10,7 @@ namespace osu.Game.Screens.Select.Carousel
/// </summary> /// </summary>
public class CarouselGroup : CarouselItem public class CarouselGroup : CarouselItem
{ {
public override DrawableCarouselItem CreateDrawableRepresentation() => null!; public override DrawableCarouselItem? CreateDrawableRepresentation() => null;
public IReadOnlyList<CarouselItem> Items => items; public IReadOnlyList<CarouselItem> Items => items;

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using System.Diagnostics;
using osu.Framework.Bindables; using osu.Framework.Bindables;
namespace osu.Game.Screens.Select.Carousel namespace osu.Game.Screens.Select.Carousel
@ -41,7 +42,7 @@ namespace osu.Game.Screens.Select.Carousel
/// <summary> /// <summary>
/// Create a fresh drawable version of this item. /// Create a fresh drawable version of this item.
/// </summary> /// </summary>
public abstract DrawableCarouselItem CreateDrawableRepresentation(); public abstract DrawableCarouselItem? CreateDrawableRepresentation();
public virtual void Filter(FilterCriteria criteria) public virtual void Filter(FilterCriteria criteria)
{ {
@ -49,7 +50,12 @@ namespace osu.Game.Screens.Select.Carousel
public virtual int CompareTo(FilterCriteria criteria, CarouselItem other) => ItemID.CompareTo(other.ItemID); public virtual int CompareTo(FilterCriteria criteria, CarouselItem other) => ItemID.CompareTo(other.ItemID);
public int CompareTo(CarouselItem? other) => CarouselYPosition.CompareTo(other!.CarouselYPosition); public int CompareTo(CarouselItem? other)
{
Debug.Assert(other != null);
return CarouselYPosition.CompareTo(other.CarouselYPosition);
}
} }
public enum CarouselItemState public enum CarouselItemState

View File

@ -192,7 +192,7 @@ namespace osu.Game.Screens.Select.Carousel
protected override bool OnClick(ClickEvent e) protected override bool OnClick(ClickEvent e)
{ {
if (Item!.State.Value == CarouselItemState.Selected) if (Item?.State.Value == CarouselItemState.Selected)
startRequested?.Invoke(beatmapInfo); startRequested?.Invoke(beatmapInfo);
return base.OnClick(e); return base.OnClick(e);
@ -200,13 +200,13 @@ namespace osu.Game.Screens.Select.Carousel
protected override void ApplyState() protected override void ApplyState()
{ {
if (Item!.State.Value != CarouselItemState.Collapsed && Alpha == 0) if (Item?.State.Value != CarouselItemState.Collapsed && Alpha == 0)
starCounter.ReplayAnimation(); starCounter.ReplayAnimation();
starDifficultyCancellationSource?.Cancel(); starDifficultyCancellationSource?.Cancel();
// Only compute difficulty when the item is visible. // Only compute difficulty when the item is visible.
if (Item.State.Value != CarouselItemState.Collapsed) if (Item?.State.Value != CarouselItemState.Collapsed)
{ {
// We've potentially cancelled the computation above so a new bindable is required. // We've potentially cancelled the computation above so a new bindable is required.
starDifficultyBindable = difficultyCache.GetBindableDifficulty(beatmapInfo, (starDifficultyCancellationSource = new CancellationTokenSource()).Token); starDifficultyBindable = difficultyCache.GetBindableDifficulty(beatmapInfo, (starDifficultyCancellationSource = new CancellationTokenSource()).Token);

View File

@ -73,10 +73,10 @@ namespace osu.Game.Screens.Select.Carousel
{ {
base.Update(); base.Update();
Debug.Assert(Item != null);
// position updates should not occur if the item is filtered away. // position updates should not occur if the item is filtered away.
// this avoids panels flying across the screen only to be eventually off-screen or faded out. // this avoids panels flying across the screen only to be eventually off-screen or faded out.
if (!Item!.Visible) if (!Item.Visible) return;
return;
float targetY = Item.CarouselYPosition; float targetY = Item.CarouselYPosition;
@ -146,7 +146,9 @@ namespace osu.Game.Screens.Select.Carousel
private void updateBeatmapDifficulties() private void updateBeatmapDifficulties()
{ {
var carouselBeatmapSet = (CarouselBeatmapSet)Item!; if (Item == null) return;
var carouselBeatmapSet = (CarouselBeatmapSet)Item;
var visibleBeatmaps = carouselBeatmapSet.Items.Where(c => c.Visible).ToArray(); var visibleBeatmaps = carouselBeatmapSet.Items.Where(c => c.Visible).ToArray();
@ -166,7 +168,7 @@ namespace osu.Game.Screens.Select.Carousel
{ {
X = 100, X = 100,
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
ChildrenEnumerable = visibleBeatmaps.Select(c => c.CreateDrawableRepresentation()) ChildrenEnumerable = visibleBeatmaps.Select(c => c.CreateDrawableRepresentation()!)
}; };
beatmapsLoadTask = LoadComponentAsync(beatmapContainer, loaded => beatmapsLoadTask = LoadComponentAsync(beatmapContainer, loaded =>
@ -191,7 +193,7 @@ namespace osu.Game.Screens.Select.Carousel
float yPos = DrawableCarouselBeatmap.CAROUSEL_BEATMAP_SPACING; float yPos = DrawableCarouselBeatmap.CAROUSEL_BEATMAP_SPACING;
bool isSelected = Item!.State.Value == CarouselItemState.Selected; bool isSelected = Item?.State.Value == CarouselItemState.Selected;
foreach (var panel in beatmapContainer.Children) foreach (var panel in beatmapContainer.Children)
{ {
@ -213,7 +215,7 @@ namespace osu.Game.Screens.Select.Carousel
List<MenuItem> items = new List<MenuItem>(); List<MenuItem> items = new List<MenuItem>();
if (Item!.State.Value == CarouselItemState.NotSelected) if (Item?.State.Value == CarouselItemState.NotSelected)
items.Add(new OsuMenuItem("Expand", MenuItemType.Highlighted, () => Item.State.Value = CarouselItemState.Selected)); items.Add(new OsuMenuItem("Expand", MenuItemType.Highlighted, () => Item.State.Value = CarouselItemState.Selected));
if (beatmapSet.OnlineID > 0 && viewDetails != null) if (beatmapSet.OnlineID > 0 && viewDetails != null)

View File

@ -103,7 +103,7 @@ namespace osu.Game.Screens.Select.Carousel
protected virtual void UpdateItem() protected virtual void UpdateItem()
{ {
if (item == null || Item == null) if (Item == null)
return; return;
Scheduler.AddOnce(ApplyState); Scheduler.AddOnce(ApplyState);
@ -126,9 +126,11 @@ namespace osu.Game.Screens.Select.Carousel
protected virtual void ApplyState() protected virtual void ApplyState()
{ {
if (Item == null) return;
// Use the fact that we know the precise height of the item from the model to avoid the need for AutoSize overhead. // Use the fact that we know the precise height of the item from the model to avoid the need for AutoSize overhead.
// Additionally, AutoSize doesn't work well due to content starting off-screen and being masked away. // Additionally, AutoSize doesn't work well due to content starting off-screen and being masked away.
Height = Item!.TotalHeight; Height = Item.TotalHeight;
switch (Item.State.Value) switch (Item.State.Value)
{ {
@ -158,7 +160,9 @@ namespace osu.Game.Screens.Select.Carousel
protected override bool OnClick(ClickEvent e) protected override bool OnClick(ClickEvent e)
{ {
Item!.State.Value = CarouselItemState.Selected; Debug.Assert(Item != null);
Item.State.Value = CarouselItemState.Selected;
return true; return true;
} }
} }