feat: re-added rest of the asset gens

This commit is contained in:
TrèsAbhi committed 2023-12-06 10:17:42 -06:00
1 parent 9df47777d0
commit 9a44b1fcfb
9 files changed
+187 -183

No files matched your search

+1
View File
@@ -28,6 +28,7 @@
}, },
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@octokit/plugin-throttling": "^8.1.3",
"@octokit/rest": "^20.0.1", "@octokit/rest": "^20.0.1",
"@prisma/client": "^5.4.1", "@prisma/client": "^5.4.1",
"@radix-ui/colors": "^3.0.0-rc.4", "@radix-ui/colors": "^3.0.0-rc.4",
+130 -163
View File
@@ -1,12 +1,14 @@
import { Octokit } from '@octokit/rest';
import { config } from 'dotenv'; import { config } from 'dotenv';
import { readdir } from 'fs/promises'; import { readdir } from 'fs/promises';
import { argv, env } from 'process'; import { argv } from 'process';
import { TankType } from '../src/components/Tanks'; import { TankType } from '../src/components/Tanks';
import { NATION_IDS } from '../src/constants/nations'; import { NATION_IDS } from '../src/constants/nations';
import { readBase64DVPL } from '../src/core/blitz/readBase64DVPL';
import { readXMLDVPL } from '../src/core/blitz/readXMLDVPL'; import { readXMLDVPL } from '../src/core/blitz/readXMLDVPL';
import { readYAMLDVPL } from '../src/core/blitz/readYAMLDVPL'; import { readYAMLDVPL } from '../src/core/blitz/readYAMLDVPL';
import commitMultipleFiles from '../src/core/blitzkrieg/commitMultipleFiles'; import commitMultipleFiles, {
FileChange,
} from '../src/core/blitzkrieg/commitMultipleFiles';
import { import {
TankDefinitions, TankDefinitions,
Tier, Tier,
@@ -34,6 +36,15 @@ interface Strings {
[key: string]: string; [key: string]: string;
} }
type BlitzTankType = 'AT-SPG' | 'lightTank' | 'mediumTank' | 'heavyTank'; type BlitzTankType = 'AT-SPG' | 'lightTank' | 'mediumTank' | 'heavyTank';
/**
* Warning! This is not exhaustive.
*/
interface TankParameters {
resourcesPath: {
smallIconPath: string;
bigIconPath: string;
};
}
const blitzTankTypeToBlitzkrieg: Record<BlitzTankType, TankType> = { const blitzTankTypeToBlitzkrieg: Record<BlitzTankType, TankType> = {
'AT-SPG': 'tank_destroyer', 'AT-SPG': 'tank_destroyer',
@@ -53,7 +64,7 @@ const DOI = {
flags: 'Gfx/Lobby/flags', flags: 'Gfx/Lobby/flags',
}; };
const octokit = new Octokit({ auth: env.GH_TOKEN }); const allTargets = argv.includes('--all-targets');
const targets = argv const targets = argv
.find((argument) => argument.startsWith('--target')) .find((argument) => argument.startsWith('--target'))
?.split('=')[1] ?.split('=')[1]
@@ -61,7 +72,7 @@ const targets = argv
if (!targets) throw new Error('No target(s) specified'); if (!targets) throw new Error('No target(s) specified');
if (targets.includes('tankDefinitions')) { if (allTargets || targets.includes('tankDefinitions')) {
console.log('Building tank definitions...'); console.log('Building tank definitions...');
const tankDefinitions: TankDefinitions = {}; const tankDefinitions: TankDefinitions = {};
@@ -82,7 +93,7 @@ if (targets.includes('tankDefinitions')) {
const tank = tanks[tankIndex]; const tank = tanks[tankIndex];
const nationVehicleId = tank.id; const nationVehicleId = tank.id;
const id = (nationVehicleId << 8) + (NATION_IDS[nation] << 4) + 1; const id = (nationVehicleId << 8) + (NATION_IDS[nation] << 4) + 1;
const name = strings[tank.userString]; const name = strings[tank.userString] ?? tankIndex;
const name_short = tank.shortUserString const name_short = tank.shortUserString
? strings[tank.shortUserString] === name ? strings[tank.shortUserString] === name
? undefined ? undefined
@@ -94,13 +105,13 @@ if (targets.includes('tankDefinitions')) {
const tier = tank.level as Tier; const tier = tank.level as Tier;
const tags = tank.tags.split(' '); const tags = tank.tags.split(' ');
const type = blitzTankTypeToBlitzkrieg[tags[0] as BlitzTankType]; const type = blitzTankTypeToBlitzkrieg[tags[0] as BlitzTankType];
const testing = tags.includes('testTank') ? true : undefined;
if ((name ?? name_short) === undefined) { if ((name ?? name_short) === undefined) {
console.warn(`Missing name for ${tankIndex}`); console.warn(`Missing name for ${tankIndex}`);
} }
tankDefinitions[id] = { tankDefinitions[id] = {
id,
name, name,
name_short, name_short,
nation, nation,
@@ -111,6 +122,7 @@ if (targets.includes('tankDefinitions')) {
: 'researchable', : 'researchable',
tier, tier,
type, type,
testing,
}; };
} }
}), }),
@@ -118,7 +130,6 @@ if (targets.includes('tankDefinitions')) {
console.log('Committing tank definitions...'); console.log('Committing tank definitions...');
await commitMultipleFiles( await commitMultipleFiles(
octokit,
'tresabhi', 'tresabhi',
'blitzkrieg-assets', 'blitzkrieg-assets',
'main', 'main',
@@ -134,170 +145,126 @@ if (targets.includes('tankDefinitions')) {
); );
} }
// console.log( if (
// ( allTargets ||
// await readDVPL( targets.includes('bigTankIcons') ||
// `${DATA}/${DOI.strings}/${LANGUAGE}.yaml.dvpl`, targets.includes('smallTankIcons')
// ) ) {
// ).toString(), console.log('Building tank icons...');
// );
// const strings = await readFile( const changes: FileChange[] = [];
// `${DATA}/${DOI.strings}/${LANGUAGE}.yaml.dvpl`, const nations = await readdir(`${DATA}/${DOI.vehicleDefinitions}`).then(
// 'utf-8', (nations) => nations.filter((nation) => nation !== 'common'),
// ).then((data) => load(data) as Record<string, string>); );
// const tankDefinitions: TankDefinitions = {}; await Promise.all(
// const tankIds: number[] = []; nations.map(async (nation) => {
// const images: Record<number, { big: string; small: string }> = {}; const tanks = await readXMLDVPL<VehicleDefinitionList>(
// const nations = await readdir( `${DATA}/${DOI.vehicleDefinitions}/${nation}/list.xml.dvpl`,
// `${TEMP}/${DOI.vehicleDefinitions}`, );
// );
// writeFileSync('test.json', JSON.stringify(strings, null, 2)); for (const tankIndex in tanks) {
const tank = tanks[tankIndex];
const nationVehicleId = tank.id;
const id = (nationVehicleId << 8) + (NATION_IDS[nation] << 4) + 1;
const parameters = await readYAMLDVPL<TankParameters>(
`${DATA}/${DOI.tankParameters}/${nation}/${tankIndex}.yaml.dvpl`,
);
const small = `${DATA}/${parameters.resourcesPath.smallIconPath
.replace(/~res:\//, '')
.replace(/\..+/, '')}.packed.webp.dvpl`;
const big = `${DATA}/${parameters.resourcesPath.bigIconPath
.replace(/~res:\//, '')
.replace(/\..+/, '')}.packed.webp.dvpl`;
// Promise.all( if (targets.includes('bigTankIcons')) {
// nations changes.push({
// .filter((nation) => nation !== 'common') content: await readBase64DVPL(big),
// .map(async (nation) => { encoding: 'base64',
// const listXML = await readFile( path: `icons/big/${id}.webp`,
// `${TEMP}/${DOI.vehicleDefinitions}/${nation}/list.xml`, });
// 'utf-8', }
// ); if (targets.includes('smallTankIcons')) {
// const list = xml2js(listXML, { compact: true }) as ElementCompact; changes.push({
content: await readBase64DVPL(small),
encoding: 'base64',
path: `icons/small/${id}.webp`,
});
}
}
}),
);
// await Promise.all( console.log('Committing tank icons...');
// Object.entries<ElementCompact>(list.root).map( await commitMultipleFiles(
// async ([vehicle, vehicleData]) => { 'tresabhi',
// const nationVehicleId = parseInt(list.root[vehicle].id._text); 'blitzkrieg-assets',
// const id = (nationVehicleId << 8) + (NATION_IDS[nation] << 4) + 1; 'main',
// const name = strings[vehicleData.userString._text]; 'tank icons',
// const name_short = strings[vehicleData.shortUserString?._text]; changes,
// const isPremium = 'gold' in vehicleData.price; true,
// const isCollector = vehicleData.sellPrice );
// ? 'gold' in vehicleData.sellPrice }
// : false;
// const tier = parseInt(vehicleData.level._text) as Tier;
// const tags = vehicleData.tags._text.split(' ');
// const type = tags[0];
// if ((name ?? name_short) === undefined) { if (allTargets || targets.includes('scratchedFlags')) {
// console.warn(`Missing name for ${vehicle}`); console.log('Building scratched flags...');
// }
// tankIds.push(id); const flags = await readdir(`${DATA}/${DOI.flags}`);
// tankDefinitions[id] = {
// id,
// name,
// name_short,
// nation,
// tree_type: isCollector
// ? 'collector'
// : isPremium
// ? 'premium'
// : 'researchable',
// tier,
// type,
// };
// // Tank images console.log('Committing scratched flags...');
// const parameterPath = `${TEMP}/${DOI.tankParameters}/${nation}/${vehicle}.yaml`; commitMultipleFiles(
// const parameterString = await readFile(parameterPath, 'utf-8'); 'tresabhi',
// const { smallIconPath, bigIconPath } = 'blitzkrieg-assets',
// parse(parameterString).resourcesPath; 'main',
// images[id] = { 'scratched flags',
// small: `${TEMP}/assets/Data/${(smallIconPath as string) await Promise.all(
// .replace(/~res:\//, '') flags
// .replace(/\..+/, '')}.packed.webp`, .filter(
// big: `${TEMP}/assets/Data/${(bigIconPath as string) (flag) =>
// .replace(/~res:\//, '') flag.startsWith('flag_tutor-tank_') &&
// .replace(/\..+/, '')}.packed.webp`, !flag.endsWith('@2x.packed.webp.dvpl'),
// }; )
// }, .map(async (flag) => {
// ), const content = await readBase64DVPL(`${DATA}/${DOI.flags}/${flag}`);
// ); const name = flag.match(/flag_tutor-tank_(.+)\.packed\.webp/)![1];
// }),
// ).then(async () => {
// if (!publish) return;
// const octokit = new Octokit({ auth: env.GH_TOKEN }); return {
// // const tankDefinitionsChange: FileChange = { content,
// // content: JSON.stringify(tankDefinitions), encoding: 'base64',
// // path: 'definitions/tanks.json', path: `flags/scratched/${name}.webp`,
// // encoding: 'utf-8', } satisfies FileChange;
// // }; }),
// // const iconsChange = ( ),
// // await Promise.all( true,
// // tankIds.map(async (id) => { );
// // try { }
// // const [contentSmall, contentBig] = await Promise.all([
// // readFile(images[id].small, { encoding: 'base64' }),
// // readFile(images[id].big, { encoding: 'base64' }),
// // ]);
// // return [ if (allTargets || targets.includes('circleFlags')) {
// // { const flags = await readdir(`${DATA}/${DOI.flags}`);
// // content: contentBig,
// // path: `icons/big/${id}.webp`,
// // encoding: 'base64',
// // },
// // {
// // content: contentSmall,
// // path: `icons/small/${id}.webp`,
// // encoding: 'base64',
// // },
// // ];
// // } catch (error) {
// // console.log(error);
// // return undefined;
// // }
// // }),
// // )
// // ).flat() as FileChange[];
// const flags = await readdir(`${TEMP}/${DOI.flags}`);
// // const scratchedFlags = await Promise.all(
// // flags
// // .filter((flag) => flag.startsWith('flag_tutor-tank_'))
// // .map(async (flag) => {
// // const content = await readFile(
// // `${TEMP}/${DOI.flags}/${flag}`,
// // { encoding: 'base64' },
// // );
// // const name = flag.match(/flag_tutor-tank_(.+)\.packed\.webp/)![1];
// // return { commitMultipleFiles(
// // content, 'tresabhi',
// // encoding: 'base64', 'blitzkrieg-assets',
// // path: `flags/scratched/${name}.webp`, 'main',
// // } satisfies FileChange; 'circle flags',
// // }), await Promise.all(
// // ); flags
// const circleFlags = await Promise.all( .filter(
// flags (flag) =>
// .filter((flag) => flag.startsWith('flag_profile-stat_')) flag.startsWith('flag_profile-stat_') &&
// .map(async (flag) => { !flag.endsWith('@2x.packed.webp.dvpl'),
// const content = await readFile( )
// `${TEMP}/${DOI.flags}/${flag}`, .map(async (flag) => {
// { encoding: 'base64' }, const content = await readBase64DVPL(`${DATA}/${DOI.flags}/${flag}`);
// ); const name = flag.match(/flag_profile-stat_(.+)\.packed\.webp/)![1];
// const name = flag.match(/flag_profile-stat_(.+)\.packed\.webp/)![1];
// return { return {
// content, content,
// encoding: 'base64', encoding: 'base64',
// path: `flags/circle/${name}.webp`, path: `flags/circle/${name}.webp`,
// } satisfies FileChange; } satisfies FileChange;
// }), }),
// ); ),
true,
// console.log('Writing files...'); );
// await commitMultipleFiles( }
// octokit,
// 'tresabhi',
// 'blitzkrieg-assets',
// 'main',
// new Date().toString(),
// circleFlags,
// true,
// );
// });
+10 -12
View File
@@ -142,18 +142,16 @@ export default function Page() {
display: 'flex', display: 'flex',
}} }}
> >
{tank.nation !== 'other' && ( <img
<img className={styles.flag}
className={styles.flag} src={asset(`flags/scratched/${tank.nation}.webp`)}
src={asset(`flags/scratched/${tank.nation}.webp`)} style={{
style={{ width: '100%',
width: '100%', height: '100%',
height: '100%', objectFit: 'contain',
objectFit: 'contain', position: 'absolute',
position: 'absolute', }}
}} />
/>
)}
<div <div
style={{ style={{
+6
View File
@@ -0,0 +1,6 @@
import { readDVPL } from './readDVPL';
export async function readBase64DVPL(file: string) {
const buffer = await readDVPL(file);
return buffer.toString('base64');
}
+1 -3
View File
@@ -1,4 +1,4 @@
import { Octokit } from '@octokit/rest'; import { octokit } from './octokit';
const TIME_PER_BLOB = 2 ** 4 * 1000; const TIME_PER_BLOB = 2 ** 4 * 1000;
@@ -9,7 +9,6 @@ export interface FileChange {
} }
export default async function commitMultipleFiles( export default async function commitMultipleFiles(
octokit: Octokit,
owner: string, owner: string,
repo: string, repo: string,
branch: string, branch: string,
@@ -61,7 +60,6 @@ export default async function commitMultipleFiles(
`Failed blob ${changeIndex + 1} / ${ `Failed blob ${changeIndex + 1} / ${
changes.length changes.length
}; retrying in ${TIME_PER_BLOB}ms...`, }; retrying in ${TIME_PER_BLOB}ms...`,
error,
); );
await new Promise((resolve) => setTimeout(resolve, TIME_PER_BLOB)); await new Promise((resolve) => setTimeout(resolve, TIME_PER_BLOB));
+1 -1
View File
@@ -3,13 +3,13 @@ import { TankType, TreeTypeString } from '../../../components/Tanks';
import { asset } from '../asset'; import { asset } from '../asset';
export interface TankDefinition { export interface TankDefinition {
id: number;
nation: string; nation: string;
name: string; name: string;
name_short?: string; name_short?: string;
tree_type: TreeTypeString; tree_type: TreeTypeString;
tier: Tier; tier: Tier;
type: TankType; type: TankType;
testing?: boolean;
} }
export type TankDefinitions = Record<number, TankDefinition>; export type TankDefinitions = Record<number, TankDefinition>;
+3
View File
@@ -1,4 +1,7 @@
import { throttling } from '@octokit/plugin-throttling';
import { Octokit } from '@octokit/rest'; import { Octokit } from '@octokit/rest';
import { secrets } from './secrets'; import { secrets } from './secrets';
Octokit.plugin(throttling);
export const octokit = new Octokit({ auth: secrets.GH_TOKEN }); export const octokit = new Octokit({ auth: secrets.GH_TOKEN });
+14 -3
View File
@@ -10,7 +10,11 @@
"noEmit": true, "noEmit": true,
"resolveJsonModule": true, "resolveJsonModule": true,
"jsx": "preserve", "jsx": "preserve",
"lib": ["dom", "dom.iterable", "esnext"], "lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true, "allowJs": true,
"incremental": true, "incremental": true,
"isolatedModules": true, "isolatedModules": true,
@@ -20,6 +24,13 @@
} }
] ]
}, },
"include": ["src/**/*", "scripts/**/*"], "include": [
"exclude": ["node_modules", "dist"] "src/**/*",
"scripts/**/*",
"dist/website/types/**/*.ts"
],
"exclude": [
"node_modules",
"dist"
]
} }
+21 -1
View File
@@ -984,7 +984,7 @@
"@octokit/types" "^12.0.0" "@octokit/types" "^12.0.0"
universal-user-agent "^6.0.0" universal-user-agent "^6.0.0"
"@octokit/openapi-types@^19.0.2": "@octokit/openapi-types@^19.0.2", "@octokit/openapi-types@^19.1.0":
version "19.1.0" version "19.1.0"
resolved "https://registry.yarnpkg.com/@octokit/openapi-types/-/openapi-types-19.1.0.tgz#75ec7e64743870fc73e1ab4bc6ec252ecdd624dc" resolved "https://registry.yarnpkg.com/@octokit/openapi-types/-/openapi-types-19.1.0.tgz#75ec7e64743870fc73e1ab4bc6ec252ecdd624dc"
integrity sha512-6G+ywGClliGQwRsjvqVYpklIfa7oRPA0vyhPQG/1Feh+B+wU0vGH1JiJ5T25d3g1JZYBHzR2qefLi9x8Gt+cpw== integrity sha512-6G+ywGClliGQwRsjvqVYpklIfa7oRPA0vyhPQG/1Feh+B+wU0vGH1JiJ5T25d3g1JZYBHzR2qefLi9x8Gt+cpw==
@@ -1008,6 +1008,14 @@
dependencies: dependencies:
"@octokit/types" "^12.3.0" "@octokit/types" "^12.3.0"
"@octokit/plugin-throttling@^8.1.3":
version "8.1.3"
resolved "https://registry.yarnpkg.com/@octokit/plugin-throttling/-/plugin-throttling-8.1.3.tgz#7fb0e001c0cb9383c6be07740b8ec326ed990f6b"
integrity sha512-pfyqaqpc0EXh5Cn4HX9lWYsZ4gGbjnSmUILeu4u2gnuM50K/wIk9s1Pxt3lVeVwekmITgN/nJdoh43Ka+vye8A==
dependencies:
"@octokit/types" "^12.2.0"
bottleneck "^2.15.3"
"@octokit/request-error@^5.0.0": "@octokit/request-error@^5.0.0":
version "5.0.1" version "5.0.1"
resolved "https://registry.yarnpkg.com/@octokit/request-error/-/request-error-5.0.1.tgz#277e3ce3b540b41525e07ba24c5ef5e868a72db9" resolved "https://registry.yarnpkg.com/@octokit/request-error/-/request-error-5.0.1.tgz#277e3ce3b540b41525e07ba24c5ef5e868a72db9"
@@ -1044,6 +1052,13 @@
dependencies: dependencies:
"@octokit/openapi-types" "^19.0.2" "@octokit/openapi-types" "^19.0.2"
"@octokit/types@^12.2.0":
version "12.4.0"
resolved "https://registry.yarnpkg.com/@octokit/types/-/types-12.4.0.tgz#8f97b601e91ce6b9776ed8152217e77a71be7aac"
integrity sha512-FLWs/AvZllw/AGVs+nJ+ELCDZZJk+kY0zMen118xhL2zD0s1etIUHm1odgjP7epxYU1ln7SZxEUWYop5bhsdgQ==
dependencies:
"@octokit/openapi-types" "^19.1.0"
"@pkgjs/[email protected]", "@pkgjs/parseargs@^0.11.0": "@pkgjs/[email protected]", "@pkgjs/parseargs@^0.11.0":
version "0.11.0" version "0.11.0"
resolved "https://registry.yarnpkg.com/@pkgjs/parseargs/-/parseargs-0.11.0.tgz#a77ea742fab25775145434eb1d2328cf5013ac33" resolved "https://registry.yarnpkg.com/@pkgjs/parseargs/-/parseargs-0.11.0.tgz#a77ea742fab25775145434eb1d2328cf5013ac33"
@@ -2532,6 +2547,11 @@ bole@^5.0.0:
fast-safe-stringify "^2.0.7" fast-safe-stringify "^2.0.7"
individual "^3.0.0" individual "^3.0.0"
bottleneck@^2.15.3:
version "2.19.5"
resolved "https://registry.yarnpkg.com/bottleneck/-/bottleneck-2.19.5.tgz#5df0b90f59fd47656ebe63c78a98419205cadd91"
integrity sha512-VHiNCbI1lKdl44tGrhNfU3lup0Tj/ZBMJB5/2ZbNXRCPuRCO7ed2mgcK4r17y+KB2EfuYuRaVlwNbAeaWGSpbw==
brace-expansion@^1.1.7: brace-expansion@^1.1.7:
version "1.1.11" version "1.1.11"
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"