diff --git a/PerformanceCalculatorGUI/Components/LazerCalculationSettings.cs b/PerformanceCalculatorGUI/Components/LazerCalculationSettings.cs index 98a87f22f..51bec38ea 100644 --- a/PerformanceCalculatorGUI/Components/LazerCalculationSettings.cs +++ b/PerformanceCalculatorGUI/Components/LazerCalculationSettings.cs @@ -23,13 +23,13 @@ namespace PerformanceCalculatorGUI.Components { public partial class LazerCalculationSettings : ToolbarButton, IHasPopover { - private readonly Bindable calculateRankedMaps = new(true); - private readonly Bindable calculateUnrankedMaps = new(false); + private readonly Bindable calculateRankedMaps = new Bindable(true); + private readonly Bindable calculateUnrankedMaps = new Bindable(false); - private readonly Bindable calculateUnsubmittedScores = new(true); - private readonly Bindable calculateUnrankedMods = new(true); + private readonly Bindable calculateUnsubmittedScores = new Bindable(true); + private readonly Bindable calculateUnrankedMods = new Bindable(true); - private readonly Bindable enableScorev1Overwrite = new(false); + private readonly Bindable enableScorev1Overwrite = new Bindable(false); public bool IsScorev1OverwritingEnabled => enableScorev1Overwrite.Value; @@ -47,6 +47,9 @@ public bool ShouldBeFiltered(ScoreInfo score) if (score.Mods.Any(h => h is OsuModRelax || h is OsuModAutopilot)) return true; + if (score.BeatmapInfo == null) + return true; + if (!calculateRankedMaps.Value && score.BeatmapInfo.Status.GrantsPerformancePoints()) return true; diff --git a/PerformanceCalculatorGUI/Components/ProfileScore.cs b/PerformanceCalculatorGUI/Components/ProfileScore.cs index 1202ba7e3..7c8813581 100644 --- a/PerformanceCalculatorGUI/Components/ProfileScore.cs +++ b/PerformanceCalculatorGUI/Components/ProfileScore.cs @@ -54,15 +54,15 @@ private static SoloScoreInfo toSoloScoreInfo(ScoreInfo score) { APIBeatmapSet dummySet = new APIBeatmapSet { - Title = score.BeatmapInfo.Metadata.Title, - TitleUnicode = score.BeatmapInfo.Metadata.TitleUnicode, - Artist = score.BeatmapInfo.Metadata.Artist, - ArtistUnicode = score.BeatmapInfo.Metadata.ArtistUnicode, + Title = score.BeatmapInfo?.Metadata.Title ?? "Error Title", + TitleUnicode = score.BeatmapInfo?.Metadata.TitleUnicode ?? "Error Title", + Artist = score.BeatmapInfo?.Metadata.Artist ?? "Error Artist", + ArtistUnicode = score.BeatmapInfo?.Metadata.ArtistUnicode ?? "Error Artist", }; APIBeatmap dummyBeatmap = new APIBeatmap { - OnlineID = score.BeatmapInfo.OnlineID, - DifficultyName = score.BeatmapInfo.DifficultyName, + OnlineID = score.BeatmapInfo?.OnlineID ?? 0, + DifficultyName = score.BeatmapInfo?.DifficultyName ?? "Error Difficulty", }; SoloScoreInfo soloScoreInfo = new SoloScoreInfo { @@ -79,7 +79,6 @@ private static SoloScoreInfo toSoloScoreInfo(ScoreInfo score) return soloScoreInfo; } - } public partial class DrawableProfileScore : CompositeDrawable @@ -214,7 +213,7 @@ private void load(RulesetStore rulesets) Width = performance_width, Anchor = Anchor.CentreRight, Origin = Anchor.CentreRight, - Children = new Drawable[] + Children = new[] { new Box { diff --git a/PerformanceCalculatorGUI/Configuration/SettingsManager.cs b/PerformanceCalculatorGUI/Configuration/SettingsManager.cs index 61da87871..506430cad 100644 --- a/PerformanceCalculatorGUI/Configuration/SettingsManager.cs +++ b/PerformanceCalculatorGUI/Configuration/SettingsManager.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System; using System.IO; using System.Reflection; using osu.Framework.Configuration; diff --git a/PerformanceCalculatorGUI/RulesetHelper.cs b/PerformanceCalculatorGUI/RulesetHelper.cs index efaaf66ea..75c4d9a2f 100644 --- a/PerformanceCalculatorGUI/RulesetHelper.cs +++ b/PerformanceCalculatorGUI/RulesetHelper.cs @@ -110,13 +110,14 @@ public static int GenerateModsHash(Mod[] mods, BeatmapDifficulty difficulty, Rul bool isSliderAccuracy = mods.OfType().All(m => !m.NoSliderHeadAccuracy.Value); byte flashlightHash = 0; + if (mods.Any(h => h is OsuModFlashlight)) { - if (!mods.Any(h => h is OsuModHidden)) flashlightHash = 1; - else flashlightHash = 2; + flashlightHash = (byte)(mods.Any(h => h is OsuModHidden) ? 2 : 1); } byte mirrorHash = 0; + if (mods.FirstOrDefault(m => m is OsuModMirror) is OsuModMirror mirror) { mirrorHash = (byte)(1 + (int)(mirror.Reflection.Value)); diff --git a/PerformanceCalculatorGUI/Screens/BeatmapLeaderboardScreen.cs b/PerformanceCalculatorGUI/Screens/BeatmapLeaderboardScreen.cs index 90ef85c85..e2f38ad5d 100644 --- a/PerformanceCalculatorGUI/Screens/BeatmapLeaderboardScreen.cs +++ b/PerformanceCalculatorGUI/Screens/BeatmapLeaderboardScreen.cs @@ -222,7 +222,7 @@ private void calculate() var difficultyCalculator = rulesetInstance.CreateDifficultyCalculator(working); - Dictionary attributesCache = new(); + Dictionary attributesCache = new Dictionary(); foreach (var score in leaderboard.Scores) { @@ -236,14 +236,9 @@ private void calculate() var parsedScore = new ProcessorScoreDecoder(working).Parse(scoreInfo); - DifficultyAttributes difficultyAttributes; int modsHash = RulesetHelper.GenerateModsHash(mods, working.BeatmapInfo.Difficulty, ruleset.Value); - if (attributesCache.ContainsKey(modsHash)) - { - difficultyAttributes = attributesCache[modsHash]; - } - else + if (!attributesCache.TryGetValue(modsHash, out var difficultyAttributes)) { difficultyAttributes = difficultyCalculator.Calculate(mods); attributesCache[modsHash] = difficultyAttributes; diff --git a/PerformanceCalculatorGUI/Screens/ProfileScreen.cs b/PerformanceCalculatorGUI/Screens/ProfileScreen.cs index 834deba06..fdb464970 100644 --- a/PerformanceCalculatorGUI/Screens/ProfileScreen.cs +++ b/PerformanceCalculatorGUI/Screens/ProfileScreen.cs @@ -462,7 +462,7 @@ private void calculateProfileFromLazer(string username) List tempScores = []; - Dictionary attributesCache = new(); + Dictionary attributesCache = new Dictionary(); foreach (var score in scoreList) { @@ -471,14 +471,9 @@ private void calculateProfileFromLazer(string username) Schedule(() => loadingLayer.Text.Value = $"Calculating {player.Username}'s scores... {currentScoresCount} / {totalScoresCount}"); - DifficultyAttributes difficultyAttributes; int modsHash = RulesetHelper.GenerateModsHash(score.Mods, working.BeatmapInfo.Difficulty, ruleset.Value); - if (attributesCache.ContainsKey(modsHash)) - { - difficultyAttributes = attributesCache[modsHash]; - } - else + if (!attributesCache.TryGetValue(modsHash, out var difficultyAttributes)) { difficultyAttributes = difficultyCalculator.Calculate(score.Mods); attributesCache[modsHash] = difficultyAttributes; @@ -560,27 +555,27 @@ private List> getRealmScores(RealmAccess realm) Schedule(() => loadingLayer.Text.Value = "Filtering scores..."); realmScores.RemoveAll(x => !currentUser.Contains(x.User.Username) // Wrong username - || x.BeatmapInfo == null // No map for score - || x.Passed == false || x.Rank == ScoreRank.F // Failed score - || x.Ruleset.OnlineID != ruleset.Value.OnlineID // Incorrect ruleset - || settingsMenu.ShouldBeFiltered(x)); // Customisable filters - - List> groupedScores = realmScores.GroupBy(g => g.BeatmapHash) - .Select(s => s.ToList()) - .ToList(); + || x.BeatmapInfo == null // No map for score + || x.Passed == false || x.Rank == ScoreRank.F // Failed score + || x.Ruleset.OnlineID != ruleset.Value.OnlineID // Incorrect ruleset + || settingsMenu.ShouldBeFiltered(x)); // Customisable filters + + List> groupedScores = realmScores.GroupBy(g => g.BeatmapHash).Select(s => s.ToList()).ToList(); + // Simulate scorev1 if enabled if (settingsMenu.IsScorev1OverwritingEnabled) { var rulesetInstance = ruleset.Value.CreateInstance(); - List> filteredScores = new(); + List> filteredScores = new List>(); foreach (var mapScores in groupedScores) { List filteredMapScores = mapScores.Where(s => s.IsLegacyScore) - .GroupBy(x => rulesetInstance.ConvertToLegacyMods(x.Mods)) - .Select(x => x.MaxBy(x => x.LegacyTotalScore)) - .ToList(); + .GroupBy(x => rulesetInstance.ConvertToLegacyMods(x.Mods)) + .Select(g => g.MaxBy(g => g.LegacyTotalScore)) + .ToList(); + filteredMapScores.AddRange(mapScores.Where(s => !s.IsLegacyScore)); filteredScores.Add(mapScores); }