Files
blitzkit/scripts/buildAssets/tankIcons.ts
T

101 lines
3.2 KiB
TypeScript
Raw Normal View History

2024-01-07 20:07:45 -06:00
import { readdir } from 'fs/promises';
2024-04-04 11:04:27 -05:00
import sharp from 'sharp';
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';
2024-04-04 11:04:27 -05:00
import { readDVPLFile } from '../../src/core/blitz/readDVPLFile';
2024-01-07 20:07:45 -06:00
import { readXMLDVPL } from '../../src/core/blitz/readXMLDVPL';
import { readYAMLDVPL } from '../../src/core/blitz/readYAMLDVPL';
2024-04-23 09:57:59 -05:00
import { commitAssets } from '../../src/core/blitzkit/commitAssets';
import { FileChange } from '../../src/core/blitzkit/commitMultipleFiles';
2024-08-14 14:04:06 -05:00
import { DATA } 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-04-13 10:36:13 -05:00
maskSlice?: {
[key: string]:
| {
enabled: boolean;
planePosition: Vector3Tuple;
planeNormal: Vector3Tuple;
planeAxis: Vector3Tuple;
frustumConeBaseRadius: number;
frustumConeAngleDegrees: number;
planeSliceMode: number;
frustumConeSliceMode: number;
}
| undefined;
};
2024-01-07 20:07:45 -06:00
}
2024-08-27 14:40:43 -05:00
export async function tankIcons() {
2024-01-07 20:07:45 -06:00
console.log('Building tank icons...');
const changes: FileChange[] = [];
2024-08-14 14:04:06 -05:00
const nations = await readdir(`${DATA}/XML/item_defs/vehicles`).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-08-14 14:04:06 -05:00
`${DATA}/XML/item_defs/vehicles/${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-08-14 14:04:06 -05:00
`${DATA}/3d/Tanks/Parameters/${nation}/${tankKey}.yaml.dvpl`,
2024-01-17 12:31:07 -06:00
);
2024-04-04 11:04:27 -05:00
const smallPath = `${DATA}/${parameters.resourcesPath.smallIconPath
2024-01-17 12:31:07 -06:00
.replace(/~res:\//, '')
.replace(/\..+/, '')}.packed.webp.dvpl`;
2024-04-04 11:04:27 -05:00
const bigPath = `${DATA}/${parameters.resourcesPath.bigIconPath
2024-01-17 12:31:07 -06:00
.replace(/~res:\//, '')
.replace(/\..+/, '')}.packed.webp.dvpl`;
2024-04-04 11:04:27 -05:00
const big = await sharp(await readDVPLFile(bigPath))
.trim()
.toBuffer();
const small = await sharp(await readDVPLFile(smallPath))
.trim()
.toBuffer();
2024-01-07 20:07:45 -06:00
2024-01-17 12:31:07 -06:00
if (big) {
changes.push({
2024-04-04 11:04:27 -05:00
content: big.toString('base64'),
2024-01-17 12:31:07 -06:00
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({
2024-04-04 11:04:27 -05:00
content: small.toString('base64'),
2024-01-17 12:31:07 -06:00
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-08-27 14:40:43 -05:00
await commitAssets('tank icons', changes);
2024-01-07 20:07:45 -06:00
}