Files
blitzkit/scripts/buildAssets/definitions.ts
T

943 lines
31 KiB
TypeScript
Raw Normal View History

2024-01-07 20:07:45 -06:00
import { readdir } from 'fs/promises';
2024-01-25 12:20:34 -06:00
import { parse as parsePath } from 'path';
2023-12-28 20:58:18 -06:00
import { Vector3Tuple } from 'three';
2024-01-25 12:20:34 -06:00
import { parse as parseYaml } from 'yaml';
2024-01-07 20:07:45 -06:00
import { TankType } from '../../src/components/Tanks';
import { readXMLDVPL } from '../../src/core/blitz/readXMLDVPL';
import { readYAMLDVPL } from '../../src/core/blitz/readYAMLDVPL';
import { toUniqueId } from '../../src/core/blitz/toUniqueId';
2024-01-20 21:35:36 -06:00
import { commitAssets } from '../../src/core/blitzkrieg/commitAssets';
2024-01-25 11:50:43 -06:00
import {
ConsumableDefinitions,
2024-01-25 13:10:20 -06:00
TankFilterDefinitionCategory,
} from '../../src/core/blitzkrieg/consumableDefinitions';
2024-01-16 17:19:46 -06:00
import {
EquipmentDefinitions,
2024-01-21 22:11:01 -06:00
EquipmentPreset,
2024-01-16 17:19:46 -06:00
EquipmentRow,
} from '../../src/core/blitzkrieg/equipmentDefinitions';
2024-01-09 18:35:42 -06:00
import {
ModelArmor,
ModelDefinitions,
} from '../../src/core/blitzkrieg/modelDefinitions';
2024-01-25 13:10:20 -06:00
import { ProvisionDefinitions } from '../../src/core/blitzkrieg/provisionDefinitions';
2024-02-05 13:33:23 -06:00
import { superCompress } from '../../src/core/blitzkrieg/superCompress';
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,
2024-01-07 20:07:45 -06:00
} from '../../src/core/blitzkrieg/tankDefinitions';
2024-01-16 16:58:00 -06:00
import { DATA, POI } from './constants';
2024-01-28 20:45:50 -06:00
import { TankParameters } from './tankIcons';
2023-12-04 10:13:14 -06:00
2024-01-07 20:07:45 -06:00
type BlitzTankType = 'AT-SPG' | 'lightTank' | 'mediumTank' | 'heavyTank';
interface Strings {
[key: string]: 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;
2024-01-20 13:43:03 -06:00
explosionRadius?: number;
2023-12-12 15:12:09 -06:00
}
> & {
icons: Record<string, string>;
};
2024-01-28 19:06:38 -06:00
interface EngineDefinitionsList {
nextAvailableId: number;
ids: Record<string, number>;
shared: {
[key: string]: {
userString: string;
level: number;
fireStartingChance: number;
};
};
}
2024-01-09 18:35:42 -06:00
type VehicleDefinitionArmor = Record<
string,
number | { vehicleDamageFactor: 0; '#text': number }
>;
2023-12-12 13:40:58 -06:00
interface VehicleDefinitions {
2024-01-28 19:32:12 -06:00
invisibility: {
moving: number;
still: number;
firePenalty: number;
};
2024-02-05 12:57:03 -06:00
speedLimits: {
forward: number;
backward: number;
};
2024-01-25 12:20:34 -06:00
consumableSlots: number;
2024-01-25 13:10:20 -06:00
provisionSlots: number;
2024-01-16 16:58:00 -06:00
optDevicePreset: string;
2023-12-31 19:26:08 -06:00
hull: {
2024-01-09 18:35:42 -06:00
armor: VehicleDefinitionArmor;
2024-01-03 18:52:22 -06:00
turretPositions: { turret: string };
turretInitialRotation?: { yaw: 0; pitch: 6.5; roll: 0 };
2024-01-27 19:06:02 -06:00
maxHealth: number;
2023-12-31 19:26:08 -06:00
};
2024-01-16 08:40:27 -06:00
chassis: {
[key: string]: {
2024-02-03 15:54:21 -06:00
rotationSpeed: number;
shotDispersionFactors: {
vehicleMovement: number;
vehicleRotation: number;
};
2024-01-22 16:54:07 -06:00
hullPosition: string;
2024-01-16 08:40:27 -06:00
armor: {
leftTrack:
| number
| {
chanceToHitByProjectile: number;
chanceToHitByExplosion: number;
'#text': number;
};
rightTrack:
| number
| {
chanceToHitByProjectile: number;
chanceToHitByExplosion: number;
'#text': number;
};
};
};
};
2024-01-28 19:06:38 -06:00
engines: {
[key: string]: unknown;
};
2023-12-12 13:40:58 -06:00
turrets0: {
[key: string]: {
2024-02-03 15:54:21 -06:00
rotationSpeed: number;
2024-01-28 19:32:12 -06:00
circularVisionRadius: number;
2024-01-27 19:06:02 -06:00
maxHealth: number;
2024-01-09 18:35:42 -06:00
armor: VehicleDefinitionArmor;
2023-12-12 13:40:58 -06:00
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 };
2024-01-28 20:45:50 -06:00
hitTester: {
collisionModel: string;
};
2023-12-12 13:40:58 -06:00
guns: {
[key: string]: {
2024-01-16 08:40:27 -06:00
armor: VehicleDefinitionArmor & {
gun?:
| number
| {
chanceToHitByProjectile: number;
chanceToHitByExplosion: number;
'#text': number;
};
};
2024-01-28 19:32:12 -06:00
invisibilityFactorAtShot: number | number[];
2023-12-14 22:19:01 -06:00
reloadTime: number;
2024-02-03 15:54:21 -06:00
aimingTime?: number;
shotDispersionRadius: number;
shotDispersionFactors?: {
turretRotation: number;
afterShot: number;
whileGunDamaged: 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
};
};
};
};
}
2024-01-07 20:07:45 -06:00
export 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-05 19:14:53 -06:00
}
2024-01-07 20:07:45 -06:00
interface TurretDefinitionsList {
nextAvailableId: number;
ids: Record<string, number>;
}
interface GunDefinitionsList {
nextAvailableId: number;
ids: Record<string, number>;
shared: {
[key: string]: {
2024-02-03 16:28:33 -06:00
rotationSpeed: number;
2024-02-03 15:54:21 -06:00
shotDispersionFactors: {
turretRotation: number;
afterShot: number;
whileGunDamaged: number;
};
aimingTime: number;
2024-01-07 20:07:45 -06:00
userString: string;
tags: string;
level: number;
pitchLimits: string;
burst?: { count: number; rate: number };
clip?: { count: number; rate: number };
shots: {
[key: string]: {
speed: number;
piercingPower: string;
};
};
};
2023-12-06 10:17:42 -06:00
};
}
2023-12-05 19:14:53 -06:00
2024-01-16 16:58:00 -06:00
export interface OptionalDevices {
[key: string]: {
id: number;
userString: string;
description: string;
icon: string;
script: unknown;
display_params: unknown;
};
}
interface OptionalDeviceSlots {
presets: {
[key: string]: {
level0: OptionalDeviceSlotRow;
level1: OptionalDeviceSlotRow;
level2: OptionalDeviceSlotRow;
};
};
}
interface OptionalDeviceSlotRow {
2024-01-16 17:19:46 -06:00
[key: string]: { device0: string; device1: string };
2024-01-16 16:58:00 -06:00
}
2024-01-25 13:10:20 -06:00
export interface ConsumablesProvisionsCommon {
2024-01-16 21:49:15 -06:00
[key: string]: {
id: number;
userString: string;
description: string;
icon: string;
category: string;
tags: string;
2024-01-25 13:10:20 -06:00
vehicleFilter?: {
2024-01-25 13:51:30 -06:00
include: { vehicle: ConsumablesVehicleFilter; nations?: string };
exclude?: { vehicle: ConsumablesVehicleFilter; nations?: string };
2024-01-16 21:49:15 -06:00
};
script: {
'#text': string;
automatic?: boolean;
duration?: number;
cooldown?: number;
shotEffect?: string;
bonusValues?: { [key: string]: number };
} & Record<string, string>;
};
}
2024-01-25 13:51:30 -06:00
type ConsumablesVehicleFilter =
2024-01-16 21:49:15 -06:00
| { minLevel: number; maxLevel: number }
| { name: string }
| { extendedTags: string };
2024-01-25 13:10:20 -06:00
const consumableProvisionEffectSuffixes = [
2024-01-16 21:49:15 -06:00
'Increase',
'Factor',
'Bias',
'Coef',
'Percent',
];
2023-12-05 19:14:53 -06:00
const blitzTankTypeToBlitzkrieg: Record<BlitzTankType, TankType> = {
2024-02-03 15:54:21 -06:00
'AT-SPG': 'tankDestroyer',
2023-12-05 19:14:53 -06:00
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
};
2024-01-16 21:49:15 -06:00
const missingStrings: Record<string, string> = {
'#artefacts:tungstentip/name': 'Tungsten Shells',
};
2024-01-25 13:10:20 -06:00
export async function definitions(production: boolean) {
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 = {};
2024-01-16 17:19:46 -06:00
const equipmentDefinitions: EquipmentDefinitions = {
presets: {},
equipments: {},
};
2024-01-16 21:49:15 -06:00
const consumableDefinitions: ConsumableDefinitions = {};
2024-01-25 13:10:20 -06:00
const provisionDefinitions: ProvisionDefinitions = {};
2024-01-16 16:58:00 -06:00
const nations = await readdir(`${DATA}/${POI.vehicleDefinitions}`).then(
2023-12-05 19:14:53 -06:00
(nations) => nations.filter((nation) => nation !== 'common'),
);
2024-01-16 21:49:15 -06:00
const tankStringIdMap: Record<string, number> = {};
2024-01-28 19:06:38 -06:00
const stringsPreInstalled = await readYAMLDVPL<Strings>(
2024-01-21 16:23:44 -06:00
`${DATA}/${POI.strings}/en.yaml.dvpl`,
2023-12-05 17:36:18 -06:00
);
2024-01-25 12:20:34 -06:00
const stringsCache = await fetch(POI.cachedStrings)
.then((response) => response.text())
.then((string) => parseYaml(string) as Strings);
2024-01-16 16:58:00 -06:00
const optionalDevices = await readXMLDVPL<{ root: OptionalDevices }>(
2024-01-16 17:19:46 -06:00
`${DATA}/${POI.optionalDevices}.dvpl`,
2024-01-16 16:58:00 -06:00
);
2024-01-28 19:06:38 -06:00
const strings = {
...stringsPreInstalled,
...stringsCache,
};
2024-01-16 16:58:00 -06:00
const optionalDeviceSlots = await readXMLDVPL<{
root: OptionalDeviceSlots;
2024-01-16 17:19:46 -06:00
}>(`${DATA}/${POI.optionalDeviceSlots}.dvpl`);
2024-01-25 13:10:20 -06:00
const consumables = await readXMLDVPL<{ root: ConsumablesProvisionsCommon }>(
2024-01-17 11:34:27 -06:00
`${DATA}/${POI.consumablesCommon}.dvpl`,
2024-01-16 21:49:15 -06:00
);
2024-01-25 13:10:20 -06:00
const provisions = await readXMLDVPL<{ root: ConsumablesProvisionsCommon }>(
`${DATA}/${POI.provisionsCommon}.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 }>(
2024-01-16 16:58:00 -06:00
`${DATA}/${POI.vehicleDefinitions}/${nation}/list.xml.dvpl`,
2023-12-05 19:14:53 -06:00
);
2023-12-12 13:40:58 -06:00
const turretList = await readXMLDVPL<{
root: TurretDefinitionsList;
}>(
2024-01-16 16:58:00 -06:00
`${DATA}/${POI.vehicleDefinitions}/${nation}/components/turrets.xml.dvpl`,
2023-12-12 13:40:58 -06:00
);
const gunList = await readXMLDVPL<{
root: GunDefinitionsList;
}>(
2024-01-16 16:58:00 -06:00
`${DATA}/${POI.vehicleDefinitions}/${nation}/components/guns.xml.dvpl`,
2023-12-12 13:40:58 -06:00
);
2023-12-12 15:12:09 -06:00
const shellList = await readXMLDVPL<{
root: ShellDefinitionsList;
}>(
2024-01-16 16:58:00 -06:00
`${DATA}/${POI.vehicleDefinitions}/${nation}/components/shells.xml.dvpl`,
2023-12-12 15:12:09 -06:00
);
2024-01-28 19:06:38 -06:00
const enginesList = await readXMLDVPL<{
root: EngineDefinitionsList;
}>(
`${DATA}/${POI.vehicleDefinitions}/${nation}/components/engines.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 }>(
2024-01-16 16:58:00 -06:00
`${DATA}/${POI.vehicleDefinitions}/${nation}/${tankKey}.xml.dvpl`,
2023-12-12 13:40:58 -06:00
);
2024-01-28 20:45:50 -06:00
const tankParameters = await readYAMLDVPL<TankParameters>(
`${DATA}/${POI.tankParameters}/${nation}/${tankKey}.yaml.dvpl`,
);
2024-01-22 16:54:07 -06:00
const defaultChassis = Object.values(tankDefinition.root.chassis).at(
-1,
)!;
2023-12-31 19:26:08 -06:00
const turretOrigin = tankDefinition.root.hull.turretPositions.turret
.split(' ')
.map(Number) as Vector3Tuple;
2024-01-22 16:54:07 -06:00
const hullOrigin = defaultChassis.hullPosition
.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-09 18:35:42 -06:00
const hullArmor: ModelArmor = { thickness: {} };
2024-01-22 16:54:07 -06:00
const trackArmorRaw = defaultChassis.armor.leftTrack;
2024-01-16 16:58:00 -06:00
const equipment = tankDefinition.root.optDevicePreset;
2024-01-16 21:49:15 -06:00
tankStringIdMap[`${nation}:${tankKey}`] = tankId;
2024-01-09 18:35:42 -06:00
Object.keys(tankDefinition.root.hull.armor)
.filter((name) => name.startsWith('armor_'))
.forEach((name) => {
const armorIdString = name.match(/armor_(\d+)/)?.[1];
if (armorIdString === undefined) {
throw new SyntaxError(`Invalid armor id: ${name}`);
}
const armorId = parseInt(armorIdString);
const armorRaw = tankDefinition.root.hull.armor[name];
if (typeof armorRaw === 'number') {
hullArmor.thickness[armorId] = armorRaw;
} else {
if (!hullArmor.spaced) hullArmor.spaced = [];
hullArmor.thickness[armorId] = armorRaw['#text'];
hullArmor.spaced.push(armorId);
}
});
2024-01-02 20:17:10 -06:00
tankDefinitions[tankId] = {
2024-01-27 19:06:02 -06:00
health: tankDefinition.root.hull.maxHealth,
2024-02-05 12:57:03 -06:00
speed: {
forwards: tankDefinition.root.speedLimits.forward,
backwards: tankDefinition.root.speedLimits.backward,
},
2024-01-02 20:17:10 -06:00
id: tankId,
2024-01-16 16:58:00 -06:00
equipment,
2024-01-25 12:20:34 -06:00
consumables: tankDefinition.root.consumableSlots,
2024-01-25 13:10:20 -06:00
provisions: tankDefinition.root.provisionSlots,
2024-01-02 20:17:10 -06:00
name:
(tank.shortUserString
2024-01-28 19:06:38 -06:00
? strings[tank.shortUserString]
: undefined) ?? strings[tank.userString],
2024-02-03 15:54:21 -06:00
nameFull: strings[tank.userString],
2024-01-02 20:17:10 -06:00
nation,
2024-02-03 15:54:21 -06:00
treeType: tankTags.includes('collectible')
2024-01-02 20:17:10 -06:00
? '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,
2024-01-28 19:32:12 -06:00
onFire: tankDefinition.root.invisibility.firePenalty,
2024-01-02 20:17:10 -06:00
},
turrets: [],
2024-01-28 19:06:38 -06:00
engines: [],
2024-02-03 15:54:21 -06:00
dispersion: {
move: defaultChassis.shotDispersionFactors.vehicleMovement,
traverse: defaultChassis.shotDispersionFactors.vehicleRotation,
},
traverseSpeed: defaultChassis.rotationSpeed,
2024-01-02 20:17:10 -06:00
};
2024-02-03 15:54:21 -06:00
if (tankDefinitions[tankId].name === tankDefinitions[tankId].nameFull) {
delete tankDefinitions[tankId].nameFull;
2024-01-21 16:03:38 -06:00
}
2024-01-02 20:17:10 -06:00
modelDefinitions[tankId] = {
2024-01-09 18:35:42 -06:00
armor: hullArmor,
2024-01-16 08:40:27 -06:00
trackThickness:
typeof trackArmorRaw === 'number'
? trackArmorRaw
: trackArmorRaw['#text'],
2024-01-02 20:17:10 -06:00
turretOrigin,
2024-01-22 16:54:07 -06:00
hullOrigin,
2024-01-03 18:52:22 -06:00
turretRotation: tankDefinition.root.hull.turretInitialRotation
? {
yaw: tankDefinition.root.hull.turretInitialRotation.yaw,
pitch: tankDefinition.root.hull.turretInitialRotation.pitch,
roll: tankDefinition.root.hull.turretInitialRotation.roll,
}
: undefined,
2024-01-28 20:45:50 -06:00
boundingBox: tankParameters.collision.hull.bbox,
2024-01-02 20:17:10 -06:00
turrets: {},
};
2024-01-28 19:06:38 -06:00
Object.keys(tankDefinition.root.engines).forEach((engineKey) => {
const engine = enginesList.root.shared[engineKey];
const engineId = toUniqueId(nation, enginesList.root.ids[engineKey]);
tankDefinitions[tankId].engines.push({
id: engineId,
name: strings[engine.userString],
fire_chance: engine.fireStartingChance,
tier: engine.level as Tier,
});
});
2024-01-02 20:17:10 -06:00
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(
2024-01-25 12:20:34 -06:00
parsePath(turret.models.undamaged).name.split('_')[1],
2024-01-01 14:48:46 -06:00
);
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-09 18:35:42 -06:00
const turretArmor: ModelArmor = { thickness: {} };
Object.keys(turret.armor)
.filter((name) => name.startsWith('armor_'))
.forEach((name) => {
const armorIdString = name.match(/armor_(\d+)/)?.[1];
if (armorIdString === undefined) {
throw new SyntaxError(`Invalid armor id: ${name}`);
}
const armorId = parseInt(armorIdString);
const armorRaw = turret.armor[name];
if (typeof armorRaw === 'number') {
turretArmor.thickness[armorId] = armorRaw;
} else {
if (!turretArmor.spaced) turretArmor.spaced = [];
turretArmor.thickness[armorId] = armorRaw['#text'];
turretArmor.spaced.push(armorId);
}
});
2024-01-02 20:17:10 -06:00
tankDefinitions[tankId].turrets.push({
2024-02-03 15:54:21 -06:00
traverseSpeed: turret.rotationSpeed,
2024-01-02 20:17:10 -06:00
id: turretId,
name:
strings[turret.userString] ??
turretKey
.replaceAll('_', ' ')
.replace(/^(Turret ([0-9] )?)+/, ''),
tier: turret.level as Tier,
guns: [],
2024-01-27 19:06:02 -06:00
health: turret.maxHealth,
2024-02-03 15:54:21 -06:00
viewRange: turret.circularVisionRadius,
2024-01-02 20:17:10 -06:00
});
modelDefinitions[tankId].turrets[turretId] = {
2024-01-09 18:35:42 -06:00
armor: turretArmor,
2024-01-02 20:17:10 -06:00
gunOrigin,
model: turretModel,
yaw:
-turretYaw[0] + turretYaw[1] === 360
? undefined
: { min: turretYaw[0], max: turretYaw[1] },
guns: {},
2024-01-28 20:45:50 -06:00
boundingBox:
tankParameters.collision[
parsePath(turret.hitTester.collisionModel).name.toLowerCase()
].bbox,
2024-01-02 20:17:10 -06:00
};
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]);
2024-01-10 17:36:11 -06:00
const gunListEntry = gunList.root.shared[gunKey];
2023-12-12 14:14:26 -06:00
const pitchLimitsRaw =
2024-01-10 17:36:11 -06:00
turretGunEntry.pitchLimits ?? gunListEntry.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(
2024-01-25 12:20:34 -06:00
parsePath(turretGunEntry.models.undamaged).name.split('_')[1],
2024-01-01 14:48:46 -06:00
);
2023-12-14 22:19:01 -06:00
const gunName =
2024-01-10 17:36:11 -06:00
strings[gunListEntry.userString] ?? gunKey.replaceAll('_', ' ');
2023-12-14 22:19:01 -06:00
const gunType =
'clip' in turretGunEntry
? turretGunEntry.pumpGunMode
2024-02-06 13:07:01 -06:00
? 'autoReloader'
: 'autoLoader'
2023-12-14 22:19:01 -06:00
: 'regular';
const gunReload =
2024-02-06 13:07:01 -06:00
gunType === 'autoReloader'
2023-12-14 22:19:01 -06:00
? 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;
2024-01-09 18:35:42 -06:00
const gunArmor: ModelArmor = { thickness: {} };
2024-02-03 15:54:21 -06:00
const shotDispersionFactors =
turretGunEntry.shotDispersionFactors ??
gunListEntry.shotDispersionFactors;
2024-01-09 18:35:42 -06:00
Object.keys(turretGunEntry.armor)
.filter((name) => name.startsWith('armor_'))
.forEach((name) => {
const armorIdString = name.match(/armor_(\d+)/)?.[1];
if (armorIdString === undefined) {
throw new SyntaxError(`Invalid armor id: ${name}`);
}
const armorId = parseInt(armorIdString);
const armorRaw = turretGunEntry.armor[name];
if (typeof armorRaw === 'number') {
gunArmor.thickness[armorId] = armorRaw;
} else {
if (!gunArmor.spaced) gunArmor.spaced = [];
gunArmor.thickness[armorId] = armorRaw['#text'];
gunArmor.spaced.push(armorId);
}
});
2024-01-02 20:17:10 -06:00
tankDefinitions[tankId].turrets[turretIndex].guns.push({
id: gunId,
2024-02-03 16:28:33 -06:00
rotationSpeed: gunListEntry.rotationSpeed,
2024-01-02 20:17:10 -06:00
name: gunName,
2024-01-10 17:36:11 -06:00
tier: gunListEntry.level as Tier,
2024-01-02 20:17:10 -06:00
shells: [],
type: gunType,
reload: gunReload,
count: gunClipCount,
interClip: gunInterClip,
2024-01-28 19:32:12 -06:00
camouflageLoss:
typeof turretGunEntry.invisibilityFactorAtShot === 'number'
? turretGunEntry.invisibilityFactorAtShot
: turretGunEntry.invisibilityFactorAtShot.at(-1)!,
2024-02-03 15:54:21 -06:00
aimTime: turretGunEntry.aimingTime ?? gunListEntry.aimingTime,
dispersion: {
base: turretGunEntry.shotDispersionRadius,
damaged: shotDispersionFactors.whileGunDamaged,
shot: shotDispersionFactors.afterShot,
traverse: shotDispersionFactors.turretRotation,
},
2024-01-02 20:17:10 -06:00
} as GunDefinition);
modelDefinitions[tankId].turrets[turretId].guns[gunId] = {
2024-01-09 18:35:42 -06:00
armor: gunArmor,
2024-01-02 20:17:10 -06:00
model: gunModel,
2024-01-16 08:40:27 -06:00
barrelThickness:
turretGunEntry.armor.gun === undefined
? 0
: typeof turretGunEntry.armor.gun === 'number'
? turretGunEntry.armor.gun
: turretGunEntry.armor.gun['#text'],
2024-01-02 20:17:10 -06:00
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,
},
};
2024-01-10 17:36:11 -06:00
Object.keys(gunListEntry.shots).forEach((shellKey) => {
const gunShellEntry = gunListEntry.shots[shellKey];
2023-12-12 15:12:09 -06:00
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('_', ' ');
2024-01-10 17:36:11 -06:00
const penetrationRaw = gunShellEntry.piercingPower
.split(' ')
.filter((penetrationString) => penetrationString !== '')
.map(Number);
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,
2024-01-10 17:36:11 -06:00
speed: gunShellEntry.speed,
2023-12-12 15:12:09 -06:00
damage: {
armor: shell.damage.armor,
2024-01-27 19:06:02 -06:00
module: shell.damage.devices,
2023-12-12 15:12:09 -06:00
},
caliber: shell.caliber,
normalization: shell.normalizationAngle,
ricochet: shell.ricochetAngle,
type: blitzShellKindToBLitzkrieg[shell.kind],
explosionRadius:
shell.kind === 'HIGH_EXPLOSIVE'
? shell.explosionRadius ?? 0
: undefined,
2023-12-12 23:35:08 -06:00
icon: shell.icon,
2024-01-10 17:36:11 -06:00
penetration:
penetrationRaw[0] === penetrationRaw[1]
? penetrationRaw[0]
: [penetrationRaw[0], penetrationRaw[1]],
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
}
}),
);
2024-01-16 17:19:46 -06:00
Object.entries(optionalDevices.root).forEach(
([optionalDeviceKey, optionalDeviceEntry]) => {
if (optionalDeviceKey === 'nextAvailableId') return;
equipmentDefinitions.equipments[optionalDeviceEntry.id] = {
name: strings[optionalDeviceEntry.userString],
};
},
);
Object.entries(optionalDeviceSlots.root.presets).forEach(
([optionalDeviceSlotKey, optionalDeviceSlotEntry]) => {
if (optionalDeviceSlotKey === 'emptyPreset') return;
equipmentDefinitions.presets[optionalDeviceSlotKey] = Object.values(
optionalDeviceSlotEntry,
).map(
(level) =>
Object.values(level).map((options) => {
return [
optionalDevices.root[options.device0].id,
optionalDevices.root[options.device1].id,
];
}) as EquipmentRow,
2024-01-21 22:11:01 -06:00
) as EquipmentPreset;
2024-01-16 17:19:46 -06:00
},
);
2024-01-16 21:49:15 -06:00
Object.values(consumables.root).forEach((consumable) => {
consumableDefinitions[consumable.id] = {
id: consumable.id,
name:
strings[consumable.userString] ??
missingStrings[consumable.userString] ??
`Unknown ${consumable.id}`,
include: [],
};
2024-01-25 13:10:20 -06:00
const includeRaw = consumable.vehicleFilter?.include.vehicle;
const excludeRaw = consumable.vehicleFilter?.exclude?.vehicle;
2024-01-16 21:49:15 -06:00
2024-01-25 13:10:20 -06:00
if (includeRaw) {
if ('minLevel' in includeRaw) {
consumableDefinitions[consumable.id].include.push({
type: 'tier',
min: includeRaw.minLevel,
max: includeRaw.maxLevel,
});
} else if ('name' in includeRaw) {
consumableDefinitions[consumable.id].include.push({
type: 'ids',
ids: includeRaw.name.split(' ').map((key) => tankStringIdMap[key]),
});
} else throw new SyntaxError('Unhandled include type');
2024-01-25 13:51:30 -06:00
if (consumable.vehicleFilter?.include.nations) {
consumableDefinitions[consumable.id].include.push({
type: 'nation',
nations: consumable.vehicleFilter.include.nations.split(' '),
});
}
2024-01-25 13:10:20 -06:00
}
2024-01-16 21:49:15 -06:00
if (excludeRaw) {
consumableDefinitions[consumable.id].exclude = [];
if ('name' in excludeRaw) {
consumableDefinitions[consumable.id].exclude!.push({
type: 'ids',
ids: excludeRaw.name.split(' ').map((key) => tankStringIdMap[key]),
});
} else if ('extendedTags' in excludeRaw) {
consumableDefinitions[consumable.id].exclude!.push({
type: 'category',
2024-01-25 11:50:43 -06:00
categories: excludeRaw.extendedTags.split(
' ',
2024-01-25 13:10:20 -06:00
) as TankFilterDefinitionCategory[],
2024-01-16 21:49:15 -06:00
});
} else throw new SyntaxError('Unhandled exclude type');
2024-01-25 13:51:30 -06:00
if (consumable.vehicleFilter?.exclude?.nations) {
consumableDefinitions[consumable.id].exclude!.push({
type: 'nation',
nations: consumable.vehicleFilter.exclude.nations.split(' '),
});
}
2024-01-16 21:49:15 -06:00
}
Object.entries({
...consumable.script,
...consumable.script.bonusValues,
}).forEach(([effectName, effect]) => {
if (
2024-01-25 13:10:20 -06:00
!consumableProvisionEffectSuffixes.some((suffix) =>
effectName.endsWith(suffix),
)
2024-01-16 21:49:15 -06:00
) {
return;
}
if (!consumableDefinitions[consumable.id].effects) {
consumableDefinitions[consumable.id].effects = {};
}
consumableDefinitions[consumable.id].effects![effectName] =
effect as number;
});
});
2024-01-25 13:10:20 -06:00
Object.values(provisions.root).forEach((provision) => {
provisionDefinitions[provision.id] = {
id: provision.id,
name:
strings[provision.userString] ??
missingStrings[provision.userString] ??
`Unknown ${provision.id}`,
include: [],
};
const includeRaw = provision.vehicleFilter?.include.vehicle;
const excludeRaw = provision.vehicleFilter?.exclude?.vehicle;
if (includeRaw) {
if ('minLevel' in includeRaw) {
provisionDefinitions[provision.id].include.push({
type: 'tier',
min: includeRaw.minLevel,
max: includeRaw.maxLevel,
});
} else if ('name' in includeRaw) {
provisionDefinitions[provision.id].include.push({
type: 'ids',
ids: includeRaw.name.split(' ').map((key) => tankStringIdMap[key]),
});
} else throw new SyntaxError('Unhandled include type');
2024-01-25 13:51:30 -06:00
if (provision.vehicleFilter?.include.nations) {
provisionDefinitions[provision.id].include.push({
type: 'nation',
nations: provision.vehicleFilter.include.nations.split(' '),
});
}
2024-01-25 13:10:20 -06:00
}
if (excludeRaw) {
provisionDefinitions[provision.id].exclude = [];
if ('name' in excludeRaw) {
provisionDefinitions[provision.id].exclude!.push({
type: 'ids',
ids: excludeRaw.name.split(' ').map((key) => tankStringIdMap[key]),
});
} else if ('extendedTags' in excludeRaw) {
provisionDefinitions[provision.id].exclude!.push({
type: 'category',
categories: excludeRaw.extendedTags.split(
' ',
) as TankFilterDefinitionCategory[],
});
} else throw new SyntaxError('Unhandled exclude type');
2024-01-25 13:51:30 -06:00
if (provision.vehicleFilter?.exclude?.nations) {
provisionDefinitions[provision.id].exclude!.push({
type: 'nation',
nations: provision.vehicleFilter.exclude.nations.split(' '),
});
}
2024-01-25 13:10:20 -06:00
}
Object.entries({
...provision.script,
...provision.script.bonusValues,
}).forEach(([effectName, effect]) => {
if (
!consumableProvisionEffectSuffixes.some((suffix) =>
effectName.endsWith(suffix),
)
) {
return;
}
if (!provisionDefinitions[provision.id].effects) {
provisionDefinitions[provision.id].effects = {};
}
provisionDefinitions[provision.id].effects![effectName] =
effect as number;
});
});
2024-01-21 00:01:32 -06:00
await commitAssets(
2024-01-03 18:52:22 -06:00
'definitions',
[
{
2024-02-05 13:33:23 -06:00
content: superCompress(tankDefinitions),
encoding: 'base64',
2024-02-07 10:02:00 -06:00
path: 'definitions/tanks.cdon.lz4',
2024-01-03 18:52:22 -06:00
},
{
2024-02-05 13:33:23 -06:00
content: superCompress(modelDefinitions),
encoding: 'base64',
2024-02-07 10:02:00 -06:00
path: 'definitions/models.cdon.lz4',
2024-01-03 18:52:22 -06:00
},
2024-01-16 17:19:46 -06:00
{
2024-02-05 13:33:23 -06:00
content: superCompress(equipmentDefinitions),
encoding: 'base64',
2024-02-07 10:02:00 -06:00
path: 'definitions/equipment.cdon.lz4',
2024-01-16 17:19:46 -06:00
},
2024-01-16 21:49:15 -06:00
{
2024-02-05 13:33:23 -06:00
content: superCompress(consumableDefinitions),
encoding: 'base64',
2024-02-07 10:02:00 -06:00
path: 'definitions/consumables.cdon.lz4',
2024-01-16 21:49:15 -06:00
},
2024-01-25 13:10:20 -06:00
{
2024-02-05 13:33:23 -06:00
content: superCompress(provisionDefinitions),
encoding: 'base64',
2024-02-07 10:02:00 -06:00
path: 'definitions/provisions.cdon.lz4',
2024-01-25 13:10:20 -06:00
},
2024-01-03 18:52:22 -06:00
],
2024-01-20 21:35:36 -06:00
production,
2024-01-03 18:52:22 -06:00
);
2023-12-05 19:14:53 -06:00
}