diff --git a/libs/constants/src/consts/map-tags.const.ts b/libs/constants/src/consts/map-tags.const.ts new file mode 100644 index 000000000..397ae0ba8 --- /dev/null +++ b/libs/constants/src/consts/map-tags.const.ts @@ -0,0 +1,80 @@ +import { Gamemode, GamemodeCategory, GamemodeToGamemodeCategory } from '../'; +import { ElementOf, ValueOf } from '../types/utils/util.type'; + +const GLOBAL_TAGS = ['Portals', 'Multiroute'] as const; + +// prettier-ignore +const GAMEMODE_TAGS = { + [GamemodeCategory.SURF]: [ + 'Unit', + 'Tech', + 'Spins', + 'Booster', + 'Headhit', + 'Bhop' + ] as const, + [GamemodeCategory.BHOP]: [ + 'Strafe', + 'Tech', + 'Fly', + 'Surf', + 'Weapons', + 'Spins' + ] as const, + [GamemodeCategory.CLIMB]: [ + 'Ladder' + ] as const, + [GamemodeCategory.RJ]: [ + 'Sync', + 'Wallpogo', + 'Speedshot', + 'Bounce', + 'Jurf', + 'Edgebug', + 'Wallbug', + 'Wallshot' + ] as const, + [GamemodeCategory.SJ]: [ + 'Airpogo', + 'Wallpogo', + 'Vert' + ] as const, + [GamemodeCategory.AHOP]: [ + 'HL2' + ] as const, + [GamemodeCategory.CONC]: [ + 'Prec', + 'Juggle', + 'Limited Ammo' + ] as const, + [GamemodeCategory.DEFRAG]: [ + 'Strafe', + 'Rocket Launcher', + 'Grenade Launcher', + 'Plasma Gun', + 'BFG', + 'Combo', + 'Haste', + 'Damageboost', + 'Climb', + 'Trick' + ] as const +}; + +// We could add support for individual subcategories (Gamemodes), but don't +// have a single example of one yet. + +/** + * Union of every possible tag in Momentum. + */ +export type MapTag = + | (typeof GLOBAL_TAGS)[number] + | ElementOf>; + +// TODO: BUMP DEPS, REMOVE SPREAD!! +export const MapTags: Map> = new Map( + [...GamemodeToGamemodeCategory.entries()].map(([gamemode, category]) => [ + gamemode, + new Set([...GLOBAL_TAGS, ...(GAMEMODE_TAGS[category] ?? [])]) as any + ]) +) as any; diff --git a/libs/constants/src/enums/gamemode.enum.ts b/libs/constants/src/enums/gamemode.enum.ts index 388116909..a27d2e701 100644 --- a/libs/constants/src/enums/gamemode.enum.ts +++ b/libs/constants/src/enums/gamemode.enum.ts @@ -30,3 +30,32 @@ export enum GamemodeCategory { CONC = 7, DEFRAG = 8 } + +// prettier-ignore +export const GamemodeCategoryToGamemode = new Map([ + [GamemodeCategory.SURF, [Gamemode.SURF]], + [GamemodeCategory.BHOP, [Gamemode.BHOP, Gamemode.BHOP_HL1]], + [GamemodeCategory.CLIMB, [Gamemode.CLIMB_MOM, Gamemode.CLIMB_KZT, Gamemode.CLIMB_16]], + [GamemodeCategory.RJ, [Gamemode.RJ]], + [GamemodeCategory.SJ, [Gamemode.SJ]], + [GamemodeCategory.AHOP, [Gamemode.AHOP]], + [GamemodeCategory.CONC, [Gamemode.CONC]], + [GamemodeCategory.DEFRAG, [Gamemode.DEFRAG_CPM, Gamemode.DEFRAG_VQ3, Gamemode.DEFRAG_VTG]] +]); + +// prettier-ignore +export const GamemodeToGamemodeCategory = new Map([ + [Gamemode.SURF, GamemodeCategory.SURF], + [Gamemode.BHOP, GamemodeCategory.BHOP], + [Gamemode.BHOP_HL1, GamemodeCategory.BHOP], + [Gamemode.CLIMB_MOM, GamemodeCategory.CLIMB], + [Gamemode.CLIMB_KZT, GamemodeCategory.CLIMB], + [Gamemode.CLIMB_16, GamemodeCategory.CLIMB], + [Gamemode.RJ, GamemodeCategory.RJ], + [Gamemode.SJ, GamemodeCategory.SJ], + [Gamemode.AHOP, GamemodeCategory.AHOP], + [Gamemode.CONC, GamemodeCategory.CONC], + [Gamemode.DEFRAG_CPM, GamemodeCategory.DEFRAG], + [Gamemode.DEFRAG_VQ3, GamemodeCategory.DEFRAG], + [Gamemode.DEFRAG_VTG, GamemodeCategory.DEFRAG] +]); diff --git a/libs/constants/src/index.ts b/libs/constants/src/index.ts index 2d711e82f..345d0ed3c 100644 --- a/libs/constants/src/index.ts +++ b/libs/constants/src/index.ts @@ -1,3 +1,4 @@ +export * from './consts/map-tags.const'; export * from './consts/jwt.const'; export * from './consts/appids.const'; export * from './consts/file-store-paths.const'; diff --git a/libs/constants/src/types/models/models.ts b/libs/constants/src/types/models/models.ts index ba72939ff..55b27b98f 100644 --- a/libs/constants/src/types/models/models.ts +++ b/libs/constants/src/types/models/models.ts @@ -15,9 +15,11 @@ import { AdminActivityType, KillswitchType, ReportType, - ReportCategory + ReportCategory, + MapTag, + Flags, + DateString } from '../../'; -import { Flags, DateString } from '../../'; // Collection of models used throughout the codebase, as well as in Panorama. // @@ -352,8 +354,6 @@ export interface MapSubmissionSuggestion { // TODO: Tags! } -export type MapTags = string[]; - export interface MapTestInvite { mapID: number; userID: number; @@ -456,7 +456,7 @@ export interface Leaderboard { tier: number | null; style: Style; type: LeaderboardType; - tags: MapTags; + tags: MapTag[]; linear: boolean; } diff --git a/libs/constants/src/types/utils/util.type.ts b/libs/constants/src/types/utils/util.type.ts new file mode 100644 index 000000000..86b32e8c8 --- /dev/null +++ b/libs/constants/src/types/utils/util.type.ts @@ -0,0 +1,13 @@ +/** + * Trivial types that are useful in many places. + * This package is exported to Panorama, which doesn't support type-fest, add + * here if needed. + */ + +export type ValueOf = T[keyof T]; +export type ElementOf = T extends (infer E)[] ? E : never; + +export type KeyOfMap = T extends Map ? K : never; +export type ValueOfMap = T extends Map ? V : never; + +export type ElementOfSet = T extends Set ? K : never;