Files
blitzkit/scripts/buildAssets/tankArmors.ts
T

49 lines
1.7 KiB
TypeScript
Raw Normal View History

2024-01-08 18:34:04 -06:00
import { NodeIO } from '@gltf-transform/core';
2024-01-09 13:36:33 -06:00
import { readdir } from 'fs/promises';
2024-01-08 18:34:04 -06:00
import { extractArmor } from '../../src/core/blitz/extractArmor';
2024-01-07 20:07:45 -06:00
import { readXMLDVPL } from '../../src/core/blitz/readXMLDVPL';
2024-01-08 18:34:04 -06:00
import { toUniqueId } from '../../src/core/blitz/toUniqueId';
2024-01-20 21:35:36 -06:00
import { commitAssets } from '../../src/core/blitzkrieg/commitAssets';
import { FileChange } from '../../src/core/blitzkrieg/commitMultipleFiles';
2024-01-16 16:58:00 -06:00
import { DATA, POI } from './constants';
2024-01-07 20:07:45 -06:00
import { VehicleDefinitionList } from './definitions';
2024-01-29 17:14:51 -06:00
export async function tankArmors(production: boolean) {
2024-01-07 20:07:45 -06:00
console.log('Building tank armors...');
2024-01-09 13:36:33 -06:00
const changes: FileChange[] = [];
2024-01-08 18:34:04 -06:00
const nodeIO = new NodeIO();
2024-01-16 16:58:00 -06:00
const nations = await readdir(`${DATA}/${POI.vehicleDefinitions}`).then(
2024-01-07 20:07:45 -06:00
(nations) => nations.filter((nation) => nation !== 'common'),
);
await Promise.all(
nations.map(async (nation) => {
const tanks = await readXMLDVPL<{ root: VehicleDefinitionList }>(
2024-01-16 16:58:00 -06:00
`${DATA}/${POI.vehicleDefinitions}/${nation}/list.xml.dvpl`,
2024-01-07 20:07:45 -06:00
);
2024-01-13 18:40:28 -06:00
await Promise.all(
Object.entries(tanks.root).map(async ([tankKey, tank]) => {
2024-01-20 13:43:03 -06:00
if (tankKey.includes('tutorial_bot')) return;
2024-01-13 18:40:28 -06:00
const id = toUniqueId(nation, tank.id);
2024-01-07 20:07:45 -06:00
2024-01-13 18:40:28 -06:00
console.log(`Building armor ${id} @ ${nation}/${tankKey}`);
2024-01-07 20:07:45 -06:00
2024-01-13 18:40:28 -06:00
const model = await extractArmor(DATA, `${nation}-${tankKey}`);
2024-01-08 18:34:04 -06:00
2024-01-13 18:40:28 -06:00
changes.push({
path: `3d/tanks/armor/${id}.glb`,
encoding: 'base64',
content: Buffer.from(await nodeIO.writeBinary(model)).toString(
'base64',
),
});
}),
);
2024-01-07 20:07:45 -06:00
}),
);
2024-01-09 13:36:33 -06:00
2024-01-21 00:01:32 -06:00
await commitAssets('tank armor', changes, production);
2024-01-07 20:07:45 -06:00
}