feat: optimized assets

This commit is contained in:
TrèsAbhi committed 2024-01-20 22:11:56 -06:00
1 parent 00244846cb
commit 7669c2d76b
13 files changed
+75 -78

No files matched your search

+38 -41
View File
@@ -18,56 +18,53 @@ interface VehicleCustomization {
export async function buildTankModels(production: boolean) {
console.log('Building tank models...');
const changes: FileChange[] = [];
const nodeIO = new NodeIO();
const nations = await readdir(`${DATA}/${POI.vehicleDefinitions}`).then(
(nations) => nations.filter((nation) => nation !== 'common'),
);
await Promise.all(
nations.map(async (nation) => {
if (nation !== 'germany') return;
for (const nationIndex in nations) {
const changes: FileChange[] = [];
const nation = nations[nationIndex];
const tanks = await readXMLDVPL<{ root: VehicleDefinitionList }>(
`${DATA}/${POI.vehicleDefinitions}/${nation}/list.xml.dvpl`,
);
const customization = await readXMLDVPL<{ root: VehicleCustomization }>(
`${DATA}/${POI.vehicleDefinitions}/${nation}/customization.xml.dvpl`,
);
const baseColor = customization.root.armorColor
.split(' ')
.slice(0, 3)
.map(Number)
.map((channel) => channel / 255) as Vector3Tuple;
const tanks = await readXMLDVPL<{ root: VehicleDefinitionList }>(
`${DATA}/${POI.vehicleDefinitions}/${nation}/list.xml.dvpl`,
);
const customization = await readXMLDVPL<{ root: VehicleCustomization }>(
`${DATA}/${POI.vehicleDefinitions}/${nation}/customization.xml.dvpl`,
);
const baseColor = customization.root.armorColor
.split(' ')
.slice(0, 3)
.map(Number)
.map((channel) => channel / 255) as Vector3Tuple;
await Promise.all(
Object.entries(tanks.root).map(async ([tankKey, tank]) => {
if (tankKey.includes('tutorial_bot')) return;
await Promise.all(
Object.entries(tanks.root).map(async ([tankKey, tank]) => {
if (tankKey.includes('tutorial_bot')) return;
const id = toUniqueId(nation, tank.id);
const id = toUniqueId(nation, tank.id);
console.log(`Building model ${id} @ ${nation}/${tankKey}`);
console.log(`Building model ${id} @ ${nation}/${tankKey}`);
const parameters = await readYAMLDVPL<TankParameters>(
`${DATA}/${POI.tankParameters}/${nation}/${tankKey}.yaml.dvpl`,
);
const model = await extractModel(
DATA,
parameters.resourcesPath.blitzModelPath.replace(/\.sc2$/, ''),
baseColor,
);
const parameters = await readYAMLDVPL<TankParameters>(
`${DATA}/${POI.tankParameters}/${nation}/${tankKey}.yaml.dvpl`,
);
const model = await extractModel(
DATA,
parameters.resourcesPath.blitzModelPath.replace(/\.sc2$/, ''),
baseColor,
);
changes.push({
path: `3d/tanks/models/${id}.glb`,
encoding: 'base64',
content: Buffer.from(await nodeIO.writeBinary(model)).toString(
'base64',
),
});
}),
);
changes.push({
path: `3d/tanks/models/${id}.glb`,
encoding: 'base64',
content: Buffer.from(await nodeIO.writeBinary(model)).toString(
'base64',
),
});
}),
);
}),
);
await commitAssets('tank models', changes, production);
await commitAssets(`tank models ${nation}`, changes, production);
}
}