New Chess Board Image

This commit is contained in:
Dragon Fire
2021-02-07 09:11:51 -05:00
parent b52ffc8e4c
commit 69707490e2
3 changed files with 15 additions and 14 deletions
Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 14 KiB

+14 -13
View File
@@ -5,7 +5,7 @@ const moment = require('moment');
const { stripIndents } = require('common-tags');
const path = require('path');
const { verify, reactIfAble } = require('../../util/Util');
const { drawImageWithTint } = require('../../util/Canvas');
const { drawImageWithTint, centerImagePart } = require('../../util/Canvas');
const { FAILURE_EMOJI_ID } = process.env;
const turnRegex = /^([A-H][1-8])(?: |, ?|-?>?)?([A-H][1-8])$/;
const pieces = ['pawn', 'rook', 'knight', 'king', 'queen', 'bishop'];
@@ -25,10 +25,9 @@ module.exports = class ChessCommand extends Command {
reason: 'Piece Images'
},
{
name: 'Wikimedia Commons',
url: 'https://commons.wikimedia.org/wiki/Main_Page',
reason: 'Board Image',
reasonURL: 'https://commons.wikimedia.org/wiki/File:Chess_board_blank.svg'
name: 'Chess.com',
url: 'https://www.chess.com/',
reason: 'Board Image'
}
],
args: [
@@ -193,8 +192,8 @@ module.exports = class ChessCommand extends Command {
const canvas = createCanvas(this.images.board.width, this.images.board.height);
const ctx = canvas.getContext('2d');
ctx.drawImage(this.images.board, 0, 0);
let w = 36;
let h = 40;
let w = 2;
let h = 3;
let row = 8;
let col = 0;
for (let i = 0; i < 64; i++) {
@@ -202,23 +201,25 @@ module.exports = class ChessCommand extends Command {
const prevGamePiece = prevPieces ? prevPieces[`${cols[col]}${row}`] : null;
if (piece) {
const parsed = this.pickImage(piece);
const img = this.images[parsed.color][parsed.name];
const { x, y, width, height } = centerImagePart(img, 61, 61, w, h);
if (prevPieces && (!prevGamePiece || piece !== prevGamePiece)) {
drawImageWithTint(ctx, this.images[parsed.color][parsed.name], 'green', w, h, 52, 52);
drawImageWithTint(ctx, img, 'green', x, y, width, height);
} else {
ctx.drawImage(this.images[parsed.color][parsed.name], w, h, 52, 52);
ctx.drawImage(img, x, y, width, height);
}
} else if (prevGamePiece) {
ctx.fillStyle = 'green';
ctx.globalAlpha = 0.5;
ctx.fillRect(w, h, 52, 52);
ctx.fillRect(w, h, 61, 61);
ctx.globalAlpha = 1;
}
w += 52 + 2;
w += 61 + 1;
col += 1;
if (col % 8 === 0 && col !== 0) {
w = 36;
w = 2;
col = 0;
h += 52 + 2;
h += 61 + 1;
row -= 1;
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "128.4.6",
"version": "128.4.7",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {