aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-07-25 10:31:22 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-07-25 10:45:18 -1000
commit37b9781e79d6cc9fc3242f5891af88b8540f722a (patch)
treec1f4e099235c181b83f167e9145a5e644c8fd5d9 /lib
parent1a33bad6b4f7fda5a5567e2c9b9d1fb20658cfc9 (diff)
downloadpatchfoo-37b9781e79d6cc9fc3242f5891af88b8540f722a.tar.gz
patchfoo-37b9781e79d6cc9fc3242f5891af88b8540f722a.zip
Improve chess rendering
- Try to align grid better. %24ydxCxrlEp+fQ+nOQars80VWKIXaT/LwKTCf0MvHKk=.sha256 - Render unprefixed message types - Render game end
Diffstat (limited to 'lib')
-rw-r--r--lib/render-msg.js85
1 files changed, 72 insertions, 13 deletions
diff --git a/lib/render-msg.js b/lib/render-msg.js
index 7a00580..e9fc413 100644
--- a/lib/render-msg.js
+++ b/lib/render-msg.js
@@ -238,13 +238,22 @@ RenderMsg.prototype.message = function (cb) {
case 'ferment/update':
case 'robeson/update':
return this.update(cb)
+ case 'chess_invite':
+ case 'ssb_chess_invite':
+ return this.chessInvite(cb)
+ case 'chess_invite_accept':
+ case 'ssb_chess_invite_accept':
+ return this.chessInviteAccept(cb)
+ case 'chess_move':
+ case 'ssb_chess_move':
+ return this.chessMove(cb)
+ case 'chess_game_end':
+ case 'ssb_chess_game_end':
+ return this.chessGameEnd(cb)
case 'wifi-network': return this.wifiNetwork(cb)
case 'mutual/credit': return this.mutualCredit(cb)
case 'mutual/account': return this.mutualAccount(cb)
case 'npm-publish': return this.npmPublish(cb)
- case 'ssb_chess_invite': return this.chessInvite(cb)
- case 'ssb_chess_invite_accept': return this.chessInviteAccept(cb)
- case 'ssb_chess_move': return this.chessMove(cb)
default: return this.object(cb)
}
}
@@ -1027,6 +1036,19 @@ function chessIdxsToLoc(i, j) {
return 'abcdefgh'[j] + (8-i)
}
+RenderMsg.prototype.chessBoard = function (board) {
+ return h('table.chess-board',
+ board.map(function (rank, i) {
+ return h('tr', rank.map(function (piece, j) {
+ var dark = (i ^ j) & 1
+ return h('td', {
+ class: 'chess-square chess-square-' + (dark ? 'dark' : 'light'),
+ }, renderChessSymbol(piece, chessIdxsToLoc(i, j)))
+ }))
+ })
+ )
+}
+
RenderMsg.prototype.chessMove = function (cb) {
var self = this
var c = self.c
@@ -1043,16 +1065,7 @@ RenderMsg.prototype.chessMove = function (cb) {
'from ', c.orig, ' ',
'to ', c.dest
),
- h('table.chess-board',
- game.board.map(function (rank, i) {
- return h('tr', rank.map(function (piece, j) {
- var dark = (i ^ j) & 1
- return h('td', {
- class: 'chess-square-' + (dark ? 'dark' : 'light'),
- }, renderChessSymbol(piece, chessIdxsToLoc(i, j)))
- }))
- })
- )
+ self.chessBoard(game.board)
], cb)
})
}
@@ -1079,3 +1092,49 @@ RenderMsg.prototype.chessInviteAccept = function (cb) {
], cb)
})
}
+
+RenderMsg.prototype.chessGameEnd = function (cb) {
+ var self = this
+ var c = self.c
+ var fen = c.fen && c.fen.length === 2 ? c.pgnMove : c.fen
+ var game = parseChess(fen)
+ var piece = game && lookupPiece(game.board, c.dest)
+ var done = multicb({pluck: 1, spread: true})
+ self.link(self.c.root, done())
+ self.link(self.c.winner, done())
+ done(function (err, rootLink, winnerLink) {
+ if (err) return cb(err)
+ self.wrap([
+ h('div', h('small', '> ', rootLink)),
+ h('p',
+ 'moved ', (piece ? renderChessSymbol(piece) : ''), ' ',
+ 'from ', c.orig, ' ',
+ 'to ', c.dest
+ ),
+ h('p',
+ h('strong', self.c.status), '. winner: ', h('strong', winnerLink)),
+ self.chessBoard(game.board)
+ ], cb)
+ })
+}
+
+RenderMsg.prototype.chessMove = function (cb) {
+ var self = this
+ var c = self.c
+ var fen = c.fen && c.fen.length === 2 ? c.pgnMove : c.fen
+ var game = parseChess(fen)
+ var piece = game && lookupPiece(game.board, c.dest)
+ self.link(self.c.root, function (err, rootLink) {
+ if (err) return cb(err)
+ self.wrap([
+ h('div', h('small', '> ', rootLink)),
+ h('p',
+ // 'player ', (c.ply || ''), ' ',
+ 'moved ', (piece ? renderChessSymbol(piece) : ''), ' ',
+ 'from ', c.orig, ' ',
+ 'to ', c.dest
+ ),
+ self.chessBoard(game.board)
+ ], cb)
+ })
+}