Files
blitzkit/scripts/buildAssets/shellIcons.ts
T

49 lines
1.5 KiB
TypeScript
Raw Normal View History

2024-01-07 20:07:45 -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-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 shellIcons(production: boolean) {
2024-01-07 20:07:45 -06:00
console.log('Building shell icons...');
const image = sharp(
await readDVPLFile(
2024-01-16 16:58:00 -06:00
`${DATA}/${POI.bigShellIcons}/texture0.packed.webp.dvpl`,
2024-01-07 20:07:45 -06:00
),
);
const changes = await Promise.all(
2024-01-16 16:58:00 -06:00
(await readdir(`${DATA}/${POI.bigShellIcons}`))
2024-01-07 20:07:45 -06:00
.filter((file) => file.endsWith('_l.txt.dvpl'))
.map(async (file) => {
const name = file.match(/(.+)_l\.txt\.dvpl/)![1];
const sizes = (
2024-01-16 16:58:00 -06:00
await readStringDVPL(`${DATA}/${POI.bigShellIcons}/${file}`)
2024-01-07 20:07:45 -06:00
)
.split('\n')[4]
.split(' ')
.map(Number);
return {
content: (
await image
.clone()
.extract({
left: sizes[0],
top: sizes[1],
width: sizes[2],
height: sizes[3],
})
.toBuffer()
).toString('base64'),
encoding: 'base64',
path: `icons/shells/${name}.webp`,
} satisfies FileChange;
}),
);
2024-01-21 00:01:32 -06:00
await commitAssets('shell icons', changes, production);
2024-01-07 20:07:45 -06:00
}