Skip to content

Commit

Permalink
update what score submission returns and show pr value
Browse files Browse the repository at this point in the history
  • Loading branch information
flustix committed Jul 17, 2024
1 parent 6978591 commit 87527ea
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 52 deletions.
4 changes: 3 additions & 1 deletion fluXis.Game.Tests/Results/TestNewResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using fluXis.Game.Screens;
using fluXis.Game.Screens.Result;
using fluXis.Shared.API.Responses.Scores;
using fluXis.Shared.Components.Scores;
using fluXis.Shared.Components.Users;
using fluXis.Shared.Scoring;
using fluXis.Shared.Scoring.Enums;
Expand All @@ -29,6 +30,7 @@ private void load(MapStore maps)
{
Accuracy = 98.661736f,
Rank = ScoreRank.S,
PerformanceRating = 8,
Score = 1139289,
MaxCombo = 1218,
Flawless = 898,
Expand Down Expand Up @@ -66,7 +68,7 @@ private class SimulatedScoreRequest : ScoreSubmitRequest
public SimulatedScoreRequest(ScoreInfo score)
: base(score)
{
Response = new APIResponse<ScoreSubmissionStats>(200, "", new ScoreSubmissionStats(0, 10, 10, 1, 2, 2, 1));
Response = new APIResponse<ScoreSubmissionStats>(200, "", new ScoreSubmissionStats(new APIScore { PerformanceRating = 7 }, 10, 10, 1, 12, 10, 2));
}
}
}
7 changes: 4 additions & 3 deletions fluXis.Game.Tests/Results/TestResultsRating.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using fluXis.Game.Online.API;
using fluXis.Game.Screens.Result.UI;
using fluXis.Shared.API.Responses.Scores;
using fluXis.Shared.Components.Scores;
using osu.Framework.Allocation;

namespace fluXis.Game.Tests.Results;
Expand All @@ -13,9 +14,9 @@ private void load()
var ratingInfo = new ResultsRatingInfo(true);
Child = ratingInfo;

AddStep("Unchanged", () => ratingInfo.ScoreResponse = new APIResponse<ScoreSubmissionStats>(200, "", new ScoreSubmissionStats(0, 10, 10, 1, 0, 0, 0)));
AddStep("Higher", () => ratingInfo.ScoreResponse = new APIResponse<ScoreSubmissionStats>(200, "", new ScoreSubmissionStats(0, 10, 10, 1, 10, 10, 1)));
AddStep("Lower", () => ratingInfo.ScoreResponse = new APIResponse<ScoreSubmissionStats>(200, "", new ScoreSubmissionStats(0, 10, 10, 1, -10, -10, -1)));
AddStep("Unchanged", () => ratingInfo.ScoreResponse = new APIResponse<ScoreSubmissionStats>(200, "", new ScoreSubmissionStats(new APIScore(), 10, 10, 1, 10, 10, 1)));
AddStep("Higher", () => ratingInfo.ScoreResponse = new APIResponse<ScoreSubmissionStats>(200, "", new ScoreSubmissionStats(new APIScore(), 10, 10, 2, 20, 20, 1)));
AddStep("Lower", () => ratingInfo.ScoreResponse = new APIResponse<ScoreSubmissionStats>(200, "", new ScoreSubmissionStats(new APIScore(), 10, 10, 1, 5, 5, 2)));
AddStep("Error", () => ratingInfo.ScoreResponse = new APIResponse<ScoreSubmissionStats>(500, "Something went wrong.", null));
}
}
9 changes: 6 additions & 3 deletions fluXis.Game/Screens/Gameplay/GameplayScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
using fluXis.Game.Skinning.Default;
using fluXis.Game.Storyboards;
using fluXis.Game.Storyboards.Drawables;
using fluXis.Shared.Replays;
using fluXis.Shared.Scoring.Enums;
using fluXis.Shared.Utils;
using osu.Framework.Allocation;
Expand Down Expand Up @@ -492,12 +493,14 @@ protected virtual void End()
screen.SubmitRequest = request;
api.PerformRequest(request);
if (request.IsSuccessful && request.Response?.Data?.ID > 0)
var resData = request.Response?.Data;
if (request.IsSuccessful && resData?.Score != null)
{
realm.RunWrite(r =>
{
var rScore = r.Find<RealmScore>(scoreId);
rScore.OnlineID = (int)request.Response.Data.ID;
rScore.OnlineID = (int)resData.Score.ID;
});
}
Expand All @@ -513,7 +516,7 @@ protected virtual void End()
});
}

