Merge branch chessserver:master into chat-dv
This commit is contained in:
@@ -6,11 +6,28 @@ const initGameBoard = function (color, player, gameId) {
|
|||||||
.then(fen => {
|
.then(fen => {
|
||||||
let board = null;
|
let board = null;
|
||||||
let game = null;
|
let game = null;
|
||||||
|
let whiteSquareGrey = '#a9a9a9';
|
||||||
|
let blackSquareGrey = '#696969';
|
||||||
const wsScheme = window.location.protocol === "https:" ? "wss://" : "ws://";
|
const wsScheme = window.location.protocol === "https:" ? "wss://" : "ws://";
|
||||||
const socket = new WebSocket(
|
const socket = new WebSocket(
|
||||||
`${wsScheme}${window.location.host}/games/${gameId}.ws?playerId=${player}`
|
`${wsScheme}${window.location.host}/games/${gameId}.ws?playerId=${player}`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
function removeGreySquares() {
|
||||||
|
$('#board .square-55d63').css('background', '');
|
||||||
|
}
|
||||||
|
|
||||||
|
function greySquare(square) {
|
||||||
|
var $square = $('#board .square-' + square);
|
||||||
|
|
||||||
|
var background = whiteSquareGrey;
|
||||||
|
if ($square.hasClass('black-3c85d')) {
|
||||||
|
background = blackSquareGrey;
|
||||||
|
}
|
||||||
|
|
||||||
|
$square.css('background', background);
|
||||||
|
}
|
||||||
|
|
||||||
function onDragStart(source, piece, position, _) {
|
function onDragStart(source, piece, position, _) {
|
||||||
if (game.turn() !== color) {
|
if (game.turn() !== color) {
|
||||||
return false;
|
return false;
|
||||||
@@ -26,6 +43,7 @@ const initGameBoard = function (color, player, gameId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onDrop(source, target) {
|
function onDrop(source, target) {
|
||||||
|
removeGreySquares();
|
||||||
try {
|
try {
|
||||||
const move = game.move({
|
const move = game.move({
|
||||||
from: source,
|
from: source,
|
||||||
@@ -46,6 +64,24 @@ const initGameBoard = function (color, player, gameId) {
|
|||||||
board.position(game.fen());
|
board.position(game.fen());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onMouseoverSquare(square, piece) {
|
||||||
|
var moves = game.moves({
|
||||||
|
square: square,
|
||||||
|
verbose: true
|
||||||
|
});
|
||||||
|
if (moves.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
greySquare(square);
|
||||||
|
for (var i = 0; i < moves.length; i++) {
|
||||||
|
greySquare(moves[i].to);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onMouseoutSquare(square, piece) {
|
||||||
|
removeGreySquares();
|
||||||
|
}
|
||||||
|
|
||||||
function updateStatusText() {
|
function updateStatusText() {
|
||||||
let status;
|
let status;
|
||||||
let moveColor = "White";
|
let moveColor = "White";
|
||||||
@@ -72,7 +108,9 @@ const initGameBoard = function (color, player, gameId) {
|
|||||||
position: fen,
|
position: fen,
|
||||||
onDragStart: onDragStart,
|
onDragStart: onDragStart,
|
||||||
onSnapEnd: onSnapEnd,
|
onSnapEnd: onSnapEnd,
|
||||||
onDrop: onDrop
|
onDrop: onDrop,
|
||||||
|
onMouseoutSquare: onMouseoutSquare,
|
||||||
|
onMouseoverSquare: onMouseoverSquare
|
||||||
};
|
};
|
||||||
board = ChessBoard("board", config);
|
board = ChessBoard("board", config);
|
||||||
const statusControl = document.getElementById("status");
|
const statusControl = document.getElementById("status");
|
||||||
|
|||||||
Reference in New Issue
Block a user