diff options
author | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-10-01 12:58:09 -1000 |
---|---|---|
committer | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-10-01 12:59:44 -1000 |
commit | 5b2e0985c1eb58df5573111b2081d09a9f489f56 (patch) | |
tree | 25218fd603f4bb9b05acb5bbc2eef1e5e5439621 /lib | |
parent | 6ab9353333f70c428f652cebcd982885c42d3ab8 (diff) | |
download | patchfoo-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')
-rw-r--r-- | lib/render-msg.js | 55 | ||||
-rw-r--r-- | lib/serve.js | 2 |
2 files changed, 42 insertions, 15 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', diff --git a/lib/serve.js b/lib/serve.js index 6a08c4a..6a0bb88 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -1198,7 +1198,7 @@ Serve.prototype.wrapMessages = function () { Serve.prototype.renderThread = function () { return pull( - this.app.render.renderFeeds(false), + this.app.render.renderFeeds({raw: false, full: this.query.full != null}), pull.map(u.toHTML) ) } |