1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-25 23:52:54 +08:00

Merge pull request #24357 from peppy/tournament-fix-null-population

Fix startup tournament population not recovering from null beatmaps
This commit is contained in:
Dean Herbert 2023-07-28 14:31:48 +09:00 committed by GitHub
commit 57e51f4d5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 37 deletions

View File

@ -1,8 +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.
#nullable disable
using System;
using System.Collections.Specialized;
using System.Linq;
@ -11,6 +9,7 @@ using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Localisation;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Graphics;
@ -21,19 +20,18 @@ namespace osu.Game.Tournament.Components
{
public partial class TournamentBeatmapPanel : CompositeDrawable
{
public readonly TournamentBeatmap Beatmap;
public readonly TournamentBeatmap? Beatmap;
private readonly string mod;
public const float HEIGHT = 50;
private readonly Bindable<TournamentMatch> currentMatch = new Bindable<TournamentMatch>();
private Box flash;
private readonly Bindable<TournamentMatch?> currentMatch = new Bindable<TournamentMatch?>();
public TournamentBeatmapPanel(TournamentBeatmap beatmap, string mod = null)
private Box flash = null!;
public TournamentBeatmapPanel(TournamentBeatmap? beatmap, string mod = "")
{
ArgumentNullException.ThrowIfNull(beatmap);
Beatmap = beatmap;
this.mod = mod;
@ -73,7 +71,7 @@ namespace osu.Game.Tournament.Components
{
new TournamentSpriteText
{
Text = Beatmap.GetDisplayTitleRomanisable(false, false),
Text = Beatmap?.GetDisplayTitleRomanisable(false, false) ?? (LocalisableString)@"unknown",
Font = OsuFont.Torus.With(weight: FontWeight.Bold),
},
new FillFlowContainer
@ -90,7 +88,7 @@ namespace osu.Game.Tournament.Components
},
new TournamentSpriteText
{
Text = Beatmap.Metadata.Author.Username,
Text = Beatmap?.Metadata.Author.Username ?? "unknown",
Padding = new MarginPadding { Right = 20 },
Font = OsuFont.Torus.With(weight: FontWeight.Bold, size: 14)
},
@ -102,7 +100,7 @@ namespace osu.Game.Tournament.Components
},
new TournamentSpriteText
{
Text = Beatmap.DifficultyName,
Text = Beatmap?.DifficultyName ?? "unknown",
Font = OsuFont.Torus.With(weight: FontWeight.Bold, size: 14)
},
}
@ -131,36 +129,37 @@ namespace osu.Game.Tournament.Components
}
}
private void matchChanged(ValueChangedEvent<TournamentMatch> match)
private void matchChanged(ValueChangedEvent<TournamentMatch?> match)
{
if (match.OldValue != null)
match.OldValue.PicksBans.CollectionChanged -= picksBansOnCollectionChanged;
match.NewValue.PicksBans.CollectionChanged += picksBansOnCollectionChanged;
if (match.NewValue != null)
match.NewValue.PicksBans.CollectionChanged += picksBansOnCollectionChanged;
updateState();
}
private void picksBansOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
private void picksBansOnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
=> updateState();
private BeatmapChoice choice;
private BeatmapChoice? choice;
private void updateState()
{
var found = currentMatch.Value.PicksBans.FirstOrDefault(p => p.BeatmapID == Beatmap.OnlineID);
var newChoice = currentMatch.Value?.PicksBans.FirstOrDefault(p => p.BeatmapID == Beatmap?.OnlineID);
bool doFlash = found != choice;
choice = found;
bool shouldFlash = newChoice != choice;
if (found != null)
if (newChoice != null)
{
if (doFlash)
flash?.FadeOutFromOne(500).Loop(0, 10);
if (shouldFlash)
flash.FadeOutFromOne(500).Loop(0, 10);
BorderThickness = 6;
BorderColour = TournamentGame.GetTeamColour(found.Team);
BorderColour = TournamentGame.GetTeamColour(newChoice.Team);
switch (found.Type)
switch (newChoice.Type)
{
case ChoiceType.Pick:
Colour = Color4.White;
@ -179,6 +178,8 @@ namespace osu.Game.Tournament.Components
BorderThickness = 0;
Alpha = 1;
}
choice = newChoice;
}
private partial class NoUnloadBeatmapSetCover : UpdateableOnlineBeatmapSetCover

View File

@ -1,8 +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.
#nullable disable
using Newtonsoft.Json;
namespace osu.Game.Tournament.Models
@ -10,9 +8,10 @@ namespace osu.Game.Tournament.Models
public class RoundBeatmap
{
public int ID;
public string Mods;
public string Mods = string.Empty;
[JsonProperty("BeatmapInfo")]
public TournamentBeatmap Beatmap;
public TournamentBeatmap? Beatmap;
}
}

