From 06faa94a33f407d77908bffc23e6e078d94799d0 Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Tue, 29 Nov 2016 12:23:00 +0100 Subject: [PATCH] more puzzle ui wip --- ui/puzzle/src/ctrl.js | 49 +++++++++++++++++++++++++++++++-------- ui/puzzle/src/moveTest.js | 11 +++++++++ ui/puzzle/src/socket.js | 6 ++++- 3 files changed, 55 insertions(+), 11 deletions(-) create mode 100644 ui/puzzle/src/moveTest.js diff --git a/ui/puzzle/src/ctrl.js b/ui/puzzle/src/ctrl.js index ffac1e3432..1f0e9b9832 100644 --- a/ui/puzzle/src/ctrl.js +++ b/ui/puzzle/src/ctrl.js @@ -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(); diff --git a/ui/puzzle/src/moveTest.js b/ui/puzzle/src/moveTest.js new file mode 100644 index 0000000000..93701c1b3a --- /dev/null +++ b/ui/puzzle/src/moveTest.js @@ -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'; + }; +}; diff --git a/ui/puzzle/src/socket.js b/ui/puzzle/src/socket.js index 22183bb99e..447755d17b 100644 --- a/ui/puzzle/src/socket.js +++ b/ui/puzzle/src/socket.js @@ -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() {