UNPKG

chessground

Version:
99 lines 3.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.start = void 0; const board = require("./board"); const fen_1 = require("./fen"); const config_1 = require("./config"); const anim_1 = require("./anim"); const drag_1 = require("./drag"); const explosion_1 = require("./explosion"); function start(state, redrawAll) { function toggleOrientation() { board.toggleOrientation(state); redrawAll(); } return { set(config) { if (config.orientation && config.orientation !== state.orientation) toggleOrientation(); (config.fen ? anim_1.anim : anim_1.render)(state => config_1.configure(state, config), state); }, state, getFen: () => fen_1.write(state.pieces), toggleOrientation, setPieces(pieces) { anim_1.anim(state => board.setPieces(state, pieces), state); }, selectSquare(key, force) { if (key) anim_1.anim(state => board.selectSquare(state, key, force), state); else if (state.selected) { board.unselect(state); state.dom.redraw(); } }, move(orig, dest) { anim_1.anim(state => board.baseMove(state, orig, dest), state); }, newPiece(piece, key) { anim_1.anim(state => board.baseNewPiece(state, piece, key), state); }, playPremove() { if (state.premovable.current) { if (anim_1.anim(board.playPremove, state)) return true; state.dom.redraw(); } return false; }, playPredrop(validate) { if (state.predroppable.current) { const result = board.playPredrop(state, validate); state.dom.redraw(); return result; } return false; }, cancelPremove() { anim_1.render(board.unsetPremove, state); }, cancelPredrop() { anim_1.render(board.unsetPredrop, state); }, cancelMove() { anim_1.render(state => { board.cancelMove(state); drag_1.cancel(state); }, state); }, stop() { anim_1.render(state => { board.stop(state); drag_1.cancel(state); }, state); }, explode(keys) { explosion_1.explosion(state, keys); }, setAutoShapes(shapes) { anim_1.render(state => (state.drawable.autoShapes = shapes), state); }, setShapes(shapes) { anim_1.render(state => (state.drawable.shapes = shapes), state); }, getKeyAtDomPos(pos) { return board.getKeyAtDomPos(pos, board.whitePov(state), state.dom.bounds()); }, redrawAll, dragNewPiece(piece, event, force) { drag_1.dragNewPiece(state, piece, event, force); }, destroy() { board.stop(state); state.dom.unbind && state.dom.unbind(); state.dom.destroyed = true; }, }; } exports.start = start; //# sourceMappingURL=api.js.map