scoresaber-reloadedv3/src/common/song-utils.ts

50 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-09-13 15:38:45 +00:00
const diffColors: Record<string, string> = {
2024-09-14 11:18:12 +00:00
easy: "#3CB371",
normal: "#59b0f4",
2024-09-14 11:18:12 +00:00
hard: "#FF6347",
expert: "#bf2a42",
2024-09-14 11:18:12 +00:00
expertplus: "#8f48db",
};
const badgesDef: {
name: string;
min: number | null;
max: number | null;
color: string;
}[] = [
{ name: "SS+", min: 95, max: null, color: diffColors.expertPlus },
{ name: "SS", min: 90, max: 95, color: diffColors.expert },
{ name: "S+", min: 85, max: 90, color: diffColors.hard },
{ name: "S", min: 80, max: 85, color: diffColors.normal },
{ name: "A", min: 70, max: 80, color: diffColors.easy },
{ name: "-", min: null, max: 70, color: "hsl(var(--accent))" },
];
2024-09-11 22:10:16 +00:00
/**
2024-09-11 23:35:54 +00:00
* Turns the difficulty of a song into a color
2024-09-11 22:10:16 +00:00
*
2024-09-11 23:35:54 +00:00
* @param diff the difficulty to get the color for
* @returns the color for the difficulty
2024-09-11 22:10:16 +00:00
*/
2024-09-11 23:35:54 +00:00
export function songDifficultyToColor(diff: string) {
diff = diff.replace("+", "Plus");
return diffColors[diff.toLowerCase() as keyof typeof diffColors];
}
/**
* Formats the accuracy into a color
*
* @param acc the accuracy to get the color for
*/
export function accuracyToColor(acc: number): string {
for (const badge of badgesDef) {
if (
(badge.min === null || acc >= badge.min) &&
(badge.max === null || acc < badge.max)
) {
return badge.color;
}
2024-09-11 22:10:16 +00:00
}
2024-09-13 15:38:45 +00:00
return "#000000"; // fallback color
2024-09-11 22:10:16 +00:00
}