aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2019-01-09 10:31:37 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2019-01-09 10:31:37 -1000
commite8eb271296e7f928e01e4260d6681593d232381f (patch)
tree2ba85aa2d7d0be8a841b517dd0dc088b45ed28e7
parent081f331f7948b2cba69f26501dd28c2f7f754192 (diff)
downloadpatchfoo-e8eb271296e7f928e01e4260d6681593d232381f.tar.gz
patchfoo-e8eb271296e7f928e01e4260d6681593d232381f.zip
Render castling better
-rw-r--r--lib/render-msg.js18
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/render-msg.js b/lib/render-msg.js
index 7794382..9308495 100644
--- a/lib/render-msg.js
+++ b/lib/render-msg.js
@@ -1315,8 +1315,9 @@ function chessPieceName(c) {
function renderChessSymbol(c, loc) {
var info = chessSymbols[c] || ['?', '', 'unknown']
+ var piece = info && c !== ' ' ? info[1] + ' ' + info[2] : ''
return h('span.symbol', {
- title: info[1] + ' ' + info[2] + (loc ? ' at ' + loc : '')
+ title: piece + (piece && loc ? ' at ' : '') + (loc || '')
}, info[0])
}
@@ -1327,7 +1328,18 @@ function chessLocToIdxs(loc) {
function lookupPiece(board, loc) {
var idxs = chessLocToIdxs(loc)
- return idxs && board[idxs[0]] && board[idxs[0]][idxs[1]]
+ if (!idxs) return
+ var piece = board[idxs[0]] && board[idxs[0]][idxs[1]]
+ if (!piece || piece === ' ') {
+ // detect castling
+ if (idxs[0] === 0 || idxs[0] === 7) {
+ if (idxs[1] === 0) idxs[1]++
+ else if (idxs[1] == 7) idxs[1]--
+ else return piece
+ piece = board[idxs[0]] && board[idxs[0]][idxs[1]]
+ }
+ }
+ return piece
}
function chessIdxsToLoc(i, j) {
@@ -1455,7 +1467,7 @@ RenderMsg.prototype.chessMoveFull = function (cb) {
}),
h('p',
// 'player ', (c.ply || ''), ' ',
- 'moved ', (piece ? [renderChessSymbol(piece), ' '] : ''),
+ piece ? ['moved ', renderChessSymbol(piece), ' '] : '',
'from ' + c.orig, ' ',
'to ' + c.dest
),