diff --git a/index.ts b/index.ts index 25320c1..26d44bc 100644 --- a/index.ts +++ b/index.ts @@ -6,9 +6,10 @@ const client = new GithubAPIClient(); export default async (req: ServerRequest) => { const userInfo = await client.requestUserInfo("ryo-ma") + const cardSize = 110; req.respond( { - body: new Card().render(), + body: new Card(cardSize).render(), headers: new Headers({ "Content-Type": "image/svg+xml" }), }, ) diff --git a/src/card.ts b/src/card.ts index 7e37f9a..157b85e 100644 --- a/src/card.ts +++ b/src/card.ts @@ -1,7 +1,20 @@ -import { TotalStarTrophy, TotalCommitTrophy, TotalFollowerTrophy } from "./trophies.ts"; +import { + Trophy, + TotalStarTrophy, + TotalCommitTrophy, + TotalFollowerTrophy, +} from "./trophies.ts"; export class Card { - constructor(private width = 800, private height = 200) { + private width = 0; + private height = 0; + constructor( + private panelSize = 110, + private maxPanelWidthCount = 6, + private maxPanelHeightCount = 2, + ) { + this.width = panelSize * this.maxPanelWidthCount; + this.height = panelSize * this.maxPanelHeightCount; } render(): string { const trophy1 = new TotalStarTrophy(0); @@ -16,6 +29,31 @@ export class Card { const trophy10 = new TotalFollowerTrophy(50); const trophy11 = new TotalFollowerTrophy(100); const trophy12 = new TotalFollowerTrophy(500); + const trophyList = new Array(); + trophyList.push(trophy1); + trophyList.push(trophy2); + trophyList.push(trophy3); + trophyList.push(trophy4); + trophyList.push(trophy5); + trophyList.push(trophy6); + trophyList.push(trophy7); + trophyList.push(trophy8); + trophyList.push(trophy9); + trophyList.push(trophy10); + trophyList.push(trophy11); + trophyList.push(trophy12); + const renderdTrophy = trophyList.reduce( + (sum: string, trophy: Trophy, i: number) => { + let x = (this.panelSize * i); + let y = 0; + if (i >= this.maxPanelWidthCount) { + x = (this.panelSize * (i - this.maxPanelWidthCount)); + y = this.panelSize; + } + return sum + trophy.render(x, y, this.panelSize); + }, + "", + ); return ` - ${trophy1.render()} - ${trophy2.render(100, 0)} - ${trophy3.render(0, 100)} - ${trophy4.render(100, 100)} - ${trophy5.render(200, 0)} - ${trophy6.render(300, 0)} - ${trophy7.render(200, 100)} - ${trophy8.render(300, 100)} - ${trophy9.render(400, 0)} - ${trophy10.render(500, 0)} - ${trophy11.render(400, 100)} - ${trophy12.render(500, 100)} + ${renderdTrophy} `; } } diff --git a/src/icons.ts b/src/icons.ts index 3d58efe..00d9232 100644 --- a/src/icons.ts +++ b/src/icons.ts @@ -7,7 +7,7 @@ const leafIcon = ` + @@ -39,7 +39,7 @@ export function getTropyIcon(rank = "?") { } return ` ${backgroundIcon} - + diff --git a/src/trophies.ts b/src/trophies.ts index 7581fcf..3392080 100644 --- a/src/trophies.ts +++ b/src/trophies.ts @@ -1,19 +1,20 @@ import { getTropyIcon } from "./icons.ts"; -abstract class Trophy { + +export abstract class Trophy { rank: string = "?"; topMessage = "Unknown"; bottomMessage = "+0"; title = ""; abstract setRank(): void; - render(x = 0, y = 0): string { + render(x = 0, y = 0, cardSize = 110): string { return ` @@ -22,8 +23,8 @@ abstract class Trophy { x="0.5" y="0.5" rx="4.5" - width="99" - height="99" + width="${cardSize - 1}" + height="${cardSize - 1}" stroke="#E4E2E2" fill="#fff" stroke-opacity="1"