From b25814e3991eb687daeedc5ee2b2544a0edbf88c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Thu, 15 Aug 2024 21:08:02 -0500 Subject: [PATCH] fix: trim --- scripts/buildAssets/definitions.ts | 7 ++-- scripts/buildAssets/gameModeIcons.ts | 52 +++++++++++++++++++++------- scripts/buildAssets/index.ts | 3 +- 3 files changed, 46 insertions(+), 16 deletions(-) diff --git a/scripts/buildAssets/definitions.ts b/scripts/buildAssets/definitions.ts index 596b2f17e..e21b2d3c2 100644 --- a/scripts/buildAssets/definitions.ts +++ b/scripts/buildAssets/definitions.ts @@ -400,7 +400,7 @@ interface AvailableNationsYaml { available_nations: string[]; } -export interface SquadBattleTypeUI { +export interface SquadBattleTypeStyles { Prototypes: { components: { UIDataLocalBindingsComponent: { @@ -496,11 +496,11 @@ export async function definitions(production: boolean) { `${DATA}/camouflages.yaml.dvpl`, ); const camouflagesXmlEntries = Object.entries(camouflagesXml.root.camouflages); - const squadBattleTypeUI = await readYAMLDVPL( + const squadBattleTypeStyles = await readYAMLDVPL( `${DATA}/UI/Screens3/Lobby/Hangar/Squad/SquadBattleType.yaml.dvpl`, ); - for (const match of squadBattleTypeUI.Prototypes[0].components.UIDataLocalBindingsComponent.data[1][2].matchAll( + for (const match of squadBattleTypeStyles.Prototypes[0].components.UIDataLocalBindingsComponent.data[1][2].matchAll( /"(\d+)" -> "(battleType\/[a-zA-Z]+)"/g, )) { const id = Number(match[1]); @@ -1336,6 +1336,7 @@ export async function definitions(production: boolean) { }; }); + return; await commitAssets( 'definitions', [ diff --git a/scripts/buildAssets/gameModeIcons.ts b/scripts/buildAssets/gameModeIcons.ts index 31c7193c8..90e3463d4 100644 --- a/scripts/buildAssets/gameModeIcons.ts +++ b/scripts/buildAssets/gameModeIcons.ts @@ -1,24 +1,52 @@ +import sharp from 'sharp'; +import { readDVPLFile } from '../../src/core/blitz/readDVPLFile'; import { readYAMLDVPL } from '../../src/core/blitz/readYAMLDVPL'; +import { commitAssets } from '../../src/core/blitzkit/commitAssets'; +import { FileChange } from '../../src/core/blitzkit/commitMultipleFiles'; import { DATA } from './constants'; -import { SquadBattleTypeUI } from './definitions'; - -// enum EGameMode { -// Rating = 7, -// Scuffle = 22, -// } +import { SquadBattleTypeStyles } from './definitions'; export async function gameModeIcons(production: boolean) { - const squadBattleTypeUI = await readYAMLDVPL( + const changes: FileChange[] = []; + const gameTypeSelectorStyles = await readYAMLDVPL( + `${DATA}/UI/Screens/Lobby/Hangar/GameTypeSelector.yaml.dvpl`, + ); + const squadBattleTypeStyles = await readYAMLDVPL( `${DATA}/UI/Screens3/Lobby/Hangar/Squad/SquadBattleType.yaml.dvpl`, ); + const bannerMatches: { name: string; path: string }[] = []; - for (const match of squadBattleTypeUI.Prototypes[0].components.UIDataLocalBindingsComponent.data[0][2].matchAll( - /"(\d+)" -> "(battleType\/[a-zA-Z]+)"/g, + for (const match of gameTypeSelectorStyles.Prototypes[0].components.UIDataLocalBindingsComponent.data[1][2].matchAll( + /eGameMode\.([a-zA-Z]+) -> "~res:([^"]+)"/g, + )) { + bannerMatches.push({ name: match[1], path: match[2] }); + } + + for (const match of squadBattleTypeStyles.Prototypes[0].components.UIDataLocalBindingsComponent.data[1][2].matchAll( + /"(\d+)" -> "battleType\/([a-zA-Z]+)"/g, )) { const id = Number(match[1]); + const name = match[2]; + let path = bannerMatches.find( + (bannerMatch) => bannerMatch.name.toLowerCase() === name.toLowerCase(), + )?.path; - // gameDefinitions.gameModes[id] = { - // name, - // }; + if (path === undefined) { + path = `/Gfx/UI/Hangar/GameTypes/battle-type_${name.toLowerCase()}`; + } + + const content = ( + await sharp(await readDVPLFile(`${DATA}${path}.packed.webp.dvpl`)) + .trim({ background: { r: 0, g: 0, b: 0, alpha: 0 } }) + .toBuffer() + ).toString('base64'); + + changes.push({ + path: `icons/game_mode_banners/${id}.webp`, + content, + encoding: 'base64', + }); } + + await commitAssets('game mode icons', changes, production); } diff --git a/scripts/buildAssets/index.ts b/scripts/buildAssets/index.ts index 7c62ac81e..0bd4afe59 100644 --- a/scripts/buildAssets/index.ts +++ b/scripts/buildAssets/index.ts @@ -17,6 +17,7 @@ import { consumableProvisionIcons } from './consumableProvisionIcons'; import { currencies } from './currencies'; import { definitions } from './definitions'; import { equipmentIcons } from './equipmentIcons'; +import { gameModeIcons } from './gameModeIcons'; import { moduleIcons } from './moduleIcons'; import { scratchedFlags } from './scratchedFlags'; import { shellIcons } from './shellIcons'; @@ -29,7 +30,7 @@ import { videos } from './videos'; if (!targets && !allTargets) throw new Error('No target(s) specified'); const methods = [ - // gameModeIcons, + gameModeIcons, definitions, tankIcons, videos,