aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/render-msg.js85
-rw-r--r--static/styles.css6
2 files changed, 78 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)
+ })
+}
diff --git a/static/styles.css b/static/styles.css
index 5980e2a..c26cf59 100644
--- a/static/styles.css
+++ b/static/styles.css
@@ -184,6 +184,12 @@ table.ssb-object td {
border: 1px solid black;
}
+.chess-square {
+ width: 1em;
+ height: 1em;
+ text-align: center;
+}
+
.chess-square-dark {
background-color: #ccc;
}