-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce UserStatisticsProvider
component and add support for respecting selected ruleset
#27128
Merged
Merged
Changes from 5 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
91fb59e
Introduce `LocalUserStatisticsProvider` component
frenzibyte 3ab60b7
Remove `IAPIProvider.Statistics` in favour of the new component
frenzibyte 633d854
Update `UserRankPanel` implementation to use new component
frenzibyte bc2b705
Fix `ImportTest.TestOsuGameBase` having null ruleset
frenzibyte 11b3fa8
Fix `TestSceneUserPanel` tests failing
frenzibyte 701fb56
Merge branch 'master' into user-statistics-provider
frenzibyte 2fd4952
Fix post-merge errors
frenzibyte 3a57b21
Move `LocalUserStatisticsProvider` to non-base game class and make de…
frenzibyte 44dd813
Make `UserStatisticsWatcher` fully rely on `LocalUserStatisticsProvider`
frenzibyte fdeb8b9
Merge branch 'master' into user-statistics-provider
frenzibyte 663b769
Update `DiscordRichPresence` to use new statistics provider component
frenzibyte 979065c
Reorder code slightly
frenzibyte 0760451
Merge branch 'master' into user-statistics-provider
peppy 6c8a900
Merge branch 'master' into user-statistics-provider
frenzibyte 4a62828
Decouple game-wide ruleset bindable and refactor `LocalUserStatistics…
frenzibyte 28f8740
Make `DifficultyRecommender` rely on the statistics provider
frenzibyte 07609b6
Fix `UserRankPanel` not updating on ruleset change
frenzibyte 1847b67
Only update user rank panel display when ruleset matches
frenzibyte caf56af
Fix various test failures
frenzibyte b106833
Fix more test / component breakage
frenzibyte 74daf85
Replace bindable with an event
frenzibyte 0b52080
Handle logged out user
frenzibyte 631bfad
Replace event subscription with callback in `UserStatisticsWatcher`
frenzibyte aa1358b
Enable NRT and fix code
frenzibyte 53b3906
Fix failing test
frenzibyte 0a3f3c3
Add guard against fetching statistics for non-legacy rulesets
bdach b76460f
Schedule the thing
frenzibyte 42c68ba
Add inline comment
frenzibyte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
osu.Game.Tests/Visual/Online/TestSceneLocalUserStatisticsProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System.Collections.Generic; | ||
using NUnit.Framework; | ||
using osu.Framework.Extensions.ObjectExtensions; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Testing; | ||
using osu.Game.Graphics.Sprites; | ||
using osu.Game.Online; | ||
using osu.Game.Online.API; | ||
using osu.Game.Online.API.Requests; | ||
using osu.Game.Online.API.Requests.Responses; | ||
using osu.Game.Rulesets.Catch; | ||
using osu.Game.Rulesets.Mania; | ||
using osu.Game.Rulesets.Osu; | ||
using osu.Game.Rulesets.Taiko; | ||
using osu.Game.Users; | ||
|
||
namespace osu.Game.Tests.Visual.Online | ||
{ | ||
public partial class TestSceneLocalUserStatisticsProvider : OsuTestScene | ||
{ | ||
private LocalUserStatisticsProvider statisticsProvider = null!; | ||
|
||
private readonly Dictionary<(int userId, string rulesetName), UserStatistics> serverSideStatistics = new Dictionary<(int userId, string rulesetName), UserStatistics>(); | ||
|
||
[SetUpSteps] | ||
public void SetUpSteps() | ||
{ | ||
AddStep("clear statistics", () => serverSideStatistics.Clear()); | ||
|
||
setUser(1000); | ||
|
||
AddStep("setup provider", () => | ||
{ | ||
OsuSpriteText text; | ||
|
||
((DummyAPIAccess)API).HandleRequest = r => | ||
{ | ||
switch (r) | ||
{ | ||
case GetUserRequest userRequest: | ||
int userId = int.Parse(userRequest.Lookup); | ||
string rulesetName = userRequest.Ruleset!.ShortName; | ||
var response = new APIUser | ||
{ | ||
Id = userId, | ||
Statistics = tryGetStatistics(userId, rulesetName) | ||
}; | ||
|
||
userRequest.TriggerSuccess(response); | ||
return true; | ||
|
||
default: | ||
return false; | ||
} | ||
}; | ||
|
||
Clear(); | ||
Add(statisticsProvider = new LocalUserStatisticsProvider()); | ||
Add(text = new OsuSpriteText | ||
{ | ||
Anchor = Anchor.Centre, | ||
Origin = Anchor.Centre, | ||
}); | ||
|
||
statisticsProvider.Statistics.BindValueChanged(s => | ||
{ | ||
text.Text = s.NewValue == null | ||
? "Statistics: (null)" | ||
: $"Statistics: (total score: {s.NewValue.TotalScore:N0})"; | ||
}); | ||
|
||
Ruleset.Value = new OsuRuleset().RulesetInfo; | ||
}); | ||
} | ||
|
||
[Test] | ||
public void TestInitialStatistics() | ||
{ | ||
AddAssert("initial statistics populated", () => statisticsProvider.Statistics.Value.AsNonNull().TotalScore, () => Is.EqualTo(4_000_000)); | ||
} | ||
|
||
[Test] | ||
public void TestRulesetChanges() | ||
{ | ||
AddAssert("statistics from osu", () => statisticsProvider.Statistics.Value.AsNonNull().TotalScore, () => Is.EqualTo(4_000_000)); | ||
AddStep("change ruleset to taiko", () => Ruleset.Value = new TaikoRuleset().RulesetInfo); | ||
AddAssert("statistics from taiko", () => statisticsProvider.Statistics.Value.AsNonNull().TotalScore, () => Is.EqualTo(3_000_000)); | ||
AddStep("change ruleset to catch", () => Ruleset.Value = new CatchRuleset().RulesetInfo); | ||
AddAssert("statistics from catch", () => statisticsProvider.Statistics.Value.AsNonNull().TotalScore, () => Is.EqualTo(2_000_000)); | ||
AddStep("change ruleset to mania", () => Ruleset.Value = new ManiaRuleset().RulesetInfo); | ||
AddAssert("statistics from mania", () => statisticsProvider.Statistics.Value.AsNonNull().TotalScore, () => Is.EqualTo(1_000_000)); | ||
} | ||
|
||
[Test] | ||
public void TestUserChanges() | ||
{ | ||
setUser(1001); | ||
|
||
AddStep("update statistics for user 1000", () => | ||
{ | ||
serverSideStatistics[(1000, "osu")] = new UserStatistics { TotalScore = 5_000_000 }; | ||
serverSideStatistics[(1000, "taiko")] = new UserStatistics { TotalScore = 6_000_000 }; | ||
}); | ||
|
||
AddAssert("statistics matches user 1001 from osu", () => statisticsProvider.Statistics.Value.AsNonNull().TotalScore, () => Is.EqualTo(4_000_000)); | ||
|
||
AddStep("change ruleset to taiko", () => Ruleset.Value = new TaikoRuleset().RulesetInfo); | ||
AddAssert("statistics matches user 1001 from taiko", () => statisticsProvider.Statistics.Value.AsNonNull().TotalScore, () => Is.EqualTo(3_000_000)); | ||
|
||
AddStep("change ruleset to osu", () => Ruleset.Value = new OsuRuleset().RulesetInfo); | ||
setUser(1000, false); | ||
|
||
AddAssert("statistics matches user 1000 from osu", () => statisticsProvider.Statistics.Value.AsNonNull().TotalScore, () => Is.EqualTo(5_000_000)); | ||
|
||
AddStep("change ruleset to osu", () => Ruleset.Value = new TaikoRuleset().RulesetInfo); | ||
AddAssert("statistics matches user 1000 from taiko", () => statisticsProvider.Statistics.Value.AsNonNull().TotalScore, () => Is.EqualTo(6_000_000)); | ||
} | ||
|
||
private UserStatistics tryGetStatistics(int userId, string rulesetName) | ||
=> serverSideStatistics.TryGetValue((userId, rulesetName), out var stats) ? stats : new UserStatistics(); | ||
|
||
private void setUser(int userId, bool generateStatistics = true) | ||
{ | ||
AddStep($"set local user to {userId}", () => | ||
{ | ||
if (generateStatistics) | ||
{ | ||
serverSideStatistics[(userId, "osu")] = new UserStatistics { TotalScore = 4_000_000 }; | ||
serverSideStatistics[(userId, "taiko")] = new UserStatistics { TotalScore = 3_000_000 }; | ||
serverSideStatistics[(userId, "fruits")] = new UserStatistics { TotalScore = 2_000_000 }; | ||
serverSideStatistics[(userId, "mania")] = new UserStatistics { TotalScore = 1_000_000 }; | ||
} | ||
|
||
((DummyAPIAccess)API).LocalUser.Value = new APIUser { Id = userId }; | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For one, very happy to see this gone from here