Change versions from freeform string to explicit support.

This commit is contained in:
zkldi
2021-08-21 01:52:01 +01:00
parent 9f3ac38b90
commit 6450bb3fc5
5 changed files with 16 additions and 17 deletions
@@ -1,3 +1,5 @@
import { GPTSupportedVersions } from "tachi-common";
export interface EamusementScoreData {
difficulty: "BEGINNER" | "NORMAL" | "HYPER" | "ANOTHER" | "LEGGENDARIA";
lamp: string;
@@ -28,7 +30,7 @@ export type RawIIDXEamusementCSVData = {
export interface IIDXEamusementCSVContext {
playtype: "SP" | "DP";
importVersion: string;
importVersion: GPTSupportedVersions["iidx:SP" | "iidx:DP"];
hasBeginnerAndLegg: boolean;
service: string;
}
@@ -72,7 +72,7 @@ export function ResolveS3Lamp(data: S3Score, logger: KtLogger): Lamps["iidx:SP"
throw new InvalidScoreFailure(`Invalid cleartype of ${data.cleartype}.`);
}
const S3_VERSION_CONV: Record<string, string> = {
const S3_VERSION_CONV = {
"3rd": "3-cs",
"4th": "4-cs",
"5th": "5-cs",
@@ -89,14 +89,14 @@ const S3_VERSION_CONV: Record<string, string> = {
emp: "16-cs",
pb: "16-cs",
us: "bmus",
};
} as const;
function ConvertVersion(joinedStyles: string) {
const styles = joinedStyles.split(",");
const style = styles[styles.length - 1];
const convertedStyle = S3_VERSION_CONV[style];
const convertedStyle = S3_VERSION_CONV[style as keyof typeof S3_VERSION_CONV];
if (!convertedStyle) {
throw new InvalidScoreFailure(`Song has invalid style ${style}.`);
@@ -1,4 +1,4 @@
import { integer } from "tachi-common";
import { GPTSupportedVersions, integer } from "tachi-common";
export interface FervidexStaticScore {
clear_type: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
@@ -9,5 +9,5 @@ export interface FervidexStaticScore {
}
export interface FervidexStaticContext {
version: string;
version: GPTSupportedVersions["iidx:SP" | "iidx:DP"];
}
@@ -1,4 +1,4 @@
import { integer } from "tachi-common";
import { GPTSupportedVersions, integer } from "tachi-common";
export interface FervidexScore {
chart: `${"sp" | "dp"}${"b" | "n" | "h" | "a" | "l"}`;
@@ -58,5 +58,5 @@ export interface FervidexScore {
}
export interface FervidexContext {
version: string;
version: GPTSupportedVersions["iidx:SP" | "iidx:DP"];
}
+6 -9
View File
@@ -1,4 +1,4 @@
import { Game, AnySongDocument, integer } from "tachi-common";
import { Game, SongDocument, integer } from "tachi-common";
import { FindOneResult } from "monk";
import db from "external/mongo/db";
import { KtLogger } from "lib/logger/logger";
@@ -11,12 +11,9 @@ import { EscapeStringRegexp } from "../misc";
* rather difficult. Prefer other functions!
* @param game - The game to search upon.
* @param title - The song title to match.
* @returns AnySongDocument
* @returns SongDocument
*/
export function FindSongOnTitle(
game: Game,
title: string
): Promise<FindOneResult<AnySongDocument>> {
export function FindSongOnTitle(game: Game, title: string): Promise<FindOneResult<SongDocument>> {
// @optimisable: Performance should be tested here by having a utility field for all-titles.
return db.songs[game].findOne({
$or: [
@@ -37,7 +34,7 @@ export function FindSongOnTitle(
export function FindSongOnTitleInsensitive(
game: Game,
title: string
): Promise<FindOneResult<AnySongDocument>> {
): Promise<FindOneResult<SongDocument>> {
// @optimisable: Performance should be tested here by having a utility field for all-titles.
const regex = new RegExp(`^${EscapeStringRegexp(title)}$`, "iu");
@@ -58,9 +55,9 @@ export function FindSongOnTitleInsensitive(
* also be the in-game-ID.
* @param game - The game to search upon.
* @param songID - The song ID to match.
* @returns AnySongDocument
* @returns SongDocument
*/
export function FindSongOnID(game: Game, songID: integer): Promise<FindOneResult<AnySongDocument>> {
export function FindSongOnID(game: Game, songID: integer): Promise<FindOneResult<SongDocument>> {
return db.songs[game].findOne({
id: songID,
});