mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 17:52:56 +08:00
reafactor: simplify type checking
This commit is contained in:
parent
b0a2e69f95
commit
e9dcc257b4
@ -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 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);
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user