Hostitel prida na volne sedadlo bota (+ Bot = heuristika, + AI bot = natrenovana siet) alebo bota odoberie; boti maju vlastnu ikonu a flag is_bot v rosteroch. Surove ucty bot:<kind>-<n> sa vsade zobrazuju cez displayName ako "Bot 2" / "AI bot 1" (stol, kopka, tabulky, historia). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
23 lines
972 B
TypeScript
23 lines
972 B
TypeScript
/** Display helpers for player names. Bot accounts follow the server-side
|
|
* convention "bot:<kind>-<n>" (see api/bots.py) — render them as a short
|
|
* friendly label instead of the raw username. */
|
|
|
|
const BOT_PREFIX = 'bot:';
|
|
|
|
export function isBotName(name?: string | null): boolean {
|
|
return !!name && name.startsWith(BOT_PREFIX);
|
|
}
|
|
|
|
/** "bot:heuristic-2" -> "Bot 2", "bot:neural-1" -> "AI bot 1"; other kinds
|
|
* keep a suffix ("Bot 1 (random)"); non-bot names pass through unchanged. */
|
|
export function displayName(name?: string | null): string {
|
|
if (!name || !isBotName(name)) return name ?? '';
|
|
const body = name.slice(BOT_PREFIX.length);
|
|
const dash = body.lastIndexOf('-');
|
|
const kind = dash > 0 ? body.slice(0, dash) : body;
|
|
const num = dash > 0 ? body.slice(dash + 1) : '';
|
|
if (kind === 'neural') return num ? `AI bot ${num}` : 'AI bot';
|
|
const label = num ? `Bot ${num}` : 'Bot';
|
|
return kind === 'heuristic' ? label : `${label} (${kind})`;
|
|
}
|