mirror of
https://github.com/DaInfLoop/Battler-Generator.git
synced 2024-11-21 13:29:55 +00:00
Add error handling
Also just known as not rendering if said item doesn't exist
This commit is contained in:
parent
228122fbbd
commit
25394c9b7c
122
utils.ts
122
utils.ts
|
@ -21,80 +21,104 @@ export async function generateBattler(
|
||||||
// Load + draw the necessary images
|
// Load + draw the necessary images
|
||||||
|
|
||||||
// [Glow]
|
// [Glow]
|
||||||
if (opts.glow && opts.glow !== "None") {
|
try {
|
||||||
const glow = await loadImage(`./assets/glows/${opts.glow}.png`);
|
if (opts.glow && opts.glow !== "None") {
|
||||||
context.drawImage(glow, 0, 0, canvas.width, canvas.height);
|
const glow = await loadImage(`./assets/glows/${opts.glow}.png`);
|
||||||
}
|
context.drawImage(glow, 0, 0, canvas.width, canvas.height);
|
||||||
|
}
|
||||||
|
} catch (err) { }
|
||||||
|
|
||||||
// [Back]
|
// [Back]
|
||||||
if (opts.back && opts.back !== "None") {
|
try {
|
||||||
const back = await loadImage(`./assets/backs/${opts.back}.png`)
|
if (opts.back && opts.back !== "None") {
|
||||||
context.drawImage(back, 0, 0, canvas.width, canvas.height)
|
const back = await loadImage(`./assets/backs/${opts.back}.png`)
|
||||||
}
|
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]
|
||||||
if (opts.upperBottom && opts.upperBottom !== "None") {
|
try {
|
||||||
const face = await loadImage(`./assets/upperBottom/${opts.face}.png`);
|
if (opts.upperBottom && opts.upperBottom !== "None") {
|
||||||
context.drawImage(face, 0, 0, canvas.width, canvas.height);
|
const face = await loadImage(`./assets/upperBottom/${opts.face}.png`);
|
||||||
}
|
context.drawImage(face, 0, 0, canvas.width, canvas.height);
|
||||||
|
}
|
||||||
|
} catch (err) { }
|
||||||
|
|
||||||
// [Bottom]
|
// [Bottom]
|
||||||
if (opts.bottom && opts.bottom !== "None") {
|
try {
|
||||||
const bottom = await loadImage(`./assets/bottoms/${opts.bottom}.png`);
|
if (opts.bottom && opts.bottom !== "None") {
|
||||||
context.drawImage(bottom, 0, 0, canvas.width, canvas.height);
|
const bottom = await loadImage(`./assets/bottoms/${opts.bottom}.png`);
|
||||||
}
|
context.drawImage(bottom, 0, 0, canvas.width, canvas.height);
|
||||||
|
}
|
||||||
|
} catch (err) { }
|
||||||
|
|
||||||
// [Top]
|
// [Top]
|
||||||
if (opts.top && opts.top !== "None") {
|
try {
|
||||||
const top = await loadImage(`./assets/tops/${opts.top}.png`);
|
if (opts.top && opts.top !== "None") {
|
||||||
context.drawImage(top, 0, 0, canvas.width, canvas.height);
|
const top = await loadImage(`./assets/tops/${opts.top}.png`);
|
||||||
}
|
context.drawImage(top, 0, 0, canvas.width, canvas.height);
|
||||||
|
}
|
||||||
|
} catch (err) { }
|
||||||
|
|
||||||
// [Face]
|
// [Face]
|
||||||
if (opts.face && opts.face !== "None") {
|
try {
|
||||||
const face = await loadImage(`./assets/faces/${opts.face}.png`);
|
if (opts.face && opts.face !== "None") {
|
||||||
context.drawImage(face, 0, 0, canvas.width, canvas.height);
|
const face = await loadImage(`./assets/faces/${opts.face}.png`);
|
||||||
}
|
context.drawImage(face, 0, 0, canvas.width, canvas.height);
|
||||||
|
}
|
||||||
|
} catch (err) { }
|
||||||
|
|
||||||
// [Hair]
|
// [Hair]
|
||||||
if (opts.hair && opts.hair !== "None") {
|
try {
|
||||||
const face = await loadImage(`./assets/hair/${opts.hair}.png`);
|
if (opts.hair && opts.hair !== "None") {
|
||||||
context.drawImage(face, 0, 0, canvas.width, canvas.height);
|
const face = await loadImage(`./assets/hair/${opts.hair}.png`);
|
||||||
}
|
context.drawImage(face, 0, 0, canvas.width, canvas.height);
|
||||||
|
}
|
||||||
|
} catch (err) { }
|
||||||
|
|
||||||
// [Hat]
|
// [Hat]
|
||||||
if (opts.hat && opts.hat !== "None") {
|
try {
|
||||||
const hat = await loadImage(`./assets/hats/${opts.hat}.png`);
|
if (opts.hat && opts.hat !== "None") {
|
||||||
context.drawImage(hat, 0, 0, canvas.width, canvas.height);
|
const hat = await loadImage(`./assets/hats/${opts.hat}.png`);
|
||||||
}
|
context.drawImage(hat, 0, 0, canvas.width, canvas.height);
|
||||||
|
}
|
||||||
|
} catch (err) { }
|
||||||
|
|
||||||
// [Eyes]
|
// [Eyes]
|
||||||
if (opts.eye && opts.eye !== "None") {
|
try {
|
||||||
const eye = await loadImage(`./assets/eyes/${opts.eye}.png`);
|
if (opts.eye && opts.eye !== "None") {
|
||||||
context.drawImage(eye, 0, 0, canvas.width, canvas.height);
|
const eye = await loadImage(`./assets/eyes/${opts.eye}.png`);
|
||||||
}
|
context.drawImage(eye, 0, 0, canvas.width, canvas.height);
|
||||||
|
}
|
||||||
|
} catch (err) { }
|
||||||
|
|
||||||
// [Upper Top]
|
// [Upper Top]
|
||||||
if (opts.upperTop && opts.upperTop !== "None") {
|
try {
|
||||||
const eye = await loadImage(`./assets/upperTop/${opts.upperTop}.png`);
|
if (opts.upperTop && opts.upperTop !== "None") {
|
||||||
context.drawImage(eye, 0, 0, canvas.width, canvas.height);
|
const eye = await loadImage(`./assets/upperTop/${opts.upperTop}.png`);
|
||||||
}
|
context.drawImage(eye, 0, 0, canvas.width, canvas.height);
|
||||||
|
}
|
||||||
|
} catch (err) { }
|
||||||
|
|
||||||
// [Neck]
|
// [Neck]
|
||||||
if (opts.neck && opts.neck !== "None") {
|
try {
|
||||||
const neck = await loadImage(`./assets/necks/${opts.neck}.png`)
|
if (opts.neck && opts.neck !== "None") {
|
||||||
context.drawImage(neck, 0, 0, canvas.width, canvas.height)
|
const neck = await loadImage(`./assets/necks/${opts.neck}.png`)
|
||||||
}
|
context.drawImage(neck, 0, 0, canvas.width, canvas.height)
|
||||||
|
}
|
||||||
|
} catch (err) { }
|
||||||
|
|
||||||
// [Buddy]
|
// [Buddy]
|
||||||
if (opts.buddy && opts.buddy !== "None") {
|
try {
|
||||||
const buddy = await loadImage(`./assets/buddies/${opts.buddy}.png`)
|
if (opts.buddy && opts.buddy !== "None") {
|
||||||
context.drawImage(buddy, 0, 0, canvas.width, canvas.height)
|
const buddy = await loadImage(`./assets/buddies/${opts.buddy}.png`)
|
||||||
}
|
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);
|
||||||
|
|
Loading…
Reference in a new issue