more progress on new analyse, try to reuse code from round
parent
27c1fe8dba
commit
2a59665fa3
|
@ -1841,9 +1841,40 @@ var storage = {
|
|||
// analyse.js //
|
||||
////////////////
|
||||
|
||||
function startAnalyse(element, cfg) {
|
||||
var data = cfg.data;
|
||||
if (data.chat) $('#chat').chat({
|
||||
messages: data.chat
|
||||
});
|
||||
var $watchers = $('#site_header div.watchers').watchers();
|
||||
if (data.tournament) $('body').data('tournament-id', data.tournament.id);
|
||||
lichess.socket = new lichess.StrongSocket(
|
||||
data.url.socket,
|
||||
data.player.version, {
|
||||
options: {
|
||||
name: "analyse"
|
||||
},
|
||||
params: {
|
||||
ran: "--ranph--"
|
||||
},
|
||||
events: {
|
||||
analysisAvailable: function() {
|
||||
$.sound.dong();
|
||||
location.href = location.href.split('#')[0] + '#' + CurrentPly;
|
||||
location.reload();
|
||||
},
|
||||
crowd: function(event) {
|
||||
$watchers.watchers("set", event.watchers);
|
||||
}
|
||||
}
|
||||
});
|
||||
LichessAnalyse(element.querySelector('.analyse'), cfg.data, cfg.routes, cfg.i18n);
|
||||
$('.crosstable', element).prependTo($('.underboard .center', element)).show();
|
||||
}
|
||||
|
||||
$(function() {
|
||||
|
||||
if (!$("#GameBoard").length) return;
|
||||
if (true || !$("#GameBoard").length) return;
|
||||
|
||||
$('div.game_control a').filter('.continue').click(function() {
|
||||
$('div.board_wrap div.continue').toggle();
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
function getPlayer(data, color) {
|
||||
if (data.player.color == color) return data.player;
|
||||
if (data.opponent.color == color) return data.opponent;
|
||||
return null;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getPlayer: getPlayer
|
||||
};
|
|
@ -1,14 +1,15 @@
|
|||
var m = require('mithril');
|
||||
var chessground = require('chessground');
|
||||
var partial = chessground.util.partial;
|
||||
var data = require('./data');
|
||||
var ground = require('./ground');
|
||||
|
||||
module.exports = function(cfg, router, i18n, socketSend) {
|
||||
|
||||
this.data = data({}, cfg);
|
||||
|
||||
this.vm = {
|
||||
flip: false
|
||||
flip: false,
|
||||
ply: 1
|
||||
};
|
||||
|
||||
this.flip = function() {
|
||||
|
@ -18,6 +19,8 @@ module.exports = function(cfg, router, i18n, socketSend) {
|
|||
});
|
||||
}.bind(this);
|
||||
|
||||
this.chessground = ground.make(this.data, cfg.game.fen);
|
||||
|
||||
this.router = router;
|
||||
|
||||
this.trans = function() {
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
var chessground = require('chessground');
|
||||
|
||||
function makeConfig(data, fen, flip) {
|
||||
return {
|
||||
viewOnly: true,
|
||||
fen: fen,
|
||||
orientation: flip ? data.opponent.color : data.player.color,
|
||||
coordinates: data.pref.coords !== 0,
|
||||
highlight: {
|
||||
lastMove: data.pref.highlight,
|
||||
check: data.pref.highlight,
|
||||
dragOver: false
|
||||
},
|
||||
animation: {
|
||||
enabled: true,
|
||||
duration: data.pref.animationDuration
|
||||
},
|
||||
events: {
|
||||
capture: $.sound.take
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function make(data, fen) {
|
||||
return new chessground.controller(makeConfig(data, fen));
|
||||
}
|
||||
|
||||
function reload(ground, data, fen, flip) {
|
||||
ground.set(makeConfig(data, fen, flip));
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
make: make,
|
||||
reload: reload
|
||||
};
|
|
@ -9,8 +9,4 @@ module.exports = function(element, config, router, i18n) {
|
|||
controller: function () { return controller; },
|
||||
view: view
|
||||
});
|
||||
|
||||
return {
|
||||
socketReceive: controller.socket.receive
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,9 +1,57 @@
|
|||
var m = require('mithril');
|
||||
var chessground = require('chessground');
|
||||
var analyse = require('./analyse');
|
||||
var partial = require('chessground').util.partial;
|
||||
|
||||
function renderTd(move, ply, curPly) {
|
||||
return move ? {
|
||||
tag: 'td',
|
||||
attrs: {
|
||||
class: 'move' + (ply === curPly ? ' active' : ''),
|
||||
'data-ply': ply
|
||||
},
|
||||
children: move
|
||||
} : null;
|
||||
}
|
||||
|
||||
function renderMovelist(ctrl) {
|
||||
return ctrl.game.moves;
|
||||
var moves = ctrl.data.game.moves;
|
||||
var pairs = [];
|
||||
for (var i = 0; i < moves.length; i += 2) pairs.push([moves[i], moves[i + 1]]);
|
||||
var result;
|
||||
if (ctrl.data.game.status.id >= 30) switch (ctrl.data.game.winner) {
|
||||
case 'white':
|
||||
result = '1-0';
|
||||
break;
|
||||
case 'black':
|
||||
result = '0-1';
|
||||
break;
|
||||
default:
|
||||
result = '½-½';
|
||||
}
|
||||
var trs = pairs.map(function(pair, i) {
|
||||
return m('tr', [
|
||||
m('td.index', i + 1),
|
||||
renderTd(pair[0], 2 * i + 1, ctrl.vm.ply),
|
||||
renderTd(pair[1], 2 * i + 2, ctrl.vm.ply)
|
||||
]);
|
||||
});
|
||||
if (result) {
|
||||
trs.push(m('tr', m('td.result[colspan=3]', result)));
|
||||
var winner = analyse.getPlayer(ctrl.data, ctrl.data.game.winner);
|
||||
trs.push(m('tr.status', m('td[colspan=3]', [
|
||||
renderStatus(ctrl),
|
||||
winner ? ', ' + ctrl.trans(winner.color == 'white' ? 'whiteIsVictorious' : 'blackIsVictorious') : null
|
||||
])));
|
||||
}
|
||||
return m('table',
|
||||
m('tbody', {
|
||||
onclick: function(e) {
|
||||
var ply = e.target.getAttribute('data-ply');
|
||||
if (ply) ctrl.jump(parseInt(ply));
|
||||
}
|
||||
},
|
||||
trs));
|
||||
}
|
||||
|
||||
function visualBoard(ctrl) {
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
var source = require('vinyl-source-stream');
|
||||
var gulp = require('gulp');
|
||||
var gutil = require('gulp-util');
|
||||
var jshint = require('gulp-jshint');
|
||||
var watchify = require('watchify');
|
||||
var browserify = require('browserify');
|
||||
var uglify = require('gulp-uglify');
|
||||
var streamify = require('gulp-streamify');
|
||||
|
||||
var sources = ['./src/main.js'];
|
||||
var destination = '../../public/compiled/';
|
||||
var onError = function(error) {
|
||||
gutil.log(gutil.colors.red(error.message));
|
||||
};
|
||||
|
||||
gulp.task('lint', function() {
|
||||
return gulp.src(paths.scripts)
|
||||
.pipe(jshint())
|
||||
.pipe(jshint.reporter('default'));
|
||||
});
|
||||
|
||||
gulp.task('dev', function() {
|
||||
var opts = watchify.args;
|
||||
opts.debug = true;
|
||||
|
||||
var bundleStream = watchify(browserify(sources, opts))
|
||||
.on('update', rebundle)
|
||||
.on('log', gutil.log);
|
||||
|
||||
function rebundle() {
|
||||
return bundleStream.bundle()
|
||||
.on('error', onError)
|
||||
.pipe(source('lichess.round.js'))
|
||||
.pipe(gulp.dest(destination));
|
||||
}
|
||||
|
||||
return rebundle();
|
||||
});
|
||||
|
||||
gulp.task('default', ['dev']);
|
|
@ -0,0 +1,35 @@
|
|||
{
|
||||
"name": "game",
|
||||
"version": "1.0.0",
|
||||
"description": "lichess.org game",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/ornicar/lila"
|
||||
},
|
||||
"keywords": [
|
||||
"chess",
|
||||
"lichess",
|
||||
"play",
|
||||
"replay"
|
||||
],
|
||||
"author": "Thibault Duplessis",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/ornicar/lila/issues"
|
||||
},
|
||||
"homepage": "https://github.com/ornicar/lila",
|
||||
"devDependencies": {
|
||||
"browserify": "^5.12.0",
|
||||
"gulp": "^3.8.8",
|
||||
"gulp-jshint": "^1.8.4",
|
||||
"gulp-streamify": "0.0.5",
|
||||
"gulp-uglify": "^1.0.1",
|
||||
"gulp-util": "^3.0.1",
|
||||
"vinyl-source-stream": "^1.0.0",
|
||||
"watchify": "^1.0.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"lodash-node": "^2.4.1",
|
||||
"mithril": "^0.1.22"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
module.exports = function(ctrl) {
|
||||
switch (ctrl.data.game.status.name) {
|
||||
case 'started':
|
||||
return ctrl.trans('playingRightNow');
|
||||
case 'aborted':
|
||||
return ctrl.trans('gameAborted');
|
||||
case 'mate':
|
||||
return ctrl.trans('checkmate');
|
||||
case 'resign':
|
||||
return ctrl.trans(ctrl.data.game.winner == 'white' ? 'blackResigned' : 'whiteResigned');
|
||||
case 'stalemate':
|
||||
return ctrl.trans('stalemate');
|
||||
case 'timeout':
|
||||
switch (ctrl.data.game.winner) {
|
||||
case 'white':
|
||||
return ctrl.trans('blackLeftTheGame');
|
||||
case 'black':
|
||||
return ctrl.trans('whiteLeftTheGame');
|
||||
default:
|
||||
return ctrl.trans('draw');
|
||||
}
|
||||
break;
|
||||
case 'draw':
|
||||
return ctrl.trans('draw');
|
||||
case 'outoftime':
|
||||
return ctrl.trans('timeOut');
|
||||
case 'noStart':
|
||||
return (ctrl.data.game.winner == 'white' ? 'Black' : 'White') + ' didn\'t move';
|
||||
case 'cheat':
|
||||
return 'Cheat detected';
|
||||
case 'variantEnd':
|
||||
switch (ctrl.data.game.variant.key) {
|
||||
case 'kingOfTheHill':
|
||||
return 'King in the center';
|
||||
case 'threeCheck':
|
||||
return 'Three checks';
|
||||
default:
|
||||
return 'Variant ending';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return ctrl.data.game.status.name;
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue