1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-26 18:52:55 +08:00

Change repopulation rules to cover the fact that the serisalisation model has changed

This also adds a progress display to show how repopulation is going. It
can take a while on a large bracket.
This commit is contained in:
Dean Herbert 2021-10-27 18:20:10 +09:00
parent 35168948fe
commit 5448b94039

View File

@ -7,12 +7,14 @@ using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Textures;
using osu.Framework.Input;
using osu.Framework.IO.Stores;
using osu.Framework.Platform;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Tournament.IO;
using osu.Game.Tournament.IPC;
using osu.Game.Tournament.Models;
@ -39,9 +41,18 @@ namespace osu.Game.Tournament
return dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
}
private TournamentSpriteText initialisationText;
[BackgroundDependencyLoader]
private void load(Storage baseStorage)
{
AddInternal(initialisationText = new TournamentSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.Torus.With(size: 32),
});
Resources.AddStore(new DllResourceStore(typeof(TournamentGameBase).Assembly));
dependencies.CacheAs<Storage>(storage = new TournamentStorage(baseStorage));
@ -123,7 +134,8 @@ namespace osu.Game.Tournament
}
addedInfo |= addPlayers();
addedInfo |= addBeatmaps();
addedInfo |= addRoundBeatmaps();
addedInfo |= addSeedingBeatmaps();
if (addedInfo)
SaveChanges();
@ -145,6 +157,8 @@ namespace osu.Game.Tournament
Add(ipc);
taskCompletionSource.SetResult(true);
initialisationText.Expire();
});
}
@ -153,75 +167,80 @@ namespace osu.Game.Tournament
/// </summary>
private bool addPlayers()
{
bool addedInfo = false;
var playersRequiringPopulation = ladder.Teams
.SelectMany(t => t.Players)
.Where(p => string.IsNullOrEmpty(p.Username)
|| p.Statistics?.GlobalRank == null
|| p.Statistics?.CountryRank == null).ToList();
foreach (var t in ladder.Teams)
if (playersRequiringPopulation.Count == 0)
return false;
for (int i = 0; i < playersRequiringPopulation.Count; i++)
{
foreach (var p in t.Players)
{
if (string.IsNullOrEmpty(p.Username)
|| p.Statistics?.GlobalRank == null
|| p.Statistics?.CountryRank == null)
{
PopulateUser(p, immediate: true);
addedInfo = true;
}
}
var p = playersRequiringPopulation[i];
PopulateUser(p, immediate: true);
updateLoadProgressMessage($"Populating user stats ({i} / {playersRequiringPopulation.Count})");
}
return addedInfo;
return true;
}
/// <summary>
/// Add missing beatmap info based on beatmap IDs
/// </summary>
private bool addBeatmaps()
private bool addRoundBeatmaps()
{
bool addedInfo = false;
var beatmapsRequiringPopulation = ladder.Rounds
.SelectMany(r => r.Beatmaps)
.Where(b => string.IsNullOrEmpty(b.BeatmapInfo?.BeatmapSet?.Title) && b.ID > 0).ToList();
foreach (var r in ladder.Rounds)
if (beatmapsRequiringPopulation.Count == 0)
return false;
for (int i = 0; i < beatmapsRequiringPopulation.Count; i++)
{
foreach (var b in r.Beatmaps.ToList())
{
if (b.BeatmapInfo != null)
continue;
var b = beatmapsRequiringPopulation[i];
if (b.ID > 0)
{
var req = new GetBeatmapRequest(new BeatmapInfo { OnlineBeatmapID = b.ID });
API.Perform(req);
b.BeatmapInfo = req.Response;
var req = new GetBeatmapRequest(new APIBeatmap { OnlineID = b.ID });
API.Perform(req);
b.BeatmapInfo = req.Response ?? new APIBeatmap();
addedInfo = true;
}
if (b.BeatmapInfo == null)
// if online population couldn't be performed, ensure we don't leave a null value behind
r.Beatmaps.Remove(b);
}
updateLoadProgressMessage($"Populating round beatmaps ({i} / {beatmapsRequiringPopulation.Count})");
}
foreach (var t in ladder.Teams)
{
foreach (var s in t.SeedingResults)
{
foreach (var b in s.Beatmaps)
{
if (b.BeatmapInfo == null && b.ID > 0)
{
var req = new GetBeatmapRequest(new BeatmapInfo { OnlineBeatmapID = b.ID });
req.Perform(API);
b.BeatmapInfo = req.Response;
addedInfo = true;
}
}
}
}
return addedInfo;
return true;
}
/// <summary>
/// Add missing beatmap info based on beatmap IDs
/// </summary>
private bool addSeedingBeatmaps()
{
var beatmapsRequiringPopulation = ladder.Teams
.SelectMany(r => r.SeedingResults)
.SelectMany(r => r.Beatmaps)
.Where(b => string.IsNullOrEmpty(b.BeatmapInfo?.BeatmapSet?.Title) && b.ID > 0).ToList();
if (beatmapsRequiringPopulation.Count == 0)
return false;
for (int i = 0; i < beatmapsRequiringPopulation.Count; i++)
{
var b = beatmapsRequiringPopulation[i];
var req = new GetBeatmapRequest(new APIBeatmap { OnlineID = b.ID });
API.Perform(req);
b.BeatmapInfo = req.Response ?? new APIBeatmap();
updateLoadProgressMessage($"Populating seeding beatmaps ({i} / {beatmapsRequiringPopulation.Count})");
}
return true;
}
private void updateLoadProgressMessage(string s) => Schedule(() => initialisationText.Text = s);
public void PopulateUser(User user, Action success = null, Action failure = null, bool immediate = false)
{
var req = new GetUserRequest(user.Id, Ruleset.Value);