2024-01-16 16:58:00 -06:00
|
|
|
import sharp from 'sharp';
|
|
|
|
|
import { readDVPLFile } from '../../src/core/blitz/readDVPLFile';
|
|
|
|
|
import { readStringDVPL } from '../../src/core/blitz/readStringDVPL';
|
|
|
|
|
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-16 16:58:00 -06:00
|
|
|
import { OptionalDevices } from './definitions';
|
|
|
|
|
|
|
|
|
|
interface Mappings {
|
|
|
|
|
Header: { version: number };
|
|
|
|
|
|
|
|
|
|
StyleSheets: {
|
|
|
|
|
selectors: string[];
|
|
|
|
|
properties: { 'bg-sprite': string };
|
|
|
|
|
}[];
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-20 21:35:36 -06:00
|
|
|
export async function equipmentIcons(production: boolean) {
|
2024-01-16 16:58:00 -06:00
|
|
|
console.log('Building equipment icons...');
|
|
|
|
|
|
|
|
|
|
const changes: FileChange[] = [];
|
|
|
|
|
const optionalDevices = await readXMLDVPL<{ root: OptionalDevices }>(
|
2024-08-14 14:04:06 -05:00
|
|
|
`${DATA}/XML/item_defs/vehicles/common/optional_devices.xml.dvpl`,
|
2024-01-16 16:58:00 -06:00
|
|
|
);
|
|
|
|
|
const mappings = await readYAMLDVPL<Mappings>(
|
2024-08-14 14:04:06 -05:00
|
|
|
`${DATA}/UI/Screens3/Lobby/Inventory/OptionalDevices/OptionalDevicesItemImage.style.yaml.dvpl`,
|
2024-01-16 16:58:00 -06:00
|
|
|
);
|
|
|
|
|
const image = sharp(
|
2024-08-14 14:04:06 -05:00
|
|
|
await readDVPLFile(
|
|
|
|
|
`${DATA}/Gfx/UI/InventoryIcons/Big/OptionalDevices/texture0.packed.webp.dvpl`,
|
|
|
|
|
),
|
2024-01-16 16:58:00 -06:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
await Promise.all(
|
|
|
|
|
Object.entries(optionalDevices.root).map(
|
|
|
|
|
async ([optionalDeviceKey, optionalDevice]) => {
|
|
|
|
|
if (optionalDeviceKey === 'nextAvailableId') return;
|
|
|
|
|
|
|
|
|
|
const mapping = mappings.StyleSheets.find((mapping) =>
|
|
|
|
|
mapping.selectors.includes(
|
|
|
|
|
`.optional_device_item.${optionalDevice.icon} #Img`,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (!mapping) {
|
|
|
|
|
console.warn(
|
|
|
|
|
`No mapping found for ${optionalDevice.icon}; skipping...`,
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const configPathRaw = mapping.properties['bg-sprite'];
|
|
|
|
|
const configPath = configPathRaw.replace('~res:/', '');
|
|
|
|
|
|
|
|
|
|
if (configPath.startsWith('Gfx/Lobby')) {
|
|
|
|
|
const configPathWebp = configPath.replace('.txt', '');
|
2024-02-11 14:17:41 -06:00
|
|
|
const image = sharp(
|
|
|
|
|
await readDVPLFile(`${DATA}/${configPathWebp}.packed.webp.dvpl`),
|
2024-01-16 16:58:00 -06:00
|
|
|
);
|
2024-02-11 14:17:41 -06:00
|
|
|
const content = (await image.trim().toBuffer()).toString('base64');
|
2024-01-16 16:58:00 -06:00
|
|
|
|
|
|
|
|
changes.push({
|
|
|
|
|
path: `icons/equipment/${optionalDevice.id}.webp`,
|
|
|
|
|
encoding: 'base64',
|
2024-02-11 14:17:41 -06:00
|
|
|
content,
|
2024-01-16 16:58:00 -06:00
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
const config = await readStringDVPL(`${DATA}/${configPath}.dvpl`);
|
|
|
|
|
const sizes = config.split('\n')[4].split(' ').map(Number);
|
|
|
|
|
const content = (
|
|
|
|
|
await image
|
|
|
|
|
.clone()
|
|
|
|
|
.extract({
|
|
|
|
|
left: sizes[0],
|
|
|
|
|
top: sizes[1],
|
|
|
|
|
width: sizes[2],
|
|
|
|
|
height: sizes[3],
|
|
|
|
|
})
|
|
|
|
|
.toBuffer()
|
|
|
|
|
).toString('base64');
|
|
|
|
|
|
|
|
|
|
changes.push({
|
|
|
|
|
path: `icons/equipment/${optionalDevice.id}.webp`,
|
|
|
|
|
encoding: 'base64',
|
|
|
|
|
content,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
2024-01-21 00:01:32 -06:00
|
|
|
await commitAssets('equipment icons', changes, production);
|
2024-01-16 16:58:00 -06:00
|
|
|
}
|