Son aktivite 2 weeks ago

Revizyon 9e3f6918ed6eab870b29846e1daf08c0f780de1e

gistfile1.txt Ham
1 function buildRows(historyKey: TGKey): ResultRow[] {
2 const { slot, date } = TGKey.parse(historyKey);
3 let players: UserKey[] = Attendance.players(historyKey);
4 const rows: ResultRow[] = [];
5 const weekKey = WRank.weekKey(new Date(date));
6
7 // Fallback — read from history file directly
8 if (players.length === 0) {
9 const history = Store.read<{ scores: TGScore[] }>(TGKey.toHistoryPath(historyKey));
10 if (history?.scores) {
11 players = [...new Set(history.scores.map((s: TGScore) => s.userKey))];
12 }
13 }
14
15 for (const userKey of players) {
16 const chars = CharacterRegistry.forUser(userKey);
17 // Find which character this user played in this TG
18 // by checking score history
19 for (const char of chars) {
20 const score = Score.get({ character: char, slot, historyKey });
21 if (!score) continue; // skip chars with no score for this TG
22
23 const wrEntry = WRank.entry(char.name, char.nation, weekKey);
24
25 rows.push({
26 character: char,
27 score,
28 position: wrEntry ? {
29 currentRank: wrEntry.currentRank,
30 previousRank: wrEntry.previousRank,
31 } : undefined,
32 leavesCount: Leaves.countForChar({ characterName: char.name }),
33 });
34 break; // found the char for this user, move to the next user
35 }
36
37 if (!rows.find(r => r.character.ownerKey === userKey)) {
38 // Build from score directly
39 const history = Store.read<{ scores: TGScore[] }>(TGKey.toHistoryPath(historyKey));
40 const score = history?.scores.find((s: TGScore) => s.userKey === userKey);
41 if (score) {
42 const foundChar = CharacterRegistry.find(score.characterName);
43 const char: Character = foundChar ?? {
44 name: score.characterName,
45 class: CLASSES[score.class as ClassKey] ?? { key: score.class as ClassKey, name: score.class, shortName: score.class },
46 level: 0,
47 nation: score.nation,
48 ownerKey: score.userKey,
49 };
50 rows.push({ character: char, score, leavesCount: 0 });
51 }
52 }
53 }
54
55 return rows;
56 }