allow premove in analysis to alleviate network lag

This commit is contained in:
Thibault Duplessis 2015-05-06 23:34:12 +02:00
parent 10319994e5
commit 14da974f1c
3 changed files with 16 additions and 8 deletions

View file

@ -28,7 +28,7 @@ module.exports = function(steps, analysis) {
nextPath.forEach(function(p) {
for (i = 0, nb = tree.length; i < nb; i++) {
var step = tree[i];
if (p.ply == step.ply) {
if (p.ply === step.ply) {
if (p.variation) {
tree = step.variations[p.variation - 1];
break;
@ -38,11 +38,9 @@ module.exports = function(steps, analysis) {
});
if (curStep) {
curStep.variations = curStep.variations || [];
if (curStep.san === step.san) return nextPath;
if (curStep.san === step.san) return false;;
for (var i = 0; i < curStep.variations.length; i++) {
if (curStep.variations[i][0].san === step.san) {
return treePath.withVariation(nextPath, i + 1);
}
if (curStep.variations[i][0].san === step.san) return false;
}
curStep.variations.push([step]);
return treePath.withVariation(nextPath, curStep.variations.length);

View file

@ -1,4 +1,5 @@
var chessground = require('chessground');
var opposite = chessground.util.opposite;
var data = require('./data');
var analyse = require('./analyse');
var ground = require('./ground');
@ -72,7 +73,6 @@ module.exports = function(opts) {
this.vm.cgConfig = config;
if (!this.chessground)
this.chessground = ground.make(this.data, config, userMove);
this.chessground.stop();
this.chessground.set(config);
if (opts.onChange) opts.onChange(config.fen, this.vm.path);
}.bind(this);
@ -116,11 +116,21 @@ module.exports = function(opts) {
};
if (prom) move.promotion = prom;
this.socket.sendAnaMove(move);
this.chessground.set({
turnColor: this.chessground.data.movable.color,
movable: {
color: opposite(this.chessground.data.movable.color)
}
});
console.log(this.chessground.data);
}.bind(this);
this.addStep = function(step, path) {
this.userJump(this.analyse.addStep(step, treePath.read(path)));
var newPath = this.analyse.addStep(step, treePath.read(path));
if (!newPath) return;
this.jump(newPath);
m.redraw();
this.chessground.playPremove();
}.bind(this);
this.reset = function() {

View file

@ -17,7 +17,7 @@ function makeConfig(data, config, onMove) {
}
},
premovable: {
enabled: false
enabled: true
},
drawable: {
enabled: true