From 07ed5f3b6b29d3a43c36cc68a26e55ced69e3666 Mon Sep 17 00:00:00 2001 From: Gyoo Date: Tue, 27 Aug 2024 17:15:25 +0200 Subject: [PATCH] feat: add chart parameter to ScoreValidator (#1167) * feat: add chart parameter to ScoreValidator * fix: non compiling tests --- server/src/game-implementations/games/_common.ts | 6 ++++-- server/src/game-implementations/games/arcaea.test.ts | 10 +++++++--- server/src/game-implementations/games/wacca.test.ts | 2 +- server/src/game-implementations/types.ts | 3 ++- .../framework/score-importing/validate-score.ts | 2 +- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/server/src/game-implementations/games/_common.ts b/server/src/game-implementations/games/_common.ts index c5396bd22..d2e268090 100644 --- a/server/src/game-implementations/games/_common.ts +++ b/server/src/game-implementations/games/_common.ts @@ -32,6 +32,7 @@ import type { SpecificUserGameStats, GPTString, ScoreDocument, + ChartDocument, } from "tachi-common"; export const EX_SCORE_CHECK: ChartSpecificMetricValidator = (exScore, chart) => { @@ -335,12 +336,13 @@ export function GradeGoalFormatter( */ export function RunValidators( validators: Array>, - score: ScoreDocument + score: ScoreDocument, + chart: ChartDocument ) { const errs = []; for (const validator of validators) { - const err = validator(score); + const err = validator(score, chart); if (err !== undefined) { errs.push(err); diff --git a/server/src/game-implementations/games/arcaea.test.ts b/server/src/game-implementations/games/arcaea.test.ts index 10654ce0d..30c2f7b99 100644 --- a/server/src/game-implementations/games/arcaea.test.ts +++ b/server/src/game-implementations/games/arcaea.test.ts @@ -8,8 +8,8 @@ import t from "tap"; import { dmf, mkMockPB, mkMockScore } from "test-utils/misc"; import ResetDBState from "test-utils/resets"; import { TestSnapshot } from "test-utils/single-process-snapshot"; -import { TestingArcaeaSheriruthFTR } from "test-utils/test-data"; -import type { ProvidedMetrics, ScoreData, ScoreDocument } from "tachi-common"; +import { TestingArcaeaSheriruthFTR, TestingWaccaPupaExp } from "test-utils/test-data"; +import type { ProvidedMetrics, ScoreData, ScoreDocument, ChartDocument } from "tachi-common"; import type { DeepPartial } from "utils/types"; const baseMetrics: ProvidedMetrics["arcaea:Touch"] = { @@ -169,7 +169,11 @@ t.test("Arcaea Implementation", (t) => { t.test("Score Validations", (t) => { const f = (s: DeepPartial>) => - RunValidators(ARCAEA_IMPL.scoreValidators, dmf(mockScore, s)); + RunValidators( + ARCAEA_IMPL.scoreValidators, + dmf(mockScore, s), + TestingArcaeaSheriruthFTR + ); t.strictSame( f({ diff --git a/server/src/game-implementations/games/wacca.test.ts b/server/src/game-implementations/games/wacca.test.ts index 3817bec55..bc2853f65 100644 --- a/server/src/game-implementations/games/wacca.test.ts +++ b/server/src/game-implementations/games/wacca.test.ts @@ -172,7 +172,7 @@ t.test("WACCA Implementation", (t) => { t.test("Score Validations", (t) => { const f = (s: DeepPartial>) => - RunValidators(WACCA_IMPL.scoreValidators, dmf(mockScore, s)); + RunValidators(WACCA_IMPL.scoreValidators, dmf(mockScore, s), TestingWaccaPupaExp); t.strictSame(f({ scoreData: { lamp: "ALL MARVELOUS", score: 1_000_000 } }), undefined); t.strictSame(f({ scoreData: { lamp: "FULL COMBO", judgements: { miss: 0 } } }), undefined); diff --git a/server/src/game-implementations/types.ts b/server/src/game-implementations/types.ts index b4e00e774..e298ecf65 100644 --- a/server/src/game-implementations/types.ts +++ b/server/src/game-implementations/types.ts @@ -164,7 +164,8 @@ export type GPTGoalProgressFormatters = { * indicating what the error was on failure. */ export type ScoreValidator = ( - score: ScoreDocument + score: ScoreDocument, + chart: ChartDocument ) => string | undefined; export interface GPTServerImplementation { diff --git a/server/src/lib/score-import/framework/score-importing/validate-score.ts b/server/src/lib/score-import/framework/score-importing/validate-score.ts index cabb408a0..121cf3f10 100644 --- a/server/src/lib/score-import/framework/score-importing/validate-score.ts +++ b/server/src/lib/score-import/framework/score-importing/validate-score.ts @@ -58,7 +58,7 @@ function ValidateScoreGameSpecific(score: ScoreDocument, chart: ChartDocument): true ); - const moreErrors = RunValidators(gptImpl.scoreValidators as any, score); + const moreErrors = RunValidators(gptImpl.scoreValidators as any, score, chart); if (moreErrors) { errs.push(...moreErrors);