mirror of
https://github.com/ppy/osu.git
synced 2025-03-15 17:47:18 +08:00
Make room requests handler handle GetBeatmapRequest
This commit is contained in:
parent
da8d94c4b4
commit
1811647e34
@ -9,27 +9,25 @@ namespace osu.Game.Online.API.Requests
|
||||
{
|
||||
public class GetBeatmapRequest : APIRequest<APIBeatmap>
|
||||
{
|
||||
private readonly IBeatmapInfo beatmapInfo;
|
||||
|
||||
private readonly string filename;
|
||||
public readonly IBeatmapInfo BeatmapInfo;
|
||||
public readonly string Filename;
|
||||
|
||||
public GetBeatmapRequest(IBeatmapInfo beatmapInfo)
|
||||
{
|
||||
this.beatmapInfo = beatmapInfo;
|
||||
|
||||
filename = (beatmapInfo as BeatmapInfo)?.Path ?? string.Empty;
|
||||
BeatmapInfo = beatmapInfo;
|
||||
Filename = (beatmapInfo as BeatmapInfo)?.Path ?? string.Empty;
|
||||
}
|
||||
|
||||
protected override WebRequest CreateWebRequest()
|
||||
{
|
||||
var request = base.CreateWebRequest();
|
||||
|
||||
if (beatmapInfo.OnlineID > 0)
|
||||
request.AddParameter(@"id", beatmapInfo.OnlineID.ToString());
|
||||
if (!string.IsNullOrEmpty(beatmapInfo.MD5Hash))
|
||||
request.AddParameter(@"checksum", beatmapInfo.MD5Hash);
|
||||
if (!string.IsNullOrEmpty(filename))
|
||||
request.AddParameter(@"filename", filename);
|
||||
if (BeatmapInfo.OnlineID > 0)
|
||||
request.AddParameter(@"id", BeatmapInfo.OnlineID.ToString());
|
||||
if (!string.IsNullOrEmpty(BeatmapInfo.MD5Hash))
|
||||
request.AddParameter(@"checksum", BeatmapInfo.MD5Hash);
|
||||
if (!string.IsNullOrEmpty(Filename))
|
||||
request.AddParameter(@"filename", Filename);
|
||||
|
||||
return request;
|
||||
}
|
||||
|
@ -135,25 +135,15 @@ namespace osu.Game.Tests.Visual.OnlinePlay
|
||||
});
|
||||
return true;
|
||||
|
||||
case GetBeatmapRequest getBeatmapRequest:
|
||||
{
|
||||
getBeatmapRequest.TriggerSuccess(createResponseBeatmaps(getBeatmapRequest.BeatmapInfo.OnlineID).Single());
|
||||
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 });
|
||||
getBeatmapsRequest.TriggerSuccess(new GetBeatmapsResponse { Beatmaps = createResponseBeatmaps(getBeatmapsRequest.BeatmapIds.ToArray()) });
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -175,6 +165,27 @@ namespace osu.Game.Tests.Visual.OnlinePlay
|
||||
}
|
||||
}
|
||||
|
||||
List<APIBeatmap> createResponseBeatmaps(params int[] beatmapIds)
|
||||
{
|
||||
var result = new List<APIBeatmap>();
|
||||
|
||||
foreach (int id in 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));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user