1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 16:07:24 +08:00

Remove unnecessary null casts

This commit is contained in:
Dean Herbert 2022-06-24 14:48:43 +09:00
parent f4173a3bff
commit f71f6302fd
23 changed files with 30 additions and 33 deletions

View File

@ -161,7 +161,7 @@ namespace osu.Game.Rulesets.Osu.Tests
=> addCheckPositionChangeSteps(timeAtRepeat(startTime, repeatIndex), positionAtRepeat(repeatIndex), positionRemainsSame);
private Func<double> timeAtRepeat(Func<double> startTime, int repeatIndex) => () => startTime() + 100 + duration_of_span * repeatIndex;
private Func<Vector2> positionAtRepeat(int repeatIndex) => repeatIndex % 2 == 0 ? (Func<Vector2>)getSliderStart : getSliderEnd;
private Func<Vector2> positionAtRepeat(int repeatIndex) => repeatIndex % 2 == 0 ? getSliderStart : getSliderEnd;
private List<Vector2> getSliderCurve() => ((PlaySliderBody)drawableSlider.Body.Drawable).CurrentCurve;
private Vector2 getSliderStart() => getSliderCurve().First();

View File

@ -364,12 +364,12 @@ namespace osu.Game.Tests.NonVisual
private void confirmCurrentFrame(int? frame)
{
Assert.AreEqual(frame is int x ? replay.Frames[x].Time : (double?)null, handler.CurrentFrame?.Time, "Unexpected current frame");
Assert.AreEqual(frame is int x ? replay.Frames[x].Time : null, handler.CurrentFrame?.Time, "Unexpected current frame");
}
private void confirmNextFrame(int? frame)
{
Assert.AreEqual(frame is int x ? replay.Frames[x].Time : (double?)null, handler.NextFrame?.Time, "Unexpected next frame");
Assert.AreEqual(frame is int x ? replay.Frames[x].Time : null, handler.NextFrame?.Time, "Unexpected next frame");
}
private class TestReplayFrame : ReplayFrame

View File

@ -58,7 +58,7 @@ namespace osu.Game.Tests.Skins
{
AddStep($"Set beatmap skin enabled to {allowBeatmapLookups}", () => config.SetValue(OsuSetting.BeatmapSkins, allowBeatmapLookups));
ISkin expected() => allowBeatmapLookups ? (ISkin)beatmapSource : userSource;
ISkin expected() => allowBeatmapLookups ? beatmapSource : userSource;
AddAssert("Check lookup is from correct source", () => requester.FindProvider(s => s.GetDrawableComponent(new TestSkinComponent()) != null) == expected());
}

View File

@ -78,7 +78,7 @@ namespace osu.Game.Tests.Visual.UserInterface
Origin = Anchor.Centre,
Width = 500,
AutoSizeAxes = Axes.Y,
Child = component = padded ? (LabelledDrawable<Drawable>)new PaddedLabelledDrawable() : new NonPaddedLabelledDrawable(),
Child = component = padded ? new PaddedLabelledDrawable() : new NonPaddedLabelledDrawable(),
};
component.Label = "a sample component";

View File

@ -3,7 +3,6 @@
#nullable disable
using System;
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Game.Graphics.Sprites;
@ -89,7 +88,7 @@ namespace osu.Game.Tests.Visual.UserInterface
AddToggleStep("toggle enabled", toggle =>
{
for (int i = 0; i < 6; i++)
button.Action = toggle ? () => { } : (Action)null;
button.Action = toggle ? () => { } : null;
});
}

View File

@ -3,7 +3,6 @@
#nullable disable
using System;
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Game.Graphics.UserInterface;
@ -29,7 +28,7 @@ namespace osu.Game.Tests.Visual.UserInterface
AddToggleStep("toggle enabled", toggle =>
{
for (int i = 0; i < 6; i++)
button.Action = toggle ? () => { } : (Action)null;
button.Action = toggle ? () => { } : null;
});
}

View File

@ -260,7 +260,7 @@ namespace osu.Game.Graphics.Containers
if (host.Window == null) return;
bool coversWholeScreen = Size == Vector2.One && safeArea.SafeAreaPadding.Value.Total == Vector2.Zero;
host.Window.CursorConfineRect = coversWholeScreen ? (RectangleF?)null : ToScreenSpace(DrawRectangle).AABBFloat;
host.Window.CursorConfineRect = coversWholeScreen ? null : ToScreenSpace(DrawRectangle).AABBFloat;
}
}
}

View File

