add acc ranges to the score (eg: A, S, SS, etc)
All checks were successful
Deploy / deploy (push) Successful in 5m19s

This commit is contained in:
Lee 2024-09-30 12:51:22 +01:00
parent bb5506148c
commit 442e52d22d
6 changed files with 43 additions and 16 deletions

@ -4,7 +4,11 @@ import * as Sentry from "@sentry/nextjs";
import NextError from "next/error"; import NextError from "next/error";
import { useEffect } from "react"; import { useEffect } from "react";
export default function GlobalError({ error }: { error: Error & { digest?: string } }) { export default function GlobalError({
error,
}: {
error: Error & { digest?: string };
}) {
useEffect(() => { useEffect(() => {
Sentry.captureException(error); Sentry.captureException(error);
}, [error]); }, [error]);

@ -28,7 +28,7 @@ const scoreBadges: ScoreBadge[] = [
* @param acc - The accuracy for the score * @param acc - The accuracy for the score
* @returns The corresponding color for the accuracy. * @returns The corresponding color for the accuracy.
*/ */
export function getScoreColorFromAccuracy(acc: number): ScoreBadge { export function getScoreBadgeFromAccuracy(acc: number): ScoreBadge {
// Check for SS+ first since it has no upper limit // Check for SS+ first since it has no upper limit
if (acc >= 95) { if (acc >= 95) {
return scoreBadges[0]; // SS+ color return scoreBadges[0]; // SS+ color

@ -1,10 +1,11 @@
import ScoreSaberLeaderboardToken from "@/common/model/token/scoresaber/score-saber-leaderboard-token"; import ScoreSaberLeaderboardToken from "@/common/model/token/scoresaber/score-saber-leaderboard-token";
import ScoreSaberScoreToken from "@/common/model/token/scoresaber/score-saber-score-token"; import ScoreSaberScoreToken from "@/common/model/token/scoresaber/score-saber-score-token";
import { formatNumberWithCommas, formatPp } from "@/common/number-utils"; import { formatNumberWithCommas, formatPp } from "@/common/number-utils";
import { getScoreColorFromAccuracy } from "@/common/song-utils"; import { getScoreBadgeFromAccuracy } from "@/common/song-utils";
import StatValue from "@/components/stat-value"; import StatValue from "@/components/stat-value";
import { XMarkIcon } from "@heroicons/react/24/solid"; import { XMarkIcon } from "@heroicons/react/24/solid";
import clsx from "clsx"; import clsx from "clsx";
import Tooltip from "@/components/tooltip";
type Badge = { type Badge = {
name: string; name: string;
@ -39,14 +40,36 @@ const badges: Badge[] = [
leaderboard: ScoreSaberLeaderboardToken, leaderboard: ScoreSaberLeaderboardToken,
) => { ) => {
const acc = (score.baseScore / leaderboard.maxScore) * 100; const acc = (score.baseScore / leaderboard.maxScore) * 100;
return getScoreColorFromAccuracy(acc).color; return getScoreBadgeFromAccuracy(acc).color;
}, },
create: ( create: (
score: ScoreSaberScoreToken, score: ScoreSaberScoreToken,
leaderboard: ScoreSaberLeaderboardToken, leaderboard: ScoreSaberLeaderboardToken,
) => { ) => {
const acc = (score.baseScore / leaderboard.maxScore) * 100; const acc = (score.baseScore / leaderboard.maxScore) * 100;
return `${acc.toFixed(2)}%`; const scoreBadge = getScoreBadgeFromAccuracy(acc);
let accDetails = `Accuracy ${scoreBadge.name != "-" ? scoreBadge.name : ""}`;
if (scoreBadge.max == null) {
accDetails += ` (> ${scoreBadge.min}%)`;
} else if (scoreBadge.min == null) {
accDetails += ` (< ${scoreBadge.max}%)`;
} else {
accDetails += ` (${scoreBadge.min}% - ${scoreBadge.max}%)`;
}
return (
<>
<Tooltip
display={
<div>
<p>{accDetails}</p>
</div>
}
>
<p className="cursor-default">{acc.toFixed(2)}%</p>
</Tooltip>
</>
);
}, },
}, },
{ {

@ -1,12 +1,12 @@
import * as Sentry from '@sentry/nextjs'; import * as Sentry from "@sentry/nextjs";
export async function register() { export async function register() {
if (process.env.NEXT_RUNTIME === 'nodejs') { if (process.env.NEXT_RUNTIME === "nodejs") {
await import('../sentry.server.config'); await import("../sentry.server.config");
} }
if (process.env.NEXT_RUNTIME === 'edge') { if (process.env.NEXT_RUNTIME === "edge") {
await import('../sentry.edge.config'); await import("../sentry.edge.config");
} }
} }