From 3c15ab566ffbcc4d645b0d6e39b005be0a2d2d1a Mon Sep 17 00:00:00 2001 From: kawarimidoll Date: Mon, 11 Jan 2021 10:37:12 +0900 Subject: [PATCH] Add transparent features --- index.ts | 10 ++++++++++ src/card.ts | 4 +++- src/trophies.ts | 5 ++++- src/utils.ts | 2 ++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/index.ts b/index.ts index 147e2af..7f5b242 100644 --- a/index.ts +++ b/index.ts @@ -25,6 +25,14 @@ export default async (req: ServerRequest) => { "margin-h", CONSTANTS.DEFAULT_MARGIN_H, ); + const noBackground = params.getBooleanValue( + "no-bg", + CONSTANTS.DEFAULT_NO_BACKGROUND, + ); + const noFrame = params.getBooleanValue( + "no-frame", + CONSTANTS.DEFAULT_NO_FRAME, + ); const titles: Array = params.getAll("title").flatMap((r) => r.split(",") ).map((r) => r.trim()); @@ -64,6 +72,8 @@ export default async (req: ServerRequest) => { CONSTANTS.DEFAULT_PANEL_SIZE, marginWidth, paddingHeight, + noBackground, + noFrame, ).render(userInfo, theme), headers: new Headers( { diff --git a/src/card.ts b/src/card.ts index 3f0be8c..8d8919f 100644 --- a/src/card.ts +++ b/src/card.ts @@ -27,6 +27,8 @@ export class Card { private panelSize: number, private marginWidth: number, private marginHight: number, + private noBackground: boolean, + private noFrame: boolean, ) { this.width = panelSize * this.maxColumn + this.marginWidth * (this.maxColumn - 1); } @@ -92,7 +94,7 @@ export class Card { const currentRow = Math.floor(i / this.maxColumn); const x = this.panelSize * currentColumn + this.marginWidth * currentColumn; const y = this.panelSize * currentRow + this.marginHight * currentRow; - return sum + trophy.render(theme, x, y, this.panelSize); + return sum + trophy.render(theme, x, y, this.panelSize, this.noBackground, this.noFrame); }, "", ); diff --git a/src/trophies.ts b/src/trophies.ts index d783484..f8d0f96 100644 --- a/src/trophies.ts +++ b/src/trophies.ts @@ -63,6 +63,8 @@ export class Trophy { x = 0, y = 0, panelSize = CONSTANTS.DEFAULT_PANEL_SIZE, + noBackground = CONSTANTS.DEFAULT_NO_BACKGROUND, + noFrame = CONSTANTS.DEFAULT_NO_FRAME, ): string { const { BACKGROUND: PRIMARY, TITLE: SECONDARY, TEXT, NEXT_RANK_BAR } = theme; const nextRankBar = getNextRankBar( @@ -88,7 +90,8 @@ export class Trophy { height="${panelSize - 1}" stroke="#e1e4e8" fill="${PRIMARY}" - stroke-opacity="1" + stroke-opacity="${noFrame ? '0' : '1'}" + fill-opacity="${noBackground ? '0' : '1'}" /> ${getTrophyIcon(theme, this.rank)} ${this.title} diff --git a/src/utils.ts b/src/utils.ts index e0a0c0e..bfce4f6 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -62,6 +62,8 @@ export const CONSTANTS = { DEFAULT_MAX_ROW: 3, DEFAULT_MARGIN_W: 0, DEFAULT_MARGIN_H: 0, + DEFAULT_NO_BACKGROUND: false, + DEFAULT_NO_FRAME: false, }; export enum RANK {