diff --git a/public/img/1991-02-23_Vassily-Ivanchuk_Garry-Kasparov_Linares_R1.gif b/public/img/preview/1991-02-23_Vassily-Ivanchuk_Garry-Kasparov_Linares_R1.gif similarity index 100% rename from public/img/1991-02-23_Vassily-Ivanchuk_Garry-Kasparov_Linares_R1.gif rename to public/img/preview/1991-02-23_Vassily-Ivanchuk_Garry-Kasparov_Linares_R1.gif diff --git a/public/img/preview/anarchy.png b/public/img/preview/anarchy.png new file mode 100644 index 0000000..07d8fb2 Binary files /dev/null and b/public/img/preview/anarchy.png differ diff --git a/public/img/preview/anarchy_candy.png b/public/img/preview/anarchy_candy.png new file mode 100644 index 0000000..acab8f1 Binary files /dev/null and b/public/img/preview/anarchy_candy.png differ diff --git a/public/img/preview/anarchy_sepia.png b/public/img/preview/anarchy_sepia.png new file mode 100644 index 0000000..beddee3 Binary files /dev/null and b/public/img/preview/anarchy_sepia.png differ diff --git a/public/img/multiboard.png b/public/img/preview/multiboard.png similarity index 100% rename from public/img/multiboard.png rename to public/img/preview/multiboard.png diff --git a/scripts/createLichessPiecesCSS.js b/scripts/createLichessPiecesCSS.js new file mode 100644 index 0000000..c878138 --- /dev/null +++ b/scripts/createLichessPiecesCSS.js @@ -0,0 +1,52 @@ +const fs = require("fs"); + +const files = fs.readdirSync("_release_assets/encoded_pieces"); + +const piecesNames = { + p: "pawn", + b: "bishop", + r: "rook", + n: "knight", + q: "queen", + k: "king", +}; + +const piecesColors = { + b: "black", + w: "white", +}; + +for (const file of files) { + const [name] = file.split("."); + + const data = JSON.parse( + fs.readFileSync(`_release_assets/encoded_pieces/${file}`, { + encoding: "utf8", + }) + ); + + const css = data + .map(([key, dataURL]) => { + const [piece, color] = key.split(""); + + return `.is2d .${piecesNames[piece]}.${piecesColors[color]} {background-image:url('${dataURL}')}`; + }) + .join("\n"); + + fs.writeFileSync(`_release_assets/lichess_css/${name}.css`, css); + + const cssExternal = data + .map(([key]) => { + const [piece, color] = key.split(""); + + return `.is2d .${piecesNames[piece]}.${ + piecesColors[color] + } {background-image:url('/assets/piece/${name}/${color}${piece.toUpperCase()}.svg')}`; + }) + .join("\n"); + + fs.writeFileSync( + `_release_assets/lichess_css/${name}.external.css`, + cssExternal + ); +} diff --git a/src/board/loaders/PiecesCache.ts b/src/board/loaders/PiecesCache.ts index 09bfb52..0b5922b 100644 --- a/src/board/loaders/PiecesCache.ts +++ b/src/board/loaders/PiecesCache.ts @@ -35,6 +35,26 @@ const PiecesCache = { return piecesImages.get(piece) as HTMLImageElement; }, + + async getDataURLs() { + return Promise.all( + [...piecesImages.entries()].map( + async ([key, img]: [string, HTMLImageElement]) => { + let blob = await fetch(img.src).then((r) => r.blob()); + let dataUrl = await new Promise((resolve) => { + let reader = new FileReader(); + reader.onload = () => resolve(reader.result); + reader.readAsDataURL(blob); + }); + + return [key, dataUrl]; + } + ) + ); + }, }; +// @ts-ignore +window.PiecesCache = PiecesCache; + export default PiecesCache;