This commit is contained in:
Maciej Caderek
2022-04-10 21:35:52 +02:00
parent 32c362b0d0
commit fc0746923c
25 changed files with 209 additions and 43 deletions

View File

@@ -22,6 +22,7 @@ import isPGN from "./utils/isPGN";
import isSafeLink from "./utils/isSafeLink";
import { PiecesStyle } from "./board/styles-pieces/piecesStyles";
import link from "./persistance/link";
import importToLichess from "./imports/importToLichess";
const main = async () => {
const board = new Board(state.boardConfig);
@@ -232,8 +233,27 @@ const main = async () => {
setState("boardConfig", "speech", !state.boardConfig.speech);
saveConfig("board");
},
async openOnLichess() {
if (state.pgn === "") {
window.open(
`https://lichess.org/analysis/${state.fen.replace(/\s+/g, "_")}`
);
return true;
}
try {
const url = await importToLichess(state.pgn, state.game.header.Site);
window.open(`${url}/${state.boardConfig.flipped ? "black" : ""}`);
return true;
} catch (e) {
return false;
}
},
};
// @ts-ignore
window.handlers = handlers;
/* Render the page */
render(
@@ -241,8 +261,10 @@ const main = async () => {
document.getElementById("root") as HTMLElement
);
const $board = document.querySelector<HTMLImageElement>("#board");
$board?.prepend(board.canvas);
const canvas = document.getElementById("canvas") as HTMLCanvasElement;
await board.setCanvas(canvas);
await player.init();
/* Load game from the url */