mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-04 04:48:15 +03:00
86 lines
1.9 KiB
TypeScript
86 lines
1.9 KiB
TypeScript
import {
|
|
ChartDocument,
|
|
Game,
|
|
GoalDocument,
|
|
IDStrings,
|
|
integer,
|
|
UserDocument,
|
|
ScoreDocument,
|
|
SessionScoreInfo,
|
|
SongDocument,
|
|
} from "tachi-common";
|
|
|
|
export function GetPBs(scoreInfo: SessionScoreInfo[]) {
|
|
return scoreInfo.filter((e) => e.isNewScore === true || e.lampDelta > 0 || e.scoreDelta > 0);
|
|
}
|
|
|
|
export function CreateSongMap<G extends Game = Game>(songs: SongDocument<G>[]) {
|
|
const songMap = new Map<integer, SongDocument<G>>();
|
|
|
|
for (const song of songs) {
|
|
songMap.set(song.id, song);
|
|
}
|
|
|
|
return songMap;
|
|
}
|
|
|
|
export function CreateUserMap(users: UserDocument[]) {
|
|
const userMap = new Map<integer, UserDocument>();
|
|
|
|
for (const user of users) {
|
|
userMap.set(user.id, user);
|
|
}
|
|
|
|
return userMap;
|
|
}
|
|
|
|
export function CreateGoalMap(goals: GoalDocument[]) {
|
|
const goalMap = new Map<string, GoalDocument>();
|
|
|
|
for (const goal of goals) {
|
|
goalMap.set(goal.goalID, goal);
|
|
}
|
|
|
|
return goalMap;
|
|
}
|
|
|
|
export function CreateChartIDMap<T extends { chartID: string }>(arr: T[]): Map<string, T> {
|
|
const map = new Map();
|
|
|
|
for (const t of arr) {
|
|
map.set(t.chartID, t);
|
|
}
|
|
|
|
return map;
|
|
}
|
|
|
|
export function CreateChartMap<I extends IDStrings = IDStrings>(charts: ChartDocument<I>[]) {
|
|
const chartMap = new Map<string, ChartDocument<I>>();
|
|
|
|
for (const chart of charts) {
|
|
chartMap.set(chart.chartID, chart);
|
|
}
|
|
|
|
return chartMap;
|
|
}
|
|
|
|
export function CreateScoreIDMap<I extends IDStrings = IDStrings>(scores: ScoreDocument<I>[]) {
|
|
const scoreMap = new Map<string, ScoreDocument<I>>();
|
|
|
|
for (const score of scores) {
|
|
scoreMap.set(score.scoreID, score);
|
|
}
|
|
|
|
return scoreMap;
|
|
}
|
|
|
|
export function CreateChartLink(chart: ChartDocument, game: Game) {
|
|
if (chart.isPrimary) {
|
|
return `/dashboard/games/${game}/${chart.playtype}/songs/${
|
|
chart.songID
|
|
}/${encodeURIComponent(chart.difficulty)}`;
|
|
}
|
|
|
|
return `/dashboard/games/${game}/${chart.playtype}/songs/${chart.songID}/${chart.chartID}`;
|
|
}
|