Fix beatmap getting nulled due to failing web request

This commit is contained in:
smoogipoo
2021-03-01 17:24:54 +09:00
parent f7e4cfa4d0
commit 7adb33f40e
3 changed files with 65 additions and 18 deletions

View File

@ -3,12 +3,15 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Game.Beatmaps;
using osu.Game.Online.API;
using osu.Game.Online.Multiplayer;
using osu.Game.Online.Rooms;
@ -28,6 +31,9 @@ namespace osu.Game.Tests.Visual.Multiplayer
[Resolved]
private Room apiRoom { get; set; } = null!;
[Resolved]
private BeatmapManager beatmaps { get; set; } = null!;
public void Connect() => isConnected.Value = true;
public void Disconnect() => isConnected.Value = false;
@ -168,5 +174,19 @@ namespace osu.Game.Tests.Visual.Multiplayer
return ((IMultiplayerClient)this).LoadRequested();
}
protected override Task<BeatmapSetInfo> GetOnlineBeatmapSet(int beatmapId, CancellationToken cancellationToken = default)
{
Debug.Assert(Room != null);
Debug.Assert(apiRoom != null);
var set = apiRoom.Playlist.FirstOrDefault(p => p.BeatmapID == beatmapId)?.Beatmap.Value.BeatmapSet
?? beatmaps.QueryBeatmap(b => b.OnlineBeatmapID == beatmapId)?.BeatmapSet;
if (set == null)
throw new InvalidOperationException("Beatmap not found.");
return Task.FromResult(set);
}
}
}