From e6f73f449c8b00e632a0734c22f81eb271c3d1a3 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Sat, 23 Jan 2021 18:54:49 -0500 Subject: [PATCH] Fix --- commands/games-mp/chess.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/commands/games-mp/chess.js b/commands/games-mp/chess.js index 7d40b798..07ece9e8 100644 --- a/commands/games-mp/chess.js +++ b/commands/games-mp/chess.js @@ -60,7 +60,7 @@ module.exports = class ChessCommand extends Command { } const game = new jsChess.Game(); let lastTurnTimeout = false; - let prevGameState = null; + let prevGameState = game.exportJson(); while (!game.exportJson().checkMate) { const user = game.exportJson().turn === 'black' ? opponent : msg.author; const gameState = game.exportJson(); @@ -121,7 +121,7 @@ module.exports = class ChessCommand extends Command { } } - displayBoard(gameState, prevGameState) { + displayBoard(gameState, prevGameState = { pieces: {} }) { const canvas = createCanvas(this.images.board.width, this.images.board.height); const ctx = canvas.getContext('2d'); ctx.drawImage(this.images.board, 0, 0); @@ -131,10 +131,10 @@ module.exports = class ChessCommand extends Command { let col = 0; for (let i = 0; i < 64; i++) { const piece = gameState.pieces[`${cols[col]}${row}`]; - const prevGamePiece = prevGameState ? prevGameState.pieces[`${cols[col]}${row}`] : null; + const prevGamePiece = prevGameState.pieces[`${cols[col]}${row}`]; if (piece) { const parsed = this.pickImage(piece); - if (prevGameState && piece !== prevGamePiece) { + if (prevGamePiece && piece !== prevGamePiece) { drawImageWithTint(ctx, this.images[parsed.color][parsed.name], 'green', w, h, 52, 52); } else { ctx.drawImage(this.images[parsed.color][parsed.name], w, h, 52, 52);