From 416ed3ce323e3af927b135a5da3da430b8c63206 Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Tue, 26 Jan 2016 10:46:16 +0700 Subject: [PATCH] support for piece drop confirmation --- ui/round/src/ctrl.js | 26 ++++++++++++++++++-------- ui/round/src/view/button.js | 2 +- ui/round/src/view/table.js | 2 +- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/ui/round/src/ctrl.js b/ui/round/src/ctrl.js index 6ffd0e37e2..f74bd01b30 100644 --- a/ui/round/src/ctrl.js +++ b/ui/round/src/ctrl.js @@ -34,6 +34,7 @@ module.exports = function(opts) { redirecting: false, replayHash: '', moveToSubmit: null, + dropToSubmit: null, buttonFeedback: null, goneBerserk: {}, resignConfirm: false, @@ -58,9 +59,9 @@ module.exports = function(opts) { this.sendMove(orig, dest, false, meta.premove); }.bind(this); - var onUserNewPiece = function(role, key) { + var onUserNewPiece = function(role, key, meta) { if (!this.replaying() && crazyValid.drop(this.chessground, this.data, role, key)) - this.sendNewPiece(role, key); + this.sendNewPiece(role, key, meta.predrop); else this.jump(this.vm.ply); }.bind(this); @@ -159,14 +160,17 @@ module.exports = function(opts) { }); }.bind(this); - this.sendNewPiece = function(role, key) { + this.sendNewPiece = function(role, key, isPredrop) { var drop = { role: role, pos: key }; if (this.clock) drop.lag = Math.round(lichess.socket.averageLag); this.resign(false); - this.socket.send('drop', drop, { + if (this.userId && this.data.pref.submitMove && !isPredrop) { + this.vm.dropToSubmit = drop; + m.redraw(); + } else this.socket.send('drop', drop, { ackable: true }); }.bind(this); @@ -369,13 +373,19 @@ module.exports = function(opts) { }.bind(this); this.submitMove = function(v) { - if (v && this.vm.moveToSubmit) { - this.socket.send('move', this.vm.moveToSubmit, { - ackable: true - }); + if (v && (this.vm.moveToSubmit || this.vm.dropToSubmit)) { + if (this.vm.moveToSubmit) + this.socket.send('move', this.vm.moveToSubmit, { + ackable: true + }); + else if (this.vm.dropToSubmit) + this.socket.send('drop', this.vm.dropToSubmit, { + ackable: true + }); $.sound.confirmation(); } else this.jump(this.vm.ply); this.vm.moveToSubmit = null; + this.vm.dropToSubmit = null; this.vm.buttonFeedback = setTimeout(function() { this.vm.buttonFeedback = null; m.redraw(); diff --git a/ui/round/src/view/button.js b/ui/round/src/view/button.js index d8f2a6cd85..a183213b78 100644 --- a/ui/round/src/view/button.js +++ b/ui/round/src/view/button.js @@ -106,7 +106,7 @@ module.exports = { ]); }, submitMove: function(ctrl) { - if (ctrl.vm.moveToSubmit) return [ + if (ctrl.vm.moveToSubmit || ctrl.vm.dropToSubmit) return [ m('a.button.text[data-icon=E]', { onclick: partial(ctrl.submitMove, true), }, 'Submit move'), diff --git a/ui/round/src/view/table.js b/ui/round/src/view/table.js index a172357d97..c427b52a6d 100644 --- a/ui/round/src/view/table.js +++ b/ui/round/src/view/table.js @@ -89,7 +89,7 @@ function renderTablePlay(ctrl) { ]); return [ renderReplay(ctrl), - ctrl.vm.moveToSubmit ? null : ( + (ctrl.vm.moveToSubmit || ctrl.vm.dropToSubmit) ? null : ( button.feedback(ctrl) || m('div.control.icons', [ game.abortable(d) ? button.standard(ctrl, null, 'L', 'abortGame', 'abort') : button.standard(ctrl, game.takebackable, 'i', 'proposeATakeback', 'takeback-yes', ctrl.takebackYes),