2022-10-26 21:33:36 +00:00
|
|
|
import Image from "next/future/image";
|
2022-10-14 19:00:47 +00:00
|
|
|
import { Component } from "react";
|
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-02-16 18:44:01 +00:00
|
|
|
export default class SongInfo extends Component {
|
2022-10-14 19:00:47 +00:00
|
|
|
constructor(params) {
|
|
|
|
super(params);
|
|
|
|
this.state = {
|
|
|
|
diffColor: undefined,
|
|
|
|
};
|
|
|
|
}
|
2022-02-17 02:25:43 +00:00
|
|
|
|
2022-10-14 19:00:47 +00:00
|
|
|
componentDidMount() {
|
|
|
|
const data = this.props.data.songData.status.beatmap;
|
|
|
|
this.formatDiff(data.difficulty);
|
|
|
|
}
|
2022-02-17 02:25:43 +00:00
|
|
|
|
2022-10-14 19:00:47 +00:00
|
|
|
/**
|
|
|
|
* Update the difficulity color from the given difficulity
|
|
|
|
*
|
|
|
|
* @param {string} diff
|
|
|
|
*/
|
|
|
|
formatDiff(diff) {
|
|
|
|
if (diff === "Expert+") {
|
|
|
|
this.setState({ diffColor: "#8f48db" });
|
|
|
|
}
|
|
|
|
if (diff === "Expert") {
|
|
|
|
this.setState({ diffColor: "#bf2a42" });
|
|
|
|
}
|
|
|
|
if (diff === "Hard") {
|
|
|
|
this.setState({ diffColor: "tomato" });
|
|
|
|
}
|
|
|
|
if (diff === "Normal") {
|
|
|
|
this.setState({ diffColor: "#59b0f4" });
|
|
|
|
}
|
|
|
|
if (diff === "Easy") {
|
|
|
|
this.setState({ diffColor: "MediumSeaGreen" });
|
|
|
|
}
|
|
|
|
}
|
2022-02-17 02:25:43 +00:00
|
|
|
|
2022-10-14 19:00:47 +00:00
|
|
|
/**
|
|
|
|
* Format the given ms
|
|
|
|
*
|
|
|
|
* @param {Number} millis
|
|
|
|
* @returns The formatted time
|
|
|
|
*/
|
|
|
|
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-16 18:44:01 +00:00
|
|
|
|
2022-10-14 19:00:47 +00:00
|
|
|
render() {
|
|
|
|
const data = this.props.data.songData.status.beatmap;
|
|
|
|
const beatSaverData = this.props.data.beatSaverData.data;
|
2022-10-22 11:28:46 +00:00
|
|
|
const mapArt = beatSaverData.mapArt;
|
2022-10-14 19:00:47 +00:00
|
|
|
const bsr = beatSaverData.bsr;
|
|
|
|
const { songName, songAuthorName, difficulty } = data;
|
|
|
|
const songTimerPercentage =
|
2022-10-22 11:34:14 +00:00
|
|
|
(this.props.data.currentSongTime / data.length) * 100000;
|
2022-02-16 18:44:01 +00:00
|
|
|
|
2022-10-27 18:40:19 +00:00
|
|
|
const cssVars = document.querySelector("." + styles.songInfoContainer);
|
|
|
|
if (cssVars) {
|
|
|
|
if (!this.props.data.isPlayerInfoVisible) {
|
|
|
|
cssVars.style.setProperty("margin-top", "5px");
|
|
|
|
cssVars.style.setProperty("--pos", "none");
|
|
|
|
} else {
|
|
|
|
cssVars.style.setProperty("margin-top", "0px");
|
|
|
|
cssVars.style.setProperty("--pos", 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-14 19:00:47 +00:00
|
|
|
return (
|
|
|
|
<div className={styles.songInfoContainer}>
|
2022-10-19 17:59:35 +00:00
|
|
|
<Image
|
2022-10-19 18:03:24 +00:00
|
|
|
width={150}
|
|
|
|
height={150}
|
2022-10-19 18:02:45 +00:00
|
|
|
alt="Song artwork"
|
2022-10-22 11:28:46 +00:00
|
|
|
src={mapArt}
|
2022-10-19 17:59:35 +00:00
|
|
|
loading="lazy"
|
|
|
|
placeholder="blur"
|
|
|
|
blurDataURL="https://cdn.fascinated.cc/IkQFyodbZv.jpg?raw=true"
|
|
|
|
/>
|
2022-10-14 19:00:47 +00:00
|
|
|
<div className={styles.songInfo}>
|
|
|
|
<p className={styles.songInfoSongName}>
|
|
|
|
{songName.length > 35
|
|
|
|
? songName.substring(0, 35) + "..."
|
|
|
|
: songName}
|
|
|
|
</p>
|
|
|
|
<p className={styles.songInfoSongAuthor}>{songAuthorName}</p>
|
|
|
|
<div className={styles.songInfoSongOtherContainer}>
|
|
|
|
<p
|
|
|
|
className={styles.songInfoDiff}
|
|
|
|
style={{ backgroundColor: this.state.diffColor }}
|
|
|
|
>
|
|
|
|
{difficulty}
|
|
|
|
</p>
|
|
|
|
<p className={styles.songInfoBsr}>!bsr {bsr}</p>
|
|
|
|
</div>
|
|
|
|
<p className={styles.songTimeText}>
|
|
|
|
{this.msToMinSeconds(this.props.data.currentSongTime * 1000)}/
|
|
|
|
{this.msToMinSeconds(data.length)}
|
|
|
|
</p>
|
|
|
|
<div className={styles.songTimeContainer}>
|
|
|
|
<div className={styles.songTimeBackground} />
|
|
|
|
<div
|
|
|
|
className={styles.songTime}
|
|
|
|
style={{ width: songTimerPercentage + "%" }}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|