Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions PerformanceCalculatorGUI/Components/ExtendedProfileScore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected override void OnHoverLost(HoverLostEvent e)

public partial class ExtendedProfileScore : CompositeDrawable
{
private const int height = 35;
public const int HEIGHT = 35;
private const int avatar_size = 35;
private const int performance_width = 100;
private const int rank_difference_width = 35;
Expand All @@ -106,7 +106,7 @@ public ExtendedProfileScore(ExtendedScore score, bool showAvatar = false)
ShowAvatar = showAvatar;

RelativeSizeAxes = Axes.X;
Height = height;
Height = HEIGHT;
}

[BackgroundDependencyLoader]
Expand Down
19 changes: 16 additions & 3 deletions PerformanceCalculatorGUI/Screens/Collections/ScoreCache.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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.Net;
using System.Threading;
using System.Threading.Tasks;
using osu.Framework.Allocation;
Expand All @@ -18,9 +19,21 @@ public partial class ScoreCache : MemoryCachingComponent<long, SoloScoreInfo?>

protected override async Task<SoloScoreInfo?> ComputeValueAsync(long lookup, CancellationToken token = default)
{
var score = await apiManager.GetJsonFromApi<SoloScoreInfo>($"scores/{lookup}").ConfigureAwait(false);
await Task.Delay(200, token).ConfigureAwait(false);
return score;
try
{
var score = await apiManager.GetJsonFromApi<SoloScoreInfo>($"scores/{lookup}").ConfigureAwait(false);
await Task.Delay(200, token).ConfigureAwait(false);
return score;
}
catch (WebException ex)
{
if (ex.Message == "NotFound")
{
return null;
}

throw;
}
}
}
}
41 changes: 37 additions & 4 deletions PerformanceCalculatorGUI/Screens/Collections/ScoreContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,32 @@
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.Profile.Sections;
using PerformanceCalculatorGUI.Components;
using PerformanceCalculatorGUI.Components.TextBoxes;

namespace PerformanceCalculatorGUI.Screens.Collections
{
public partial class ScoreContainer : Container
{
public ExtendedScore Score { get; }
public long ScoreId { get; }
public ExtendedScore? Score { get; }

private readonly IconButton deleteButton;

public delegate void OnDeleteHandler(long scoreId);

public event OnDeleteHandler? OnDelete;

public ScoreContainer(ExtendedScore score)
public ScoreContainer(long scoreId, ExtendedScore? score)
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;

ScoreId = scoreId;
Score = score;
Child = new GridContainer
{
Expand All @@ -43,10 +49,10 @@ public ScoreContainer(ExtendedScore score)
Icon = FontAwesome.Regular.TrashAlt,
Action = () =>
{
OnDelete?.Invoke((long)score.SoloScore.ID!);
OnDelete?.Invoke(scoreId);
}
},
new ExtendedProfileScore(score, true)
Score != null ? new ExtendedProfileScore(Score, true) : new NullProfileScore(ScoreId)
}
}
};
Expand All @@ -70,5 +76,32 @@ protected override void OnHoverLost(HoverLostEvent e)

base.OnHoverLost(e);
}

private partial class NullProfileScore : ProfileItemContainer
{
public NullProfileScore(long scoreId)
{
RelativeSizeAxes = Axes.X;
Height = ExtendedProfileScore.HEIGHT;

CornerRadius = ExtendedLabelledTextBox.CORNER_RADIUS;
AddRangeInternal(new Drawable[]
{
new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.GetFont(size: 14f, weight: FontWeight.Bold),
Text = $"Score ID {scoreId} does not exist."
}
});
}

