Files
blitzkit/scripts/buildAssets/tankArmors.ts
T

60 lines
1.8 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-09 13:36:33 -06:00
import commitMultipleFiles, {
FileChange,
} from '../../src/core/blitzkrieg/commitMultipleFiles';
2024-01-08 18:34:04 -06:00
import { DATA, DOI } from './constants';
2024-01-07 20:07:45 -06:00
import { VehicleDefinitionList } from './definitions';
export async function buildTankArmors() {
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-07 20:07:45 -06:00
const nations = await readdir(`${DATA}/${DOI.vehicleDefinitions}`).then(
(nations) => nations.filter((nation) => nation !== 'common'),
);
await Promise.all(
nations.map(async (nation) => {
2024-01-12 13:57:32 -06:00
if (nation !== 'france') return;
2024-01-10 18:14:55 -06:00
2024-01-07 20:07:45 -06:00
const tanks = await readXMLDVPL<{ root: VehicleDefinitionList }>(
`${DATA}/${DOI.vehicleDefinitions}/${nation}/list.xml.dvpl`,
);
for (const tankKey in tanks.root) {
const tank = tanks.root[tankKey];
2024-01-08 18:34:04 -06:00
const id = toUniqueId(nation, tank.id);
2024-01-07 20:07:45 -06:00
2024-01-10 13:22:55 -06:00
// if (id !== 7297) continue; // 60tp
2024-01-10 18:14:55 -06:00
// if (id !== 5137) continue; // tiger ii
2024-01-08 18:34:04 -06:00
// if (id !== 24609) continue; // concept 1b
2024-01-07 20:07:45 -06:00
console.log(`Building armor ${id} @ ${nation}/${tankKey}`);
2024-01-08 18:34:04 -06:00
2024-01-09 13:07:27 -06:00
const model = await extractArmor(DATA, `${nation}-${tankKey}`);
2024-01-08 18:34:04 -06:00
2024-01-09 13:36:33 -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
await commitMultipleFiles(
'tresabhi',
'blitzkrieg-assets',
'main',
'tank armor',
changes,
true,
);
2024-01-07 20:07:45 -06:00
}