gistfile1.txt
· 1.2 KiB · Text
Неформатований
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;
}
| 1 | function buildRows(historyKey: TGKey): ResultRow[] { |
| 2 | const { slot } = TGKey.parse(historyKey); |
| 3 | let players: UserKey[] = Attendance.players(historyKey); |
| 4 | const rows: ResultRow[] = []; |
| 5 | |
| 6 | // Fallback — read from history file directly |
| 7 | if (players.length === 0) { |
| 8 | const history = Store.read<{ scores: TGScore[] }>(TGKey.toHistoryPath(historyKey)); |
| 9 | if (history?.scores) { |
| 10 | players = [...new Set(history.scores.map((s: TGScore) => s.userKey))]; |
| 11 | } |
| 12 | } |
| 13 | |
| 14 | for (const userKey of players) { |
| 15 | const chars = CharacterRegistry.forUser(userKey); |
| 16 | // Find which character this user played in this TG |
| 17 | // by checking score history |
| 18 | for (const char of chars) { |
| 19 | const score = Score.get({ character: char, slot }); |
| 20 | if (!score && chars.indexOf(char) < chars.length - 1) continue; |
| 21 | |
| 22 | const wrEntry = WRank.entry(char.name, char.nation); |
| 23 | rows.push({ |
| 24 | character: char, |
| 25 | score: score ?? undefined, |
| 26 | position: wrEntry ? { |
| 27 | currentRank: wrEntry.currentRank, |
| 28 | previousRank: wrEntry.previousRank, |
| 29 | } : undefined, |
| 30 | leavesCount: Leaves.countForChar({ characterName: char.name }), |
| 31 | }); |
| 32 | break; |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | return rows; |
| 37 | } |