import Image from "next/image"; import { useSettingsStore } from "../store/overlaySettingsStore"; import { useSongDataStore } from "../store/songDataStore"; import styles from "../styles/songInfo.module.css"; /** * Format the given ms * * @param {Number} millis * @returns The formatted time */ function msToMinSeconds(millis) { const minutes = Math.floor(millis / 60000); const seconds = Number(((millis % 60000) / 1000).toFixed(0)); return seconds === 60 ? minutes + 1 + ":00" : minutes + ":" + (seconds < 10 ? "0" : "") + seconds; } /** * Update the difficulity color from the given difficulity * * @param {string} diff */ function formatDiff(diff) { if (diff === "ExpertPlus") { return "#8f48db"; } if (diff === "Expert") { return "#bf2a42"; } if (diff === "Hard") { return "tomato"; } if (diff === "Normal") { return "#59b0f4"; } if (diff === "Easy") { return "MediumSeaGreen"; } } export default function SongInfo() { const [showSongInfo, shouldReplacePlayerInfoWithScore, songTimeHex] = useSettingsStore((store) => [ store.showSongInfo, store.shouldReplacePlayerInfoWithScore, store.songTimeHex, ]); const [ isLoading, bsr, mapArt, songTitle, songSubTitle, songDifficulty, currentSongTime, songLength, paused, ] = useSongDataStore((store) => [ store.isLoading, store.bsr, store.mapArt, store.songTitle, store.songSubTitle, store.songDifficulty, store.currentSongTime, store.songLength, store.paused, ]); if (!showSongInfo) { return null; } if (isLoading) { return null; } const songTimerPercentage = (currentSongTime / songLength) * 100000; const diffColor = formatDiff(songDifficulty); return (
{songTitle.length > 35 ? songTitle.substring(0, 35) + "..." : songTitle}
{songSubTitle}
{songDifficulty.replace("Plus", "+")}
!bsr {bsr}
{msToMinSeconds(currentSongTime * 1000)}/{msToMinSeconds(songLength)}