Refactor generateCardId function to accept variable arguments for enhanced ID generation

This commit is contained in:
w 2025-07-16 22:37:22 -03:00
parent eff962608f
commit 18b1eef26e

View file

@ -72,9 +72,9 @@ const artistInput = document.getElementById("artistInput");
const downloadBtn = document.getElementById("downloadBtn");
// Generate a unique ID for the card based on pack and card name
async function generateCardId(packName, cardName) {
async function generateCardId(...args) {
const encoder = new TextEncoder();
const data = encoder.encode(packName + ':' + cardName);
const data = encoder.encode(args.join(':'));
const hashBuffer = await crypto.subtle.digest('SHA-1', data);
// Convert hash to hex
@ -130,7 +130,7 @@ function drawCard() {
}
async function drawCardId() {
const id = await generateCardId(packInput.value, nameInput.value);
const id = await generateCardId(packInput.value, nameInput.value, powerInput.value, charmInput.value, witInput.value, artistInput.value);
ctx.font = "15px sans-serif";
ctx.fillText("KC-" + id, canvas.width/2, canvas.height - 30);
}