@ -1,7 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
@ -47,7 +46,7 @@ namespace osu.Game.Graphics.UserInterface
protected override void LoadComplete()
{
Active.BindDisabledChanged(disabled => Action = disabled ? (Action?)null : Active.Toggle, true);
Active.BindDisabledChanged(disabled => Action = disabled ? null : Active.Toggle, true);
Active.BindValueChanged(_ =>
{
updateActiveState();

View File

@ -34,6 +34,6 @@ namespace osu.Game.Graphics.UserInterface
{
}
public override IconUsage? GetIconForState(bool state) => state ? (IconUsage?)FontAwesome.Solid.Check : null;
public override IconUsage? GetIconForState(bool state) => state ? FontAwesome.Solid.Check : null;
}
}

View File

@ -89,7 +89,7 @@ namespace osu.Game
public virtual bool UseDevelopmentServer => DebugUtils.IsDebugBuild;
internal EndpointConfiguration CreateEndpoints() =>
UseDevelopmentServer ? (EndpointConfiguration)new DevelopmentEndpointConfiguration() : new ProductionEndpointConfiguration();
UseDevelopmentServer ? new DevelopmentEndpointConfiguration() : new ProductionEndpointConfiguration();
public virtual Version AssemblyVersion => Assembly.GetEntryAssembly()?.GetName().Version ?? new Version();
@ -583,6 +583,6 @@ namespace osu.Game
ControlPointInfo IBeatSyncProvider.ControlPoints => Beatmap.Value.Beatmap.ControlPointInfo;
IClock IBeatSyncProvider.Clock => Beatmap.Value.TrackLoaded ? Beatmap.Value.Track : (IClock)null;
ChannelAmplitudes? IBeatSyncProvider.Amplitudes => Beatmap.Value.TrackLoaded ? Beatmap.Value.Track.CurrentAmplitudes : (ChannelAmplitudes?)null;
ChannelAmplitudes? IBeatSyncProvider.Amplitudes => Beatmap.Value.TrackLoaded ? Beatmap.Value.Track.CurrentAmplitudes : null;
}
}

View File

@ -46,8 +46,8 @@ namespace osu.Game.Overlays.Mods
&& !ModUtils.CheckCompatibleSet(selectedMods.Value.Append(Mod));
}
protected override Colour4 BackgroundColour => incompatible.Value ? (Colour4)ColourProvider.Background6 : base.BackgroundColour;
protected override Colour4 ForegroundColour => incompatible.Value ? (Colour4)ColourProvider.Background5 : base.ForegroundColour;
protected override Colour4 BackgroundColour => incompatible.Value ? ColourProvider.Background6 : base.BackgroundColour;
protected override Colour4 ForegroundColour => incompatible.Value ? ColourProvider.Background5 : base.ForegroundColour;
protected override void UpdateState()
{

View File

@ -442,7 +442,7 @@ namespace osu.Game.Overlays.Mods
case ModType.DifficultyIncrease:
case ModType.Automation:
return hotkeyStyle == ModSelectHotkeyStyle.Sequential
? (IModHotkeyHandler)SequentialModHotkeyHandler.Create(ModType)
? SequentialModHotkeyHandler.Create(ModType)
: new ClassicModHotkeyHandler(allowIncompatibleSelection);
default:

View File

@ -216,9 +216,9 @@ namespace osu.Game.Overlays.Mods
base.OnMouseUp(e);
}
protected virtual Colour4 BackgroundColour => Active.Value ? activeColour.Darken(0.3f) : (Colour4)ColourProvider.Background3;
protected virtual Colour4 ForegroundColour => Active.Value ? activeColour : (Colour4)ColourProvider.Background2;
protected virtual Colour4 TextColour => Active.Value ? (Colour4)ColourProvider.Background6 : Colour4.White;
protected virtual Colour4 BackgroundColour => Active.Value ? activeColour.Darken(0.3f) : ColourProvider.Background3;
protected virtual Colour4 ForegroundColour => Active.Value ? activeColour : ColourProvider.Background2;
protected virtual Colour4 TextColour => Active.Value ? ColourProvider.Background6 : Colour4.White;
protected virtual void UpdateState()
{

View File

@ -79,7 +79,7 @@ namespace osu.Game.Rulesets
public int OnlineID
{
get => ID ?? -1;
set => ID = value >= 0 ? value : (int?)null;
set => ID = value >= 0 ? value : null;
}
#endregion

View File

@ -87,7 +87,7 @@ namespace osu.Game.Rulesets.Objects
}
public SliderPath(PathType type, Vector2[] controlPoints, double? expectedDistance = null)
: this(controlPoints.Select((c, i) => new PathControlPoint(c, i == 0 ? (PathType?)type : null)).ToArray(), expectedDistance)
: this(controlPoints.Select((c, i) => new PathControlPoint(c, i == 0 ? type : null)).ToArray(), expectedDistance)
{
}

View File

@ -161,7 +161,7 @@ namespace osu.Game.Rulesets.Replays
CurrentTime = Math.Clamp(time, frameStart, frameEnd);
// In an important section, a mid-frame time cannot be used and a null is returned instead.
return inImportantSection && frameStart < time && time < frameEnd ? null : (double?)CurrentTime;
return inImportantSection && frameStart < time && time < frameEnd ? null : CurrentTime;
}
private double getFrameTime(int index)

