Start work on adding BeatLeader support
This commit is contained in:
parent
b7d249aee5
commit
2b46c39747
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "BeatSaber Overlay",
|
"name": "BeatSaber Overlay",
|
||||||
"description": "A simple scoresaber overlay for OBS",
|
"title": "BeatSaber Overlay - Simple and easy to use BeatSaber overlay",
|
||||||
|
"description": "Free, simple, and easy to use beat saber overlay for OBS",
|
||||||
"color": "#0EBFE9",
|
"color": "#0EBFE9",
|
||||||
"url": "https://bs-overlay.fascinated.cc",
|
"url": "https://bs-overlay.fascinated.cc",
|
||||||
"proxy_url": "https://bangor375.herokuapp.com"
|
"proxy_url": "https://bangor375.herokuapp.com"
|
||||||
|
@ -12,7 +12,7 @@ function MyApp({ Component, pageProps }) {
|
|||||||
// 2. Use at the root of your app
|
// 2. Use at the root of your app
|
||||||
<NextUIProvider>
|
<NextUIProvider>
|
||||||
<Head>
|
<Head>
|
||||||
<title>{Config.name}</title>
|
<title>{Config.title}</title>
|
||||||
<meta name="twitter:title" content= {Config.name} />
|
<meta name="twitter:title" content= {Config.name} />
|
||||||
<meta property="og:site_name" content= {Config.name} key="title" />
|
<meta property="og:site_name" content= {Config.name} key="title" />
|
||||||
<meta property="og:url" content= {Config.url} key="title" />
|
<meta property="og:url" content= {Config.url} key="title" />
|
||||||
|
@ -8,6 +8,7 @@ import SongInfo from "../components/SongInfo";
|
|||||||
|
|
||||||
// Why do u have to proxy requests... it's so dumb LOL
|
// Why do u have to proxy requests... it's so dumb LOL
|
||||||
const SCORESABER_API_URL = Config.proxy_url + "/https://scoresaber.com/api/player/%s/full";
|
const SCORESABER_API_URL = Config.proxy_url + "/https://scoresaber.com/api/player/%s/full";
|
||||||
|
const BEATLEADER_API_URL = Config.proxy_url + "/https://api.beatleader.xyz/player/%s";
|
||||||
const GITHUB_URL = "https://github.com/RealFascinated/beatsaber-overlay";
|
const GITHUB_URL = "https://github.com/RealFascinated/beatsaber-overlay";
|
||||||
|
|
||||||
export default class Home extends Component {
|
export default class Home extends Component {
|
||||||
@ -20,7 +21,8 @@ export default class Home extends Component {
|
|||||||
this.state = {
|
this.state = {
|
||||||
loading: true,
|
loading: true,
|
||||||
id: undefined,
|
id: undefined,
|
||||||
isValidScoresaber: true,
|
isValidSteamId: true,
|
||||||
|
websiteType: "scoresaber",
|
||||||
data: undefined,
|
data: undefined,
|
||||||
showPlayerStats: true,
|
showPlayerStats: true,
|
||||||
showScore: false,
|
showScore: false,
|
||||||
@ -92,10 +94,15 @@ export default class Home extends Component {
|
|||||||
|
|
||||||
const id = params.id;
|
const id = params.id;
|
||||||
if (!id) { // Check if the id param is valid
|
if (!id) { // Check if the id param is valid
|
||||||
this.setState({ loading: false, isValidScoresaber: false });
|
this.setState({ loading: false, isValidSteamId: false });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if the player wants to disable their stats (pp, global pos, etc)
|
||||||
|
if (params.beatleader === 'true') {
|
||||||
|
this.setState({ websiteType: "beatleader" });
|
||||||
|
}
|
||||||
|
|
||||||
// Check if the player wants to disable their stats (pp, global pos, etc)
|
// Check if the player wants to disable their stats (pp, global pos, etc)
|
||||||
if (params.playerstats === 'false') {
|
if (params.playerstats === 'false') {
|
||||||
this.setState({ showPlayerStats: false });
|
this.setState({ showPlayerStats: false });
|
||||||
@ -121,30 +128,34 @@ export default class Home extends Component {
|
|||||||
|
|
||||||
await this.updateData(id);
|
await this.updateData(id);
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
if (!this.state.isValidScoresaber) {
|
if (!this.state.isValidSteamId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await this.updateData(id);
|
await this.updateData(id);
|
||||||
}, 30_000); // Update the scoresaber data every 30 seconds.
|
}, 30_000); // Update the player data every 30 seconds.
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch and update the data from ScoreSaber
|
* Fetch and update the data from the respective platform
|
||||||
*
|
*
|
||||||
* @param {string} id The scoresaber id of the player
|
* @param {string} id The steam id of the player
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
async updateData(id) {
|
async updateData(id) {
|
||||||
const data = await fetch(SCORESABER_API_URL.replace("%s", id), {
|
const data = await fetch(this.state.websiteType == "scoresaber" ? SCORESABER_API_URL.replace("%s", id) : BEATLEADER_API_URL.replace("%s", id), {
|
||||||
mode: 'cors'
|
mode: 'cors'
|
||||||
});
|
});
|
||||||
if (data.status === 422) { // Invalid scoresaber account (I think??)
|
if (this.state.websiteType == "scoresaber") {
|
||||||
this.setState({ loading: false, isValidScoresaber: false });
|
if (data.status === 422) { // Invalid steam account (I think??)
|
||||||
|
this.setState({ loading: false, isValidSteamId: false });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} else { // Assume BeatLeader
|
||||||
|
|
||||||
|
}
|
||||||
const json = await data.json();
|
const json = await data.json();
|
||||||
if (json.errorMessage) { // Invalid scoresaber account
|
if (json.errorMessage) { // Invalid steam account
|
||||||
this.setState({ loading: false, isValidScoresaber: false });
|
this.setState({ loading: false, isValidSteamId: false });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.setState({ loading: false, id: id, data: json });
|
this.setState({ loading: false, id: id, data: json });
|
||||||
@ -300,10 +311,10 @@ export default class Home extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { loading, isValidScoresaber, data } = this.state;
|
const { loading, isValidSteamId, data } = this.state;
|
||||||
|
|
||||||
// When in the main menu, show this colour so it's actually readable
|
// When in the main menu, show this colour so it's actually readable
|
||||||
if (!isValidScoresaber && !loading) {
|
if (!isValidSteamId && !loading) {
|
||||||
const body = document.body;
|
const body = document.body;
|
||||||
body.style.backgroundColor = "#181a1b";
|
body.style.backgroundColor = "#181a1b";
|
||||||
}
|
}
|
||||||
@ -313,14 +324,14 @@ export default class Home extends Component {
|
|||||||
<div className={'loading'}>
|
<div className={'loading'}>
|
||||||
<h2>Loading...</h2>
|
<h2>Loading...</h2>
|
||||||
</div>
|
</div>
|
||||||
: !isValidScoresaber ?
|
: !isValidSteamId ?
|
||||||
<div className={'invalid-player'}>
|
<div className={'invalid-player'}>
|
||||||
<h1>BeatSaber Overlay</h1>
|
<h1>BeatSaber Overlay</h1>
|
||||||
<div style={{ fontWeight: 'bold', marginBottom: '50px' }}>
|
<div style={{ fontWeight: 'bold', marginBottom: '50px' }}>
|
||||||
<p>This is currently just a simple overlay for OBS displaying ScoreSaber stats.</p>
|
<p>This is currently just a simple overlay for OBS displaying ScoreSaber or BeatLeader stats.</p>
|
||||||
<p>If you have any suggestions you can message me on discord @ Fascinated#4719</p>
|
<p>If you have any suggestions you can message me on discord @ Fascinated#4719</p>
|
||||||
</div>
|
</div>
|
||||||
<p>Provide a valid scoresaber id</p>
|
<p>Provide a valid steam id for scoresaber or beatleader</p>
|
||||||
<p>Example: {document.location.origin}?id=76561198449412074</p>
|
<p>Example: {document.location.origin}?id=76561198449412074</p>
|
||||||
<p>Example with Score Info: {document.location.origin}?id=76561198449412074&scoreinfo=true</p>
|
<p>Example with Score Info: {document.location.origin}?id=76561198449412074&scoreinfo=true</p>
|
||||||
<div className={'info'}>
|
<div className={'info'}>
|
||||||
|
Reference in New Issue
Block a user