From 3be91469aa2484383772cd85581b90c3b742ca3b Mon Sep 17 00:00:00 2001 From: tresabhi <43380238+tresabhi@users.noreply.github.com> Date: Sun, 13 Sep 2026 13:20:45 -0500 Subject: [PATCH] strict types --- bun.lock | 1 + cspell.json | 2 + packages/core/package.json | 1 + packages/core/src/blitz/constants.ts | 2 +- packages/core/src/blitzkit/api/client.ts | 4 +- .../checkConsumableProvisionInclusivity.ts | 2 +- packages/core/src/blitzkit/metaSortTank.ts | 2 +- .../blitzkit/resolvePenetrationCoefficient.ts | 2 +- .../src/blitzkit/tankDefinitions/constants.ts | 2 +- packages/core/src/blitzkit/tankNames.ts | 2 +- packages/core/src/types/consumablesCommon.ts | 10 +- .../src/types/provisionConsumableScript.ts | 140 ++++++++++++++++++ packages/core/src/types/provisionsCommon.ts | 8 +- .../definitions/consumables.pb.ts | 10 -- 14 files changed, 156 insertions(+), 32 deletions(-) create mode 100644 packages/core/src/types/provisionConsumableScript.ts diff --git a/bun.lock b/bun.lock index 47fded7c9..2d40f8548 100644 --- a/bun.lock +++ b/bun.lock @@ -26,6 +26,7 @@ "name": "@blitzkit/core", "dependencies": { "@blitzkit/i18n": "workspace:*", + "@blitzkit/protos": "workspace:*", "@bufbuild/protobuf": "^2.9.0", "@octokit/plugin-throttling": "^11.0.1", "@octokit/rest": "^22.0.0", diff --git a/cspell.json b/cspell.json index a67dd4960..d8c19f591 100644 --- a/cspell.json +++ b/cspell.json @@ -1,6 +1,8 @@ { "words": [ "gamemodes", + "Recoverkit", + "Repairkit", "Tankopedia" ] } diff --git a/packages/core/package.json b/packages/core/package.json index d7e3bf264..43884eda9 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -5,6 +5,7 @@ "main": "src/index.ts", "dependencies": { "@blitzkit/i18n": "workspace:*", + "@blitzkit/protos": "workspace:*", "@bufbuild/protobuf": "^2.9.0", "@octokit/plugin-throttling": "^11.0.1", "@octokit/rest": "^22.0.0", diff --git a/packages/core/src/blitz/constants.ts b/packages/core/src/blitz/constants.ts index 64ec733be..729cd5ef9 100644 --- a/packages/core/src/blitz/constants.ts +++ b/packages/core/src/blitz/constants.ts @@ -1,4 +1,4 @@ -import { TankClass, TankType } from "../protos"; +import { TankClass, TankType } from "@blitzkit/protos"; import type { BlitzStats } from "../statistics"; export const TANK_TYPES = [ diff --git a/packages/core/src/blitzkit/api/client.ts b/packages/core/src/blitzkit/api/client.ts index 1b3b1f487..12d8181c5 100644 --- a/packages/core/src/blitzkit/api/client.ts +++ b/packages/core/src/blitzkit/api/client.ts @@ -1,5 +1,4 @@ import { alias } from "@blitzkit/core"; -import { fetchPB } from "../../protobuf"; import { CamouflageDefinitions, ConsumableDefinitions, @@ -11,7 +10,8 @@ import { ProvisionDefinitions, SkillDefinitions, TankDefinitions, -} from "../../protos"; +} from "@blitzkit/protos"; +import { fetchPB } from "../../protobuf"; import { BlitzKitAPI } from "./base"; export class ClientBlitzKitAPI extends BlitzKitAPI { diff --git a/packages/core/src/blitzkit/checkConsumableProvisionInclusivity.ts b/packages/core/src/blitzkit/checkConsumableProvisionInclusivity.ts index 7b942ba94..992652d0f 100644 --- a/packages/core/src/blitzkit/checkConsumableProvisionInclusivity.ts +++ b/packages/core/src/blitzkit/checkConsumableProvisionInclusivity.ts @@ -4,7 +4,7 @@ import { GunDefinition, Provision, TankDefinition, -} from "../protos"; +} from "@blitzkit/protos"; export function checkConsumableProvisionInclusivity( consumableProvision: Consumable | Provision, diff --git a/packages/core/src/blitzkit/metaSortTank.ts b/packages/core/src/blitzkit/metaSortTank.ts index f146915b1..1b41cbbdc 100644 --- a/packages/core/src/blitzkit/metaSortTank.ts +++ b/packages/core/src/blitzkit/metaSortTank.ts @@ -1,5 +1,5 @@ +import { GameDefinitions, TankDefinition, TankType } from "@blitzkit/protos"; import { TANK_CLASSES } from "../blitz/constants"; -import { GameDefinitions, TankDefinition, TankType } from "../protos"; const treeTypeOrder = [ TankType.TANK_TYPE_RESEARCHABLE, diff --git a/packages/core/src/blitzkit/resolvePenetrationCoefficient.ts b/packages/core/src/blitzkit/resolvePenetrationCoefficient.ts index 56dcb2560..26ee3f65c 100644 --- a/packages/core/src/blitzkit/resolvePenetrationCoefficient.ts +++ b/packages/core/src/blitzkit/resolvePenetrationCoefficient.ts @@ -1,4 +1,4 @@ -import { Equalizer, ShellType } from "../protos"; +import { Equalizer, ShellType } from "@blitzkit/protos"; export function resolvePenetrationCoefficient( calibratedShells: boolean, diff --git a/packages/core/src/blitzkit/tankDefinitions/constants.ts b/packages/core/src/blitzkit/tankDefinitions/constants.ts index 5224cdae7..7c4906b81 100644 --- a/packages/core/src/blitzkit/tankDefinitions/constants.ts +++ b/packages/core/src/blitzkit/tankDefinitions/constants.ts @@ -1,5 +1,5 @@ +import { CrewType, ShellType, TankClass, TankType } from "@blitzkit/protos"; import { times } from "lodash-es"; -import { CrewType, ShellType, TankClass, TankType } from "../../protos"; export const SHELL_NAMES: Record = { [ShellType.SHELL_TYPE_AP]: "AP", diff --git a/packages/core/src/blitzkit/tankNames.ts b/packages/core/src/blitzkit/tankNames.ts index 04d02de14..9a141daca 100644 --- a/packages/core/src/blitzkit/tankNames.ts +++ b/packages/core/src/blitzkit/tankNames.ts @@ -1,7 +1,7 @@ import { BlitzKitAPI } from "@blitzkit/core/src/blitzkit/api/base"; import locales from "@blitzkit/i18n/locales.json"; +import { I18nString } from "@blitzkit/protos"; import { deburr, times } from "lodash-es"; -import { I18nString } from "../protos"; export async function fetchTankNames(api: BlitzKitAPI) { const [tankDefinitions, camouflageDefinitions] = await Promise.all([ diff --git a/packages/core/src/types/consumablesCommon.ts b/packages/core/src/types/consumablesCommon.ts index 6b4068edf..fd4dd23d8 100644 --- a/packages/core/src/types/consumablesCommon.ts +++ b/packages/core/src/types/consumablesCommon.ts @@ -1,3 +1,4 @@ +import { ProvisionConsumableScript } from "@blitzkit/core/src/types/provisionConsumableScript"; import { ConsumablesVehicleFilter } from "./consumablesVehicleFilter"; export interface ConsumablesCommon { @@ -12,13 +13,6 @@ export interface ConsumablesCommon { include: { vehicle: ConsumablesVehicleFilter; nations?: string }; exclude?: { vehicle: ConsumablesVehicleFilter; nations?: string }; }; - script: { - "#text": string; - automatic?: boolean; - cooldown: number; - duration?: number; - shotEffect?: string; - bonusValues?: { [key: string]: number }; - } & Record; + script: ProvisionConsumableScript; }; } diff --git a/packages/core/src/types/provisionConsumableScript.ts b/packages/core/src/types/provisionConsumableScript.ts new file mode 100644 index 000000000..e2c8436fc --- /dev/null +++ b/packages/core/src/types/provisionConsumableScript.ts @@ -0,0 +1,140 @@ +export type ProvisionConsumableScript = + | { + "#text": "Extinguisher"; + cooldown: number; + automatic: boolean; + } + | { + "#text": "Repairkit"; + cooldown: number; + } + | { + "#text": "Afterburning"; + cooldown: number; + duration: number; + bonusValues: { + enginePowerIncrease: number; + }; + } + | { + "#text": "Berserk"; + cooldown: number; + duration: number; + bonusValues: { + gunReloadSpeedIncrease: number; + }; + } + | { + "#text": "Recoverkit"; + cooldown: number; + } + | { + "#text": "ImprovedAfterburning"; + cooldown: number; + duration: number; + enginePowerIncrease: number; + rotationSpeedFactor: number; + fwdSpeedLimitBias: number; + bkwdSpeedLimitBias: number; + } + | { + "#text": "FireControlSystem"; + cooldown: number; + duration: number; + shotDispersionAngleFactor: number; + aimingTimeFactor: number; + } + | { + "#text": "NewAutoloader"; + cooldown: number; + duration: number; + clipReloadTimeFactor: number; + gunReloadTimeFactor: number; + } + | { + "#text": "ShieldKit"; + cooldown: number; + duration: number; + shieldCoef: number; + } + | { + "#text": "TungstenTip"; + cooldown: number; + duration: number; + minDamageFactor: number; + maxDamageFactor: number; + shotEffect: "dangerousTracer"; + } + | { + "#text": "ArmorMover"; + cooldown: number; + duration: number; + deactivateStates: number; + activateStates: number; + bonusValues: { + damageReductionPercent: number; + }; + } + | { + "#text": "ImprovedAfterburning"; + cooldown: number; + duration: number; + enginePowerIncrease: number; + rotationSpeedFactor: number; + fwdSpeedLimitBias: number; + bkwdSpeedLimitBias: number; + } + | { + "#text": "Stimulator"; + bonusValues: { + crewLevelIncrease: number; + }; + } + | { + "#text": "AntiHighExplosive"; + bonusValues: { + factor: number; + }; + } + | { + "#text": "Fuel"; + bonusValues: { + enginePowerIncrease: number; + turretRotationSpeedIncrease: number; + }; + } + | { + "#text": "SafetySet"; + bonusValues: { + crewChanceToHitFactor: number; + repairSpeedIncrease: number; + fireProtectionIncrease: number; + explosivesHealthIncrease: number; + }; + } + | { + "#text": "SmallHPStock"; + hpStockPercent: number; + } + | { + "#text": "GearOil"; + bonusValues: { + fwdSpeedLimitBias: number; + bkwdSpeedLimitBias: number; + enginePowerIncrease: number; + }; + } + | { + "#text": "GunPowder"; + bonusValues: { + projectileSpeedFactor: number; + }; + } + | { + "#text": "AttributesModifier"; + attributes: { + firmGroundPassabilityIncrease: number; + mediumGroundPassabilityIncrease: number; + repairSpeedFactor: number; + }; + }; diff --git a/packages/core/src/types/provisionsCommon.ts b/packages/core/src/types/provisionsCommon.ts index 9bd27ad3e..42bc2956a 100644 --- a/packages/core/src/types/provisionsCommon.ts +++ b/packages/core/src/types/provisionsCommon.ts @@ -1,3 +1,4 @@ +import { ProvisionConsumableScript } from "@blitzkit/core/src/types/provisionConsumableScript"; import { ConsumablesVehicleFilter } from "./consumablesVehicleFilter"; export interface ProvisionsCommon { @@ -12,11 +13,6 @@ export interface ProvisionsCommon { include: { vehicle: ConsumablesVehicleFilter; nations?: string }; exclude?: { vehicle: ConsumablesVehicleFilter; nations?: string }; }; - script: { - "#text": string; - automatic?: boolean; - shotEffect?: string; - bonusValues?: { [key: string]: number }; - } & Record; + script: ProvisionConsumableScript; }; } diff --git a/packages/website/src/pages/[...chunk_api]/definitions/consumables.pb.ts b/packages/website/src/pages/[...chunk_api]/definitions/consumables.pb.ts index acaf04dad..c384c12c3 100644 --- a/packages/website/src/pages/[...chunk_api]/definitions/consumables.pb.ts +++ b/packages/website/src/pages/[...chunk_api]/definitions/consumables.pb.ts @@ -1,20 +1,10 @@ import { ConsumableDefinitions } from "@blitzkit/core"; import { api } from "../../../blitzkit/api"; -import { vfs } from "../../../core/blitzkit/vfs"; export { getStaticPaths } from "../_index"; export async function GET() { - const test = await vfs.xml( - "Data/XML/item_defs/vehicles/common/consumables/common.xml", - ); - - return Response.json(test); - const definitions = await api.consumables(); - - return Response.json(definitions); - const bytes = ConsumableDefinitions.encode(definitions).finish(); return new Response(bytes);