This commit is contained in:
Maciej Caderek
2022-02-10 01:14:20 +01:00
parent 20f415d70c
commit e93ac083fa
9 changed files with 176 additions and 21 deletions

View File

@@ -1,5 +1,5 @@
import { BoardConfig, PiecesStyle, Position } from "./../types"; import { BoardConfig, PiecesStyle, Position } from "./../types";
import { Style } from "../types"; import { Style, BoardStyle } from "../types";
import drawRectangle from "./layers/drawRectangle"; import drawRectangle from "./layers/drawRectangle";
import drawCoords from "./layers/drawCoords"; import drawCoords from "./layers/drawCoords";
import drawMoveIndicators from "./layers/drawMoveIndicators"; import drawMoveIndicators from "./layers/drawMoveIndicators";
@@ -11,7 +11,7 @@ import boards from "./styles-board";
const defaultConfig: BoardConfig = { const defaultConfig: BoardConfig = {
size: 720, size: 720,
tiles: 8, tiles: 8,
boardStyle: boards.avocado, boardStyle: "avocado",
piecesStyle: "gioco", piecesStyle: "gioco",
showBorder: true, showBorder: true,
showExtraInfo: true, showExtraInfo: true,
@@ -135,8 +135,8 @@ class Board {
return this.size; return this.size;
} }
setStyle(style: Style) { setStyle(style: BoardStyle) {
this.style = style; this.style = boards[style];
return this; return this;
} }
@@ -195,6 +195,8 @@ class Board {
canvas.width = this.size; canvas.width = this.size;
canvas.height = this.size + this.margin * 2; canvas.height = this.size + this.margin * 2;
console.log({ style: this.style });
const { background, dark, light, border, coords } = this.style; const { background, dark, light, border, coords } = this.style;
await drawRectangle(ctx, this.width, this.height, 0, 0, border); await drawRectangle(ctx, this.width, this.height, 0, 0, border);

View File

@@ -1,7 +1,6 @@
import { BoardConfig, GameConfig } from "./types"; import { BoardConfig, GameConfig } from "./types";
import Board from "./board/Board"; import Board from "./board/Board";
import Game from "./game/Game"; import Game from "./game/Game";
import styles from "./board/styles-board";
import pgns from "./test-data/pgns"; import pgns from "./test-data/pgns";
import createAnimation from "./encoders/createAnimation"; import createAnimation from "./encoders/createAnimation";
// import { decompressPGN } from "./game/PGNHelpers"; // import { decompressPGN } from "./game/PGNHelpers";
@@ -18,7 +17,7 @@ import App from "./ui/App";
const boardConfig: BoardConfig = { const boardConfig: BoardConfig = {
size: 1024, size: 1024,
tiles: 8, tiles: 8,
boardStyle: styles.calm, boardStyle: "calm",
piecesStyle: "tatiana", piecesStyle: "tatiana",
showBorder: true, showBorder: true,
showExtraInfo: true, showExtraInfo: true,

View File

@@ -1,11 +1,10 @@
import { createStore } from "solid-js/store"; import { createStore } from "solid-js/store";
import { BoardConfig, GameConfig } from "./types"; import { BoardConfig, GameConfig } from "./types";
import styles from "./board/styles-board";
const boardConfig: BoardConfig = { const boardConfig: BoardConfig = {
size: 1024, size: 1024,
boardStyle: styles.calm, tiles: 8,
boardStyle: "calm",
piecesStyle: "tatiana", piecesStyle: "tatiana",
showBorder: true, showBorder: true,
showExtraInfo: true, showExtraInfo: true,

View File

@@ -92,6 +92,20 @@ export type Piece =
| "nb" | "nb"
| "pb"; | "pb";
export type BoardStyle =
| "chesscom"
| "lichess"
| "lila"
| "peach"
| "standard"
| "violet"
| "avocado"
| "calm"
| "laguna"
| "sunset"
| "rainbow"
| "rainbowLight";
export type PiecesStyle = export type PiecesStyle =
| "alpha" | "alpha"
| "cardinal" | "cardinal"
@@ -106,7 +120,7 @@ export type PiecesStyle =
export type BoardConfig = { export type BoardConfig = {
size: number; size: number;
tiles: number; tiles: number;
boardStyle: Style; boardStyle: BoardStyle;
piecesStyle: PiecesStyle; piecesStyle: PiecesStyle;
showBorder: boolean; showBorder: boolean;
showExtraInfo: boolean; showExtraInfo: boolean;

View File

@@ -1,3 +1,14 @@
.boards { .boards {
text-align: left; text-align: center;
}
.boards__ico {
border: solid 5px black;
margin: 5px;
cursor: pointer;
}
.boards__ico--active {
border-color: white;
cursor: default;
} }

View File

@@ -1,11 +1,13 @@
import { Component, For, createSignal } from "solid-js"; import { Component, For, createSignal } from "solid-js";
import { Handlers, StyleCategory } from "../../types"; import { Handlers, StyleCategory, BoardStyle, Style } from "../../types";
import Scrollable from "./reusable/Scrollable"; import Scrollable from "./reusable/Scrollable";
import "./Boards.css"; import "./Boards.css";
import styles from "../../board/styles-board"; import styles from "../../board/styles-board";
import Board from "../../board/Board"; import Board from "../../board/Board";
import { state, setState } from "../../state";
type BoardPreview = { type BoardPreview = {
key: keyof typeof styles;
name: string; name: string;
category: StyleCategory; category: StyleCategory;
img: string; img: string;
@@ -21,21 +23,22 @@ const prepareBoards = async () => {
showExtraInfo: false, showExtraInfo: false,
}); });
for (const style of Object.values(styles)) { for (const [key, style] of Object.entries(styles) as [BoardStyle, Style][]) {
await board.updateConfig({ boardStyle: style }); await board.updateConfig({ boardStyle: key });
await board.frame(null, {}); await board.frame(null, {});
board.render(); board.render();
boards.push({ boards.push({
key,
name: style.name, name: style.name,
category: style.category, category: style.category,
img: board.toImgUrl(), img: board.toImgUrl(),
}); } as BoardPreview);
} }
return boards; return boards;
}; };
const Boards: Component<{ handlers: Handlers }> = (props) => { const Boards: Component<{ handlers: Handlers }> = () => {
const [boards, setBoards] = createSignal<BoardPreview[]>([]); const [boards, setBoards] = createSignal<BoardPreview[]>([]);
prepareBoards().then((data) => setBoards(data)); prepareBoards().then((data) => setBoards(data));
@@ -44,7 +47,20 @@ const Boards: Component<{ handlers: Handlers }> = (props) => {
<Scrollable class="boards"> <Scrollable class="boards">
<For each={boards()}> <For each={boards()}>
{(board) => { {(board) => {
return <img src={board.img} title={board.name} />; return (
<img
class={
"boards__ico" +
(state.board.boardStyle === board.key
? " boards__ico--active"
: "")
}
onClick={() => setState("board", "boardStyle", board.key)}
src={board.img}
title={board.name}
draggable={false}
/>
);
}} }}
</For> </For>
</Scrollable> </Scrollable>

View File

@@ -1,2 +1,16 @@
.pieces { .pieces {
text-align: center;
}
.pieces__ico {
border: solid 5px black;
margin: 5px;
cursor: pointer;
width: 82px;
background-color: #ffffff22;
}
.pieces__ico--active {
border-color: white;
cursor: default;
} }

View File

@@ -1,10 +1,108 @@
import { Component, For } from "solid-js"; import { Component, For } from "solid-js";
import { Handlers } from "../../types"; import { Handlers, PiecesStyle } from "../../types";
import Scrollable from "./reusable/Scrollable"; import Scrollable from "./reusable/Scrollable";
import piecesSets from "../../board/styles-pieces";
import { state, setState } from "../../state";
import "./Pieces.css"; import "./Pieces.css";
const Pieces: Component<{ handlers: Handlers }> = (props) => { const pieces = Object.entries(piecesSets).map(([key, data]) => ({
return <Scrollable class="pieces">Pieces</Scrollable>; key,
img: data.nw,
})) as { key: PiecesStyle; img: string }[];
const Pieces: Component<{ handlers: Handlers }> = () => {
return (
<Scrollable class="pieces">
{
<For each={pieces}>
{(item) => (
<img
class={
"pieces__ico" +
(state.board.piecesStyle === item.key
? " pieces__ico--active"
: "")
}
onClick={() => setState("board", "piecesStyle", item.key)}
src={item.img}
title={item.key}
draggable={false}
/>
)}
</For>
}
</Scrollable>
);
}; };
export default Pieces; export default Pieces;
// import { Component, For, createSignal } from "solid-js";
// import { Handlers, StyleCategory, BoardStyle, Style } from "../../types";
// import Scrollable from "./reusable/Scrollable";
// import "./Boards.css";
// import styles from "../../board/styles-board";
// import Board from "../../board/Board";
// import { state, setState } from "../../state";
// type BoardPreview = {
// key: keyof typeof styles;
// name: string;
// category: StyleCategory;
// img: string;
// };
// const prepareBoards = async () => {
// const boards = [];
// const board = new Board({
// size: 72,
// tiles: 2,
// showBorder: true,
// showExtraInfo: false,
// });
// for (const [key, style] of Object.entries(styles) as [BoardStyle, Style][]) {
// await board.updateConfig({ boardStyle: key });
// await board.frame(null, {});
// board.render();
// boards.push({
// key,
// name: style.name,
// category: style.category,
// img: board.toImgUrl(),
// } as BoardPreview);
// }
// return boards;
// };
// const Boards: Component<{ handlers: Handlers }> = (props) => {
// const [boards, setBoards] = createSignal<BoardPreview[]>([]);
// prepareBoards().then((data) => setBoards(data));
// return (
// <Scrollable class="boards">
// <For each={boards()}>
// {(board) => {
// return (
// <img
// class={
// "boards__ico" +
// (state.board.boardStyle === board.key
// ? " boards__ico--active"
// : "")
// }
// onClick={() => setState("board", "boardStyle", board.key)}
// src={board.img}
// title={board.name}
// />
// );
// }}
// </For>
// </Scrollable>
// );
// };
// export default Boards;

View File

@@ -5,7 +5,9 @@ import Share from "./Share";
import Boards from "./Boards"; import Boards from "./Boards";
import Pieces from "./Pieces"; import Pieces from "./Pieces";
const SetupTabs: Component<{ handlers: Handlers }> = (props) => { const SetupTabs: Component<{
handlers: Handlers;
}> = (props) => {
const [tab, setTab] = createSignal("share"); const [tab, setTab] = createSignal("share");
return ( return (