analysis: enter variation with shift+right
This commit is contained in:
parent
40b457c820
commit
80a83f8899
|
@ -1,3 +1,5 @@
|
|||
var path = require('./path');
|
||||
|
||||
function canGoForward(ctrl) {
|
||||
var tree = ctrl.analyse.tree;
|
||||
var ok = false;
|
||||
|
@ -13,6 +15,23 @@ function canGoForward(ctrl) {
|
|||
return ok;
|
||||
}
|
||||
|
||||
function canEnterVariation(ctrl) {
|
||||
var tree = ctrl.analyse.tree;
|
||||
var ok = false;
|
||||
ctrl.vm.path.forEach(function(step) {
|
||||
for (i = 0, nb = tree.length; i < nb; i++) {
|
||||
var move = tree[i];
|
||||
if (step.ply === move.ply) {
|
||||
if (step.variation) {
|
||||
tree = move.variations[step.variation - 1];
|
||||
break;
|
||||
} else ok = move.variations.length > 0;
|
||||
}
|
||||
}
|
||||
});
|
||||
return ok;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
canGoForward: canGoForward,
|
||||
|
@ -53,5 +72,10 @@ module.exports = {
|
|||
ply: 0,
|
||||
variation: null
|
||||
}]);
|
||||
},
|
||||
|
||||
enterVariation: function(ctrl) {
|
||||
if (canEnterVariation(ctrl))
|
||||
ctrl.userJump(path.withVariation(ctrl.vm.path, 1));
|
||||
}
|
||||
};
|
||||
|
|
|
@ -23,6 +23,10 @@ module.exports = function(ctrl) {
|
|||
control.next(ctrl);
|
||||
m.redraw();
|
||||
}));
|
||||
k.bind('shift+right', preventing(function() {
|
||||
control.enterVariation(ctrl);
|
||||
m.redraw();
|
||||
}));
|
||||
k.bind(['up', 'k'], preventing(function() {
|
||||
control.first(ctrl);
|
||||
m.redraw();
|
||||
|
|
Loading…
Reference in a new issue