2022-10-26 21:33:36 +00:00
|
|
|
import Image from "next/future/image";
|
2022-10-28 18:52:47 +00:00
|
|
|
import { useSettingsStore } from "../store/overlaySettingsStore";
|
|
|
|
import { useSongDataStore } from "../store/songDataStore";
|
2022-02-16 18:44:01 +00:00
|
|
|
|
2022-10-23 20:47:57 +00:00
|
|
|
import styles from "../styles/songInfo.module.css";
|
2022-10-10 12:14:25 +00:00
|
|
|
|
2022-10-28 18:52:47 +00:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
2022-02-17 02:25:43 +00:00
|
|
|
|
2022-10-28 18:52:47 +00:00
|
|
|
/**
|
|
|
|
* Update the difficulity color from the given difficulity
|
|
|
|
*
|
|
|
|
* @param {string} diff
|
|
|
|
*/
|
|
|
|
function formatDiff(diff) {
|
|
|
|
if (diff === "ExpertPlus") {
|
|
|
|
return "#8f48db";
|
2022-10-14 19:00:47 +00:00
|
|
|
}
|
2022-10-28 18:52:47 +00:00
|
|
|
if (diff === "Expert") {
|
|
|
|
return "#bf2a42";
|
|
|
|
}
|
|
|
|
if (diff === "Hard") {
|
|
|
|
return "tomato";
|
|
|
|
}
|
|
|
|
if (diff === "Normal") {
|
|
|
|
return "#59b0f4";
|
|
|
|
}
|
|
|
|
if (diff === "Easy") {
|
|
|
|
return "MediumSeaGreen";
|
2022-10-14 19:00:47 +00:00
|
|
|
}
|
2022-10-28 18:52:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default function SongInfo() {
|
|
|
|
const [showSongInfo, shouldReplacePlayerInfoWithScore] = useSettingsStore(
|
|
|
|
(store) => [store.showSongInfo, store.shouldReplacePlayerInfoWithScore]
|
|
|
|
);
|
|
|
|
const [
|
|
|
|
isLoading,
|
|
|
|
bsr,
|
|
|
|
mapArt,
|
|
|
|
songTitle,
|
|
|
|
songSubTitle,
|
|
|
|
songDifficulty,
|
|
|
|
currentSongTime,
|
|
|
|
songLength,
|
|
|
|
] = useSongDataStore((store) => [
|
|
|
|
store.isLoading,
|
|
|
|
store.bsr,
|
|
|
|
store.mapArt,
|
|
|
|
store.songTitle,
|
|
|
|
store.songSubTitle,
|
|
|
|
store.songDifficulty,
|
|
|
|
store.currentSongTime,
|
|
|
|
store.songLength,
|
|
|
|
]);
|
2022-02-17 02:25:43 +00:00
|
|
|
|
2022-10-28 18:52:47 +00:00
|
|
|
if (!showSongInfo) {
|
|
|
|
return null;
|
2022-10-14 19:00:47 +00:00
|
|
|
}
|
2022-02-16 18:44:01 +00:00
|
|
|
|
2022-10-28 18:52:47 +00:00
|
|
|
if (isLoading) {
|
|
|
|
return null;
|
|
|
|
}
|
2022-02-16 18:44:01 +00:00
|
|
|
|
2022-10-28 18:52:47 +00:00
|
|
|
const songTimerPercentage = (currentSongTime / songLength) * 100000;
|
|
|
|
const diffColor = formatDiff(songDifficulty);
|
2022-10-27 18:40:19 +00:00
|
|
|
|
2022-10-28 18:52:47 +00:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={styles.songInfoContainer}
|
|
|
|
style={{
|
|
|
|
bottom: shouldReplacePlayerInfoWithScore ? "" : 0,
|
|
|
|
left: shouldReplacePlayerInfoWithScore ? "" : 0,
|
2022-10-29 14:37:59 +00:00
|
|
|
position: shouldReplacePlayerInfoWithScore ? "" : "fixed",
|
2022-10-28 18:52:47 +00:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Image
|
|
|
|
width={150}
|
|
|
|
height={150}
|
|
|
|
alt="Song artwork"
|
|
|
|
src={mapArt}
|
|
|
|
loading="lazy"
|
|
|
|
placeholder="blur"
|
|
|
|
blurDataURL="https://cdn.fascinated.cc/IkQFyodbZv.jpg?raw=true"
|
|
|
|
/>
|
|
|
|
<div className={styles.songInfo}>
|
|
|
|
<p className={styles.songInfoSongName}>
|
|
|
|
{songTitle.length > 35
|
|
|
|
? songTitle.substring(0, 35) + "..."
|
|
|
|
: songTitle}
|
|
|
|
</p>
|
|
|
|
<p className={styles.songInfoSongSubName}>{songSubTitle}</p>
|
|
|
|
<div className={styles.songInfoSongOtherContainer}>
|
|
|
|
<p
|
|
|
|
className={styles.songInfoDiff}
|
|
|
|
style={{ backgroundColor: diffColor }}
|
|
|
|
>
|
|
|
|
{songDifficulty.replace("Plus", "+")}
|
2022-10-14 19:00:47 +00:00
|
|
|
</p>
|
2022-10-28 18:52:47 +00:00
|
|
|
<p className={styles.songInfoBsr}>!bsr {bsr}</p>
|
|
|
|
</div>
|
|
|
|
<p className={styles.songTimeText}>
|
|
|
|
{msToMinSeconds(currentSongTime * 1000)}/{msToMinSeconds(songLength)}
|
|
|
|
</p>
|
|
|
|
<div className={styles.songTimeContainer}>
|
|
|
|
<div className={styles.songTimeBackground} />
|
|
|
|
<div
|
|
|
|
className={styles.songTime}
|
|
|
|
style={{ width: songTimerPercentage + "%" }}
|
|
|
|
/>
|
2022-10-14 19:00:47 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-10-28 18:52:47 +00:00
|
|
|
</div>
|
|
|
|
);
|
2022-10-14 19:00:47 +00:00
|
|
|
}
|