feat(assets): new assets loading system (currently only for images)

This commit is contained in:
2025-12-17 12:28:48 +01:00
parent a31f72f41d
commit 2f16f382e5
106 changed files with 359 additions and 366 deletions

View File

@@ -1,13 +1,5 @@
<script setup lang="ts">
import CALENDAR_IMAGE from "/assets/images/home/top-screen/calendar/calendar.webp";
import LAST_ROW_IMAGE from "/assets/images/home/top-screen/calendar/last-row.webp";
import DAY_SELECTOR_IMAGE from "/assets/images/home/top-screen/calendar/day-selector.webp";
const [calendarImage, lastRowImage, daySelectorImage] = useImages(
CALENDAR_IMAGE,
LAST_ROW_IMAGE,
DAY_SELECTOR_IMAGE,
);
const { assets } = useAssets();
useRender((ctx) => {
ctx.fillStyle = "black";
@@ -29,11 +21,19 @@ useRender((ctx) => {
const firstDay = new Date(year, month, 1).getDay();
const daysInMonth = new Date(year, month + 1, 0).getDate();
ctx.drawImage(calendarImage!, CALENDAR_LEFT - 3, CALENDAR_TOP - 33);
ctx.drawImage(
assets.home.topScreen.calendar.calendar,
CALENDAR_LEFT - 3,
CALENDAR_TOP - 33,
);
const extraRow = CALENDAR_COLS * CALENDAR_ROWS - daysInMonth - firstDay < 0;
if (extraRow) {
ctx.drawImage(lastRowImage!, CALENDAR_LEFT - 3, CALENDAR_TOP + 79);
ctx.drawImage(
assets.home.topScreen.calendar.lastRow,
CALENDAR_LEFT - 3,
CALENDAR_TOP + 79,
);
}
for (let col = 0; col < CALENDAR_ROWS + (extraRow ? 1 : 0); col += 1) {
@@ -49,7 +49,11 @@ useRender((ctx) => {
const cellTop = CALENDAR_TOP + col * 16;
if (now.getDate() === day) {
ctx.drawImage(daySelectorImage!, cellLeft, cellTop);
ctx.drawImage(
assets.home.topScreen.calendar.daySelector,
cellLeft,
cellTop,
);
}
ctx.fillText(