feat: add bms displayTables to gameSpecific settings, refactor duplicate implementation out

This commit is contained in:
zkldi
2022-10-14 00:04:34 +01:00
parent 8db22b7ff4
commit 09becfcc3a
2 changed files with 31 additions and 23 deletions
+29 -6
View File
@@ -36,6 +36,33 @@ function prSchemaFnWrap(schema: PrudenceSchema) {
};
}
export const PR_GAMESPECIFIC_SETTINGS = (game: Game): PrudenceSchema => {
switch (game) {
case "iidx":
return {
display2DXTra: p.optional("boolean"),
bpiTarget: p.optional(p.isBoundedInteger(0, 100)),
};
case "sdvx":
case "usc":
return {
vf6Target: p.optional(p.isBetween(0, 0.5)),
};
case "bms":
return {
displayTables: ["string"],
};
case "jubeat":
return {
// 165.1 is the max jubility.
jubilityTarget: p.optional(p.isBetween(0, 165.1)),
};
default:
return {};
}
};
const PR_GAME_STATS = (game: Game, playtype: Playtypes[Game], gptConfig: GamePTConfig) => ({
userID: p.isPositiveNonZeroInteger,
game: p.is(game),
@@ -926,12 +953,8 @@ const PRE_SCHEMAS = {
(self) => Array.isArray(self) && self.length <= 6
),
scoreBucket: p.isIn(null, "grade", "lamp"),
gameSpecific:
game === "iidx"
? {
display2DXTra: "boolean",
}
: {},
gameSpecific: PR_GAMESPECIFIC_SETTINGS(game),
},
})(s);
},
@@ -5,6 +5,7 @@ import CreateLogCtx from "lib/logger/logger";
import p from "prudence";
import { RequirePermissions } from "server/middleware/auth";
import { GetGamePTConfig } from "tachi-common";
import { PR_GAMESPECIFIC_SETTINGS } from "tachi-common/lib/schemas";
import { FormatPrError, optNull } from "utils/prudence";
import { GetUGPT } from "utils/req-tachi-data";
import { FormatUserDoc } from "utils/user";
@@ -30,23 +31,7 @@ router.patch(
const gptConfig = GetGamePTConfig(game, playtype);
let gameSpecificSchema = {};
if (game === "iidx") {
gameSpecificSchema = {
display2DXTra: p.optional("boolean"),
bpiTarget: p.optional(p.isBoundedInteger(0, 100)),
};
} else if (game === "sdvx" || game === "usc") {
gameSpecificSchema = {
vf6Target: p.optional(p.isBetween(0, 0.5)),
};
} else if (game === "jubeat") {
gameSpecificSchema = {
// 165.1 is the max jubility.
jubilityTarget: p.optional(p.isBetween(0, 165.1)),
};
}
const gameSpecificSchema = PR_GAMESPECIFIC_SETTINGS(game);
const err = p(req.safeBody, {
preferredScoreAlg: p.optional(p.nullable(p.isIn(gptConfig.scoreRatingAlgs))),