From 5774f51b06e2f3c91f2712a344fcef73bc885506 Mon Sep 17 00:00:00 2001 From: Rainnny7 Date: Tue, 29 Oct 2024 16:25:57 -0400 Subject: [PATCH] make score difficulty random --- projects/website/src/common/song-utils.ts | 13 ++++++++++--- .../website/src/components/home/realtime-scores.tsx | 11 ++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/projects/website/src/common/song-utils.ts b/projects/website/src/common/song-utils.ts index da5d607..8bbd965 100644 --- a/projects/website/src/common/song-utils.ts +++ b/projects/website/src/common/song-utils.ts @@ -1,6 +1,6 @@ import { MapDifficulty } from "@ssr/common/score/map-difficulty"; -type Difficulty = { +export type Difficulty = { /** * The name of the difficulty */ @@ -63,14 +63,21 @@ export function getScoreBadgeFromAccuracy(acc: number): ScoreBadge { return scoreBadges[scoreBadges.length - 1]; } +/** + * Get a random difficulty, except ExpertPlus. + */ +export function getRandomDifficulty(): Difficulty { + return difficulties[Math.floor(Math.random() * (difficulties.length - 1))]; +} + /** * Gets a {@link Difficulty} from its name * * @param diff the name of the difficulty * @returns the difficulty */ -export function getDifficulty(diff: MapDifficulty) { - const difficulty = difficulties.find(d => d.name === diff); +export function getDifficulty(diff: Difficulty | MapDifficulty) { + const difficulty = difficulties.find(d => d.name === (typeof diff === "string" ? diff : diff.name)); if (!difficulty) { throw new Error(`Unknown difficulty: ${diff}`); } diff --git a/projects/website/src/components/home/realtime-scores.tsx b/projects/website/src/components/home/realtime-scores.tsx index 65c2e1b..8f2e448 100644 --- a/projects/website/src/components/home/realtime-scores.tsx +++ b/projects/website/src/components/home/realtime-scores.tsx @@ -1,7 +1,7 @@ import { Database } from "lucide-react"; import { getRandomInteger } from "@/common/utils"; import { GlobeAmericasIcon } from "@heroicons/react/24/solid"; -import { getDifficulty } from "@/common/song-utils"; +import { Difficulty, getDifficulty, getRandomDifficulty } from "@/common/song-utils"; import { AnimatedList } from "@/components/ui/animated-list"; type ScoreProps = { @@ -28,7 +28,7 @@ let scores: ScoreProps[] = [ songArt: "https://cdn.scoresaber.com/covers/8E4B7917C01E5987A5B3FF13FAA3CA8F27D21D34.png", songName: "RATATA", songAuthor: "Skrillex, Missy Elliot & Mr. Oizo", - setBy: "Minion", + setBy: "Rainnny", }, { songArt: "https://cdn.scoresaber.com/covers/98F73BD330852EAAEBDC695140EAC8F2027AEEC8.png", @@ -63,7 +63,7 @@ export default function RealtimeScores() { {/* Content */}
- + {scores.map((score, index) => ( ))} @@ -74,6 +74,7 @@ export default function RealtimeScores() { } function Score({ songArt, songName, songAuthor, setBy }: ScoreProps) { + const difficulty: Difficulty = getRandomDifficulty(); return (
{/* Set By */} @@ -98,10 +99,10 @@ function Score({ songArt, songName, songAuthor, setBy }: ScoreProps) {
- Hard + {difficulty.name}