This commit is contained in:
Maciej Caderek
2022-02-11 16:20:40 +01:00
parent 4374db0197
commit 56abf27629
4 changed files with 24 additions and 5 deletions

View File

@@ -1,4 +1,4 @@
import { BoardConfig, GameConfig } from "./types"; import { BoardConfig, BoardStyle, GameConfig, PiecesStyle } from "./types";
import Board from "./board/Board"; import Board from "./board/Board";
import Game from "./game/Game"; import Game from "./game/Game";
import pgns from "./test-data/pgns"; import pgns from "./test-data/pgns";
@@ -33,6 +33,8 @@ const gameConfig: GameConfig = {
fromPly: null, fromPly: null,
toPly: null, toPly: null,
loop: true, loop: true,
format: "GIF",
size: "M",
}; };
const createDownloadLink = async (pgn: string, boardConfig: BoardConfig) => { const createDownloadLink = async (pgn: string, boardConfig: BoardConfig) => {
@@ -104,6 +106,12 @@ const main = async () => {
player.pause(); player.pause();
player.goto(ply); player.goto(ply);
}, },
changeBoardStyle(style: BoardStyle) {
board.updateConfig({ boardStyle: style });
},
changePiecesStyle(style: PiecesStyle) {
board.updateConfig({ piecesStyle: style });
},
}; };
/** /**
@@ -130,6 +138,9 @@ const main = async () => {
// controls.load(); // controls.load();
}; };
// @ts-ignore
window.board = board;
document.addEventListener( document.addEventListener(
"contextmenu", "contextmenu",
(e) => { (e) => {

View File

@@ -199,4 +199,6 @@ export type Handlers = {
flip(): void; flip(): void;
togglePlay(): void; togglePlay(): void;
goto(ply: number): void; goto(ply: number): void;
changeBoardStyle: (style: BoardStyle) => void;
changePiecesStyle: (style: PiecesStyle) => void;
}; };

View File

@@ -38,7 +38,7 @@ const prepareBoards = async () => {
return boards; return boards;
}; };
const Boards: Component<{ handlers: Handlers }> = () => { const Boards: Component<{ handlers: Handlers }> = (props) => {
const [boards, setBoards] = createSignal<BoardPreview[]>([]); const [boards, setBoards] = createSignal<BoardPreview[]>([]);
prepareBoards().then((data) => setBoards(data)); prepareBoards().then((data) => setBoards(data));
@@ -55,7 +55,10 @@ const Boards: Component<{ handlers: Handlers }> = () => {
? " boards__ico--active" ? " boards__ico--active"
: "") : "")
} }
onClick={() => setState("board", "boardStyle", board.key)} onClick={() => {
setState("board", "boardStyle", board.key);
props.handlers.changeBoardStyle(board.key);
}}
src={board.img} src={board.img}
title={board.name} title={board.name}
draggable={false} draggable={false}

View File

@@ -10,7 +10,7 @@ const pieces = Object.entries(piecesSets).map(([key, data]) => ({
img: data.nw, img: data.nw,
})) as { key: PiecesStyle; img: string }[]; })) as { key: PiecesStyle; img: string }[];
const Pieces: Component<{ handlers: Handlers }> = () => { const Pieces: Component<{ handlers: Handlers }> = (props) => {
return ( return (
<Scrollable class="pieces"> <Scrollable class="pieces">
{ {
@@ -23,7 +23,10 @@ const Pieces: Component<{ handlers: Handlers }> = () => {
? " pieces__ico--active" ? " pieces__ico--active"
: "") : "")
} }
onClick={() => setState("board", "piecesStyle", item.key)} onClick={() => {
setState("board", "piecesStyle", item.key);
props.handlers.changePiecesStyle(item.key);
}}
src={item.img} src={item.img}
title={item.key} title={item.key}
draggable={false} draggable={false}