Add error handling

Also just known as not rendering if said item doesn't exist
This commit is contained in:
DaInfLoop 2024-04-30 11:24:37 +00:00
parent 228122fbbd
commit 25394c9b7c

View file

@ -21,80 +21,104 @@ export async function generateBattler(
// Load + draw the necessary images // Load + draw the necessary images
// [Glow] // [Glow]
try {
if (opts.glow && opts.glow !== "None") { if (opts.glow && opts.glow !== "None") {
const glow = await loadImage(`./assets/glows/${opts.glow}.png`); const glow = await loadImage(`./assets/glows/${opts.glow}.png`);
context.drawImage(glow, 0, 0, canvas.width, canvas.height); context.drawImage(glow, 0, 0, canvas.width, canvas.height);
} }
} catch (err) { }
// [Back] // [Back]
try {
if (opts.back && opts.back !== "None") { if (opts.back && opts.back !== "None") {
const back = await loadImage(`./assets/backs/${opts.back}.png`) const back = await loadImage(`./assets/backs/${opts.back}.png`)
context.drawImage(back, 0, 0, canvas.width, canvas.height) context.drawImage(back, 0, 0, canvas.width, canvas.height)
} }
} catch (err) { }
// [Base] // [Base]
const base = await loadImage(`./assets/bases/${opts.colour || "Black"}.png`); const base = await loadImage(`./assets/bases/${opts.colour || "Black"}.png`);
context.drawImage(base, 0, 0, canvas.width, canvas.height); context.drawImage(base, 0, 0, canvas.width, canvas.height);
// [Upper Bottom] // [Upper Bottom]
try {
if (opts.upperBottom && opts.upperBottom !== "None") { if (opts.upperBottom && opts.upperBottom !== "None") {
const face = await loadImage(`./assets/upperBottom/${opts.face}.png`); const face = await loadImage(`./assets/upperBottom/${opts.face}.png`);
context.drawImage(face, 0, 0, canvas.width, canvas.height); context.drawImage(face, 0, 0, canvas.width, canvas.height);
} }
} catch (err) { }
// [Bottom] // [Bottom]
try {
if (opts.bottom && opts.bottom !== "None") { if (opts.bottom && opts.bottom !== "None") {
const bottom = await loadImage(`./assets/bottoms/${opts.bottom}.png`); const bottom = await loadImage(`./assets/bottoms/${opts.bottom}.png`);
context.drawImage(bottom, 0, 0, canvas.width, canvas.height); context.drawImage(bottom, 0, 0, canvas.width, canvas.height);
} }
} catch (err) { }
// [Top] // [Top]
try {
if (opts.top && opts.top !== "None") { if (opts.top && opts.top !== "None") {
const top = await loadImage(`./assets/tops/${opts.top}.png`); const top = await loadImage(`./assets/tops/${opts.top}.png`);
context.drawImage(top, 0, 0, canvas.width, canvas.height); context.drawImage(top, 0, 0, canvas.width, canvas.height);
} }
} catch (err) { }
// [Face] // [Face]
try {
if (opts.face && opts.face !== "None") { if (opts.face && opts.face !== "None") {
const face = await loadImage(`./assets/faces/${opts.face}.png`); const face = await loadImage(`./assets/faces/${opts.face}.png`);
context.drawImage(face, 0, 0, canvas.width, canvas.height); context.drawImage(face, 0, 0, canvas.width, canvas.height);
} }
} catch (err) { }
// [Hair] // [Hair]
try {
if (opts.hair && opts.hair !== "None") { if (opts.hair && opts.hair !== "None") {
const face = await loadImage(`./assets/hair/${opts.hair}.png`); const face = await loadImage(`./assets/hair/${opts.hair}.png`);
context.drawImage(face, 0, 0, canvas.width, canvas.height); context.drawImage(face, 0, 0, canvas.width, canvas.height);
} }
} catch (err) { }
// [Hat] // [Hat]
try {
if (opts.hat && opts.hat !== "None") { if (opts.hat && opts.hat !== "None") {
const hat = await loadImage(`./assets/hats/${opts.hat}.png`); const hat = await loadImage(`./assets/hats/${opts.hat}.png`);
context.drawImage(hat, 0, 0, canvas.width, canvas.height); context.drawImage(hat, 0, 0, canvas.width, canvas.height);
} }
} catch (err) { }
// [Eyes] // [Eyes]
try {
if (opts.eye && opts.eye !== "None") { if (opts.eye && opts.eye !== "None") {
const eye = await loadImage(`./assets/eyes/${opts.eye}.png`); const eye = await loadImage(`./assets/eyes/${opts.eye}.png`);
context.drawImage(eye, 0, 0, canvas.width, canvas.height); context.drawImage(eye, 0, 0, canvas.width, canvas.height);
} }
} catch (err) { }
// [Upper Top] // [Upper Top]
try {
if (opts.upperTop && opts.upperTop !== "None") { if (opts.upperTop && opts.upperTop !== "None") {
const eye = await loadImage(`./assets/upperTop/${opts.upperTop}.png`); const eye = await loadImage(`./assets/upperTop/${opts.upperTop}.png`);
context.drawImage(eye, 0, 0, canvas.width, canvas.height); context.drawImage(eye, 0, 0, canvas.width, canvas.height);
} }
} catch (err) { }
// [Neck] // [Neck]
try {
if (opts.neck && opts.neck !== "None") { if (opts.neck && opts.neck !== "None") {
const neck = await loadImage(`./assets/necks/${opts.neck}.png`) const neck = await loadImage(`./assets/necks/${opts.neck}.png`)
context.drawImage(neck, 0, 0, canvas.width, canvas.height) context.drawImage(neck, 0, 0, canvas.width, canvas.height)
} }
} catch (err) { }
// [Buddy] // [Buddy]
try {
if (opts.buddy && opts.buddy !== "None") { if (opts.buddy && opts.buddy !== "None") {
const buddy = await loadImage(`./assets/buddies/${opts.buddy}.png`) const buddy = await loadImage(`./assets/buddies/${opts.buddy}.png`)
context.drawImage(buddy, 0, 0, canvas.width, canvas.height) context.drawImage(buddy, 0, 0, canvas.width, canvas.height)
} }
} catch (err) { }
if (opts.direction && opts.direction == "left") { if (opts.direction && opts.direction == "left") {
let flipped = createCanvas(1280, 1280); let flipped = createCanvas(1280, 1280);