Added script to export piece sets for Lichess
|
Before Width: | Height: | Size: 3.1 MiB After Width: | Height: | Size: 3.1 MiB |
BIN
public/img/preview/anarchy.png
Normal file
|
After Width: | Height: | Size: 140 KiB |
BIN
public/img/preview/anarchy_candy.png
Normal file
|
After Width: | Height: | Size: 45 KiB |
BIN
public/img/preview/anarchy_sepia.png
Normal file
|
After Width: | Height: | Size: 451 KiB |
|
Before Width: | Height: | Size: 262 KiB After Width: | Height: | Size: 262 KiB |
52
scripts/createLichessPiecesCSS.js
Normal file
@@ -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
|
||||
);
|
||||
}
|
||||
@@ -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;
|
||||
|
||||