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

66 lines
1.9 KiB
TypeScript
Raw Normal View History

2024-10-24 17:05:46 -05:00
import { assertSecret, BlitzGlossary } from '@blitzkit/core';
2024-03-15 12:28:29 -05:00
import sharp from 'sharp';
import { readDVPLFile } from '../../src/core/blitz/readDVPLFile';
2024-09-07 21:45:00 -05:00
import { commitAssets } from '../core/github/commitAssets';
import { FileChange } from '../core/github/commitMultipleFiles';
2024-03-15 12:28:29 -05:00
import { DATA } from './constants';
const ICONS = [
['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-08-27 14:40:43 -05:00
export async function currencies() {
2024-03-15 12:28:29 -05:00
console.log('Building currency icons...');
2024-08-21 20:23:39 -05:00
const changes: FileChange[] = [];
await Promise.all(
2024-03-15 12:28:29 -05:00
ICONS.map(async ([file, name]) => {
2024-10-21 18:32:52 -05:00
const content = await sharp(
2025-01-14 19:22:41 -06:00
await readDVPLFile(`${DATA}/Gfx/Lobby/currency/${file}`),
2024-10-21 18:32:52 -05:00
)
.trim()
.toBuffer();
2024-03-15 12:28:29 -05:00
2024-08-21 20:23:39 -05:00
changes.push({
2024-03-15 12:28:29 -05:00
content,
path: `icons/currencies/${name}.webp`,
2024-08-21 20:23:39 -05:00
});
2024-03-15 12:28:29 -05:00
}),
);
2024-11-29 12:11:51 -06:00
const glossary = await fetch(
assertSecret(import.meta.env.WOTB_GLOSSARY),
).then((response) => response.json() as Promise<BlitzGlossary>);
2024-08-21 20:23:39 -05:00
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(),
);
2024-10-21 18:32:52 -05:00
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
changes.push({
content,
path: `icons/currencies/${key}.webp`,
});
}),
);
2024-08-27 14:40:43 -05:00
await commitAssets('currency icons', changes);
2024-03-15 12:28:29 -05:00
}