mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 15:07:44 +08:00
Split out more requests + responses
This commit is contained in:
parent
0e9991b81a
commit
b9ec179713
@ -7,6 +7,7 @@ using System.Linq;
|
|||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
using osu.Game.Online.Multiplayer;
|
using osu.Game.Online.Multiplayer;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
using osu.Game.Screens.Multi.Match.Components;
|
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();
|
var scores = Enumerable.Range(0, 50).Select(createRoomScore).ToArray();
|
||||||
|
|
||||||
@ -111,7 +112,7 @@ namespace osu.Game.Tests.Visual
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private RoomScore createRoomScore(int id) => new RoomScore
|
private APIRoomScoreInfo createRoomScore(int id) => new APIRoomScoreInfo
|
||||||
{
|
{
|
||||||
User = new User { Id = id, Username = $"User {id}" },
|
User = new User { Id = id, Username = $"User {id}" },
|
||||||
Accuracy = 0.98,
|
Accuracy = 0.98,
|
||||||
|
@ -7,7 +7,7 @@ using osu.Game.Online.API.Requests.Responses;
|
|||||||
|
|
||||||
namespace osu.Game.Online.API.Requests
|
namespace osu.Game.Online.API.Requests
|
||||||
{
|
{
|
||||||
public class CreateRoomScoreRequest : APIRequest<APIRoomScore>
|
public class CreateRoomScoreRequest : APIRequest<APIScoreToken>
|
||||||
{
|
{
|
||||||
private readonly int roomId;
|
private readonly int roomId;
|
||||||
private readonly int playlistItemId;
|
private readonly int playlistItemId;
|
||||||
|
20
osu.Game/Online/API/Requests/GetRoomScoresRequest.cs
Normal file
20
osu.Game/Online/API/Requests/GetRoomScoresRequest.cs
Normal 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";
|
||||||
|
}
|
||||||
|
}
|
17
osu.Game/Online/API/Requests/Responses/APIRoomScoreInfo.cs
Normal file
17
osu.Game/Online/API/Requests/Responses/APIRoomScoreInfo.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
}
|
@ -5,7 +5,7 @@ using Newtonsoft.Json;
|
|||||||
|
|
||||||
namespace osu.Game.Online.API.Requests.Responses
|
namespace osu.Game.Online.API.Requests.Responses
|
||||||
{
|
{
|
||||||
public class APIRoomScore
|
public class APIScoreToken
|
||||||
{
|
{
|
||||||
[JsonProperty("id")]
|
[JsonProperty("id")]
|
||||||
public int ID { get; set; }
|
public int ID { get; set; }
|
@ -3,19 +3,20 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Online.API;
|
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.Leaderboards;
|
||||||
using osu.Game.Online.Multiplayer;
|
using osu.Game.Online.Multiplayer;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Multi.Match.Components
|
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;
|
private readonly Room room;
|
||||||
|
|
||||||
@ -34,7 +35,7 @@ namespace osu.Game.Screens.Multi.Match.Components
|
|||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override APIRequest FetchScores(Action<IEnumerable<RoomScore>> scoresCallback)
|
protected override APIRequest FetchScores(Action<IEnumerable<APIRoomScoreInfo>> scoresCallback)
|
||||||
{
|
{
|
||||||
if (room.RoomID == null)
|
if (room.RoomID == null)
|
||||||
return null;
|
return null;
|
||||||
@ -50,24 +51,12 @@ namespace osu.Game.Screens.Multi.Match.Components
|
|||||||
return req;
|
return req;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override LeaderboardScore CreateDrawableScore(RoomScore model, int index) => new MatchLeaderboardScore(model, index);
|
protected override LeaderboardScore CreateDrawableScore(APIRoomScoreInfo 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";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MatchLeaderboardScore : LeaderboardScore
|
public class MatchLeaderboardScore : LeaderboardScore
|
||||||
{
|
{
|
||||||
public MatchLeaderboardScore(RoomScore score, int rank)
|
public MatchLeaderboardScore(APIRoomScoreInfo score, int rank)
|
||||||
: base(score, rank)
|
: base(score, rank)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -81,8 +70,8 @@ namespace osu.Game.Screens.Multi.Match.Components
|
|||||||
protected override IEnumerable<LeaderboardScoreStatistic> GetStatistics(ScoreInfo model) => new[]
|
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_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_refresh, "Total Attempts", ((APIRoomScoreInfo)model).TotalAttempts.ToString()),
|
||||||
new LeaderboardScoreStatistic(FontAwesome.fa_check, "Completed Beatmaps", ((RoomScore)model).CompletedAttempts.ToString()),
|
new LeaderboardScoreStatistic(FontAwesome.fa_check, "Completed Beatmaps", ((APIRoomScoreInfo)model).CompletedAttempts.ToString()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,13 +79,4 @@ namespace osu.Game.Screens.Multi.Match.Components
|
|||||||
{
|
{
|
||||||
Overall
|
Overall
|
||||||
}
|
}
|
||||||
|
|
||||||
public class RoomScore : ScoreInfo
|
|
||||||
{
|
|
||||||
[JsonProperty("attempts")]
|
|
||||||
public int TotalAttempts { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty("completed")]
|
|
||||||
public int CompletedAttempts { get; set; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ using osu.Framework.Graphics.Sprites;
|
|||||||
using osu.Framework.Lists;
|
using osu.Framework.Lists;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
using osu.Game.Online.Multiplayer;
|
using osu.Game.Online.Multiplayer;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
using osu.Game.Screens.Multi.Match.Components;
|
using osu.Game.Screens.Multi.Match.Components;
|
||||||
@ -73,13 +74,13 @@ namespace osu.Game.Screens.Multi.Ranking.Pages
|
|||||||
leaderboard.ScoresLoaded = scoresLoaded;
|
leaderboard.ScoresLoaded = scoresLoaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scoresLoaded(IEnumerable<RoomScore> scores)
|
private void scoresLoaded(IEnumerable<APIRoomScoreInfo> scores)
|
||||||
{
|
{
|
||||||
Action<SpriteText> gray = s => s.Colour = colours.Gray8;
|
Action<SpriteText> gray = s => s.Colour = colours.Gray8;
|
||||||
|
|
||||||
rankText.AddText("You are placed ", gray);
|
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 =>
|
rankText.AddText($"#{index + 1} ", s =>
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user