From aaae8fb8ff396058f22cc301df4c5f74cd08a0d1 Mon Sep 17 00:00:00 2001 From: tresabhi <43380238+tresabhi@users.noreply.github.com> Date: Tue, 4 Aug 2026 19:40:57 -0500 Subject: [PATCH] module icons --- .../scripts/src/buildAssets/moduleIcons.ts | 34 ---------------- .../[...chunk_api]/icons/modules/[id].webp.ts | 40 +++++++++++++++++++ 2 files changed, 40 insertions(+), 34 deletions(-) delete mode 100644 packages/scripts/src/buildAssets/moduleIcons.ts create mode 100644 packages/website/src/pages/[...chunk_api]/icons/modules/[id].webp.ts diff --git a/packages/scripts/src/buildAssets/moduleIcons.ts b/packages/scripts/src/buildAssets/moduleIcons.ts deleted file mode 100644 index 01b9790b1..000000000 --- a/packages/scripts/src/buildAssets/moduleIcons.ts +++ /dev/null @@ -1,34 +0,0 @@ -import sharp from "sharp"; -import { AssetUploader } from "../core/github/assetUploader"; -import { vfs } from "./constants"; - -export async function moduleIcons() { - console.log("Building module icons..."); - - using uploader = new AssetUploader("module icons"); - const files = await vfs - .dir(`Data/Gfx/UI/ModulesTechTree`) - .then((files) => - files.filter( - (file) => - !file.endsWith("@2x.packed.webp") && file.startsWith("vehicle"), - ), - ); - - for (const file of files) { - const nameRaw = file.match(/vehicle(.+)\.packed\.webp/)![1]; - const name = nameRaw[0].toLowerCase() + nameRaw.slice(1); - const content = await sharp( - await vfs.file(`Data/Gfx/UI/ModulesTechTree/${file}`), - ) - .trim() - .toBuffer(); - - await uploader.add({ - content, - path: `icons/modules/${name}.webp`, - }); - } - - await uploader.flush(); -} diff --git a/packages/website/src/pages/[...chunk_api]/icons/modules/[id].webp.ts b/packages/website/src/pages/[...chunk_api]/icons/modules/[id].webp.ts new file mode 100644 index 000000000..9237a57a2 --- /dev/null +++ b/packages/website/src/pages/[...chunk_api]/icons/modules/[id].webp.ts @@ -0,0 +1,40 @@ +import type { APIContext, GetStaticPathsItem } from "astro"; +import sharp from "sharp"; +import { mixStaticPaths } from "../../../../core/blitzkit/mixStaticPaths"; +import { vfs } from "../../../../core/blitzkit/vfs"; +import { getStaticPaths as _getStaticPaths } from "../../_index"; + +export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => { + const paths: GetStaticPathsItem[] = []; + + const files = await vfs + .dir(`Data/Gfx/UI/ModulesTechTree`) + .then((files) => + files.filter( + (file) => + !file.endsWith("@2x.packed.webp") && file.startsWith("vehicle"), + ), + ); + + for (const file of files) { + const nameRaw = file.match(/vehicle(.+)\.packed\.webp/)![1]; + const id = nameRaw[0].toLowerCase() + nameRaw.slice(1); + const path = `Data/Gfx/UI/ModulesTechTree/${file}`; + + paths.push({ + params: { id }, + props: { path }, + }); + } + + return paths; +}); + +export async function GET({ props }: APIContext<{ path: string }>) { + const buffer = await sharp(await vfs.file(props.path)) + .trim() + .toBuffer(); + const bytes = new Uint8Array(buffer); + + return new Response(bytes); +}