2025-09-05 20:45:04 -05:00
|
|
|
import { toUniqueId } from "@blitzkit/core";
|
|
|
|
|
import { NodeIO } from "@gltf-transform/core";
|
|
|
|
|
import { ALL_EXTENSIONS } from "@gltf-transform/extensions";
|
2025-09-05 23:34:59 -05:00
|
|
|
import { readdir, writeFile } from "fs/promises";
|
2025-09-05 20:45:04 -05:00
|
|
|
import { extractModel } from "../core/blitz/extractModel";
|
|
|
|
|
import { readXMLDVPL } from "../core/blitz/readXMLDVPL";
|
|
|
|
|
import { readYAMLDVPL } from "../core/blitz/readYAMLDVPL";
|
|
|
|
|
import { FileChange } from "../core/github/commitMultipleFiles";
|
|
|
|
|
import { DATA } from "./constants";
|
|
|
|
|
import { VehicleDefinitionList } from "./definitions";
|
|
|
|
|
import { TankParameters } from "./tankIcons";
|
2024-01-07 20:07:45 -06:00
|
|
|
|
2024-08-27 14:40:43 -05:00
|
|
|
export async function tankModels() {
|
2025-09-05 20:45:04 -05:00
|
|
|
console.log("Building tank models...");
|
2024-01-07 20:07:45 -06:00
|
|
|
|
2024-11-11 12:50:33 -06:00
|
|
|
const nodeIO = new NodeIO().registerExtensions(ALL_EXTENSIONS);
|
2024-08-14 14:04:06 -05:00
|
|
|
const nations = await readdir(`${DATA}/XML/item_defs/vehicles`).then(
|
2025-09-05 20:45:04 -05:00
|
|
|
(nations) => nations.filter((nation) => nation !== "common")
|
2024-01-07 20:07:45 -06:00
|
|
|
);
|
|
|
|
|
|
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 }>(
|
2025-09-05 20:45:04 -05:00
|
|
|
`${DATA}/XML/item_defs/vehicles/${nation}/list.xml`
|
2024-01-20 22:11:56 -06:00
|
|
|
);
|
2025-09-05 20:45:04 -05:00
|
|
|
const entries = Object.entries(tanks.root);
|
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
|
|
|
|
2025-09-05 20:45:04 -05:00
|
|
|
let index = 0;
|
|
|
|
|
for (const [tankKey, tank] of entries) {
|
|
|
|
|
console.log(` ${++index} / ${entries.length} : ${tankKey}`);
|
|
|
|
|
|
|
|
|
|
if (tankKey.includes("tutorial_bot")) continue;
|
2024-01-07 20:07:45 -06:00
|
|
|
|
2025-04-05 02:07:35 +00:00
|
|
|
const id = toUniqueId(nation, tank.id);
|
2025-08-10 14:03:13 -05:00
|
|
|
|
2025-09-05 23:34:59 -05:00
|
|
|
if (id !== 5681) continue;
|
|
|
|
|
|
2025-04-05 02:07:35 +00:00
|
|
|
const parameters = await readYAMLDVPL<TankParameters>(
|
2025-09-05 20:45:04 -05:00
|
|
|
`${DATA}/3d/Tanks/Parameters/${nation}/${tankKey}.yaml`
|
2025-04-05 02:07:35 +00:00
|
|
|
);
|
|
|
|
|
const model = await extractModel(
|
|
|
|
|
DATA,
|
2025-09-05 20:45:04 -05:00
|
|
|
parameters.resourcesPath.blitzModelPath.replace(/\.sc2$/, "")
|
2025-04-05 02:07:35 +00:00
|
|
|
);
|
2025-09-05 23:34:59 -05:00
|
|
|
const content = Buffer.from(await nodeIO.writeBinary(model));
|
2024-01-07 20:07:45 -06:00
|
|
|
|
2025-09-05 23:34:59 -05:00
|
|
|
changes.push({ path: `3d/tanks/models/${id}.glb`, content });
|
|
|
|
|
|
|
|
|
|
await writeFile(
|
|
|
|
|
"C:/Projects/blitzkit/packages/website/public/test.glb",
|
|
|
|
|
content
|
|
|
|
|
);
|
2025-04-05 02:07:35 +00:00
|
|
|
}
|
2024-01-07 20:07:45 -06:00
|
|
|
|
2025-09-05 23:34:59 -05:00
|
|
|
// await commitAssets(`tank models ${nation}`, changes);
|
2024-01-20 22:11:56 -06:00
|
|
|
}
|
2024-01-07 20:07:45 -06:00
|
|
|
}
|