more puzzle ui wip

puzzle-ui
Thibault Duplessis 2016-11-29 12:23:00 +01:00
parent 556faddb22
commit 06faa94a33
3 changed files with 55 additions and 11 deletions

View File

@ -10,6 +10,7 @@ var keyboard = require('./keyboard');
var opposite = chessground.util.opposite;
var groundBuild = require('./ground');
var socketBuild = require('./socket');
var moveTestBuild = require('./moveTest');
var throttle = require('common').throttle;
var xhr = require('./xhr');
var sound = require('./sound');
@ -35,7 +36,11 @@ module.exports = function(opts, i18n) {
};
vm.initialPath = treePath.fromNodeList(treeOps.mainlineNodeList(tree.root));
setPath(vm.initialPath);
setPath(treePath.init(vm.initialPath));
setTimeout(function() {
jump(vm.initialPath);
m.redraw();
}, 500);
var showGround = function() {
var node = vm.node;
@ -51,12 +56,12 @@ module.exports = function(opts, i18n) {
check: node.check,
lastMove: uciToLastMove(node.uci)
};
if (!dests && !node.check) {
// premove while dests are loading from server
// can't use when in check because it highlights the wrong king
config.turnColor = opposite(color);
config.movable.color = color;
}
// if (!dests && !node.check) {
// // premove while dests are loading from server
// // can't use when in check because it highlights the wrong king
// config.turnColor = opposite(color);
// config.movable.color = color;
// }
vm.cgConfig = config;
if (!ground) ground = groundBuild(data, config, userMove);
ground.set(config);
@ -69,11 +74,34 @@ module.exports = function(opts, i18n) {
sendMove(orig, dest);
};
var getDests = throttle(800, false, function() {
if (!vm.node.dests) socket.sendAnaDests({
var sendMove = function(orig, dest, prom) {
var move = {
orig: orig,
dest: dest,
fen: vm.node.fen,
path: vm.path
});
};
if (prom) move.promotion = prom;
socket.sendAnaMove(move);
moveTest(vm.path, move);
// preparePremoving();
};
// var preparePremoving = function() {
// ground.set({
// turnColor: ground.data.movable.color,
// movable: {
// color: opposite(ground.chessground.data.movable.color)
// }
// });
// };
var getDests = throttle(800, false, function() {
if (!vm.node.dests && treePath.contains(vm.path, vm.initialPath))
socket.sendAnaDests({
fen: vm.node.fen,
path: vm.path
});
});
var uciToLastMove = function(uci) {
@ -170,6 +198,7 @@ module.exports = function(opts, i18n) {
},
destsCache: data.game.destsCache
});
var moveTest = moveTestBuild(tree, vm.initialPath, data.puzzle.lines);
showGround();

View File

@ -0,0 +1,11 @@
module.exports = function(tree, initialPath, lines) {
return function(path, move) {
var uci = move.orig + move.dest + (move.promotion || '');
var node = tree.nodeAtPath(path);
var isNew = node.children.filter(function(c) {
return c.uci === uci;
}).length === 0;
return 'win';
};
};

View File

@ -11,6 +11,10 @@ module.exports = function(opts) {
};
var handlers = {
node: function(data) {
clearTimeout(anaMoveTimeout);
opts.addNode(data.node, data.path);
},
stepFailure: function(data) {
clearTimeout(anaMoveTimeout);
opts.reset();
@ -38,7 +42,7 @@ module.exports = function(opts) {
clearTimeout(anaDestsTimeout);
if (anaDestsCache[req.path]) setTimeout(function() {
handlers.dests(anaDestsCache[req.path]);
}, 300);
}, 10);
else {
opts.send('anaDests', req);
anaDestsTimeout = setTimeout(function() {