WIP
This commit is contained in:
@@ -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
9
src/encoders/sizeToPX.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
const sizeToPX = {
|
||||
XS: 256,
|
||||
S: 512,
|
||||
M: 720,
|
||||
L: 1024,
|
||||
XL: 1440,
|
||||
};
|
||||
|
||||
export default sizeToPX;
|
||||
Reference in New Issue
Block a user