This commit is contained in:
Maciej Caderek
2022-01-13 06:00:00 +01:00
commit f3069d6dd1
48 changed files with 2220 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
import { PieceType, PieceColor, Piece } from "../../types";
import piecesSets from "../styles-pieces";
import loadImage from "./loadImage";
const images: Map<string, HTMLImageElement> = new Map();
const PiecesCache = {
async get(
piecesSetName: keyof typeof piecesSets,
pieceName: PieceType,
pieceColor: PieceColor
) {
const piece = `${pieceName}${pieceColor}` as Piece;
const key = `${piecesSetName}_${piece}`;
if (!images.has(key)) {
const pieceSrc = piecesSets[piecesSetName][piece];
const img = await loadImage(pieceSrc);
images.set(key, img);
}
return images.get(key) as HTMLImageElement;
},
};
export default PiecesCache;