reorganize round crazyhouse UI code
This commit is contained in:
parent
8d681be85c
commit
ec34acdf3d
|
@ -1,9 +1,8 @@
|
||||||
var util = require('./util');
|
|
||||||
var game = require('game').game;
|
var game = require('game').game;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
||||||
validateDrop: function(chessground, data, piece, pos) {
|
drop: function(chessground, data, piece, pos) {
|
||||||
|
|
||||||
if (!game.isPlayerTurn(data)) return false;
|
if (!game.isPlayerTurn(data)) return false;
|
||||||
|
|
51
ui/round/src/crazy/crazyView.js
Normal file
51
ui/round/src/crazy/crazyView.js
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
var round = require('../round');
|
||||||
|
var partial = require('chessground').util.partial;
|
||||||
|
var crazyDrag = require('./crazyDrag');
|
||||||
|
var m = require('mithril');
|
||||||
|
|
||||||
|
function crazyPocketTag(role, color) {
|
||||||
|
return {
|
||||||
|
tag: 'div',
|
||||||
|
attrs: {
|
||||||
|
class: 'no-square'
|
||||||
|
},
|
||||||
|
children: [{
|
||||||
|
tag: 'piece',
|
||||||
|
attrs: {
|
||||||
|
class: role + ' ' + color
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
pocket: function(ctrl, color, position) {
|
||||||
|
var step = round.plyStep(ctrl.data, ctrl.vm.ply);
|
||||||
|
if (!step.crazy) return;
|
||||||
|
var pocket = step.crazy.pockets[color === 'white' ? 0 : 1];
|
||||||
|
var oKeys = Object.keys(pocket)
|
||||||
|
var crowded = oKeys.length > 4;
|
||||||
|
return m('div', {
|
||||||
|
class: 'pocket ' + position + (oKeys.length > 4 ? ' crowded' : ''),
|
||||||
|
config: position === 'bottom' ? function(el, isUpdate, context) {
|
||||||
|
if (isUpdate) return;
|
||||||
|
var onstart = partial(crazyDrag, ctrl);
|
||||||
|
el.addEventListener('mousedown', onstart);
|
||||||
|
context.onunload = function() {
|
||||||
|
el.removeEventListener('mousedown', onstart);
|
||||||
|
};
|
||||||
|
} : null
|
||||||
|
},
|
||||||
|
oKeys.map(function(role) {
|
||||||
|
var pieces = [];
|
||||||
|
for (var i = 0; i < pocket[role]; i++) pieces.push(crazyPocketTag(role, color));
|
||||||
|
return m('div', {
|
||||||
|
class: 'role',
|
||||||
|
'data-role': role,
|
||||||
|
'data-color': color,
|
||||||
|
}, pieces);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
|
@ -18,7 +18,7 @@ var moveOn = require('./moveOn');
|
||||||
var atomic = require('./atomic');
|
var atomic = require('./atomic');
|
||||||
var sound = require('./sound');
|
var sound = require('./sound');
|
||||||
var util = require('./util');
|
var util = require('./util');
|
||||||
var crazyhouse = require('./crazyhouse');
|
var crazyValid = require('./crazy/crazyValid');
|
||||||
|
|
||||||
module.exports = function(opts) {
|
module.exports = function(opts) {
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ module.exports = function(opts) {
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
||||||
var onUserNewPiece = function(piece, pos) {
|
var onUserNewPiece = function(piece, pos) {
|
||||||
if (!this.replaying() && crazyhouse.validateDrop(this.chessground, this.data, piece, pos))
|
if (!this.replaying() && crazyValid.drop(this.chessground, this.data, piece, pos))
|
||||||
this.sendNewPiece(piece.role, pos);
|
this.sendNewPiece(piece.role, pos);
|
||||||
else this.jump(this.vm.ply);
|
else this.jump(this.vm.ply);
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
var game = require('game').game;
|
var game = require('game').game;
|
||||||
var perf = require('game').perf;
|
var perf = require('game').perf;
|
||||||
var round = require('../round');
|
|
||||||
var chessground = require('chessground');
|
var chessground = require('chessground');
|
||||||
var renderTable = require('./table');
|
var renderTable = require('./table');
|
||||||
var renderPromotion = require('../promotion').view;
|
var renderPromotion = require('../promotion').view;
|
||||||
var mod = require('game').view.mod;
|
var mod = require('game').view.mod;
|
||||||
var partial = require('chessground').util.partial;
|
|
||||||
var button = require('./button');
|
var button = require('./button');
|
||||||
var blind = require('../blind');
|
var blind = require('../blind');
|
||||||
var keyboard = require('../keyboard');
|
var keyboard = require('../keyboard');
|
||||||
var crazyDrag = require('../crazyDrag');
|
var crazyView = require('../crazy/crazyView');
|
||||||
var m = require('mithril');
|
var m = require('mithril');
|
||||||
|
|
||||||
function materialTag(role) {
|
function materialTag(role) {
|
||||||
|
@ -21,50 +19,6 @@ function materialTag(role) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function crazyPocketTag(role, color) {
|
|
||||||
return {
|
|
||||||
tag: 'div',
|
|
||||||
attrs: {
|
|
||||||
class: 'no-square'
|
|
||||||
},
|
|
||||||
children: [{
|
|
||||||
tag: 'piece',
|
|
||||||
attrs: {
|
|
||||||
class: role + ' ' + color
|
|
||||||
}
|
|
||||||
}]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderCrazyPocket(ctrl, color, position) {
|
|
||||||
var step = round.plyStep(ctrl.data, ctrl.vm.ply);
|
|
||||||
if (!step.crazy) return;
|
|
||||||
var pocket = step.crazy.pockets[color === 'white' ? 0 : 1];
|
|
||||||
var oKeys = Object.keys(pocket)
|
|
||||||
var crowded = oKeys.length > 4;
|
|
||||||
return m('div', {
|
|
||||||
class: 'pocket ' + position + (oKeys.length > 4 ? ' crowded' : ''),
|
|
||||||
config: position === 'bottom' ? function(el, isUpdate, context) {
|
|
||||||
if (isUpdate) return;
|
|
||||||
var onstart = partial(crazyDrag, ctrl);
|
|
||||||
el.addEventListener('mousedown', onstart);
|
|
||||||
context.onunload = function() {
|
|
||||||
el.removeEventListener('mousedown', onstart);
|
|
||||||
};
|
|
||||||
} : null
|
|
||||||
},
|
|
||||||
oKeys.map(function(role) {
|
|
||||||
var pieces = [];
|
|
||||||
for (var i = 0; i < pocket[role]; i++) pieces.push(crazyPocketTag(role, color));
|
|
||||||
return m('div', {
|
|
||||||
class: 'role',
|
|
||||||
'data-role': role,
|
|
||||||
'data-color': color,
|
|
||||||
}, pieces);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderMaterial(ctrl, material, checks) {
|
function renderMaterial(ctrl, material, checks) {
|
||||||
var children = [];
|
var children = [];
|
||||||
for (var role in material) {
|
for (var role in material) {
|
||||||
|
@ -176,9 +130,9 @@ module.exports = function(ctrl) {
|
||||||
ctrl.data.blind ? blindBoard(ctrl) : visualBoard(ctrl),
|
ctrl.data.blind ? blindBoard(ctrl) : visualBoard(ctrl),
|
||||||
m('div.lichess_ground',
|
m('div.lichess_ground',
|
||||||
renderBerserk(ctrl, ctrl.data.opponent.color, 'top'),
|
renderBerserk(ctrl, ctrl.data.opponent.color, 'top'),
|
||||||
renderCrazyPocket(ctrl, ctrl.data.opponent.color, 'top') || renderMaterial(ctrl, material[ctrl.data.opponent.color], ctrl.data.player.checks),
|
crazyView.pocket(ctrl, ctrl.data.opponent.color, 'top') || renderMaterial(ctrl, material[ctrl.data.opponent.color], ctrl.data.player.checks),
|
||||||
renderTable(ctrl),
|
renderTable(ctrl),
|
||||||
renderCrazyPocket(ctrl, ctrl.data.player.color, 'bottom') || renderMaterial(ctrl, material[ctrl.data.player.color], ctrl.data.opponent.checks),
|
crazyView.pocket(ctrl, ctrl.data.player.color, 'bottom') || renderMaterial(ctrl, material[ctrl.data.player.color], ctrl.data.opponent.checks),
|
||||||
renderBerserk(ctrl, ctrl.data.player.color, 'bottom'))
|
renderBerserk(ctrl, ctrl.data.player.color, 'bottom'))
|
||||||
])
|
])
|
||||||
]),
|
]),
|
||||||
|
|
Loading…
Reference in a new issue