more puzzle ui wip
This commit is contained in:
parent
556faddb22
commit
06faa94a33
|
@ -10,6 +10,7 @@ var keyboard = require('./keyboard');
|
||||||
var opposite = chessground.util.opposite;
|
var opposite = chessground.util.opposite;
|
||||||
var groundBuild = require('./ground');
|
var groundBuild = require('./ground');
|
||||||
var socketBuild = require('./socket');
|
var socketBuild = require('./socket');
|
||||||
|
var moveTestBuild = require('./moveTest');
|
||||||
var throttle = require('common').throttle;
|
var throttle = require('common').throttle;
|
||||||
var xhr = require('./xhr');
|
var xhr = require('./xhr');
|
||||||
var sound = require('./sound');
|
var sound = require('./sound');
|
||||||
|
@ -35,7 +36,11 @@ module.exports = function(opts, i18n) {
|
||||||
};
|
};
|
||||||
|
|
||||||
vm.initialPath = treePath.fromNodeList(treeOps.mainlineNodeList(tree.root));
|
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 showGround = function() {
|
||||||
var node = vm.node;
|
var node = vm.node;
|
||||||
|
@ -51,12 +56,12 @@ module.exports = function(opts, i18n) {
|
||||||
check: node.check,
|
check: node.check,
|
||||||
lastMove: uciToLastMove(node.uci)
|
lastMove: uciToLastMove(node.uci)
|
||||||
};
|
};
|
||||||
if (!dests && !node.check) {
|
// if (!dests && !node.check) {
|
||||||
// premove while dests are loading from server
|
// // premove while dests are loading from server
|
||||||
// can't use when in check because it highlights the wrong king
|
// // can't use when in check because it highlights the wrong king
|
||||||
config.turnColor = opposite(color);
|
// config.turnColor = opposite(color);
|
||||||
config.movable.color = color;
|
// config.movable.color = color;
|
||||||
}
|
// }
|
||||||
vm.cgConfig = config;
|
vm.cgConfig = config;
|
||||||
if (!ground) ground = groundBuild(data, config, userMove);
|
if (!ground) ground = groundBuild(data, config, userMove);
|
||||||
ground.set(config);
|
ground.set(config);
|
||||||
|
@ -69,11 +74,34 @@ module.exports = function(opts, i18n) {
|
||||||
sendMove(orig, dest);
|
sendMove(orig, dest);
|
||||||
};
|
};
|
||||||
|
|
||||||
var getDests = throttle(800, false, function() {
|
var sendMove = function(orig, dest, prom) {
|
||||||
if (!vm.node.dests) socket.sendAnaDests({
|
var move = {
|
||||||
|
orig: orig,
|
||||||
|
dest: dest,
|
||||||
fen: vm.node.fen,
|
fen: vm.node.fen,
|
||||||
path: vm.path
|
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) {
|
var uciToLastMove = function(uci) {
|
||||||
|
@ -170,6 +198,7 @@ module.exports = function(opts, i18n) {
|
||||||
},
|
},
|
||||||
destsCache: data.game.destsCache
|
destsCache: data.game.destsCache
|
||||||
});
|
});
|
||||||
|
var moveTest = moveTestBuild(tree, vm.initialPath, data.puzzle.lines);
|
||||||
|
|
||||||
showGround();
|
showGround();
|
||||||
|
|
||||||
|
|
11
ui/puzzle/src/moveTest.js
Normal file
11
ui/puzzle/src/moveTest.js
Normal 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';
|
||||||
|
};
|
||||||
|
};
|
|
@ -11,6 +11,10 @@ module.exports = function(opts) {
|
||||||
};
|
};
|
||||||
|
|
||||||
var handlers = {
|
var handlers = {
|
||||||
|
node: function(data) {
|
||||||
|
clearTimeout(anaMoveTimeout);
|
||||||
|
opts.addNode(data.node, data.path);
|
||||||
|
},
|
||||||
stepFailure: function(data) {
|
stepFailure: function(data) {
|
||||||
clearTimeout(anaMoveTimeout);
|
clearTimeout(anaMoveTimeout);
|
||||||
opts.reset();
|
opts.reset();
|
||||||
|
@ -38,7 +42,7 @@ module.exports = function(opts) {
|
||||||
clearTimeout(anaDestsTimeout);
|
clearTimeout(anaDestsTimeout);
|
||||||
if (anaDestsCache[req.path]) setTimeout(function() {
|
if (anaDestsCache[req.path]) setTimeout(function() {
|
||||||
handlers.dests(anaDestsCache[req.path]);
|
handlers.dests(anaDestsCache[req.path]);
|
||||||
}, 300);
|
}, 10);
|
||||||
else {
|
else {
|
||||||
opts.send('anaDests', req);
|
opts.send('anaDests', req);
|
||||||
anaDestsTimeout = setTimeout(function() {
|
anaDestsTimeout = setTimeout(function() {
|
||||||
|
|
Loading…
Reference in a new issue