1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-05 09:42:54 +08:00

Fix more test / component breakage

This commit is contained in:
Salman Alshamrani 2024-11-17 20:35:59 -05:00
parent caf56afba6
commit b106833663
3 changed files with 26 additions and 14 deletions

View File

@ -33,7 +33,7 @@ namespace osu.Game.Tests.Visual.SongSelect
{ {
AddStep("populate ruleset statistics", () => AddStep("populate ruleset statistics", () =>
{ {
((DummyAPIAccess)API).HandleRequest += r => ((DummyAPIAccess)API).HandleRequest = r =>
{ {
switch (r) switch (r)
{ {

View File

@ -12,6 +12,7 @@ using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Online; using osu.Game.Online;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Users;
namespace osu.Game.Beatmaps namespace osu.Game.Beatmaps
{ {
@ -24,7 +25,10 @@ namespace osu.Game.Beatmaps
private readonly LocalUserStatisticsProvider statisticsProvider; private readonly LocalUserStatisticsProvider statisticsProvider;
[Resolved] [Resolved]
private Bindable<RulesetInfo> ruleset { get; set; } private Bindable<RulesetInfo> gameRuleset { get; set; }
[Resolved]
private RulesetStore rulesets { get; set; } = null!;
private readonly Dictionary<string, double> recommendedDifficultyMapping = new Dictionary<string, double>(); private readonly Dictionary<string, double> recommendedDifficultyMapping = new Dictionary<string, double>();
@ -36,14 +40,14 @@ namespace osu.Game.Beatmaps
{ {
get get
{ {
if (LoadState < LoadState.Ready || ruleset.Value == null) if (LoadState < LoadState.Ready || gameRuleset.Value == null)
return Enumerable.Empty<string>(); return Enumerable.Empty<string>();
return recommendedDifficultyMapping return recommendedDifficultyMapping
.OrderByDescending(pair => pair.Value) .OrderByDescending(pair => pair.Value)
.Select(pair => pair.Key) .Select(pair => pair.Key)
.Where(r => !r.Equals(ruleset.Value.ShortName, StringComparison.Ordinal)) .Where(r => !r.Equals(gameRuleset.Value.ShortName, StringComparison.Ordinal))
.Prepend(ruleset.Value.ShortName); .Prepend(gameRuleset.Value.ShortName);
} }
} }
@ -54,19 +58,28 @@ namespace osu.Game.Beatmaps
this.statisticsProvider = statisticsProvider; this.statisticsProvider = statisticsProvider;
} }
[BackgroundDependencyLoader]
private void load()
{
foreach (var ruleset in rulesets.AvailableRulesets)
{
if (statisticsProvider.GetStatisticsFor(ruleset) is UserStatistics statistics)
updateMapping(ruleset, statistics);
}
}
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
statisticsUpdate = statisticsProvider.StatisticsUpdate.GetBoundCopy(); statisticsUpdate = statisticsProvider.StatisticsUpdate.GetBoundCopy();
statisticsUpdate.BindValueChanged(u => statisticsUpdate.ValueChanged += u => updateMapping(u.NewValue.Ruleset, u.NewValue.NewStatistics);
{ }
if (u.NewValue == null)
return;
// algorithm taken from https://github.com/ppy/osu-web/blob/e6e2825516449e3d0f3f5e1852c6bdd3428c3437/app/Models/User.php#L1505 private void updateMapping(RulesetInfo ruleset, UserStatistics statistics)
recommendedDifficultyMapping[u.NewValue.Ruleset.ShortName] = Math.Pow((double)(u.NewValue.NewStatistics.PP ?? 0), 0.4) * 0.195; {
}, true); // algorithm taken from https://github.com/ppy/osu-web/blob/e6e2825516449e3d0f3f5e1852c6bdd3428c3437/app/Models/User.php#L1505
recommendedDifficultyMapping[ruleset.ShortName] = Math.Pow((double)(statistics.PP ?? 0), 0.4) * 0.195;
} }
/// <summary> /// <summary>

View File

@ -1071,6 +1071,7 @@ namespace osu.Game
LocalUserStatisticsProvider statisticsProvider; LocalUserStatisticsProvider statisticsProvider;
loadComponentSingleFile(statisticsProvider = new LocalUserStatisticsProvider(), Add, true); loadComponentSingleFile(statisticsProvider = new LocalUserStatisticsProvider(), Add, true);
loadComponentSingleFile(difficultyRecommender = new DifficultyRecommender(statisticsProvider), Add, true);
loadComponentSingleFile(new UserStatisticsWatcher(statisticsProvider), Add, true); loadComponentSingleFile(new UserStatisticsWatcher(statisticsProvider), Add, true);
loadComponentSingleFile(Toolbar = new Toolbar loadComponentSingleFile(Toolbar = new Toolbar
{ {
@ -1141,8 +1142,6 @@ namespace osu.Game
loadComponentSingleFile(new BackgroundDataStoreProcessor(), Add); loadComponentSingleFile(new BackgroundDataStoreProcessor(), Add);
loadComponentSingleFile(new DetachedBeatmapStore(), Add, true); loadComponentSingleFile(new DetachedBeatmapStore(), Add, true);
loadComponentSingleFile(difficultyRecommender = new DifficultyRecommender(statisticsProvider), Add, true);
Add(externalLinkOpener = new ExternalLinkOpener()); Add(externalLinkOpener = new ExternalLinkOpener());
Add(new MusicKeyBindingHandler()); Add(new MusicKeyBindingHandler());
Add(new OnlineStatusNotifier(() => ScreenStack.CurrentScreen)); Add(new OnlineStatusNotifier(() => ScreenStack.CurrentScreen));