toggle analysis arrows

pull/1031/head
Thibault Duplessis 2015-09-24 19:04:16 +02:00
parent c9c1e891cd
commit 8ec35f48c5
3 changed files with 35 additions and 10 deletions

View File

@ -67,6 +67,9 @@ module.exports = {
onclick: partial(ctrl.togglePlay, speed.delay)
}, 'Auto play ' + speed.name);
}) : null,
m('a.button.text', {
onclick: ctrl.toggleAutoShapes
}, 'Show analysis arrows'),
deleteButton(ctrl.data, ctrl.userId),
ctrl.ongoing ? null : m('div.continue_with.' + ctrl.data.game.id, [
m('a.button', {

View File

@ -39,7 +39,8 @@ module.exports = function(opts) {
step: null,
cgConfig: null,
comments: true,
flip: false
flip: false,
showAutoShapes: util.storedProp('show-auto-shapes', true)
};
this.flip = function() {
@ -229,15 +230,18 @@ module.exports = function(opts) {
this.toggleCeval = function() {
this.ceval.toggle();
if (this.ceval.enabled())
setAutoShapesFromEval();
else
this.chessground.setAutoShapes([]);
if (this.ceval.enabled()) setAutoShapesFromEval();
else this.chessground.setAutoShapes([]);
startCeval();
}.bind(this);
this.toggleAutoShapes = function() {
if (this.vm.showAutoShapes(!this.vm.showAutoShapes())) setAutoShapesFromEval();
else this.chessground.setAutoShapes([]);
}.bind(this);
var setAutoShapesFromEval = function() {
if (!this.ceval.enabled()) return;
if (!this.ceval.enabled() || !this.vm.showAutoShapes()) return;
var s = this.vm.step,
shapes = [];
if (s.eval && s.eval.best) shapes.push(makeAutoShapeFromUci(s.eval.best, 'paleGreen'));

View File

@ -2,9 +2,13 @@ var piotr2key = require('./piotr').piotr2key;
var UNDEF = 'undefined';
var defined = function(v) {
return typeof v !== UNDEF;
};
module.exports = {
readDests: function(lines) {
if (typeof lines === UNDEF) return null;
if (!defined(lines)) return null;
var dests = {};
if (lines) lines.split(' ').forEach(function(line) {
dests[piotr2key[line[0]]] = line.split('').slice(1).map(function(c) {
@ -13,9 +17,7 @@ module.exports = {
});
return dests;
},
defined: function(v) {
return typeof v !== UNDEF;
},
defined: defined,
empty: function(a) {
return !a || a.length === 0;
},
@ -26,6 +28,22 @@ module.exports = {
synthetic: function(data) {
return data.game.id === 'synthetic';
},
storedProp: function(k, defaultValue) {
var sk = 'analyse.' + k;
var value;
var isBoolean = defaultValue === true || defaultValue === false;
return function(v) {
if (defined(v) && v !== value) {
value = v + '';
lichess.storage.set(sk, v);
}
else if (!defined(value)) {
value = lichess.storage.get(sk);
if (value === null) value = defaultValue + '';
}
return isBoolean ? value === 'true' : value;
};
},
/**
* https://github.com/niksy/throttle-debounce/blob/master/lib/throttle.js
*