Files
blitzkit/scripts/buildAssets/tankModels.ts
T

58 lines
2.0 KiB
TypeScript
Raw Normal View History

2024-01-07 20:07:45 -06:00
import { NodeIO } from '@gltf-transform/core';
2024-01-09 13:36:33 -06:00
import { readdir } from 'fs/promises';
2024-01-07 20:07:45 -06:00
import { extractModel } from '../../src/core/blitz/extractModel';
import { readXMLDVPL } from '../../src/core/blitz/readXMLDVPL';
import { readYAMLDVPL } from '../../src/core/blitz/readYAMLDVPL';
2024-01-08 18:34:04 -06:00
import { toUniqueId } from '../../src/core/blitz/toUniqueId';
2024-02-21 09:54:58 -06:00
import { commitAssets } from '../../src/core/blitzkrieg/commitAssets';
import { FileChange } from '../../src/core/blitzkrieg/commitMultipleFiles';
2024-02-20 11:21:01 -06:00
import { DATA, POI } from './constants';
2024-01-07 20:07:45 -06:00
import { VehicleDefinitionList } from './definitions';
import { TankParameters } from './tankIcons';
2024-01-29 15:27:21 -06:00
export async function tankModels(production: boolean) {
2024-01-07 20:07:45 -06:00
console.log('Building tank models...');
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'),
);
2024-01-20 22:11:56 -06:00
for (const nationIndex in nations) {
const nation = nations[nationIndex];
2024-02-21 07:45:48 -06:00
const changes: FileChange[] = [];
2024-02-21 08:07:27 -06:00
const tanks = await readXMLDVPL<{ root: VehicleDefinitionList }>(
2024-01-20 22:11:56 -06:00
`${DATA}/${POI.vehicleDefinitions}/${nation}/list.xml.dvpl`,
);
2024-01-19 23:33:27 -06:00
2024-02-20 11:21:01 -06:00
console.log(`Building models for ${nation}`);
2024-02-18 19:11:41 -06:00
2024-01-20 22:11:56 -06:00
await Promise.all(
Object.entries(tanks.root).map(async ([tankKey, tank]) => {
if (tankKey.includes('tutorial_bot')) return;
2024-01-07 20:07:45 -06:00
2024-01-20 22:11:56 -06:00
const id = toUniqueId(nation, tank.id);
2024-01-20 13:43:03 -06:00
2024-01-20 22:11:56 -06:00
console.log(`Building model ${id} @ ${nation}/${tankKey}`);
2024-01-07 20:07:45 -06:00
2024-01-20 22:11:56 -06:00
const parameters = await readYAMLDVPL<TankParameters>(
`${DATA}/${POI.tankParameters}/${nation}/${tankKey}.yaml.dvpl`,
);
const model = await extractModel(
DATA,
parameters.resourcesPath.blitzModelPath.replace(/\.sc2$/, ''),
);
2024-01-07 20:07:45 -06:00
2024-02-21 07:45:48 -06:00
changes.push({
path: `3d/tanks/models/${id}.glb`,
2024-02-21 12:51:39 -06:00
content: Buffer.from(await nodeIO.writeBinary(model)).toString(
'base64',
),
encoding: 'base64',
2024-02-21 07:45:48 -06:00
});
2024-01-20 22:11:56 -06:00
}),
);
2024-01-07 20:07:45 -06:00
2024-02-21 07:45:48 -06:00
await commitAssets(`tank models ${nation}`, changes, production);
2024-01-20 22:11:56 -06:00
}
2024-01-07 20:07:45 -06:00
}