Skip to content

Commit

Permalink
New match type: ddrSongHash
Browse files Browse the repository at this point in the history
  • Loading branch information
tranq88 committed Dec 4, 2024
1 parent 70abc32 commit 77fd708
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 3 deletions.
3 changes: 2 additions & 1 deletion common/src/config/game-support/ddr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,13 @@ export const DDR_SP_CONF = {
chartData: z.strictObject({
inGameID: zodNonNegativeInt,
stepCount: zodNonNegativeInt.optional(),
ddrSongHash: z.string().optional(), // optional because konaste-only songs have no hashes
}),

preferences: z.strictObject({}),
scoreMeta: z.strictObject({}),

supportedMatchTypes: ["inGameID", "songTitle", "tachiSongID"],
supportedMatchTypes: ["inGameID", "songTitle", "tachiSongID", "ddrSongHash"],
} as const satisfies INTERNAL_GAME_PT_CONFIG;

export const DDR_DP_CONF = {
Expand Down
3 changes: 2 additions & 1 deletion common/src/lib/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,8 @@ const PR_BATCH_MANUAL_SCORE = (game: Game, playtype: Playtype): PrudenceSchema =
"inGameID",
"inGameStrID",
"uscChartHash",
"popnChartHash"
"popnChartHash",
"ddrSongHash"
),
identifier: "string",
comment: optNull(p.isBoundedString(3, 240)),
Expand Down
3 changes: 2 additions & 1 deletion common/src/types/batch-manual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ type MatchTypesWithDifficulty =
| "inGameStrID"
| "sdvxInGameID"
| "songTitle"
| "tachiSongID";
| "tachiSongID"
| "ddrSongHash";

export type MatchTypes = MatchTypesNoDifficulty | MatchTypesWithDifficulty;

Expand Down
28 changes: 28 additions & 0 deletions seeds/scripts/test/match-type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,34 @@ const MATCH_TYPE_CHECKS: Record<
},
},
uscChartHash: { type: "CHARTS", fn: (c) => c.data.hashSHA1 },
ddrSongHash: {
type: "CHARTS",
fn: (c) => {
// if there's no ddrSongHash then it must be a konaste song
// so just use the inGameID
if (c.data.ddrSongHash === undefined) {
return `${c.data.inGameID}-${c.difficulty}`;
}

// edge case for the song "B4U (The Acolyte mix)"
//
// for some reason konmai decided to change its inGameID in DDR A3
// so now there's an a20plus version and an a3 version
// (see songIDs 37225 and 37310)
//
// unfortunately, they decided to keep the same ddrSongHash across both!
// so we manually distinguish it here.
const B4UAcolyteSongHash = "01lbO69qQiP691ll6DIiqPbIdd9O806o";
if (c.data.ddrSongHash === B4UAcolyteSongHash) {
if (c.versions[0] === "a20plus") {
return `${c.data.ddrSongHash}-${c.difficulty}-a20plus`;
}
}
// perhaps we could just merge the two "songs" together in the seeds to avoid all this?

return `${c.data.ddrSongHash}-${c.difficulty}`;
},
},
};

let exitCode = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,46 @@ export async function ResolveMatchTypeToTachiData(
return { song, chart };
}

case "ddrSongHash": {
const difficulty = AssertStrAsDifficulty(data.difficulty, game, playtype);

let chart: ChartDocument | null;

if (context.version) {
chart = await db.anyCharts.ddr.findOne({
"data.ddrSongHash": data.identifier,
playtype,
difficulty,
versions: context.version,
});
} else {
chart = await db.anyCharts.ddr.findOne({
"data.ddrSongHash": data.identifier,
playtype,
difficulty,
isPrimary: true,
});
}

if (!chart) {
throw new SongOrChartNotFoundFailure(
`Cannot find chart for ddrSongHash ${data.identifier} (${playtype}).`,
importType,
data,
context
);
}

const song = await db.anySongs.ddr.findOne({ id: chart.songID });

if (!song) {
logger.severe(`Song-Chart desync on ${chart.songID}.`);
throw new InternalFailure(`Failed to get song for a chart that exists.`);
}

return { song, chart };
}

default: {
const { matchType } = data;

Expand Down

0 comments on commit 77fd708

Please sign in to comment.