Skip to content

Commit

Permalink
Merge pull request #29512 from peppy/toolbar-pp-change-weird
Browse files Browse the repository at this point in the history
Fix toolbar PP change showing `+0` instead of `0`
  • Loading branch information
bdach authored Aug 22, 2024
2 parents df94c22 + 67f0ea5 commit a32a817
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
29 changes: 26 additions & 3 deletions osu.Game.Tests/Visual/Menus/TestSceneToolbarUserButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public void TestStates()
public void TestTransientUserStatisticsDisplay()
{
AddStep("Log in", () => dummyAPI.Login("wang", "jang"));

AddStep("Gain", () =>
{
var transientUpdateDisplay = this.ChildrenOfType<TransientUserStatisticsUpdateDisplay>().Single();
Expand All @@ -113,6 +114,7 @@ public void TestTransientUserStatisticsDisplay()
PP = 1357
});
});

AddStep("Loss", () =>
{
var transientUpdateDisplay = this.ChildrenOfType<TransientUserStatisticsUpdateDisplay>().Single();
Expand All @@ -129,22 +131,42 @@ public void TestTransientUserStatisticsDisplay()
PP = 1234
});
});
AddStep("No change", () =>

// Tests flooring logic works as expected.
AddStep("Tiny increase in PP", () =>
{
var transientUpdateDisplay = this.ChildrenOfType<TransientUserStatisticsUpdateDisplay>().Single();
transientUpdateDisplay.LatestUpdate.Value = new UserStatisticsUpdate(
new ScoreInfo(),
new UserStatistics
{
GlobalRank = 111_111,
PP = 1357
PP = 1357.6m
},
new UserStatistics
{
GlobalRank = 111_111,
PP = 1357
PP = 1358.1m
});
});

AddStep("No change 1", () =>
{
var transientUpdateDisplay = this.ChildrenOfType<TransientUserStatisticsUpdateDisplay>().Single();
transientUpdateDisplay.LatestUpdate.Value = new UserStatisticsUpdate(
new ScoreInfo(),
new UserStatistics
{
GlobalRank = 111_111,
PP = 1357m
},
new UserStatistics
{
GlobalRank = 111_111,
PP = 1357.1m
});
});

AddStep("Was null", () =>
{
var transientUpdateDisplay = this.ChildrenOfType<TransientUserStatisticsUpdateDisplay>().Single();
Expand All @@ -161,6 +183,7 @@ public void TestTransientUserStatisticsDisplay()
PP = 1357
});
});

AddStep("Became null", () =>
{
var transientUpdateDisplay = this.ChildrenOfType<TransientUserStatisticsUpdateDisplay>().Single();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public partial class TransientUserStatisticsUpdateDisplay : CompositeDrawable
public Bindable<UserStatisticsUpdate?> LatestUpdate { get; } = new Bindable<UserStatisticsUpdate?>();

private Statistic<int> globalRank = null!;
private Statistic<decimal> pp = null!;
private Statistic<int> pp = null!;

[BackgroundDependencyLoader]
private void load(UserStatisticsWatcher? userStatisticsWatcher)
Expand All @@ -43,7 +43,7 @@ private void load(UserStatisticsWatcher? userStatisticsWatcher)
Children = new Drawable[]
{
globalRank = new Statistic<int>(UsersStrings.ShowRankGlobalSimple, @"#", Comparer<int>.Create((before, after) => before - after)),
pp = new Statistic<decimal>(RankingsStrings.StatPerformance, string.Empty, Comparer<decimal>.Create((before, after) => Math.Sign(after - before))),
pp = new Statistic<int>(RankingsStrings.StatPerformance, string.Empty, Comparer<int>.Create((before, after) => Math.Sign(after - before))),
}
};

Expand Down Expand Up @@ -83,7 +83,7 @@ protected override void LoadComplete()
}

if (update.After.PP != null)
pp.Display(update.Before.PP ?? update.After.PP.Value, Math.Abs((update.After.PP - update.Before.PP) ?? 0M), update.After.PP.Value);
pp.Display((int)(update.Before.PP ?? update.After.PP.Value), (int)Math.Abs(((int?)update.After.PP - (int?)update.Before.PP) ?? 0M), (int)update.After.PP.Value);

this.Delay(5000).FadeOut(500, Easing.OutQuint);
});
Expand Down

0 comments on commit a32a817

Please sign in to comment.