Files
blitzkit/scripts/buildAssets/definitions.ts
T

1510 lines
48 KiB
TypeScript
Raw Normal View History

2024-03-31 18:24:19 -05: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-03-07 18:30:02 -06:00
import { TankClass } from '../../src/components/Tanks';
2024-05-03 12:02:56 -05:00
import { WARGAMING_APPLICATION_ID } from '../../src/constants/wargamingApplicationID';
2024-04-06 11:14:07 -05:00
import { readStringDVPL } from '../../src/core/blitz/readStringDVPL';
2024-01-07 20:07:45 -06:00
import { readXMLDVPL } from '../../src/core/blitz/readXMLDVPL';
import { readYAMLDVPL } from '../../src/core/blitz/readYAMLDVPL';
import { toUniqueId } from '../../src/core/blitz/toUniqueId';
2024-08-13 19:38:05 -05:00
import { CamouflageDefinitions } from '../../src/core/blitzkit/camouflageDefinitions';
2024-04-23 09:57:59 -05:00
import { commitAssets } from '../../src/core/blitzkit/commitAssets';
2024-01-25 11:50:43 -06:00
import {
ConsumableDefinitions,
2024-08-16 13:48:23 -05:00
ConsumableEntry,
2024-01-25 13:10:20 -06:00
TankFilterDefinitionCategory,
2024-04-23 09:57:59 -05:00
} from '../../src/core/blitzkit/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,
2024-04-23 09:57:59 -05:00
} from '../../src/core/blitzkit/equipmentDefinitions';
import { GameDefinitions } from '../../src/core/blitzkit/gameDefinitions';
2024-04-27 10:50:09 -05:00
import { MapDefinitions } from '../../src/core/blitzkit/mapDefinitions';
2024-01-09 18:35:42 -06:00
import {
ModelArmor,
ModelDefinitions,
2024-04-23 09:57:59 -05:00
} from '../../src/core/blitzkit/modelDefinitions';
2024-08-16 13:48:23 -05:00
import {
ProvisionDefinitions,
ProvisionEntry,
} from '../../src/core/blitzkit/provisionDefinitions';
2024-04-23 09:57:59 -05:00
import { SkillDefinitions } from '../../src/core/blitzkit/skillDefinitions';
import { superCompress } from '../../src/core/blitzkit/superCompress';
2023-12-12 15:12:09 -06:00
import {
2024-02-16 21:07:48 -06:00
Crew,
2024-02-16 10:20:20 -06:00
CrewMember,
2023-12-14 22:19:01 -06:00
GunDefinition,
2023-12-12 15:12:09 -06:00
ShellType,
2023-12-14 22:19:01 -06:00
TankDefinitions,
2024-08-20 11:51:05 -05:00
TankPrice,
2023-12-05 17:36:18 -06:00
Tier,
2024-05-04 12:05:37 -05:00
Unlock,
2024-04-23 09:57:59 -05:00
} from '../../src/core/blitzkit/tankDefinitions';
2024-08-14 14:04:06 -05:00
import { DATA } from './constants';
2024-03-31 18:24:19 -05:00
import { Avatar } from './skillIcons';
2024-01-28 20:45:50 -06:00
import { TankParameters } from './tankIcons';
2023-12-04 10:13:14 -06:00
2024-04-21 19:40:38 -05:00
export interface BlitzStrings {
2024-01-07 20:07:45 -06:00
[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-02-08 10:58:03 -06:00
weight: number;
power: number;
2024-01-28 19:06:38 -06:00
};
};
}
2024-02-08 10:58:03 -06:00
export interface ChassisDefinitionsList {
nextAvailableId: number;
ids: Record<string, number>;
}
2024-01-09 18:35:42 -06:00
type VehicleDefinitionArmor = Record<
string,
number | { vehicleDamageFactor: 0; '#text': number }
>;
2024-03-13 23:23:06 -05:00
interface UnlocksInner {
2024-05-04 12:05:37 -05:00
cost: number | string;
2024-03-13 23:23:06 -05:00
'#text': number;
}
type Unlocks = {
[key in 'vehicle' | 'engine' | 'chassis' | 'turret' | 'gun']:
| UnlocksInner
| UnlocksInner[];
};
type UnlocksListing = Unlocks | undefined;
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-16 10:20:20 -06:00
crew: Record<CrewMember, string | string[]>;
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-03-13 18:50:08 -05:00
optDevicePreset: string | 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;
2024-02-08 10:58:03 -06:00
weight: number;
2023-12-31 19:26:08 -06:00
};
2024-01-16 08:40:27 -06:00
chassis: {
[key: string]: {
2024-03-13 23:23:06 -05:00
unlocks: UnlocksListing;
2024-02-08 10:58:03 -06:00
weight: number;
terrainResistance: string;
2024-02-03 15:54:21 -06:00
rotationSpeed: number;
2024-04-01 19:05:55 -05:00
userString: string;
2024-02-03 15:54:21 -06:00
shotDispersionFactors: {
vehicleMovement: number;
vehicleRotation: number;
};
2024-02-08 11:09:33 -06:00
level: 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: {
2024-03-13 23:23:06 -05:00
[key: string]: {
unlocks: UnlocksListing;
};
2024-01-28 19:06:38 -06:00
};
2023-12-12 13:40:58 -06:00
turrets0: {
[key: string]: {
2024-03-13 23:23:06 -05:00
unlocks: UnlocksListing;
2024-02-03 15:54:21 -06:00
rotationSpeed: number;
2024-02-08 10:58:03 -06:00
weight: 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-03-13 23:23:06 -05:00
unlocks: UnlocksListing;
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-08 10:58:03 -06:00
weight: number;
2024-02-03 15:54:21 -06:00
shotDispersionFactors: {
turretRotation: number;
afterShot: number;
whileGunDamaged: number;
};
aimingTime: number;
2024-02-16 09:48:57 -06:00
shotDispersionRadius: 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-02-13 09:40:00 -06:00
export interface ConsumablesCommon {
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;
2024-02-13 09:40:00 -06:00
cooldown: number;
2024-01-16 21:49:15 -06:00
duration?: number;
2024-02-13 09:40:00 -06:00
shotEffect?: string;
bonusValues?: { [key: string]: number };
} & Record<string, string>;
};
}
export interface ProvisionsCommon {
[key: string]: {
id: number;
userString: string;
description: string;
icon: string;
category: string;
tags: string;
vehicleFilter?: {
include: { vehicle: ConsumablesVehicleFilter; nations?: string };
exclude?: { vehicle: ConsumablesVehicleFilter; nations?: string };
};
script: {
'#text': string;
automatic?: boolean;
2024-01-16 21:49:15 -06:00
shotEffect?: string;
bonusValues?: { [key: string]: number };
} & Record<string, string>;
};
}
2024-08-13 19:38:05 -05:00
type CamouflagesInclude =
| {
nations?: string;
}
| {
vehicle?: { name?: string; minLevel?: number; maxLevel?: number };
};
interface CamouflagesXML {
camouflages: Record<
string,
{
id: number;
userString: string;
description: string;
category: string;
group: string;
kind: string;
notInShop: boolean;
unlockCostCategory?: string;
vehicleFilter: {
include?: CamouflagesInclude | CamouflagesInclude[];
};
script: string[] | string;
icon?: string;
unlockPremium?: string;
unlockQuest?: string;
unlockClanLevel?: number;
unlockShopBundle?: string;
unlockTankRank?: number;
}
>;
}
type CamouflagesYaml = Record<
string,
{
userString?: string;
shortUserString?: 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-04-27 10:50:09 -05:00
export interface Maps {
maps: {
[key: string]: {
id: number;
tags?: string;
localName: string;
avaliableInTrainingRoom: boolean; // lol wg typo
spriteFrame: number;
supremacyPointsThreshold?: number;
availableModes: number[];
shadowMapsAvailable?: boolean;
assaultRespawnPoints: {
allies: MapAlly[];
enemies: MapAlly[];
};
levels?: number[];
};
};
}
export interface MapAlly {
respawnNumber: number;
points: Array<number[]>;
}
2024-06-19 20:53:59 -05:00
interface AvailableNationsYaml {
available_nations: string[];
}
2024-08-15 21:08:02 -05:00
export interface SquadBattleTypeStyles {
2024-08-15 13:35:09 -05:00
Prototypes: {
components: {
UIDataLocalBindingsComponent: {
data: [string, string, string][];
};
};
}[];
}
2024-08-16 13:05:27 -05:00
type CombatRolesYaml = Record<
string,
{
id: number;
default_abilities: string[];
}
>;
2024-04-23 10:19:32 -05:00
const blitzShellKindToBlitzkit: Record<ShellKind, ShellType> = {
2024-06-19 20:53:59 -05:00
ARMOR_PIERCING: ShellType.AP,
ARMOR_PIERCING_CR: ShellType.APCR,
HIGH_EXPLOSIVE: ShellType.HE,
HOLLOW_CHARGE: ShellType.HEAT,
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-04-21 19:40:38 -05:00
export const botPattern = /^.+((tutorial_bot(\d+)?)|(TU(R?)))$/;
2024-01-16 21:49:15 -06:00
2024-08-27 14:40:43 -05:00
export async function definitions() {
2024-02-11 14:17:41 -06:00
console.log('Building definitions...');
2023-11-06 23:02:26 -06:00
2024-05-03 12:02:56 -05:00
const wargamingTankopedia = (await fetch(
`https://api.wotblitz.com/wotb/encyclopedia/vehicles/?application_id=${WARGAMING_APPLICATION_ID}&fields=description`,
).then((response) => response.json())) as {
data: { [key: number]: { description: null | string } };
};
2024-08-14 20:46:55 -05:00
2024-04-06 11:14:07 -05:00
const gameDefinitions: GameDefinitions = {
version: (await readStringDVPL(`${DATA}/version.txt.dvpl`))
.split(' ')[0]
.split('.')
.slice(0, 3)
.join('.'),
2024-06-19 20:53:59 -05:00
nations: (
await readYAMLDVPL<AvailableNationsYaml>(
`${DATA}/available_nations.yaml.dvpl`,
)
).available_nations,
2024-08-14 20:46:55 -05:00
gameModes: {},
2024-08-16 13:48:23 -05:00
roles: {},
2024-04-06 11:14:07 -05:00
};
2023-12-31 19:26:08 -06:00
const tankDefinitions: TankDefinitions = {};
2024-08-13 19:38:05 -05:00
const camouflageDefinitions: CamouflageDefinitions = {};
2024-01-02 20:17:10 -06:00
const modelDefinitions: ModelDefinitions = {};
2024-04-27 10:50:09 -05:00
const mapDefinitions: MapDefinitions = {};
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-03-31 18:24:19 -05:00
const skillDefinitions: SkillDefinitions = {
classes: { lightTank: [], mediumTank: [], heavyTank: [], 'AT-SPG': [] },
};
2024-08-14 14:04:06 -05:00
const nations = await readdir(`${DATA}/XML/item_defs/vehicles`).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-04-21 19:40:38 -05:00
const stringsPreInstalled = await readYAMLDVPL<BlitzStrings>(
2024-08-14 14:04:06 -05:00
`${DATA}/Strings/en.yaml.dvpl`,
2023-12-05 17:36:18 -06:00
);
2024-08-14 14:04:06 -05:00
const stringsCache = await fetch(
'https://stufficons.wgcdn.co/localizations/en.yaml',
)
2024-01-25 12:20:34 -06:00
.then((response) => response.text())
2024-04-21 19:40:38 -05:00
.then((string) => parseYaml(string) as BlitzStrings);
2024-01-16 16:58:00 -06:00
const optionalDevices = await readXMLDVPL<{ root: OptionalDevices }>(
2024-08-14 14:04:06 -05:00
`${DATA}/XML/item_defs/vehicles/common/optional_devices.xml.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-08-14 14:04:06 -05:00
}>(`${DATA}/XML/item_defs/vehicles/common/optional_device_slots.xml.dvpl`);
2024-08-16 13:48:23 -05:00
const consumables: ConsumablesCommon = {};
const provisions: ProvisionsCommon = {};
for (const match of (
await readStringDVPL(
`${DATA}/XML/item_defs/vehicles/common/consumables/list.xml.dvpl`,
)
).matchAll(/<items path="(.+)\.xml"\/>/g)) {
if (match[1] === 'prototypes') continue;
Object.assign(
consumables,
(
await readXMLDVPL<{ root: ConsumablesCommon }>(
`${DATA}/XML/item_defs/vehicles/common/consumables/${match[1]}.xml.dvpl`,
)
).root,
);
}
for (const match of (
await readStringDVPL(
`${DATA}/XML/item_defs/vehicles/common/provisions/list.xml.dvpl`,
)
).matchAll(/<items path="(.+)\.xml"\/>/g)) {
if (match[1] === 'prototypes') continue;
Object.assign(
provisions,
(
await readXMLDVPL<{ root: ConsumablesCommon }>(
`${DATA}/XML/item_defs/vehicles/common/provisions/${match[1]}.xml.dvpl`,
)
).root,
);
}
2024-03-31 18:24:19 -05:00
const avatar = await readXMLDVPL<{ root: Avatar }>(
`${DATA}/XML/item_defs/tankmen/avatar.xml.dvpl`,
);
2024-04-27 10:50:09 -05:00
const maps = await readYAMLDVPL<Maps>(`${DATA}/maps.yaml.dvpl`);
2024-03-14 23:31:50 -05:00
const tankXps = new Map<number, number>();
2024-08-13 19:38:05 -05:00
const camouflagesXml = await readXMLDVPL<{ root: CamouflagesXML }>(
`${DATA}/XML/item_defs/vehicles/common/camouflages.xml.dvpl`,
);
const camouflagesYaml = await readYAMLDVPL<CamouflagesYaml>(
`${DATA}/camouflages.yaml.dvpl`,
);
const camouflagesXmlEntries = Object.entries(camouflagesXml.root.camouflages);
2024-08-15 21:08:02 -05:00
const squadBattleTypeStyles = await readYAMLDVPL<SquadBattleTypeStyles>(
2024-08-15 13:35:09 -05:00
`${DATA}/UI/Screens3/Lobby/Hangar/Squad/SquadBattleType.yaml.dvpl`,
);
2024-08-16 12:52:29 -05:00
const gameTypeSelectorStyles = await readYAMLDVPL<SquadBattleTypeStyles>(
`${DATA}/UI/Screens/Lobby/Hangar/GameTypeSelector.yaml.dvpl`,
);
const gameModeNativeNames: Record<string, number> = {};
2024-08-16 13:05:27 -05:00
const combatRoles = await readYAMLDVPL<CombatRolesYaml>(
`${DATA}/XML/item_defs/vehicles/common/combat_roles.yaml.dvpl`,
);
2024-08-16 13:48:23 -05:00
const consumableNativeNames: Record<string, number> = {};
const provisionNativeNames: Record<string, number> = {};
2024-08-13 19:38:05 -05:00
2024-08-15 21:08:02 -05:00
for (const match of squadBattleTypeStyles.Prototypes[0].components.UIDataLocalBindingsComponent.data[1][2].matchAll(
2024-08-16 12:52:29 -05:00
/"(\d+)" -> "(battleType\/([a-zA-Z]+))"/g,
2024-08-14 20:46:55 -05:00
)) {
2024-08-15 13:35:09 -05:00
const id = Number(match[1]);
const name = strings[match[2]];
2024-08-14 20:46:55 -05:00
2024-08-16 12:52:29 -05:00
gameModeNativeNames[match[3]] = id;
2024-08-14 20:46:55 -05:00
gameDefinitions.gameModes[id] = {
name,
};
}
2024-08-16 12:52:29 -05:00
for (const match of gameTypeSelectorStyles.Prototypes[0].components.UIDataLocalBindingsComponent.data[1][2].matchAll(
/eGameMode\.([a-zA-Z]+) -> "~res:\/Gfx\/UI\/Hangar\/GameTypes\/battle-type_([^"]+)"/g,
)) {
Object.entries(gameModeNativeNames).forEach(([key, value]) => {
if (key.toLowerCase() === match[2].toLowerCase()) {
gameModeNativeNames[match[1]] = value;
}
});
}
2024-08-13 19:38:05 -05:00
camouflagesXmlEntries.forEach(([camoKey, camo]) => {
const yamlEntry = camouflagesYaml[camoKey];
const fullName = yamlEntry.userString
? strings[yamlEntry.userString]
: undefined;
const shortName = yamlEntry.shortUserString
? strings[yamlEntry.shortUserString]
: undefined;
const resolvedTankName = shortName ?? fullName;
const resolvedTankNameFull =
resolvedTankName === fullName ? undefined : fullName;
camouflageDefinitions[camo.id] = {
id: camo.id,
name: strings[camo.userString],
tankName: resolvedTankName,
tankNameFull: resolvedTankNameFull,
};
});
2024-03-14 23:31:50 -05: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-08-14 14:04:06 -05:00
`${DATA}/XML/item_defs/vehicles/${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-08-14 14:04:06 -05:00
`${DATA}/XML/item_defs/vehicles/${nation}/components/turrets.xml.dvpl`,
2023-12-12 13:40:58 -06:00
);
const gunList = await readXMLDVPL<{
root: GunDefinitionsList;
2024-08-14 14:04:06 -05:00
}>(`${DATA}/XML/item_defs/vehicles/${nation}/components/guns.xml.dvpl`);
2023-12-12 15:12:09 -06:00
const shellList = await readXMLDVPL<{
root: ShellDefinitionsList;
2024-08-14 14:04:06 -05:00
}>(`${DATA}/XML/item_defs/vehicles/${nation}/components/shells.xml.dvpl`);
2024-01-28 19:06:38 -06:00
const enginesList = await readXMLDVPL<{
root: EngineDefinitionsList;
}>(
2024-08-14 14:04:06 -05:00
`${DATA}/XML/item_defs/vehicles/${nation}/components/engines.xml.dvpl`,
2024-01-28 19:06:38 -06:00
);
2024-02-08 10:58:03 -06:00
const chassisList = await readXMLDVPL<{
root: ChassisDefinitionsList;
}>(
2024-08-14 14:04:06 -05:00
`${DATA}/XML/item_defs/vehicles/${nation}/components/chassis.xml.dvpl`,
2024-02-08 10:58:03 -06:00
);
2023-12-05 19:14:53 -06:00
2024-05-03 23:58:19 -05:00
function resolveUnlocks(unlocks?: Unlocks) {
if (!unlocks) return undefined;
return Object.entries(unlocks)
.map(([type, list]) =>
(Array.isArray(list) ? list : [list]).map((item) => {
const typeTyped = type as keyof Unlocks;
let rawId: number;
if (typeTyped === 'chassis') {
rawId = chassisList.root.ids[item['#text']];
} else if (typeTyped === 'engine') {
rawId = enginesList.root.ids[item['#text']];
} else if (typeTyped === 'gun') {
rawId = gunList.root.ids[item['#text']];
} else if (typeTyped === 'turret') {
rawId = turretList.root.ids[item['#text']];
} else if (typeTyped === 'vehicle') {
rawId = tankList.root[item['#text']].id;
}
return {
type: typeTyped,
id: toUniqueId(nation, rawId!),
2024-05-04 12:05:37 -05:00
cost: {
type:
typeof item.cost === 'number'
? 'xp'
: item.cost.split(':')[0],
value:
typeof item.cost === 'number'
? item.cost
: Number(item.cost.split(':')[1]),
},
} satisfies Unlock;
2024-05-03 23:58:19 -05:00
}),
)
.flat();
}
2023-12-12 13:40:58 -06:00
for (const tankKey in tankList.root) {
2024-04-08 22:04:50 -05:00
if (botPattern.test(tankKey)) continue;
2024-03-15 12:28:29 -05:00
const gunXps = new Map<number, number>();
const turretXps = new Map<number, number>();
const engineXps = new Map<number, number>();
const trackXps = new Map<number, number>();
2023-12-12 13:40:58 -06:00
const tank = tankList.root[tankKey];
2024-08-20 11:51:05 -05:00
let tankPrice: TankPrice;
2023-12-12 13:40:58 -06:00
const tankDefinition = await readXMLDVPL<{ root: VehicleDefinitions }>(
2024-08-14 14:04:06 -05:00
`${DATA}/XML/item_defs/vehicles/${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>(
2024-08-14 14:04:06 -05:00
`${DATA}/3d/Tanks/Parameters/${nation}/${tankKey}.yaml.dvpl`,
2024-01-28 20:45:50 -06:00
);
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-09 18:35:42 -06:00
const hullArmor: ModelArmor = { thickness: {} };
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
2024-08-20 11:51:05 -05:00
if (tank.sellPrice) {
tankPrice = {
type: 'gold',
value: tank.sellPrice['#text'] * 2,
};
} else if (typeof tank.price === 'number') {
tankPrice = {
type: 'credits',
value: tank.price,
};
} else {
tankPrice = {
type: 'credits',
value: tank.price['#text'] * 400,
};
}
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-02-16 21:07:48 -06:00
const crew: Crew[] = [];
2024-02-22 10:56:45 -06:00
const fixedCamouflage = tankTags.includes('eventCamouflage_user');
2024-03-13 23:23:06 -05:00
const totalUnlocks: UnlocksListing[] = [];
2024-02-16 10:20:20 -06:00
2024-08-13 19:38:05 -05:00
Object.entries(tankDefinition.root.crew).forEach(([crewKey, value]) => {
2024-02-16 21:07:48 -06:00
let entry: Crew;
2024-08-13 19:38:05 -05:00
const index = crew.findIndex(({ type }) => type === crewKey);
2024-02-16 21:07:48 -06:00
if (index === -1) {
2024-08-13 19:38:05 -05:00
entry = { type: crewKey as CrewMember };
2024-02-16 21:07:48 -06:00
crew.push(entry);
} else {
entry = crew[index];
}
2024-02-16 10:20:20 -06:00
if (typeof value === 'string') {
2024-02-16 21:07:48 -06:00
if (entry.count === undefined) {
entry.count = 1;
} else {
entry.count++;
}
if (value !== '') {
entry.substitute = value
.split('\n')
.map((member) => member.trim()) as CrewMember[];
}
2024-02-16 10:20:20 -06:00
} else {
2024-02-16 21:07:48 -06:00
if (entry.count === undefined) {
entry.count = value.length;
} else {
entry.count += value.length;
}
}
if (entry.count === 1) {
delete entry.count;
2024-02-16 10:20:20 -06:00
}
});
2024-01-02 20:17:10 -06:00
2024-08-13 19:38:05 -05:00
const camouflages = camouflagesXmlEntries
.filter(([, camo]) => {
if (!camo.vehicleFilter.include) return false;
if (camo.unlockCostCategory !== 'legendary-skins-gold')
return false;
const includeArray = Array.isArray(camo.vehicleFilter.include)
? camo.vehicleFilter.include
: [camo.vehicleFilter.include];
return includeArray.some((filter) => {
if ('vehicle' in filter && filter.vehicle?.name) {
return filter.vehicle.name === `${nation}:${tankKey}`;
}
return false;
});
})
.map(([, camo]) => camo.id);
2024-01-02 20:17:10 -06:00
tankDefinitions[tankId] = {
2024-02-08 10:58:03 -06:00
id: tankId,
2024-08-16 12:52:29 -05:00
roles: {},
2024-08-13 19:38:05 -05:00
camouflages: camouflages.length === 0 ? undefined : camouflages,
2024-05-03 12:02:56 -05:00
description:
2024-05-03 19:03:25 -05:00
wargamingTankopedia.data[tankId]?.description ?? undefined,
2024-02-22 10:56:45 -06:00
fixedCamouflage: fixedCamouflage ? true : undefined,
2024-02-16 10:20:20 -06:00
crew,
2024-02-08 10:58:03 -06:00
weight: tankDefinition.root.hull.weight,
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-03-13 18:50:08 -05:00
equipment:
typeof equipment === 'string' ? equipment : equipment.at(-1)!,
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,
2024-03-07 18:30:02 -06:00
class: tankTags[0] as TankClass,
2024-01-02 20:17:10 -06:00
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-08 10:58:03 -06:00
tracks: [],
2024-01-02 20:17:10 -06:00
};
2024-08-16 12:52:29 -05:00
if (tank.combatRole) {
Object.entries(tank.combatRole).forEach(([gameMode, role]) => {
const id = Object.entries(gameModeNativeNames).find(
([key]) => key.toLowerCase() === gameMode.toLowerCase(),
)?.[1];
if (id === undefined) {
throw new Error(
`Unknown game mode in tank ${tankKey}: ${gameMode}`,
);
}
2024-08-16 13:05:27 -05:00
tankDefinitions[tankId].roles[id] = combatRoles[role].id;
2024-08-16 12:52:29 -05: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-02 20:17:10 -06:00
turretOrigin,
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-02-08 10:58:03 -06:00
tracks: {},
2024-01-02 20:17:10 -06:00
};
2024-02-08 10:58:03 -06:00
Object.keys(tankDefinition.root.chassis).forEach((key) => {
const track = tankDefinition.root.chassis[key];
const trackId = toUniqueId(nation, chassisList.root.ids[key]);
const terrainResistances = track.terrainResistance
.split(' ')
.map(Number);
const trackArmorRaw = track.armor.leftTrack;
const hullOrigin = track.hullPosition
.split(' ')
.map(Number) as Vector3Tuple;
2024-03-13 23:23:06 -05:00
totalUnlocks.push(track.unlocks);
2024-02-08 10:58:03 -06:00
tankDefinitions[tankId].tracks.push({
id: trackId,
weight: track.weight,
2024-04-01 19:05:55 -05:00
name: strings[track.userString],
2024-02-08 10:58:03 -06:00
traverseSpeed: track.rotationSpeed,
dispersion: {
move: track.shotDispersionFactors.vehicleMovement,
traverse: track.shotDispersionFactors.vehicleRotation,
},
resistance: {
hard: terrainResistances[0],
medium: terrainResistances[1],
soft: terrainResistances[2],
},
2024-02-08 11:09:33 -06:00
tier: track.level as Tier,
2024-05-03 23:58:19 -05:00
unlocks: resolveUnlocks(track.unlocks),
2024-02-08 10:58:03 -06:00
});
modelDefinitions[tankId].tracks[trackId] = {
thickness:
typeof trackArmorRaw === 'number'
? trackArmorRaw
: trackArmorRaw['#text'],
origin: hullOrigin,
};
});
2024-01-28 19:06:38 -06:00
Object.keys(tankDefinition.root.engines).forEach((engineKey) => {
2024-03-13 23:23:06 -05:00
const engine = tankDefinition.root.engines[engineKey];
const engineListEntry = enginesList.root.shared[engineKey];
2024-01-28 19:06:38 -06:00
const engineId = toUniqueId(nation, enginesList.root.ids[engineKey]);
2024-03-13 23:23:06 -05:00
totalUnlocks.push(engine.unlocks);
2024-01-28 19:06:38 -06:00
tankDefinitions[tankId].engines.push({
id: engineId,
2024-03-13 23:23:06 -05:00
name: strings[engineListEntry.userString],
fireChance: engineListEntry.fireStartingChance,
tier: engineListEntry.level as Tier,
weight: engineListEntry.weight,
power: engineListEntry.power,
2024-05-03 23:58:19 -05:00
unlocks: resolveUnlocks(engine.unlocks),
2024-01-28 19:06:38 -06:00
});
});
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: {} };
2024-03-13 23:23:06 -05:00
totalUnlocks.push(turret.unlocks);
2024-01-09 18:35:42 -06:00
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({
id: turretId,
2024-02-08 10:58:03 -06:00
traverseSpeed: turret.rotationSpeed,
2024-01-02 20:17:10 -06:00
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-02-08 10:58:03 -06:00
weight: turret.weight,
2024-05-03 23:58:19 -05:00
unlocks: resolveUnlocks(turret.unlocks),
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) => {
2024-03-13 23:23:06 -05:00
const gun = turret.guns[gunKey];
2023-12-12 14:14:26 -06:00
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-03-13 23:23:06 -05:00
gun.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-03-13 23:23:06 -05:00
parsePath(gun.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 =
2024-03-13 23:23:06 -05:00
'clip' in gun
? gun.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'
2024-03-13 23:23:06 -05:00
? gun.pumpGunReloadTimes!.split(' ').map(Number)
: gun.reloadTime;
2023-12-14 22:19:01 -06:00
const gunClipCount =
2024-03-13 23:23:06 -05:00
gunType === 'regular' ? undefined : gun.clip!.count;
2024-03-12 17:09:21 -05:00
const gunIntraClip =
2024-03-13 23:23:06 -05:00
gunType === 'regular' ? undefined : 60 / gun.clip!.rate;
const front = gun.extraPitchLimits?.front
? gun.extraPitchLimits.front.split(' ').map(Number)
2024-01-02 20:17:10 -06:00
: undefined;
2024-03-13 23:23:06 -05:00
const back = gun.extraPitchLimits?.back
? gun.extraPitchLimits.back.split(' ').map(Number)
2024-01-02 20:17:10 -06:00
: undefined;
2024-03-13 23:23:06 -05:00
const transition = gun.extraPitchLimits?.transition
? typeof gun.extraPitchLimits.transition === 'number'
? gun.extraPitchLimits.transition
: gun.extraPitchLimits.transition.at(-1)!
2024-01-02 20:17:10 -06:00
: undefined;
2024-01-09 18:35:42 -06:00
const gunArmor: ModelArmor = { thickness: {} };
2024-02-03 15:54:21 -06:00
const shotDispersionFactors =
2024-03-13 23:23:06 -05:00
gun.shotDispersionFactors ?? gunListEntry.shotDispersionFactors;
2024-04-13 10:36:13 -05:00
const maskName = `gun_${gunModel.toString().padStart(2, '0')}`;
const maskEnabled =
tankParameters.maskSlice?.[maskName]?.enabled ?? false;
let mask: number | undefined;
if (maskEnabled) {
const maskRaw = tankParameters.maskSlice![maskName]!;
mask = maskRaw.planePosition[1];
} else {
mask = undefined;
}
2024-01-09 18:35:42 -06:00
2024-03-13 23:23:06 -05:00
totalUnlocks.push(gun.unlocks);
Object.keys(gun.armor)
2024-01-09 18:35:42 -06:00
.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);
2024-03-13 23:23:06 -05:00
const armorRaw = gun.armor[name];
2024-01-09 18:35:42 -06:00
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-08 10:58:03 -06:00
weight: gunListEntry.weight,
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,
2024-03-12 17:09:21 -05:00
intraClip: gunIntraClip,
2024-01-28 19:32:12 -06:00
camouflageLoss:
2024-03-13 23:23:06 -05:00
typeof gun.invisibilityFactorAtShot === 'number'
? gun.invisibilityFactorAtShot
: gun.invisibilityFactorAtShot.at(-1)!,
aimTime: gun.aimingTime ?? gunListEntry.aimingTime,
2024-02-03 15:54:21 -06:00
dispersion: {
2024-02-16 09:48:57 -06:00
base:
2024-03-13 23:23:06 -05:00
gun.shotDispersionRadius ??
2024-02-16 09:48:57 -06:00
gunListEntry.shotDispersionRadius,
2024-02-03 15:54:21 -06:00
damaged: shotDispersionFactors.whileGunDamaged,
shot: shotDispersionFactors.afterShot,
traverse: shotDispersionFactors.turretRotation,
},
2024-05-03 23:58:19 -05:00
unlocks: resolveUnlocks(gun.unlocks),
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-04-13 10:36:13 -05:00
mask,
2024-02-08 11:08:22 -06:00
thickness:
2024-03-13 23:23:06 -05:00
gun.armor.gun === undefined
2024-01-16 08:40:27 -06:00
? 0
2024-03-13 23:23:06 -05:00
: typeof gun.armor.gun === 'number'
? gun.armor.gun
: gun.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,
2024-04-23 10:19:32 -05:00
type: blitzShellKindToBlitzkit[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
},
);
2024-03-13 23:23:06 -05:00
totalUnlocks.forEach((unlocks) => {
if (unlocks === undefined) return;
2024-03-14 23:31:50 -05:00
2024-03-13 23:23:06 -05:00
Object.entries(unlocks).forEach(([key, value]) => {
(Array.isArray(value) ? value : [value]).forEach((vehicle) => {
2024-03-14 23:31:50 -05:00
switch (key as keyof Unlocks) {
case 'vehicle': {
const tankListEntry = tankList.root[vehicle['#text']];
const currentTank = tankDefinitions[tankId];
const successorId = toUniqueId(nation, tankListEntry.id);
2024-03-13 23:23:06 -05:00
2024-05-04 12:05:37 -05:00
tankXps.set(successorId, vehicle.cost as number);
2024-03-13 23:23:06 -05:00
2024-03-14 23:31:50 -05:00
if (currentTank.successors === undefined) {
currentTank.successors = [];
}
if (!currentTank.successors!.includes(successorId)) {
currentTank.successors!.push(successorId);
}
break;
}
case 'gun': {
gunXps.set(
toUniqueId(nation, gunList.root.ids[vehicle['#text']]),
2024-05-04 12:05:37 -05:00
vehicle.cost as number,
2024-03-14 23:31:50 -05:00
);
break;
}
case 'turret': {
turretXps.set(
toUniqueId(nation, turretList.root.ids[vehicle['#text']]),
2024-05-04 12:05:37 -05:00
vehicle.cost as number,
2024-03-14 23:31:50 -05:00
);
break;
}
case 'engine': {
engineXps.set(
toUniqueId(nation, enginesList.root.ids[vehicle['#text']]),
2024-05-04 12:05:37 -05:00
vehicle.cost as number,
2024-03-14 23:31:50 -05:00
);
break;
}
case 'chassis': {
trackXps.set(
toUniqueId(nation, chassisList.root.ids[vehicle['#text']]),
2024-05-04 12:05:37 -05:00
vehicle.cost as number,
2024-03-14 23:31:50 -05:00
);
break;
}
2024-03-13 23:23:06 -05:00
}
});
});
});
2024-03-15 12:28:29 -05:00
Object.values(tankDefinitions[tankId].turrets).forEach((turret) => {
turret.xp = turretXps.get(turret.id);
Object.values(turret.guns).forEach((gun) => {
gun.xp = gunXps.get(gun.id);
});
});
Object.values(tankDefinitions[tankId].engines).forEach((engine) => {
engine.xp = engineXps.get(engine.id);
});
Object.values(tankDefinitions[tankId].tracks).forEach((track) => {
track.xp = trackXps.get(track.id);
});
2023-12-05 19:14:53 -06:00
}
}),
);
2024-03-14 23:31:50 -05:00
Object.values(tankDefinitions).forEach((tank) => {
tank.xp = tankXps.get(tank.id);
});
2024-03-13 23:23:06 -05:00
Object.values(tankDefinitions).forEach((tank) => {
tank.successors?.forEach((predecessorId) => {
if (tankDefinitions[predecessorId].ancestors === undefined) {
tankDefinitions[predecessorId].ancestors = [];
}
if (!tankDefinitions[predecessorId].ancestors?.includes(tank.id)) {
tankDefinitions[predecessorId].ancestors?.push(tank.id);
}
});
});
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],
2024-05-05 12:04:27 -05:00
description: strings[optionalDeviceEntry.description],
2024-01-16 17:19:46 -06:00
};
},
);
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-08-16 13:48:23 -05:00
Object.entries(consumables).forEach(([key, consumable]) => {
consumableNativeNames[key] = consumable.id;
const entry = {
2024-01-16 21:49:15 -06:00
id: consumable.id,
2024-08-16 13:48:23 -05:00
gameMode: 'gameModeFilter' in consumable,
2024-02-13 09:40:00 -06:00
cooldown: consumable.script.cooldown,
duration: consumable.script.duration,
2024-01-16 21:49:15 -06:00
name:
strings[consumable.userString] ??
missingStrings[consumable.userString] ??
`Unknown ${consumable.id}`,
2024-08-16 13:48:23 -05:00
} as ConsumableEntry;
consumableDefinitions[consumable.id] = entry;
2024-01-16 21:49:15 -06:00
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-08-16 13:48:23 -05:00
if (!entry.gameMode) {
if (includeRaw) {
entry.include = [];
2024-01-25 13:51:30 -06:00
2024-08-16 13:48:23 -05:00
if ('minLevel' in includeRaw) {
entry.include.push({
type: 'tier',
min: includeRaw.minLevel,
max: includeRaw.maxLevel,
});
} else if ('name' in includeRaw) {
entry.include.push({
type: 'ids',
ids: includeRaw.name.split(' ').map((key) => tankStringIdMap[key]),
});
} else throw new SyntaxError('Unhandled include type');
if (consumable.vehicleFilter?.include.nations) {
entry.include.push({
type: 'nation',
nations: consumable.vehicleFilter.include.nations.split(' '),
});
}
2024-01-25 13:51:30 -06:00
}
2024-01-16 21:49:15 -06:00
2024-08-16 13:48:23 -05:00
if (excludeRaw) {
entry.exclude = [];
2024-01-16 21:49:15 -06:00
2024-08-16 13:48:23 -05:00
if ('name' in excludeRaw) {
entry.exclude!.push({
type: 'ids',
ids: excludeRaw.name.split(' ').map((key) => tankStringIdMap[key]),
});
} else if ('extendedTags' in excludeRaw) {
entry.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
2024-08-16 13:48:23 -05:00
if (consumable.vehicleFilter?.exclude?.nations) {
entry.exclude!.push({
type: 'nation',
nations: consumable.vehicleFilter.exclude.nations.split(' '),
});
}
2024-01-25 13:51:30 -06:00
}
2024-01-16 21:49:15 -06:00
}
});
2024-08-16 13:48:23 -05:00
Object.entries(provisions).forEach(([key, provision]) => {
provisionNativeNames[key] = provision.id;
const entry = {
2024-01-25 13:10:20 -06:00
id: provision.id,
2024-08-16 13:48:23 -05:00
gameMode: 'gameModeFilter' in provision,
2024-01-25 13:10:20 -06:00
name:
strings[provision.userString] ??
missingStrings[provision.userString] ??
`Unknown ${provision.id}`,
2024-08-16 13:48:23 -05:00
} as ProvisionEntry;
provisionDefinitions[provision.id] = entry;
2024-01-25 13:10:20 -06:00
const includeRaw = provision.vehicleFilter?.include.vehicle;
const excludeRaw = provision.vehicleFilter?.exclude?.vehicle;
2024-08-16 13:48:23 -05:00
if (!entry.gameMode) {
if (includeRaw) {
entry.include = [];
2024-01-25 13:51:30 -06:00
2024-08-16 13:48:23 -05:00
if ('minLevel' in includeRaw) {
entry.include.push({
type: 'tier',
min: includeRaw.minLevel,
max: includeRaw.maxLevel,
});
} else if ('name' in includeRaw) {
entry.include.push({
type: 'ids',
ids: includeRaw.name.split(' ').map((key) => tankStringIdMap[key]),
});
} else throw new SyntaxError('Unhandled include type');
if (provision.vehicleFilter?.include.nations) {
entry.include.push({
type: 'nation',
nations: provision.vehicleFilter.include.nations.split(' '),
});
}
2024-01-25 13:51:30 -06:00
}
2024-01-25 13:10:20 -06:00
2024-08-16 13:48:23 -05:00
if (excludeRaw) {
entry.exclude = [];
2024-01-25 13:10:20 -06:00
2024-08-16 13:48:23 -05:00
if ('name' in excludeRaw) {
entry.exclude!.push({
type: 'ids',
ids: excludeRaw.name.split(' ').map((key) => tankStringIdMap[key]),
});
} else if ('extendedTags' in excludeRaw) {
entry.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
2024-08-16 13:48:23 -05:00
if (provision.vehicleFilter?.exclude?.nations) {
entry.exclude!.push({
type: 'nation',
nations: provision.vehicleFilter.exclude.nations.split(' '),
});
}
2024-01-25 13:51:30 -06:00
}
2024-01-25 13:10:20 -06:00
}
2024-02-16 23:08:20 -06:00
if (provision.script.bonusValues?.crewLevelIncrease !== undefined) {
provisionDefinitions[provision.id].crew =
provision.script.bonusValues?.crewLevelIncrease;
}
2024-01-25 13:10:20 -06:00
});
2024-08-16 13:48:23 -05:00
Object.entries(combatRoles).forEach(([, value]) => {
gameDefinitions.roles[value.id] = { provisions: [], consumables: [] };
value.default_abilities.forEach((ability) => {
if (ability in consumableNativeNames) {
gameDefinitions.roles[value.id].consumables.push(
consumableNativeNames[ability],
);
} else if (ability in provisionNativeNames) {
gameDefinitions.roles[value.id].provisions.push(
provisionNativeNames[ability],
);
} else throw new Error(`Unknown ability ${ability}`);
});
});
2024-03-31 18:24:19 -05:00
Object.entries(avatar.root.skillsByClasses).forEach(([tankClass, skills]) => {
skillDefinitions.classes[tankClass as TankClass] = skills.split(' ');
});
2024-04-27 10:50:09 -05:00
Object.entries(maps.maps).forEach(([key, map]) => {
mapDefinitions[map.id] = {
id: map.id,
name: strings[`#maps:${key}:${map.localName}`],
};
});
2024-08-27 14:40:43 -05:00
await commitAssets('definitions', [
{
content: superCompress(gameDefinitions),
encoding: 'base64',
path: 'definitions/game.cdon.lz4',
},
{
content: superCompress(tankDefinitions),
encoding: 'base64',
path: 'definitions/tanks.cdon.lz4',
},
{
content: superCompress(modelDefinitions),
encoding: 'base64',
path: 'definitions/models.cdon.lz4',
},
{
content: superCompress(equipmentDefinitions),
encoding: 'base64',
path: 'definitions/equipment.cdon.lz4',
},
{
content: superCompress(consumableDefinitions),
encoding: 'base64',
path: 'definitions/consumables.cdon.lz4',
},
{
content: superCompress(provisionDefinitions),
encoding: 'base64',
path: 'definitions/provisions.cdon.lz4',
},
{
content: superCompress(skillDefinitions),
encoding: 'base64',
path: 'definitions/skills.cdon.lz4',
},
{
content: superCompress(mapDefinitions),
encoding: 'base64',
path: 'definitions/maps.cdon.lz4',
},
{
content: superCompress(camouflageDefinitions),
encoding: 'base64',
path: 'definitions/camouflages.cdon.lz4',
},
]);
2023-12-05 19:14:53 -06:00
}