Skip to content

Commit

Permalink
feat: add support for BeatLeader
Browse files Browse the repository at this point in the history
  • Loading branch information
motzel committed Jul 12, 2022
1 parent 3772fec commit 54dbbcc
Show file tree
Hide file tree
Showing 7 changed files with 732 additions and 147 deletions.
8 changes: 8 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
force = true
headers = {X-From = "Netlify"}

[[redirects]]
from = "/cors/beatleader/*"
to = "https://api.beatleader.xyz/:splat"
status = 200
force = true
headers = {X-From = "Netlify"}


[[redirects]]
from = '/build/*'
to = '/build/:splat'
Expand Down
25 changes: 20 additions & 5 deletions src/components/PpCalc.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@
import Badge from './Badge.svelte'
import {debounce} from '../utils/debounce'
import {formatNumber} from '../utils/format'
import {accFromPpFactor, calcPpBoundary, getWhatIfScore, PP_PER_STAR, ppFactorFromAcc} from '../utils/pp'
import {
accFromPpFactor,
calcPpBoundary,
getPpFromAccAndStars,
getWhatIfScore,
PP_PER_STAR,
ppFactorFromAcc,
} from '../utils/pp'
import Value from './Value.svelte'
export let scores = null;
export let service = 'scoresaber';
const DEBOUNCE_THRESHOLD = 300;
const ACC_THRESHOLDS = [92, 93, 94, 95, 96, 97, 98, 99];
Expand Down Expand Up @@ -35,18 +43,22 @@
}
async function calcPpFromStars(stars, acc) {
const newRawPpFromStars = PP_PER_STAR * stars * ppFactorFromAcc(acc);
const newRawPpFromStars = getPpFromAccAndStars(acc, stars, service);
const whatIf = getWhatIfScore(scores, -1, newRawPpFromStars)?.diff ?? null;
if (whatIf && !isNaN(whatIf)) ppValue = whatIf;
}
function getStarsForAcc(rawPp, acc) {
return rawPp / PP_PER_STAR / ppFactorFromAcc(acc);
return service === 'beatleader'
? rawPp / PP_PER_STAR / acc * 100
: rawPp / PP_PER_STAR / ppFactorFromAcc(acc);
}
function getAccForStars(rawPp, stars) {
return accFromPpFactor(rawPp / PP_PER_STAR / stars);
return service === 'beatleader'
? rawPp / PP_PER_STAR / stars * 100
: accFromPpFactor(rawPp / PP_PER_STAR / stars);
}
function calcStarsAndAccFromRawPp(rawPp) {
Expand All @@ -68,7 +80,10 @@
ppValue = 1;
accuracy = DEFAULT_ACC;
const whatIf = getWhatIfScore(scores, -1, PP_PER_STAR * maxStars * ppFactorFromAcc(100));
const whatIf = getWhatIfScore(
scores, -1,
getPpFromAccAndStars(100, maxStars, service),
);
if (whatIf) maxPp = whatIf.diff;
}
Expand Down
9 changes: 5 additions & 4 deletions src/components/Scores.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<script>
import Pager from './Pager.svelte'
import SongScore from './SongScore.svelte'
import {PP_PER_STAR, ppFactorFromAcc} from '../utils/pp'
import {getPpFromAccAndStars} from '../utils/pp'
export let scores = null;
export let modifiedPercentage = {};
export let service = 'scoresaber';
const ITEMS_PER_PAGE = 8;
Expand All @@ -25,16 +26,16 @@
const maxScore = leaderboard?.maxScore ?? 0;
const stars = leaderboard?.stars ?? 0;
const basePp = score?.pp ?? 0;
const basePercentage = (score?.modifiedScore ?? 0) / maxScore * 100;
const basePercentage = maxScore ? (score?.modifiedScore ?? 0) / maxScore * 100 : score?.percentage;
let pp = basePp;
let percentage = basePercentage;
if (modifiedPercentage[leaderboard?.id]) {
percentage = modifiedPercentage[leaderboard.id].percentage;
pp = PP_PER_STAR * stars * ppFactorFromAcc(percentage);
pp = getPpFromAccAndStars(percentage, stars, service);
}
return maxScore
return basePercentage
? {
leaderboard,
score: {
Expand Down
Loading

0 comments on commit 54dbbcc

Please sign in to comment.