mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 03:59:50 +02:00
feat: consumable icons
This commit is contained in:
1 parent
d4e8ec125f
commit
c56eaa258d
4 files changed
+161
-4
No files matched your search
@@ -19,5 +19,8 @@ export const POI = {
|
|||||||
'UI/Screens3/Lobby/Inventory/OptionalDevices/OptionalDevicesItemImage.style.yaml',
|
'UI/Screens3/Lobby/Inventory/OptionalDevices/OptionalDevicesItemImage.style.yaml',
|
||||||
optionalDevicesImage:
|
optionalDevicesImage:
|
||||||
'Gfx/UI/InventoryIcons/Big/OptionalDevices/texture0.packed.webp',
|
'Gfx/UI/InventoryIcons/Big/OptionalDevices/texture0.packed.webp',
|
||||||
consumables: 'XML/item_defs/vehicles/common/consumables/common.xml',
|
consumablesCommon: 'XML/item_defs/vehicles/common/consumables/common.xml',
|
||||||
|
consumableIcons: 'Gfx/UI/InventoryIcons/Big/Consumables',
|
||||||
|
equipmentItemImageMappings:
|
||||||
|
'UI/Screens3/Lobby/Inventory/Equipment/EquipmentItemImage.style.yaml',
|
||||||
} as const;
|
} as const;
|
||||||
@@ -0,0 +1,149 @@
|
|||||||
|
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';
|
||||||
|
import commitMultipleFiles, {
|
||||||
|
FileChange,
|
||||||
|
} from '../../src/core/blitzkrieg/commitMultipleFiles';
|
||||||
|
import { DATA, POI } from './constants';
|
||||||
|
import { ConsumablesCommon } from './definitions';
|
||||||
|
|
||||||
|
interface Mappings {
|
||||||
|
Header: { version: number };
|
||||||
|
StyleSheets: {
|
||||||
|
selectors: string[];
|
||||||
|
properties: { 'bg-sprite': string };
|
||||||
|
}[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function buildConsumableIcons() {
|
||||||
|
console.log('Building consumable icons...');
|
||||||
|
|
||||||
|
const changes: FileChange[] = [];
|
||||||
|
// const files = await readdir(`${DATA}/${POI.consumableIcons}`);
|
||||||
|
const texture = sharp(
|
||||||
|
await readDVPLFile(
|
||||||
|
`${DATA}/${POI.consumableIcons}/texture0.packed.webp.dvpl`,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
// const consumablesCommon = await readXMLDVPL<{ root: ConsumablesCommon }>(
|
||||||
|
// `${DATA}/${POI.consumablesCommon}.dvpl`,
|
||||||
|
// );
|
||||||
|
// const consumablesCommonValues = Object.values(consumablesCommon.root);
|
||||||
|
|
||||||
|
// await Promise.all(
|
||||||
|
// files
|
||||||
|
// .filter(
|
||||||
|
// (file) => file.endsWith('.txt.dvpl') && !file.endsWith('@2x.txt.dvpl'),
|
||||||
|
// )
|
||||||
|
// .map(async (file) => {
|
||||||
|
// const name = file.replace('.txt.dvpl', '');
|
||||||
|
// const sizes = await (
|
||||||
|
// await readStringDVPL(`${DATA}/${POI.consumableIcons}/${file}`)
|
||||||
|
// )
|
||||||
|
// .split('\n')[4]
|
||||||
|
// .split(' ')
|
||||||
|
// .map(Number);
|
||||||
|
// const commonEntry = consumablesCommonValues.find(
|
||||||
|
// (consumable) => consumable.icon === name,
|
||||||
|
// );
|
||||||
|
|
||||||
|
// if (!commonEntry) {
|
||||||
|
// console.warn(`No common entry found for ${name}; skipping...`);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const content = (
|
||||||
|
// await texture
|
||||||
|
// .clone()
|
||||||
|
// .extract({
|
||||||
|
// left: sizes[0],
|
||||||
|
// top: sizes[1],
|
||||||
|
// width: sizes[2],
|
||||||
|
// height: sizes[3],
|
||||||
|
// })
|
||||||
|
// .toBuffer()
|
||||||
|
// ).toString('base64');
|
||||||
|
|
||||||
|
// changes.push({
|
||||||
|
// path: `icons/consumables/${commonEntry.id}.webp`,
|
||||||
|
// encoding: 'base64',
|
||||||
|
// content,
|
||||||
|
// });
|
||||||
|
// }),
|
||||||
|
// );
|
||||||
|
|
||||||
|
const equipmentItemImageMappings = await readYAMLDVPL<Mappings>(
|
||||||
|
`${DATA}/${POI.equipmentItemImageMappings}.dvpl`,
|
||||||
|
);
|
||||||
|
const consumablesCommon = await readXMLDVPL<{ root: ConsumablesCommon }>(
|
||||||
|
`${DATA}/${POI.consumablesCommon}.dvpl`,
|
||||||
|
);
|
||||||
|
const styleSheets = Object.values(equipmentItemImageMappings.StyleSheets);
|
||||||
|
|
||||||
|
Promise.all(
|
||||||
|
Object.values(consumablesCommon.root).map(async (consumable) => {
|
||||||
|
const styleSheet = styleSheets.find((styleSheet) =>
|
||||||
|
styleSheet.selectors.includes(
|
||||||
|
`.equipment_item.${consumable.icon} * .equipment-img`,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!styleSheet) {
|
||||||
|
throw new Error(
|
||||||
|
`No style sheet found for consumable ${consumable.icon}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const configPath = styleSheet.properties['bg-sprite']
|
||||||
|
.replace('~res:/', '')
|
||||||
|
.replace('.psd', '.txt');
|
||||||
|
|
||||||
|
if (configPath.startsWith('Gfx/Shared')) {
|
||||||
|
const imagePath = `${configPath}.packed.webp.dvpl`;
|
||||||
|
const content = (await readDVPLFile(`${DATA}/${imagePath}`)).toString(
|
||||||
|
'base64',
|
||||||
|
);
|
||||||
|
|
||||||
|
changes.push({
|
||||||
|
path: `icons/consumables/${consumable.id}.webp`,
|
||||||
|
encoding: 'base64',
|
||||||
|
content,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const sizes = (await readStringDVPL(`${DATA}/${configPath}.dvpl`))
|
||||||
|
.split('\n')[4]
|
||||||
|
.split(' ')
|
||||||
|
.map(Number);
|
||||||
|
const content = (
|
||||||
|
await texture
|
||||||
|
.clone()
|
||||||
|
.extract({
|
||||||
|
left: sizes[0],
|
||||||
|
top: sizes[1],
|
||||||
|
width: sizes[2],
|
||||||
|
height: sizes[3],
|
||||||
|
})
|
||||||
|
.toBuffer()
|
||||||
|
).toString('base64');
|
||||||
|
|
||||||
|
changes.push({
|
||||||
|
path: `icons/consumables/${consumable.id}.webp`,
|
||||||
|
encoding: 'base64',
|
||||||
|
content,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log('Committing consumable icons...');
|
||||||
|
await commitMultipleFiles(
|
||||||
|
'tresabhi',
|
||||||
|
'blitzkrieg-assets',
|
||||||
|
'main',
|
||||||
|
'consumable icons',
|
||||||
|
changes,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -183,7 +183,7 @@ interface OptionalDeviceSlotRow {
|
|||||||
[key: string]: { device0: string; device1: string };
|
[key: string]: { device0: string; device1: string };
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Consumables {
|
export interface ConsumablesCommon {
|
||||||
[key: string]: {
|
[key: string]: {
|
||||||
id: number;
|
id: number;
|
||||||
userString: string;
|
userString: string;
|
||||||
@@ -259,8 +259,8 @@ export async function buildDefinitions() {
|
|||||||
const optionalDeviceSlots = await readXMLDVPL<{
|
const optionalDeviceSlots = await readXMLDVPL<{
|
||||||
root: OptionalDeviceSlots;
|
root: OptionalDeviceSlots;
|
||||||
}>(`${DATA}/${POI.optionalDeviceSlots}.dvpl`);
|
}>(`${DATA}/${POI.optionalDeviceSlots}.dvpl`);
|
||||||
const consumables = await readXMLDVPL<{ root: Consumables }>(
|
const consumables = await readXMLDVPL<{ root: ConsumablesCommon }>(
|
||||||
`${DATA}/${POI.consumables}.dvpl`,
|
`${DATA}/${POI.consumablesCommon}.dvpl`,
|
||||||
);
|
);
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { config } from 'dotenv';
|
import { config } from 'dotenv';
|
||||||
import { argv } from 'process';
|
import { argv } from 'process';
|
||||||
import { circleFlags } from './circleFlags';
|
import { circleFlags } from './circleFlags';
|
||||||
|
import { buildConsumableIcons } from './consumableIcons';
|
||||||
import { buildDefinitions } from './definitions';
|
import { buildDefinitions } from './definitions';
|
||||||
import { equipmentIcons } from './equipmentIcons';
|
import { equipmentIcons } from './equipmentIcons';
|
||||||
import { buildModuleIcons } from './moduleIcons';
|
import { buildModuleIcons } from './moduleIcons';
|
||||||
@@ -62,3 +63,7 @@ if (allTargets || targets?.includes('tankArmor')) {
|
|||||||
if (allTargets || targets?.includes('equipmentIcons')) {
|
if (allTargets || targets?.includes('equipmentIcons')) {
|
||||||
await equipmentIcons();
|
await equipmentIcons();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (allTargets || targets?.includes('consumableIcons')) {
|
||||||
|
await buildConsumableIcons();
|
||||||
|
}
|
||||||
Reference in new issue
Block a user