From 8a4ec7d15372ebe5f2b55d546ac80002eb481872 Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 26 Oct 2023 17:37:35 +0100 Subject: [PATCH] add diff names to scores --- src/components/Avatar.tsx | 2 -- src/components/player/Score.tsx | 39 +++++++++++++++++++++++++-------- src/utils/songUtils.ts | 37 +++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 11 deletions(-) create mode 100644 src/utils/songUtils.ts diff --git a/src/components/Avatar.tsx b/src/components/Avatar.tsx index 131168c..38f777c 100644 --- a/src/components/Avatar.tsx +++ b/src/components/Avatar.tsx @@ -22,8 +22,6 @@ export default function Avatar({ src={url} width={size} height={size} - loading="lazy" - placeholder="blur" priority /> diff --git a/src/components/player/Score.tsx b/src/components/player/Score.tsx index a4a47a6..43b4553 100644 --- a/src/components/player/Score.tsx +++ b/src/components/player/Score.tsx @@ -2,6 +2,10 @@ import { ScoresaberLeaderboardInfo } from "@/schemas/scoresaber/leaderboard"; import { ScoresaberPlayer } from "@/schemas/scoresaber/player"; import { ScoresaberScore } from "@/schemas/scoresaber/score"; import { formatNumber } from "@/utils/number"; +import { + scoresaberDifficultyNumberToName, + songDifficultyToColor, +} from "@/utils/songUtils"; import { formatDate, formatTimeAgo } from "@/utils/timeUtils"; import { CheckIcon, @@ -20,6 +24,9 @@ type ScoreProps = { export default function Score({ score, player, leaderboard }: ScoreProps) { const isFullCombo = score.missedNotes + score.badCuts === 0; + const diffName = scoresaberDifficultyNumberToName( + leaderboard.difficulty.difficulty, + ); return (
@@ -37,15 +44,29 @@ export default function Score({ score, player, leaderboard }: ScoreProps) {
{/* Song Image */}
- {leaderboard.songName} +
+ {leaderboard.songName} +
+

+ {scoresaberDifficultyNumberToName( + leaderboard.difficulty.difficulty, + true, + )} +

+
+
{/* Song Info */}

{leaderboard.songName}

diff --git a/src/utils/songUtils.ts b/src/utils/songUtils.ts new file mode 100644 index 0000000..9aba8bc --- /dev/null +++ b/src/utils/songUtils.ts @@ -0,0 +1,37 @@ +export function songDifficultyToColor(diff: string) { + console.log(diff); + switch (diff.toLowerCase()) { + case "easy": + return "#3cb371"; + case "normal": + return "#59b0f4"; + case "hard": + return "#FF6347"; + case "expert": + return "#bf2a42"; + case "expert+": + return "#8f48db"; + default: + return "gray"; + } +} + +export function scoresaberDifficultyNumberToName( + diff: number, + shortened: boolean = false, +) { + switch (diff) { + case 1: + return !shortened ? "Easy" : "E"; + case 3: + return !shortened ? "Normal" : "N"; + case 5: + return !shortened ? "Hard" : "H"; + case 7: + return !shortened ? "Expert" : "Ex"; + case 9: + return !shortened ? "Expert+" : "Ex+"; + default: + return "unknown"; + } +}