mirror of
https://github.com/reiyua/github-profile-trophy-reiyua-mirror.git
synced 2026-11-17 06:02:09 +11:00
Add small trophy icon
This commit is contained in:
parent
a34c235cd6
commit
c426484370
3 changed files with 68 additions and 51 deletions
74
src/icons.ts
74
src/icons.ts
|
|
@ -26,46 +26,52 @@ Created by potrace 1.15, written by Peter Selinger 2001-2017
|
|||
<path d="M7249 1054 c-42 -7 -109 -25 -150 -40 -76 -27 -226 -101 -267 -133 l-24 -18 41 -66 c22 -37 36 -67 31 -67 -18 0 -11 -80 11 -121 11 -22 53 -73 92 -113 279 -282 682 -361 1251 -245 113 23 172 49 188 84 14 30 3 72 -20 77 -9 3 18 15 61 29 l78 24 -93 81 c-362 313 -622 460 -902 509 -106 18 -194 18 -297 -1z"/>
|
||||
</g>
|
||||
</svg>`;
|
||||
function getPlusIcon(color: string): string {
|
||||
return `
|
||||
<svg x="65" y="20" width="100" height="100" viewBox="0 0 30 30" class="bi bi-trophy" fill="${color}" xmlns="http://www.w3.org/2000/svg">
|
||||
<circle cx="8" cy="6" r="3" />
|
||||
<text x="5.5" y="7.9" font-family="Verdana, Arial, Helvetica, sans-serif" fill="#fff" font-weight="bold" font-size="6">+</text>
|
||||
</svg>
|
||||
`;
|
||||
|
||||
function getSmallTropyIcon(icon: string, color: string, count: number): string {
|
||||
const leftXPosition = 2;
|
||||
const rightXPosition = 73;
|
||||
const getIcon = (x: number) => {
|
||||
return `<svg x="${x}" y="30" width="65" height="65" viewBox="0 0 30 30" class="bi bi-trophy" fill="${color}" xmlns="http://www.w3.org/2000/svg">
|
||||
${icon}
|
||||
</svg>`
|
||||
};
|
||||
if (count == 1) {
|
||||
// Double Rank
|
||||
return getIcon(rightXPosition);
|
||||
} else if (count == 2){
|
||||
// Triple Rank
|
||||
return `${getIcon(leftXPosition)}${getIcon(rightXPosition)}`
|
||||
}
|
||||
// Single Rank
|
||||
return ''
|
||||
|
||||
}
|
||||
export function getTropyIcon(rank = RANK.UNKNOWN) {
|
||||
let color = "currentColor";
|
||||
let backgroundIcon = "";
|
||||
let optionRankIcon = "";
|
||||
if (rank == RANK.SP) {
|
||||
color = goldColor;
|
||||
backgroundIcon = leafIcon;
|
||||
optionRankIcon = getPlusIcon(color);
|
||||
} else if (rank == RANK.S) {
|
||||
color = goldColor;
|
||||
backgroundIcon = leafIcon;
|
||||
} else if (rank == RANK.AP) {
|
||||
color = silverColor;
|
||||
backgroundIcon = leafIcon;
|
||||
optionRankIcon = getPlusIcon(color);
|
||||
} else if (rank == RANK.A) {
|
||||
color = silverColor;
|
||||
backgroundIcon = leafIcon;
|
||||
} else if (rank == RANK.B) {
|
||||
color = bronzeColor;
|
||||
}
|
||||
return `
|
||||
${backgroundIcon}
|
||||
${optionRankIcon}
|
||||
<svg x="28" y="20" width="100" height="100" viewBox="0 0 30 30" class="bi bi-trophy" fill="${color}" xmlns="http://www.w3.org/2000/svg">
|
||||
const icon = `
|
||||
<path d="M3 1h10c-.495 3.467-.5 10-5 10S3.495 4.467 3 1zm0 15a1 1 0 0 1 1-1h8a1 1 0 0 1 1 1H3zm2-1a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1H5z"/>
|
||||
<path fill-rule="evenodd" d="M12.5 3a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm-3 2a3 3 0 1 1 6 0 3 3 0 0 1-6 0zm-6-2a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm-3 2a3 3 0 1 1 6 0 3 3 0 0 1-6 0z"/>
|
||||
<path d="M7 10h2v4H7v-4z"/>
|
||||
<path d="M10 11c0 .552-.895 1-2 1s-2-.448-2-1 .895-1 2-1 2 .448 2 1z"/>
|
||||
<circle cx="8" cy="6" r="4" fill="#fff" />
|
||||
<text x="6" y="8" font-family="Courier, Monospace" font-size="7" fill="#333">${
|
||||
rank.replace("+", "")
|
||||
}</text>
|
||||
<text x="6" y="8" font-family="Courier, Monospace" font-size="7" fill="#333">${rank.slice(0, 1)}</text>
|
||||
`;
|
||||
|
||||
let color = "currentColor";
|
||||
let backgroundIcon = "";
|
||||
if (rank.slice(0, 1) === RANK.S) {
|
||||
color = goldColor;
|
||||
backgroundIcon = leafIcon;
|
||||
} else if (rank.slice(0, 1) === RANK.A) {
|
||||
color = silverColor;
|
||||
backgroundIcon = leafIcon;
|
||||
} else if (rank === RANK.B) {
|
||||
color = bronzeColor;
|
||||
}
|
||||
const optionRankIcon = getSmallTropyIcon(icon, color, rank.length - 1);
|
||||
return `
|
||||
${backgroundIcon}
|
||||
${optionRankIcon}
|
||||
<svg x="28" y="20" width="100" height="100" viewBox="0 0 30 30" class="bi bi-trophy" fill="${color}" xmlns="http://www.w3.org/2000/svg">
|
||||
${icon}
|
||||
</svg>`;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,9 @@ export abstract class Trophy {
|
|||
topMessage = "Unknown";
|
||||
bottomMessage = "0";
|
||||
title = "";
|
||||
constructor(score: number) {
|
||||
this.bottomMessage = abridgeScore(score);
|
||||
}
|
||||
abstract setRank(): void;
|
||||
render(x = 0, y = 0, panelSize = CONSTANTS.DEFALT_PANEL_SIZE): string {
|
||||
return `
|
||||
|
|
@ -39,12 +42,11 @@ export abstract class Trophy {
|
|||
|
||||
export class TotalStarTrophy extends Trophy {
|
||||
constructor(private score: number) {
|
||||
super();
|
||||
super(score);
|
||||
this.title = "Star";
|
||||
this.setRank();
|
||||
}
|
||||
setRank() {
|
||||
this.bottomMessage = abridgeScore(this.score);
|
||||
if (this.score >= 200) {
|
||||
this.rank = RANK.S;
|
||||
this.topMessage = "Super Star";
|
||||
|
|
@ -63,16 +65,21 @@ export class TotalStarTrophy extends Trophy {
|
|||
|
||||
export class TotalCommitTrophy extends Trophy {
|
||||
constructor(private score: number) {
|
||||
super();
|
||||
super(score);
|
||||
this.title = "Commit";
|
||||
this.setRank();
|
||||
}
|
||||
setRank() {
|
||||
this.bottomMessage = abridgeScore(this.score);
|
||||
if (this.score >= 1000) {
|
||||
this.rank = RANK.S;
|
||||
this.topMessage = "Super Commiter";
|
||||
} else if (this.score >= 500) {
|
||||
this.rank = RANK.AAA;
|
||||
this.topMessage = "High Commiter";
|
||||
} else if (this.score >= 300) {
|
||||
this.rank = RANK.AA;
|
||||
this.topMessage = "High Commiter";
|
||||
} else if (this.score >= 200) {
|
||||
this.rank = RANK.A;
|
||||
this.topMessage = "High Commiter";
|
||||
} else if (this.score >= 100) {
|
||||
|
|
@ -87,12 +94,11 @@ export class TotalCommitTrophy extends Trophy {
|
|||
|
||||
export class TotalFollowerTrophy extends Trophy {
|
||||
constructor(private score: number) {
|
||||
super();
|
||||
super(score);
|
||||
this.title = "Follower";
|
||||
this.setRank();
|
||||
}
|
||||
setRank() {
|
||||
this.bottomMessage = abridgeScore(this.score);
|
||||
if (this.score >= 100) {
|
||||
this.rank = RANK.S;
|
||||
this.topMessage = "Celebrity";
|
||||
|
|
@ -110,20 +116,19 @@ export class TotalFollowerTrophy extends Trophy {
|
|||
}
|
||||
export class TotalIssueTrophy extends Trophy {
|
||||
constructor(private score: number) {
|
||||
super();
|
||||
super(score);
|
||||
this.title = "Issue";
|
||||
this.setRank();
|
||||
}
|
||||
setRank() {
|
||||
this.bottomMessage = abridgeScore(this.score);
|
||||
if(this.score >= 300) {
|
||||
this.rank = RANK.SP;
|
||||
this.rank = RANK.SS;
|
||||
this.topMessage = "Deep Issuer";
|
||||
} else if (this.score >= 100) {
|
||||
this.rank = RANK.S;
|
||||
this.topMessage = "Super Issuer";
|
||||
} else if (this.score >= 50) {
|
||||
this.rank = RANK.AP;
|
||||
this.rank = RANK.AA;
|
||||
this.topMessage = "Heavy Issuer";
|
||||
} else if (this.score >= 20) {
|
||||
this.rank = RANK.A;
|
||||
|
|
@ -140,17 +145,16 @@ export class TotalIssueTrophy extends Trophy {
|
|||
|
||||
export class TotalPullRequestTrophy extends Trophy {
|
||||
constructor(private score: number) {
|
||||
super();
|
||||
super(score);
|
||||
this.title = "PR";
|
||||
this.setRank();
|
||||
}
|
||||
setRank() {
|
||||
this.bottomMessage = abridgeScore(this.score);
|
||||
if (this.score >= 100) {
|
||||
this.rank = RANK.S;
|
||||
this.topMessage = "God PR User";
|
||||
} else if (this.score >= 50) {
|
||||
this.rank = RANK.AP;
|
||||
this.rank = RANK.AA;
|
||||
this.topMessage = "Heavy PR User";
|
||||
} else if (this.score >= 20) {
|
||||
this.rank = RANK.A;
|
||||
|
|
@ -167,15 +171,20 @@ export class TotalPullRequestTrophy extends Trophy {
|
|||
|
||||
export class TotalRepositoryTrophy extends Trophy {
|
||||
constructor(private score: number) {
|
||||
super();
|
||||
super(score);
|
||||
this.title = "Repo";
|
||||
this.setRank();
|
||||
}
|
||||
setRank() {
|
||||
this.bottomMessage = abridgeScore(this.score);
|
||||
if (this.score >= 100) {
|
||||
this.rank = RANK.S;
|
||||
this.topMessage = "God Repo Creator";
|
||||
} else if (this.score >= 50) {
|
||||
this.rank = RANK.AAA;
|
||||
this.topMessage = "High Repo Creator";
|
||||
} else if (this.score >= 40) {
|
||||
this.rank = RANK.AA;
|
||||
this.topMessage = "High Repo Creator";
|
||||
} else if (this.score >= 20) {
|
||||
this.rank = RANK.A;
|
||||
this.topMessage = "High Repo Creator";
|
||||
|
|
|
|||
|
|
@ -31,9 +31,11 @@ export const CONSTANTS = {
|
|||
};
|
||||
|
||||
export enum RANK {
|
||||
SP = "S+",
|
||||
SSS = "SSS",
|
||||
SS = "SS",
|
||||
S = "S",
|
||||
AP = "A+",
|
||||
AAA = "AAA",
|
||||
AA = "AA",
|
||||
A = "A",
|
||||
B = "B",
|
||||
C = "C",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue