mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 03:59:50 +02:00
feat: assets writing
This commit is contained in:
1 parent
3cf81afc4a
commit
e23f898c5f
3 files changed
+98
-33
No files matched your search
@@ -132,8 +132,8 @@ if (publish) {
|
|||||||
'main',
|
'main',
|
||||||
new Date().toString(),
|
new Date().toString(),
|
||||||
[
|
[
|
||||||
{ path: infoPath, content: infoJSON },
|
{ path: infoPath, content: infoJSON, encoding: 'utf-8' },
|
||||||
{ path: leaderboardPath, content: leaderboardJSON },
|
{ path: leaderboardPath, content: leaderboardJSON, encoding: 'utf-8' },
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+88
-29
@@ -1,15 +1,21 @@
|
|||||||
|
import { Octokit } from '@octokit/rest';
|
||||||
|
import decompress from 'decompress';
|
||||||
import { cp, mkdir, readFile, readdir, rm, writeFile } from 'fs/promises';
|
import { cp, mkdir, readFile, readdir, rm, writeFile } from 'fs/promises';
|
||||||
import { load } from 'js-yaml';
|
import { load } from 'js-yaml';
|
||||||
import { argv } from 'process';
|
import { argv, env } from 'process';
|
||||||
import { ElementCompact, xml2js } from 'xml-js';
|
import { ElementCompact, xml2js } from 'xml-js';
|
||||||
import { parse } from 'yaml';
|
import { parse } from 'yaml';
|
||||||
import { TreeTypeString } from '../src/components/Tanks';
|
import { TreeTypeString } from '../src/components/Tanks';
|
||||||
import { NATION_IDS } from '../src/constants/nations';
|
import { NATION_IDS } from '../src/constants/nations';
|
||||||
|
import commitMultipleFiles, { FileChange } from './commitMultipleFiles';
|
||||||
|
|
||||||
const VEHICLE_DEFS = 'assets/Data/XML/item_defs/vehicles';
|
const publish = argv.includes('--publish');
|
||||||
const APK_FILE = argv
|
const apkFile = argv
|
||||||
.find((argument) => argument.startsWith('--file'))
|
.find((argument) => argument.startsWith('--file'))
|
||||||
?.split('=')[1];
|
?.split('=')[1];
|
||||||
|
const noRewrite = argv.includes('--no-rewrite');
|
||||||
|
|
||||||
|
const VEHICLE_DEFS = 'assets/Data/XML/item_defs/vehicles';
|
||||||
const STRINGS = 'assets/Data/Strings';
|
const STRINGS = 'assets/Data/Strings';
|
||||||
const LANGUAGE = 'en';
|
const LANGUAGE = 'en';
|
||||||
const TANK_PARAMETERS = 'assets/Data/3d/Tanks/Parameters';
|
const TANK_PARAMETERS = 'assets/Data/3d/Tanks/Parameters';
|
||||||
@@ -23,17 +29,20 @@ const DIRECTORIES_OF_INTEREST = [
|
|||||||
BIG_ICONS,
|
BIG_ICONS,
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!APK_FILE) throw new Error('No file specified');
|
if (!apkFile) throw new Error('No file specified');
|
||||||
|
|
||||||
// console.log('Removing old Blitz files...');
|
console.log('Removing old tankopedia files...');
|
||||||
// await rm('temp/blitz', { recursive: true, force: true });
|
|
||||||
await rm('dist/tankopedia', { recursive: true, force: true });
|
await rm('dist/tankopedia', { recursive: true, force: true });
|
||||||
|
if (!noRewrite) {
|
||||||
|
console.log('Removing old temp files...');
|
||||||
|
await rm('temp/blitz', { recursive: true, force: true });
|
||||||
|
|
||||||
// console.log('Extracting Blitz files...');
|
console.log('Extracting Blitz files...');
|
||||||
// await decompress(APK_FILE, 'temp/blitz', {
|
await decompress(apkFile, 'temp/blitz', {
|
||||||
// filter: (file) =>
|
filter: (file) =>
|
||||||
// DIRECTORIES_OF_INTEREST.some((dir) => file.path.startsWith(dir)),
|
DIRECTORIES_OF_INTEREST.some((dir) => file.path.startsWith(dir)),
|
||||||
// });
|
});
|
||||||
|
}
|
||||||
|
|
||||||
console.log('Creating new tankopedia folder');
|
console.log('Creating new tankopedia folder');
|
||||||
await mkdir('dist/tankopedia');
|
await mkdir('dist/tankopedia');
|
||||||
@@ -53,6 +62,8 @@ const strings = await readFile(
|
|||||||
'utf-8',
|
'utf-8',
|
||||||
).then((data) => load(data) as Record<string, string>);
|
).then((data) => load(data) as Record<string, string>);
|
||||||
const tankopedia: Record<number, BlitzkriegTankopedia> = {};
|
const tankopedia: Record<number, BlitzkriegTankopedia> = {};
|
||||||
|
const tankIds: number[] = [];
|
||||||
|
const images: Record<number, { big: string; small: string }> = {};
|
||||||
const nations = await readdir(`temp/blitz/${VEHICLE_DEFS}`);
|
const nations = await readdir(`temp/blitz/${VEHICLE_DEFS}`);
|
||||||
|
|
||||||
Promise.all(
|
Promise.all(
|
||||||
@@ -82,6 +93,7 @@ Promise.all(
|
|||||||
const tags = vehicleData.tags._text.split(' ');
|
const tags = vehicleData.tags._text.split(' ');
|
||||||
const type = tags[0];
|
const type = tags[0];
|
||||||
|
|
||||||
|
tankIds.push(id);
|
||||||
tankopedia[id] = {
|
tankopedia[id] = {
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
@@ -101,26 +113,73 @@ Promise.all(
|
|||||||
const parameterString = await readFile(parameterPath, 'utf-8');
|
const parameterString = await readFile(parameterPath, 'utf-8');
|
||||||
const { smallIconPath, bigIconPath } =
|
const { smallIconPath, bigIconPath } =
|
||||||
parse(parameterString).resourcesPath;
|
parse(parameterString).resourcesPath;
|
||||||
|
images[id] = {
|
||||||
|
small: `temp/blitz/assets/Data/${(smallIconPath as string)
|
||||||
|
.replace(/~res:\//, '')
|
||||||
|
.replace(/\..+/, '')}.packed.webp`,
|
||||||
|
big: `temp/blitz/assets/Data/${(bigIconPath as string)
|
||||||
|
.replace(/~res:\//, '')
|
||||||
|
.replace(/\..+/, '')}.packed.webp`,
|
||||||
|
};
|
||||||
|
|
||||||
cp(
|
if (!publish) {
|
||||||
`temp/blitz/assets/Data/${(smallIconPath as string)
|
cp(images[id].small, `dist/tankopedia/icons/small/${id}.webp`);
|
||||||
.replace(/~res:\//, '')
|
cp(images[id].big, `dist/tankopedia/icons/big/${id}.webp`);
|
||||||
.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(() =>
|
).then(async () => {
|
||||||
writeFile(
|
if (publish) {
|
||||||
'dist/tankopedia/tankopedia.json',
|
const octokit = new Octokit({ auth: env.GH_TOKEN });
|
||||||
JSON.stringify(tankopedia, null, 2),
|
|
||||||
),
|
// console.log('Writing tankopedia.json');
|
||||||
);
|
// commitMultipleFiles(
|
||||||
|
// octokit,
|
||||||
|
// 'tresabhi',
|
||||||
|
// 'blitzkrieg-assets',
|
||||||
|
// 'main',
|
||||||
|
// new Date().toString(),
|
||||||
|
// [
|
||||||
|
// {
|
||||||
|
// content: JSON.stringify(tankopedia),
|
||||||
|
// path: 'tankopedia.json',
|
||||||
|
// encoding: 'utf-8',
|
||||||
|
// },
|
||||||
|
// ],
|
||||||
|
// );
|
||||||
|
|
||||||
|
console.log('Writing big icons...');
|
||||||
|
await commitMultipleFiles(
|
||||||
|
octokit,
|
||||||
|
'tresabhi',
|
||||||
|
'blitzkrieg-assets',
|
||||||
|
'main',
|
||||||
|
new Date().toString(),
|
||||||
|
(await Promise.all(
|
||||||
|
tankIds.map(async (id) => {
|
||||||
|
try {
|
||||||
|
const content = await readFile(images[id].big, {
|
||||||
|
encoding: 'base64',
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
content,
|
||||||
|
path: `icons/big/${id}.webp`,
|
||||||
|
encoding: 'base64',
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
)) as FileChange[],
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
writeFile(
|
||||||
|
'dist/tankopedia/tankopedia.json',
|
||||||
|
JSON.stringify(tankopedia, null, 2),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -1,12 +1,18 @@
|
|||||||
import { Octokit } from '@octokit/rest';
|
import { Octokit } from '@octokit/rest';
|
||||||
|
|
||||||
|
export interface FileChange {
|
||||||
|
path: string;
|
||||||
|
content: string;
|
||||||
|
encoding: 'utf-8' | 'base64';
|
||||||
|
}
|
||||||
|
|
||||||
export default async function commitMultipleFiles(
|
export default async function commitMultipleFiles(
|
||||||
octokit: Octokit,
|
octokit: Octokit,
|
||||||
owner: string,
|
owner: string,
|
||||||
repo: string,
|
repo: string,
|
||||||
branch: string,
|
branch: string,
|
||||||
message: string,
|
message: string,
|
||||||
changes: { path: string; content: string }[],
|
changes: FileChange[],
|
||||||
) {
|
) {
|
||||||
// Get the latest commit SHA on the specified branch
|
// Get the latest commit SHA on the specified branch
|
||||||
const { data: refData } = await octokit.git.getRef({
|
const { data: refData } = await octokit.git.getRef({
|
||||||
@@ -31,7 +37,7 @@ export default async function commitMultipleFiles(
|
|||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
content: change.content,
|
content: change.content,
|
||||||
encoding: 'utf-8',
|
encoding: change.encoding,
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in new issue
Block a user