From be0804ae59d9db1f62547e17465aa52fb07ed564 Mon Sep 17 00:00:00 2001 From: tresabhi <43380238+tresabhi@users.noreply.github.com> Date: Tue, 4 Aug 2026 19:52:06 -0500 Subject: [PATCH] booster icons --- .../scripts/src/buildAssets/boosterIcons.ts | 46 ---------------- .../icons/boosters/[id].webp.ts | 53 +++++++++++++++++++ .../[...chunk_api]/icons/shells/[id].webp.ts | 5 -- 3 files changed, 53 insertions(+), 51 deletions(-) delete mode 100644 packages/scripts/src/buildAssets/boosterIcons.ts create mode 100644 packages/website/src/pages/[...chunk_api]/icons/boosters/[id].webp.ts diff --git a/packages/scripts/src/buildAssets/boosterIcons.ts b/packages/scripts/src/buildAssets/boosterIcons.ts deleted file mode 100644 index e2cda995c..000000000 --- a/packages/scripts/src/buildAssets/boosterIcons.ts +++ /dev/null @@ -1,46 +0,0 @@ -import sharp from "sharp"; -import { AssetUploader } from "../core/github/assetUploader"; -import { vfs } from "./constants"; - -export async function boosterIcons() { - console.log("Building booster icons..."); - - const uploader = new AssetUploader("booster icons"); - const boosterFiles = await vfs - .dir("Data/Gfx/Shared/boosters") - .then((files) => - files.filter( - (file) => !file.includes("@2x.txt") && !file.startsWith("texture0"), - ), - ); - const image = sharp( - await vfs.file(`Data/Gfx/Shared/boosters/texture0.packed.webp`), - ); - - for (const file of boosterFiles) { - const name = file.match(/booster_(.+).txt/)?.[1]; - - if (name === undefined) continue; - - const sizes = (await vfs.text(`Data/Gfx/Shared/boosters/${file}`)) - .split("\n")[4] - .split(" ") - .map(Number); - const content = await image - .clone() - .extract({ - left: sizes[0], - top: sizes[1], - width: sizes[2], - height: sizes[3], - }) - .toBuffer(); - - await uploader.add({ - path: `icons/boosters/${name}.webp`, - content, - }); - } - - await uploader.flush(); -} diff --git a/packages/website/src/pages/[...chunk_api]/icons/boosters/[id].webp.ts b/packages/website/src/pages/[...chunk_api]/icons/boosters/[id].webp.ts new file mode 100644 index 000000000..2e3d176bb --- /dev/null +++ b/packages/website/src/pages/[...chunk_api]/icons/boosters/[id].webp.ts @@ -0,0 +1,53 @@ +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 boosterFiles = await vfs + .dir("Data/Gfx/Shared/boosters") + .then((files) => + files.filter( + (file) => !file.includes("@2x.txt") && !file.startsWith("texture0"), + ), + ); + + for (const file of boosterFiles) { + const id = file.match(/booster_(.+).txt/)?.[1]; + + if (id === undefined) continue; + + const sizes = (await vfs.text(`Data/Gfx/Shared/boosters/${file}`)) + .split("\n")[4] + .split(" ") + .map(Number); + + paths.push({ + params: { id }, + props: { sizes }, + }); + } + + return paths; +}); + +export async function GET({ props }: APIContext<{ sizes: number[] }>) { + const image = sharp( + await vfs.file(`Data/Gfx/Shared/boosters/texture0.packed.webp`), + ); + const buffer = await image + .clone() + .extract({ + left: props.sizes[0], + top: props.sizes[1], + width: props.sizes[2], + height: props.sizes[3], + }) + .toBuffer(); + const bytes = new Uint8Array(buffer); + + return new Response(bytes); +} diff --git a/packages/website/src/pages/[...chunk_api]/icons/shells/[id].webp.ts b/packages/website/src/pages/[...chunk_api]/icons/shells/[id].webp.ts index ad614b1a3..f8c520d04 100644 --- a/packages/website/src/pages/[...chunk_api]/icons/shells/[id].webp.ts +++ b/packages/website/src/pages/[...chunk_api]/icons/shells/[id].webp.ts @@ -7,11 +7,6 @@ import { getStaticPaths as _getStaticPaths } from "../../_index"; export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => { const paths: GetStaticPathsItem[] = []; - const image = sharp( - await vfs.file( - `Data/Gfx/Shared/tank-supply/ammunition/big/texture0.packed.webp`, - ), - ); const files = await vfs .dir(`Data/Gfx/Shared/tank-supply/ammunition/big`) .then((files) => files.filter((file) => file.endsWith("_l.txt")));