From a0a864ef444602f8ac4a3e1b348590e305cb61b1 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Fri, 28 Jun 2024 18:47:41 +0100 Subject: [PATCH] Update inventory helper to generate image height dynamically based on card amount --- src/helpers/InventoryHelper.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/helpers/InventoryHelper.ts b/src/helpers/InventoryHelper.ts index 287bfe9..d464c39 100644 --- a/src/helpers/InventoryHelper.ts +++ b/src/helpers/InventoryHelper.ts @@ -119,12 +119,14 @@ export default class InventoryHelper { } private static async GenerateInventoryImage(page: InventoryPage): Promise { - const gridSize = 3; + const gridWidth = 3; + const gridHeight = Math.ceil(page.cards.length / gridWidth); + const imageWidth = 526; const imageHeight = 712; - const canvasWidth = imageWidth * gridSize; - const canvasHeight = imageHeight * Math.floor((gridSize ** 2) / gridSize); + const canvasWidth = imageWidth * gridWidth; + const canvasHeight = imageHeight * gridHeight; const canvas = createCanvas(canvasWidth, canvasHeight); const ctx = canvas.getContext("2d"); @@ -139,8 +141,8 @@ export default class InventoryHelper { continue; } - const x = i % gridSize; - const y = Math.floor(i / gridSize); + const x = i % gridWidth; + const y = Math.floor(i / gridWidth); const imageX = imageWidth * x; const imageY = imageHeight * y;