Files
blitzkit/scripts/buildAssets/moduleIcons.ts
T

35 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-01-07 20:07:45 -06:00
import { readdir } from 'fs/promises';
2024-04-08 09:23:26 -05:00
import sharp from 'sharp';
import { readDVPLFile } from '../../src/core/blitz/readDVPLFile';
2024-04-23 09:57:59 -05:00
import { commitAssets } from '../../src/core/blitzkit/commitAssets';
import { FileChange } from '../../src/core/blitzkit/commitMultipleFiles';
2024-02-20 11:21:01 -06:00
import { DATA, POI } from './constants';
2024-01-07 20:07:45 -06:00
2024-01-29 17:14:51 -06:00
export async function moduleIcons(production: boolean) {
2024-01-07 20:07:45 -06:00
console.log('Building module icons...');
const changes = await Promise.all(
2024-01-16 16:58:00 -06:00
(await readdir(`${DATA}/${POI.moduleIcons}`))
2024-01-07 20:07:45 -06:00
.filter(
(file) =>
!file.endsWith('@2x.packed.webp.dvpl') && file.startsWith('vehicle'),
)
.map(async (file) => {
const nameRaw = file.match(/vehicle(.+)\.packed\.webp\.dvpl/)![1];
const name = nameRaw[0].toLowerCase() + nameRaw.slice(1);
2024-04-08 09:23:26 -05:00
const content = (
await sharp(await readDVPLFile(`${DATA}/${POI.moduleIcons}/${file}`))
.trim()
.toBuffer()
).toString('base64');
2024-01-07 20:07:45 -06:00
return {
content,
path: `icons/modules/${name}.webp`,
encoding: 'base64',
} satisfies FileChange;
}),
);
2024-01-21 00:01:32 -06:00
await commitAssets('module icons', changes, production);
2024-01-07 20:07:45 -06:00
}