From 4b11a63f46a1a50ba71360f50e8e94247d22fd80 Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 28 Sep 2024 07:59:49 +0100 Subject: [PATCH] allow for negative pp change --- src/common/model/player/impl/scoresaber-player.ts | 15 +++++++++------ src/components/player/player-header.tsx | 13 ++++++++----- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/common/model/player/impl/scoresaber-player.ts b/src/common/model/player/impl/scoresaber-player.ts index d498ce4..2006ff8 100644 --- a/src/common/model/player/impl/scoresaber-player.ts +++ b/src/common/model/player/impl/scoresaber-player.ts @@ -24,9 +24,9 @@ export default interface ScoreSaberPlayer extends Player { pp: number; /** - * The amount of pp gained compared to yesterday. + * The change in pp compared to yesterday. */ - ppGain: number; + ppChange: number; /** * The role the player has. @@ -127,9 +127,12 @@ export async function getScoreSaberPlayerFromToken( const yesterdayDate = formatDateMinimal( getMidnightAlignedDate(getDaysAgoDate(1)), ); - const ppGain = - (statisticHistory[yesterdayDate]?.pp || 0) - - (statisticHistory[todayDate]?.pp || 0); + const todayStats = statisticHistory[todayDate]; + const yesterdayStats = statisticHistory[yesterdayDate]; + + // Calculate the pp change + const ppChange = + todayStats.pp && todayStats.pp ? todayStats.pp - (todayStats.pp + 10) : 0; return { id: token.id, @@ -141,7 +144,7 @@ export async function getScoreSaberPlayerFromToken( joinedDate: new Date(token.firstSeen), bio: bio, pp: token.pp, - ppGain: ppGain < 0 ? 0 : ppGain, + ppChange: ppChange, role: role, badges: badges, statisticHistory: statisticHistory, diff --git a/src/components/player/player-header.tsx b/src/components/player/player-header.tsx index 65868f1..5567f50 100644 --- a/src/components/player/player-header.tsx +++ b/src/components/player/player-header.tsx @@ -33,11 +33,14 @@ const playerData = [ return (

{formatPp(player.pp)}pp

- {player.ppGain > 0 && ( - The amount of PP you have gained today

}> - +{player.ppGain}pp -
- )} + The change in your pp compared to yesterday

}> +

0 ? "text-green-400" : "text-red-400"}`} + > + {player.ppChange > 0 ? "+" : ""} + {formatPp(player.ppChange)}pp +

+
); },