checkpoint: insanity ascends (35)

127 errors to go
This commit is contained in:
zkldi
2023-01-19 16:39:42 +00:00
parent 2b0e65f0c8
commit 5cbb2d5f8a
131 changed files with 2106 additions and 1886 deletions
+42 -12
View File
@@ -6,6 +6,7 @@ import {
} from "../config/config";
import type { GradeBoundary } from "../constants/grade-boundaries";
import type {
BMSCourseDocument,
ChartDocument,
GPTString,
GPTStrings,
@@ -228,6 +229,17 @@ export function FmtNum(num: number) {
return num.toLocaleString();
}
export function FmtPercent(v: number, dp = 2) {
return `${v.toFixed(dp)}%`;
}
/**
* Turns a number of 12834 into "12834" instead of "12,834".
*/
export function FmtScoreNoCommas(v: number) {
return v.toString();
}
function WrapGrade(grade: string) {
if (grade.endsWith("-") || grade.endsWith("+")) {
return `(${grade})`;
@@ -236,18 +248,6 @@ function WrapGrade(grade: string) {
return grade;
}
type FormatGradeDeltaReturns =
| {
lower: string;
upper: string;
closer: "upper";
}
| {
lower: string;
upper?: string;
closer: "lower";
};
function RelativeGradeDelta<G extends string>(
gradeBoundaries: Array<GradeBoundary<G>>,
scoreGrade: G,
@@ -378,3 +378,33 @@ export function FormatPrError(err: PrudenceError, foreword = "Error"): string {
return `${foreword}: ${err.keychain} | ${err.message}${receivedText}.`;
}
export function GetBMSCourseIndex(course: BMSCourseDocument) {
const gptConf = GetGamePTConfig("bms", course.playtype);
const cls = gptConf.classes[course.set];
if (!cls) {
throw new Error(
`Invalid BMSCourse set of ${course.set}. No classes are defined for this set.`
);
}
return cls.values.findIndex((e) => e.id === course.value);
}
/**
* Util for getting a games' grade for a given score.
*/
export function GetGrade<G extends string>(grades: Array<GradeBoundary<G>>, score: number): G {
// sort grades going downwards in their boundaries.
const descendingGrades = grades.slice(0).sort((a, b) => b.lowerBound - a.lowerBound);
for (const { name, lowerBound } of descendingGrades) {
if (score >= lowerBound) {
return name;
}
}
throw new Error(`Could not resolve grade for score ${score}.`);
}