aboutsummaryrefslogtreecommitdiff
path: root/lib/render-msg.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/render-msg.js')
-rw-r--r--lib/render-msg.js55
1 files changed, 41 insertions, 14 deletions
diff --git a/lib/render-msg.js b/lib/render-msg.js
index 0359a1f..8ba45eb 100644
--- a/lib/render-msg.js
+++ b/lib/render-msg.js
@@ -147,6 +147,9 @@ RenderMsg.prototype.actions = function () {
h('a', {href: '?gt=' + this.msg.timestamp}, '↓'), ' '] : '',
this.c.type === 'gathering' ? [
h('a', {href: this.render.toUrl('/about/' + encodeURIComponent(this.msg.key))}, 'about'), ' '] : '',
+ /^(ssb_)?chess_/.test(this.c.type) ? [
+ h('a', {href: this.toUrl(this.msg.key) + '?full',
+ title: 'view full game board'}, 'full'), ' '] : '',
typeof this.c.text === 'string' ? [
h('a', {href: this.toUrl(this.msg.key) + '?raw=md',
title: 'view markdown source'}, 'md'), ' '] : '',
@@ -1029,24 +1032,28 @@ function parseChess(fen) {
var chessSymbols = {
' ': [' ', ''],
- P: ['♙', 'white pawn'],
- N: ['♘', 'white knight'],
- B: ['♗', 'white bishop'],
- R: ['♖', 'white rook'],
- Q: ['♕', 'white queen'],
- K: ['♔', 'white king'],
- p: ['♟', 'black pawn'],
- n: ['♞', 'black knight'],
- b: ['♝', 'black bishop'],
- r: ['♜', 'black rook'],
- q: ['♛', 'black queen'],
- k: ['♚', 'black king'],
+ P: ['♙', 'white', 'pawn'],
+ N: ['♘', 'white', 'knight'],
+ B: ['♗', 'white', 'bishop'],
+ R: ['♖', 'white', 'rook'],
+ Q: ['♕', 'white', 'queen'],
+ K: ['♔', 'white', 'king'],
+ p: ['♟', 'black', 'pawn'],
+ n: ['♞', 'black', 'knight'],
+ b: ['♝', 'black', 'bishop'],
+ r: ['♜', 'black', 'rook'],
+ q: ['♛', 'black', 'queen'],
+ k: ['♚', 'black', 'king'],
+}
+
+function chessPieceName(c) {
+ return chessSymbols[c] && chessSymbols[c][2] || '?'
}
function renderChessSymbol(c, loc) {
- var info = chessSymbols[c] || ['?', 'unknown']
+ var info = chessSymbols[c] || ['?', '', 'unknown']
return h('span.symbol', {
- title: info[1] + (loc ? ' at ' + loc : '')
+ title: info[1] + ' ' + info[2] + (loc ? ' at ' + loc : '')
}, info[0])
}
@@ -1156,6 +1163,11 @@ RenderMsg.prototype.chessGameEnd = function (cb) {
}
RenderMsg.prototype.chessMove = function (cb) {
+ if (this.opts.full) return this.chessMoveFull(cb)
+ return this.chessMoveMini(cb)
+}
+
+RenderMsg.prototype.chessMoveFull = function (cb) {
var self = this
var c = self.c
var fen = c.fen && c.fen.length === 2 ? c.pgnMove : c.fen
@@ -1176,6 +1188,21 @@ RenderMsg.prototype.chessMove = function (cb) {
})
}
+RenderMsg.prototype.chessMoveMini = 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.wrapMini([
+ 'moved ', chessPieceName(piece), ' ',
+ 'to ', c.dest
+ ], cb)
+ })
+}
+
RenderMsg.prototype.acmeChallengesHttp01 = function (cb) {
var self = this
self.wrapMini(h('span',