protected override bool OnHover(HoverEvent e)
{
base.OnHover(e);
return false;
}
}
}
}
41 changes: 23 additions & 18 deletions PerformanceCalculatorGUI/Screens/CollectionsScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,29 +269,34 @@ private void calculateScores()
foreach (long scoreId in currentCollection.Value.Scores)
{
var score = await scoreCache.GetScore(scoreId).ConfigureAwait(false);
if (score == null)
continue;

var rulesetInstance = rulesets.GetRuleset(score.RulesetID)!.CreateInstance();
ExtendedScore? extendedScore = null;

var working = ProcessorWorkingBeatmap.FromFileOrId(score.BeatmapID.ToString(), cachePath: configManager.GetBindable<string>(Settings.CachePath).Value);
if (score != null)
{
var rulesetInstance = rulesets.GetRuleset(score.RulesetID)!.CreateInstance();

var working = ProcessorWorkingBeatmap.FromFileOrId(score.BeatmapID.ToString(), cachePath: configManager.GetBindable<string>(Settings.CachePath).Value);

Mod[] mods = score.Mods.Select(x => x.ToMod(rulesetInstance)).ToArray();
Mod[] mods = score.Mods.Select(x => x.ToMod(rulesetInstance)).ToArray();

var scoreInfo = score.ToScoreInfo(rulesets, working.BeatmapInfo);
var scoreInfo = score.ToScoreInfo(rulesets, working.BeatmapInfo);

var parsedScore = new ProcessorScoreDecoder(working).Parse(scoreInfo);
var parsedScore = new ProcessorScoreDecoder(working).Parse(scoreInfo);

var difficultyCalculator = rulesetInstance.CreateDifficultyCalculator(working);
var difficultyAttributes = difficultyCalculator.Calculate(mods);
var performanceCalculator = rulesetInstance.CreatePerformanceCalculator();
if (performanceCalculator == null)
continue;
var difficultyCalculator = rulesetInstance.CreateDifficultyCalculator(working);
var difficultyAttributes = difficultyCalculator.Calculate(mods);
var performanceCalculator = rulesetInstance.CreatePerformanceCalculator();
if (performanceCalculator == null)
continue;

var perfAttributes = performanceCalculator.Calculate(parsedScore.ScoreInfo, difficultyAttributes);
extendedScore = new ExtendedScore(score, difficultyAttributes, perfAttributes);
}

var perfAttributes = performanceCalculator.Calculate(parsedScore.ScoreInfo, difficultyAttributes);
Schedule(() =>
{
var scoreContainer = new ScoreContainer(new ExtendedScore(score, difficultyAttributes, perfAttributes));
var scoreContainer = new ScoreContainer(scoreId, extendedScore);
scoreContainer.OnDelete += onScoreRemove;

scoresList.Add(scoreContainer);
Expand Down Expand Up @@ -388,7 +393,7 @@ private void updateSorting(CollectionSortCriteria sortCriteria)
{
for (int i = 0; i < scoresList.Count; i++)
{
scoresList.SetLayoutPosition(scoresList[i], Array.IndexOf(currentCollection.Value!.Scores, scoresList[i].Score.SoloScore.ID));
scoresList.SetLayoutPosition(scoresList[i], Array.IndexOf(currentCollection.Value!.Scores, scoresList[i].ScoreId));
}

return;
Expand All @@ -399,15 +404,15 @@ private void updateSorting(CollectionSortCriteria sortCriteria)
switch (sortCriteria)
{
case CollectionSortCriteria.Live:
sortedScores = scoresList.Children.OrderByDescending(x => x.Score.LivePP).ToArray();
sortedScores = scoresList.Children.OrderByDescending(x => x.Score?.LivePP).ToArray();
break;

case CollectionSortCriteria.Local:
sortedScores = scoresList.Children.OrderByDescending(x => x.Score.PerformanceAttributes?.Total).ToArray();
sortedScores = scoresList.Children.OrderByDescending(x => x.Score?.PerformanceAttributes?.Total).ToArray();
break;

case CollectionSortCriteria.Difference:
sortedScores = scoresList.Children.OrderByDescending(x => x.Score.PerformanceAttributes?.Total - x.Score.LivePP).ToArray();
sortedScores = scoresList.Children.OrderByDescending(x => x.Score?.PerformanceAttributes?.Total - x.Score?.LivePP).ToArray();
break;

default:
Expand Down
Loading