From d2be3d833bdf9cca88630cdfa92440973f04d0c6 Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 19 Oct 2024 14:41:01 +0100 Subject: [PATCH] add role colors --- projects/common/src/scoresaber.util.ts | 101 ++++++++++++++++++ .../src/components/player/player-header.tsx | 10 +- .../website/src/components/table-player.tsx | 8 +- 3 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 projects/common/src/scoresaber.util.ts diff --git a/projects/common/src/scoresaber.util.ts b/projects/common/src/scoresaber.util.ts new file mode 100644 index 0000000..e729239 --- /dev/null +++ b/projects/common/src/scoresaber.util.ts @@ -0,0 +1,101 @@ +import ScoreSaberPlayerToken from "./types/token/scoresaber/score-saber-player-token"; +import ScoreSaberLeaderboardPlayerInfoToken from "./types/token/scoresaber/score-saber-leaderboard-player-info-token"; +import ScoreSaberPlayer from "./player/impl/scoresaber-player"; + +type ScoreSaberRole = { + /** + * The name of the role. + */ + name: string; + + /** + * The permissions for the role. + */ + permissions?: number; + + /** + * The role for this role. + */ + role?: string; + + /** + * The color of the role. + */ + color: string; +}; + +const scoreSaberPermission = { + RT: 1, + QAT: 2, + QATHead: 4, + NAT: 8, + ADMIN: 16, + PANDA: 32, + SUPPORTER: 64, + PPFARMER: 128, +}; + +export const scoreSaberRoles: ScoreSaberRole[] = [ + { + name: "Admin", + permissions: + scoreSaberPermission.RT | + scoreSaberPermission.QAT | + scoreSaberPermission.QATHead | + scoreSaberPermission.NAT | + scoreSaberPermission.ADMIN, + color: "#bfdcf9", + }, + { + name: "Head of Quality Assurance", + role: "Head of Quality Assurance", + permissions: scoreSaberPermission.QAT | scoreSaberPermission.QATHead, + color: "#ff006f", + }, + { + name: "Nomination Assessment Team", + role: "Nomination Assessment", + permissions: scoreSaberPermission.RT | scoreSaberPermission.NAT, + color: "#0b64f0", + }, + { + name: "Quality Assurance Team", + role: "Quality Assurance", + permissions: scoreSaberPermission.RT | scoreSaberPermission.NAT, + color: "#f70000", + }, + { + name: "Ranking Team", + role: "Ranking Team", + permissions: scoreSaberPermission.RT, + color: "#1abc9c", + }, + { + name: "Ranking Team Recruit", + role: "Recruit", + permissions: scoreSaberPermission.RT, + color: "#11806a", + }, + { + name: "Supporter", + role: "Supporter", + color: "#f96854", + }, +]; + +/** + * Gets the role for a player. + * + * @param player the player + * @returns the role + */ +export function getScoreSaberRole( + player: ScoreSaberPlayerToken | ScoreSaberLeaderboardPlayerInfoToken | ScoreSaberPlayer +): ScoreSaberRole | undefined { + const roles = player.role?.split(", ") || [player.role]; + for (const role of scoreSaberRoles) { + if (roles.includes(role.name)) { + return role; + } + } +} diff --git a/projects/website/src/components/player/player-header.tsx b/projects/website/src/components/player/player-header.tsx index 9f79997..55f2640 100644 --- a/projects/website/src/components/player/player-header.tsx +++ b/projects/website/src/components/player/player-header.tsx @@ -13,6 +13,7 @@ import Link from "next/link"; import { capitalizeFirstLetter } from "@/common/string-utils"; import AddFriend from "@/components/friend/add-friend"; import PlayerSteamProfile from "@/components/player/player-steam-profile"; +import { getScoreSaberRole } from "@ssr/common/scoresaber.util"; /** * Renders the change for a stat. @@ -176,7 +177,14 @@ export default function PlayerHeader({ player }: Props) {
-

{player.name}

+

+ {player.name} +

diff --git a/projects/website/src/components/table-player.tsx b/projects/website/src/components/table-player.tsx index 725db02..9f315b2 100644 --- a/projects/website/src/components/table-player.tsx +++ b/projects/website/src/components/table-player.tsx @@ -3,6 +3,7 @@ import CountryFlag from "@/components/country-flag"; import Link from "next/link"; import ScoreSaberPlayerToken from "@ssr/common/types/token/scoresaber/score-saber-player-token"; import ScoreSaberLeaderboardPlayerInfoToken from "@ssr/common/types/token/scoresaber/score-saber-leaderboard-player-info-token"; +import { getScoreSaberRole } from "@ssr/common/scoresaber.util"; type TablePlayerProps = { /** @@ -27,7 +28,12 @@ export function TablePlayer({ player, claimedPlayer }: TablePlayerProps) { -

+

{player.name}