move score page fetching to the backend
This commit is contained in:
1
projects/common/src/score/difficulty.ts
Normal file
1
projects/common/src/score/difficulty.ts
Normal file
@ -0,0 +1 @@
|
||||
export type Difficulty = "Easy" | "Normal" | "Hard" | "Expert" | "Expert+" | "Unknown";
|
62
projects/common/src/score/impl/scoresaber-score.ts
Normal file
62
projects/common/src/score/impl/scoresaber-score.ts
Normal file
@ -0,0 +1,62 @@
|
||||
import Score from "../score";
|
||||
import { Modifier } from "../modifier";
|
||||
import ScoreSaberScoreToken from "../../types/token/scoresaber/score-saber-score-token";
|
||||
import ScoreSaberLeaderboardPlayerInfoToken from "../../types/token/scoresaber/score-saber-leaderboard-player-info-token";
|
||||
|
||||
export default interface ScoreSaberScore extends Score {
|
||||
/**
|
||||
* The score's id.
|
||||
*/
|
||||
readonly id: string;
|
||||
|
||||
/**
|
||||
* The amount of pp for the score.
|
||||
* @private
|
||||
*/
|
||||
readonly pp: number;
|
||||
|
||||
/**
|
||||
* The weight of the score, or undefined if not ranked.s
|
||||
* @private
|
||||
*/
|
||||
readonly weight?: number;
|
||||
|
||||
/**
|
||||
* The player who set the score
|
||||
*/
|
||||
readonly playerInfo: ScoreSaberLeaderboardPlayerInfoToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a {@link ScoreSaberScore} from a {@link ScoreSaberScoreToken}.
|
||||
*
|
||||
* @param token the token to convert
|
||||
*/
|
||||
export function getScoreSaberScoreFromToken(token: ScoreSaberScoreToken): ScoreSaberScore {
|
||||
const modifiers: Modifier[] =
|
||||
token.modifiers == undefined || token.modifiers === ""
|
||||
? []
|
||||
: token.modifiers.split(",").map(mod => {
|
||||
mod = mod.toUpperCase();
|
||||
const modifier = Modifier[mod as keyof typeof Modifier];
|
||||
if (modifier === undefined) {
|
||||
throw new Error(`Unknown modifier: ${mod}`);
|
||||
}
|
||||
return modifier;
|
||||
});
|
||||
|
||||
return {
|
||||
leaderboard: "scoresaber",
|
||||
score: token.baseScore,
|
||||
rank: token.rank,
|
||||
modifiers: modifiers,
|
||||
misses: token.missedNotes,
|
||||
badCuts: token.badCuts,
|
||||
fullCombo: token.fullCombo,
|
||||
timestamp: new Date(token.timeSet),
|
||||
id: token.id,
|
||||
pp: token.pp,
|
||||
weight: token.weight,
|
||||
playerInfo: token.leaderboardPlayerInfo,
|
||||
};
|
||||
}
|
20
projects/common/src/score/modifier.ts
Normal file
20
projects/common/src/score/modifier.ts
Normal file
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* The score modifiers.
|
||||
*/
|
||||
export enum Modifier {
|
||||
DA = "Disappearing Arrows",
|
||||
FS = "Faster Song",
|
||||
SF = "Super Fast Song",
|
||||
SS = "Slower Song",
|
||||
GN = "Ghost Notes",
|
||||
NA = "No Arrows",
|
||||
NO = "No Obstacles",
|
||||
SA = "Strict Angles",
|
||||
SC = "Small Notes",
|
||||
PM = "Pro Mode",
|
||||
CS = "Fail on Saber Clash",
|
||||
IF = "One Life",
|
||||
BE = "Battery Energy",
|
||||
NF = "No Fail",
|
||||
NB = "No Bombs",
|
||||
}
|
6
projects/common/src/score/player-leaderboard-score.ts
Normal file
6
projects/common/src/score/player-leaderboard-score.ts
Normal file
@ -0,0 +1,6 @@
|
||||
export default interface PlayerLeaderboardScore<S> {
|
||||
/**
|
||||
* The score that was set.
|
||||
*/
|
||||
readonly score: S;
|
||||
}
|
18
projects/common/src/score/player-score.ts
Normal file
18
projects/common/src/score/player-score.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { BeatSaverMap } from "../model/beatsaver/beatsaver-map";
|
||||
|
||||
export interface PlayerScore<S, L> {
|
||||
/**
|
||||
* The score.
|
||||
*/
|
||||
readonly score: S;
|
||||
|
||||
/**
|
||||
* The leaderboard the score was set on.
|
||||
*/
|
||||
readonly leaderboard: L;
|
||||
|
||||
/**
|
||||
* The BeatSaver of the song.
|
||||
*/
|
||||
readonly beatSaver?: BeatSaverMap;
|
||||
}
|
4
projects/common/src/score/score-sort.ts
Normal file
4
projects/common/src/score/score-sort.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export enum ScoreSort {
|
||||
top = "top",
|
||||
recent = "recent",
|
||||
}
|
51
projects/common/src/score/score.ts
Normal file
51
projects/common/src/score/score.ts
Normal file
@ -0,0 +1,51 @@
|
||||
import { Modifier } from "./modifier";
|
||||
import { Leaderboards } from "../leaderboard";
|
||||
|
||||
export default interface Score {
|
||||
/**
|
||||
* The leaderboard the score is from.
|
||||
*/
|
||||
readonly leaderboard: Leaderboards;
|
||||
|
||||
/**
|
||||
* The base score for the score.
|
||||
* @private
|
||||
*/
|
||||
readonly score: number;
|
||||
|
||||
/**
|
||||
* The rank for the score.
|
||||
* @private
|
||||
*/
|
||||
readonly rank: number;
|
||||
|
||||
/**
|
||||
* The modifiers used on the score.
|
||||
* @private
|
||||
*/
|
||||
readonly modifiers: Modifier[];
|
||||
|
||||
/**
|
||||
* The amount missed notes.
|
||||
* @private
|
||||
*/
|
||||
readonly misses: number;
|
||||
|
||||
/**
|
||||
* The amount of bad cuts.
|
||||
* @private
|
||||
*/
|
||||
readonly badCuts: number;
|
||||
|
||||
/**
|
||||
* Whether every note was hit.
|
||||
* @private
|
||||
*/
|
||||
readonly fullCombo: boolean;
|
||||
|
||||
/**
|
||||
* The time the score was set.
|
||||
* @private
|
||||
*/
|
||||
readonly timestamp: Date;
|
||||
}
|
Reference in New Issue
Block a user