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

48 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-02-13 19:46:34 -06:00
import { readdir } from 'fs/promises';
import sharp from 'sharp';
import { readDVPLFile } from '../../src/core/blitz/readDVPLFile';
import { readStringDVPL } from '../../src/core/blitz/readStringDVPL';
2024-09-07 21:45:00 -05:00
import { commitAssets } from '../core/github/commitAssets';
import { FileChange } from '../core/github/commitMultipleFiles';
2024-08-14 14:04:06 -05:00
import { DATA } from './constants';
2024-02-13 19:46:34 -06:00
2024-08-27 14:40:43 -05:00
export async function boosterIcons() {
2024-08-14 14:04:06 -05:00
const boosterFiles = (await readdir(`${DATA}/Gfx/Shared/boosters`)).filter(
2025-01-14 19:22:41 -06:00
(file) => !file.includes('@2x.txt') && !file.startsWith('texture0'),
2024-02-13 19:46:34 -06:00
);
const image = sharp(
2025-01-14 19:22:41 -06:00
await readDVPLFile(`${DATA}/Gfx/Shared/boosters/texture0.packed.webp`),
2024-02-13 19:46:34 -06:00
);
const changes: FileChange[] = [];
await Promise.all(
boosterFiles.map(async (file) => {
2025-01-14 19:22:41 -06:00
const name = file.match(/booster_(.+).txt/)?.[1];
2024-06-22 17:46:25 -05:00
if (name === undefined) return;
2024-02-13 19:46:34 -06:00
const sizes = (
2024-08-14 14:04:06 -05:00
await readStringDVPL(`${DATA}/Gfx/Shared/boosters/${file}`)
2024-02-13 19:46:34 -06:00
)
.split('\n')[4]
.split(' ')
.map(Number);
2024-10-21 18:32:52 -05:00
const content = await image
.clone()
.extract({
left: sizes[0],
top: sizes[1],
width: sizes[2],
height: sizes[3],
})
.toBuffer();
2024-02-13 19:46:34 -06:00
changes.push({
path: `icons/boosters/${name}.webp`,
content,
});
}),
);
2024-08-27 14:40:43 -05:00
await commitAssets('booster icons', changes);
2024-02-13 19:46:34 -06:00
}