feat(assets): use single texture atlas instead of loading all images individually
This commit is contained in:
@@ -11,23 +11,28 @@ const CLICK_RADIUS = 22;
|
||||
const BUTTONS = {
|
||||
prev: {
|
||||
position: [36, 100],
|
||||
image: assets.projects.bottomScreen.prevPressed,
|
||||
image: assets.images.projects.bottomScreen.prevPressed,
|
||||
},
|
||||
quit: {
|
||||
position: [88, 156],
|
||||
image: assets.projects.bottomScreen.quitPressed,
|
||||
image: assets.images.projects.bottomScreen.quitPressed,
|
||||
},
|
||||
link: {
|
||||
position: [168, 156],
|
||||
image: assets.projects.bottomScreen.linkPressed,
|
||||
image: assets.images.projects.bottomScreen.linkPressed,
|
||||
},
|
||||
next: {
|
||||
position: [220, 100],
|
||||
image: assets.projects.bottomScreen.nextPressed,
|
||||
image: assets.images.projects.bottomScreen.nextPressed,
|
||||
},
|
||||
} as const satisfies Record<
|
||||
string,
|
||||
{ position: Point; image: HTMLImageElement }
|
||||
{
|
||||
position: Point;
|
||||
image: {
|
||||
draw: (ctx: CanvasRenderingContext2D, x: number, y: number) => void;
|
||||
};
|
||||
}
|
||||
>;
|
||||
|
||||
type ButtonType = keyof typeof BUTTONS;
|
||||
@@ -115,15 +120,15 @@ onClick((x, y) => {
|
||||
onRender((ctx) => {
|
||||
// Draw disabled buttons
|
||||
if (store.currentProject === 0) {
|
||||
ctx.drawImage(
|
||||
assets.projects.bottomScreen.prevDisabled,
|
||||
assets.images.projects.bottomScreen.prevDisabled.draw(
|
||||
ctx,
|
||||
BUTTONS.prev.position[0] - 14,
|
||||
BUTTONS.prev.position[1] - 14,
|
||||
);
|
||||
}
|
||||
if (store.currentProject === store.projects.length - 1) {
|
||||
ctx.drawImage(
|
||||
assets.projects.bottomScreen.nextDisabled,
|
||||
assets.images.projects.bottomScreen.nextDisabled.draw(
|
||||
ctx,
|
||||
BUTTONS.next.position[0] - 14,
|
||||
BUTTONS.next.position[1] - 14,
|
||||
);
|
||||
@@ -131,24 +136,24 @@ onRender((ctx) => {
|
||||
|
||||
if (currentAnimation?.showButton) {
|
||||
const image = BUTTONS[currentAnimation.type].image;
|
||||
ctx.drawImage(
|
||||
image!,
|
||||
image.draw(
|
||||
ctx,
|
||||
currentAnimation.position[0] - 14,
|
||||
currentAnimation.position[1] - 14,
|
||||
);
|
||||
}
|
||||
|
||||
if (currentAnimation?.showSmallCircle) {
|
||||
ctx.drawImage(
|
||||
assets.projects.bottomScreen.circleSmall,
|
||||
assets.images.projects.bottomScreen.circleSmall.draw(
|
||||
ctx,
|
||||
currentAnimation.position[0] - 28,
|
||||
currentAnimation.position[1] - 28,
|
||||
);
|
||||
}
|
||||
|
||||
if (currentAnimation?.showBigCircle) {
|
||||
ctx.drawImage(
|
||||
assets.projects.bottomScreen.circleBig,
|
||||
assets.images.projects.bottomScreen.circleBig.draw(
|
||||
ctx,
|
||||
currentAnimation.position[0] - 44,
|
||||
currentAnimation.position[1] - 44,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user