This commit is contained in:
Maciej Caderek
2022-02-12 23:16:01 +01:00
parent 840545886d
commit 6274236ac7
13 changed files with 227 additions and 177 deletions

View File

@@ -67,7 +67,12 @@ const main = async () => {
const player = new Player(board, gameConfig);
const game = new Game().loadPGN(pgn);
setState({ moves: game.getMoves() });
setState({
moves: game.getMoves(),
pgn,
ply: 0,
fen: game.getPosition(0).fen,
});
const handlers = {
prev() {
@@ -88,19 +93,24 @@ const main = async () => {
},
toggleBorder() {
board.toggleBorder();
setState("board", "showBorder", !state.board.showBorder);
},
showBorder() {
board.showBorder();
setState("board", "showBorder", true);
},
hideBorder() {
board.hideBorder();
setState("board", "showBorder", false);
},
toggleExtraInfo() {
board.toggleExtraInfo();
setState("board", "showExtraInfo", !state.board.showExtraInfo);
},
flip() {
board.flip();
setState("board", "flipped", !state.board.flipped);
},
togglePlay() {
player.playing ? player.pause() : player.play();
@@ -111,9 +121,11 @@ const main = async () => {
},
changeBoardStyle(style: BoardStyle) {
board.setStyle(style);
setState("board", "boardStyle", style);
},
changePiecesStyle(style: PiecesStyle) {
board.setPiecesStyle(style);
setState("board", "piecesStyle", style);
},
async loadPGN(pgn: string) {
const game = new Game().loadPGN(pgn);
@@ -126,13 +138,21 @@ const main = async () => {
await player.load(game);
},
async downloadImage() {
const data = await createImage(state.fen, state.board, 1024);
const data = await createImage(
state.fen,
state.pgn,
state.ply,
state.board,
state.game.picSize
);
download(data, "fen", "png");
},
};
// @ts-ignore
window.handlers = handlers;
// @ts-ignore
window.state = state;
/**
* RENDER