import type { LiveGame } from './protocol.js'; import { fmtClock } from './time.js'; export const GAME_NAME: Record = { valorant: '발로란트', lol: '리그 오브 레전드' }; /** 지금 게임 상태를 한 줄로 (헤더 · 알림용): "경쟁전 · 어센트 · R15 8:6" */ export function liveGameLine(g: LiveGame): string { if (!g.inMatch) return g.phase + (g.mode && g.connected ? ` · ${g.mode}` : ''); const parts = [g.mode, g.map].filter(Boolean) as string[]; if (g.round != null && g.score) parts.push(`R${g.round} ${g.score.ally}:${g.score.enemy}`); else if (g.score) parts.push(`${g.score.ally}:${g.score.enemy}`); if (g.gameTimeSec != null) parts.push(fmtClock(g.gameTimeSec * 1000)); return parts.join(' · ') || '경기 중'; } /** 지금 게임 상태 자세히 (앱 게임 연동 탭 · 사이트 패널): [항목, 값] */ export function liveGameRows(g: LiveGame, now = Date.now()): [string, string][] { const rows: [string, string][] = [['상태', g.phase]]; if (g.self?.name) rows.push(['내 계정', g.self.name]); if (g.mode) rows.push(['모드', g.mode]); if (g.map) rows.push(['맵', g.map]); if (g.inMatch) { if (g.round != null) rows.push(['라운드', `${g.round}라운드`]); if (g.score) rows.push([g.round != null ? '점수 (우리 : 상대)' : '점수', `${g.score.ally} : ${g.score.enemy}`]); if (g.gameTimeSec != null) rows.push(['게임 시간', fmtClock(g.gameTimeSec * 1000)]); else if (g.startedAt) rows.push(['경과', fmtClock(Math.max(0, now - g.startedAt))]); if (g.teamKills) rows.push(['팀 킬 (우리 : 상대)', `${g.teamKills.ally} : ${g.teamKills.enemy}`]); if (g.self?.character) rows.push([g.game === 'lol' ? '내 챔피언' : '내 요원', g.self.character]); if (g.self?.kda) rows.push(['KDA', g.self.kda]); if (g.self?.extra) rows.push(['내 성적', g.self.extra]); if (g.players) rows.push(['인원', `${g.players}명`]); } if (g.error) rows.push(['오류', g.error]); return rows; }