feat: some type prefixes

This commit is contained in:
TrèsAbhi committed 2025-10-13 23:15:32 -05:00
1 parent dc60cffdff
commit 0d8cb5c1ae
31 files changed
+225 -222

No files matched your search

@@ -1,7 +1,7 @@
import {
Armor,
AssaultRanges,
BlitzTankClass,
type BlitzTankClass,
CamouflageDefinitions,
Consumable,
ConsumableDefinitions,
@@ -35,15 +35,15 @@ import locales from "@blitzkit/i18n/locales.json";
import { readdir } from "fs/promises";
import { deburr } from "lodash-es";
import { parse as parsePath } from "path";
import { Vector3Tuple } from "three";
import type { Vector3Tuple } from "three";
import { parse as parseYaml } from "yaml";
import { readStringDVPL } from "../core/blitz/readStringDVPL";
import { readXMLDVPL } from "../core/blitz/readXMLDVPL";
import { readYAMLDVPL } from "../core/blitz/readYAMLDVPL";
import { commitAssets } from "../core/github/commitAssets";
import { DATA } from "./constants";
import { Avatar } from "./skillIcons";
import { TankParameters } from "./tankIcons";
import type { Avatar } from "./skillIcons";
import type { TankParameters } from "./tankIcons";
const nonAlphanumericRegex = /[^a-z0-9]/g;
const multipleDashesRegex = /--+/g;
+14 -14
View File
@@ -1,10 +1,10 @@
import { TankClass } from '@blitzkit/core';
import sharp from 'sharp';
import { readDVPLFile } from '../core/blitz/readDVPLFile';
import { readXMLDVPL } from '../core/blitz/readXMLDVPL';
import { commitAssets } from '../core/github/commitAssets';
import { FileChange } from '../core/github/commitMultipleFiles';
import { DATA } from './constants';
import { TankClass } from "@blitzkit/core";
import sharp from "sharp";
import { readDVPLFile } from "../core/blitz/readDVPLFile";
import { readXMLDVPL } from "../core/blitz/readXMLDVPL";
import { commitAssets } from "../core/github/commitAssets";
import type { FileChange } from "../core/github/commitMultipleFiles";
import { DATA } from "./constants";
interface SkillIcon {
name: string;
@@ -20,22 +20,22 @@ export interface Avatar {
effectDescription: string;
tipDescription: string;
icon: SkillIcon | SkillIcon[];
type: 'continuous' | 'trigger';
type: "continuous" | "trigger";
};
};
}
export async function skillIcons() {
console.log('Building skill icons...');
console.log("Building skill icons...");
const avatar = await readXMLDVPL<{ root: Avatar }>(
`${DATA}/XML/item_defs/tankmen/avatar.xml`,
`${DATA}/XML/item_defs/tankmen/avatar.xml`
);
const changes = await Promise.all(
Object.values(avatar.root.skills).map(async (skill) => {
const icon = Array.isArray(skill.icon) ? skill.icon[0] : skill.icon;
const name = icon.name.split('/').at(-1)!.replace(/_\d$/, '');
const path = `${DATA}${icon.name.replace('~res:', '')}.packed.webp`;
const name = icon.name.split("/").at(-1)!.replace(/_\d$/, "");
const path = `${DATA}${icon.name.replace("~res:", "")}.packed.webp`;
const image = sharp(await readDVPLFile(path)).trim();
const content = await image.toBuffer();
@@ -43,8 +43,8 @@ export async function skillIcons() {
content,
path: `icons/skills/${name}.webp`,
} satisfies FileChange;
}),
})
);
commitAssets('skill icons', changes);
commitAssets("skill icons", changes);
}
+23 -23
View File
@@ -1,14 +1,14 @@
import { NATION_IDS } from '@blitzkit/core';
import { readdir } from 'fs/promises';
import sharp from 'sharp';
import { Vector3Tuple } from 'three';
import { readDVPLFile } from '../core/blitz/readDVPLFile';
import { readXMLDVPL } from '../core/blitz/readXMLDVPL';
import { readYAMLDVPL } from '../core/blitz/readYAMLDVPL';
import { commitAssets } from '../core/github/commitAssets';
import { FileChange } from '../core/github/commitMultipleFiles';
import { DATA } from './constants';
import { VehicleDefinitionList } from './definitions';
import { NATION_IDS } from "@blitzkit/core";
import { readdir } from "fs/promises";
import sharp from "sharp";
import type { Vector3Tuple } from "three";
import { readDVPLFile } from "../core/blitz/readDVPLFile";
import { readXMLDVPL } from "../core/blitz/readXMLDVPL";
import { readYAMLDVPL } from "../core/blitz/readYAMLDVPL";
import { commitAssets } from "../core/github/commitAssets";
import type { FileChange } from "../core/github/commitMultipleFiles";
import { DATA } from "./constants";
import type { VehicleDefinitionList } from "./definitions";
export interface TankParameters {
resourcesPath: {
@@ -43,35 +43,35 @@ export interface TankParameters {
}
export async function tankIcons() {
console.log('Building tank icons...');
console.log("Building tank icons...");
const changes: FileChange[] = [];
const nations = await readdir(`${DATA}/XML/item_defs/vehicles`).then(
(nations) => nations.filter((nation) => nation !== 'common'),
(nations) => nations.filter((nation) => nation !== "common")
);
await Promise.all(
nations.map(async (nation) => {
const tanks = await readXMLDVPL<{ root: VehicleDefinitionList }>(
`${DATA}/XML/item_defs/vehicles/${nation}/list.xml`,
`${DATA}/XML/item_defs/vehicles/${nation}/list.xml`
);
await Promise.all(
Object.entries(tanks.root).map(async ([tankKey, tank]) => {
if (tankKey.includes('tutorial_bot')) return;
if (tankKey.includes("tutorial_bot")) return;
const nationVehicleId = tank.id;
const id = (nationVehicleId << 8) + (NATION_IDS[nation] << 4) + 1;
const parameters = await readYAMLDVPL<TankParameters>(
`${DATA}/3d/Tanks/Parameters/${nation}/${tankKey}.yaml`,
`${DATA}/3d/Tanks/Parameters/${nation}/${tankKey}.yaml`
);
const smallPath = `${DATA}/${parameters.resourcesPath.smallIconPath
.replace(/~res:\//, '')
.replace(/\..+/, '')}.packed.webp`;
.replace(/~res:\//, "")
.replace(/\..+/, "")}.packed.webp`;
const bigPath = `${DATA}/${parameters.resourcesPath.bigIconPath
.replace(/~res:\//, '')
.replace(/\..+/, '')}.packed.webp`;
.replace(/~res:\//, "")
.replace(/\..+/, "")}.packed.webp`;
const big = await sharp(await readDVPLFile(bigPath))
.trim()
.toBuffer();
@@ -91,10 +91,10 @@ export async function tankIcons() {
path: `icons/tanks/small/${id}.webp`,
});
}
}),
})
);
}),
})
);
await commitAssets('tank icons', changes);
await commitAssets("tank icons", changes);
}
@@ -1,8 +1,8 @@
import { asset } from '@blitzkit/core';
import ProgressBar from 'progress';
import { compareUint8Arrays } from './compareUint8Arrays';
import { GithubChangeBlob, createBlob } from './createBlob';
import { octokit } from './octokit';
import { asset } from "@blitzkit/core";
import ProgressBar from "progress";
import { compareUint8Arrays } from "./compareUint8Arrays";
import { type GithubChangeBlob, createBlob } from "./createBlob";
import { octokit } from "./octokit";
export interface FileChange {
path: string;
@@ -15,33 +15,33 @@ enum DiffStatus {
Unchanged,
}
const heuristicFormats = ['glb', 'webp', 'jpg', 'png'];
const heuristicFormats = ["glb", "webp", "jpg", "png"];
export async function commitMultipleFiles(
repoRaw: string,
branch: string,
message: string,
changesRaw: FileChange[],
changesRaw: FileChange[]
) {
const changes: FileChange[] = [];
await Promise.all(
changesRaw.map(async (change) => {
const response = await fetch(asset(change.path), {
headers: { 'Accept-Encoding': 'identity' },
headers: { "Accept-Encoding": "identity" },
});
let diff: { change: number; status: DiffStatus };
if (response.status === 404) {
diff = { change: change.content.length, status: DiffStatus.New };
} else if (
response.headers.has('Content-Length') &&
Number(response.headers.get('Content-Length')) !== change.content.length
response.headers.has("Content-Length") &&
Number(response.headers.get("Content-Length")) !== change.content.length
) {
diff = {
change:
change.content.length -
Number(response.headers.get('Content-Length')),
Number(response.headers.get("Content-Length")),
status: DiffStatus.Changed,
};
} else if (response.status === 200) {
@@ -68,7 +68,7 @@ export async function commitMultipleFiles(
}
} else {
throw new Error(
`Unexpected status code ${response.status} for ${change.path}`,
`Unexpected status code ${response.status} for ${change.path}`
);
}
@@ -78,17 +78,17 @@ export async function commitMultipleFiles(
} else {
console.log(
`${
diff.status === DiffStatus.New ? '🟢' : '🟡'
} (${diff.change > 0 ? '+' : ''}${diff.change.toLocaleString()}B) ${change.path}`,
diff.status === DiffStatus.New ? "🟢" : "🟡"
} (${diff.change > 0 ? "+" : ""}${diff.change.toLocaleString()}B) ${change.path}`
);
changes.push(change);
}
}),
})
);
if (changes.length === 0) return;
const [owner, repo] = repoRaw.split('/');
const [owner, repo] = repoRaw.split("/");
const latestCommitSha = (
await octokit.git.getRef({
owner,
@@ -104,7 +104,7 @@ export async function commitMultipleFiles(
})
).data.tree.sha;
const blobs: GithubChangeBlob[] = [];
const bar = new ProgressBar('Blobs :bar', changes.length);
const bar = new ProgressBar("Blobs :bar", changes.length);
for (const change of changes) {
const createdBlob = await createBlob(owner, repo, change);
+11 -11
View File
@@ -1,12 +1,12 @@
import { throttle } from 'lodash-es';
import { FileChange } from './commitMultipleFiles';
import { octokit } from './octokit';
import { throttle } from "lodash-es";
import type { FileChange } from "./commitMultipleFiles";
import { octokit } from "./octokit";
export interface GithubChangeBlob {
sha: string;
path: string;
mode: '100644';
type: 'blob';
mode: "100644";
type: "blob";
}
const TIME_PER_BLOB = 2 ** 4 * 1000;
@@ -20,21 +20,21 @@ export const createBlob = throttle(
await octokit.git.createBlob({
owner,
repo,
content: Buffer.from(change.content).toString('base64'),
encoding: 'base64',
content: Buffer.from(change.content).toString("base64"),
encoding: "base64",
})
).data;
return {
sha,
path: change.path,
mode: '100644',
type: 'blob',
mode: "100644",
type: "blob",
} satisfies GithubChangeBlob;
} catch (error) {
console.warn(
`Failed blob ${change.path}; retrying in ${TIME_PER_BLOB}ms...`,
error,
error
);
await new Promise((resolve) => setTimeout(resolve, TIME_PER_BLOB));
@@ -42,5 +42,5 @@ export const createBlob = throttle(
}
},
(5000 / (60 * 60 * 1000)) * 0.9,
{ trailing: true },
{ trailing: true }
);