diff --git a/scripts/buildAssets/constants.ts b/scripts/buildAssets/constants.ts index ddf82aa74..6ff1bc164 100644 --- a/scripts/buildAssets/constants.ts +++ b/scripts/buildAssets/constants.ts @@ -4,8 +4,7 @@ export const DATA = export const POI = { vehicleDefinitions: 'XML/item_defs/vehicles', strings: 'Strings', - cachedStrings: - 'C:/Users/coola/Documents/DAVAProject/cache/localizations/en.yaml', + cachedStrings: 'https://stufficons.wgcdn.co/localizations/en.yaml', tankParameters: '3d/Tanks/Parameters', smallIcons: 'Gfx/UI/BattleScreenHUD/SmallTankIcons', bigIcons: 'Gfx/UI/BigTankIcons', diff --git a/scripts/buildAssets/definitions.ts b/scripts/buildAssets/definitions.ts index eae2b8548..f6ea2e4f4 100644 --- a/scripts/buildAssets/definitions.ts +++ b/scripts/buildAssets/definitions.ts @@ -1,9 +1,9 @@ import { readdir } from 'fs/promises'; -import { parse } from 'path'; +import { parse as parsePath } from 'path'; import { Vector3Tuple } from 'three'; +import { parse as parseYaml } from 'yaml'; import { TankType } from '../../src/components/Tanks'; import { readXMLDVPL } from '../../src/core/blitz/readXMLDVPL'; -import { readYAML } from '../../src/core/blitz/readYAML'; import { readYAMLDVPL } from '../../src/core/blitz/readYAMLDVPL'; import { toUniqueId } from '../../src/core/blitz/toUniqueId'; import { commitAssets } from '../../src/core/blitzkrieg/commitAssets'; @@ -60,6 +60,7 @@ type VehicleDefinitionArmor = Record< >; interface VehicleDefinitions { invisibility: { moving: number; still: number; firePenalty: number }; + consumableSlots: number; optDevicePreset: string; hull: { armor: VehicleDefinitionArmor; @@ -257,7 +258,9 @@ export async function buildDefinitions(production: boolean) { const strings = await readYAMLDVPL( `${DATA}/${POI.strings}/en.yaml.dvpl`, ); - const stringsCache = await readYAML(POI.cachedStrings); + const stringsCache = await fetch(POI.cachedStrings) + .then((response) => response.text()) + .then((string) => parseYaml(string) as Strings); const optionalDevices = await readXMLDVPL<{ root: OptionalDevices }>( `${DATA}/${POI.optionalDevices}.dvpl`, ); @@ -338,6 +341,7 @@ export async function buildDefinitions(production: boolean) { tankDefinitions[tankId] = { id: tankId, equipment, + consumables: tankDefinition.root.consumableSlots, name: (tank.shortUserString ? strings[tank.shortUserString] ?? @@ -392,7 +396,7 @@ export async function buildDefinitions(production: boolean) { (turretKey, turretIndex) => { const turret = tankDefinition.root.turrets0[turretKey]; const turretModel = Number( - parse(turret.models.undamaged).name.split('_')[1], + parsePath(turret.models.undamaged).name.split('_')[1], ); const turretId = toUniqueId(nation, turretList.root.ids[turretKey]); const turretYaw = ( @@ -468,7 +472,7 @@ export async function buildDefinitions(production: boolean) { .split(' ') .map(Number) as [number, number]; const gunModel = Number( - parse(turretGunEntry.models.undamaged).name.split('_')[1], + parsePath(turretGunEntry.models.undamaged).name.split('_')[1], ); const gunName = strings[gunListEntry.userString] ?? gunKey.replaceAll('_', ' '); diff --git a/src/app/tools/tankopedia/[id]/components/Configure.tsx b/src/app/tools/tankopedia/[id]/components/Configure.tsx index 48d1a6f3f..51c277f8e 100644 --- a/src/app/tools/tankopedia/[id]/components/Configure.tsx +++ b/src/app/tools/tankopedia/[id]/components/Configure.tsx @@ -21,6 +21,10 @@ export function Configure() { (state) => state.equipmentMatrix, ); const consumables = useTankopediaTemporary((state) => state.consumables); + const consumablesList = Object.values(awaitedConsumableDefinitions).filter( + (consumable) => + checkConsumableInclusivity(consumable, protagonist.tank, protagonist.gun), + ); return ( @@ -94,10 +98,14 @@ export function Configure() { equipment={equipment[0]} first rowChild - selected={equipmentMatrix[rowIndex][columnIndex] === 0} + selected={equipmentMatrix[rowIndex][columnIndex] === -1} onClick={() => { mutateTankopediaTemporary((draft) => { - draft.equipmentMatrix[rowIndex][columnIndex] = 0; + if (equipmentMatrix[rowIndex][columnIndex] === -1) { + draft.equipmentMatrix[rowIndex][columnIndex] = 0; + } else { + draft.equipmentMatrix[rowIndex][columnIndex] = -1; + } }); }} /> @@ -109,7 +117,11 @@ export function Configure() { selected={equipmentMatrix[rowIndex][columnIndex] === 1} onClick={() => { mutateTankopediaTemporary((draft) => { - draft.equipmentMatrix[rowIndex][columnIndex] = 1; + if (equipmentMatrix[rowIndex][columnIndex] === 1) { + draft.equipmentMatrix[rowIndex][columnIndex] = 0; + } else { + draft.equipmentMatrix[rowIndex][columnIndex] = 1; + } }); }} /> @@ -121,36 +133,41 @@ export function Configure() { - Consumables + + Consumables (max {protagonist.tank.consumables}) + - {Object.values(awaitedConsumableDefinitions) - .filter((consumable) => - checkConsumableInclusivity( - consumable, - protagonist.tank, - protagonist.gun, - ), - ) - .map((consumable) => ( - { - mutateTankopediaTemporary((draft) => { - if (draft.consumables.includes(consumable.id)) { - draft.consumables = draft.consumables.filter( - (id) => id !== consumable.id, - ); - } else { - draft.consumables.push(consumable.id); - } - }); - }} - /> - ))} + + {consumablesList.map((consumable, index) => { + const selected = consumables.includes(consumable.id); + + return ( + { + mutateTankopediaTemporary((draft) => { + if (selected) { + draft.consumables = draft.consumables.filter( + (id) => id !== consumable.id, + ); + } else { + draft.consumables.push(consumable.id); + } + }); + }} + /> + ); + })} + diff --git a/src/components/ModuleButton.tsx b/src/components/ModuleButton.tsx index a0f90c8c3..e0b70da3a 100644 --- a/src/components/ModuleButton.tsx +++ b/src/components/ModuleButton.tsx @@ -72,6 +72,7 @@ export function ModuleButton({ {...(props as unknown as ComponentProps)} > (file: string) { const yaml = (await readFile(file)).toString(); - return parse(yaml) as Type; } diff --git a/src/core/blitzkrieg/tankDefinitions.ts b/src/core/blitzkrieg/tankDefinitions.ts index c71d4bb88..4d33bb0b8 100644 --- a/src/core/blitzkrieg/tankDefinitions.ts +++ b/src/core/blitzkrieg/tankDefinitions.ts @@ -19,6 +19,7 @@ export interface TankDefinition { name: string; name_full?: string; tree_type: TreeTypeString; + consumables: number; tier: Tier; type: TankType; testing?: boolean; diff --git a/src/stores/tankopedia.ts b/src/stores/tankopedia.ts index ef56760d5..373bac842 100644 --- a/src/stores/tankopedia.ts +++ b/src/stores/tankopedia.ts @@ -46,7 +46,7 @@ interface TankopediaPersistent { }; } -export type EquipmentMatrix = (0 | 1)[][]; +export type EquipmentMatrix = (-1 | 0 | 1)[][]; interface TankopediaTemporary { model: { @@ -100,9 +100,9 @@ export const useTankopediaTemporary = create()( }, }, equipmentMatrix: [ - [1, 0, 0], - [0, 1, 1], - [0, 1, 0], + [0, 0, 0], + [0, 0, 0], + [0, 0, 0], ], mode: 'model', consumables: [],