1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 15:53:51 +08:00

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. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
@ -15,6 +16,7 @@ namespace osu.Game.Configuration
{ {
Set(Static.LoginOverlayDisplayed, false); Set(Static.LoginOverlayDisplayed, false);
Set(Static.MutedAudioNotificationShownOnce, false); Set(Static.MutedAudioNotificationShownOnce, false);
Set(Static.SeasonEndDate, DateTimeOffset.MinValue);
Set(Static.SeasonalBackgrounds, new List<APISeasonalBackground>()); Set(Static.SeasonalBackgrounds, new List<APISeasonalBackground>());
} }
} }
@ -23,6 +25,7 @@ namespace osu.Game.Configuration
{ {
LoginOverlayDisplayed, LoginOverlayDisplayed,
MutedAudioNotificationShownOnce, MutedAudioNotificationShownOnce,
SeasonalBackgrounds SeasonEndDate,
SeasonalBackgrounds,
} }
} }

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
@ -18,19 +19,24 @@ namespace osu.Game.Graphics.Backgrounds
[LongRunningLoad] [LongRunningLoad]
public class SeasonalBackgroundLoader : Component public class SeasonalBackgroundLoader : Component
{ {
private Bindable<DateTimeOffset> endDate;
private Bindable<List<APISeasonalBackground>> backgrounds; private Bindable<List<APISeasonalBackground>> backgrounds;
private int current; private int current;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(SessionStatics sessionStatics, IAPIProvider api) private void load(SessionStatics sessionStatics, IAPIProvider api)
{ {
endDate = sessionStatics.GetBindable<DateTimeOffset>(Static.SeasonEndDate);
backgrounds = sessionStatics.GetBindable<List<APISeasonalBackground>>(Static.SeasonalBackgrounds); backgrounds = sessionStatics.GetBindable<List<APISeasonalBackground>>(Static.SeasonalBackgrounds);
if (backgrounds.Value.Any()) return; if (backgrounds.Value.Any()) return;
var request = new GetSeasonalBackgroundsRequest(); var request = new GetSeasonalBackgroundsRequest();
request.Success += response => request.Success += response =>
{ {
endDate.Value = response.EndDate;
backgrounds.Value = response.Backgrounds ?? backgrounds.Value; backgrounds.Value = response.Backgrounds ?? backgrounds.Value;
current = RNG.Next(0, backgrounds.Value.Count); current = RNG.Next(0, backgrounds.Value.Count);
}; };
@ -46,6 +52,8 @@ namespace osu.Game.Graphics.Backgrounds
return new SeasonalBackground(url); return new SeasonalBackground(url);
} }
public bool IsInSeason() => DateTimeOffset.Now < endDate.Value;
} }
[LongRunningLoad] [LongRunningLoad]

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Newtonsoft.Json; using Newtonsoft.Json;
@ -8,6 +9,9 @@ namespace osu.Game.Online.API.Requests.Responses
{ {
public class APISeasonalBackgrounds public class APISeasonalBackgrounds
{ {
[JsonProperty("ends_at")]
public DateTimeOffset EndDate;
[JsonProperty("backgrounds")] [JsonProperty("backgrounds")]
public List<APISeasonalBackground> Backgrounds { get; set; } public List<APISeasonalBackground> Backgrounds { get; set; }
} }

View File

@ -109,7 +109,7 @@ namespace osu.Game.Screens.Backgrounds
switch (showSeasonalBackgrounds.Value) switch (showSeasonalBackgrounds.Value)
{ {
case SeasonalBackgrounds.Sometimes: case SeasonalBackgrounds.Sometimes:
if (RNG.NextBool()) if (seasonalBackgroundLoader.IsInSeason())
goto case SeasonalBackgrounds.Always; goto case SeasonalBackgrounds.Always;
break; break;