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

@@ -1,17 +1,28 @@
import { BoardConfig } from "../types";
import { BoardConfig, Size } from "../types";
import Board from "../board/Board";
import Game from "../game/Game";
import sizeToPX from "./sizeToPX";
const createImage = async (
fen: string,
pgn: string | null,
ply: number = 0,
boardConfig: BoardConfig,
size: number
size: Size
) => {
const game = new Game().loadFEN(fen);
const board = new Board({ ...boardConfig, size });
console.log({ fen, pgn, ply, size });
const game = new Game();
const position = game.getPosition(0);
await board.frame(position, {});
if (pgn) {
game.loadPGN(pgn);
} else {
game.loadFEN(fen);
}
const board = new Board({ ...boardConfig, size: sizeToPX[size] });
const position = game.getPosition(ply);
await board.frame(position, game.header);
board.render();
return board.toImgUrl();

9
src/encoders/sizeToPX.ts Normal file
View File

@@ -0,0 +1,9 @@
const sizeToPX = {
XS: 256,
S: 512,
M: 720,
L: 1024,
XL: 1440,
};
export default sizeToPX;