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

97 lines
2.8 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";
2025-10-23 21:22:21 -05:00
import { AssetUploader } from "../core/github/assetUploader";
2025-10-13 23:15:32 -05:00
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
2025-10-23 21:22:21 -05:00
using uploader = new AssetUploader("tank icons");
2024-12-16 22:42:27 -06:00
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
2025-10-23 21:22:21 -05:00
for (const nation of nations) {
const tanks = await readXMLDVPL<{ root: VehicleDefinitionList }>(
`${DATA}/XML/item_defs/vehicles/${nation}/list.xml`
);
for (const tankKey in tanks.root) {
const tank = tanks.root[tankKey];
if (tankKey.includes("tutorial_bot")) continue;
const nationVehicleId = tank.id;
const id = (nationVehicleId << 8) + (NATION_IDS[nation] << 4) + 1;
const parameters = await readYAMLDVPL<TankParameters>(
`${DATA}/3d/Tanks/Parameters/${nation}/${tankKey}.yaml`
2024-12-16 22:42:27 -06:00
);
2025-10-23 21:22:21 -05:00
const smallPath = `${DATA}/${parameters.resourcesPath.smallIconPath
.replace(/~res:\//, "")
.replace(/\..+/, "")}.packed.webp`;
const bigPath = `${DATA}/${parameters.resourcesPath.bigIconPath
.replace(/~res:\//, "")
.replace(/\..+/, "")}.packed.webp`;
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
2025-10-23 21:22:21 -05:00
if (big) {
await uploader.add({
content: big,
path: `icons/tanks/big/${id}.webp`,
});
}
if (small) {
await uploader.add({
content: small,
path: `icons/tanks/small/${id}.webp`,
});
}
}
}
2024-01-20 13:43:03 -06:00
2025-10-23 21:22:21 -05:00
await uploader.flush();
2024-01-07 20:07:45 -06:00
}