Files
blitzkit/packages/scripts/src/buildAssets/boosterIcons.ts
T
2025-01-14 19:22:41 -06:00

49 lines
1.4 KiB
TypeScript

import { readdir } from 'fs/promises';
import sharp from 'sharp';
import { readDVPLFile } from '../../src/core/blitz/readDVPLFile';
import { readStringDVPL } from '../../src/core/blitz/readStringDVPL';
import { commitAssets } from '../core/github/commitAssets';
import { FileChange } from '../core/github/commitMultipleFiles';
import { DATA } from './constants';
export async function boosterIcons() {
const boosterFiles = (await readdir(`${DATA}/Gfx/Shared/boosters`)).filter(
(file) => !file.includes('@2x.txt') && !file.startsWith('texture0'),
);
const image = sharp(
await readDVPLFile(`${DATA}/Gfx/Shared/boosters/texture0.packed.webp`),
);
const changes: FileChange[] = [];
await Promise.all(
boosterFiles.map(async (file) => {
const name = file.match(/booster_(.+).txt/)?.[1];
if (name === undefined) return;
const sizes = (
await readStringDVPL(`${DATA}/Gfx/Shared/boosters/${file}`)
)
.split('\n')[4]
.split(' ')
.map(Number);
const content = await image
.clone()
.extract({
left: sizes[0],
top: sizes[1],
width: sizes[2],
height: sizes[3],
})
.toBuffer();
changes.push({
path: `icons/boosters/${name}.webp`,
content,
});
}),
);
await commitAssets('booster icons', changes);
}