mirror of
https://github.com/danbee/chess
synced 2025-03-04 08:39:06 +00:00
Add turn indicator
This commit is contained in:
parent
90e330e3a0
commit
c95f1c6032
@ -1,16 +1,68 @@
|
|||||||
|
@mixin move-indicator {
|
||||||
|
display: block;
|
||||||
|
content: "";
|
||||||
|
width: 2vmin;
|
||||||
|
height: 2vmin;
|
||||||
|
position: absolute;
|
||||||
|
right: 2vmin;
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
|
||||||
.board {
|
.board {
|
||||||
background: lighten($black-square-color, 7%);
|
background: lighten($black-square-color, 7%);
|
||||||
border-collapse: unset;
|
border-collapse: unset;
|
||||||
|
border-spacing: 1px;
|
||||||
color: $white-square-color;
|
color: $white-square-color;
|
||||||
border-radius: 2vmin;
|
border-radius: 2vmin;
|
||||||
box-shadow: 0 0.5vmin 3vmin rgba(0, 0, 0, 0.4);
|
box-shadow: 0 0.5vmin 3vmin rgba(0, 0, 0, 0.4);
|
||||||
height: 80vmin;
|
position: relative;
|
||||||
margin: 0 auto;
|
height: 90vmin;
|
||||||
width: 80vmin;
|
width: 90vmin;
|
||||||
|
|
||||||
th {
|
th {
|
||||||
|
font-size: 0.6rem;
|
||||||
color: darken($black-square-color, 10%);
|
color: darken($black-square-color, 10%);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.white-to-move:before {
|
||||||
|
@include move-indicator;
|
||||||
|
background: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.black-to-move:before {
|
||||||
|
@include move-indicator;
|
||||||
|
background: #000;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.player-is-white.white-to-move:before,
|
||||||
|
&.player-is-black.black-to-move:before {
|
||||||
|
bottom: 2vmin;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.player-is-white.black-to-move:before,
|
||||||
|
&.player-is-black.white-to-move:before {
|
||||||
|
top: 2vmin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (min-width: 480px) {
|
||||||
|
.board {
|
||||||
|
border-spacing: 2px;
|
||||||
|
|
||||||
|
th {
|
||||||
|
font-size: 0.8rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (min-width: 768px) {
|
||||||
|
.board {
|
||||||
|
border-spacing: 3px;
|
||||||
|
|
||||||
|
th {
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.board-square {
|
.board-square {
|
||||||
@ -30,7 +82,7 @@
|
|||||||
|
|
||||||
.board-border-top,
|
.board-border-top,
|
||||||
.board-border-bottom {
|
.board-border-bottom {
|
||||||
height: 4vmin;
|
height: 5%;
|
||||||
|
|
||||||
th {
|
th {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
@ -41,7 +93,7 @@
|
|||||||
|
|
||||||
.board-border-left,
|
.board-border-left,
|
||||||
.board-border-right {
|
.board-border-right {
|
||||||
width: 4vmin;
|
width: 5%;
|
||||||
|
|
||||||
padding: 0;
|
padding: 0;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
body {
|
html {
|
||||||
background: $background-color;
|
background: $background-color;
|
||||||
color: mix($background-color, $foreground-color, 20%);
|
color: mix($background-color, $foreground-color, 20%);
|
||||||
}
|
}
|
||||||
@ -21,7 +21,7 @@ h1 {
|
|||||||
|
|
||||||
.container {
|
.container {
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
width: 80%;
|
width: 90%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-group {
|
.form-group {
|
||||||
|
|||||||
@ -71,7 +71,7 @@ class ChessBoardSquare extends React.Component {
|
|||||||
this.props.piece.type,
|
this.props.piece.type,
|
||||||
this.props.piece.colour,
|
this.props.piece.colour,
|
||||||
{ "selected": this.isSelectedSquare() }
|
{ "selected": this.isSelectedSquare() }
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,12 +2,14 @@ import React from "react";
|
|||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import $ from "jquery";
|
import $ from "jquery";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
|
import classNames from "classnames";
|
||||||
|
|
||||||
|
import socket from "../socket";
|
||||||
|
|
||||||
import { setPlayer, setGame, setGameId } from "../store/actions";
|
import { setPlayer, setGame, setGameId } from "../store/actions";
|
||||||
|
|
||||||
import ChessBoardSquare from "./chess-board-square";
|
import ChessBoardSquare from "./chess-board-square";
|
||||||
|
|
||||||
import socket from "../socket";
|
|
||||||
|
|
||||||
class ChessBoard extends React.Component {
|
class ChessBoard extends React.Component {
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
const { gameId, store } = this.props;
|
const { gameId, store } = this.props;
|
||||||
@ -28,6 +30,11 @@ class ChessBoard extends React.Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getTurn() {
|
||||||
|
const { store } = this.props;
|
||||||
|
return store.getState().turn;
|
||||||
|
}
|
||||||
|
|
||||||
getBoard() {
|
getBoard() {
|
||||||
const { store } = this.props;
|
const { store } = this.props;
|
||||||
return store.getState().board;
|
return store.getState().board;
|
||||||
@ -61,9 +68,9 @@ class ChessBoard extends React.Component {
|
|||||||
return _.map(this.ranks(), (rankId) => {
|
return _.map(this.ranks(), (rankId) => {
|
||||||
return (
|
return (
|
||||||
<tr className="board-rank" key={rankId}>
|
<tr className="board-rank" key={rankId}>
|
||||||
<th class="board-border-left">{rankId}</th>
|
<th className="board-border-left">{rankId}</th>
|
||||||
{this.renderFiles(rankId)}
|
{this.renderFiles(rankId)}
|
||||||
<td class="board-border-left"></td>
|
<td className="board-border-left"></td>
|
||||||
</tr>
|
</tr>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -92,12 +99,23 @@ class ChessBoard extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boardClass() {
|
||||||
|
const turn = this.getTurn();
|
||||||
|
const player = this.getPlayer();
|
||||||
|
|
||||||
|
return classNames(
|
||||||
|
"board",
|
||||||
|
turn + "-to-move",
|
||||||
|
"player-is-" + player
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<table class="board">
|
<table className={this.boardClass()}>
|
||||||
<thead>
|
<thead>
|
||||||
<tr class="board-border-top">
|
<tr className="board-border-top">
|
||||||
<th class="board-border-left"></th>
|
<th className="board-border-left"></th>
|
||||||
<th>a</th>
|
<th>a</th>
|
||||||
<th>b</th>
|
<th>b</th>
|
||||||
<th>c</th>
|
<th>c</th>
|
||||||
@ -106,15 +124,15 @@ class ChessBoard extends React.Component {
|
|||||||
<th>f</th>
|
<th>f</th>
|
||||||
<th>g</th>
|
<th>g</th>
|
||||||
<th>h</th>
|
<th>h</th>
|
||||||
<th class="board-border-left"></th>
|
<th className="board-border-left"></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>{this.renderRanks()}</tbody>
|
<tbody>{this.renderRanks()}</tbody>
|
||||||
<tfoot>
|
<tfoot>
|
||||||
<tr class="board-border-bottom">
|
<tr className="board-border-bottom">
|
||||||
<th class="board-border-left"></th>
|
<th className="board-border-left"></th>
|
||||||
<th colspan="8"></th>
|
<th colspan="8"></th>
|
||||||
<th class="board-border-left"></th>
|
<th className="board-border-left"></th>
|
||||||
</tr>
|
</tr>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user