refactor keyboard moving
parent
f478463849
commit
d470f6c609
|
@ -10,9 +10,7 @@ function lichessKeyboardMove(opts) {
|
|||
var foundUci = v.length >= 2 && sans && sanToUci(v, sans);
|
||||
if (foundUci) {
|
||||
if (v.toLowerCase() === 'o-o' && sans['O-O-O'] && !force) return;
|
||||
opts.cancel();
|
||||
opts.select(foundUci.slice(0, 2));
|
||||
opts.select(foundUci.slice(2));
|
||||
opts.san(foundUci.slice(0, 2), foundUci.slice(2));
|
||||
clear();
|
||||
} else if (sans && v.match(keyRegex)) {
|
||||
opts.select(v);
|
||||
|
|
|
@ -58,7 +58,7 @@ module.exports = function(opts) {
|
|||
this.socket = new socket(opts.socketSend, this);
|
||||
|
||||
var onUserMove = function(orig, dest, meta) {
|
||||
lichess.ab && lichess.ab(this, meta);
|
||||
lichess.ab && (!this.keyboardMove || !this.keyboardMove.usedSan) && lichess.ab(this, meta);
|
||||
if (!promotion.start(this, orig, dest, meta))
|
||||
this.sendMove(orig, dest, false, meta.premove);
|
||||
}.bind(this);
|
||||
|
|
|
@ -5,6 +5,11 @@ module.exports = {
|
|||
var focus = m.prop(false);
|
||||
var handler;
|
||||
var preHandlerBuffer = step.fen;
|
||||
var select = function(key) {
|
||||
if (cg.data.selected === key) cg.cancelMove();
|
||||
else cg.selectSquare(key, true);
|
||||
};
|
||||
var usedSan = false;
|
||||
return {
|
||||
update: function(step) {
|
||||
if (handler) handler(step.fen, cg.data.movable.dests);
|
||||
|
@ -15,11 +20,14 @@ module.exports = {
|
|||
if (preHandlerBuffer) handler(preHandlerBuffer, cg.data.movable.dests);
|
||||
},
|
||||
focus: focus,
|
||||
select: function(key) {
|
||||
if (cg.data.selected === key) cg.cancelMove();
|
||||
else cg.selectSquare(key, true);
|
||||
san: function(orig, dest) {
|
||||
usedSan = true;
|
||||
cg.cancelMove();
|
||||
select(orig);
|
||||
select(dest);
|
||||
},
|
||||
cancel: cg.cancelMove
|
||||
select: select,
|
||||
usedSan: usedSan
|
||||
};
|
||||
},
|
||||
view: function(ctrl) {
|
||||
|
@ -31,7 +39,7 @@ module.exports = {
|
|||
input: el,
|
||||
focus: ctrl.focus,
|
||||
select: ctrl.select,
|
||||
cancel: ctrl.cancel
|
||||
san: ctrl.san
|
||||
}));
|
||||
});
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue