1
0
mirror of https://github.com/ppy/osu.git synced 2026-05-26 06:09:53 +08:00

Update user statistics retrieval with API changes

This commit is contained in:
Salman Ahmed
2021-02-16 04:51:21 +03:00
Unverified
parent d15ffff9a5
commit 5b4999e8af
3 changed files with 7 additions and 22 deletions
@@ -1,6 +1,7 @@
// 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 System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Graphics;
@@ -155,7 +156,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
Id = i,
Username = $"User {i}",
AllStatistics =
RulesetsStatistics = new Dictionary<string, UserStatistics>
{
{ Ruleset.Value.ShortName, new UserStatistics { GlobalRank = RNG.Next(1, 100000) } }
},
@@ -196,7 +197,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
Id = 0,
Username = "User 0",
AllStatistics =
RulesetsStatistics = new Dictionary<string, UserStatistics>
{
{ Ruleset.Value.ShortName, new UserStatistics { GlobalRank = RNG.Next(1, 100000) } }
},
@@ -165,7 +165,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
var ruleset = rulesets.GetRuleset(Room.Settings.RulesetID);
var currentModeRank = User.User?.AllStatistics.GetValueOrDefault(ruleset.ShortName)?.GlobalRank;
var currentModeRank = User.User?.RulesetsStatistics?.GetValueOrDefault(ruleset.ShortName)?.GlobalRank;
userRankText.Text = currentModeRank != null ? $"#{currentModeRank.Value:N0}" : string.Empty;
userStateDisplay.UpdateStatus(User.State, User.BeatmapAvailability);
+3 -19
View File
@@ -5,12 +5,9 @@ using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.Serialization;
using JetBrains.Annotations;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using osu.Framework.Bindables;
using osu.Game.IO.Serialization;
using osu.Game.Online.API.Requests;
namespace osu.Game.Users
@@ -243,22 +240,9 @@ namespace osu.Game.Users
/// Otherwise empty. Can be altered for testing purposes.
/// </summary>
// todo: this should likely be moved to a separate UserCompact class at some point.
[UsedImplicitly]
public readonly Dictionary<string, UserStatistics> AllStatistics = new Dictionary<string, UserStatistics>();
[UsedImplicitly]
[JsonExtensionData]
private readonly IDictionary<string, JToken> otherProperties = new Dictionary<string, JToken>();
[OnDeserialized]
private void onDeserialized(StreamingContext context)
{
foreach (var kvp in otherProperties.Where(kvp => kvp.Key.StartsWith("statistics_", StringComparison.Ordinal)))
{
var shortName = kvp.Key.Replace("statistics_", string.Empty);
AllStatistics[shortName] = kvp.Value.ToObject<UserStatistics>(JsonSerializer.Create(JsonSerializableExtensions.CreateGlobalSettings()));
}
}
[JsonProperty("statistics_rulesets")]
[CanBeNull]
public Dictionary<string, UserStatistics> RulesetsStatistics { get; set; }
public override string ToString() => Username;