protected Shared.Replays.Replay SaveReplay(Guid scoreID)
protected Replay SaveReplay(Guid scoreID)
{
try
{
Expand Down
43 changes: 25 additions & 18 deletions fluXis.Game/Screens/Result/Normal/NormalResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using fluXis.Game.Screens.Result.UI;
using fluXis.Game.Skinning;
using fluXis.Game.Utils;
using fluXis.Shared.API.Responses.Scores;
using fluXis.Shared.Components.Users;
using fluXis.Shared.Scoring;
using fluXis.Shared.Scoring.Enums;
Expand Down Expand Up @@ -305,7 +306,7 @@ private void load()
new Entry
{
Title = "Performance Rating",
Value = score.PerformanceRating > 0 ? $"{score.PerformanceRating.ToStringInvariant("00.00")}pr" : "--.--pr"
Value = getPerfRatingStr()
},
new Entry
{
Expand Down Expand Up @@ -530,14 +531,9 @@ private void updateStats()

if (res.Success)
{
ptrStat.Value = res.Data.PotentialRating;
ptrStat.Difference = res.Data.PotentialRatingChange;

ovrStat.Value = res.Data.OverallRating;
ovrStat.Difference = res.Data.OverallRatingChange;

rankStat.Value = res.Data.Rank;
rankStat.Difference = res.Data.RankChange;
ovrStat.StatChange = res.Data.OverallRating;
ptrStat.StatChange = res.Data.PotentialRating;
rankStat.StatChange = res.Data.Rank;

onlineStats.FadeIn(200);
}
Expand All @@ -554,6 +550,19 @@ private void updateStats()
}
}

private string getPerfRatingStr()
{
var sc = results.SubmitRequest?.Response?.Data?.Score;
var value = 0d;

if (sc is { PerformanceRating: > 0 })
value = sc.PerformanceRating;
else if (score.PerformanceRating > 0)
value = score.PerformanceRating;

return value > 0 ? $"{value.ToStringInvariant("00.00")}pr" : "--.--pr";
}

private Drawable getGradient(Colour4 color, bool right)
{
var gradient = ColourInfo.GradientHorizontal(right ? color.Opacity(0) : color, right ? color : color.Opacity(0));
Expand Down Expand Up @@ -686,27 +695,25 @@ private partial class OnlineStatistic : FillFlowContainer
public string Title { get; init; } = "Title";
public bool DisplayAsRank { get; init; }

public double Value
{
set => valueText.Text = DisplayAsRank ? $"#{value}" : value.ToStringInvariant("00.00");
}

public double Difference
public ScoreSubmissionStats.StatisticChange StatChange
{
set
{
var diff = value.Current - value.Previous;
valueText.Text = DisplayAsRank ? $"#{(int)value.Current}" : value.Current.ToStringInvariant("00.00");

var negativeColor = Colour4.FromHex("#FF5555");
var positiveColor = Colour4.FromHex("#55FF55");

switch (value)
switch (diff)
{
case > 0:
differenceText.Text = DisplayAsRank ? $"+{value}" : $"+{value.ToStringInvariant("00.00")}";
differenceText.Text = DisplayAsRank ? $"+{diff}" : $"+{diff.ToStringInvariant("00.00")}";
differenceText.Colour = DisplayAsRank ? negativeColor : positiveColor;
break;

case < 0:
differenceText.Text = DisplayAsRank ? $"{value}" : $"{value.ToStringInvariant("00.00")}";
differenceText.Text = DisplayAsRank ? $"{diff}" : $"{diff.ToStringInvariant("00.00")}";
differenceText.Colour = DisplayAsRank ? positiveColor : negativeColor;
break;

Expand Down
9 changes: 4 additions & 5 deletions fluXis.Game/Screens/Result/UI/ResultsRatingInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using fluXis.Game.Graphics.UserInterface;
using fluXis.Game.Graphics.UserInterface.Color;
using fluXis.Game.Online.API;
using fluXis.Game.Utils;
using fluXis.Shared.API.Responses.Scores;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
Expand Down Expand Up @@ -33,7 +32,7 @@ public APIResponse<ScoreSubmissionStats> ScoreResponse
return;
}
var ovrc = value.Data.OverallRatingChange;
/*var ovrc = value.Data.OverallRatingChange;
var pvrc = value.Data.PotentialRatingChange;
ovr.Text = value.Data.OverallRating.ToStringInvariant();
Expand All @@ -55,9 +54,9 @@ public APIResponse<ScoreSubmissionStats> ScoreResponse
ovrChange.Colour = FluXisColors.Text2;
ovrChange.Text = "SAME";
break;
}
}*/
switch (pvrc)
/*switch (pvrc)
{
case > 0:
pvrChange.Colour = Colour4.FromHex("#55FF55");
Expand All @@ -73,7 +72,7 @@ public APIResponse<ScoreSubmissionStats> ScoreResponse
pvrChange.Colour = FluXisColors.Text2;
pvrChange.Text = "KEEP";
break;
}
}*/
ratingContainer.FadeIn(200);
});
Expand Down
54 changes: 32 additions & 22 deletions fluXis.Shared/API/Responses/Scores/ScoreSubmissionStats.cs
Original file line number Diff line number Diff line change
@@ -1,45 +1,55 @@
using fluXis.Shared.Components.Scores;
using fluXis.Shared.Utils;
using Newtonsoft.Json;

namespace fluXis.Shared.API.Responses.Scores;

public class ScoreSubmissionStats
{
[JsonProperty("id")]
public long ID { get; set; }
[JsonProperty("score")]
public APIScore Score { get; init; } = null!;

[JsonProperty("ovr")]
public double OverallRating { get; init; }
public StatisticChange OverallRating { get; init; } = null!;

[JsonProperty("ptr")]
public double PotentialRating { get; init; }
public StatisticChange PotentialRating { get; init; } = null!;

[JsonProperty("rank")]
public int Rank { get; init; }
public StatisticChange Rank { get; init; } = null!;

[JsonProperty("ovrChange")]
public double OverallRatingChange { get; init; }

[JsonProperty("ptrChange")]
public double PotentialRatingChange { get; init; }

[JsonProperty("rankChange")]
public int RankChange { get; init; }

public ScoreSubmissionStats(long id, double overallRating, double potentialRating, int rank, double overallRatingChange, double potentialRatingChange, int rankChange)
public ScoreSubmissionStats(APIScore score, double prevOvr, double prevPtr, int prevRank, double curOvr, double curPtr, int curRank)
{
ID = id;
OverallRating = overallRating;
PotentialRating = potentialRating;
Rank = rank;
OverallRatingChange = overallRatingChange;
PotentialRatingChange = potentialRatingChange;
RankChange = rankChange;
Score = score;
OverallRating = new StatisticChange(prevOvr, curOvr);
PotentialRating = new StatisticChange(prevPtr, curPtr);
Rank = new StatisticChange(prevRank, curRank);
}

[JsonConstructor]
[Obsolete(JsonUtils.JSON_CONSTRUCTOR_ERROR, true)]
public ScoreSubmissionStats()
{
}

public class StatisticChange
{
[JsonProperty("prev")]
public double Previous { get; init; }

[JsonProperty("now")]
public double Current { get; init; }

public StatisticChange(double prev, double cur)
{
Previous = prev;
Current = cur;
}

[JsonConstructor]
[Obsolete(JsonUtils.JSON_CONSTRUCTOR_ERROR, true)]
public StatisticChange()
{
}
}
}

0 comments on commit 87527ea

Please sign in to comment.