View File

@ -24,6 +24,6 @@ namespace osu.Game.Screens.Edit.Components.Menus
Action.Value = () => difficultyChangeFunc.Invoke(beatmapInfo);
}
public override IconUsage? GetIconForState(bool state) => state ? (IconUsage?)FontAwesome.Solid.Check : null;
public override IconUsage? GetIconForState(bool state) => state ? FontAwesome.Solid.Check : null;
}
}

View File

@ -131,7 +131,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
}
private static string? getCommonBank(SampleControlPoint[] relevantControlPoints) => relevantControlPoints.Select(point => point.SampleBank).Distinct().Count() == 1 ? relevantControlPoints.First().SampleBank : null;
private static int? getCommonVolume(SampleControlPoint[] relevantControlPoints) => relevantControlPoints.Select(point => point.SampleVolume).Distinct().Count() == 1 ? (int?)relevantControlPoints.First().SampleVolume : null;
private static int? getCommonVolume(SampleControlPoint[] relevantControlPoints) => relevantControlPoints.Select(point => point.SampleVolume).Distinct().Count() == 1 ? relevantControlPoints.First().SampleVolume : null;
private void updateBankFor(IEnumerable<HitObject> objects, string? newBank)
{

View File

@ -908,6 +908,6 @@ namespace osu.Game.Screens.Edit
ControlPointInfo IBeatSyncProvider.ControlPoints => editorBeatmap.ControlPointInfo;
IClock IBeatSyncProvider.Clock => clock;
ChannelAmplitudes? IBeatSyncProvider.Amplitudes => Beatmap.Value.TrackLoaded ? Beatmap.Value.Track.CurrentAmplitudes : (ChannelAmplitudes?)null;
ChannelAmplitudes? IBeatSyncProvider.Amplitudes => Beatmap.Value.TrackLoaded ? Beatmap.Value.Track.CurrentAmplitudes : null;
}
}

View File

@ -255,7 +255,7 @@ namespace osu.Game.Screens.Play
ControlPointInfo IBeatSyncProvider.ControlPoints => beatmap.Beatmap.ControlPointInfo;
IClock IBeatSyncProvider.Clock => GameplayClock;
ChannelAmplitudes? IBeatSyncProvider.Amplitudes => beatmap.TrackLoaded ? beatmap.Track.CurrentAmplitudes : (ChannelAmplitudes?)null;
ChannelAmplitudes? IBeatSyncProvider.Amplitudes => beatmap.TrackLoaded ? beatmap.Track.CurrentAmplitudes : null;
private class HardwareCorrectionOffsetClock : FramedOffsetClock
{

View File

@ -92,8 +92,8 @@ namespace osu.Game.Screens.Select.Carousel
var beatmaps = carouselSet.Beatmaps.ToList();
return beatmaps.Count > maximum_difficulty_icons
? (IEnumerable<DifficultyIcon>)beatmaps.GroupBy(b => b.BeatmapInfo.Ruleset)
.Select(group => new FilterableGroupedDifficultyIcon(group.ToList(), group.Last().BeatmapInfo.Ruleset))
? beatmaps.GroupBy(b => b.BeatmapInfo.Ruleset)
.Select(group => new FilterableGroupedDifficultyIcon(group.ToList(), group.Last().BeatmapInfo.Ruleset))
: beatmaps.Select(b => new FilterableDifficultyIcon(b));
}
}

View File

@ -448,14 +448,14 @@ namespace osu.Game.Screens.Utility
mainArea.AddRange(new[]
{
new LatencyArea(Key.Number1, betterSide == 1 ? mapDifficultyToTargetFrameRate(DifficultyLevel) : (int?)null)
new LatencyArea(Key.Number1, betterSide == 1 ? mapDifficultyToTargetFrameRate(DifficultyLevel) : null)
{
Width = 0.5f,
VisualMode = { BindTarget = VisualMode },
IsActiveArea = { Value = true },
ReportUserBest = () => recordResult(betterSide == 0),
},
new LatencyArea(Key.Number2, betterSide == 0 ? mapDifficultyToTargetFrameRate(DifficultyLevel) : (int?)null)
new LatencyArea(Key.Number2, betterSide == 0 ? mapDifficultyToTargetFrameRate(DifficultyLevel) : null)
{
Width = 0.5f,
VisualMode = { BindTarget = VisualMode },

View File

@ -56,7 +56,7 @@ namespace osu.Game.Storyboards
{
var first = Alpha.Commands.FirstOrDefault();
return first?.StartValue == 0 ? first.StartTime : (double?)null;
return first?.StartValue == 0 ? first.StartTime : null;
}
}