From e9dcc257b48ae26302c598df7d433e09007a40ba Mon Sep 17 00:00:00 2001 From: tsrk Date: Wed, 15 Feb 2023 22:06:35 +0000 Subject: [PATCH] reafactor: simplify type checking --- osu.Game/Screens/Play/DefaultKeyCounterDisplay.cs | 6 +++--- osu.Game/Screens/Play/KeyCounterDisplay.cs | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/osu.Game/Screens/Play/DefaultKeyCounterDisplay.cs b/osu.Game/Screens/Play/DefaultKeyCounterDisplay.cs index 332474a517..b69ecfd7ae 100644 --- a/osu.Game/Screens/Play/DefaultKeyCounterDisplay.cs +++ b/osu.Game/Screens/Play/DefaultKeyCounterDisplay.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System; using System.Collections.Generic; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -43,14 +42,15 @@ namespace osu.Game.Screens.Play public override void Add(KeyCounter key) { base.Add(key); - if (key is not DefaultKeyCounter defaultKey) - throw new ArgumentException($"{key.GetType()} is not a supported {nameof(KeyCounter)}.", nameof(key)); + DefaultKeyCounter defaultKey = (DefaultKeyCounter)key; defaultKey.FadeTime = key_fade_time; defaultKey.KeyDownTextColor = KeyDownTextColor; defaultKey.KeyUpTextColor = KeyUpTextColor; } + protected override bool CheckType(KeyCounter key) => key is DefaultKeyCounter; + protected override void UpdateVisibility() => // Isolate changing visibility of the key counters from fading this component. KeyFlow.FadeTo(AlwaysVisible.Value || ConfigVisibility.Value ? 1 : 0, duration); diff --git a/osu.Game/Screens/Play/KeyCounterDisplay.cs b/osu.Game/Screens/Play/KeyCounterDisplay.cs index f5af67caea..ed47af11a3 100644 --- a/osu.Game/Screens/Play/KeyCounterDisplay.cs +++ b/osu.Game/Screens/Play/KeyCounterDisplay.cs @@ -29,12 +29,15 @@ namespace osu.Game.Screens.Play public override void Add(KeyCounter key) { - ArgumentNullException.ThrowIfNull(key); + if (!CheckType(key)) + throw new ArgumentException($"{key.GetType()} is not a supported {nameof(KeyCounter)}.", nameof(key)); base.Add(key); key.IsCounting = IsCounting; } + protected virtual bool CheckType(KeyCounter key) => true; + [BackgroundDependencyLoader] private void load(OsuConfigManager config) {