From 7fffac329b2718f0ea918cd9fd53d3e2b47cc93e Mon Sep 17 00:00:00 2001 From: cel Date: Sat, 23 Sep 2017 10:35:37 -1000 Subject: Render chess resigned --- lib/render-msg.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/render-msg.js b/lib/render-msg.js index 1cb0936..9b69603 100644 --- a/lib/render-msg.js +++ b/lib/render-msg.js @@ -1045,7 +1045,7 @@ function chessLocToIdxs(loc) { function lookupPiece(board, loc) { var idxs = chessLocToIdxs(loc) - return board[idxs[0]] && board[idxs[0]][idxs[1]] + return idxs && board[idxs[0]] && board[idxs[0]][idxs[1]] } function chessIdxsToLoc(i, j) { @@ -1053,6 +1053,7 @@ function chessIdxsToLoc(i, j) { } RenderMsg.prototype.chessBoard = function (board) { + if (!board) return '' return h('table.chess-board', board.map(function (rank, i) { return h('tr', rank.map(function (piece, j) { @@ -1112,6 +1113,14 @@ RenderMsg.prototype.chessInviteAccept = function (cb) { RenderMsg.prototype.chessGameEnd = function (cb) { var self = this var c = self.c + if (c.status === 'resigned') return self.link(self.c.root, function (err, rootLink) { + if (err) return cb(err) + self.wrap([ + h('div', h('small', '> ', rootLink)), + h('p', h('strong', 'resigned')) + ], cb) + }) + var fen = c.fen && c.fen.length === 2 ? c.pgnMove : c.fen var game = parseChess(fen) var piece = game && lookupPiece(game.board, c.dest) -- cgit v1.2.3