Add the new fields for the lr2hook.

This commit is contained in:
zkldi
2021-12-11 23:49:17 +00:00
parent 9e31b8574c
commit 612a3de389
3 changed files with 47 additions and 2 deletions
@@ -1,6 +1,7 @@
import { Lamps } from "tachi-common";
import { Lamps, ScoreDocument } from "tachi-common";
import {
InternalFailure,
InvalidScoreFailure,
KTDataNotFoundFailure,
} from "lib/score-import/framework/common/converter-failures";
import { GenericGetGradeAndPercent } from "lib/score-import/framework/common/score-utils";
@@ -61,6 +62,7 @@ export const ConverterLR2Hook: ConverterFunction<LR2HookScore, LR2HookContext> =
},
},
scoreMeta: {
random: chart.playtype === "7K" ? ConvertRandom(data.playerData.random) : null,
client: "LR2",
},
};
@@ -68,6 +70,21 @@ export const ConverterLR2Hook: ConverterFunction<LR2HookScore, LR2HookContext> =
return { song, chart, dryScore };
};
function ConvertRandom(
random: LR2HookScore["playerData"]["random"]
): ScoreDocument<"bms:7K">["scoreMeta"]["random"] {
switch (random) {
case "NONRAN":
return "NONRAN";
case "MIRROR":
return "MIRROR";
case "RAN":
return "RANDOM";
case "S-RAN":
return "S-RANDOM";
}
}
function ConvertLamp(lamp: LR2HookScore["scoreData"]["lamp"]): Lamps["bms:7K" | "bms:14K"] {
switch (lamp) {
case "EASY":
@@ -5,8 +5,18 @@ import p, { PrudenceSchema } from "prudence";
import ScoreImportFatalError from "lib/score-import/framework/score-importing/score-import-error";
import { FormatPrError } from "utils/prudence";
const SUPPORTED_RANDOMS = ["NONRAN", "MIRROR", "RAN", "S-RAN"];
const PR_LR2Hook: PrudenceSchema = {
md5: "string",
playerData: {
autoScr: p.is(false),
// don't really need this, but it's
// { "ALL", "SINGLE", "7K", "5K", "DOUBLE", "14K", "10K", "9K" };
gameMode: p.any,
// ALLSCR and H-RAN may also be sent, but we don't support them.
random: p.isIn(SUPPORTED_RANDOMS),
},
scoreData: {
pgreat: p.isPositiveInteger,
great: p.isPositiveInteger,
@@ -40,7 +50,20 @@ export function ParseLR2Hook(
logger: KtLogger
): ParserFunctionReturns<LR2HookScore, LR2HookContext> {
// Ignore excess keys, as lr2hook is likely to add more features in the future.
const err = p(body, PR_LR2Hook, undefined, { allowExcessKeys: true });
const err = p(
body,
PR_LR2Hook,
{
playerData: {
autoScr:
"Auto Scratch cannot be turned on, as it is treated as an EASY CLEAR by LR2.",
random: `Expected any of ${SUPPORTED_RANDOMS.join(
", "
)}. Note that ALLSCR and H-RAN are not supported!`,
},
},
{ allowExcessKeys: true }
);
if (err) {
throw new ScoreImportFatalError(400, FormatPrError(err));
@@ -2,6 +2,11 @@ import { integer } from "tachi-common";
export interface LR2HookScore {
md5: string;
playerData: {
autoScr: boolean;
gameMode: unknown;
random: "NONRAN" | "MIRROR" | "RAN" | "S-RAN";
};
scoreData: {
pgreat: integer;
great: integer;