augment trees, pitch-limit fallback, and cached definitions

This commit is contained in:
tresabhi committed 2026-11-15 17:28:43 -06:00
1 parent da9c5272bc
commit 79129ff3c0
57 files changed
+2196 -717

No files matched your search

+13
View File
@@ -16,12 +16,15 @@ import { fetchPB } from "../../api";
import { fetchJSON } from "../../api/fetchJSON";
import { BlitzScripts } from "../../types/blitzScripts";
import { AbstractBlitzKitAPI } from "./abstract";
import { Cache } from "./server/0_base";
export class ClientBlitzKitAPI extends AbstractBlitzKitAPI {
@Cache()
game() {
return fetchPB(alias("api", "/definitions/game.pb"), GameDefinitions);
}
@Cache()
consumables() {
return fetchPB(
alias("api", "/definitions/consumables.pb"),
@@ -29,10 +32,12 @@ export class ClientBlitzKitAPI extends AbstractBlitzKitAPI {
);
}
@Cache()
tanks() {
return fetchPB(alias("api", "/definitions/tanks.pb"), TankDefinitions);
}
@Cache()
camouflages() {
return fetchPB(
alias("api", "/definitions/camouflage.pb"),
@@ -40,6 +45,7 @@ export class ClientBlitzKitAPI extends AbstractBlitzKitAPI {
);
}
@Cache()
provisions() {
return fetchPB(
alias("api", "/definitions/provisions.pb"),
@@ -47,14 +53,17 @@ export class ClientBlitzKitAPI extends AbstractBlitzKitAPI {
);
}
@Cache()
models() {
return fetchPB(alias("api", "/definitions/models.pb"), ModelDefinitions);
}
@Cache()
skills() {
return fetchPB(alias("api", "/definitions/skills.pb"), SkillDefinitions);
}
@Cache()
equipment() {
return fetchPB(
alias("api", "/definitions/equipment.pb"),
@@ -62,18 +71,22 @@ export class ClientBlitzKitAPI extends AbstractBlitzKitAPI {
);
}
@Cache()
gallery() {
return fetchPB(alias("api", "/definitions/gallery.pb"), Gallery);
}
@Cache()
maps() {
return fetchPB(alias("api", "/definitions/maps.pb"), MapDefinitions);
}
@Cache()
scripts() {
return fetchJSON<BlitzScripts>(alias("api", "/definitions/scripts.json"));
}
@Cache()
strings(locale: string) {
return fetchJSON<Strings>(alias("api", `/strings/${locale}.json`));
}
@@ -13,11 +13,20 @@ import {
toUniqueId,
TurretDefinitionsList,
UnlocksListing,
UpgradeAttributesXml,
UpgradeProgressionXml,
UpgradeProgressionXmlNode,
UpgradeProgressionXmlRequirement,
VehicleDefinitionList,
VehicleDefinitions,
} from "@blitzkit/core";
import {
AssaultRanges,
AugmentAttribute,
AugmentNode,
AugmentNodeType,
AugmentProgression,
AugmentRequirement,
Crew,
Equalizer,
GunDefinition,
@@ -32,6 +41,14 @@ import {
} from "@blitzkit/protos";
import { Cache, ServerBlitzKitAPI0 } from "./0_base";
// What an augment attribute shows, by attribute name
interface AugmentAttributeDefinition {
icon: string;
title: string;
}
type AugmentAttributeDefinitions = Map<string, AugmentAttributeDefinition>;
export abstract class ServerBlitzKitAPI1 extends ServerBlitzKitAPI0 {
private parseResearchCost(raw: number | string) {
if (typeof raw === "number") {
@@ -51,6 +68,129 @@ export abstract class ServerBlitzKitAPI1 extends ServerBlitzKitAPI0 {
}
}
private parseAugmentProgression(
xml: UpgradeProgressionXml,
attributeDefinitions: AugmentAttributeDefinitions,
) {
const iconName = (path?: string) => path?.split("/").at(-1);
const types = {
NODETYPE_COMMON: AugmentNodeType.AUGMENT_NODE_TYPE_COMMON,
NODETYPE_MECHANIC: AugmentNodeType.AUGMENT_NODE_TYPE_MECHANIC,
NODETYPE_ALTERNATIVE_MECHANIC:
AugmentNodeType.AUGMENT_NODE_TYPE_ALTERNATIVE,
} satisfies Record<UpgradeProgressionXmlNode["nodeType"], AugmentNodeType>;
const parseRequirements = (
requiredNodes: UpgradeProgressionXmlNode["requiredNodes"],
) =>
(requiredNodes === undefined || requiredNodes === ""
? []
: requiredNodes.node
).map((requirement: UpgradeProgressionXmlRequirement) =>
typeof requirement === "string"
? ({
tech_name: requirement,
vertical_first: false,
} satisfies AugmentRequirement)
: ({
tech_name: requirement["#text"],
vertical_first: requirement["@_verticalFirst"] === "true",
} satisfies AugmentRequirement),
);
const parseNode = (node: UpgradeProgressionXmlNode) =>
({
id: node.id,
tech_name: node.techName,
type: types[node.nodeType],
xp_cost: node.xpCost ?? 0,
position:
node.gridPosition === undefined
? undefined
: { x: node.gridPosition.column, y: node.gridPosition.row },
requires: parseRequirements(node.requiredNodes),
attributes: (node.attributes?.attribute ?? []).map(
({ attributeName, value }) => {
const definition = attributeDefinitions.get(attributeName);
return {
name: attributeName,
value: typeof value === "boolean" ? Number(value) : value,
icon: iconName(definition?.icon),
title:
definition === undefined
? undefined
: this.getString(definition.title),
} satisfies AugmentAttribute;
},
),
name:
node.displayName === undefined
? undefined
: this.getString(node.displayName),
} satisfies AugmentNode);
const parsedNodes = xml.nodes.node.map(parseNode);
const byTechName = new Map(
parsedNodes.map((node) => [node.tech_name, node]),
);
const groups =
xml.alternativeMechanicGroups?.alternativeMechanicGroup ?? [];
if (groups.length > 1) {
throw new Error(
"Upgrade progression with more than one alternative group",
);
}
const group = groups.at(0);
const alternativeNames = new Set(group?.alternativeNodes.node);
for (const node of parsedNodes) {
if (
node.type === AugmentNodeType.AUGMENT_NODE_TYPE_ALTERNATIVE &&
!alternativeNames.has(node.tech_name)
) {
throw new Error(
`Alternative upgrade ${node.tech_name} belongs to no group`,
);
}
}
return {
rows: xml.matrix.rows,
columns: xml.matrix.columns,
nodes: parsedNodes.filter(
(node) => node.type !== AugmentNodeType.AUGMENT_NODE_TYPE_ALTERNATIVE,
),
group:
group === undefined
? undefined
: {
tech_name: group.techName,
name: this.getString(group.displayName),
description: this.getString(group.description),
icon: iconName(group.icon),
xp_cost: group.xpCost,
position: {
x: group.gridPosition.column,
y: group.gridPosition.row,
},
requires: parseRequirements(group.requiredNodes),
alternatives: group.alternativeNodes.node.map((techName) => {
const node = byTechName.get(techName);
if (node === undefined) {
throw new Error(`Unknown alternative upgrade ${techName}`);
}
return node;
}),
},
} satisfies AugmentProgression;
}
@Cache()
async tanks() {
const tankDefinitions = TankDefinitions.create();
@@ -164,6 +304,23 @@ export abstract class ServerBlitzKitAPI1 extends ServerBlitzKitAPI0 {
const tankXps = new Map<number, ResearchCost>();
// Only some builds ship augment trees
const upgradeAttributesPath =
"Data/XML/item_defs/vehicles/common/tank_upgrade_attributes.xml";
const upgradeAttributeDefinitions: AugmentAttributeDefinitions = new Map();
if ((await this.vfs.resolve(upgradeAttributesPath)) !== null) {
const upgradeAttributes =
await this.vfs.xmlWithAttributes<UpgradeAttributesXml>(
upgradeAttributesPath,
);
for (const { attributeName, icon, title } of upgradeAttributes.root
.attributes.attribute) {
upgradeAttributeDefinitions.set(attributeName, { icon, title });
}
}
for (const nation of this.nationsDir!) {
const tankList = await this.vfs.xml<{ root: VehicleDefinitionList }>(
`Data/XML/item_defs/vehicles/${nation}/list.xml`,
@@ -429,12 +586,25 @@ export abstract class ServerBlitzKitAPI1 extends ServerBlitzKitAPI0 {
}
}
const augment_progression =
tankDefinition.root.upgradeProgression === undefined
? undefined
: this.parseAugmentProgression(
(
await this.vfs.xmlWithAttributes<{
root: { upgradeProgression: UpgradeProgressionXml };
}>(`Data/XML/item_defs/vehicles/${nation}/${tankKey}.xml`)
).root.upgradeProgression,
upgradeAttributeDefinitions,
);
tankDefinitions.tanks[tankId] = {
ancestors: [],
successors: [],
id: tankId,
dev_name: tankKey,
module_positions,
augment_progression,
roles: {},
camouflages: camouflages,
fixed_camouflage: fixedCamouflage,
@@ -21,6 +21,13 @@ import { MathUtils, Vector3 as THREEVector3, Vector3Tuple } from "three";
import { Cache } from "./0_base";
import { ServerBlitzKitAPI2 } from "./2_camouflages";
// The `front` and `back` tags hold "min max range" in degrees
function parseExtraPitchLimitValues(raw: string | undefined) {
if (raw === undefined) return undefined;
return raw.trim().split(/\s+/).map(Number);
}
export abstract class ServerBlitzKitAPI3 extends ServerBlitzKitAPI2 {
private vector3TupleToBlitzkit(tuple: Vector3Tuple) {
return { x: tuple[0], y: tuple[1], z: -tuple[2] } satisfies ProtoVector3;
@@ -350,17 +357,21 @@ export abstract class ServerBlitzKitAPI3 extends ServerBlitzKitAPI2 {
gunModel = 2;
}
const front = gun.extraPitchLimits?.front
? gun.extraPitchLimits.front.split(" ").map(Number)
: undefined;
const back = gun.extraPitchLimits?.back
? gun.extraPitchLimits.back.split(" ").map(Number)
: undefined;
const transition = gun.extraPitchLimits?.transition
? typeof gun.extraPitchLimits.transition === "number"
? gun.extraPitchLimits.transition
: gun.extraPitchLimits.transition.at(-1)!
: undefined;
// The client merges shared and per-tank values one field at a time:
// front, back and transition each fall back on the shared gun
const extraPitchLimits = {
...gunListEntry.extraPitchLimits,
...gun.extraPitchLimits,
};
const front = parseExtraPitchLimitValues(extraPitchLimits.front);
const back = parseExtraPitchLimitValues(extraPitchLimits.back);
// A repeated tag overwrites the last one, and one value covers both
const transition =
extraPitchLimits.transition === undefined
? undefined
: typeof extraPitchLimits.transition === "number"
? extraPitchLimits.transition
: extraPitchLimits.transition.at(-1)!;
const gunArmor: Armor = { thickness: {}, spaced: [] };
const maskName = `gun_${gunModel.toString().padStart(2, "0")}`;
const maskEnabled =
@@ -4,9 +4,21 @@ import { XMLParser } from "fast-xml-parser";
import type { normalize } from "node:path/posix";
import { parse as parseYaml } from "yaml";
// Tags of an upgrade progression that are lists even with a single child
const UPGRADE_PROGRESSION_LIST_TAGS = new Set([
"node",
"attribute",
"alternativeMechanicGroup",
]);
export abstract class AbstractVFS {
textDecoder = new TextDecoder();
private xmlParser = new XMLParser();
private attributeXmlParser = new XMLParser({
ignoreAttributes: false,
// A lone child would otherwise parse to an object instead of a list
isArray: (name) => UPGRADE_PROGRESSION_LIST_TAGS.has(name),
});
protected normalizePath?: typeof normalize;
@@ -80,6 +92,12 @@ export abstract class AbstractVFS {
return this.xmlParser.parse(file) as Type;
}
// Keeps attributes as `@_name` and lists as arrays, which `xml` drops
async xmlWithAttributes<Type>(path: string) {
const file = await this.text(path);
return this.attributeXmlParser.parse(file) as Type;
}
protected async _csv(text: string, options: Options = {}) {
const parsed = parseCSV(text, options);
return parsed;
@@ -17,6 +17,11 @@ export interface GunDefinitionsList {
tags: string;
level: number;
pitchLimits: string;
extraPitchLimits?: {
front?: string;
back?: string;
transition?: number | number[];
};
burst?: { count: number; rate: number };
clip?: { count: number; rate: number };
shots: {
+1
View File
@@ -23,6 +23,7 @@ export * from "./tankParameters";
export * from "./tanksStats";
export * from "./techTreeLayoutYaml";
export * from "./turretDefinitionsList";
export * from "./upgradeProgressionXml";
export * from "./vehicleDefinitionArmor";
export * from "./vehicleDefinitionList";
export * from "./vehicleDefinitions";
@@ -0,0 +1,61 @@
// Parsed with attributes and with these elements forced to arrays, see
// `AbstractVFS.xmlWithAttributes`
// Plain text unless the connector carries `verticalFirst`
export type UpgradeProgressionXmlRequirement =
| string
// Attribute values stay strings
| { "#text": string; "@_verticalFirst"?: string };
export interface UpgradeProgressionXmlAttribute {
attributeName: string;
// Numbers, or `true`/`false` for switches
value: number | boolean;
}
export interface UpgradeProgressionXmlNode {
id: number;
techName: string;
nodeType:
| "NODETYPE_COMMON"
| "NODETYPE_MECHANIC"
| "NODETYPE_ALTERNATIVE_MECHANIC";
xpCost?: number;
displayName?: string;
icon?: string;
gridPosition?: { row: number; column: number };
// Empty elements parse to an empty string
requiredNodes?: "" | { node: UpgradeProgressionXmlRequirement[] };
attributes?: { attribute: UpgradeProgressionXmlAttribute[] };
}
export interface UpgradeProgressionXmlGroup {
techName: string;
displayName: string;
description: string;
icon?: string;
xpCost: number;
gridPosition: { row: number; column: number };
requiredNodes: { node: UpgradeProgressionXmlRequirement[] };
alternativeNodes: { node: string[] };
}
export interface UpgradeProgressionXml {
matrix: { rows: number; columns: number };
alternativeMechanicGroups?: {
alternativeMechanicGroup: UpgradeProgressionXmlGroup[];
};
nodes: { node: UpgradeProgressionXmlNode[] };
}
export interface UpgradeAttributesXml {
root: {
attributes: {
attribute: {
attributeName: string;
icon: string;
title: string;
}[];
};
};
}
@@ -1,4 +1,4 @@
import { BlitzModuleType } from "@blitzkit/core";
import { BlitzModuleType, VehicleDefinitionArmor } from "@blitzkit/core";
export interface VehicleDefinitions {
invisibility: {
@@ -13,6 +13,8 @@ export interface VehicleDefinitions {
};
consumableSlots: number;
provisionSlots: number;
// Tier 11 tanks only, parsed separately because it needs attributes
upgradeProgression?: object;
optDevicePreset: string | string[];
hull: {
armor: VehicleDefinitionArmor;