1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 14:17:26 +08:00

Fix multiplayer aggregate score inheriting from ScoreInfo

This commit is contained in:
Dean Herbert 2019-12-03 16:10:25 +09:00
parent bb00b4166e
commit 36224dca13
7 changed files with 63 additions and 32 deletions

View File

@ -83,7 +83,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
private class TestMatchLeaderboard : RoomLeaderboardPage.ResultsMatchLeaderboard
{
protected override APIRequest FetchScores(Action<IEnumerable<APIRoomScoreInfo>> scoresCallback)
protected override APIRequest FetchScores(Action<IEnumerable<APIUserScoreAggregate>> scoresCallback)
{
var scores = Enumerable.Range(0, 50).Select(createRoomScore).ToArray();
@ -93,7 +93,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
return null;
}
private APIRoomScoreInfo createRoomScore(int id) => new APIRoomScoreInfo
private APIUserScoreAggregate createRoomScore(int id) => new APIUserScoreAggregate
{
User = new User { Id = id, Username = $"User {id}" },
Accuracy = 0.98,

View File

@ -6,7 +6,7 @@ using osu.Game.Online.API.Requests.Responses;
namespace osu.Game.Online.API.Requests
{
public class GetRoomScoresRequest : APIRequest<List<APIRoomScoreInfo>>
public class GetRoomScoresRequest : APIRequest<List<APIUserScoreAggregate>>
{
private readonly int roomId;

View File

@ -1,17 +0,0 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
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 CompletedBeatmaps { get; set; }
}
}

View File

@ -0,0 +1,45 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using Newtonsoft.Json;
using osu.Game.Scoring;
using osu.Game.Users;
namespace osu.Game.Online.API.Requests.Responses
{
public class APIUserScoreAggregate
{
[JsonProperty("attempts")]
public int TotalAttempts { get; set; }
[JsonProperty("completed")]
public int CompletedBeatmaps { get; set; }
[JsonProperty("accuracy")]
public double Accuracy { get; set; }
[JsonProperty(@"pp")]
public double? PP { get; set; }
[JsonProperty(@"room_id")]
public int RoomID { get; set; }
[JsonProperty("total_score")]
public long TotalScore { get; set; }
[JsonProperty(@"user_id")]
public long UserID { get; set; }
[JsonProperty("user")]
public User User { get; set; }
public ScoreInfo CreateScoreInfo() =>
new ScoreInfo
{
Accuracy = Accuracy,
PP = PP,
TotalScore = TotalScore,
User = User,
};
}
}

View File

@ -13,9 +13,9 @@ using osu.Game.Online.Multiplayer;
namespace osu.Game.Screens.Multi.Match.Components
{
public class MatchLeaderboard : Leaderboard<MatchLeaderboardScope, APIRoomScoreInfo>
public class MatchLeaderboard : Leaderboard<MatchLeaderboardScope, APIUserScoreAggregate>
{
public Action<IEnumerable<APIRoomScoreInfo>> ScoresLoaded;
public Action<IEnumerable<APIUserScoreAggregate>> ScoresLoaded;
[Resolved(typeof(Room), nameof(Room.RoomID))]
private Bindable<int?> roomId { get; set; }
@ -35,7 +35,7 @@ namespace osu.Game.Screens.Multi.Match.Components
protected override bool IsOnlineScope => true;
protected override APIRequest FetchScores(Action<IEnumerable<APIRoomScoreInfo>> scoresCallback)
protected override APIRequest FetchScores(Action<IEnumerable<APIUserScoreAggregate>> scoresCallback)
{
if (roomId.Value == null)
return null;
@ -51,7 +51,7 @@ namespace osu.Game.Screens.Multi.Match.Components
return req;
}
protected override LeaderboardScore CreateDrawableScore(APIRoomScoreInfo model, int index) => new MatchLeaderboardScore(model, index);
protected override LeaderboardScore CreateDrawableScore(APIUserScoreAggregate model, int index) => new MatchLeaderboardScore(model, index);
}
public enum MatchLeaderboardScope

View File

@ -12,9 +12,12 @@ namespace osu.Game.Screens.Multi.Match.Components
{
public class MatchLeaderboardScore : LeaderboardScore
{
public MatchLeaderboardScore(APIRoomScoreInfo score, int rank)
: base(score, rank)
private readonly APIUserScoreAggregate score;
public MatchLeaderboardScore(APIUserScoreAggregate score, int rank)
: base(score.CreateScoreInfo(), rank)
{
this.score = score;
}
[BackgroundDependencyLoader]
@ -26,8 +29,8 @@ namespace osu.Game.Screens.Multi.Match.Components
protected override IEnumerable<LeaderboardScoreStatistic> GetStatistics(ScoreInfo model) => new[]
{
new LeaderboardScoreStatistic(FontAwesome.Solid.Crosshairs, "Accuracy", string.Format(model.Accuracy % 1 == 0 ? @"{0:P0}" : @"{0:P2}", model.Accuracy)),
new LeaderboardScoreStatistic(FontAwesome.Solid.Sync, "Total Attempts", ((APIRoomScoreInfo)model).TotalAttempts.ToString()),
new LeaderboardScoreStatistic(FontAwesome.Solid.Check, "Completed Beatmaps", ((APIRoomScoreInfo)model).CompletedBeatmaps.ToString()),
new LeaderboardScoreStatistic(FontAwesome.Solid.Sync, "Total Attempts", score.TotalAttempts.ToString()),
new LeaderboardScoreStatistic(FontAwesome.Solid.Check, "Completed Beatmaps", score.CompletedBeatmaps.ToString()),
};
}
}

View File

@ -74,7 +74,7 @@ namespace osu.Game.Screens.Multi.Ranking.Pages
leaderboard.ScoresLoaded = scoresLoaded;
}
private void scoresLoaded(IEnumerable<APIRoomScoreInfo> scores)
private void scoresLoaded(IEnumerable<APIUserScoreAggregate> scores)
{
void gray(SpriteText s) => s.Colour = colours.GrayC;
@ -87,7 +87,7 @@ namespace osu.Game.Screens.Multi.Ranking.Pages
rankText.AddText(name + "\n", white);
rankText.AddText("You are placed ", gray);
int index = scores.IndexOf(new APIRoomScoreInfo { User = Score.User }, new FuncEqualityComparer<APIRoomScoreInfo>((s1, s2) => s1.User.Id.Equals(s2.User.Id)));
int index = scores.IndexOf(new APIUserScoreAggregate { User = Score.User }, new FuncEqualityComparer<APIUserScoreAggregate>((s1, s2) => s1.User.Id.Equals(s2.User.Id)));
rankText.AddText($"#{index + 1} ", s =>
{
@ -104,7 +104,7 @@ namespace osu.Game.Screens.Multi.Ranking.Pages
{
protected override bool FadeTop => true;
protected override LeaderboardScore CreateDrawableScore(APIRoomScoreInfo model, int index)
protected override LeaderboardScore CreateDrawableScore(APIUserScoreAggregate model, int index)
=> new ResultsMatchLeaderboardScore(model, index);
protected override FillFlowContainer<LeaderboardScore> CreateScoreFlow()
@ -120,7 +120,7 @@ namespace osu.Game.Screens.Multi.Ranking.Pages
private class ResultsMatchLeaderboardScore : MatchLeaderboardScore
{
public ResultsMatchLeaderboardScore(APIRoomScoreInfo score, int rank)
public ResultsMatchLeaderboardScore(APIUserScoreAggregate score, int rank)
: base(score, rank)
{
}