wip
40
src/draw.ts
@ -1,5 +1,43 @@
|
|||||||
import { DominionCard } from "./types.ts";
|
import { DominionCard } from "./types.ts";
|
||||||
|
|
||||||
|
const imageCache: Record<string, HTMLImageElement> = {};
|
||||||
|
export const loadImage = (
|
||||||
|
key: string,
|
||||||
|
src: string
|
||||||
|
): Promise<HTMLImageElement> => {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
if (key in imageCache && imageCache[key]) {
|
||||||
|
resolve(imageCache[key]);
|
||||||
|
}
|
||||||
|
const img = new Image();
|
||||||
|
img.onload = () => {
|
||||||
|
imageCache[key] = img;
|
||||||
|
resolve(img);
|
||||||
|
};
|
||||||
|
img.src = src;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const imageList = [
|
||||||
|
{
|
||||||
|
key: "card",
|
||||||
|
src: "/assets/CardColorOne.png",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const imageInfo of imageList) {
|
||||||
|
const { key, src } = imageInfo;
|
||||||
|
await loadImage(key, src);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getImage = (key: string) => {
|
||||||
|
const image = imageCache[key];
|
||||||
|
if (!image) {
|
||||||
|
throw Error(`Tried to get an invalid image ${key}`);
|
||||||
|
}
|
||||||
|
return image;
|
||||||
|
};
|
||||||
|
|
||||||
export const drawCard = (
|
export const drawCard = (
|
||||||
context: CanvasRenderingContext2D,
|
context: CanvasRenderingContext2D,
|
||||||
card: DominionCard
|
card: DominionCard
|
||||||
@ -19,7 +57,7 @@ const drawStandardCard = async (
|
|||||||
const h = context.canvas.height;
|
const h = context.canvas.height;
|
||||||
context.save();
|
context.save();
|
||||||
context.fillStyle = "brown";
|
context.fillStyle = "brown";
|
||||||
context.fillRect(0, 0, w, h);
|
context.drawImage(getImage("card"), 0, 0);
|
||||||
context.restore();
|
context.restore();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
BIN
src/static/assets/BaseCardBrown.png
Normal file
After Width: | Height: | Size: 624 KiB |
BIN
src/static/assets/BaseCardColorOne.png
Normal file
After Width: | Height: | Size: 484 KiB |
BIN
src/static/assets/BaseCardGray.png
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
src/static/assets/BaseCardIcon.png
Normal file
After Width: | Height: | Size: 36 KiB |
BIN
src/static/assets/CardBrown.png
Normal file
After Width: | Height: | Size: 142 KiB |
BIN
src/static/assets/CardColorOne.png
Normal file
After Width: | Height: | Size: 1.6 MiB |
BIN
src/static/assets/CardColorThree.png
Normal file
After Width: | Height: | Size: 1.0 MiB |
BIN
src/static/assets/CardColorTwo.png
Normal file
After Width: | Height: | Size: 1.0 MiB |
BIN
src/static/assets/CardColorTwoBig.png
Normal file
After Width: | Height: | Size: 1.2 MiB |
BIN
src/static/assets/CardColorTwoNight.png
Normal file
After Width: | Height: | Size: 1.3 MiB |
BIN
src/static/assets/CardColorTwoSmall.png
Normal file
After Width: | Height: | Size: 1.0 MiB |
BIN
src/static/assets/CardGray.png
Normal file
After Width: | Height: | Size: 117 KiB |
BIN
src/static/assets/CardPortraitIcon.png
Normal file
After Width: | Height: | Size: 48 KiB |
BIN
src/static/assets/Coin.png
Normal file
After Width: | Height: | Size: 49 KiB |
BIN
src/static/assets/Debt.png
Normal file
After Width: | Height: | Size: 41 KiB |
BIN
src/static/assets/DescriptionFocus.png
Normal file
After Width: | Height: | Size: 1.2 MiB |
BIN
src/static/assets/DoubleColorOne.png
Normal file
After Width: | Height: | Size: 960 KiB |
BIN
src/static/assets/DoubleUncoloredDetails.png
Normal file
After Width: | Height: | Size: 466 KiB |
BIN
src/static/assets/EventBrown.png
Normal file
After Width: | Height: | Size: 265 KiB |
BIN
src/static/assets/EventBrown2.png
Normal file
After Width: | Height: | Size: 90 KiB |
BIN
src/static/assets/EventColorOne.png
Normal file
After Width: | Height: | Size: 353 KiB |
BIN
src/static/assets/EventColorTwo.png
Normal file
After Width: | Height: | Size: 291 KiB |
BIN
src/static/assets/EventHeirloom.png
Normal file
After Width: | Height: | Size: 200 KiB |
BIN
src/static/assets/Heirloom.png
Normal file
After Width: | Height: | Size: 175 KiB |
BIN
src/static/assets/MatBannerBottom.png
Normal file
After Width: | Height: | Size: 157 KiB |
BIN
src/static/assets/MatBannerTop.png
Normal file
After Width: | Height: | Size: 113 KiB |
BIN
src/static/assets/MatIcon.png
Normal file
After Width: | Height: | Size: 131 KiB |
BIN
src/static/assets/PileMarkerColorOne.png
Normal file
After Width: | Height: | Size: 916 KiB |
BIN
src/static/assets/PileMarkerGrey.png
Normal file
After Width: | Height: | Size: 735 KiB |
BIN
src/static/assets/PileMarkerIcon.png
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
src/static/assets/Potion.png
Normal file
After Width: | Height: | Size: 23 KiB |
BIN
src/static/assets/Sun.png
Normal file
After Width: | Height: | Size: 32 KiB |
BIN
src/static/assets/TraitBrown.png
Normal file
After Width: | Height: | Size: 316 KiB |
BIN
src/static/assets/TraitBrownSide.png
Normal file
After Width: | Height: | Size: 88 KiB |
BIN
src/static/assets/TraitColorOne.png
Normal file
After Width: | Height: | Size: 384 KiB |
BIN
src/static/assets/TraitColorOneSide.png
Normal file
After Width: | Height: | Size: 140 KiB |
BIN
src/static/assets/Traveller.png
Normal file
After Width: | Height: | Size: 88 KiB |
BIN
src/static/assets/VP-Token.png
Normal file
After Width: | Height: | Size: 50 KiB |
BIN
src/static/assets/VP.png
Normal file
After Width: | Height: | Size: 38 KiB |