View File

@ -139,9 +139,11 @@ namespace osu.Game.Tournament.Screens.Editors
public void CreateNew()
{
var user = new RoundBeatmap();
round.Beatmaps.Add(user);
flow.Add(new RoundBeatmapRow(round, user));
var b = new RoundBeatmap();
round.Beatmaps.Add(b);
flow.Add(new RoundBeatmapRow(round, b));
}
public partial class RoundBeatmapRow : CompositeDrawable

View File

@ -165,11 +165,11 @@ namespace osu.Game.Tournament.Screens.MapPool
if (map != null)
{
if (e.Button == MouseButton.Left && map.Beatmap.OnlineID > 0)
if (e.Button == MouseButton.Left && map.Beatmap?.OnlineID > 0)
addForBeatmap(map.Beatmap.OnlineID);
else
{
var existing = CurrentMatch.Value.PicksBans.FirstOrDefault(p => p.BeatmapID == map.Beatmap.OnlineID);
var existing = CurrentMatch.Value.PicksBans.FirstOrDefault(p => p.BeatmapID == map.Beatmap?.OnlineID);
if (existing != null)
{
@ -195,7 +195,7 @@ namespace osu.Game.Tournament.Screens.MapPool
if (CurrentMatch.Value == null)
return;
if (CurrentMatch.Value.Round.Value.Beatmaps.All(b => b.Beatmap.OnlineID != beatmapId))
if (CurrentMatch.Value.Round.Value.Beatmaps.All(b => b.Beatmap?.OnlineID != beatmapId))
// don't attempt to add if the beatmap isn't in our pool
return;

View File

@ -19,7 +19,6 @@ using osu.Game.Database;
using osu.Game.Graphics;
using osu.Game.Online;
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;
@ -236,7 +235,7 @@ namespace osu.Game.Tournament
{
var beatmapsRequiringPopulation = ladder.Rounds
.SelectMany(r => r.Beatmaps)
.Where(b => b.Beatmap?.OnlineID == 0 && b.ID > 0).ToList();
.Where(b => (b.Beatmap == null || b.Beatmap?.OnlineID == 0) && b.ID > 0).ToList();
if (beatmapsRequiringPopulation.Count == 0)
return false;
@ -245,7 +244,9 @@ namespace osu.Game.Tournament
{
var b = beatmapsRequiringPopulation[i];
b.Beatmap = new TournamentBeatmap(await beatmapCache.GetBeatmapAsync(b.ID).ConfigureAwait(false) ?? new APIBeatmap());
var populated = await beatmapCache.GetBeatmapAsync(b.ID).ConfigureAwait(false);
if (populated != null)
b.Beatmap = new TournamentBeatmap(populated);
updateLoadProgressMessage($"Populating round beatmaps ({i} / {beatmapsRequiringPopulation.Count})");
}
@ -270,7 +271,9 @@ namespace osu.Game.Tournament
{
var b = beatmapsRequiringPopulation[i];
b.Beatmap = new TournamentBeatmap(await beatmapCache.GetBeatmapAsync(b.ID).ConfigureAwait(false) ?? new APIBeatmap());
var populated = await beatmapCache.GetBeatmapAsync(b.ID).ConfigureAwait(false);
if (populated != null)
b.Beatmap = new TournamentBeatmap(populated);
updateLoadProgressMessage($"Populating seeding beatmaps ({i} / {beatmapsRequiringPopulation.Count})");
}