feat: display projects as pokemons in pokemon platinum

This commit is contained in:
2025-12-11 17:16:00 +01:00
parent 25313d19a8
commit 2910eb15bd
59 changed files with 393 additions and 480 deletions

View File

@@ -1,122 +0,0 @@
<script setup lang="ts">
import SCOPE_BADGE_IMAGE from "~/assets/images/projects/top-screen/scope-badge.png";
const store = useProjectsStore();
const [scopeBadgeImage, ...projectPreviews] = useImages(
SCOPE_BADGE_IMAGE,
...store.projects.map((x) => x.preview),
);
const getBounds = () => ({
startIndex: Math.max(store.currentProject - 1, 0),
endIndex: Math.min(store.currentProject + 1 + 1, store.projects.length),
});
const TECH_BADGES: Record<string, { label: string; color: string }> = {
nuxt: { label: "Nuxt", color: "#00DC82" },
typescript: { label: "TypeScript", color: "#3178C6" },
rust: { label: "Rust", color: "#CE422B" },
html: { label: "HTML", color: "#E34C26" },
go: { label: "Go", color: "#00ADD8" },
node: { label: "Node", color: "#339933" },
stenciljs: { label: "Stencil", color: "#5851FF" },
jira: { label: "Jira", color: "#0052CC" },
confluence: { label: "Confluence", color: "#2DA2E5" },
vba: { label: "VBA", color: "#5D2B90" },
};
const BADGE_PADDING = 2;
const BADGE_SPACING = 2;
const BADGE_MARGIN = 1;
const BADGE_HEIGHT = 11;
const drawTechBadges = (
ctx: CanvasRenderingContext2D,
technologies: string[],
x: number,
y: number,
): void => {
ctx.font = "7px NDS7";
let currentX = x;
for (let i = technologies.length - 1; i >= 0; i--) {
const badge = TECH_BADGES[technologies[i]?.toLowerCase() ?? ""];
if (!badge) throw new Error(`Unknown technology: ${technologies[i]}`);
const { actualBoundingBoxRight: textWidth } = ctx.measureText(badge.label);
const badgeWidth = textWidth + BADGE_PADDING * 2;
currentX -= badgeWidth;
ctx.fillStyle = badge.color;
ctx.fillRect(currentX, y, badgeWidth, BADGE_HEIGHT);
ctx.fillStyle = "#FFFFFF";
ctx.textBaseline = "top";
ctx.fillText(badge.label, currentX + BADGE_PADDING, y + 2);
currentX -= BADGE_SPACING;
}
};
useRender((ctx) => {
const project = store.projects[store.currentProject];
if (!project) return;
ctx.font = "10px NDS10";
ctx.fillStyle = "#000000";
const { startIndex, endIndex } = getBounds();
for (let i = startIndex; i < endIndex; i += 1) {
const previewImage = projectPreviews[i]!;
const offsetFromCenter = i - store.currentProject;
const baseX = (256 - previewImage.width) / 2;
const x = baseX + 256 * offsetFromCenter + store.offsetX * (256 / 69);
const y = (192 - previewImage.height) / 2 + 10;
// game
ctx.save();
ctx.translate(x, y);
ctx.fillStyle = "#a6a6a6";
ctx.fillRect(0, 0, previewImage.width + 2, previewImage.height + 2);
ctx.fillStyle = "#000000";
ctx.fillRect(-1, -1, previewImage.width + 2, previewImage.height + 2);
ctx.save();
ctx.shadowColor = "rgba(0, 0, 0, 0.5)";
ctx.shadowBlur = 10;
ctx.shadowOffsetX = 2;
ctx.shadowOffsetY = 2;
ctx.drawImage(previewImage, 0, 0);
ctx.restore();
// technologies
const project = store.projects[i]!;
if (project.technologies && project.technologies.length > 0) {
const badgeY = previewImage.height - BADGE_HEIGHT - BADGE_MARGIN;
const badgeX = previewImage.width - BADGE_MARGIN;
drawTechBadges(ctx, project.technologies, badgeX, badgeY);
}
// scope
ctx.translate(previewImage.width - scopeBadgeImage!.width + 3, -2);
ctx.drawImage(scopeBadgeImage!, 0, 0);
ctx.font = "7px NDS7";
ctx.fillStyle = "#000000";
ctx.textBaseline = "top";
fillTextCentered(ctx, project.scope.toUpperCase(), 0, -5, 40);
ctx.restore();
}
});
defineOptions({
render: () => null,
});
</script>

View File

