This commit is contained in:
Maciej Caderek
2022-02-17 03:36:40 +01:00
parent 3095c3b55e
commit 10cea708f0
25 changed files with 326 additions and 115 deletions

View File

@@ -8,9 +8,9 @@ import MP4 from "./MP4";
const getData = (board: Board, encoder: GIF | WebM | MP4) => {
return encoder instanceof GIF
? board.toImgElement()
: encoder instanceof MP4
? board.toImageData()
: encoder instanceof MP4
? board.toClampedArray()
: board.canvas;
};
@@ -18,7 +18,8 @@ const createAnimation = async (
pgn: string,
boardConfig: BoardConfig,
format: "GIF" | "WebM" | "MP4",
size: Size
size: Size,
includeTitleScreen: boolean
) => {
const game = new Game().loadPGN(pgn);
const board = new Board({ ...boardConfig, size: sizeToPX[size] });
@@ -31,11 +32,13 @@ const createAnimation = async (
const header = game.header;
await board.titleFrame(header);
board.render();
if (includeTitleScreen) {
await board.titleFrame(header);
board.render();
// @ts-ignore
await encoder.add(getData(board, encoder), 4);
// @ts-ignore
await encoder.add(getData(board, encoder), 4);
}
for (let ply = 0; ply < game.length; ply++) {
const position = game.getPosition(ply);