Move config setting logic to background loader

This commit is contained in:
Bartłomiej Dach
2020-10-30 20:32:14 +01:00
parent cf0e8e0a62
commit 67a325f47d
2 changed files with 18 additions and 13 deletions

View File

@ -18,12 +18,14 @@ namespace osu.Game.Graphics.Backgrounds
[LongRunningLoad] [LongRunningLoad]
public class SeasonalBackgroundLoader : Component public class SeasonalBackgroundLoader : Component
{ {
private Bindable<SeasonalBackgroundMode> seasonalBackgroundMode;
private Bindable<APISeasonalBackgrounds> seasonalBackgrounds; private Bindable<APISeasonalBackgrounds> seasonalBackgrounds;
private int current; private int current;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(SessionStatics sessionStatics, IAPIProvider api) private void load(OsuConfigManager config, SessionStatics sessionStatics, IAPIProvider api)
{ {
seasonalBackgroundMode = config.GetBindable<SeasonalBackgroundMode>(OsuSetting.SeasonalBackgroundMode);
seasonalBackgrounds = sessionStatics.GetBindable<APISeasonalBackgrounds>(Static.SeasonalBackgrounds); seasonalBackgrounds = sessionStatics.GetBindable<APISeasonalBackgrounds>(Static.SeasonalBackgrounds);
if (seasonalBackgrounds.Value != null) return; if (seasonalBackgrounds.Value != null) return;
@ -38,10 +40,17 @@ namespace osu.Game.Graphics.Backgrounds
api.PerformAsync(request); api.PerformAsync(request);
} }
public SeasonalBackground LoadBackground() public SeasonalBackground LoadNextBackground()
{ {
if (seasonalBackgroundMode.Value == SeasonalBackgroundMode.Never
|| (seasonalBackgroundMode.Value == SeasonalBackgroundMode.Sometimes && !isInSeason))
{
return null;
}
var backgrounds = seasonalBackgrounds.Value.Backgrounds; var backgrounds = seasonalBackgrounds.Value.Backgrounds;
if (backgrounds == null || !backgrounds.Any()) return null; if (backgrounds == null || !backgrounds.Any())
return null;
current = (current + 1) % backgrounds.Count; current = (current + 1) % backgrounds.Count;
string url = backgrounds[current].Url; string url = backgrounds[current].Url;
@ -49,7 +58,7 @@ namespace osu.Game.Graphics.Backgrounds
return new SeasonalBackground(url); return new SeasonalBackground(url);
} }
public bool IsInSeason => seasonalBackgrounds.Value != null && DateTimeOffset.Now < seasonalBackgrounds.Value.EndDate; private bool isInSeason => seasonalBackgrounds.Value != null && DateTimeOffset.Now < seasonalBackgrounds.Value.EndDate;
} }
[LongRunningLoad] [LongRunningLoad]

View File

@ -79,16 +79,12 @@ namespace osu.Game.Screens.Backgrounds
Background newBackground; Background newBackground;
string backgroundName; string backgroundName;
if (seasonalBackgroundMode.Value == SeasonalBackgroundMode.Always var seasonalBackground = seasonalBackgroundLoader.LoadNextBackground();
|| (seasonalBackgroundMode.Value == SeasonalBackgroundMode.Sometimes && seasonalBackgroundLoader.IsInSeason))
{
var seasonalBackground = seasonalBackgroundLoader.LoadBackground();
if (seasonalBackground != null) if (seasonalBackground != null)
{ {
seasonalBackground.Depth = currentDisplay; seasonalBackground.Depth = currentDisplay;
return seasonalBackground; return seasonalBackground;
}
} }
switch (introSequence.Value) switch (introSequence.Value)