51 lines
1.9 KiB
TypeScript
51 lines
1.9 KiB
TypeScript
import { parseServerName, T5_ZOMBIE_MAPS, T6_ZOMBIE_MAPS, zombieMaps } from '../map-aliases.js';
|
|
|
|
export function gameTitle(game: string | null | undefined, compact = false): string {
|
|
if (game?.toLowerCase() === 't5') return compact ? 'BO1' : 'Black Ops I';
|
|
if (game?.toLowerCase() === 't6') return compact ? 'BO2' : 'Black Ops II';
|
|
return game?.toUpperCase() || 'Unknown game';
|
|
}
|
|
|
|
export function mapTitle(map: string | null | undefined): string {
|
|
const matches = [...T5_ZOMBIE_MAPS, ...T6_ZOMBIE_MAPS].filter(
|
|
(entry) => entry.canonical === map?.toLowerCase()
|
|
);
|
|
// Engine identifiers alone cannot distinguish selections such as Town and TranZit.
|
|
if (matches.length > 1) return `${map} (variant unknown)`;
|
|
return matches[0]?.friendly ?? map ?? '—';
|
|
}
|
|
|
|
export function serverTitle(name: string): string {
|
|
const parsed = parseServerName(name);
|
|
if (
|
|
!parsed ||
|
|
!['t5', 't6'].includes(parsed.game.toLowerCase()) ||
|
|
(parsed.gameMode !== null && parsed.gameMode !== 'zombie') ||
|
|
!parsed.mapCanonical
|
|
) {
|
|
return name;
|
|
}
|
|
const title =
|
|
zombieMaps(parsed.game).find((entry) => entry.slug === parsed.mapSlug)?.friendly ??
|
|
mapTitle(parsed.mapCanonical);
|
|
return parsed.lobby === null ? title : `${title} · Lobby ${parsed.lobby}`;
|
|
}
|
|
|
|
export function serverIdentity(name: string): { map: string; lobby: number | null; game: string } {
|
|
const parsed = parseServerName(name);
|
|
if (
|
|
!parsed ||
|
|
!['t5', 't6'].includes(parsed.game.toLowerCase()) ||
|
|
!parsed.mapCanonical ||
|
|
(parsed.gameMode && parsed.gameMode !== 'zombie')
|
|
)
|
|
return { map: name, lobby: null, game: '' };
|
|
return {
|
|
map:
|
|
zombieMaps(parsed.game).find((entry) => entry.slug === parsed.mapSlug)?.friendly ??
|
|
mapTitle(parsed.mapCanonical),
|
|
lobby: parsed.lobby,
|
|
game: parsed.game === 't6' ? 'Black Ops II' : 'Black Ops I'
|
|
};
|
|
}
|