Skip to content

Commit

Permalink
feat: add chart parameter to ScoreValidator (#1167)
Browse files Browse the repository at this point in the history
* feat: add chart parameter to ScoreValidator

* fix: non compiling tests
  • Loading branch information
Gyoo authored Aug 27, 2024
1 parent 2a07244 commit 07ed5f3
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
6 changes: 4 additions & 2 deletions server/src/game-implementations/games/_common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import type {
SpecificUserGameStats,
GPTString,
ScoreDocument,
ChartDocument,
} from "tachi-common";

export const EX_SCORE_CHECK: ChartSpecificMetricValidator<IIDXLikes> = (exScore, chart) => {
Expand Down Expand Up @@ -335,12 +336,13 @@ export function GradeGoalFormatter<G extends string>(
*/
export function RunValidators<GPT extends GPTString>(
validators: Array<ScoreValidator<GPT>>,
score: ScoreDocument<GPT>
score: ScoreDocument<GPT>,
chart: ChartDocument<GPT>
) {
const errs = [];

for (const validator of validators) {
const err = validator(score);
const err = validator(score, chart);

if (err !== undefined) {
errs.push(err);
Expand Down
10 changes: 7 additions & 3 deletions server/src/game-implementations/games/arcaea.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Check warning on line 11 in server/src/game-implementations/games/arcaea.test.ts

View workflow job for this annotation

GitHub Actions / test

'TestingWaccaPupaExp' is defined but never used. Allowed unused vars must match /^_/u
import type { ProvidedMetrics, ScoreData, ScoreDocument, ChartDocument } from "tachi-common";
import type { DeepPartial } from "utils/types";

const baseMetrics: ProvidedMetrics["arcaea:Touch"] = {
Expand Down Expand Up @@ -169,7 +169,11 @@ t.test("Arcaea Implementation", (t) => {

t.test("Score Validations", (t) => {
const f = (s: DeepPartial<ScoreDocument<"arcaea:Touch">>) =>
RunValidators(ARCAEA_IMPL.scoreValidators, dmf(mockScore, s));
RunValidators(
ARCAEA_IMPL.scoreValidators,
dmf(mockScore, s),
TestingArcaeaSheriruthFTR
);

t.strictSame(
f({
Expand Down
2 changes: 1 addition & 1 deletion server/src/game-implementations/games/wacca.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ t.test("WACCA Implementation", (t) => {

t.test("Score Validations", (t) => {
const f = (s: DeepPartial<ScoreDocument<"wacca:Single">>) =>
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);
Expand Down
3 changes: 2 additions & 1 deletion server/src/game-implementations/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ export type GPTGoalProgressFormatters<GPT extends GPTString> = {
* indicating what the error was on failure.
*/
export type ScoreValidator<GPT extends GPTString> = (
score: ScoreDocument<GPT>
score: ScoreDocument<GPT>,
chart: ChartDocument<GPT>
) => string | undefined;

export interface GPTServerImplementation<GPT extends GPTString> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 07ed5f3

Please sign in to comment.