forked from ryo-ma/github-profile-trophy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrophy_list.ts
71 lines (69 loc) · 2.08 KB
/
trophy_list.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import {
Trophy,
TotalStarTrophy,
TotalCommitTrophy,
TotalFollowerTrophy,
TotalIssueTrophy,
TotalPullRequestTrophy,
TotalRepositoryTrophy,
MultipleLangTrophy,
LongTimeAccountTrophy,
AncientAccountTrophy,
Joined2020Trophy,
AllSuperRankTrophy,
MultipleOrganizationsTrophy,
} from "./trophy.ts";
import { UserInfo } from "./user_info.ts";
import { RANK_ORDER, RANK } from "./utils.ts";
export class TrophyList {
private trophies = new Array<Trophy>();
constructor(userInfo: UserInfo) {
// Base trophies
this.trophies.push(
new TotalStarTrophy(userInfo.totalStargazers),
new TotalCommitTrophy(userInfo.totalCommits),
new TotalFollowerTrophy(userInfo.totalFollowers),
new TotalIssueTrophy(userInfo.totalIssues),
new TotalPullRequestTrophy(userInfo.totalPullRequests),
new TotalRepositoryTrophy(userInfo.totalRepositories),
);
// Secret trophies
this.trophies.push(
new AllSuperRankTrophy(this.isAllSRank),
new MultipleLangTrophy(userInfo.languageCount),
new LongTimeAccountTrophy(userInfo.durationYear),
new AncientAccountTrophy(userInfo.ancientAccount),
new Joined2020Trophy(userInfo.joined2020),
new MultipleOrganizationsTrophy(userInfo.totalOrganizations),
);
}
get length() {
return this.trophies.length;
}
get getArray() {
return this.trophies;
}
private get isAllSRank() {
return this.trophies.every((trophy) => trophy.rank.slice(0, 1) == RANK.S) ? 1 : 0;
}
filterByHideen() {
this.trophies = this.trophies.filter((trophy) =>
!trophy.hidden || trophy.rank !== RANK.UNKNOWN
);
}
filterByTitles(titles: Array<string>) {
this.trophies = this.trophies.filter((trophy) => {
return trophy.filterTitles.some((title) => titles.includes(title));
});
}
filterByRanks(ranks: Array<string>) {
this.trophies = this.trophies.filter((trophy) =>
ranks.includes(trophy.rank)
);
}
sortByRank() {
this.trophies = this.trophies.sort((a: Trophy, b: Trophy) =>
RANK_ORDER.indexOf(a.rank) - RANK_ORDER.indexOf(b.rank)
);
}
}