Files
blitzkit/scripts/buildAssets/tankIcons.ts
T

80 lines
2.6 KiB
TypeScript
Raw Normal View History

2024-01-07 20:07:45 -06:00
import { readdir } from 'fs/promises';
2024-01-28 20:45:50 -06:00
import { Vector3Tuple } from 'three';
2024-01-07 20:07:45 -06:00
import { NATION_IDS } from '../../src/constants/nations';
import { readBase64DVPL } from '../../src/core/blitz/readBase64DVPL';
import { readXMLDVPL } from '../../src/core/blitz/readXMLDVPL';
import { readYAMLDVPL } from '../../src/core/blitz/readYAMLDVPL';
2024-01-20 21:35:36 -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';
export interface TankParameters {
resourcesPath: {
smallIconPath: string;
bigIconPath: string;
blitzModelPath: string;
};
2024-01-28 20:45:50 -06:00
collision: {
[key: string]: {
points: Vector3Tuple;
bbox: {
min: Vector3Tuple;
max: Vector3Tuple;
};
averageThickness?: Record<string, number>;
};
};
2024-01-07 20:07:45 -06:00
}
2024-01-29 17:14:51 -06:00
export async function tankIcons(production: boolean) {
2024-01-07 20:07:45 -06:00
console.log('Building tank icons...');
const changes: FileChange[] = [];
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-17 12:31:07 -06:00
await Promise.all(
2024-01-20 13:43:03 -06:00
Object.entries(tanks.root).map(async ([tankKey, tank]) => {
if (tankKey.includes('tutorial_bot')) return;
2024-01-17 12:31:07 -06:00
const nationVehicleId = tank.id;
const id = (nationVehicleId << 8) + (NATION_IDS[nation] << 4) + 1;
const parameters = await readYAMLDVPL<TankParameters>(
2024-01-20 13:43:03 -06:00
`${DATA}/${POI.tankParameters}/${nation}/${tankKey}.yaml.dvpl`,
2024-01-17 12:31:07 -06:00
);
const small = `${DATA}/${parameters.resourcesPath.smallIconPath
.replace(/~res:\//, '')
.replace(/\..+/, '')}.packed.webp.dvpl`;
const big = `${DATA}/${parameters.resourcesPath.bigIconPath
.replace(/~res:\//, '')
.replace(/\..+/, '')}.packed.webp.dvpl`;
2024-01-07 20:07:45 -06:00
2024-01-17 12:31:07 -06:00
if (big) {
changes.push({
content: await readBase64DVPL(big),
encoding: 'base64',
2024-01-17 12:39:02 -06:00
path: `icons/tanks/big/${id}.webp`,
2024-01-17 12:31:07 -06:00
});
}
if (small) {
changes.push({
content: await readBase64DVPL(small),
encoding: 'base64',
2024-01-17 12:39:02 -06:00
path: `icons/tanks/small/${id}.webp`,
2024-01-17 12:31:07 -06:00
});
}
}),
);
2024-01-07 20:07:45 -06:00
}),
);
2024-01-21 00:01:32 -06:00
await commitAssets('tank icons', changes, production);
2024-01-07 20:07:45 -06:00
}