Skip to content
Open
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
94 changes: 62 additions & 32 deletions PerformanceCalculatorGUI/Components/ExtendedProfileScore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Leaderboards;
using osu.Game.Overlays;
using osu.Game.Overlays.Profile.Sections;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Difficulty;
using osu.Game.Rulesets.Mods;

Check failure on line 28 in PerformanceCalculatorGUI/Components/ExtendedProfileScore.cs

View workflow job for this annotation

GitHub Actions / Code Quality

Using directive is not required by the code and can be safely removed in PerformanceCalculatorGUI\Components\ExtendedProfileScore.cs on line 28
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.UI;
using osu.Game.Scoring;
using osu.Game.Users.Drawables;
using osu.Game.Utils;
using osuTK;
Expand All @@ -36,7 +39,7 @@
{
public class ExtendedScore
{
public SoloScoreInfo SoloScore { get; }
public IScoreInfo Score { get; }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just ScoreInfo? The only reason this is using SoloScoreInfo now is because the data is always sourced from the API so it was convenient, but we convert it to ScoreInfo anyway to run pp calculation

public double? LivePP { get; }

public Bindable<int> Position { get; } = new Bindable<int>();
Expand All @@ -45,13 +48,40 @@
public PerformanceAttributes? PerformanceAttributes { get; }
public DifficultyAttributes DifficultyAttributes { get; }

public ExtendedScore(SoloScoreInfo score, DifficultyAttributes difficultyAttributes, PerformanceAttributes? performanceAttributes)
public ExtendedScore(IScoreInfo score, DifficultyAttributes difficultyAttributes, PerformanceAttributes? performanceAttributes)
{
SoloScore = score;
Score = score;
PerformanceAttributes = performanceAttributes;
DifficultyAttributes = difficultyAttributes;
LivePP = score.PP;
}

// IScoreInfo is missing statistics right now, but both SoloScoreInfo and ScoreInfo have it (and I believe it's planned for future)
// I think handling conversion at this level is the most elegant, although it means supporting any additional types that inherit from IScoreInfo will need to be manually added here
public Dictionary<HitResult, int>? Statistics

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just awful

{
get
{
if (Score is SoloScoreInfo soloScore)
return soloScore.Statistics;
if (Score is ScoreInfo scoreInfo)
return scoreInfo.Statistics;
return null;

Check failure on line 69 in PerformanceCalculatorGUI/Components/ExtendedProfileScore.cs

View workflow job for this annotation

GitHub Actions / Code Quality

Separate control transfer statement with empty line in PerformanceCalculatorGUI\Components\ExtendedProfileScore.cs on line 69
}
}
// Exists for largely the same reasoning as Statistics, except rather than a missing field it's because APIMod doesn't inherit from IMod at all

Check failure on line 72 in PerformanceCalculatorGUI/Components/ExtendedProfileScore.cs

View workflow job for this annotation

GitHub Actions / Code Quality

Blank lines are missing, expected minimum 1 instead of 0 in PerformanceCalculatorGUI\Components\ExtendedProfileScore.cs on line 72
// This returns APIMod[]? instead of Mod[]? because it means ruleset handling isn't necessary
public APIMod[]? Mods
{
get
{
if (Score is ScoreInfo scoreInfo)
return scoreInfo.Mods.Select(m => new APIMod(m)).ToArray();
if (Score is SoloScoreInfo soloScoreInfo)
return soloScoreInfo.Mods;
return null;

Check failure on line 82 in PerformanceCalculatorGUI/Components/ExtendedProfileScore.cs

View workflow job for this annotation

GitHub Actions / Code Quality

Separate control transfer statement with empty line in PerformanceCalculatorGUI\Components\ExtendedProfileScore.cs on line 82
}
}
}

public partial class ExtendedProfileItemContainer : ProfileItemContainer
Expand Down Expand Up @@ -88,7 +118,7 @@

private const float performance_background_shear = 0.45f;

public readonly ExtendedScore Score;
public readonly ExtendedScore ExtScore;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public readonly ExtendedScore ExtScore;
public readonly ExtendedScore ExtendedScore;


public readonly bool ShowAvatar;

Expand All @@ -102,7 +132,7 @@

public ExtendedProfileScore(ExtendedScore score, bool showAvatar = false)
{
Score = score;
ExtScore = score;
ShowAvatar = showAvatar;

RelativeSizeAxes = Axes.X;
Expand All @@ -114,27 +144,27 @@
{
int avatarPadding = ShowAvatar ? avatar_size : 0;
int rankDifferenceWidth = ShowAvatar ? 8 : rank_difference_width;
var scoreRuleset = rulesets.GetRuleset(Score.SoloScore.RulesetID)?.CreateInstance() ?? throw new InvalidOperationException();
var scoreRuleset = rulesets.GetRuleset(ExtScore.Score.Ruleset.OnlineID)?.CreateInstance() ?? throw new InvalidOperationException();

AddInternal(new ExtendedProfileItemContainer
{
OnHoverAction = () =>
{
positionChangeText.Text = $"#{Score.Position.Value}";
positionChangeText.Text = $"#{ExtScore.Position.Value}";
},
OnUnhoverAction = () =>
{
positionChangeText.Text = $"{Score.PositionChange.Value:+0;-0;-}";
positionChangeText.Text = $"{ExtScore.PositionChange.Value:+0;-0;-}";
},
Children = new[]
{
ShowAvatar
? new ClickableAvatar(Score.SoloScore.User, true)
? new ClickableAvatar((APIUser)ExtScore.Score.User, true)
{
Masking = true,
CornerRadius = ExtendedLabelledTextBox.CORNER_RADIUS,
Size = new Vector2(avatar_size),
Action = () => { host.OpenUrlExternally($"https://osu.ppy.sh/users/{Score.SoloScore.User?.Id}"); }
Action = () => { host.OpenUrlExternally($"https://osu.ppy.sh/users/{ExtScore.Score.User?.OnlineID}"); }

Check failure on line 167 in PerformanceCalculatorGUI/Components/ExtendedProfileScore.cs

View workflow job for this annotation

GitHub Actions / Code Quality

Conditional access qualifier expression is never null according to nullable reference types' annotations in PerformanceCalculatorGUI\Components\ExtendedProfileScore.cs on line 167
}
: Empty(),
new Container
Expand All @@ -151,7 +181,7 @@
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Colour = colourProvider.Light1,
Text = $"{Score.PositionChange.Value:+0;-0;-}"
Text = $"{ExtScore.PositionChange.Value:+0;-0;-}"
}
},
new Container
Expand Down Expand Up @@ -180,13 +210,13 @@
Padding = new MarginPadding { Top = 2 },
Children = new Drawable[]
{
new UpdateableRank(Score.SoloScore.Rank)
new UpdateableRank(ExtScore.Score.Rank)
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Size = new Vector2(40, 12),
},
new TinyStarRatingDisplay(Score.DifficultyAttributes)
new TinyStarRatingDisplay(ExtScore.DifficultyAttributes)
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Expand All @@ -202,7 +232,7 @@
Spacing = new Vector2(0, 0.5f),
Children = new Drawable[]
{
new ScoreBeatmapMetadataContainer(Score.SoloScore.Beatmap),
new ScoreBeatmapMetadataContainer(ExtScore.Score.Beatmap),
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Expand All @@ -212,11 +242,11 @@
{
new OsuSpriteText
{
Text = $"{Score.SoloScore.Beatmap?.DifficultyName}",
Text = $"{ExtScore.Score.Beatmap?.DifficultyName}",
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Regular),
Colour = colours.Yellow
},
new DrawableDate(Score.SoloScore.EndedAt, 12)
new DrawableDate(ExtScore.Score.Date, 12)
{
Colour = colourProvider.Foreground1
}
Expand Down Expand Up @@ -268,7 +298,7 @@
{
new OsuSpriteText
{
Text = Score.SoloScore.Accuracy.FormatAccuracy(),
Text = ExtScore.Score.Accuracy.FormatAccuracy(),
Font = OsuFont.GetFont(weight: FontWeight.Bold, italics: true),
Colour = colours.Yellow,
Anchor = Anchor.TopCentre,
Expand All @@ -285,7 +315,7 @@
formatCombo(),
new OsuSpriteText
{
Text = $"{{ {formatStatistics(Score.SoloScore.Statistics, scoreRuleset)} }}",
Text = $"{{ {formatStatistics(ExtScore.Statistics, scoreRuleset)} }}",

Check failure on line 318 in PerformanceCalculatorGUI/Components/ExtendedProfileScore.cs

View workflow job for this annotation

GitHub Actions / Code Quality

Possible null reference argument for parameter 'statistics' in 'PerformanceCalculatorGUI.Components.ExtendedProfileScore.formatStatistics' in PerformanceCalculatorGUI\Components\ExtendedProfileScore.cs on line 318
Font = OsuFont.GetFont(size: small_text_font_size, weight: FontWeight.Regular),
Colour = colourProvider.Light2,
Anchor = Anchor.TopCentre,
Expand All @@ -310,7 +340,7 @@
Child = new OsuSpriteText
{
Font = OsuFont.GetFont(weight: FontWeight.Bold),
Text = Score.LivePP != null ? $"{Score.LivePP:0}pp" : "- pp"
Text = ExtScore.LivePP != null ? $"{ExtScore.LivePP:0}pp" : "- pp"
},
},
new OsuSpriteText
Expand All @@ -332,7 +362,7 @@
Origin = Anchor.CentreRight,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(2),
Children = Score.SoloScore.Mods.Select(mod => new ModIcon(mod.ToMod(scoreRuleset))
Children = ExtScore.Mods.Select(mod => new ModIcon(mod.ToMod(scoreRuleset))

Check failure on line 365 in PerformanceCalculatorGUI/Components/ExtendedProfileScore.cs

View workflow job for this annotation

GitHub Actions / Code Quality

Possible null reference argument for parameter 'source' in 'System.Linq.Enumerable.Select<TSource,TResult>' in PerformanceCalculatorGUI\Components\ExtendedProfileScore.cs on line 365
{
Scale = new Vector2(0.35f)
}).ToList(),
Expand Down Expand Up @@ -372,27 +402,27 @@
Shear = new Vector2(performance_background_shear, 0),
EdgeSmoothness = new Vector2(2, 0),
},
new ScorePerformanceContainer(Score)
new ScorePerformanceContainer(ExtScore)
}
}
}
});

Score.PositionChange.BindValueChanged(v => { positionChangeText.Text = $"{v.NewValue:+0;-0;-}"; });
ExtScore.PositionChange.BindValueChanged(v => { positionChangeText.Text = $"{v.NewValue:+0;-0;-}"; });
}

private OsuSpriteText formatCombo()
{
bool isFullCombo = Score.SoloScore.MaxCombo == Score.DifficultyAttributes.MaxCombo;
bool isFullCombo = ExtScore.Score.MaxCombo == ExtScore.DifficultyAttributes.MaxCombo;

return new ExtendedOsuSpriteText
{
Text = $"{Score.SoloScore.MaxCombo}x",
Text = $"{ExtScore.Score.MaxCombo}x",
Font = OsuFont.GetFont(size: small_text_font_size, weight: FontWeight.Regular),
Colour = isFullCombo ? colours.GreenLight : colourProvider.Light2,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
TooltipContent = $"{Score.SoloScore.MaxCombo} / {Score.DifficultyAttributes.MaxCombo}x"
TooltipContent = $"{ExtScore.Score.MaxCombo} / {ExtScore.DifficultyAttributes.MaxCombo}x"
};
}

Expand Down Expand Up @@ -471,14 +501,14 @@

private partial class ScorePerformanceContainer : OsuHoverContainer
{
private readonly ExtendedScore score;
private readonly ExtendedScore extScore;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private readonly ExtendedScore extScore;
private readonly ExtendedScore extendedScore;


[Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!;

public ScorePerformanceContainer(ExtendedScore score)
{
this.score = score;
this.extScore = score;

Check failure on line 511 in PerformanceCalculatorGUI/Components/ExtendedProfileScore.cs

View workflow job for this annotation

GitHub Actions / Code Quality

Qualifier 'this.' is redundant in PerformanceCalculatorGUI\Components\ExtendedProfileScore.cs on line 511
RelativeSizeAxes = Axes.Both;
Padding = new MarginPadding
{
Expand All @@ -493,7 +523,7 @@
{
Action = () =>
{
sceneManager.SwitchToSimulate(score.SoloScore.BeatmapID, score.SoloScore.ID);
sceneManager.SwitchToSimulate(extScore.Score.Beatmap.OnlineID, (ulong?)extScore.Score.OnlineID);

Check failure on line 526 in PerformanceCalculatorGUI/Components/ExtendedProfileScore.cs

View workflow job for this annotation

GitHub Actions / Code Quality

Dereference of a possibly null reference in PerformanceCalculatorGUI\Components\ExtendedProfileScore.cs on line 526
};

Child = new FillFlowContainer
Expand All @@ -507,16 +537,16 @@
new ExtendedOsuSpriteText
{
Font = OsuFont.GetFont(weight: FontWeight.Bold),
Text = $"{score.PerformanceAttributes?.Total:0}pp",
Text = $"{extScore.PerformanceAttributes?.Total:0}pp",
Colour = colourProvider.Highlight1,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
TooltipContent = $"{AttributeConversion.ToReadableString(score.PerformanceAttributes)}"
TooltipContent = $"{AttributeConversion.ToReadableString(extScore.PerformanceAttributes)}"
},
new OsuSpriteText
{
Font = OsuFont.GetFont(size: small_text_font_size),
Text = $"{score.PerformanceAttributes?.Total - score.LivePP:+0.0;-0.0;-}",
Text = $"{extScore.PerformanceAttributes?.Total - extScore.LivePP:+0.0;-0.0;-}",
Colour = getPpDifferenceColor(),
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre
Expand All @@ -527,7 +557,7 @@

private Color4 getPpDifferenceColor()
{
double difference = score.PerformanceAttributes?.Total - score.LivePP ?? 0;
double difference = extScore.PerformanceAttributes?.Total - extScore.LivePP ?? 0;
var baseColor = colourProvider.Light1;

return difference switch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{
public partial class ScoreContainer : Container
{
public ExtendedScore Score { get; }
public ExtendedScore ExtScore { get; }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public ExtendedScore ExtScore { get; }
public ExtendedScore ExtendedScore { get; }


private readonly IconButton deleteButton;

Expand All @@ -25,7 +25,7 @@
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;

Score = score;
ExtScore = score;
Child = new GridContainer
{
RelativeSizeAxes = Axes.X,
Expand All @@ -43,7 +43,7 @@
Icon = FontAwesome.Regular.TrashAlt,
Action = () =>
{
OnDelete?.Invoke((long)score.SoloScore.ID!);
OnDelete?.Invoke(ExtScore.Score.OnlineID!);

Check failure on line 46 in PerformanceCalculatorGUI/Screens/Collections/ScoreContainer.cs

View workflow job for this annotation

GitHub Actions / Code Quality

The nullable warning suppression expression is redundant in PerformanceCalculatorGUI\Screens\Collections\ScoreContainer.cs on line 46
}
},
new ExtendedProfileScore(score, true)
Expand Down
8 changes: 4 additions & 4 deletions PerformanceCalculatorGUI/Screens/CollectionsScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,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].ExtScore.Score.OnlineID));
}

return;
Expand All @@ -399,15 +399,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.ExtScore.LivePP).ToArray();
break;

case CollectionSortCriteria.Local:
sortedScores = scoresList.Children.OrderByDescending(x => x.Score.PerformanceAttributes?.Total).ToArray();
sortedScores = scoresList.Children.OrderByDescending(x => x.ExtScore.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.ExtScore.PerformanceAttributes?.Total - x.ExtScore.LivePP).ToArray();
break;

default:
Expand Down
Loading