mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-01 03:18:06 +03:00
factor out SUPPORTED_GAMES
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
|
||||
import { PrivateUserDocument, ScoreDocument } from "tachi-common";
|
||||
import { grades, lamps, supportedGames, validPlaytypes } from "tachi-common/js/config";
|
||||
import { grades, lamps, validPlaytypes } from "tachi-common/js/config";
|
||||
import db from "../../src/db/db";
|
||||
import MigrateRecords from "./migrate";
|
||||
import CreateLogCtx from "../../src/common/logger";
|
||||
|
||||
@@ -3,7 +3,7 @@ import { Command } from "commander";
|
||||
import CreateLogCtx from "../src/lib/logger/logger";
|
||||
import { IndexOptions } from "mongodb";
|
||||
import { ValidDatabases } from "tachi-common";
|
||||
import { supportedGames } from "tachi-common/js/config";
|
||||
import { CONF_INFO } from "../src/lib/setup/config";
|
||||
|
||||
const logger = CreateLogCtx(__filename);
|
||||
|
||||
@@ -87,7 +87,7 @@ const staticIndexes: Partial<Record<ValidDatabases, Index[]>> = {
|
||||
|
||||
const indexes: Partial<Record<ValidDatabases, Index[]>> = staticIndexes;
|
||||
|
||||
for (const game of supportedGames) {
|
||||
for (const game of CONF_INFO.SUPPORTED_GAMES) {
|
||||
if (indexes[`charts-${game}` as "charts-iidx"]) {
|
||||
indexes[`charts-${game}` as "charts-iidx"]!.push(
|
||||
index({ chartID: 1 }, UNIQUE),
|
||||
@@ -138,7 +138,7 @@ export async function SetIndexes(dbst: string) {
|
||||
logger.info("Done.");
|
||||
}
|
||||
|
||||
// if calling this as a script
|
||||
// if calling this as a script -- similar to pythons if __name__ == "__main__"
|
||||
if (require.main === module) {
|
||||
SetIndexes(options.db ?? "ktblackdb").then(process.exit(0));
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import Prudence, { PrudenceSchema } from "prudence";
|
||||
import db from "../src/db/db";
|
||||
import { PRUDENCE_CHART_SCHEMAS, PRUDENCE_SCORE_SCHEMAS, STATIC_SCHEMAS } from "../src/db/schemas";
|
||||
import { PRUDENCE_SCORE_SCHEMAS, STATIC_SCHEMAS } from "../src/db/schemas";
|
||||
import CreateLogCtx from "../src/common/logger";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { PrudenceError } from "prudence/js/error";
|
||||
import { supportedGames, validPlaytypes } from "tachi-common/js/config";
|
||||
import { validPlaytypes } from "tachi-common/js/config";
|
||||
import { CONF_INFO } from "../src/lib/setup/config";
|
||||
|
||||
const BASE_DIR = path.join(__dirname, "./validate-database-errs");
|
||||
|
||||
@@ -62,7 +63,7 @@ async function ValidateScores(): Promise<void> {
|
||||
let globalTotal = 0;
|
||||
let globalSuccess = 0;
|
||||
let globalFail = 0;
|
||||
for (const game of supportedGames) {
|
||||
for (const game of CONF_INFO.SUPPORTED_GAMES) {
|
||||
for (const playtype of validPlaytypes[game]) {
|
||||
// @ts-expect-error shut up
|
||||
const schema = PRUDENCE_SCORE_SCHEMAS[game][playtype];
|
||||
@@ -134,7 +135,7 @@ async function ValidateChartsOrSongs(type: "songs" | "charts"): Promise<void> {
|
||||
let globalTotal = 0;
|
||||
let globalSuccess = 0;
|
||||
let globalFail = 0;
|
||||
for (const game of supportedGames) {
|
||||
for (const game of CONF_INFO.SUPPORTED_GAMES) {
|
||||
const schema = STATIC_SCHEMAS[type]![game];
|
||||
|
||||
let successCount = 0;
|
||||
|
||||
Vendored
+2
-2
@@ -7,9 +7,9 @@ import {
|
||||
validHitData,
|
||||
validDifficulties,
|
||||
validPlaytypes,
|
||||
supportedGames,
|
||||
} from "tachi-common/js/config";
|
||||
import p, { PrudenceSchema, ValidSchemaValue } from "prudence";
|
||||
import { CONF_INFO } from "../../lib/setup/config";
|
||||
|
||||
const LAZY_EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/u;
|
||||
|
||||
@@ -408,7 +408,7 @@ const PRUDENCE_FOLDER_CHART_LOOKUP: PrudenceSchema = {
|
||||
|
||||
const PRUDENCE_FOLDER: PrudenceSchema = {
|
||||
title: "string",
|
||||
game: p.isIn(supportedGames),
|
||||
game: p.isIn(CONF_INFO.SUPPORTED_GAMES),
|
||||
playtype: (self, parent) => p.isIn(validPlaytypes[parent.game as Game])(self),
|
||||
folderID: "string",
|
||||
table: "string",
|
||||
|
||||
@@ -2,12 +2,13 @@ import { KtLogger } from "../../../../logger/logger";
|
||||
import ScoreImportFatalError from "../../../framework/score-importing/score-import-error";
|
||||
import { BatchManual, BatchManualContext, BatchManualScore } from "./types";
|
||||
import p, { PrudenceSchema, ValidSchemaValue } from "prudence";
|
||||
import { lamps, supportedGames, validHitData, validPlaytypes } from "tachi-common/js/config";
|
||||
import { lamps, validHitData, validPlaytypes } from "tachi-common/js/config";
|
||||
import { Game, ImportTypes } from "tachi-common";
|
||||
import { ConverterBatchManual } from "./converter";
|
||||
import deepmerge from "deepmerge";
|
||||
import { FormatPrError } from "../../../../../utils/prudence";
|
||||
import { ParserFunctionReturnsSync } from "../types";
|
||||
import { CONF_INFO } from "../../../../setup/config";
|
||||
|
||||
const optNull = (v: ValidSchemaValue) => p.optional(p.nullable(v));
|
||||
|
||||
@@ -101,7 +102,7 @@ const PR_BatchManualScore = (game: Game): PrudenceSchema => ({
|
||||
const PR_BatchManual = (game: Game): PrudenceSchema => ({
|
||||
head: {
|
||||
service: p.isBoundedString(3, 15),
|
||||
game: p.isIn(supportedGames),
|
||||
game: p.isIn(CONF_INFO.SUPPORTED_GAMES),
|
||||
version: "*?string",
|
||||
},
|
||||
body: [PR_BatchManualScore(game)],
|
||||
@@ -140,10 +141,10 @@ export function ParseBatchManualFromObject(
|
||||
);
|
||||
}
|
||||
|
||||
if (!supportedGames.includes(possiblyGame)) {
|
||||
if (!CONF_INFO.SUPPORTED_GAMES.includes(possiblyGame)) {
|
||||
throw new ScoreImportFatalError(
|
||||
400,
|
||||
`Invalid game ${possiblyGame} - expected any of ${supportedGames.join(", ")}`
|
||||
`Invalid game ${possiblyGame} - expected any of ${CONF_INFO.SUPPORTED_GAMES.join(", ")}`
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,7 @@ import JSON5 from "json5";
|
||||
import fs from "fs";
|
||||
import p from "prudence";
|
||||
import { FormatPrError } from "../../utils/prudence";
|
||||
import { integer } from "tachi-common";
|
||||
|
||||
import { integer, Game } from "tachi-common";
|
||||
dotenv.config(); // imports things like NODE_ENV from a local .env file if one is present.
|
||||
|
||||
// reads from $pwd/conf.json5
|
||||
@@ -38,8 +37,9 @@ export interface TachiConfig {
|
||||
CDN_ROOT: string;
|
||||
TYPE: "ktchi" | "btchi" | "omni";
|
||||
PORT: integer;
|
||||
INFO: {
|
||||
TYPE_INFO: {
|
||||
NAME: string;
|
||||
SUPPORTED_GAMES: Game[];
|
||||
};
|
||||
}
|
||||
|
||||
@@ -64,15 +64,17 @@ if (err) {
|
||||
/**
|
||||
* KTCHI | Kamaitachi is the arcade build of Tachi.
|
||||
*/
|
||||
const KTCHI_INFO: TachiConfig["INFO"] = {
|
||||
const KTCHI_INFO: TachiConfig["TYPE_INFO"] = {
|
||||
NAME: "Kamaitachi",
|
||||
SUPPORTED_GAMES: ["iidx", "gitadora", "chunithm", "maimai", "museca", "sdvx"],
|
||||
};
|
||||
|
||||
/**
|
||||
* BTCHI | Bokutachi is the home-simulator build of Tachi.
|
||||
*/
|
||||
const BTCHI_INFO: TachiConfig["INFO"] = {
|
||||
const BTCHI_INFO: TachiConfig["TYPE_INFO"] = {
|
||||
NAME: "Bokutachi",
|
||||
SUPPORTED_GAMES: ["usc", "bms"],
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -81,16 +83,17 @@ const BTCHI_INFO: TachiConfig["INFO"] = {
|
||||
* If you're one of those nerds who is reading this to figure out how to steal and rerun
|
||||
* this codebase this is what you're looking for.
|
||||
*/
|
||||
const OMNI_INFO: TachiConfig["INFO"] = {
|
||||
const OMNI_INFO: TachiConfig["TYPE_INFO"] = {
|
||||
NAME: "Omnitachi",
|
||||
SUPPORTED_GAMES: [...KTCHI_INFO.SUPPORTED_GAMES, ...BTCHI_INFO.SUPPORTED_GAMES],
|
||||
};
|
||||
|
||||
if (config.TYPE === "ktchi") {
|
||||
config.INFO = KTCHI_INFO;
|
||||
config.TYPE_INFO = KTCHI_INFO;
|
||||
} else if (config.TYPE === "btchi") {
|
||||
config.INFO = BTCHI_INFO;
|
||||
config.TYPE_INFO = BTCHI_INFO;
|
||||
} else if (config.type === "omni") {
|
||||
config.INFO = OMNI_INFO;
|
||||
config.TYPE_INFO = OMNI_INFO;
|
||||
}
|
||||
|
||||
const tachiConfig = config as TachiConfig;
|
||||
@@ -104,6 +107,6 @@ export const EAG_API_URL = tachiConfig.EAG_API_URL;
|
||||
export const ARC_API_URL = tachiConfig.ARC_API_URL;
|
||||
export const ARC_AUTH_TOKEN = tachiConfig.ARC_AUTH_TOKEN;
|
||||
export const KTCDN_ROOT = tachiConfig.CDN_ROOT;
|
||||
export const CONF_INFO = tachiConfig.INFO;
|
||||
export const CONF_INFO = tachiConfig.TYPE_INFO;
|
||||
export const PORT = tachiConfig.PORT;
|
||||
export const CONFIG = tachiConfig;
|
||||
|
||||
Reference in New Issue
Block a user