diff --git a/common/src/config/config.ts b/common/src/config/config.ts index a2e3cda59..363221d26 100644 --- a/common/src/config/config.ts +++ b/common/src/config/config.ts @@ -1,3 +1,4 @@ +/* eslint-disable lines-around-comment */ import { FormatSieglindeBMS, FormatSieglindePMS } from "./internal-utils"; import { COLOUR_SET } from "../constants/colour-set"; import { @@ -83,7 +84,28 @@ interface BaseGamePTConfig { clearLamp: Lamps[I]; classHumanisedFormat: Record>; - classProperties: Record; + classProperties: Record< + GameClassSets[I], + { + /** + * If a worse thing comes in for this, should this metric go down? + * I.e. if a user is 4th dan and they submit 3rd dan, should it go + * down to 3rd dan? (Hopefully not). This makes the most sense for + * metrics like "colour" in games, which are a function of some profile + * skill. If said profile skill goes down, it should reflect in that + * colour. + */ + downgradable: boolean; + + /** + * Can this class be sent in `batchManual.classes`? This only makes sense + * for classes that aren't a function of existing state, so things like + * submitting dan rank makes sense, but submitting things like "Colour" + * makes no sense (as it's a function of profile skill). + */ + canBeBatchManualSubmitted: boolean; + } + >; judgements: Array; @@ -361,7 +383,7 @@ const GAME_PT_CONFIGS: GamePTConfigs = { dan: IIDXDans, }, classProperties: { - dan: { downgradable: false }, + dan: { downgradable: false, canBeBatchManualSubmitted: true }, }, supportsESD: true, @@ -563,7 +585,7 @@ const GAME_PT_CONFIGS: GamePTConfigs = { dan: IIDXDans, }, classProperties: { - dan: { downgradable: false }, + dan: { downgradable: false, canBeBatchManualSubmitted: true }, }, supportsESD: true, @@ -691,7 +713,7 @@ const GAME_PT_CONFIGS: GamePTConfigs = { colour: CHUNITHMColours, }, classProperties: { - colour: { downgradable: true }, + colour: { downgradable: true, canBeBatchManualSubmitted: false }, }, supportsESD: false, @@ -788,8 +810,8 @@ const GAME_PT_CONFIGS: GamePTConfigs = { vfClass: SDVXVFClasses, }, classProperties: { - dan: { downgradable: false }, - vfClass: { downgradable: true }, + dan: { downgradable: false, canBeBatchManualSubmitted: true }, + vfClass: { downgradable: true, canBeBatchManualSubmitted: false }, }, supportsESD: false, @@ -1162,10 +1184,10 @@ const GAME_PT_CONFIGS: GamePTConfigs = { scratchDan: BMSScratchDans, }, classProperties: { - genocideDan: { downgradable: false }, - stslDan: { downgradable: false }, - lnDan: { downgradable: false }, - scratchDan: { downgradable: false }, + genocideDan: { downgradable: false, canBeBatchManualSubmitted: true }, + stslDan: { downgradable: false, canBeBatchManualSubmitted: true }, + lnDan: { downgradable: false, canBeBatchManualSubmitted: true }, + scratchDan: { downgradable: false, canBeBatchManualSubmitted: true }, }, supportsESD: false, @@ -1280,8 +1302,8 @@ const GAME_PT_CONFIGS: GamePTConfigs = { stslDan: BMSDPSlDans, }, classProperties: { - genocideDan: { downgradable: false }, - stslDan: { downgradable: false }, + genocideDan: { downgradable: false, canBeBatchManualSubmitted: true }, + stslDan: { downgradable: false, canBeBatchManualSubmitted: true }, }, supportsESD: false, @@ -1417,8 +1439,8 @@ const GAME_PT_CONFIGS: GamePTConfigs = { dan: MaimaiDXDans, }, classProperties: { - colour: { downgradable: true }, - dan: { downgradable: true }, + colour: { downgradable: true, canBeBatchManualSubmitted: false }, + dan: { downgradable: false, canBeBatchManualSubmitted: true }, }, supportsESD: false, @@ -1519,7 +1541,7 @@ const GAME_PT_CONFIGS: GamePTConfigs = { colour: GitadoraColours, }, classProperties: { - colour: { downgradable: true }, + colour: { downgradable: true, canBeBatchManualSubmitted: false }, }, supportsESD: false, @@ -1603,7 +1625,7 @@ const GAME_PT_CONFIGS: GamePTConfigs = { colour: GitadoraColours, }, classProperties: { - colour: { downgradable: true }, + colour: { downgradable: true, canBeBatchManualSubmitted: false }, }, supportsESD: false, @@ -1697,8 +1719,8 @@ const GAME_PT_CONFIGS: GamePTConfigs = { colour: WaccaColours, }, classProperties: { - stageUp: { downgradable: false }, - colour: { downgradable: true }, + stageUp: { downgradable: false, canBeBatchManualSubmitted: true }, + colour: { downgradable: true, canBeBatchManualSubmitted: false }, }, supportsESD: false, @@ -1787,7 +1809,7 @@ const GAME_PT_CONFIGS: GamePTConfigs = { class: PopnClasses, }, classProperties: { - class: { downgradable: true }, + class: { downgradable: true, canBeBatchManualSubmitted: false }, }, supportsESD: false, @@ -1879,7 +1901,7 @@ const GAME_PT_CONFIGS: GamePTConfigs = { colour: JubeatColours, }, classProperties: { - colour: { downgradable: true }, + colour: { downgradable: true, canBeBatchManualSubmitted: false }, }, supportsESD: false, @@ -1999,7 +2021,7 @@ const GAME_PT_CONFIGS: GamePTConfigs = { dan: PMSDans, }, classProperties: { - dan: { downgradable: false }, + dan: { downgradable: false, canBeBatchManualSubmitted: true }, }, supportsESD: false, @@ -2112,7 +2134,7 @@ const GAME_PT_CONFIGS: GamePTConfigs = { dan: PMSDans, }, classProperties: { - dan: { downgradable: false }, + dan: { downgradable: false, canBeBatchManualSubmitted: true }, }, supportsESD: false, diff --git a/common/src/lib/schemas.ts b/common/src/lib/schemas.ts index c4a682f17..2e0e3b93c 100644 --- a/common/src/lib/schemas.ts +++ b/common/src/lib/schemas.ts @@ -9,6 +9,7 @@ import { UserAuthLevels } from "../types"; import deepmerge from "deepmerge"; import { p } from "prudence"; import type { GamePTConfig } from "../config/config"; +import type { AllClassSets } from "../game-classes"; import type { Game, IDStrings, NotificationBody, Playtype, Playtypes } from "../types"; import type { PrudenceSchema, @@ -1358,31 +1359,24 @@ const PR_BATCH_MANUAL_SCORE = (game: Game, playtype: Playtype): PrudenceSchema = }; }; -// both iidx sp and dp share dans. -const IIDXStringDans = GetGamePTConfig("iidx", "SP").classHumanisedFormat.dan.map((e) => e.id); -const SDVXStringDans = GetGamePTConfig("sdvx", "Single").classHumanisedFormat.dan.map((e) => e.id); -const WaccaStringStageUps = GetGamePTConfig("wacca", "Single").classHumanisedFormat.stageUp.map( - (e) => e.id -); +const PR_BATCH_MANUAL_CLASSES = (game: Game, playtype: Playtype): PrudenceSchema => { + const config = GetGamePTConfig(game, playtype); -const PR_BATCH_MANUAL_CLASSES = (game: Game): PrudenceSchema => { - // This can be implemented for any non-static class (i.e. dans). - switch (game) { - case "iidx": - return { - dan: optNull(p.isIn(IIDXStringDans)), - }; - case "sdvx": - return { - dan: optNull(p.isIn(SDVXStringDans)), - }; - case "wacca": - return { - stageUp: optNull(p.isIn(WaccaStringStageUps)), - }; - default: - return {}; + const schema: PrudenceSchema = {}; + + // for all classes this GPT supports + // if `canBeBatchManualSubmitted` is true, allow it to be batchManualSubmitted. + for (const [s, v] of Object.entries(config.classHumanisedFormat)) { + const set = s as AllClassSets; + + const classProperties = config.classProperties[set]; + + if (classProperties.canBeBatchManualSubmitted) { + schema[set] = optNull(p.isIn(v.map((e) => e.id))); + } } + + return schema; }; export const PR_BATCH_MANUAL = (game: Game, playtype: Playtype): PrudenceSchema => ({ @@ -1393,5 +1387,5 @@ export const PR_BATCH_MANUAL = (game: Game, playtype: Playtype): PrudenceSchema version: "*?string", }, scores: [PR_BATCH_MANUAL_SCORE(game, playtype)], - classes: optNull(PR_BATCH_MANUAL_CLASSES(game)), + classes: optNull(PR_BATCH_MANUAL_CLASSES(game, playtype)), });