Fix duplicate code in setting default logic

This commit is contained in:
Dean Herbert
2021-04-19 11:25:43 +09:00
parent 1e56f14f5b
commit 2b6caf9b65

View File

@ -1,6 +1,7 @@
// 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 osu.Framework.Bindables;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays;
@ -12,23 +13,18 @@ namespace osu.Game.Configuration
/// </summary>
public class SessionStatics : InMemoryConfigManager<Static>
{
protected override void InitialiseDefaults()
{
SetDefault(Static.LoginOverlayDisplayed, false);
SetDefault(Static.MutedAudioNotificationShownOnce, false);
SetDefault(Static.LowBatteryNotificationShownOnce, false);
SetDefault(Static.LastHoverSoundPlaybackTime, (double?)null);
SetDefault<APISeasonalBackgrounds>(Static.SeasonalBackgrounds, null);
}
protected override void InitialiseDefaults() => ResetValues();
public void ResetValues()
{
GetOriginalBindable<bool>(Static.LoginOverlayDisplayed).SetDefault();
GetOriginalBindable<bool>(Static.MutedAudioNotificationShownOnce).SetDefault();
GetOriginalBindable<bool>(Static.LowBatteryNotificationShownOnce).SetDefault();
GetOriginalBindable<double?>(Static.LastHoverSoundPlaybackTime).SetDefault();
GetOriginalBindable<APISeasonalBackgrounds>(Static.SeasonalBackgrounds).SetDefault();
ensureDefault(SetDefault(Static.LoginOverlayDisplayed, false));
ensureDefault(SetDefault(Static.MutedAudioNotificationShownOnce, false));
ensureDefault(SetDefault(Static.LowBatteryNotificationShownOnce, false));
ensureDefault(SetDefault(Static.LastHoverSoundPlaybackTime, (double?)null));
ensureDefault(SetDefault<APISeasonalBackgrounds>(Static.SeasonalBackgrounds, null));
}
private void ensureDefault<T>(Bindable<T> bindable) => bindable.SetDefault();
}
public enum Static