Files
blitzkit/packages/scripts/src/buildAssets/tankIcons.ts
T

100 lines
3.0 KiB
TypeScript
Raw Normal View History

2025-10-13 23:15:32 -05:00
import { NATION_IDS } from "@blitzkit/core";
import { readdir } from "fs/promises";
import sharp from "sharp";
import type { Vector3Tuple } from "three";
import { readDVPLFile } from "../core/blitz/readDVPLFile";
import { readXMLDVPL } from "../core/blitz/readXMLDVPL";
import { readYAMLDVPL } from "../core/blitz/readYAMLDVPL";
import { commitAssets } from "../core/github/commitAssets";
import type { FileChange } from "../core/github/commitMultipleFiles";
import { DATA } from "./constants";
import type { VehicleDefinitionList } from "./definitions";
2024-12-16 22:42:27 -06:00
export interface TankParameters {
resourcesPath: {
smallIconPath: string;
bigIconPath: string;
blitzModelPath: string;
};
collision: {
[key: string]: {
points: Vector3Tuple;
bbox: {
min: Vector3Tuple;
max: Vector3Tuple;
};
averageThickness?: Record<string, number>;
};
};
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() {
2025-10-13 23:15:32 -05:00
console.log("Building tank icons...");
2024-01-07 20:07:45 -06:00
2024-12-16 22:42:27 -06:00
const changes: FileChange[] = [];
const nations = await readdir(`${DATA}/XML/item_defs/vehicles`).then(
2025-10-13 23:15:32 -05:00
(nations) => nations.filter((nation) => nation !== "common")
2024-12-16 22:42:27 -06:00
);
2024-01-07 20:07:45 -06:00
2024-12-16 22:42:27 -06:00
await Promise.all(
nations.map(async (nation) => {
const tanks = await readXMLDVPL<{ root: VehicleDefinitionList }>(
2025-10-13 23:15:32 -05:00
`${DATA}/XML/item_defs/vehicles/${nation}/list.xml`
2024-12-16 22:42:27 -06:00
);
2024-01-07 20:07:45 -06:00
2024-12-16 22:42:27 -06:00
await Promise.all(
Object.entries(tanks.root).map(async ([tankKey, tank]) => {
2025-10-13 23:15:32 -05:00
if (tankKey.includes("tutorial_bot")) return;
2024-01-20 13:43:03 -06:00
2024-12-16 22:42:27 -06:00
const nationVehicleId = tank.id;
const id = (nationVehicleId << 8) + (NATION_IDS[nation] << 4) + 1;
2025-08-10 14:03:13 -05:00
2024-12-16 22:42:27 -06:00
const parameters = await readYAMLDVPL<TankParameters>(
2025-10-13 23:15:32 -05:00
`${DATA}/3d/Tanks/Parameters/${nation}/${tankKey}.yaml`
2024-12-16 22:42:27 -06:00
);
const smallPath = `${DATA}/${parameters.resourcesPath.smallIconPath
2025-10-13 23:15:32 -05:00
.replace(/~res:\//, "")
.replace(/\..+/, "")}.packed.webp`;
2024-12-16 22:42:27 -06:00
const bigPath = `${DATA}/${parameters.resourcesPath.bigIconPath
2025-10-13 23:15:32 -05:00
.replace(/~res:\//, "")
.replace(/\..+/, "")}.packed.webp`;
2024-12-16 22:42:27 -06: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-12-16 22:42:27 -06:00
if (big) {
changes.push({
content: big,
path: `icons/tanks/big/${id}.webp`,
});
}
if (small) {
changes.push({
content: small,
path: `icons/tanks/small/${id}.webp`,
});
}
2025-10-13 23:15:32 -05:00
})
2024-12-16 22:42:27 -06:00
);
2025-10-13 23:15:32 -05:00
})
2024-12-16 22:42:27 -06:00
);
2024-01-07 20:07:45 -06:00
2025-10-13 23:15:32 -05:00
await commitAssets("tank icons", changes);
2024-01-07 20:07:45 -06:00
}