From afc8f637bc30e13d74adae10258741c3142407ad Mon Sep 17 00:00:00 2001 From: Jay-Karia Date: Sun, 4 Aug 2024 21:36:28 +0530 Subject: [PATCH 1/2] chore: get input param --- api/index.ts | 2 ++ src/card.ts | 6 ++++-- src/icons.ts | 3 ++- src/trophy.ts | 3 ++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/api/index.ts b/api/index.ts index dfe8e19c..a7b05295 100644 --- a/api/index.ts +++ b/api/index.ts @@ -60,6 +60,7 @@ async function app(req: Request): Promise { const ranks: Array = params.getAll("rank").flatMap((r) => r.split(",") ).map((r) => r.trim()); + const trophy_style = params.get("trophy_style"); if (username === null) { const [base] = req.url.split("?"); @@ -139,6 +140,7 @@ async function app(req: Request): Promise { paddingHeight, noBackground, noFrame, + trophy_style, ).render(userInfo, theme), { headers: defaultHeaders, diff --git a/src/card.ts b/src/card.ts index b2762b42..7c2d70e2 100644 --- a/src/card.ts +++ b/src/card.ts @@ -16,6 +16,7 @@ export class Card { private marginHeight: number, private noBackground: boolean, private noFrame: boolean, + private trophyStyle: string | null, ) { this.width = panelSize * this.maxColumn + this.marginWidth * (this.maxColumn - 1); @@ -61,7 +62,7 @@ export class Card { fill="none" xmlns="http://www.w3.org/2000/svg" > - ${this.renderTrophy(trophyList, theme)} + ${this.renderTrophy(trophyList, theme, this.trophyStyle)} `; } private getRow(trophyList: TrophyList) { @@ -76,7 +77,7 @@ export class Card { return this.panelSize * row + this.marginHeight * (row - 1); } - private renderTrophy(trophyList: TrophyList, theme: Theme) { + private renderTrophy(trophyList: TrophyList, theme: Theme, trophyStyle: string | null) { return trophyList.getArray.reduce( (sum: string, trophy: Trophy, i: number) => { const currentColumn = i % this.maxColumn; @@ -92,6 +93,7 @@ export class Card { this.panelSize, this.noBackground, this.noFrame, + trophyStyle, ); }, "", diff --git a/src/icons.ts b/src/icons.ts index 7cabc097..0a885fae 100644 --- a/src/icons.ts +++ b/src/icons.ts @@ -88,9 +88,10 @@ const getSmallTrophyIcon = ( // Single Rank return ""; }; -export const getTrophyIcon = (theme: Theme, rank = RANK.UNKNOWN) => { +export const getTrophyIcon = (theme: Theme, rank = RANK.UNKNOWN, trophyStyle: string | null = null) => { let color = theme.DEFAULT_RANK_BASE; let rankColor = theme.DEFAULT_RANK_TEXT; + console.log(trophyStyle) let backgroundIcon = ""; let gradationColor = ` diff --git a/src/trophy.ts b/src/trophy.ts index f81cdc78..14cfbdca 100644 --- a/src/trophy.ts +++ b/src/trophy.ts @@ -65,6 +65,7 @@ export class Trophy { panelSize = CONSTANTS.DEFAULT_PANEL_SIZE, noBackground = CONSTANTS.DEFAULT_NO_BACKGROUND, noFrame = CONSTANTS.DEFAULT_NO_FRAME, + trophyStyle: string | null = null, ): string { const { BACKGROUND: PRIMARY, TITLE: SECONDARY, TEXT, NEXT_RANK_BAR } = theme; @@ -94,7 +95,7 @@ export class Trophy { stroke-opacity="${noFrame ? "0" : "1"}" fill-opacity="${noBackground ? "0" : "1"}" /> - ${getTrophyIcon(theme, this.rank)} + ${getTrophyIcon(theme, this.rank, trophyStyle)} ${this.title} ${this.topMessage} ${this.bottomMessage} From a92179b3b71d798ecf3a3a65aae04db3dca47fd3 Mon Sep 17 00:00:00 2001 From: Jay-Karia Date: Sun, 4 Aug 2024 21:50:33 +0530 Subject: [PATCH 2/2] chore: add utilities --- src/TrophyStyles/football.ts | 21 +++++++++++++++++++++ src/TrophyStyles/index.ts | 7 +++++++ src/icons.ts | 36 ++++++++++++++++++++++-------------- 3 files changed, 50 insertions(+), 14 deletions(-) create mode 100644 src/TrophyStyles/football.ts create mode 100644 src/TrophyStyles/index.ts diff --git a/src/TrophyStyles/football.ts b/src/TrophyStyles/football.ts new file mode 100644 index 00000000..0b945080 --- /dev/null +++ b/src/TrophyStyles/football.ts @@ -0,0 +1,21 @@ +const SECRET = ``; +const SSS = ``; +const SS = ``; +const S = ``; +const AAA = ``; +const AA = ``; +const A = ``; +const B = ``; +const C = ``; + +export default { + SECRET, + SSS, + SS, + S, + AAA, + AA, + A, + B, + C, +}; \ No newline at end of file diff --git a/src/TrophyStyles/index.ts b/src/TrophyStyles/index.ts new file mode 100644 index 00000000..61000936 --- /dev/null +++ b/src/TrophyStyles/index.ts @@ -0,0 +1,7 @@ +import football from "./football.ts"; + +export const trophyStyles = { + football +}; + +export default trophyStyles; \ No newline at end of file diff --git a/src/icons.ts b/src/icons.ts index 0a885fae..5d7a5171 100644 --- a/src/icons.ts +++ b/src/icons.ts @@ -1,5 +1,6 @@ import { RANK } from "./utils.ts"; import { Theme } from "./theme.ts"; +import trophyStyles from "./TrophyStyles/index.ts"; const leafIcon = (laurel: string): string => { return ` @@ -91,7 +92,6 @@ const getSmallTrophyIcon = ( export const getTrophyIcon = (theme: Theme, rank = RANK.UNKNOWN, trophyStyle: string | null = null) => { let color = theme.DEFAULT_RANK_BASE; let rankColor = theme.DEFAULT_RANK_TEXT; - console.log(trophyStyle) let backgroundIcon = ""; let gradationColor = ` @@ -139,21 +139,29 @@ export const getTrophyIcon = (theme: Theme, rank = RANK.UNKNOWN, trophyStyle: st - ${ - rank.slice(0, 1) - } + ${rank.slice(0, 1) + } `; const optionRankIcon = getSmallTrophyIcon(icon, color, rank.length - 1); return ` - ${backgroundIcon} - ${optionRankIcon} - - - ${gradationColor} - - - - ${icon} - + ${trophyStyle ? + // custom trophy style + ` + ${trophyStyles[trophyStyle][rank]} + ` + : + // default trophy style + ` + ${backgroundIcon} + ${optionRankIcon} + + + ${gradationColor} + + + + ${icon} + + `} `; };