Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add chart parameter to ScoreValidator #1167

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
SpecificUserGameStats,
GPTString,
ScoreDocument,
ChartDocument,
} from "tachi-common";

export const EX_SCORE_CHECK: ChartSpecificMetricValidator<IIDXLikes> = (exScore, chart) => {
Expand Down Expand Up @@ -224,7 +225,7 @@
SDVXLIKE_GBOUNDARIES,
pb.scoreData.grade,
pb.scoreData.score,
SDVXLIKE_GBOUNDARIES[goalValue]!.name

Check warning on line 228 in server/src/game-implementations/games/_common.ts

View workflow job for this annotation

GitHub Actions / test

Forbidden non-null assertion
),
};

Expand Down Expand Up @@ -335,12 +336,13 @@
*/
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 { 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("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
Loading