@@ -0,0 +1,134 @@
<script setup lang="ts">
import BACKGROUND_IMAGE from "~/assets/images/projects/top-screen/background.webp";
const store = useProjectsStore();
const [backgroundImage, ...projectImages] = useImages(
BACKGROUND_IMAGE,
...store.projects.map((project) => `/images/projects/${project.id}.webp`),
);
const drawTextWithShadow = (
ctx: CanvasRenderingContext2D,
color: "white" | "black",
text: string,
x: number,
y: number,
) => {
ctx.fillStyle = color === "white" ? "#505050" : "#a8b8b8";
ctx.fillText(text, x + 1, y + 0);
ctx.fillText(text, x + 1, y + 1);
ctx.fillText(text, x + 0, y + 1);
ctx.fillStyle = color === "white" ? "#f8f8f8" : "#101820";
ctx.fillText(text, x, y);
};
const drawTextWithShadow2Lines = (
ctx: CanvasRenderingContext2D,
text: string,
x: number,
y: number,
maxWidth: number,
line1Color: "white" | "black",
line2Color: "white" | "black",
) => {
const { actualBoundingBoxRight: textWidth } = ctx.measureText(text);
if (textWidth <= maxWidth) {
drawTextWithShadow(ctx, line1Color, text, x, y);
return;
}
const words = text.split(" ");
let firstLine = "";
let secondLine = "";
for (let i = 0; i < words.length; i++) {
const testLine = firstLine + (firstLine ? " " : "") + words[i];
const { actualBoundingBoxRight: testWidth } = ctx.measureText(testLine);
if (testWidth > maxWidth && firstLine) {
secondLine = words.slice(i).join(" ");
break;
}
firstLine = testLine;
}
drawTextWithShadow(ctx, line1Color, firstLine, x, y);
drawTextWithShadow(ctx, line2Color, secondLine, x, y + 16);
};
useRender((ctx) => {
ctx.drawImage(backgroundImage!, 0, 0);
ctx.textBaseline = "hanging";
ctx.font = "16px Pokemon DP Pro";
const project = store.projects[store.currentProject];
if (!project) return;
// image
const projectImage = projectImages[store.currentProject]!;
ctx.drawImage(
projectImage,
Math.floor(52 - projectImage.width / 2),
Math.floor(104 - projectImage.height / 2),
);
// text
drawTextWithShadow(ctx, "white", project.title.toUpperCase(), 23, 25);
drawTextWithShadow(ctx, "black", project.scope, 12, 41);
drawTextWithShadow2Lines(
ctx,
project.description,
8,
161,
90,
"white",
"black",
);
const { actualBoundingBoxRight: textWidth } = ctx.measureText(
project.summary,
);
drawTextWithShadow(
ctx,
"black",
project.summary,
Math.floor(185 - textWidth / 2),
19,
);
let textY = 35;
for (let i = 0; i < project.tasks.length; i += 1) {
const lines = project.tasks[i]!.split("\\n");
ctx.fillStyle = i % 2 === 0 ? "#6870d8" : "#8890f8";
ctx.fillRect(106, textY - 1, 150, lines.length * 16);
ctx.fillStyle = i % 2 === 0 ? "#8890f8" : "#b0b8d0";
ctx.fillRect(105, textY - 1, 1, lines.length * 16);
for (let j = 0; j < lines.length; j += 1) {
drawTextWithShadow(ctx, "white", lines[j]!, 118, textY);
textY += 16;
}
}
drawTextWithShadow2Lines(
ctx,
project.technologies.join(", "),
111,
161,
145,
"black",
"black",
);
});
defineOptions({
render: () => null,
});
</script>

View File

@@ -1,59 +0,0 @@
<script setup lang="ts">
import STATUS_BAR_IMAGE from "/assets/images/home/top-screen/status-bar/status-bar.webp";
import GBA_DISPLAY_IMAGE from "/assets/images/home/top-screen/status-bar/gba-display.webp";
import STARTUP_MODE_IMAGE from "/assets/images/home/top-screen/status-bar/startup-mode.webp";
import BATTERY_IMAGE from "/assets/images/home/top-screen/status-bar/battery.webp";
const [statusBarImage, gbaDisplayImage, startupModeImage, batteryImage] =
useImages(
STATUS_BAR_IMAGE,
GBA_DISPLAY_IMAGE,
STARTUP_MODE_IMAGE,
BATTERY_IMAGE,
);
useRender((ctx) => {
const TEXT_Y = 11;
//ctx.translate(0, store.isIntro ? store.intro.statusBarY : 0);
//ctx.globalAlpha = store.isOutro ? store.outro.stage2Opacity : 1;
ctx.drawImage(statusBarImage!, 0, 0);
ctx.fillStyle = "#ffffff";
ctx.font = "7px NDS7";
// username
ctx.fillText("pihkaal", 3, TEXT_Y);
// time + date
const fillNumberCell = (value: number, cellX: number, offset: number) => {
const text = value.toFixed().padStart(2, "0");
const { actualBoundingBoxRight: width } = ctx.measureText(text);
const x = cellX * 16;
ctx.fillText(text, Math.floor(x + offset + (16 - width) / 2), TEXT_Y);
};
const now = new Date();
fillNumberCell(now.getHours(), 9, 1);
if (Math.floor(now.getMilliseconds() / 500) % 2 == 0) {
ctx.fillText(":", 159, TEXT_Y);
}
fillNumberCell(now.getMinutes(), 10, -1);
fillNumberCell(now.getDate(), 11, 1);
ctx.fillText("/", 190, TEXT_Y);
fillNumberCell(now.getMonth() + 1, 12, -1);
// icons
ctx.drawImage(gbaDisplayImage!, 210, 2);
ctx.drawImage(startupModeImage!, 226, 2);
ctx.drawImage(batteryImage!, 242, 4);
});
defineOptions({
render: () => null,
});
</script>

View File

@@ -1,7 +1,6 @@
<script setup lang="ts">
import Background from "./Background.vue";
import StatusBar from "./StatusBar.vue";
import Previews from "./Previews.vue";
import Project from "./Project.vue";
const store = useProjectsStore();
</script>
@@ -9,7 +8,5 @@ const store = useProjectsStore();
<template>
<Background />
<StatusBar />
<Previews v-if="!store.loading" />
<Project v-if="!store.loading" />
</template>