From 5757348dd6776a0ef8b0d53035f269a51c8763e4 Mon Sep 17 00:00:00 2001 From: zkldi <20380519+zkldi@users.noreply.github.com> Date: Sat, 23 Apr 2022 05:55:37 +0100 Subject: [PATCH] style: replace Playtypes[Game] with Playtype --- .../lib/game-settings/create-game-settings.ts | 4 ++-- .../framework/calculated-data/stats.ts | 14 +++++++++++--- .../framework/common/score-utils.ts | 8 ++++---- .../framework/common/string-asserts.ts | 4 ++-- .../lib/score-import/framework/common/types.ts | 4 ++-- .../framework/milestones/milestones.ts | 6 +++--- .../score-importing/score-import-main.ts | 6 +++--- .../framework/sessions/calculated-data.ts | 4 ++-- .../score-import/framework/sessions/sessions.ts | 8 ++++---- .../user-game-stats/builtin-class-handlers.ts | 14 +++++++------- .../framework/user-game-stats/classes.ts | 14 +++++++++++--- .../framework/user-game-stats/rating.ts | 17 +++++++++-------- .../framework/user-game-stats/types.ts | 4 ++-- .../framework/user-game-stats/update-ugs.ts | 4 ++-- .../import-types/common/batch-manual/parser.ts | 9 +++++---- .../import-types/common/batch-manual/types.ts | 4 ++-- .../ir/fervidex-static/class-handler.test.ts | 2 +- server/src/lib/score-mutation/delete-scores.ts | 4 ++-- server/src/lib/search/search.ts | 5 +++-- server/src/lib/showcase/get-stats.ts | 4 ++-- server/src/lib/targets/goal-utils.ts | 7 ++++--- server/src/lib/targets/goals.ts | 8 ++++---- .../api/v1/games/_game/_playtype/middleware.ts | 6 +++--- .../api/v1/games/_game/_playtype/router.ts | 12 ++++++++++-- server/src/utils/calculations/recalc-scores.ts | 6 +++--- server/src/utils/class.ts | 4 ++-- server/src/utils/folder.ts | 13 +++---------- server/src/utils/misc.ts | 6 +++--- server/src/utils/queries/charts.ts | 15 ++++++++------- server/src/utils/queries/stats.ts | 4 ++-- server/src/utils/reset-state/destroy-ugpt.ts | 4 ++-- server/src/utils/string-checks.ts | 8 ++++---- server/src/utils/types.ts | 4 ++-- server/src/utils/user.ts | 4 ++-- 34 files changed, 131 insertions(+), 109 deletions(-) diff --git a/server/src/lib/game-settings/create-game-settings.ts b/server/src/lib/game-settings/create-game-settings.ts index 721640893..9256ecc45 100644 --- a/server/src/lib/game-settings/create-game-settings.ts +++ b/server/src/lib/game-settings/create-game-settings.ts @@ -1,13 +1,13 @@ import db from "external/mongo/db"; import CreateLogCtx from "lib/logger/logger"; -import { Game, integer, Playtypes } from "tachi-common"; +import { Game, integer, Playtype, Playtypes } from "tachi-common"; const logger = CreateLogCtx(__filename); /** * Create GameSettings for a UGPT (which contains their preferences). */ -export async function CreateGameSettings(userID: integer, game: Game, playtype: Playtypes[Game]) { +export async function CreateGameSettings(userID: integer, game: Game, playtype: Playtype) { const exists = await db["game-settings"].findOne({ userID, game, diff --git a/server/src/lib/score-import/framework/calculated-data/stats.ts b/server/src/lib/score-import/framework/calculated-data/stats.ts index b3f141a6d..618ef7425 100644 --- a/server/src/lib/score-import/framework/calculated-data/stats.ts +++ b/server/src/lib/score-import/framework/calculated-data/stats.ts @@ -1,5 +1,13 @@ import { KtLogger } from "lib/logger/logger"; -import { ChartDocument, Game, GetGamePTConfig, IIDX_LAMPS, integer, Playtypes } from "tachi-common"; +import { + ChartDocument, + Game, + GetGamePTConfig, + IIDX_LAMPS, + integer, + Playtype, + Playtypes, +} from "tachi-common"; import { DryScore } from "../common/types"; /** @@ -133,7 +141,7 @@ const ratingParameters = { export function CalculateKTRating( dryScore: DryScore, game: "ddr" | "museca", - playtype: Playtypes[Game], + playtype: Playtype, chart: ChartDocument, logger: KtLogger ) { @@ -193,7 +201,7 @@ export function CalculateKTLampRatingIIDXDP(dryScore: DryScore, chart: ChartDocu function LampRatingNoTierlistInfo( dryScore: DryScore, game: Game, - playtype: Playtypes[Game], + playtype: Playtype, chart: ChartDocument ) { const gptConfig = GetGamePTConfig(game, playtype); diff --git a/server/src/lib/score-import/framework/common/score-utils.ts b/server/src/lib/score-import/framework/common/score-utils.ts index e2070f9c6..70c4c0b90 100644 --- a/server/src/lib/score-import/framework/common/score-utils.ts +++ b/server/src/lib/score-import/framework/common/score-utils.ts @@ -7,7 +7,7 @@ import { GetGamePTConfig, Grades, IDStrings, - Playtypes, + Playtype, } from "tachi-common"; import { InternalFailure, InvalidScoreFailure } from "./converter-failures"; @@ -18,7 +18,7 @@ const logger = CreateLogCtx(__filename); */ export function GetGradeFromPercent( game: Game, - playtype: Playtypes[Game], + playtype: Playtype, percent: number ): Grades[I] { const gptConfig = GetGamePTConfig(game, playtype); @@ -101,7 +101,7 @@ export function GenericCalculatePercent(game: Game, score: number, chart?: Chart */ export function ValidatePercent( game: Game, - playtype: Playtypes[Game], + playtype: Playtype, percent: number, chart: ChartDocument ) { @@ -177,7 +177,7 @@ export function JubeatGetGrade(score: number): Grades["jubeat:Single"] { */ export function CalculateESDForGame( game: Game, - playtype: Playtypes[Game], + playtype: Playtype, percent: number ): number | null { const gptConfig = GetGamePTConfig(game, playtype); diff --git a/server/src/lib/score-import/framework/common/string-asserts.ts b/server/src/lib/score-import/framework/common/string-asserts.ts index 068c75537..67e3bc8f4 100644 --- a/server/src/lib/score-import/framework/common/string-asserts.ts +++ b/server/src/lib/score-import/framework/common/string-asserts.ts @@ -1,9 +1,9 @@ -import { Difficulties, Game, GetGamePTConfig, IDStrings, Playtypes } from "tachi-common"; +import { Difficulties, Game, GetGamePTConfig, IDStrings, Playtype, Playtypes } from "tachi-common"; import { InvalidScoreFailure } from "./converter-failures"; export function AssertStrAsDifficulty( strVal: string, game: Game, - playtype: Playtypes[Game] + playtype: Playtype ): Difficulties[IDStrings] { const validDifficulties = GetGamePTConfig(game, playtype).difficulties; diff --git a/server/src/lib/score-import/framework/common/types.ts b/server/src/lib/score-import/framework/common/types.ts index 9e8fb4e0b..e2abb7d63 100644 --- a/server/src/lib/score-import/framework/common/types.ts +++ b/server/src/lib/score-import/framework/common/types.ts @@ -1,4 +1,4 @@ -import { IDStrings, ScoreDocument, Playtypes, Game } from "tachi-common"; +import { IDStrings, ScoreDocument, Playtype, Game } from "tachi-common"; /** * An intermediate score format that will be filled out by @@ -11,4 +11,4 @@ export type DryScore = Pick< scoreData: Omit["scoreData"], "gradeIndex" | "lampIndex" | "esd">; }; -export type ScorePlaytypeMap = Partial>; +export type ScorePlaytypeMap = Partial>; diff --git a/server/src/lib/score-import/framework/milestones/milestones.ts b/server/src/lib/score-import/framework/milestones/milestones.ts index da49ee84a..2fde5e0f4 100644 --- a/server/src/lib/score-import/framework/milestones/milestones.ts +++ b/server/src/lib/score-import/framework/milestones/milestones.ts @@ -8,7 +8,7 @@ import { integer, MilestoneDocument, MilestoneImportInfo, - Playtypes, + Playtype, MilestoneSubscriptionDocument, } from "tachi-common"; import { CalculateMilestoneOutOf, GetGoalIDsFromMilestone } from "lib/targets/milestones"; @@ -52,7 +52,7 @@ export function ProcessMilestoneFromGII( export async function UpdateUsersMilestones( importGoalInfo: GoalImportInfo[], game: Game, - playtypes: Playtypes[Game][], + playtypes: Playtype[], userID: integer, logger: KtLogger ) { @@ -157,7 +157,7 @@ export async function UpdateUsersMilestones( async function GetRelevantMilestones( goalIDs: string[], game: Game, - playtypes: Playtypes[Game][], + playtypes: Playtype[], userID: integer, logger: KtLogger ) { diff --git a/server/src/lib/score-import/framework/score-importing/score-import-main.ts b/server/src/lib/score-import/framework/score-importing/score-import-main.ts index 7513438c4..8395f613f 100644 --- a/server/src/lib/score-import/framework/score-importing/score-import-main.ts +++ b/server/src/lib/score-import/framework/score-importing/score-import-main.ts @@ -9,7 +9,7 @@ import { ImportProcessingInfo, ImportTypes, integer, - Playtypes, + Playtype, PublicUserDocument, } from "tachi-common"; import { GetMillisecondsSince } from "utils/misc"; @@ -303,7 +303,7 @@ export async function HandlePostImportSteps( logger.debug(`PB Processing took ${pbTime} milliseconds (${pbTimeRel}ms/doc)`); - const playtypes = Object.keys(scorePlaytypeMap) as Playtypes[Game][]; + const playtypes = Object.keys(scorePlaytypeMap) as Playtype[]; SetJobProgress(job, "Updating profile statistics."); @@ -368,7 +368,7 @@ export async function HandlePostImportSteps( */ async function UpdateUsersGameStats( game: Game, - modifiedPlaytypes: Playtypes[Game][], + modifiedPlaytypes: Playtype[], userID: integer, classHandler: ClassHandler | null, logger: KtLogger diff --git a/server/src/lib/score-import/framework/sessions/calculated-data.ts b/server/src/lib/score-import/framework/sessions/calculated-data.ts index e1ba05774..92c637166 100644 --- a/server/src/lib/score-import/framework/sessions/calculated-data.ts +++ b/server/src/lib/score-import/framework/sessions/calculated-data.ts @@ -1,4 +1,4 @@ -import { Game, Playtypes, ScoreDocument, SessionDocument } from "tachi-common"; +import { Game, Playtype, Playtypes, ScoreDocument, SessionDocument } from "tachi-common"; type ScoreCalculatedDataOnly = Pick; @@ -146,7 +146,7 @@ const CalculatedDataFunctions: CalculatedDataFunctions = { export function CreateSessionCalcData( game: Game, - playtype: Playtypes[Game], + playtype: Playtype, scoreCalcData: ScoreCalculatedDataOnly[] ): SessionDocument["calculatedData"] { // @ts-expect-error standard game->pt stuff. diff --git a/server/src/lib/score-import/framework/sessions/sessions.ts b/server/src/lib/score-import/framework/sessions/sessions.ts index b5dc603c3..619cb550d 100644 --- a/server/src/lib/score-import/framework/sessions/sessions.ts +++ b/server/src/lib/score-import/framework/sessions/sessions.ts @@ -6,7 +6,7 @@ import { ImportTypes, integer, PBScoreDocument, - Playtypes, + Playtype, ScoreDocument, SessionDocument, SessionInfoReturn, @@ -38,7 +38,7 @@ export async function CreateSessions( importType, scores, game, - playtype as Playtypes[Game], + playtype as Playtype, logger ); @@ -112,7 +112,7 @@ function CreateSession( groupInfo: SessionScoreInfo[], groupScores: ScoreDocument[], game: Game, - playtype: Playtypes[Game] + playtype: Playtype ): SessionDocument { const name = GenerateRandomSessionName(); @@ -141,7 +141,7 @@ export async function LoadScoresIntoSessions( importType: ImportTypes, importScores: ScoreDocument[], game: Game, - playtype: Playtypes[Game], + playtype: Playtype, baseLogger: KtLogger ): Promise { const logger = AppendLogCtx("Session Generation", baseLogger); diff --git a/server/src/lib/score-import/framework/user-game-stats/builtin-class-handlers.ts b/server/src/lib/score-import/framework/user-game-stats/builtin-class-handlers.ts index aee714ad7..886784a24 100644 --- a/server/src/lib/score-import/framework/user-game-stats/builtin-class-handlers.ts +++ b/server/src/lib/score-import/framework/user-game-stats/builtin-class-handlers.ts @@ -7,12 +7,12 @@ import { WACCA_COLOURS, } from "lib/constants/classes"; import { KtLogger } from "lib/logger/logger"; -import { Game, integer, Playtypes, ScoreCalculatedDataLookup } from "tachi-common"; +import { Game, integer, Playtype, Playtypes, ScoreCalculatedDataLookup } from "tachi-common"; import { GameClasses } from "tachi-common/js/game-classes"; export function CalculateSDVXClass( game: Game, - playtype: Playtypes[Game], + playtype: Playtype, userID: integer, ratings: Partial>, logger: KtLogger @@ -51,7 +51,7 @@ export function SDVXVF6ToClass(vf: number, logger: KtLogger) { export function CalculateGitadoraColour( game: Game, - playtype: Playtypes[Game], + playtype: Playtype, userID: integer, ratings: Record, logger: KtLogger @@ -103,7 +103,7 @@ export function GitadoraSkillToColour(sk: number) { export function CalculateWACCAColour( game: Game, - playtype: Playtypes[Game], + playtype: Playtype, userID: integer, ratings: Record ) { @@ -136,7 +136,7 @@ function WACCARateToColour(rate: number) { export function CalculatePopnClass( game: Game, - playtype: Playtypes[Game], + playtype: Playtype, userID: integer, ratings: Record ) { @@ -167,7 +167,7 @@ function PopnClassPointsToClass(points: number) { export function CalculateChunithmColour( game: Game, - playtype: Playtypes[Game], + playtype: Playtype, userID: integer, ratings: Record ) { @@ -202,7 +202,7 @@ function ChuniRatingToColour(rating: number) { export function CalculateJubeatColour( game: Game, - playtype: Playtypes[Game], + playtype: Playtype, userID: integer, ratings: Record ) { diff --git a/server/src/lib/score-import/framework/user-game-stats/classes.ts b/server/src/lib/score-import/framework/user-game-stats/classes.ts index 6a538687f..f51f1124c 100644 --- a/server/src/lib/score-import/framework/user-game-stats/classes.ts +++ b/server/src/lib/score-import/framework/user-game-stats/classes.ts @@ -2,7 +2,15 @@ import deepmerge from "deepmerge"; import db from "external/mongo/db"; import { KtLogger } from "lib/logger/logger"; import { EmitWebhookEvent } from "lib/webhooks/webhooks"; -import { ClassDelta, Game, IDStrings, integer, Playtypes, UserGameStats } from "tachi-common"; +import { + ClassDelta, + Game, + IDStrings, + integer, + Playtype, + Playtypes, + UserGameStats, +} from "tachi-common"; import { GameClasses } from "tachi-common/js/game-classes"; import { ReturnClassIfGreater } from "utils/class"; import { @@ -84,7 +92,7 @@ const STATIC_CLASS_HANDLERS: ClassHandlerMap = { */ export async function UpdateUGSClasses( game: Game, - playtype: Playtypes[Game], + playtype: Playtype, userID: integer, ratings: Record, ClassHandler: ClassHandler | null, @@ -123,7 +131,7 @@ export async function UpdateUGSClasses( */ export async function ProcessClassDeltas( game: Game, - playtype: Playtypes[Game], + playtype: Playtype, classes: ScoreClasses, userGameStats: UserGameStats | null, userID: integer, diff --git a/server/src/lib/score-import/framework/user-game-stats/rating.ts b/server/src/lib/score-import/framework/user-game-stats/rating.ts index 59bd61d77..97a642a5a 100644 --- a/server/src/lib/score-import/framework/user-game-stats/rating.ts +++ b/server/src/lib/score-import/framework/user-game-stats/rating.ts @@ -6,6 +6,7 @@ import { IDStrings, UserGameStats, PBScoreDocument, + Playtype, } from "tachi-common"; import db from "external/mongo/db"; import { KtLogger } from "lib/logger/logger"; @@ -13,7 +14,7 @@ import { KtLogger } from "lib/logger/logger"; type CustomCalcNames = ScoreCalculatedDataLookup[IDStrings]; function LazySumAll(key: CustomCalcNames) { - return async (game: Game, playtype: Playtypes[Game], userID: integer) => { + return async (game: Game, playtype: Playtype, userID: integer) => { const sc = await db["personal-bests"].find({ game: game, playtype: playtype, @@ -49,7 +50,7 @@ function LazyCalcN( returnMean = false, nullIfNotEnoughScores = false ) { - return async (game: Game, playtype: Playtypes[Game], userID: integer) => { + return async (game: Game, playtype: Playtype, userID: integer) => { const sc = await db["personal-bests"].find( { game: game, @@ -91,7 +92,7 @@ type RatingFunctions = { [G in Game]: { [P in Playtypes[G]]: ( game: Game, - playtype: Playtypes[Game], + playtype: Playtype, userID: integer, logger: KtLogger ) => Promise; @@ -194,7 +195,7 @@ const RatingFunctions: RatingFunctions = { export function CalculateRatings( game: Game, - playtype: Playtypes[Game], + playtype: Playtype, userID: integer, logger: KtLogger ): Promise>> { @@ -205,7 +206,7 @@ export function CalculateRatings( // Wacca has a funny algorithm for rate involving gitadora-style latest chart bonuses, async function CalculateWACCARate( game: Game, - playtype: Playtypes[Game], + playtype: Playtype, userID: integer, logger: KtLogger ) { @@ -267,7 +268,7 @@ async function CalculateWACCARate( async function CalculateGitadoraSkill( game: Game, - playtype: Playtypes[Game], + playtype: Playtype, userID: integer, logger: KtLogger ) { @@ -300,7 +301,7 @@ export async function GetBestRatingOnSongs( songIDs: integer[], userID: integer, game: Game, - playtype: Playtypes[Game], + playtype: Playtype, ratingProp: "skill", limit = 25 ): Promise { @@ -334,7 +335,7 @@ export async function GetBestRatingOnSongs( async function CalculateJubility( game: Game, - playtype: Playtypes[Game], + playtype: Playtype, userID: integer, logger: KtLogger ): Promise { diff --git a/server/src/lib/score-import/framework/user-game-stats/types.ts b/server/src/lib/score-import/framework/user-game-stats/types.ts index f16dbfdda..e160f57d3 100644 --- a/server/src/lib/score-import/framework/user-game-stats/types.ts +++ b/server/src/lib/score-import/framework/user-game-stats/types.ts @@ -1,5 +1,5 @@ import { KtLogger } from "lib/logger/logger"; -import { Game, IDStrings, integer, Playtypes } from "tachi-common"; +import { Game, IDStrings, integer, Playtype, Playtypes } from "tachi-common"; import { GameClasses } from "tachi-common/js/game-classes"; export type ScoreClasses = Partial>; @@ -7,7 +7,7 @@ export type ScoreClasses = Partial>; export interface ClassHandler { ( game: Game, - playtype: Playtypes[Game], + playtype: Playtype, userID: integer, ratings: Record, logger: KtLogger diff --git a/server/src/lib/score-import/framework/user-game-stats/update-ugs.ts b/server/src/lib/score-import/framework/user-game-stats/update-ugs.ts index ee0742857..a497b9189 100644 --- a/server/src/lib/score-import/framework/user-game-stats/update-ugs.ts +++ b/server/src/lib/score-import/framework/user-game-stats/update-ugs.ts @@ -5,14 +5,14 @@ import db from "external/mongo/db"; import { CreateGameSettings } from "lib/game-settings/create-game-settings"; import { KtLogger } from "lib/logger/logger"; -import { ClassDelta, Game, integer, Playtypes, UserGameStats } from "tachi-common"; +import { ClassDelta, Game, integer, Playtype, UserGameStats } from "tachi-common"; import { ProcessClassDeltas, UpdateUGSClasses } from "./classes"; import { CalculateRatings } from "./rating"; import { ClassHandler } from "./types"; export async function UpdateUsersGamePlaytypeStats( game: Game, - playtype: Playtypes[Game], + playtype: Playtype, userID: integer, classHandler: ClassHandler | null, logger: KtLogger diff --git a/server/src/lib/score-import/import-types/common/batch-manual/parser.ts b/server/src/lib/score-import/import-types/common/batch-manual/parser.ts index ffecb7ac8..53390bfad 100644 --- a/server/src/lib/score-import/import-types/common/batch-manual/parser.ts +++ b/server/src/lib/score-import/import-types/common/batch-manual/parser.ts @@ -9,6 +9,7 @@ import { GetGameConfig, GetGamePTConfig, ImportTypes, + Playtype, Playtypes, } from "tachi-common"; import { FormatPrError } from "utils/prudence"; @@ -39,7 +40,7 @@ const PR_DPRandom = (self: unknown) => { return true; }; -const PR_ScoreMeta = (game: Game, playtype: Playtypes[Game]): PrudenceSchema => { +const PR_ScoreMeta = (game: Game, playtype: Playtype): PrudenceSchema => { if (game === "iidx") { const random = playtype === "SP" @@ -148,7 +149,7 @@ const PR_HitMeta = (game: Game): PrudenceSchema => { return {}; }; -const PR_BatchManualScore = (game: Game, playtype: Playtypes[Game]): PrudenceSchema => { +const PR_BatchManualScore = (game: Game, playtype: Playtype): PrudenceSchema => { const gptConfig = GetGamePTConfig(game, playtype); return { score: p.isPositiveInteger, @@ -228,7 +229,7 @@ const PR_BatchManualClasses = (game: Game): PrudenceSchema => { } }; -const PR_BatchManual = (game: Game, playtype: Playtypes[Game]): PrudenceSchema => ({ +const PR_BatchManual = (game: Game, playtype: Playtype): PrudenceSchema => ({ meta: { service: p.isBoundedString(3, 15), game: p.isIn(TachiConfig.GAMES), @@ -302,7 +303,7 @@ export function ParseBatchManualFromObject( ); } - const playtype: Playtypes[Game] = possiblyPlaytype; + const playtype: Playtype = possiblyPlaytype; // now that we have the game, we can validate this against // the prudence schema for batch-manual. diff --git a/server/src/lib/score-import/import-types/common/batch-manual/types.ts b/server/src/lib/score-import/import-types/common/batch-manual/types.ts index 42f10dff8..ac4f96b85 100644 --- a/server/src/lib/score-import/import-types/common/batch-manual/types.ts +++ b/server/src/lib/score-import/import-types/common/batch-manual/types.ts @@ -1,8 +1,8 @@ -import { Game, GPTSupportedVersions, IDStrings, Playtypes } from "tachi-common"; +import { Game, GPTSupportedVersions, IDStrings, Playtype, Playtypes } from "tachi-common"; export interface BatchManualContext { game: Game; - playtype: Playtypes[Game]; + playtype: Playtype; service: string; version: GPTSupportedVersions[IDStrings] | null; } diff --git a/server/src/lib/score-import/import-types/ir/fervidex-static/class-handler.test.ts b/server/src/lib/score-import/import-types/ir/fervidex-static/class-handler.test.ts index 00caf6418..225e3a1a3 100644 --- a/server/src/lib/score-import/import-types/ir/fervidex-static/class-handler.test.ts +++ b/server/src/lib/score-import/import-types/ir/fervidex-static/class-handler.test.ts @@ -53,7 +53,7 @@ t.test("#FerStaticClassHandler", (t) => { t.test("Should skip if playtype is invalid", (t) => { const fn = CreateFerStaticClassHandler({ sp_dan: 5, dp_dan: 7 }); - const res = fn("iidx", "INVALID" as Playtypes[Game], 1, {}, logger); + const res = fn("iidx", "INVALID" as Playtype, 1, {}, logger); t.equal(res, undefined, "Should skip over as a failsafe."); diff --git a/server/src/lib/score-mutation/delete-scores.ts b/server/src/lib/score-mutation/delete-scores.ts index 42e19de28..c94716a88 100644 --- a/server/src/lib/score-mutation/delete-scores.ts +++ b/server/src/lib/score-mutation/delete-scores.ts @@ -4,7 +4,7 @@ import CreateLogCtx from "lib/logger/logger"; import { UpdateChartRanking } from "lib/score-import/framework/pb/create-pb-doc"; import { ProcessPBs } from "lib/score-import/framework/pb/process-pbs"; import { UpdateUsersGamePlaytypeStats } from "lib/score-import/framework/user-game-stats/update-ugs"; -import { Game, Playtypes, ScoreDocument } from "tachi-common"; +import { Game, Playtype, ScoreDocument } from "tachi-common"; const logger = CreateLogCtx(__filename); @@ -216,7 +216,7 @@ export async function DeleteMultipleScores(scores: ScoreDocument[], blacklist = const ugpts = [...new Set(scores.map((e) => `${e.game}-${e.playtype}-${e.userID}`))]; for (const ugpt of ugpts) { - const [game, playtype, strUserID] = ugpt.split("-") as [Game, Playtypes[Game], string]; + const [game, playtype, strUserID] = ugpt.split("-") as [Game, Playtype, string]; const userID = Number(strUserID); diff --git a/server/src/lib/search/search.ts b/server/src/lib/search/search.ts index dfb299ca1..6b78aae08 100644 --- a/server/src/lib/search/search.ts +++ b/server/src/lib/search/search.ts @@ -8,6 +8,7 @@ import { ChartDocument, Game, integer, + Playtype, Playtypes, PublicUserDocument, SessionDocument, @@ -77,7 +78,7 @@ export function SearchGameSongs( export async function SearchGameSongsAndCharts( game: Game, search: string, - playtype?: Playtypes[Game], + playtype?: Playtype, limit = 100 ) { const songs = await SearchGameSongs(game, search, limit); @@ -98,7 +99,7 @@ export async function SearchGameSongsAndCharts( export function SearchSessions( search: string, game?: Game, - playtype?: Playtypes[Game], + playtype?: Playtype, userID?: integer, limit = 100 ) { diff --git a/server/src/lib/showcase/get-stats.ts b/server/src/lib/showcase/get-stats.ts index 4ddbfc382..a15e5be64 100644 --- a/server/src/lib/showcase/get-stats.ts +++ b/server/src/lib/showcase/get-stats.ts @@ -1,5 +1,5 @@ import db from "external/mongo/db"; -import { integer, Game, Playtypes, ShowcaseStatDetails } from "tachi-common"; +import { integer, Game, Playtype, ShowcaseStatDetails } from "tachi-common"; import CreateLogCtx from "lib/logger/logger"; import { EvaluateShowcaseStat } from "./evaluator"; import { GetRelatedStatDocuments } from "./get-related"; @@ -14,7 +14,7 @@ const logger = CreateLogCtx(__filename); export async function EvaluateUsersStatsShowcase( userID: integer, game: Game, - playtype: Playtypes[Game], + playtype: Playtype, projectUserStats?: integer ) { const getSettingsID = projectUserStats ?? userID; diff --git a/server/src/lib/targets/goal-utils.ts b/server/src/lib/targets/goal-utils.ts index 3141534bf..2dc750181 100644 --- a/server/src/lib/targets/goal-utils.ts +++ b/server/src/lib/targets/goal-utils.ts @@ -6,6 +6,7 @@ import { Game, GetGamePTConfig, GoalDocument, + Playtype, Playtypes, } from "tachi-common"; import { GetFolderForIDGuaranteed, HumaniseChartID } from "utils/db"; @@ -16,7 +17,7 @@ export async function CreateGoalTitle( charts: GoalDocument["charts"], criteria: GoalDocument["criteria"], game: Game, - playtype: Playtypes[Game] + playtype: Playtype ) { const formattedCriteria = FormatCriteria(criteria, game, playtype); @@ -83,7 +84,7 @@ async function FormatCharts(charts: GoalDocument["charts"], game: Game) { } } -function FormatCriteria(criteria: GoalDocument["criteria"], game: Game, playtype: Playtypes[Game]) { +function FormatCriteria(criteria: GoalDocument["criteria"], game: Game, playtype: Playtype) { const gptConfig = GetGamePTConfig(game, playtype); switch (criteria.key) { @@ -109,7 +110,7 @@ export async function ValidateGoalChartsAndCriteria( charts: GoalDocument["charts"], criteria: GoalDocument["criteria"], game: Game, - playtype: Playtypes[Game] + playtype: Playtype ) { let chartCount = 0; // Validating the charts supplied diff --git a/server/src/lib/targets/goals.ts b/server/src/lib/targets/goals.ts index cb4b87d3b..459c4332b 100644 --- a/server/src/lib/targets/goals.ts +++ b/server/src/lib/targets/goals.ts @@ -9,7 +9,7 @@ import { GoalDocument, integer, PBScoreDocument, - Playtypes, + Playtype, GoalSubscriptionDocument, MilestoneSubscriptionDocument, MilestoneDocument, @@ -42,7 +42,7 @@ export function CreateGoalID( charts: GoalDocument["charts"], criteria: GoalDocument["criteria"], game: Game, - playtype: Playtypes[Game] + playtype: Playtype ) { return `G${fjsh.hash({ charts, criteria, game, playtype }, "sha256")}`; } @@ -218,7 +218,7 @@ type PBWithBadPoor = PBScoreDocument< export function HumaniseGoalProgress( game: Game, - playtype: Playtypes[Game], + playtype: Playtype, key: GoalKeys, value: number, userPB: PBScoreDocument | null @@ -268,7 +268,7 @@ export async function ConstructGoal( charts: GoalDocument["charts"], criteria: GoalDocument["criteria"], game: Game, - playtype: Playtypes[Game] + playtype: Playtype ): Promise { // Throws if the charts or criteria are invalid somehow. await ValidateGoalChartsAndCriteria(charts, criteria, game, playtype); diff --git a/server/src/server/router/api/v1/games/_game/_playtype/middleware.ts b/server/src/server/router/api/v1/games/_game/_playtype/middleware.ts index c2776bec5..422e1d4ed 100644 --- a/server/src/server/router/api/v1/games/_game/_playtype/middleware.ts +++ b/server/src/server/router/api/v1/games/_game/_playtype/middleware.ts @@ -1,4 +1,4 @@ -import { Game, GetGameConfig, Playtypes } from "tachi-common"; +import { Game, GetGameConfig, Playtype, Playtypes } from "tachi-common"; import { RequestHandler } from "express"; import { SYMBOL_TachiData } from "lib/constants/tachi"; import { AssignToReqTachiData } from "utils/req-tachi-data"; @@ -8,14 +8,14 @@ export const ValidatePlaytypeFromParam: RequestHandler = (req, res, next) => { const gameConfig = GetGameConfig(game); - if (!gameConfig.validPlaytypes.includes(req.params.playtype as Playtypes[Game])) { + if (!gameConfig.validPlaytypes.includes(req.params.playtype as Playtype)) { return res.status(400).json({ success: false, description: `The playtype ${req.params.playtype} is not supported.`, }); } - AssignToReqTachiData(req, { playtype: req.params.playtype as Playtypes[Game] }); + AssignToReqTachiData(req, { playtype: req.params.playtype as Playtype }); return next(); }; diff --git a/server/src/server/router/api/v1/games/_game/_playtype/router.ts b/server/src/server/router/api/v1/games/_game/_playtype/router.ts index 6ea578348..33ee83f5c 100644 --- a/server/src/server/router/api/v1/games/_game/_playtype/router.ts +++ b/server/src/server/router/api/v1/games/_game/_playtype/router.ts @@ -5,7 +5,15 @@ import { FindOptions } from "monk"; import NodeCache from "node-cache"; import p from "prudence"; import prValidate from "server/middleware/prudence-validate"; -import { FormatGame, Game, GetGamePTConfig, integer, Playtypes, UserGameStats } from "tachi-common"; +import { + FormatGame, + Game, + GetGamePTConfig, + integer, + Playtype, + Playtypes, + UserGameStats, +} from "tachi-common"; import { GetRelevantSongsAndCharts } from "utils/db"; import { IsString } from "utils/misc"; import { GetClassDistribution } from "utils/queries/stats"; @@ -32,7 +40,7 @@ const gptStatCache = new NodeCache(); async function GetGameStats( game: Game, - playtype: Playtypes[Game] + playtype: Playtype ): Promise<{ scoreCount: integer; playerCount: integer; chartCount: integer }> { const cacheRes = gptStatCache.get(`${game}:${playtype}`); diff --git a/server/src/utils/calculations/recalc-scores.ts b/server/src/utils/calculations/recalc-scores.ts index 8b80b5c90..2f91b97b6 100644 --- a/server/src/utils/calculations/recalc-scores.ts +++ b/server/src/utils/calculations/recalc-scores.ts @@ -1,6 +1,6 @@ /* eslint-disable no-await-in-loop */ import db from "external/mongo/db"; -import { Game, integer, Playtypes, PublicUserDocument } from "tachi-common"; +import { Game, integer, Playtype, Playtypes, PublicUserDocument } from "tachi-common"; import CreateLogCtx from "lib/logger/logger"; import { CreateCalculatedData } from "lib/score-import/framework/calculated-data/calculated-data"; import { UpdateUsersGamePlaytypeStats } from "lib/score-import/framework/user-game-stats/update-ugs"; @@ -67,13 +67,13 @@ export async function RecalcAllScores(filter = {}) { logger.info(`Updating Profiles for ${modifiedUsers.size} users...`); for (const userInfo of modifiedUsers.values()) { - const [game, playtype, strUserID] = userInfo.split("-") as [Game, Playtypes[Game], string]; + const [game, playtype, strUserID] = userInfo.split("-") as [Game, Playtype, string]; const userID = Number(strUserID); await UpdateUsersGamePlaytypeStats( game as Game, - playtype as Playtypes[Game], + playtype as Playtype, userID, null, logger diff --git a/server/src/utils/class.ts b/server/src/utils/class.ts index f2e00cf21..aae55e1f0 100644 --- a/server/src/utils/class.ts +++ b/server/src/utils/class.ts @@ -2,7 +2,7 @@ import db from "external/mongo/db"; import { CreateGameSettings } from "lib/game-settings/create-game-settings"; import CreateLogCtx from "lib/logger/logger"; import { EmitWebhookEvent } from "lib/webhooks/webhooks"; -import { Game, IDStrings, integer, Playtypes, UserGameStats } from "tachi-common"; +import { Game, IDStrings, integer, Playtype, UserGameStats } from "tachi-common"; import { GameClassSets } from "tachi-common/js/game-classes"; const logger = CreateLogCtx(__filename); @@ -35,7 +35,7 @@ export function ReturnClassIfGreater( export async function UpdateClassIfGreater( userID: integer, game: Game, - playtype: Playtypes[Game], + playtype: Playtype, classSet: GameClassSets[IDStrings], classVal: integer ) { diff --git a/server/src/utils/folder.ts b/server/src/utils/folder.ts index a81495cb9..e114eb7ab 100644 --- a/server/src/utils/folder.ts +++ b/server/src/utils/folder.ts @@ -10,6 +10,7 @@ import { FolderDocument, Playtypes, Game, + Playtype, } from "tachi-common"; import db from "external/mongo/db"; import CreateLogCtx from "lib/logger/logger"; @@ -264,19 +265,11 @@ export function GetGradeLampDistributionForFolders(userID: integer, folders: Fol return Promise.all(folders.map((f) => GetGradeLampDistributionForFolder(userID, f))); } -export function CreateFolderID( - query: Record, - game: Game, - playtype: Playtypes[Game] -) { +export function CreateFolderID(query: Record, game: Game, playtype: Playtype) { return `F${fjsh.hash(Object.assign({ game, playtype }, query), "SHA256")}`; } -export async function GetRecentlyViewedFolders( - userID: integer, - game: Game, - playtype: Playtypes[Game] -) { +export async function GetRecentlyViewedFolders(userID: integer, game: Game, playtype: Playtype) { const views = await db["recent-folder-views"].find( { userID, diff --git a/server/src/utils/misc.ts b/server/src/utils/misc.ts index 1f0e81a49..921e13d1d 100644 --- a/server/src/utils/misc.ts +++ b/server/src/utils/misc.ts @@ -2,7 +2,7 @@ import { exec } from "child_process"; import crypto from "crypto"; import { ONE_HOUR } from "lib/constants/time"; import { TachiConfig } from "lib/setup/config"; -import { Game, GamePTConfig, GetGameConfig, integer, Playtypes } from "tachi-common"; +import { Game, GamePTConfig, GetGameConfig, integer, Playtype, Playtypes } from "tachi-common"; import { URL } from "url"; // https://github.com/sindresorhus/escape-string-regexp/blob/main/index.js @@ -68,8 +68,8 @@ export function IsValidGame(str: string): str is Game { return !!TachiConfig.GAMES.includes(str as Game); } -export function IsValidPlaytype(game: Game, str: string): str is Playtypes[Game] { - return GetGameConfig(game).validPlaytypes.includes(str as Playtypes[Game]); +export function IsValidPlaytype(game: Game, str: string): str is Playtype { + return GetGameConfig(game).validPlaytypes.includes(str as Playtype); } export function IsValidScoreAlg( diff --git a/server/src/utils/queries/charts.ts b/server/src/utils/queries/charts.ts index 412ac396f..9759b8639 100644 --- a/server/src/utils/queries/charts.ts +++ b/server/src/utils/queries/charts.ts @@ -7,6 +7,7 @@ import { GPTSupportedVersions, IDStrings, integer, + Playtype, Playtypes, } from "tachi-common"; @@ -69,7 +70,7 @@ export function FindChartWithPTDFVersion< export function FindDDRChartOnSongHash( songHash: string, // Technically both of these should be "ddr" instead of Game, but it proves hard to work with. - playtype: Playtypes[Game], + playtype: Playtype, difficulty: Difficulties[IDStrings] ) { // note: this only works on accident because monk @@ -99,7 +100,7 @@ export function FindBMSChartOnHash(hash: string) { export function FindChartOnInGameID( game: Game, inGameID: number, - playtype: Playtypes[Game], + playtype: Playtype, difficulty: Difficulties[IDStrings] ) { if (game === "bms" || game === "usc") { @@ -119,7 +120,7 @@ export function FindChartOnInGameID( */ export function FindIIDXChartOnInGameID( inGameID: number, - playtype: Playtypes[Game], + playtype: Playtype, difficulty: Difficulties[IDStrings] ) { return db.charts.iidx.findOne({ @@ -137,7 +138,7 @@ export function FindIIDXChartOnInGameID( */ export function FindIIDXChartOnInGameIDVersion( inGameID: number, - playtype: Playtypes[Game], + playtype: Playtype, difficulty: Difficulties[IDStrings], version: GPTSupportedVersions[IDStrings] ) { @@ -156,7 +157,7 @@ export function FindIIDXChartOnInGameIDVersion( export function FindChartOnInGameIDVersion( game: Game, inGameID: number, - playtype: Playtypes[Game], + playtype: Playtype, difficulty: Difficulties[I], version: GPTSupportedVersions[I] ) { @@ -243,7 +244,7 @@ export function FindChartOnSHA256(game: Game, hash: string) { }); } -export function FindChartOnSHA256Playtype(game: Game, hash: string, playtype: Playtypes[Game]) { +export function FindChartOnSHA256Playtype(game: Game, hash: string, playtype: Playtype) { if (game !== "bms" && game !== "usc" && game !== "iidx" && game !== "pms") { throw new Error(`Cannot call FindChartOnSHA256 for game ${game}.`); } @@ -267,7 +268,7 @@ export function FindChartOnARCID(game: "iidx" | "ddr" | "jubeat" | "sdvx", arcID */ export async function FindChartsOnPopularity( game: Game, - playtype: Playtypes[Game], + playtype: Playtype, songIDs?: integer[], skip = 0, limit = 100, diff --git a/server/src/utils/queries/stats.ts b/server/src/utils/queries/stats.ts index 16c8de85a..72506a00e 100644 --- a/server/src/utils/queries/stats.ts +++ b/server/src/utils/queries/stats.ts @@ -1,13 +1,13 @@ import db from "external/mongo/db"; import { ONE_HOUR } from "lib/constants/time"; import NodeCache from "node-cache"; -import { Game, gameClasses, IDStrings, integer, Playtypes } from "tachi-common"; +import { Game, gameClasses, IDStrings, integer, Playtype, Playtypes } from "tachi-common"; const classDistCache = new NodeCache(); export async function GetClassDistribution( game: Game, - playtype: Playtypes[Game], + playtype: Playtype, className: gameClasses.GameClassSets[IDStrings] ) { const cacheKey = `${game}:${playtype}:${className}`; diff --git a/server/src/utils/reset-state/destroy-ugpt.ts b/server/src/utils/reset-state/destroy-ugpt.ts index 6b0b40a40..ea951155e 100644 --- a/server/src/utils/reset-state/destroy-ugpt.ts +++ b/server/src/utils/reset-state/destroy-ugpt.ts @@ -1,5 +1,5 @@ import db from "external/mongo/db"; -import { integer, Game, Playtypes } from "tachi-common"; +import { integer, Game, Playtypes, Playtype } from "tachi-common"; import { UpdateAllPBs } from "utils/calculations/recalc-scores"; /** @@ -10,7 +10,7 @@ import { UpdateAllPBs } from "utils/calculations/recalc-scores"; export default async function DestroyUserGamePlaytypeData( userID: integer, game: Game, - playtype: Playtypes[Game] + playtype: Playtype ) { await db["game-stats-snapshots"].remove({ userID, diff --git a/server/src/utils/string-checks.ts b/server/src/utils/string-checks.ts index e40fe2087..957723400 100644 --- a/server/src/utils/string-checks.ts +++ b/server/src/utils/string-checks.ts @@ -1,4 +1,4 @@ -import { Game, GamePTConfig, GetGamePTConfig, Playtypes } from "tachi-common"; +import { Game, GamePTConfig, GetGamePTConfig, Playtype, Playtypes } from "tachi-common"; import { IsString } from "./misc"; const isIntegerRegex = /^-?\d+$/u; @@ -47,7 +47,7 @@ export type ProfileRatingAlgs = GamePTConfig["defaultProfileRatingAlg"]; export type ScoreRatingAlgs = GamePTConfig["defaultScoreRatingAlg"]; export type SessionRatingAlgs = GamePTConfig["defaultSessionRatingAlg"]; -export function CheckStrProfileAlg(game: Game, playtype: Playtypes[Game], strVal: string) { +export function CheckStrProfileAlg(game: Game, playtype: Playtype, strVal: string) { const gptConfig = GetGamePTConfig(game, playtype); // @hack @@ -58,7 +58,7 @@ export function CheckStrProfileAlg(game: Game, playtype: Playtypes[Game], strVal return strVal as ProfileRatingAlgs; } -export function CheckStrScoreAlg(game: Game, playtype: Playtypes[Game], strVal: string) { +export function CheckStrScoreAlg(game: Game, playtype: Playtype, strVal: string) { const gptConfig = GetGamePTConfig(game, playtype); // @hack @@ -69,7 +69,7 @@ export function CheckStrScoreAlg(game: Game, playtype: Playtypes[Game], strVal: return strVal as ScoreRatingAlgs; } -export function CheckStrSessionAlg(game: Game, playtype: Playtypes[Game], strVal: string) { +export function CheckStrSessionAlg(game: Game, playtype: Playtype, strVal: string) { const gptConfig = GetGamePTConfig(game, playtype); // @hack diff --git a/server/src/utils/types.ts b/server/src/utils/types.ts index 893334f39..d77c5e075 100644 --- a/server/src/utils/types.ts +++ b/server/src/utils/types.ts @@ -7,7 +7,7 @@ import { PublicUserDocument, UserGameStats, Game, - Playtypes, + Playtype, SongDocument, UserSettings, TachiAPIClientDocument, @@ -61,7 +61,7 @@ export interface TachiRequestData { requestedUser?: PublicUserDocument; requestedUserGameStats?: UserGameStats; game?: Game; - playtype?: Playtypes[Game]; + playtype?: Playtype; chartDoc?: ChartDocument; songDoc?: SongDocument; diff --git a/server/src/utils/user.ts b/server/src/utils/user.ts index 35b1bb0af..b36786ab0 100644 --- a/server/src/utils/user.ts +++ b/server/src/utils/user.ts @@ -6,7 +6,7 @@ import { GetGamePTConfig, IDStrings, integer, - Playtypes, + Playtype, PublicUserDocument, UGSRatingsLookup, UserGameStats, @@ -171,7 +171,7 @@ export async function GetUsersRanking(stats: UserGameStats) { return (aggRes[0].ranking + 1) as integer; } -export function GetUGPTPlaycount(userID: integer, game: Game, playtype: Playtypes[Game]) { +export function GetUGPTPlaycount(userID: integer, game: Game, playtype: Playtype) { return db.scores.count({ userID, game, playtype }); }