Add small trophy icon

This commit is contained in:
ryo-ma 2020-08-25 23:25:40 +09:00
parent a34c235cd6
commit c426484370
3 changed files with 68 additions and 51 deletions

View file

@ -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"/> <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> </g>
</svg>`; </svg>`;
function getPlusIcon(color: string): string {
return ` function getSmallTropyIcon(icon: string, color: string, count: number): string {
<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"> const leftXPosition = 2;
<circle cx="8" cy="6" r="3" /> const rightXPosition = 73;
<text x="5.5" y="7.9" font-family="Verdana, Arial, Helvetica, sans-serif" fill="#fff" font-weight="bold" font-size="6">+</text> const getIcon = (x: number) => {
</svg> 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) { export function getTropyIcon(rank = RANK.UNKNOWN) {
let color = "currentColor"; const icon = `
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">
<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 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 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="M7 10h2v4H7v-4z"/>
<path d="M10 11c0 .552-.895 1-2 1s-2-.448-2-1 .895-1 2-1 2 .448 2 1z"/> <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" /> <circle cx="8" cy="6" r="4" fill="#fff" />
<text x="6" y="8" font-family="Courier, Monospace" font-size="7" fill="#333">${ <text x="6" y="8" font-family="Courier, Monospace" font-size="7" fill="#333">${rank.slice(0, 1)}</text>
rank.replace("+", "") `;
}</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>`; </svg>`;
} }

View file

@ -6,6 +6,9 @@ export abstract class Trophy {
topMessage = "Unknown"; topMessage = "Unknown";
bottomMessage = "0"; bottomMessage = "0";
title = ""; title = "";
constructor(score: number) {
this.bottomMessage = abridgeScore(score);
}
abstract setRank(): void; abstract setRank(): void;
render(x = 0, y = 0, panelSize = CONSTANTS.DEFALT_PANEL_SIZE): string { render(x = 0, y = 0, panelSize = CONSTANTS.DEFALT_PANEL_SIZE): string {
return ` return `
@ -39,12 +42,11 @@ export abstract class Trophy {
export class TotalStarTrophy extends Trophy { export class TotalStarTrophy extends Trophy {
constructor(private score: number) { constructor(private score: number) {
super(); super(score);
this.title = "Star"; this.title = "Star";
this.setRank(); this.setRank();
} }
setRank() { setRank() {
this.bottomMessage = abridgeScore(this.score);
if (this.score >= 200) { if (this.score >= 200) {
this.rank = RANK.S; this.rank = RANK.S;
this.topMessage = "Super Star"; this.topMessage = "Super Star";
@ -63,16 +65,21 @@ export class TotalStarTrophy extends Trophy {
export class TotalCommitTrophy extends Trophy { export class TotalCommitTrophy extends Trophy {
constructor(private score: number) { constructor(private score: number) {
super(); super(score);
this.title = "Commit"; this.title = "Commit";
this.setRank(); this.setRank();
} }
setRank() { setRank() {
this.bottomMessage = abridgeScore(this.score);
if (this.score >= 1000) { if (this.score >= 1000) {
this.rank = RANK.S; this.rank = RANK.S;
this.topMessage = "Super Commiter"; this.topMessage = "Super Commiter";
} else if (this.score >= 500) { } 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.rank = RANK.A;
this.topMessage = "High Commiter"; this.topMessage = "High Commiter";
} else if (this.score >= 100) { } else if (this.score >= 100) {
@ -87,12 +94,11 @@ export class TotalCommitTrophy extends Trophy {
export class TotalFollowerTrophy extends Trophy { export class TotalFollowerTrophy extends Trophy {
constructor(private score: number) { constructor(private score: number) {
super(); super(score);
this.title = "Follower"; this.title = "Follower";
this.setRank(); this.setRank();
} }
setRank() { setRank() {
this.bottomMessage = abridgeScore(this.score);
if (this.score >= 100) { if (this.score >= 100) {
this.rank = RANK.S; this.rank = RANK.S;
this.topMessage = "Celebrity"; this.topMessage = "Celebrity";
@ -110,20 +116,19 @@ export class TotalFollowerTrophy extends Trophy {
} }
export class TotalIssueTrophy extends Trophy { export class TotalIssueTrophy extends Trophy {
constructor(private score: number) { constructor(private score: number) {
super(); super(score);
this.title = "Issue"; this.title = "Issue";
this.setRank(); this.setRank();
} }
setRank() { setRank() {
this.bottomMessage = abridgeScore(this.score);
if(this.score >= 300) { if(this.score >= 300) {
this.rank = RANK.SP; this.rank = RANK.SS;
this.topMessage = "Deep Issuer"; this.topMessage = "Deep Issuer";
} else if (this.score >= 100) { } else if (this.score >= 100) {
this.rank = RANK.S; this.rank = RANK.S;
this.topMessage = "Super Issuer"; this.topMessage = "Super Issuer";
} else if (this.score >= 50) { } else if (this.score >= 50) {
this.rank = RANK.AP; this.rank = RANK.AA;
this.topMessage = "Heavy Issuer"; this.topMessage = "Heavy Issuer";
} else if (this.score >= 20) { } else if (this.score >= 20) {
this.rank = RANK.A; this.rank = RANK.A;
@ -140,17 +145,16 @@ export class TotalIssueTrophy extends Trophy {
export class TotalPullRequestTrophy extends Trophy { export class TotalPullRequestTrophy extends Trophy {
constructor(private score: number) { constructor(private score: number) {
super(); super(score);
this.title = "PR"; this.title = "PR";
this.setRank(); this.setRank();
} }
setRank() { setRank() {
this.bottomMessage = abridgeScore(this.score);
if (this.score >= 100) { if (this.score >= 100) {
this.rank = RANK.S; this.rank = RANK.S;
this.topMessage = "God PR User"; this.topMessage = "God PR User";
} else if (this.score >= 50) { } else if (this.score >= 50) {
this.rank = RANK.AP; this.rank = RANK.AA;
this.topMessage = "Heavy PR User"; this.topMessage = "Heavy PR User";
} else if (this.score >= 20) { } else if (this.score >= 20) {
this.rank = RANK.A; this.rank = RANK.A;
@ -167,15 +171,20 @@ export class TotalPullRequestTrophy extends Trophy {
export class TotalRepositoryTrophy extends Trophy { export class TotalRepositoryTrophy extends Trophy {
constructor(private score: number) { constructor(private score: number) {
super(); super(score);
this.title = "Repo"; this.title = "Repo";
this.setRank(); this.setRank();
} }
setRank() { setRank() {
this.bottomMessage = abridgeScore(this.score);
if (this.score >= 100) { if (this.score >= 100) {
this.rank = RANK.S; this.rank = RANK.S;
this.topMessage = "God Repo Creator"; 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) { } else if (this.score >= 20) {
this.rank = RANK.A; this.rank = RANK.A;
this.topMessage = "High Repo Creator"; this.topMessage = "High Repo Creator";

View file

@ -31,9 +31,11 @@ export const CONSTANTS = {
}; };
export enum RANK { export enum RANK {
SP = "S+", SSS = "SSS",
SS = "SS",
S = "S", S = "S",
AP = "A+", AAA = "AAA",
AA = "AA",
A = "A", A = "A",
B = "B", B = "B",
C = "C", C = "C",