aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/render-msg.js110
1 files changed, 110 insertions, 0 deletions
diff --git a/lib/render-msg.js b/lib/render-msg.js
index 5fcf9ff..8251905 100644
--- a/lib/render-msg.js
+++ b/lib/render-msg.js
@@ -153,6 +153,7 @@ RenderMsg.prototype.wrapMini = function (content, cb) {
}
RenderMsg.prototype.actions = function () {
+ var lastMove
return this.msg.key ?
h('form', {method: 'post', action: ''},
this.msg.rel ? [this.msg.rel, ' '] : '',
@@ -163,6 +164,8 @@ RenderMsg.prototype.actions = function () {
title: 'view post edit diff'}, 'diff'), ' '] : '',
this.c.type === 'gathering' ? [
h('a', {href: this.render.toUrl('/about/' + encodeURIComponent(this.msg.key))}, 'about'), ' '] : '',
+ this.c.type === 'ssb-igo' && (lastMove = this.c.values[0] && this.c.values[0].lastMove) ? [
+ h('a', {href: this.render.toUrl(lastMove)}, 'previous'), ' '] : '',
/^(ssb_)?chess_/.test(this.c.type) ? [
h('a', {href: this.toUrl(this.msg.key) + '?full',
title: 'view full game board'}, 'full'), ' '] : '',
@@ -308,6 +311,7 @@ RenderMsg.prototype.message = function (cb) {
case 'edit': return this.edit(cb)
case 'dark-crystal/shard': return this.shard(cb)
case 'invite': return this.invite(cb)
+ case 'ssb-igo': return this.igo(cb)
default: return this.object(cb)
}
}
@@ -1946,3 +1950,109 @@ RenderMsg.prototype.invite = function (cb) {
]), cb)
})
}
+
+RenderMsg.prototype.pickIgoFn = function () {
+ switch (this.c.tag) {
+ case 'App.IgoMsg.Kibitz': return this.igoKibitz
+ case 'App.IgoMsg.OfferMatch': return this.igoOfferMatch
+ case 'App.IgoMsg.AcceptMatch': return this.igoAcceptMatch
+ case 'App.IgoMsg.PlayMove': return this.igoPlayMove
+ }
+}
+
+RenderMsg.prototype.igo = function (cb) {
+ var self = this
+ var fn = self.pickIgoFn()
+ if (!fn) return self.object(cb)
+ var done = multicb({pluck: 1})
+ u.toArray(this.c.values).forEach(function (value) {
+ fn.call(self, value, done())
+ })
+ done(function (err, els) {
+ if (err) return self.wrap(u.renderError(err), cb)
+ if (els.length === 1 && els[0].tagName === 'span') return self.wrapMini(els[0], cb)
+ self.wrap(h('div', els), cb)
+ })
+}
+
+RenderMsg.prototype.igoKibitz = function (value, cb) {
+ var self = this
+ var text = value && value.text
+ self.link(value.move, function (err, moveLink) {
+ cb(null, h('div', [
+ h('div', h('small', h('span.symbol', '  ↳'), ' ', moveLink || '?')),
+ text ? h('div', {innerHTML: self.render.markdown(text)}) : ''
+ ]))
+ })
+}
+
+RenderMsg.prototype.igoOfferMatch = function (value, cb) {
+ var self = this
+ var terms = self.c.terms || {}
+ var size = Number(terms.size)
+ var komi = Number(terms.komi)
+ var handicap = Number(terms.handicap)
+ var opponentId = value.opponentKey
+ /*
+ var myColor = self.c.myColor || {}
+ var color =
+ myColor.tag === 'App.IgoMsg.Black' ? 'black ●' :
+ myColor.tag === 'App.IgoMsg.White' ? 'white ○' :
+ '?'
+ */
+ self.link(opponentId, function (err, opponentLink) {
+ cb(null, h('span', [
+ 'invites ',
+ opponentLink,
+ ' to play Go'
+ ]))
+ })
+}
+
+RenderMsg.prototype.igoAcceptMatch = function (value, cb) {
+ var self = this
+ /*
+ var terms = self.c.terms || {}
+ var size = Number(terms.size)
+ var komi = Number(terms.komi)
+ var handicap = Number(terms.handicap)
+ */
+ self.getMsg(value.offerKey, function (err, offerMsg) {
+ if (err) return cb(err)
+ self.link(offerMsg && offerMsg.value.author, function (err, offerAuthorLink) {
+ if (err) return cb(err)
+ cb(null, h('span',
+ 'accepts ',
+ h('a', {href: self.toUrl(offerMsg && offerMsg.key)}, 'invitation to play Go'), ' ',
+ 'with ', offerAuthorLink
+ ))
+ })
+ })
+}
+
+RenderMsg.prototype.igoPlayMove = function (value, cb) {
+ var self = this
+ // value.subjectiveMoveNum
+ var move = value.move || {}
+ if (move.tag === 'App.IgoMsg.PlayStone') {
+ var moveValues = u.toArray(move.values)
+ if (moveValues.length === 1) {
+ var moveValue = moveValues[0]
+ if (moveValue.tag === 'App.IgoMsg.BoardPosition') {
+ var boardPosValues = moveValue.values
+ if (boardPosValues.length === 1) {
+ var boardPos = boardPosValues[0]
+ var x = Number(boardPos.x)
+ var y = Number(boardPos.y)
+ return cb(null, h('span',
+ 'placed a stone at ',
+ '[' + x + ', ' + y + ']'))
+ }
+ }
+ }
+ }
+
+ var table = self.valueTable(move, 2, function (err) {
+ cb(err, table)
+ })
+}