From af8c87f5afc114b899bd245e401248ba9f7eb37a Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 21 Oct 2024 13:39:02 +0100 Subject: [PATCH] add player role badge --- .../common/src/player/impl/scoresaber-player.ts | 10 ++-------- projects/common/src/utils/scoresaber.util.ts | 2 +- .../website/src/components/player/player-stats.tsx | 14 ++++++++++++-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/projects/common/src/player/impl/scoresaber-player.ts b/projects/common/src/player/impl/scoresaber-player.ts index 067486d..1ea3cd9 100644 --- a/projects/common/src/player/impl/scoresaber-player.ts +++ b/projects/common/src/player/impl/scoresaber-player.ts @@ -29,7 +29,7 @@ export default interface ScoreSaberPlayer extends Player { /** * The role the player has. */ - role: ScoreSaberRole | undefined; + role: string | undefined; /** * The badges the player has. @@ -87,7 +87,6 @@ export async function getScoreSaberPlayerFromToken( lines: token.bio?.split("\n") || [], linesStripped: token.bio?.replace(/<[^>]+>/g, "")?.split("\n") || [], }; - const role = token.role == null ? undefined : (token.role as ScoreSaberRole); const badges: ScoreSaberBadge[] = token.badges?.map(badge => { return { @@ -269,7 +268,7 @@ export async function getScoreSaberPlayerFromToken( monthly: getStatisticChanges(30), yearly: getStatisticChanges(365), }, - role: role, + role: token.role == null ? undefined : token.role, badges: badges, statisticHistory: statisticHistory, statistics: token.scoreStats, @@ -299,11 +298,6 @@ export type ScoreSaberBio = { linesStripped: string[]; }; -/** - * The ScoreSaber account roles. - */ -export type ScoreSaberRole = "Admin"; - /** * A badge for a player. */ diff --git a/projects/common/src/utils/scoresaber.util.ts b/projects/common/src/utils/scoresaber.util.ts index c45c55a..8b135ab 100644 --- a/projects/common/src/utils/scoresaber.util.ts +++ b/projects/common/src/utils/scoresaber.util.ts @@ -2,7 +2,7 @@ import ScoreSaberPlayerToken from "../types/token/scoresaber/score-saber-player- import ScoreSaberLeaderboardPlayerInfoToken from "../types/token/scoresaber/score-saber-leaderboard-player-info-token"; import ScoreSaberPlayer from "../player/impl/scoresaber-player"; -type ScoreSaberRole = { +export type ScoreSaberRole = { /** * The name of the role. */ diff --git a/projects/website/src/components/player/player-stats.tsx b/projects/website/src/components/player/player-stats.tsx index 8124e74..7658e35 100644 --- a/projects/website/src/components/player/player-stats.tsx +++ b/projects/website/src/components/player/player-stats.tsx @@ -4,9 +4,9 @@ import ScoreSaberPlayer from "@ssr/common/player/impl/scoresaber-player"; import { formatDate } from "@ssr/common/utils/time-utils"; import { ReactNode } from "react"; import Tooltip from "@/components/tooltip"; -import { getPlayerHistoryToday } from "@ssr/common/utils/player-utils"; import { DailyChange } from "@/components/statistic/daily-change"; import { PlayerStat } from "@ssr/common/player/player-stat"; +import { getScoreSaberRole } from "@ssr/common/scoresaber.util"; type Stat = { name: string; @@ -92,6 +92,16 @@ const playerStats: Stat[] = [ }; }, }, + { + name: "Role", + create: (player: ScoreSaberPlayer) => { + const role = getScoreSaberRole(player); + + return { + value: role?.name, + }; + }, + }, ]; type Props = { @@ -103,7 +113,7 @@ export default function PlayerStats({ player }: Props) {
{playerStats.map((badge, index) => { const toRender = badge.create(player); - if (toRender === undefined) { + if (toRender === undefined || toRender.value === undefined) { return
; } const { tooltip, value } = toRender;