Files
blitzkit/scripts/buildAssets/boosterIcons.ts
T

51 lines
1.5 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-04-23 09:57:59 -05:00
import { commitAssets } from '../../src/core/blitzkit/commitAssets';
import { FileChange } from '../../src/core/blitzkit/commitMultipleFiles';
2024-08-14 14:04:06 -05:00
import { DATA } from './constants';
2024-02-13 19:46:34 -06:00
export async function boosterIcons(production: boolean) {
2024-08-14 14:04:06 -05:00
const boosterFiles = (await readdir(`${DATA}/Gfx/Shared/boosters`)).filter(
2024-02-13 19:46:34 -06:00
(file) => !file.endsWith('@2x.txt.dvpl') && !file.startsWith('texture0'),
);
const image = sharp(
2024-08-14 14:04:06 -05:00
await readDVPLFile(`${DATA}/Gfx/Shared/boosters/texture0.packed.webp.dvpl`),
2024-02-13 19:46:34 -06:00
);
const changes: FileChange[] = [];
await Promise.all(
boosterFiles.map(async (file) => {
2024-06-22 17:46:25 -05:00
const name = file.match(/booster_(.+).txt.dvpl/)?.[1];
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);
const content = (
await image
.clone()
.extract({
left: sizes[0],
top: sizes[1],
width: sizes[2],
height: sizes[3],
})
.toBuffer()
).toString('base64');
changes.push({
path: `icons/boosters/${name}.webp`,
content,
encoding: 'base64',
});
}),
);
await commitAssets('booster icons', changes, production);
}