onix-chess-game
Version:
Chess game board
75 lines (73 loc) • 2.74 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Chessground = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const classnames_1 = tslib_1.__importDefault(require("classnames"));
const react_bootstrap_1 = require("react-bootstrap");
const chessground_1 = require("chessground");
const onix_board_assets_1 = require("onix-board-assets");
class Chessground extends React.Component {
constructor(props) {
super(props);
this.boardElement = null;
this.cg = undefined;
this.redrawBoard = () => {
const { cg } = this;
if (cg !== undefined) {
cg.redrawAll();
}
};
this.renderPromotion = () => {
const { inPromotion } = this.state;
const pieces = ["queen", "rook", "bishop", "knight"].map((role) => {
return 1; //[color, role as cg.Role];
});
if (inPromotion) {
return (React.createElement(react_bootstrap_1.Modal, { show: inPromotion },
React.createElement(react_bootstrap_1.Modal.Body, null,
React.createElement("div", { className: "promotion-block" }))));
}
return null;
};
this.state = {
inPromotion: !!props.inPromotion
};
}
componentDidMount() {
this.cg = chessground_1.Chessground(this.boardElement, this.props.board);
window.addEventListener("resize", this.redrawBoard);
}
componentWillUnmount() {
const { cg } = this;
if (cg !== undefined) {
cg.destroy();
}
window.removeEventListener("resize", this.redrawBoard);
}
render() {
const { props, renderPromotion } = this;
const { size, square, piece, board } = props;
const containerClass = [
"pos-builder",
"is2d",
square,
onix_board_assets_1.BoardSizeClass[size],
{ "coords-no": !(board.coordinates) }
];
return (React.createElement(react_bootstrap_1.Container, { className: classnames_1.default(containerClass) },
React.createElement("div", { className: classnames_1.default("board-container", piece) },
React.createElement("div", { className: "main-board", ref: el => this.boardElement = el }),
renderPromotion())));
}
}
exports.Chessground = Chessground;
Chessground.defaultProps = {
locale: "ru-ru",
size: onix_board_assets_1.BoardSize.Normal,
piece: "alpha",
square: "color-blue",
inPromotion: false,
board: {},
};
//# sourceMappingURL=Chessground.js.map