Make "Sometimes" setting depend on season end date, rather than chance

This commit is contained in:
Max Hübner 2020-10-30 10:27:43 +01:00
parent fb1e09b3e7
commit f27ce7521d
4 changed files with 17 additions and 2 deletions

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 System;
using System.Collections.Generic;
using osu.Game.Online.API.Requests.Responses;
@ -15,6 +16,7 @@ protected override void InitialiseDefaults()
{
Set(Static.LoginOverlayDisplayed, false);
Set(Static.MutedAudioNotificationShownOnce, false);
Set(Static.SeasonEndDate, DateTimeOffset.MinValue);
Set(Static.SeasonalBackgrounds, new List<APISeasonalBackground>());
}
}
@ -23,6 +25,7 @@ public enum Static
{
LoginOverlayDisplayed,
MutedAudioNotificationShownOnce,
SeasonalBackgrounds
SeasonEndDate,
SeasonalBackgrounds,
}
}

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 System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
@ -18,19 +19,24 @@ namespace osu.Game.Graphics.Backgrounds
[LongRunningLoad]
public class SeasonalBackgroundLoader : Component
{
private Bindable<DateTimeOffset> endDate;
private Bindable<List<APISeasonalBackground>> backgrounds;
private int current;
[BackgroundDependencyLoader]
private void load(SessionStatics sessionStatics, IAPIProvider api)
{
endDate = sessionStatics.GetBindable<DateTimeOffset>(Static.SeasonEndDate);
backgrounds = sessionStatics.GetBindable<List<APISeasonalBackground>>(Static.SeasonalBackgrounds);
if (backgrounds.Value.Any()) return;
var request = new GetSeasonalBackgroundsRequest();
request.Success += response =>
{
endDate.Value = response.EndDate;
backgrounds.Value = response.Backgrounds ?? backgrounds.Value;
current = RNG.Next(0, backgrounds.Value.Count);
};
@ -46,6 +52,8 @@ public SeasonalBackground LoadBackground()
return new SeasonalBackground(url);
}
public bool IsInSeason() => DateTimeOffset.Now < endDate.Value;
}
[LongRunningLoad]

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 System;
using System.Collections.Generic;
using Newtonsoft.Json;
@ -8,6 +9,9 @@ namespace osu.Game.Online.API.Requests.Responses
{
public class APISeasonalBackgrounds
{
[JsonProperty("ends_at")]
public DateTimeOffset EndDate;
[JsonProperty("backgrounds")]
public List<APISeasonalBackground> Backgrounds { get; set; }
}

View File

@ -109,7 +109,7 @@ private Background createBackground()
switch (showSeasonalBackgrounds.Value)
{
case SeasonalBackgrounds.Sometimes:
if (RNG.NextBool())
if (seasonalBackgroundLoader.IsInSeason())
goto case SeasonalBackgrounds.Always;
break;