mirror of
https://github.com/ppy/osu.git
synced 2025-03-24 09:37:19 +08:00
Merge pull request #16181 from dekrain/statics-reset-no-sb
Split session statics reset method to prevent unloading seasonal backgrounds
This commit is contained in:
commit
df975fb29e
@ -1,9 +1,10 @@
|
||||
// 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 NUnit.Framework;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Input;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
|
||||
namespace osu.Game.Tests.NonVisual
|
||||
{
|
||||
@ -11,37 +12,32 @@ namespace osu.Game.Tests.NonVisual
|
||||
public class SessionStaticsTest
|
||||
{
|
||||
private SessionStatics sessionStatics;
|
||||
private IdleTracker sessionIdleTracker;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
[Test]
|
||||
public void TestSessionStaticsReset()
|
||||
{
|
||||
sessionStatics = new SessionStatics();
|
||||
sessionIdleTracker = new GameIdleTracker(1000);
|
||||
|
||||
sessionStatics.SetValue(Static.LoginOverlayDisplayed, true);
|
||||
sessionStatics.SetValue(Static.MutedAudioNotificationShownOnce, true);
|
||||
sessionStatics.SetValue(Static.LowBatteryNotificationShownOnce, true);
|
||||
sessionStatics.SetValue(Static.LastHoverSoundPlaybackTime, (double?)1d);
|
||||
sessionStatics.SetValue(Static.SeasonalBackgrounds, new APISeasonalBackgrounds { EndDate = new DateTimeOffset(2022, 1, 1, 0, 0, 0, TimeSpan.Zero) });
|
||||
|
||||
sessionIdleTracker.IsIdle.BindValueChanged(e =>
|
||||
{
|
||||
if (e.NewValue)
|
||||
sessionStatics.ResetValues();
|
||||
});
|
||||
}
|
||||
Assert.IsFalse(sessionStatics.GetBindable<bool>(Static.LoginOverlayDisplayed).IsDefault);
|
||||
Assert.IsFalse(sessionStatics.GetBindable<bool>(Static.MutedAudioNotificationShownOnce).IsDefault);
|
||||
Assert.IsFalse(sessionStatics.GetBindable<bool>(Static.LowBatteryNotificationShownOnce).IsDefault);
|
||||
Assert.IsFalse(sessionStatics.GetBindable<double?>(Static.LastHoverSoundPlaybackTime).IsDefault);
|
||||
Assert.IsFalse(sessionStatics.GetBindable<APISeasonalBackgrounds>(Static.SeasonalBackgrounds).IsDefault);
|
||||
|
||||
[Test]
|
||||
[Timeout(2000)]
|
||||
public void TestSessionStaticsReset()
|
||||
{
|
||||
sessionIdleTracker.IsIdle.BindValueChanged(e =>
|
||||
{
|
||||
Assert.IsTrue(sessionStatics.GetBindable<bool>(Static.LoginOverlayDisplayed).IsDefault);
|
||||
Assert.IsTrue(sessionStatics.GetBindable<bool>(Static.MutedAudioNotificationShownOnce).IsDefault);
|
||||
Assert.IsTrue(sessionStatics.GetBindable<bool>(Static.LowBatteryNotificationShownOnce).IsDefault);
|
||||
Assert.IsTrue(sessionStatics.GetBindable<double?>(Static.LastHoverSoundPlaybackTime).IsDefault);
|
||||
});
|
||||
sessionStatics.ResetAfterInactivity();
|
||||
|
||||
Assert.IsTrue(sessionStatics.GetBindable<bool>(Static.LoginOverlayDisplayed).IsDefault);
|
||||
Assert.IsTrue(sessionStatics.GetBindable<bool>(Static.MutedAudioNotificationShownOnce).IsDefault);
|
||||
Assert.IsTrue(sessionStatics.GetBindable<bool>(Static.LowBatteryNotificationShownOnce).IsDefault);
|
||||
// some statics should not reset despite inactivity.
|
||||
Assert.IsFalse(sessionStatics.GetBindable<double?>(Static.LastHoverSoundPlaybackTime).IsDefault);
|
||||
Assert.IsFalse(sessionStatics.GetBindable<APISeasonalBackgrounds>(Static.SeasonalBackgrounds).IsDefault);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 osu.Framework.Bindables;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Overlays;
|
||||
@ -13,18 +12,27 @@ namespace osu.Game.Configuration
|
||||
/// </summary>
|
||||
public class SessionStatics : InMemoryConfigManager<Static>
|
||||
{
|
||||
protected override void InitialiseDefaults() => ResetValues();
|
||||
|
||||
public void ResetValues()
|
||||
protected override void InitialiseDefaults()
|
||||
{
|
||||
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));
|
||||
SetDefault(Static.LoginOverlayDisplayed, false);
|
||||
SetDefault(Static.MutedAudioNotificationShownOnce, false);
|
||||
SetDefault(Static.LowBatteryNotificationShownOnce, false);
|
||||
SetDefault(Static.LastHoverSoundPlaybackTime, (double?)null);
|
||||
SetDefault<APISeasonalBackgrounds>(Static.SeasonalBackgrounds, null);
|
||||
}
|
||||
|
||||
private void ensureDefault<T>(Bindable<T> bindable) => bindable.SetDefault();
|
||||
/// <summary>
|
||||
/// Revert statics to their defaults after being idle for appropriate amount of time.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This only affects a subset of statics which the user would expect to have reset after a break.
|
||||
/// </remarks>
|
||||
public void ResetAfterInactivity()
|
||||
{
|
||||
GetBindable<bool>(Static.LoginOverlayDisplayed).SetDefault();
|
||||
GetBindable<bool>(Static.MutedAudioNotificationShownOnce).SetDefault();
|
||||
GetBindable<bool>(Static.LowBatteryNotificationShownOnce).SetDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public enum Static
|
||||
|
@ -680,7 +680,7 @@ namespace osu.Game
|
||||
sessionIdleTracker.IsIdle.BindValueChanged(idle =>
|
||||
{
|
||||
if (idle.NewValue)
|
||||
SessionStatics.ResetValues();
|
||||
SessionStatics.ResetAfterInactivity();
|
||||
});
|
||||
|
||||
Add(sessionIdleTracker);
|
||||
|
Loading…
x
Reference in New Issue
Block a user