Files
blitzkit/scripts/buildAssets.ts
T

701 lines
22 KiB
TypeScript
Raw Normal View History

2023-12-23 14:28:29 -06:00
import { NodeIO } from '@gltf-transform/core';
2023-12-04 10:13:14 -06:00
import { config } from 'dotenv';
2023-12-31 19:26:08 -06:00
import { readdir, writeFile } from 'fs/promises';
2024-01-01 14:00:41 -06:00
import { parse } from 'path';
2023-12-06 10:17:42 -06:00
import { argv } from 'process';
2023-12-12 23:35:08 -06:00
import sharp from 'sharp';
2023-12-28 20:58:18 -06:00
import { Vector3Tuple } from 'three';
2023-12-05 19:14:53 -06:00
import { TankType } from '../src/components/Tanks';
2023-11-06 23:02:26 -06:00
import { NATION_IDS } from '../src/constants/nations';
2023-12-25 12:37:37 -06:00
import { extractModel } from '../src/core/blitz/extractModel';
2023-12-06 10:17:42 -06:00
import { readBase64DVPL } from '../src/core/blitz/readBase64DVPL';
2023-12-12 23:35:08 -06:00
import { readDVPLFile } from '../src/core/blitz/readDVPLFile';
import { readStringDVPL } from '../src/core/blitz/readStringDVPL';
2023-12-05 19:14:53 -06:00
import { readXMLDVPL } from '../src/core/blitz/readXMLDVPL';
import { readYAMLDVPL } from '../src/core/blitz/readYAMLDVPL';
2023-12-12 13:40:58 -06:00
import { toUniqueId } from '../src/core/blitz/toUniqueId';
2023-12-06 10:17:42 -06:00
import commitMultipleFiles, {
FileChange,
} from '../src/core/blitzkrieg/commitMultipleFiles';
2024-01-02 20:17:10 -06:00
import { ModelDefinitions } from '../src/core/blitzkrieg/modelDefinitions';
2023-12-12 15:12:09 -06:00
import {
2023-12-14 22:19:01 -06:00
GunDefinition,
2023-12-12 15:12:09 -06:00
ShellType,
2023-12-17 20:47:30 -06:00
TankDefinitionPrice,
2023-12-14 22:19:01 -06:00
TankDefinitions,
2023-12-05 17:36:18 -06:00
Tier,
2023-12-14 22:19:01 -06:00
} from '../src/core/blitzkrieg/tankDefinitions';
2023-12-04 10:13:14 -06:00
config();
2023-11-06 23:02:26 -06:00
2023-12-12 13:40:58 -06:00
// WARNING! MOST OF THESE TYPES ARE NOT EXHAUSTIVE!
2023-12-28 20:58:18 -06:00
interface VehicleCustomization {
armorColor: string;
}
2023-12-05 19:14:53 -06:00
interface VehicleDefinitionList {
[key: string]: {
id: number;
userString: string;
shortUserString?: string;
description: string;
price: number | { gold: ''; '#text': number };
sellPrice?: { gold: ''; '#text': number };
enrichmentPermanentCost: number;
notInShop?: boolean;
tags: string;
level: number;
combatRole?: Record<string, string>;
configurationModes: string;
};
}
2023-12-12 13:40:58 -06:00
interface TurretDefinitionsList {
nextAvailableId: number;
ids: Record<string, number>;
}
interface GunDefinitionsList {
nextAvailableId: number;
ids: Record<string, number>;
shared: {
[key: string]: {
userString: string;
tags: string;
level: number;
pitchLimits: string;
2023-12-12 14:14:26 -06:00
burst?: { count: number; rate: number };
clip?: { count: number; rate: number };
2023-12-12 15:12:09 -06:00
shots: {
[key: string]: {
speed: number;
piercingPower: string;
};
};
2023-12-12 13:40:58 -06:00
};
};
}
2023-12-12 15:12:09 -06:00
type ShellKind =
| 'ARMOR_PIERCING'
| 'ARMOR_PIERCING_CR'
| 'HIGH_EXPLOSIVE'
| 'HOLLOW_CHARGE';
type ShellDefinitionsList = Record<
string,
{
id: number;
userString: string;
icon: string;
kind: ShellKind;
caliber: number;
damage: { armor: number; devices: number };
normalizationAngle: number;
ricochetAngle: number;
}
> & {
icons: Record<string, string>;
};
2023-12-12 13:40:58 -06:00
interface VehicleDefinitions {
2023-12-17 20:47:30 -06:00
invisibility: { moving: number; still: number; firePenalty: number };
2023-12-31 19:26:08 -06:00
hull: {
turretPositions: {
turret: string;
};
};
2023-12-12 13:40:58 -06:00
turrets0: {
[key: string]: {
userString: number;
level: number;
yawLimits: string | string[];
2023-12-31 19:26:08 -06:00
gunPosition: string | string[];
2024-01-01 14:00:41 -06:00
models: { undamaged: string };
2023-12-12 13:40:58 -06:00
guns: {
[key: string]: {
2023-12-14 22:19:01 -06:00
reloadTime: number;
2023-12-12 13:40:58 -06:00
maxAmmo: number;
2024-01-02 20:17:10 -06:00
extraPitchLimits?: {
front?: string;
back?: string;
transition?: number | number[];
};
2023-12-12 13:40:58 -06:00
pitchLimits?: string | string[];
2023-12-14 22:19:01 -06:00
pumpGunMode?: boolean;
pumpGunReloadTimes?: string;
clip?: { count: number; rate: number };
2024-01-01 14:48:46 -06:00
models: { undamaged: string };
2023-12-12 13:40:58 -06:00
};
};
};
};
}
2023-12-05 19:14:53 -06:00
interface Strings {
[key: string]: string;
}
type BlitzTankType = 'AT-SPG' | 'lightTank' | 'mediumTank' | 'heavyTank';
2023-12-06 10:17:42 -06:00
interface TankParameters {
resourcesPath: {
smallIconPath: string;
bigIconPath: string;
2023-12-09 15:56:25 -06:00
blitzModelPath: string;
2023-12-06 10:17:42 -06:00
};
}
2023-12-05 19:14:53 -06:00
const blitzTankTypeToBlitzkrieg: Record<BlitzTankType, TankType> = {
'AT-SPG': 'tank_destroyer',
lightTank: 'light',
mediumTank: 'medium',
heavyTank: 'heavy',
};
2023-12-12 15:12:09 -06:00
const blitzShellKindToBLitzkrieg: Record<ShellKind, ShellType> = {
ARMOR_PIERCING: 'ap',
2023-12-12 23:35:08 -06:00
ARMOR_PIERCING_CR: 'ap_cr',
2023-12-12 15:12:09 -06:00
HIGH_EXPLOSIVE: 'he',
2023-12-12 23:35:08 -06:00
HOLLOW_CHARGE: 'hc',
2023-12-12 15:12:09 -06:00
};
2023-12-05 17:59:58 -06:00
const DATA =
'C:/Program Files (x86)/Steam/steamapps/common/World of Tanks Blitz/Data';
2023-11-27 17:50:02 -06:00
const LANGUAGE = 'en';
2023-12-05 19:14:53 -06:00
const DOI = {
2023-12-05 17:59:58 -06:00
vehicleDefinitions: 'XML/item_defs/vehicles',
strings: 'Strings',
tankParameters: '3d/Tanks/Parameters',
smallIcons: 'Gfx/UI/BattleScreenHUD/SmallTankIcons',
bigIcons: 'Gfx/UI/BigTankIcons',
flags: 'Gfx/Lobby/flags',
2023-12-09 15:56:25 -06:00
'3d': '3d',
2023-12-12 23:35:08 -06:00
bigShellIcons: 'Gfx/Shared/tank-supply/ammunition/big',
2023-12-14 22:19:01 -06:00
moduleIcons: 'Gfx/UI/ModulesTechTree',
2023-11-27 17:50:02 -06:00
};
2023-12-06 10:17:42 -06:00
const allTargets = argv.includes('--all-targets');
2023-12-05 19:14:53 -06:00
const targets = argv
.find((argument) => argument.startsWith('--target'))
?.split('=')[1]
.split(',');
2023-11-16 12:57:46 -06:00
2023-12-06 10:19:13 -06:00
if (!targets && !allTargets) throw new Error('No target(s) specified');
2023-12-05 17:59:58 -06:00
2023-12-12 13:40:58 -06:00
if (allTargets || targets?.includes('definitions')) {
2023-12-05 19:14:53 -06:00
console.log('Building tank definitions...');
2023-11-06 23:02:26 -06:00
2023-12-31 19:26:08 -06:00
const tankDefinitions: TankDefinitions = {};
2024-01-02 20:17:10 -06:00
const modelDefinitions: ModelDefinitions = {};
2023-12-05 19:14:53 -06:00
const nations = await readdir(`${DATA}/${DOI.vehicleDefinitions}`).then(
(nations) => nations.filter((nation) => nation !== 'common'),
);
const strings = await readYAMLDVPL<Strings>(
`${DATA}/${DOI.strings}/${LANGUAGE}.yaml.dvpl`,
2023-12-05 17:36:18 -06:00
);
2023-12-05 19:14:53 -06:00
await Promise.all(
nations.map(async (nation) => {
2023-12-12 13:40:58 -06:00
const tankList = await readXMLDVPL<{ root: VehicleDefinitionList }>(
2023-12-05 19:14:53 -06:00
`${DATA}/${DOI.vehicleDefinitions}/${nation}/list.xml.dvpl`,
);
2023-12-12 13:40:58 -06:00
const turretList = await readXMLDVPL<{
root: TurretDefinitionsList;
}>(
`${DATA}/${DOI.vehicleDefinitions}/${nation}/components/turrets.xml.dvpl`,
);
const gunList = await readXMLDVPL<{
root: GunDefinitionsList;
}>(
`${DATA}/${DOI.vehicleDefinitions}/${nation}/components/guns.xml.dvpl`,
);
2023-12-12 15:12:09 -06:00
const shellList = await readXMLDVPL<{
root: ShellDefinitionsList;
}>(
`${DATA}/${DOI.vehicleDefinitions}/${nation}/components/shells.xml.dvpl`,
);
2023-12-05 19:14:53 -06:00
2023-12-12 13:40:58 -06:00
for (const tankKey in tankList.root) {
const tank = tankList.root[tankKey];
2023-12-17 20:47:30 -06:00
const tankPrice: TankDefinitionPrice =
typeof tank.price === 'number'
? { type: 'credits', value: tank.price }
: { type: 'gold', value: tank.price['#text'] };
2023-12-12 13:40:58 -06:00
const tankDefinition = await readXMLDVPL<{ root: VehicleDefinitions }>(
`${DATA}/${DOI.vehicleDefinitions}/${nation}/${tankKey}.xml.dvpl`,
);
2023-12-31 19:26:08 -06:00
const turretOrigin = tankDefinition.root.hull.turretPositions.turret
.split(' ')
.map(Number) as Vector3Tuple;
2023-12-12 13:40:58 -06:00
const tankId = toUniqueId(nation, tank.id);
const tankTags = tank.tags.split(' ');
2024-01-02 20:17:10 -06:00
tankDefinitions[tankId] = {
id: tankId,
name:
(tank.shortUserString
? strings[tank.shortUserString]
: undefined) ??
strings[tank.userString] ??
tankKey.replaceAll('_', ' '),
nation,
tree_type: (tank.sellPrice ? 'gold' in tank.sellPrice : false)
? 'collector'
: (typeof tank.price === 'number' ? false : 'gold' in tank.price)
? 'premium'
: 'researchable',
tier: tank.level as Tier,
type: blitzTankTypeToBlitzkrieg[tankTags[0] as BlitzTankType],
testing: tankTags.includes('testTank') ? true : undefined,
price: tankPrice,
camouflage: {
still: tankDefinition.root.invisibility.still,
moving: tankDefinition.root.invisibility.moving,
firing: tankDefinition.root.invisibility.firePenalty,
},
turrets: [],
};
modelDefinitions[tankId] = {
turretOrigin,
turrets: {},
};
Object.keys(tankDefinition.root.turrets0).forEach(
(turretKey, turretIndex) => {
2023-12-12 13:40:58 -06:00
const turret = tankDefinition.root.turrets0[turretKey];
2024-01-01 14:48:46 -06:00
const turretModel = Number(
parse(turret.models.undamaged).name.split('_')[1],
);
2023-12-12 13:40:58 -06:00
const turretId = toUniqueId(nation, turretList.root.ids[turretKey]);
2023-12-17 20:47:30 -06:00
const turretYaw = (
typeof turret.yawLimits === 'string'
? turret.yawLimits
: turret.yawLimits.at(-1)!
)
.split(' ')
.map(Number) as [number, number];
2023-12-31 19:26:08 -06:00
const gunOrigin = (
typeof turret.gunPosition === 'string'
? turret.gunPosition
: turret.gunPosition[0]
)
.split(' ')
.map(Number) as Vector3Tuple;
2024-01-02 20:17:10 -06:00
tankDefinitions[tankId].turrets.push({
id: turretId,
name:
strings[turret.userString] ??
turretKey
.replaceAll('_', ' ')
.replace(/^(Turret ([0-9] )?)+/, ''),
tier: turret.level as Tier,
guns: [],
});
modelDefinitions[tankId].turrets[turretId] = {
gunOrigin,
model: turretModel,
yaw:
-turretYaw[0] + turretYaw[1] === 360
? undefined
: { min: turretYaw[0], max: turretYaw[1] },
guns: {},
};
Object.keys(turret.guns).forEach((gunKey, gunIndex) => {
2023-12-12 14:14:26 -06:00
const turretGunEntry = turret.guns[gunKey];
const gunId = toUniqueId(nation, gunList.root.ids[gunKey]);
const gun = gunList.root.shared[gunKey];
const pitchLimitsRaw =
turretGunEntry.pitchLimits ?? gun.pitchLimits;
2023-12-14 22:19:01 -06:00
const gunPitch = (
typeof pitchLimitsRaw === 'string'
? pitchLimitsRaw
: pitchLimitsRaw.at(-1)!
)
.split(' ')
.map(Number) as [number, number];
2024-01-01 14:48:46 -06:00
const gunModel = Number(
parse(turretGunEntry.models.undamaged).name.split('_')[1],
);
2023-12-14 22:19:01 -06:00
const gunName =
strings[gun.userString] ?? gunKey.replaceAll('_', ' ');
const gunType =
'clip' in turretGunEntry
? turretGunEntry.pumpGunMode
? 'auto_reloader'
: 'auto_loader'
: 'regular';
const gunReload =
gunType === 'auto_reloader'
? turretGunEntry.pumpGunReloadTimes!.split(' ').map(Number)
: turretGunEntry.reloadTime;
const gunClipCount =
gunType === 'regular' ? undefined : turretGunEntry.clip!.count;
const gunInterClip =
gunType === 'regular'
? undefined
: 60 / turretGunEntry.clip!.rate;
2024-01-02 20:17:10 -06:00
const front = turretGunEntry.extraPitchLimits?.front
? turretGunEntry.extraPitchLimits.front.split(' ').map(Number)
: undefined;
const back = turretGunEntry.extraPitchLimits?.back
? turretGunEntry.extraPitchLimits.back.split(' ').map(Number)
: undefined;
const transition = turretGunEntry.extraPitchLimits?.transition
? typeof turretGunEntry.extraPitchLimits.transition === 'number'
? turretGunEntry.extraPitchLimits.transition
: turretGunEntry.extraPitchLimits.transition.at(-1)!
: undefined;
tankDefinitions[tankId].turrets[turretIndex].guns.push({
id: gunId,
name: gunName,
tier: gun.level as Tier,
shells: [],
type: gunType,
reload: gunReload,
count: gunClipCount,
interClip: gunInterClip,
} as GunDefinition);
modelDefinitions[tankId].turrets[turretId].guns[gunId] = {
model: gunModel,
pitch: {
min: gunPitch[0],
max: gunPitch[1],
front: front
? {
min: front[0],
max: front[1],
range: front[2],
}
: undefined,
back: back
? {
min: back[0],
max: back[1],
range: back[2],
}
: undefined,
transition,
},
};
Object.keys(gun.shots).forEach((shellKey) => {
2023-12-12 15:12:09 -06:00
const turretShellEntry = gun.shots[shellKey];
const shell = shellList.root[shellKey];
const shellId = toUniqueId(nation, shell.id);
2023-12-14 22:19:01 -06:00
const shellName =
strings[shell.userString] ?? shellKey.replaceAll('_', ' ');
2023-12-12 15:12:09 -06:00
2024-01-02 20:17:10 -06:00
tankDefinitions[tankId].turrets[turretIndex].guns[
gunIndex
].shells.push({
2023-12-12 15:12:09 -06:00
id: shellId,
2023-12-14 22:19:01 -06:00
name: shellName,
2023-12-12 15:12:09 -06:00
speed: turretShellEntry.speed,
damage: {
armor: shell.damage.armor,
devices: shell.damage.devices,
},
caliber: shell.caliber,
normalization: shell.normalizationAngle,
ricochet: shell.ricochetAngle,
type: blitzShellKindToBLitzkrieg[shell.kind],
2023-12-12 23:35:08 -06:00
icon: shell.icon,
2024-01-02 20:17:10 -06:00
});
2023-12-12 15:12:09 -06:00
});
2023-12-12 14:14:26 -06:00
});
2023-12-12 13:40:58 -06:00
},
);
2023-12-05 19:14:53 -06:00
}
}),
);
2023-12-12 15:12:09 -06:00
console.log('Committing tank definitions...');
2024-01-01 14:48:46 -06:00
await commitMultipleFiles(
'tresabhi',
'blitzkrieg-assets',
'main',
'definitions',
[
{
content: JSON.stringify(tankDefinitions),
encoding: 'utf-8',
path: 'definitions/tanks.json',
},
2024-01-02 20:17:10 -06:00
{
content: JSON.stringify(modelDefinitions),
encoding: 'utf-8',
path: 'definitions/models.json',
},
2024-01-01 14:48:46 -06:00
],
true,
);
2023-12-05 19:14:53 -06:00
}
2023-12-06 10:17:42 -06:00
if (
allTargets ||
2023-12-06 10:19:13 -06:00
targets?.includes('bigTankIcons') ||
targets?.includes('smallTankIcons')
2023-12-06 10:17:42 -06:00
) {
console.log('Building tank icons...');
2023-12-05 19:14:53 -06:00
2023-12-06 10:17:42 -06:00
const changes: FileChange[] = [];
const nations = await readdir(`${DATA}/${DOI.vehicleDefinitions}`).then(
(nations) => nations.filter((nation) => nation !== 'common'),
);
2023-12-05 19:14:53 -06:00
2023-12-06 10:17:42 -06:00
await Promise.all(
nations.map(async (nation) => {
2023-12-12 13:40:58 -06:00
const tanks = await readXMLDVPL<{ root: VehicleDefinitionList }>(
2023-12-06 10:17:42 -06:00
`${DATA}/${DOI.vehicleDefinitions}/${nation}/list.xml.dvpl`,
);
2023-12-05 19:14:53 -06:00
2023-12-12 13:40:58 -06:00
for (const tankIndex in tanks.root) {
const tank = tanks.root[tankIndex];
2023-12-06 10:17:42 -06:00
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`;
2023-12-05 19:14:53 -06:00
2023-12-06 10:19:13 -06:00
if (allTargets || targets?.includes('bigTankIcons')) {
2023-12-06 10:17:42 -06:00
changes.push({
content: await readBase64DVPL(big),
encoding: 'base64',
2023-12-14 22:19:01 -06:00
path: `icons/tank/big/${id}.webp`,
2023-12-06 10:17:42 -06:00
});
}
2023-12-06 10:19:13 -06:00
if (allTargets || targets?.includes('smallTankIcons')) {
2023-12-06 10:17:42 -06:00
changes.push({
content: await readBase64DVPL(small),
encoding: 'base64',
2023-12-14 22:19:01 -06:00
path: `icons/tank/small/${id}.webp`,
2023-12-06 10:17:42 -06:00
});
}
}
}),
);
2023-12-05 19:14:53 -06:00
2023-12-06 10:17:42 -06:00
console.log('Committing tank icons...');
await commitMultipleFiles(
'tresabhi',
'blitzkrieg-assets',
'main',
'tank icons',
changes,
true,
);
}
2023-12-05 19:14:53 -06:00
2023-12-06 10:19:13 -06:00
if (allTargets || targets?.includes('scratchedFlags')) {
2023-12-06 10:17:42 -06:00
console.log('Building scratched flags...');
2023-12-05 19:14:53 -06:00
2023-12-06 10:17:42 -06:00
const flags = await readdir(`${DATA}/${DOI.flags}`);
2023-12-05 19:14:53 -06:00
2023-12-06 10:17:42 -06:00
console.log('Committing scratched flags...');
commitMultipleFiles(
'tresabhi',
'blitzkrieg-assets',
'main',
'scratched flags',
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}/${DOI.flags}/${flag}`);
const name = flag.match(/flag_tutor-tank_(.+)\.packed\.webp/)![1];
2023-12-05 19:14:53 -06:00
2023-12-06 10:17:42 -06:00
return {
content,
encoding: 'base64',
path: `flags/scratched/${name}.webp`,
} satisfies FileChange;
}),
),
true,
);
}
2023-12-05 19:14:53 -06:00
2023-12-06 10:19:13 -06:00
if (allTargets || targets?.includes('circleFlags')) {
2023-12-06 10:17:42 -06:00
const flags = await readdir(`${DATA}/${DOI.flags}`);
2023-12-05 19:14:53 -06:00
2023-12-06 10:17:42 -06:00
commitMultipleFiles(
'tresabhi',
'blitzkrieg-assets',
'main',
'circle flags',
await Promise.all(
flags
.filter(
(flag) =>
flag.startsWith('flag_profile-stat_') &&
!flag.endsWith('@2x.packed.webp.dvpl'),
)
.map(async (flag) => {
const content = await readBase64DVPL(`${DATA}/${DOI.flags}/${flag}`);
const name = flag.match(/flag_profile-stat_(.+)\.packed\.webp/)![1];
2023-12-05 19:14:53 -06:00
2023-12-06 10:17:42 -06:00
return {
content,
encoding: 'base64',
path: `flags/circle/${name}.webp`,
} satisfies FileChange;
}),
),
true,
);
}
2023-12-09 15:56:25 -06:00
if (allTargets || targets?.includes('tankModels')) {
console.log('Building tank models...');
2023-12-22 15:59:06 -06:00
// if (existsSync('dist/assets/models')) {
// await rm('dist/assets/models', { recursive: true });
// }
2023-12-09 15:56:25 -06:00
2023-12-22 15:59:06 -06:00
const nodeIO = new NodeIO();
2023-12-09 15:56:25 -06:00
const nations = await readdir(`${DATA}/${DOI.vehicleDefinitions}`).then(
(nations) => nations.filter((nation) => nation !== 'common'),
);
await Promise.all(
2023-12-09 19:05:46 -06:00
nations.map(async (nation) => {
2023-12-12 13:40:58 -06:00
const tanks = await readXMLDVPL<{ root: VehicleDefinitionList }>(
2023-12-09 15:56:25 -06:00
`${DATA}/${DOI.vehicleDefinitions}/${nation}/list.xml.dvpl`,
);
2023-12-28 20:58:18 -06:00
const customization = await readXMLDVPL<{ root: VehicleCustomization }>(
`${DATA}/${DOI.vehicleDefinitions}/${nation}/customization.xml.dvpl`,
);
const baseColor = customization.root.armorColor
.split(' ')
.slice(0, 3)
.map(Number)
.map((channel) => channel / 255) as Vector3Tuple;
2023-12-09 15:56:25 -06:00
2023-12-12 13:40:58 -06:00
for (const tankIndex in tanks.root) {
const tank = tanks.root[tankIndex];
2023-12-09 15:56:25 -06:00
const nationVehicleId = tank.id;
const id = (nationVehicleId << 8) + (NATION_IDS[nation] << 4) + 1;
2023-12-29 19:56:50 -06:00
// if (id !== 15697) continue; // chieftain TODO: investigate vertices stream over read
2024-01-03 11:56:37 -06:00
// if (id !== 24609) continue; // concept 1b
if (id !== 7425) continue; // isu 152
2023-12-25 11:21:39 -06:00
// if (id !== 4417) continue; // amx m4 mle
2023-12-25 20:50:19 -06:00
// if (id !== 7297) continue; // 60tp
2023-12-31 20:47:21 -06:00
// if (id !== 1) continue; // t-34
2023-12-30 13:02:47 -06:00
// if (id !== 6753) continue; // type 71
2024-01-02 13:31:34 -06:00
// if (id !== 5137) continue; // tiger ii
2024-01-02 20:17:10 -06:00
// if (id !== 11633) continue; // forest witch
2023-12-30 12:43:46 -06:00
// if (id !== 6225) continue; // fv215b
2023-12-29 12:41:21 -06:00
2023-12-10 17:03:01 -06:00
console.log(`Building model ${id} @ ${nation}/${tankIndex}`);
2023-12-09 15:56:25 -06:00
const parameters = await readYAMLDVPL<TankParameters>(
`${DATA}/${DOI.tankParameters}/${nation}/${tankIndex}.yaml.dvpl`,
);
2023-12-25 12:37:37 -06:00
const model = await extractModel(
2023-12-23 14:28:29 -06:00
DATA,
parameters.resourcesPath.blitzModelPath.replace(/\.sc2$/, ''),
2023-12-28 20:58:18 -06:00
baseColor,
2023-12-19 20:11:37 -06:00
);
2023-12-31 20:47:21 -06:00
writeFile(`public/test/${id}.glb`, await nodeIO.writeBinary(model));
2023-12-31 19:26:08 -06:00
// await mkdir(`dist/assets/models/${id}`, { recursive: true });
// nodeIO.write(`dist/assets/models/${id}/index.gltf`, model);
2023-12-09 15:56:25 -06:00
}
}),
);
}
2023-12-12 23:35:08 -06:00
if (allTargets || targets?.includes('shellIcons')) {
console.log('Building shell icons...');
const image = sharp(
await readDVPLFile(
`${DATA}/${DOI.bigShellIcons}/texture0.packed.webp.dvpl`,
),
);
const changes = await Promise.all(
(await readdir(`${DATA}/${DOI.bigShellIcons}`))
.filter((file) => file.endsWith('_l.txt.dvpl'))
.map(async (file) => {
const name = file.match(/(.+)_l\.txt\.dvpl/)![1];
const sizes = (
await readStringDVPL(`${DATA}/${DOI.bigShellIcons}/${file}`)
)
.split('\n')[4]
.split(' ')
.map(Number);
return {
content: (
await image
.clone()
.extract({
left: sizes[0],
top: sizes[1],
width: sizes[2],
height: sizes[3],
})
.toBuffer()
).toString('base64'),
encoding: 'base64',
2023-12-14 22:19:01 -06:00
path: `icons/shells/${name}.webp`,
2023-12-12 23:35:08 -06:00
} satisfies FileChange;
}),
);
console.log('Committing shell icons...');
commitMultipleFiles(
'tresabhi',
'blitzkrieg-assets',
'main',
'shell icons',
changes,
true,
);
}
2023-12-14 22:19:01 -06:00
if (allTargets || targets?.includes('moduleIcons')) {
console.log('Building module icons...');
const changes = await Promise.all(
(await readdir(`${DATA}/${DOI.moduleIcons}`))
.filter(
(file) =>
!file.endsWith('@2x.packed.webp.dvpl') && file.startsWith('vehicle'),
)
.map(async (file) => {
const nameRaw = file.match(/vehicle(.+)\.packed\.webp\.dvpl/)![1];
const name = nameRaw[0].toLowerCase() + nameRaw.slice(1);
const content = await readBase64DVPL(
`${DATA}/${DOI.moduleIcons}/${file}`,
);
return {
content,
path: `icons/modules/${name}.webp`,
encoding: 'base64',
} satisfies FileChange;
}),
);
console.log('Committing module icons...');
commitMultipleFiles(
'tresabhi',
'blitzkrieg-assets',
'main',
'module icons',
changes,
true,
);
}