mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Fix
This commit is contained in:
@@ -74,7 +74,7 @@ module.exports = class PokedexBoxSpriteCommand extends Command {
|
||||
const y = Math.floor(this.id / 12) * 30;
|
||||
ctx.imageSmoothingEnabled = false;
|
||||
ctx.drawImage(this.client.pokemon.sprites, x, y, 40, 30, 0, 0, 250, 250);
|
||||
cropToContent(ctx, canvas.width, canvas.height);
|
||||
cropToContent(ctx, canvas, canvas.width, canvas.height);
|
||||
return msg.say(`#${pokemon.displayID} - ${pokemon.name}`, {
|
||||
files: [{
|
||||
attachment: canvas.toBuffer(),
|
||||
|
||||
@@ -158,7 +158,7 @@ module.exports = class Pokemon {
|
||||
const x = 40 * (this.id % 12);
|
||||
const y = Math.floor(this.id / 12) * 30;
|
||||
ctx.drawImage(this.store.sprites, x, y, 40, 30, 0, 0, 40, 30);
|
||||
cropToContent(ctx, canvas.width, canvas.height);
|
||||
cropToContent(ctx, canvas, canvas.width, canvas.height);
|
||||
return canvas.toBuffer();
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -146,9 +146,9 @@ module.exports = class CanvasUtil {
|
||||
return ctx;
|
||||
}
|
||||
|
||||
static cropToContent(ctx, w, h) {
|
||||
static cropToContent(ctx, canvas, w, h) {
|
||||
const pix = { x: [], y: [] };
|
||||
const imageData = ctx.getImageData(0, 0, ctx.canvas.width, ctx.canvas.height);
|
||||
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
||||
let index;
|
||||
for (let y = 0; y < h; y++) {
|
||||
for (let x = 0; x < w; x++) {
|
||||
@@ -165,8 +165,8 @@ module.exports = class CanvasUtil {
|
||||
const newW = (1 + pix.x[n]) - pix.x[0];
|
||||
const newH = (1 + pix.y[n]) - pix.y[0];
|
||||
const cut = ctx.getImageData(pix.x[0], pix.y[0], newW, newH);
|
||||
ctx.canvas.width = newW;
|
||||
ctx.canvas.height = newH;
|
||||
canvas.width = newW;
|
||||
canvas.height = newH;
|
||||
ctx.putImageData(cut, 0, 0);
|
||||
return ctx;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user