import { FormatGame, Game, Playtypes, IDStrings, UGSRatingsLookup, GetGamePTConfig } from "tachi-common"; import { ProcessEnv } from "../setup"; import { PrependTachiUrl } from "./fetch-tachi"; export interface SimpleGameType { game: T; playtype: Playtypes[T]; } export const simpleGameTypeToString = (gpt: SimpleGameType): IDStrings => `${gpt.game}:${gpt.playtype}`; export const stringToSimpleGameType = (gptString: string): SimpleGameType => { return { game: gptString.split(":")[0], playtype: gptString.split(":")[1] }; }; export const formatGameWrapper = (gpt: SimpleGameType): string => FormatGame(gpt.game, gpt.playtype); export const capitalise = (s: string): string => (s && s[0].toUpperCase() + s.slice(1)) || ""; export const prettyRatingString = (rating: UGSRatingsLookup[I]): string => { return capitalise(rating); }; export const getPfpUrl = (userId: number): string => { if (ProcessEnv.ENV !== "prod") { return `https://kamaitachi.xyz/static/images/users/${userId}-pfp.png`; } return PrependTachiUrl(`/users/${userId}/pfp`); }; export const gameIdentifierStrings = [ "iidx:SP", "iidx:DP", "sdvx:Single", "usc:Single", "ddr:SP", "ddr:DP", "maimai:Single", "museca:Single", "bms:7K", "bms:14K", "chunithm:Single", "gitadora:Gita", "gitadora:Dora" ]; export const gamesToChoicesObject = (): [name: string, value: string][] => { return gameIdentifierStrings.map((identifier) => { return [formatGameWrapper(stringToSimpleGameType(identifier)), identifier]; }); }; export const formatGameScoreRating = ( gpt: SimpleGameType, ratingName: UGSRatingsLookup[I], value: number ): string => { const gptConfig = GetGamePTConfig(gpt.game, gpt.playtype); const val = gptConfig.profileRatingAlgFormatters[ratingName]; if (val) { return val(value); } return value.toFixed(2); };