feat: tankopedia images

This commit is contained in:
TrèsAbhi committed 2023-11-16 12:57:46 -06:00
1 parent 032d98e6bd
commit 393da234e4
3 files changed
+62 -19

No files matched your search

+1
View File
@@ -53,6 +53,7 @@
"vitepress": "^1.0.0-rc.20",
"vitepress-plugin-auto-sidebar": "^1.1.0",
"xml-js": "^1.6.11",
"yaml": "^2.3.4",
"zustand": "^4.4.1"
},
"devDependencies": {
+56 -19
View File
@@ -1,23 +1,41 @@
import decompress from 'decompress';
import { readFile, readdir, rm, writeFile } from 'fs/promises';
import { cp, mkdir, readFile, readdir, rm, writeFile } from 'fs/promises';
import { load } from 'js-yaml';
import { argv } from 'process';
import { ElementCompact, xml2js } from 'xml-js';
import { parse } from 'yaml';
import { NATION_IDS } from '../src/constants/nations';
const REWRITE = false;
const VEHICLE_DEFS = 'assets/Data/XML/item_defs/vehicles';
const APK_FILE = 'temp/blitz.apk';
const APK_FILE = argv
.find((argument) => argument.startsWith('--file'))
?.split('=')[1];
const STRINGS = 'assets/Data/Strings';
const LANGUAGE = 'en';
const DIRECTORIES_OF_INTEREST = [VEHICLE_DEFS, STRINGS];
const TANK_PARAMETERS = 'assets/Data/3d/Tanks/Parameters';
const SMALL_ICONS = 'assets/Data/Gfx/UI/BattleScreenHUD/SmallTankIcons';
const BIG_ICONS = 'assets/Data/Gfx/UI/BigTankIcons';
const DIRECTORIES_OF_INTEREST = [
VEHICLE_DEFS,
STRINGS,
TANK_PARAMETERS,
SMALL_ICONS,
BIG_ICONS,
];
if (REWRITE) {
await rm('temp/blitz', { recursive: true, force: true });
decompress(APK_FILE, 'temp/blitz', {
filter: (file) =>
DIRECTORIES_OF_INTEREST.some((dir) => file.path.startsWith(dir)),
});
}
if (!APK_FILE) throw new Error('No file specified');
// console.log('Removing old Blitz files...');
// await rm('temp/blitz', { recursive: true, force: true });
await rm('dist/tankopedia', { recursive: true, force: true });
// console.log('Extracting Blitz files...');
// await decompress(APK_FILE, 'temp/blitz', {
// filter: (file) =>
// DIRECTORIES_OF_INTEREST.some((dir) => file.path.startsWith(dir)),
// });
console.log('Creating new tankopedia folder');
await mkdir('dist/tankopedia');
interface BlitzkriegTankopedia {
id: number;
@@ -37,7 +55,7 @@ const strings = await readFile(
const tankopedia: Record<number, BlitzkriegTankopedia> = {};
const nations = await readdir(`temp/blitz/${VEHICLE_DEFS}`);
await Promise.all(
Promise.all(
nations
.filter((nation) => nation !== 'common')
.map(async (nation) => {
@@ -50,10 +68,7 @@ await Promise.all(
await Promise.all(
Object.entries<ElementCompact>(list.root).map(
async ([vehicle, vehicleData]) => {
// const vehicleXML = await readFile(
// `temp/blitz/${VEHICLE_DEFS}/${nation}/${vehicle}.xml`,
// 'utf-8',
// ).then((xml) => xml2js(xml, { compact: true }) as ElementCompact);
// Tankopedia
const nationVehicleId = parseInt(list.root[vehicle].id._text);
const id = (nationVehicleId << 8) + (NATION_IDS[nation] << 4) + 1;
// TODO: use userString property instead
@@ -77,10 +92,32 @@ await Promise.all(
tier,
type,
};
// Tank images
const parameterPath = `temp/blitz/${TANK_PARAMETERS}/${nation}/${vehicle}.yaml`;
const parameterString = await readFile(parameterPath, 'utf-8');
const { smallIconPath, bigIconPath } =
parse(parameterString).resourcesPath;
cp(
`temp/blitz/assets/Data/${(smallIconPath as string)
.replace(/~res:\//, '')
.replace(/\..+/, '')}.packed.webp`,
`dist/tankopedia/icons/small/${id}.webp`,
);
cp(
`temp/blitz/assets/Data/${(bigIconPath as string)
.replace(/~res:\//, '')
.replace(/\..+/, '')}.packed.webp`,
`dist/tankopedia/icons/big/${id}.webp`,
);
},
),
);
}),
).then(() =>
writeFile(
'dist/tankopedia/tankopedia.json',
JSON.stringify(tankopedia, null, 2),
),
);
writeFile('dist/tankopedia.json', JSON.stringify(tankopedia, null, 2));
+5
View File
@@ -4640,6 +4640,11 @@ yallist@^3.0.2:
resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.1.1.tgz#dbb7daf9bfd8bac9ab45ebf602b8cbad0d5d08fd"
integrity sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==
yaml@^2.3.4:
version "2.3.4"
resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.3.4.tgz#53fc1d514be80aabf386dc6001eb29bf3b7523b2"
integrity sha512-8aAvwVUSHpfEqTQ4w/KMlf3HcRdt50E5ODIQJBw1fQ5RL34xabzxtUlzTXVqc4rkZsPbvrXKWnABCD7kWSmocA==
yauzl@^2.4.2:
version "2.10.0"
resolved "https://registry.yarnpkg.com/yauzl/-/yauzl-2.10.0.tgz#c7eb17c93e112cb1086fa6d8e51fb0667b79a5f9"