make score difficulty random

This commit is contained in:
Rainnny7 2024-10-29 16:25:57 -04:00
parent 8814b9881e
commit 5774f51b06
2 changed files with 16 additions and 8 deletions

@ -1,6 +1,6 @@
import { MapDifficulty } from "@ssr/common/score/map-difficulty"; import { MapDifficulty } from "@ssr/common/score/map-difficulty";
type Difficulty = { export type Difficulty = {
/** /**
* The name of the difficulty * The name of the difficulty
*/ */
@ -63,14 +63,21 @@ export function getScoreBadgeFromAccuracy(acc: number): ScoreBadge {
return scoreBadges[scoreBadges.length - 1]; 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 * Gets a {@link Difficulty} from its name
* *
* @param diff the name of the difficulty * @param diff the name of the difficulty
* @returns the difficulty * @returns the difficulty
*/ */
export function getDifficulty(diff: MapDifficulty) { export function getDifficulty(diff: Difficulty | MapDifficulty) {
const difficulty = difficulties.find(d => d.name === diff); const difficulty = difficulties.find(d => d.name === (typeof diff === "string" ? diff : diff.name));
if (!difficulty) { if (!difficulty) {
throw new Error(`Unknown difficulty: ${diff}`); throw new Error(`Unknown difficulty: ${diff}`);
} }

@ -1,7 +1,7 @@
import { Database } from "lucide-react"; import { Database } from "lucide-react";
import { getRandomInteger } from "@/common/utils"; import { getRandomInteger } from "@/common/utils";
import { GlobeAmericasIcon } from "@heroicons/react/24/solid"; 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"; import { AnimatedList } from "@/components/ui/animated-list";
type ScoreProps = { type ScoreProps = {
@ -28,7 +28,7 @@ let scores: ScoreProps[] = [
songArt: "https://cdn.scoresaber.com/covers/8E4B7917C01E5987A5B3FF13FAA3CA8F27D21D34.png", songArt: "https://cdn.scoresaber.com/covers/8E4B7917C01E5987A5B3FF13FAA3CA8F27D21D34.png",
songName: "RATATA", songName: "RATATA",
songAuthor: "Skrillex, Missy Elliot & Mr. Oizo", songAuthor: "Skrillex, Missy Elliot & Mr. Oizo",
setBy: "Minion", setBy: "Rainnny",
}, },
{ {
songArt: "https://cdn.scoresaber.com/covers/98F73BD330852EAAEBDC695140EAC8F2027AEEC8.png", songArt: "https://cdn.scoresaber.com/covers/98F73BD330852EAAEBDC695140EAC8F2027AEEC8.png",
@ -63,7 +63,7 @@ export default function RealtimeScores() {
{/* Content */} {/* Content */}
<div className="w-full flex flex-col justify-center items-center"> <div className="w-full flex flex-col justify-center items-center">
<AnimatedList className="w-full max-w-[32rem] h-96 divide-y divide-muted overflow-hidden"> <AnimatedList className="w-full max-w-[32rem] h-96 divide-y divide-muted overflow-hidden" delay={1500}>
{scores.map((score, index) => ( {scores.map((score, index) => (
<Score key={index} {...score} /> <Score key={index} {...score} />
))} ))}
@ -74,6 +74,7 @@ export default function RealtimeScores() {
} }
function Score({ songArt, songName, songAuthor, setBy }: ScoreProps) { function Score({ songArt, songName, songAuthor, setBy }: ScoreProps) {
const difficulty: Difficulty = getRandomDifficulty();
return ( return (
<figure className="py-2 flex flex-col text-sm"> <figure className="py-2 flex flex-col text-sm">
{/* Set By */} {/* Set By */}
@ -98,10 +99,10 @@ function Score({ songArt, songName, songAuthor, setBy }: ScoreProps) {
<div <div
className="absolute inset-x-0 bottom-0 py-px flex justify-center text-xs rounded-t-lg" className="absolute inset-x-0 bottom-0 py-px flex justify-center text-xs rounded-t-lg"
style={{ style={{
backgroundColor: getDifficulty("Hard").color + "f0", // Transparency value (in hex 0-255) backgroundColor: getDifficulty(difficulty).color + "f0", // Transparency value (in hex 0-255)
}} }}
> >
Hard {difficulty.name}
</div> </div>
</div> </div>