mirror of
https://github.com/osukey/osukey.git
synced 2025-07-03 01:09:57 +09:00
Handle beatmap lookup requests in TestRoomRequestsHandler
This commit is contained in:
@ -4,12 +4,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
using osu.Game.Scoring;
|
||||
using osu.Game.Screens.OnlinePlay.Components;
|
||||
using osu.Game.Tests.Beatmaps;
|
||||
|
||||
namespace osu.Game.Tests.Visual.OnlinePlay
|
||||
{
|
||||
@ -33,9 +37,9 @@ namespace osu.Game.Tests.Visual.OnlinePlay
|
||||
/// </summary>
|
||||
/// <param name="request">The API request to handle.</param>
|
||||
/// <param name="localUser">The local user to store in responses where required.</param>
|
||||
/// <param name="game">The game base for cases where actual online requests need to be sent.</param>
|
||||
/// <param name="beatmapManager">The beatmap manager to attempt to retrieve beatmaps from, prior to returning dummy beatmaps.</param>
|
||||
/// <returns>Whether the request was successfully handled.</returns>
|
||||
public bool HandleRequest(APIRequest request, APIUser localUser, OsuGameBase game)
|
||||
public bool HandleRequest(APIRequest request, APIUser localUser, BeatmapManager beatmapManager)
|
||||
{
|
||||
switch (request)
|
||||
{
|
||||
@ -128,6 +132,26 @@ namespace osu.Game.Tests.Visual.OnlinePlay
|
||||
Statistics = new Dictionary<HitResult, int>()
|
||||
});
|
||||
return true;
|
||||
|
||||
case GetBeatmapsRequest getBeatmapsRequest:
|
||||
var result = new List<APIBeatmap>();
|
||||
|
||||
foreach (int id in getBeatmapsRequest.BeatmapIds)
|
||||
{
|
||||
var baseBeatmap = beatmapManager.QueryBeatmap(b => b.OnlineID == id);
|
||||
|
||||
if (baseBeatmap == null)
|
||||
{
|
||||
baseBeatmap = new TestBeatmap(new RulesetInfo { OnlineID = 0 }).BeatmapInfo;
|
||||
baseBeatmap.OnlineID = id;
|
||||
baseBeatmap.BeatmapSet!.OnlineID = id;
|
||||
}
|
||||
|
||||
result.Add(OsuTestScene.CreateAPIBeatmap(baseBeatmap));
|
||||
}
|
||||
|
||||
getBeatmapsRequest.TriggerSuccess(new GetBeatmapsResponse { Beatmaps = result });
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
Reference in New Issue
Block a user