diff --git a/scripts/buildAssets/circleFlags.ts b/scripts/buildAssets/circleFlags.ts deleted file mode 100644 index 2ce95a293..000000000 --- a/scripts/buildAssets/circleFlags.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { readdir } from 'fs/promises'; -import sharp from 'sharp'; -import { readDVPLFile } from '../../src/core/blitz/readDVPLFile'; -import { commitAssets } from '../../src/core/blitzkit/commitAssets'; -import { FileChange } from '../../src/core/blitzkit/commitMultipleFiles'; -import { DATA } from './constants'; - -export async function circleFlags(production: boolean) { - const flags = await readdir(`${DATA}/Gfx/Lobby/flags`); - const changes = await Promise.all( - flags - .filter( - (flag) => - flag.startsWith('flag_profile-stat_') && - !flag.endsWith('@2x.packed.webp.dvpl'), - ) - .map(async (flag) => { - const image = sharp( - await readDVPLFile(`${DATA}/Gfx/Lobby/flags/${flag}`), - ); - const content = ( - await image.trim({ threshold: 100 }).toBuffer() - ).toString('base64'); - const name = flag.match(/flag_profile-stat_(.+)\.packed\.webp/)![1]; - - return { - content, - encoding: 'base64', - path: `flags/circle/${name}.webp`, - } satisfies FileChange; - }), - ); - - await commitAssets('circle flags', changes, production); -} diff --git a/scripts/buildAssets/flags.ts b/scripts/buildAssets/flags.ts new file mode 100644 index 000000000..21ca7f41c --- /dev/null +++ b/scripts/buildAssets/flags.ts @@ -0,0 +1,86 @@ +import { readdir, writeFile } from 'fs/promises'; +import sharp from 'sharp'; +import { readBase64DVPL } from '../../src/core/blitz/readBase64DVPL'; +import { readDVPLFile } from '../../src/core/blitz/readDVPLFile'; +import { commitAssets } from '../../src/core/blitzkit/commitAssets'; +import { FileChange } from '../../src/core/blitzkit/commitMultipleFiles'; +import { DATA } from './constants'; + +export async function flags(production: boolean) { + console.log('Building flags...'); + + const changes = [ + ...(await Promise.all( + (await readdir(`${DATA}/Gfx/Lobby/flags`)) + .filter( + (flag) => + flag.startsWith('flag_profile-stat_') && + !flag.endsWith('@2x.packed.webp.dvpl'), + ) + .map(async (flag) => { + const image = sharp( + await readDVPLFile(`${DATA}/Gfx/Lobby/flags/${flag}`), + ); + const content = ( + await image.trim({ threshold: 100 }).toBuffer() + ).toString('base64'); + const name = flag.match(/flag_profile-stat_(.+)\.packed\.webp/)![1]; + + return { + content, + encoding: 'base64', + path: `flags/circle/${name}.webp`, + } satisfies FileChange; + }), + )), + ...(await Promise.all( + (await readdir(`${DATA}/Gfx/Lobby/flags`)) + .filter( + (flag) => + flag.startsWith('flag_tutor-tank_') && + !flag.endsWith('@2x.packed.webp.dvpl'), + ) + .map(async (flag) => { + const content = await readBase64DVPL( + `${DATA}/Gfx/Lobby/flags/${flag}`, + ); + const name = flag.match(/flag_tutor-tank_(.+)\.packed\.webp/)![1]; + + return { + content, + encoding: 'base64', + path: `flags/scratched/${name}.webp`, + } satisfies FileChange; + }), + )), + ...(await Promise.all( + (await readdir(`${DATA}/Gfx/Lobby/flags`)) + .filter( + (flag) => + flag.startsWith('flag_filter_') && + flag.endsWith('@2x.packed.webp.dvpl'), + ) + .map(async (flag) => { + const content = ( + await sharp(await readDVPLFile(`${DATA}/Gfx/Lobby/flags/${flag}`)) + .trim({ + threshold: 100, + background: { r: 0, g: 0, b: 0, alpha: 0 }, + }) + .toBuffer() + ).toString('base64'); + const name = flag.match(/flag_filter_(.+)@2x\.packed\.webp/)![1]; + + writeFile(`temp/icons/${name}.webp`, content, { encoding: 'base64' }); + + return { + content, + encoding: 'base64', + path: `flags/fade_small/${name}.webp`, + } satisfies FileChange; + }), + )), + ]; + + await commitAssets('flags', changes, production); +} diff --git a/scripts/buildAssets/index.ts b/scripts/buildAssets/index.ts index 6a37cf087..4d6b5abae 100644 --- a/scripts/buildAssets/index.ts +++ b/scripts/buildAssets/index.ts @@ -12,14 +12,13 @@ const production = argv.includes('--production'); import { boosterIcons } from './boosterIcons'; import { camouflageIcons } from './camouflageIcons'; -import { circleFlags } from './circleFlags'; import { consumableProvisionIcons } from './consumableProvisionIcons'; import { currencies } from './currencies'; import { definitions } from './definitions'; import { equipmentIcons } from './equipmentIcons'; +import { flags } from './flags'; import { gameModeBanners } from './gameModeBanners'; import { moduleIcons } from './moduleIcons'; -import { scratchedFlags } from './scratchedFlags'; import { shellIcons } from './shellIcons'; import { skillIcons } from './skillIcons'; import { tankArmors } from './tankArmors'; @@ -34,10 +33,9 @@ const methods = [ definitions, tankIcons, videos, - scratchedFlags, currencies, skillIcons, - circleFlags, + flags, shellIcons, moduleIcons, equipmentIcons, diff --git a/scripts/buildAssets/scratchedFlags.ts b/scripts/buildAssets/scratchedFlags.ts deleted file mode 100644 index c3cc6880d..000000000 --- a/scripts/buildAssets/scratchedFlags.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { readdir } from 'fs/promises'; -import { readBase64DVPL } from '../../src/core/blitz/readBase64DVPL'; -import { commitAssets } from '../../src/core/blitzkit/commitAssets'; -import { FileChange } from '../../src/core/blitzkit/commitMultipleFiles'; -import { DATA } from './constants'; - -export async function scratchedFlags(production: boolean) { - console.log('Building scratched flags...'); - - const flags = await readdir(`${DATA}/Gfx/Lobby/flags`); - const changes = await Promise.all( - flags - .filter( - (flag) => - flag.startsWith('flag_tutor-tank_') && - !flag.endsWith('@2x.packed.webp.dvpl'), - ) - .map(async (flag) => { - const content = await readBase64DVPL(`${DATA}/Gfx/Lobby/flags/${flag}`); - const name = flag.match(/flag_tutor-tank_(.+)\.packed\.webp/)![1]; - - return { - content, - encoding: 'base64', - path: `flags/scratched/${name}.webp`, - } satisfies FileChange; - }), - ); - - await commitAssets('scratched flags', changes, production); -}