mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: currency icons
This commit is contained in:
1 parent
679bd2956b
commit
575fdbbcc3
1 file changed
+42
-3
@@ -14,10 +14,19 @@ const ICONS = [
|
|||||||
['currency_battle-xp_xl.packed.webp', 'xp'],
|
['currency_battle-xp_xl.packed.webp', 'xp'],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
type BlitzGlossary = Record<
|
||||||
|
string,
|
||||||
|
{
|
||||||
|
image_url: null | string;
|
||||||
|
}
|
||||||
|
>;
|
||||||
|
|
||||||
export async function currencies(production: boolean) {
|
export async function currencies(production: boolean) {
|
||||||
console.log('Building currency icons...');
|
console.log('Building currency icons...');
|
||||||
|
|
||||||
const changes = await Promise.all(
|
const changes: FileChange[] = [];
|
||||||
|
|
||||||
|
await Promise.all(
|
||||||
ICONS.map(async ([file, name]) => {
|
ICONS.map(async ([file, name]) => {
|
||||||
const content = (
|
const content = (
|
||||||
await sharp(
|
await sharp(
|
||||||
@@ -27,11 +36,41 @@ export async function currencies(production: boolean) {
|
|||||||
.toBuffer()
|
.toBuffer()
|
||||||
).toString('base64');
|
).toString('base64');
|
||||||
|
|
||||||
return {
|
changes.push({
|
||||||
content,
|
content,
|
||||||
encoding: 'base64',
|
encoding: 'base64',
|
||||||
path: `icons/currencies/${name}.webp`,
|
path: `icons/currencies/${name}.webp`,
|
||||||
} satisfies FileChange;
|
});
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
const glossary = await fetch(process.env.WOTB_GLOSSARY!).then(
|
||||||
|
(response) => response.json() as Promise<BlitzGlossary>,
|
||||||
|
);
|
||||||
|
|
||||||
|
await Promise.all(
|
||||||
|
Object.entries(glossary)
|
||||||
|
.filter(([key]) => /^prx_season_\d+$/.test(key))
|
||||||
|
.map(async ([key, item]) => {
|
||||||
|
if (item.image_url === null) throw new Error(`No image_url for ${key}`);
|
||||||
|
|
||||||
|
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()
|
||||||
|
).toString('base64');
|
||||||
|
|
||||||
|
changes.push({
|
||||||
|
content,
|
||||||
|
encoding: 'base64',
|
||||||
|
path: `icons/currencies/${key}.webp`,
|
||||||
|
});
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user