Files
blitzkit/packages/scripts/src/buildAssets/currencies.ts
T

62 lines
1.7 KiB
TypeScript
Raw Normal View History

2025-10-23 21:22:21 -05:00
import { assertSecret, BlitzGlossary } from "@blitzkit/core";
import sharp from "sharp";
import { AssetUploader } from "../core/github/assetUploader";
2025-11-26 13:18:44 -06:00
import { vfs } from "./constants";
2024-03-15 12:28:29 -05:00
const ICONS = [
2025-10-23 21:22:21 -05:00
["currency_silver_m.packed.webp", "silver"],
["currency_premium_xl.packed.webp", "premium"],
["currency_gold_m.packed.webp", "gold"],
["currency_free-xp_xl.packed.webp", "free-xp"],
["currency_elite-xp_xl.packed.webp", "elite-xp"],
["currency_crew-xp_xl.packed.webp", "crew-xp"],
["currency_battle-xp_xl.packed.webp", "xp"],
2024-03-15 12:28:29 -05:00
];
2024-08-27 14:40:43 -05:00
export async function currencies() {
2025-10-23 21:22:21 -05:00
console.log("Building currency icons...");
2024-03-15 12:28:29 -05:00
2025-10-23 21:22:21 -05:00
using uploader = new AssetUploader("currency icons");
2024-08-21 20:23:39 -05:00
2025-10-23 21:22:21 -05:00
for (const [file, name] of ICONS) {
const content = await sharp(
2025-11-26 13:18:44 -06:00
await vfs.file(`Data/Gfx/Lobby/currency/${file}`)
2025-10-23 21:22:21 -05:00
)
.trim()
.toBuffer();
2024-03-15 12:28:29 -05:00
2025-10-23 21:22:21 -05:00
await uploader.add({
content,
path: `icons/currencies/${name}.webp`,
});
}
2024-03-15 12:28:29 -05:00
2025-10-23 21:22:21 -05:00
const glossary = await fetch(assertSecret(import.meta.env.WOTB_GLOSSARY))
.then((response) => response.json() as Promise<BlitzGlossary>)
.then((glossary) =>
Object.values(glossary)
.entries()
.filter(([key]) => /^prx_season_\d+$/.test(`${key}`))
);
2024-08-21 20:23:39 -05:00
2025-10-23 21:22:21 -05:00
for (const [key, item] of glossary) {
if (item.image_url === null) throw new Error(`No image_url for ${key}`);
2024-08-21 20:23:39 -05:00
2025-10-23 21:22:21 -05:00
const imageRaw = await fetch(item.image_url).then((response) =>
response.arrayBuffer()
);
const content = await sharp(imageRaw)
.trim({
threshold: 100,
background: { r: 0, g: 0, b: 0, alpha: 0 },
})
.toBuffer();
2024-08-21 20:23:39 -05:00
2025-10-23 21:22:21 -05:00
await uploader.add({
content,
path: `icons/currencies/${key}.webp`,
});
}
2024-08-21 20:23:39 -05:00
2025-10-23 21:22:21 -05:00
await uploader.flush();
2024-03-15 12:28:29 -05:00
}