aboutsummaryrefslogtreecommitdiff
path: root/lib/render-msg.js
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-10-01 12:58:09 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-10-01 12:59:44 -1000
commit5b2e0985c1eb58df5573111b2081d09a9f489f56 (patch)
tree25218fd603f4bb9b05acb5bbc2eef1e5e5439621 /lib/render-msg.js
parent6ab9353333f70c428f652cebcd982885c42d3ab8 (diff)
downloadpatchfoo-5b2e0985c1eb58df5573111b2081d09a9f489f56.tar.gz
patchfoo-5b2e0985c1eb58df5573111b2081d09a9f489f56.zip
Render chess messages mini, with link to expand
Prefers words instead of symbol, to work better in dillo
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',