1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 22:07:25 +08:00

Split out more requests + responses

This commit is contained in:
smoogipoo 2018-12-22 15:45:16 +09:00
parent 0e9991b81a
commit b9ec179713
7 changed files with 54 additions and 35 deletions

View File

@ -7,6 +7,7 @@ using System.Linq;
using osu.Framework.Allocation;
using osu.Game.Beatmaps;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Multiplayer;
using osu.Game.Scoring;
using osu.Game.Screens.Multi.Match.Components;
@ -101,7 +102,7 @@ namespace osu.Game.Tests.Visual
{
}
protected override APIRequest FetchScores(Action<IEnumerable<RoomScore>> scoresCallback)
protected override APIRequest FetchScores(Action<IEnumerable<APIRoomScoreInfo>> scoresCallback)
{
var scores = Enumerable.Range(0, 50).Select(createRoomScore).ToArray();
@ -111,7 +112,7 @@ namespace osu.Game.Tests.Visual
return null;
}
private RoomScore createRoomScore(int id) => new RoomScore
private APIRoomScoreInfo createRoomScore(int id) => new APIRoomScoreInfo
{
User = new User { Id = id, Username = $"User {id}" },
Accuracy = 0.98,

View File

@ -7,7 +7,7 @@ using osu.Game.Online.API.Requests.Responses;
namespace osu.Game.Online.API.Requests
{
public class CreateRoomScoreRequest : APIRequest<APIRoomScore>
public class CreateRoomScoreRequest : APIRequest<APIScoreToken>
{
private readonly int roomId;
private readonly int playlistItemId;

View File

@ -0,0 +1,20 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using osu.Game.Online.API.Requests.Responses;
namespace osu.Game.Online.API.Requests
{
public class GetRoomScoresRequest : APIRequest<List<APIRoomScoreInfo>>
{
private readonly int roomId;
public GetRoomScoresRequest(int roomId)
{
this.roomId = roomId;
}
protected override string Target => $@"rooms/{roomId}/leaderboard";
}
}

View File

@ -0,0 +1,17 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using Newtonsoft.Json;
using osu.Game.Scoring;
namespace osu.Game.Online.API.Requests.Responses
{
public class APIRoomScoreInfo : ScoreInfo
{
[JsonProperty("attempts")]
public int TotalAttempts { get; set; }
[JsonProperty("completed")]
public int CompletedAttempts { get; set; }
}
}

View File

@ -5,7 +5,7 @@ using Newtonsoft.Json;
namespace osu.Game.Online.API.Requests.Responses
{
public class APIRoomScore
public class APIScoreToken
{
[JsonProperty("id")]
public int ID { get; set; }

View File

@ -3,19 +3,20 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using osu.Framework.Allocation;
using osu.Game.Graphics;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Leaderboards;
using osu.Game.Online.Multiplayer;
using osu.Game.Scoring;
namespace osu.Game.Screens.Multi.Match.Components
{
public class MatchLeaderboard : Leaderboard<MatchLeaderboardScope, RoomScore>
public class MatchLeaderboard : Leaderboard<MatchLeaderboardScope, APIRoomScoreInfo>
{
public Action<IEnumerable<RoomScore>> ScoresLoaded;
public Action<IEnumerable<APIRoomScoreInfo>> ScoresLoaded;
private readonly Room room;
@ -34,7 +35,7 @@ namespace osu.Game.Screens.Multi.Match.Components
}, true);
}
protected override APIRequest FetchScores(Action<IEnumerable<RoomScore>> scoresCallback)
protected override APIRequest FetchScores(Action<IEnumerable<APIRoomScoreInfo>> scoresCallback)
{
if (room.RoomID == null)
return null;
@ -50,24 +51,12 @@ namespace osu.Game.Screens.Multi.Match.Components
return req;
}
protected override LeaderboardScore CreateDrawableScore(RoomScore model, int index) => new MatchLeaderboardScore(model, index);
private class GetRoomScoresRequest : APIRequest<List<RoomScore>>
{
private readonly int roomId;
public GetRoomScoresRequest(int roomId)
{
this.roomId = roomId;
}
protected override string Target => $@"rooms/{roomId}/leaderboard";
}
protected override LeaderboardScore CreateDrawableScore(APIRoomScoreInfo model, int index) => new MatchLeaderboardScore(model, index);
}
public class MatchLeaderboardScore : LeaderboardScore
{
public MatchLeaderboardScore(RoomScore score, int rank)
public MatchLeaderboardScore(APIRoomScoreInfo score, int rank)
: base(score, rank)
{
}
@ -81,8 +70,8 @@ namespace osu.Game.Screens.Multi.Match.Components
protected override IEnumerable<LeaderboardScoreStatistic> GetStatistics(ScoreInfo model) => new[]
{
new LeaderboardScoreStatistic(FontAwesome.fa_crosshairs, "Accuracy", string.Format(model.Accuracy % 1 == 0 ? @"{0:P0}" : @"{0:P2}", model.Accuracy)),
new LeaderboardScoreStatistic(FontAwesome.fa_refresh, "Total Attempts", ((RoomScore)model).TotalAttempts.ToString()),
new LeaderboardScoreStatistic(FontAwesome.fa_check, "Completed Beatmaps", ((RoomScore)model).CompletedAttempts.ToString()),
new LeaderboardScoreStatistic(FontAwesome.fa_refresh, "Total Attempts", ((APIRoomScoreInfo)model).TotalAttempts.ToString()),
new LeaderboardScoreStatistic(FontAwesome.fa_check, "Completed Beatmaps", ((APIRoomScoreInfo)model).CompletedAttempts.ToString()),
};
}
@ -90,13 +79,4 @@ namespace osu.Game.Screens.Multi.Match.Components
{
Overall
}
public class RoomScore : ScoreInfo
{
[JsonProperty("attempts")]
public int TotalAttempts { get; set; }
[JsonProperty("completed")]
public int CompletedAttempts { get; set; }
}
}

View File

@ -12,6 +12,7 @@ using osu.Framework.Graphics.Sprites;
using osu.Framework.Lists;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Multiplayer;
using osu.Game.Scoring;
using osu.Game.Screens.Multi.Match.Components;
@ -73,13 +74,13 @@ namespace osu.Game.Screens.Multi.Ranking.Pages
leaderboard.ScoresLoaded = scoresLoaded;
}
private void scoresLoaded(IEnumerable<RoomScore> scores)
private void scoresLoaded(IEnumerable<APIRoomScoreInfo> scores)
{
Action<SpriteText> gray = s => s.Colour = colours.Gray8;
rankText.AddText("You are placed ", gray);
int index = scores.IndexOf(new RoomScore { User = Score.User }, new FuncEqualityComparer<RoomScore>((s1, s2) => s1.User.Id.Equals(s2.User.Id)));
int index = scores.IndexOf(new APIRoomScoreInfo { User = Score.User }, new FuncEqualityComparer<APIRoomScoreInfo>((s1, s2) => s1.User.Id.Equals(s2.User.Id)));
rankText.AddText($"#{index + 1} ", s =>
{