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

75 lines
2.3 KiB
TypeScript
Raw Normal View History

2024-09-02 10:30:20 -05:00
import { readdir } from 'fs/promises';
2024-08-16 21:08:50 -05:00
import sharp from 'sharp';
2024-09-07 21:45:00 -05:00
import { readDVPLFile } from '../core/blitz/readDVPLFile';
import { commitAssets } from '../core/github/commitAssets';
import { FileChange } from '../core/github/commitMultipleFiles';
2024-08-16 21:08:50 -05:00
import { DATA } from './constants';
2024-08-27 14:40:43 -05:00
export async function flags() {
2024-08-16 21:08:50 -05:00
console.log('Building flags...');
const changes = [
...(await Promise.all(
2024-10-21 18:32:52 -05:00
(await readdir(`${DATA}/Gfx/Lobby/flags`))
2024-08-16 21:08:50 -05:00
.filter(
(flag) =>
flag.startsWith('flag_profile-stat_') &&
2025-01-14 19:22:41 -06:00
!flag.endsWith('@2x.packed.webp'),
2024-08-16 21:08:50 -05:00
)
.map(async (flag) => {
const image = sharp(
await readDVPLFile(`${DATA}/Gfx/Lobby/flags/${flag}`),
);
2024-10-21 18:32:52 -05:00
const content = await image.trim({ threshold: 100 }).toBuffer();
2024-08-16 21:08:50 -05:00
const name = flag.match(/flag_profile-stat_(.+)\.packed\.webp/)![1];
return {
content,
path: `flags/circle/${name}.webp`,
} satisfies FileChange;
}),
)),
...(await Promise.all(
2024-10-21 18:32:52 -05:00
(await readdir(`${DATA}/Gfx/Lobby/flags`))
2024-08-16 21:08:50 -05:00
.filter(
(flag) =>
flag.startsWith('flag_tutor-tank_') &&
2025-01-14 19:22:41 -06:00
!flag.endsWith('@2x.packed.webp'),
2024-08-16 21:08:50 -05:00
)
.map(async (flag) => {
2024-10-21 18:32:52 -05:00
const content = await readDVPLFile(`${DATA}/Gfx/Lobby/flags/${flag}`);
2024-08-16 21:08:50 -05:00
const name = flag.match(/flag_tutor-tank_(.+)\.packed\.webp/)![1];
return {
path: `flags/scratched/${name}.webp`,
2024-10-21 18:32:52 -05:00
content,
2024-08-16 21:08:50 -05:00
} satisfies FileChange;
}),
)),
...(await Promise.all(
2024-10-21 18:32:52 -05:00
(await readdir(`${DATA}/Gfx/Lobby/flags`))
2024-08-16 21:08:50 -05:00
.filter(
(flag) =>
2025-01-14 19:22:41 -06:00
flag.startsWith('flag_filter_') && flag.endsWith('@2x.packed.webp'),
2024-08-16 21:08:50 -05:00
)
.map(async (flag) => {
2024-10-21 18:32:52 -05:00
const content = await sharp(
await readDVPLFile(`${DATA}/Gfx/Lobby/flags/${flag}`),
)
.trim({
threshold: 100,
background: { r: 0, g: 0, b: 0, alpha: 0 },
})
.toBuffer();
2024-08-16 21:08:50 -05:00
const name = flag.match(/flag_filter_(.+)@2x\.packed\.webp/)![1];
return {
content,
path: `flags/fade_small/${name}.webp`,
} satisfies FileChange;
}),
)),
];
2024-08-27 14:40:43 -05:00
await commitAssets('flags', changes);
2024-08-16 21:08:50 -05:00
}