1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 11:37:28 +08:00

Use pattern matching wherever possible

This commit is contained in:
Dean Herbert 2019-02-28 14:35:00 +09:00
parent 94a389319d
commit e2c6a8bc07
13 changed files with 17 additions and 29 deletions

View File

@ -83,8 +83,7 @@ namespace osu.Desktop
public override void SetHost(GameHost host) public override void SetHost(GameHost host)
{ {
base.SetHost(host); base.SetHost(host);
var desktopWindow = host.Window as DesktopGameWindow; if (host.Window is DesktopGameWindow desktopWindow)
if (desktopWindow != null)
{ {
desktopWindow.CursorState |= CursorState.Hidden; desktopWindow.CursorState |= CursorState.Hidden;

View File

@ -74,8 +74,7 @@ namespace osu.Game.Rulesets.Mania.Beatmaps
protected override IEnumerable<ManiaHitObject> ConvertHitObject(HitObject original, IBeatmap beatmap) protected override IEnumerable<ManiaHitObject> ConvertHitObject(HitObject original, IBeatmap beatmap)
{ {
var maniaOriginal = original as ManiaHitObject; if (original is ManiaHitObject maniaOriginal)
if (maniaOriginal != null)
{ {
yield return maniaOriginal; yield return maniaOriginal;
yield break; yield break;

View File

@ -127,8 +127,7 @@ namespace osu.Game.Rulesets.Osu.Difficulty.Preprocessing
{ {
Vector2 pos = hitObject.StackedPosition; Vector2 pos = hitObject.StackedPosition;
var slider = hitObject as Slider; if (hitObject is Slider slider)
if (slider != null)
{ {
computeSliderCursorPosition(slider); computeSliderCursorPosition(slider);
pos = slider.LazyEndPosition ?? pos; pos = slider.LazyEndPosition ?? pos;

View File

@ -58,8 +58,7 @@ namespace osu.Game.Rulesets.Osu.UI
{ {
h.OnNewResult += onNewResult; h.OnNewResult += onNewResult;
var c = h as IDrawableHitObjectWithProxiedApproach; if (h is IDrawableHitObjectWithProxiedApproach c)
if (c != null)
{ {
var original = c.ProxiedLayer; var original = c.ProxiedLayer;

View File

@ -37,11 +37,9 @@ namespace osu.Game.Graphics.UserInterface
private void updateAccentColour() private void updateAccentColour()
{ {
var header = Header as IHasAccentColour; if (Header is IHasAccentColour header) header.AccentColour = accentColour;
if (header != null) header.AccentColour = accentColour;
var menu = Menu as IHasAccentColour; if (Menu is IHasAccentColour menu) menu.AccentColour = accentColour;
if (menu != null) menu.AccentColour = accentColour;
} }
protected override DropdownHeader CreateHeader() => new OsuDropdownHeader(); protected override DropdownHeader CreateHeader() => new OsuDropdownHeader();
@ -149,8 +147,7 @@ namespace osu.Game.Graphics.UserInterface
{ {
base.UpdateForegroundColour(); base.UpdateForegroundColour();
var content = Foreground.Children.FirstOrDefault() as Content; if (Foreground.Children.FirstOrDefault() is Content content) content.Chevron.Alpha = IsHovered ? 1 : 0;
if (content != null) content.Chevron.Alpha = IsHovered ? 1 : 0;
} }
protected override Drawable CreateContent() => new Content(); protected override Drawable CreateContent() => new Content();

View File

@ -64,8 +64,7 @@ namespace osu.Game.Graphics.UserInterface
set set
{ {
accentColour = value; accentColour = value;
var dropdown = Dropdown as IHasAccentColour; if (Dropdown is IHasAccentColour dropdown)
if (dropdown != null)
dropdown.AccentColour = value; dropdown.AccentColour = value;
foreach (var i in TabContainer.Children.OfType<IHasAccentColour>()) foreach (var i in TabContainer.Children.OfType<IHasAccentColour>())
i.AccentColour = value; i.AccentColour = value;

View File

@ -600,8 +600,7 @@ namespace osu.Game
private void loadComponentSingleFile<T>(T d, Action<T> add) private void loadComponentSingleFile<T>(T d, Action<T> add)
where T : Drawable where T : Drawable
{ {
var focused = d as FocusedOverlayContainer; if (d is FocusedOverlayContainer focused)
if (focused != null)
{ {
focused.StateChanged += s => focused.StateChanged += s =>
{ {

View File

@ -118,8 +118,7 @@ namespace osu.Game.Overlays
notification.Closed += notificationClosed; notification.Closed += notificationClosed;
var hasCompletionTarget = notification as IHasCompletionTarget; if (notification is IHasCompletionTarget hasCompletionTarget)
if (hasCompletionTarget != null)
hasCompletionTarget.CompletionTarget = Post; hasCompletionTarget.CompletionTarget = Post;
var ourType = notification.GetType(); var ourType = notification.GetType();

View File

@ -16,8 +16,7 @@ namespace osu.Game.Rulesets.Mods
public override void ApplyToClock(IAdjustableClock clock) public override void ApplyToClock(IAdjustableClock clock)
{ {
var pitchAdjust = clock as IHasPitchAdjust; if (clock is IHasPitchAdjust pitchAdjust)
if (pitchAdjust != null)
pitchAdjust.PitchAdjust = 0.75; pitchAdjust.PitchAdjust = 0.75;
else else
base.ApplyToClock(clock); base.ApplyToClock(clock);

View File

@ -16,8 +16,7 @@ namespace osu.Game.Rulesets.Mods
public override void ApplyToClock(IAdjustableClock clock) public override void ApplyToClock(IAdjustableClock clock)
{ {
var pitchAdjust = clock as IHasPitchAdjust; if (clock is IHasPitchAdjust pitchAdjust)
if (pitchAdjust != null)
pitchAdjust.PitchAdjust = 1.5; pitchAdjust.PitchAdjust = 1.5;
else else
base.ApplyToClock(clock); base.ApplyToClock(clock);

View File

@ -241,8 +241,7 @@ namespace osu.Game.Screens.Play
ComboCounter?.Current.BindTo(processor.Combo); ComboCounter?.Current.BindTo(processor.Combo);
HealthDisplay?.Current.BindTo(processor.Health); HealthDisplay?.Current.BindTo(processor.Health);
var shd = HealthDisplay as StandardHealthDisplay; if (HealthDisplay is StandardHealthDisplay shd)
if (shd != null)
processor.NewJudgement += shd.Flash; processor.NewJudgement += shd.Flash;
} }
} }

View File

@ -70,8 +70,7 @@ namespace osu.Game.Storyboards
applyCommands(drawable, getCommands(g => g.Alpha, triggeredGroups), (d, value) => d.Alpha = value, (d, value, duration, easing) => d.FadeTo(value, duration, easing)); applyCommands(drawable, getCommands(g => g.Alpha, triggeredGroups), (d, value) => d.Alpha = value, (d, value, duration, easing) => d.FadeTo(value, duration, easing));
applyCommands(drawable, getCommands(g => g.BlendingMode, triggeredGroups), (d, value) => d.Blending = value, (d, value, duration, easing) => d.TransformBlendingMode(value, duration), false); applyCommands(drawable, getCommands(g => g.BlendingMode, triggeredGroups), (d, value) => d.Blending = value, (d, value, duration, easing) => d.TransformBlendingMode(value, duration), false);
var flippable = drawable as IFlippable; if (drawable is IFlippable flippable)
if (flippable != null)
{ {
applyCommands(drawable, getCommands(g => g.FlipH, triggeredGroups), (d, value) => flippable.FlipH = value, (d, value, duration, easing) => flippable.TransformFlipH(value, duration), false); applyCommands(drawable, getCommands(g => g.FlipH, triggeredGroups), (d, value) => flippable.FlipH = value, (d, value, duration, easing) => flippable.TransformFlipH(value, duration), false);
applyCommands(drawable, getCommands(g => g.FlipV, triggeredGroups), (d, value) => flippable.FlipV = value, (d, value, duration, easing) => flippable.TransformFlipV(value, duration), false); applyCommands(drawable, getCommands(g => g.FlipV, triggeredGroups), (d, value) => flippable.FlipV = value, (d, value, duration, easing) => flippable.TransformFlipV(value, duration), false);

View File

@ -158,9 +158,11 @@
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseFormatSpecifierInFormatString/@EntryIndexedValue">WARNING</s:String> <s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseFormatSpecifierInFormatString/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseFormatSpecifierInInterpolation/@EntryIndexedValue">WARNING</s:String> <s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseFormatSpecifierInInterpolation/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseNameofExpression/@EntryIndexedValue">WARNING</s:String> <s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseNameofExpression/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseNegatedPatternMatching/@EntryIndexedValue"></s:String>
<s:Boolean x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseNegatedPatternMatching/@EntryIndexRemoved">True</s:Boolean>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseNullPropagation/@EntryIndexedValue">WARNING</s:String> <s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseNullPropagation/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseObjectOrCollectionInitializer/@EntryIndexedValue">WARNING</s:String> <s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseObjectOrCollectionInitializer/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UsePatternMatching/@EntryIndexedValue">HINT</s:String> <s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UsePatternMatching/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseStringInterpolation/@EntryIndexedValue">WARNING</s:String> <s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseStringInterpolation/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=VariableCanBeMadeConst/@EntryIndexedValue">WARNING</s:String> <s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=VariableCanBeMadeConst/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=VirtualMemberCallInConstructor/@EntryIndexedValue">HINT</s:String> <s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=VirtualMemberCallInConstructor/@EntryIndexedValue">HINT</s:String>