mirror of
https://github.com/osukey/osukey.git
synced 2025-08-05 15:44:04 +09:00
Un-nest class
This commit is contained in:
@ -117,8 +117,10 @@ namespace osu.Game.Screens.Select
|
||||
private readonly Stack<CarouselBeatmap> randomSelectedBeatmaps = new Stack<CarouselBeatmap>();
|
||||
|
||||
protected List<DrawableCarouselItem> Items = new List<DrawableCarouselItem>();
|
||||
|
||||
private CarouselRoot root;
|
||||
public SongSelect.DifficultyRecommender DifficultyRecommender;
|
||||
|
||||
public DifficultyRecommender DifficultyRecommender;
|
||||
|
||||
public BeatmapCarousel()
|
||||
{
|
||||
|
75
osu.Game/Screens/Select/DifficultyRecommender.cs
Normal file
75
osu.Game/Screens/Select/DifficultyRecommender.cs
Normal file
@ -0,0 +1,75 @@
|
||||
// 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;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Rulesets;
|
||||
|
||||
namespace osu.Game.Screens.Select
|
||||
{
|
||||
public class DifficultyRecommender : Component
|
||||
{
|
||||
[Resolved]
|
||||
private IAPIProvider api { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private RulesetStore rulesets { get; set; }
|
||||
|
||||
private readonly Dictionary<RulesetInfo, double> recommendedStarDifficulty = new Dictionary<RulesetInfo, double>();
|
||||
|
||||
private int pendingAPIRequests;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
updateRecommended();
|
||||
}
|
||||
|
||||
private void updateRecommended()
|
||||
{
|
||||
if (pendingAPIRequests > 0)
|
||||
return;
|
||||
if (api.LocalUser.Value is GuestUser)
|
||||
return;
|
||||
|
||||
rulesets.AvailableRulesets.ForEach(rulesetInfo =>
|
||||
{
|
||||
var req = new GetUserRequest(api.LocalUser.Value.Id, rulesetInfo);
|
||||
|
||||
req.Success += result =>
|
||||
{
|
||||
// algorithm taken from https://github.com/ppy/osu-web/blob/e6e2825516449e3d0f3f5e1852c6bdd3428c3437/app/Models/User.php#L1505
|
||||
recommendedStarDifficulty[rulesetInfo] = Math.Pow((double)(result.Statistics.PP ?? 0), 0.4) * 0.195;
|
||||
pendingAPIRequests--;
|
||||
};
|
||||
|
||||
req.Failure += _ => pendingAPIRequests--;
|
||||
|
||||
pendingAPIRequests++;
|
||||
api.Queue(req);
|
||||
});
|
||||
}
|
||||
|
||||
public BeatmapInfo GetRecommendedBeatmap(IEnumerable<BeatmapInfo> beatmaps, RulesetInfo currentRuleset)
|
||||
{
|
||||
if (!recommendedStarDifficulty.ContainsKey(currentRuleset))
|
||||
{
|
||||
updateRecommended();
|
||||
return null;
|
||||
}
|
||||
|
||||
return beatmaps.OrderBy(b =>
|
||||
{
|
||||
var difference = b.StarDifficulty - recommendedStarDifficulty[currentRuleset];
|
||||
return difference >= 0 ? difference * 2 : difference * -1; // prefer easier over harder
|
||||
}).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
@ -36,9 +36,6 @@ using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Game.Overlays.Notifications;
|
||||
using osu.Game.Scoring;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||
using osu.Game.Online.API.Requests;
|
||||
|
||||
namespace osu.Game.Screens.Select
|
||||
{
|
||||
@ -787,65 +784,6 @@ namespace osu.Game.Screens.Select
|
||||
return base.OnKeyDown(e);
|
||||
}
|
||||
|
||||
public class DifficultyRecommender : Component
|
||||
{
|
||||
[Resolved]
|
||||
private IAPIProvider api { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private RulesetStore rulesets { get; set; }
|
||||
|
||||
private readonly Dictionary<RulesetInfo, double> recommendedStarDifficulty = new Dictionary<RulesetInfo, double>();
|
||||
|
||||
private int pendingAPIRequests;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
updateRecommended();
|
||||
}
|
||||
|
||||
private void updateRecommended()
|
||||
{
|
||||
if (pendingAPIRequests > 0)
|
||||
return;
|
||||
if (api.LocalUser.Value is GuestUser)
|
||||
return;
|
||||
|
||||
rulesets.AvailableRulesets.ForEach(rulesetInfo =>
|
||||
{
|
||||
var req = new GetUserRequest(api.LocalUser.Value.Id, rulesetInfo);
|
||||
|
||||
req.Success += result =>
|
||||
{
|
||||
// algorithm taken from https://github.com/ppy/osu-web/blob/e6e2825516449e3d0f3f5e1852c6bdd3428c3437/app/Models/User.php#L1505
|
||||
recommendedStarDifficulty[rulesetInfo] = Math.Pow((double)(result.Statistics.PP ?? 0), 0.4) * 0.195;
|
||||
pendingAPIRequests--;
|
||||
};
|
||||
|
||||
req.Failure += _ => pendingAPIRequests--;
|
||||
|
||||
pendingAPIRequests++;
|
||||
api.Queue(req);
|
||||
});
|
||||
}
|
||||
|
||||
public BeatmapInfo GetRecommendedBeatmap(IEnumerable<BeatmapInfo> beatmaps, RulesetInfo currentRuleset)
|
||||
{
|
||||
if (!recommendedStarDifficulty.ContainsKey(currentRuleset))
|
||||
{
|
||||
updateRecommended();
|
||||
return null;
|
||||
}
|
||||
|
||||
return beatmaps.OrderBy(b =>
|
||||
{
|
||||
var difference = b.StarDifficulty - recommendedStarDifficulty[currentRuleset];
|
||||
return difference >= 0 ? difference * 2 : difference * -1; // prefer easier over harder
|
||||
}).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
private class VerticalMaskingContainer : Container
|
||||
{
|
||||
private const float panel_overflow = 1.2f;
|
||||
|
Reference in New Issue
Block a user