function buildRows(historyKey: TGKey): ResultRow[] { const { slot } = TGKey.parse(historyKey); let players: UserKey[] = Attendance.players(historyKey); const rows: ResultRow[] = []; // Fallback — read from history file directly if (players.length === 0) { const history = Store.read<{ scores: TGScore[] }>(TGKey.toHistoryPath(historyKey)); if (history?.scores) { players = [...new Set(history.scores.map((s: TGScore) => s.userKey))]; } } for (const userKey of players) { const chars = CharacterRegistry.forUser(userKey); // Find which character this user played in this TG // by checking score history for (const char of chars) { const score = Score.get({ character: char, slot }); if (!score && chars.indexOf(char) < chars.length - 1) continue; const wrEntry = WRank.entry(char.name, char.nation); rows.push({ character: char, score: score ?? undefined, position: wrEntry ? { currentRank: wrEntry.currentRank, previousRank: wrEntry.previousRank, } : undefined, leavesCount: Leaves.countForChar({ characterName: char.name }), }); break; } } return rows; }