mirror of
https://github.com/ppy/osu.git
synced 2024-12-05 03:13:22 +08:00
Remove IAPIProvider.Statistics
in favour of the new component
This commit is contained in:
parent
91fb59ee15
commit
3ab60b76df
@ -8,6 +8,7 @@ using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Models;
|
||||
using osu.Game.Online;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
@ -25,6 +26,7 @@ namespace osu.Game.Tests.Visual.Online
|
||||
{
|
||||
protected override bool UseOnlineAPI => false;
|
||||
|
||||
private LocalUserStatisticsProvider statisticsProvider = null!;
|
||||
private SoloStatisticsWatcher watcher = null!;
|
||||
|
||||
[Resolved]
|
||||
@ -109,7 +111,9 @@ namespace osu.Game.Tests.Visual.Online
|
||||
|
||||
AddStep("create watcher", () =>
|
||||
{
|
||||
Child = watcher = new SoloStatisticsWatcher();
|
||||
Clear();
|
||||
Add(statisticsProvider = new LocalUserStatisticsProvider());
|
||||
Add(watcher = new SoloStatisticsWatcher(statisticsProvider));
|
||||
});
|
||||
}
|
||||
|
||||
@ -289,7 +293,7 @@ namespace osu.Game.Tests.Visual.Online
|
||||
AddStep("signal score processed", () => ((ISpectatorClient)spectatorClient).UserScoreProcessed(userId, scoreId));
|
||||
AddUntilStep("update received", () => update != null);
|
||||
AddAssert("local user values are correct", () => dummyAPI.LocalUser.Value.Statistics.TotalScore, () => Is.EqualTo(5_000_000));
|
||||
AddAssert("statistics values are correct", () => dummyAPI.Statistics.Value!.TotalScore, () => Is.EqualTo(5_000_000));
|
||||
AddAssert("statistics values are correct", () => statisticsProvider.Statistics.Value!.TotalScore, () => Is.EqualTo(5_000_000));
|
||||
}
|
||||
|
||||
private int nextUserId = 2000;
|
||||
|
@ -55,7 +55,6 @@ namespace osu.Game.Online.API
|
||||
public IBindable<APIUser> LocalUser => localUser;
|
||||
public IBindableList<APIUser> Friends => friends;
|
||||
public IBindable<UserActivity> Activity => activity;
|
||||
public IBindable<UserStatistics> Statistics => statistics;
|
||||
|
||||
public INotificationsClient NotificationsClient { get; }
|
||||
|
||||
@ -70,8 +69,6 @@ namespace osu.Game.Online.API
|
||||
private Bindable<UserStatus?> configStatus { get; } = new Bindable<UserStatus?>();
|
||||
private Bindable<UserStatus?> localUserStatus { get; } = new Bindable<UserStatus?>();
|
||||
|
||||
private Bindable<UserStatistics> statistics { get; } = new Bindable<UserStatistics>();
|
||||
|
||||
protected bool HasLogin => authentication.Token.Value != null || (!string.IsNullOrEmpty(ProvidedUsername) && !string.IsNullOrEmpty(password));
|
||||
|
||||
private readonly CancellationTokenSource cancellationToken = new CancellationTokenSource();
|
||||
@ -595,21 +592,9 @@ namespace osu.Game.Online.API
|
||||
flushQueue();
|
||||
}
|
||||
|
||||
public void UpdateStatistics(UserStatistics newStatistics)
|
||||
{
|
||||
statistics.Value = newStatistics;
|
||||
|
||||
if (IsLoggedIn)
|
||||
localUser.Value.Statistics = newStatistics;
|
||||
}
|
||||
|
||||
private static APIUser createGuestUser() => new GuestUser();
|
||||
|
||||
private void setLocalUser(APIUser user) => Scheduler.Add(() =>
|
||||
{
|
||||
localUser.Value = user;
|
||||
statistics.Value = user.Statistics;
|
||||
}, false);
|
||||
private void setLocalUser(APIUser user) => Scheduler.Add(() => localUser.Value = user, false);
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
|
@ -30,8 +30,6 @@ namespace osu.Game.Online.API
|
||||
|
||||
public Bindable<UserActivity> Activity { get; } = new Bindable<UserActivity>();
|
||||
|
||||
public Bindable<UserStatistics?> Statistics { get; } = new Bindable<UserStatistics?>();
|
||||
|
||||
public DummyNotificationsClient NotificationsClient { get; } = new DummyNotificationsClient();
|
||||
INotificationsClient IAPIProvider.NotificationsClient => NotificationsClient;
|
||||
|
||||
@ -158,11 +156,6 @@ namespace osu.Game.Online.API
|
||||
private void onSuccessfulLogin()
|
||||
{
|
||||
state.Value = APIState.Online;
|
||||
Statistics.Value = new UserStatistics
|
||||
{
|
||||
GlobalRank = 1,
|
||||
CountryRank = 1
|
||||
};
|
||||
}
|
||||
|
||||
public void Logout()
|
||||
@ -173,14 +166,6 @@ namespace osu.Game.Online.API
|
||||
LocalUser.Value = new GuestUser();
|
||||
}
|
||||
|
||||
public void UpdateStatistics(UserStatistics newStatistics)
|
||||
{
|
||||
Statistics.Value = newStatistics;
|
||||
|
||||
if (IsLoggedIn)
|
||||
LocalUser.Value.Statistics = newStatistics;
|
||||
}
|
||||
|
||||
public IHubClientConnector? GetHubConnector(string clientName, string endpoint, bool preferMessagePack) => null;
|
||||
|
||||
public IChatClient GetChatClient() => new TestChatClientConnector(this);
|
||||
@ -196,7 +181,6 @@ namespace osu.Game.Online.API
|
||||
IBindable<APIUser> IAPIProvider.LocalUser => LocalUser;
|
||||
IBindableList<APIUser> IAPIProvider.Friends => Friends;
|
||||
IBindable<UserActivity> IAPIProvider.Activity => Activity;
|
||||
IBindable<UserStatistics?> IAPIProvider.Statistics => Statistics;
|
||||
|
||||
/// <summary>
|
||||
/// Skip 2FA requirement for next login.
|
||||
|
@ -29,11 +29,6 @@ namespace osu.Game.Online.API
|
||||
/// </summary>
|
||||
IBindable<UserActivity> Activity { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The current user's online statistics.
|
||||
/// </summary>
|
||||
IBindable<UserStatistics?> Statistics { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The language supplied by this provider to API requests.
|
||||
/// </summary>
|
||||
@ -123,11 +118,6 @@ namespace osu.Game.Online.API
|
||||
/// </summary>
|
||||
void Logout();
|
||||
|
||||
/// <summary>
|
||||
/// Sets Statistics bindable.
|
||||
/// </summary>
|
||||
void UpdateStatistics(UserStatistics newStatistics);
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new <see cref="IHubClientConnector"/>. May be null if not supported.
|
||||
/// </summary>
|
||||
|
@ -22,6 +22,8 @@ namespace osu.Game.Online.Solo
|
||||
/// </summary>
|
||||
public partial class SoloStatisticsWatcher : Component
|
||||
{
|
||||
private readonly LocalUserStatisticsProvider? statisticsProvider;
|
||||
|
||||
[Resolved]
|
||||
private SpectatorClient spectatorClient { get; set; } = null!;
|
||||
|
||||
@ -33,6 +35,11 @@ namespace osu.Game.Online.Solo
|
||||
|
||||
private Dictionary<string, UserStatistics>? latestStatistics;
|
||||
|
||||
public SoloStatisticsWatcher(LocalUserStatisticsProvider? statisticsProvider = null)
|
||||
{
|
||||
this.statisticsProvider = statisticsProvider;
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
@ -127,7 +134,7 @@ namespace osu.Game.Online.Solo
|
||||
{
|
||||
string rulesetName = callback.Score.Ruleset.ShortName;
|
||||
|
||||
api.UpdateStatistics(updatedStatistics);
|
||||
statisticsProvider?.UpdateStatistics(updatedStatistics, callback.Score.Ruleset);
|
||||
|
||||
if (latestStatistics == null)
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user