diff --git a/scripts/buildAssets/definitions.ts b/scripts/buildAssets/definitions.ts index 89af27e07..ab2c17f1b 100644 --- a/scripts/buildAssets/definitions.ts +++ b/scripts/buildAssets/definitions.ts @@ -35,6 +35,7 @@ import { TankDefinitionPrice, TankDefinitions, Tier, + Unlock, } from '../../src/core/blitzkit/tankDefinitions'; import { DATA, POI } from './constants'; import { Avatar } from './skillIcons'; @@ -86,7 +87,7 @@ type VehicleDefinitionArmor = Record< number | { vehicleDamageFactor: 0; '#text': number } >; interface UnlocksInner { - cost: number; + cost: number | string; '#text': number; } type Unlocks = { @@ -477,7 +478,17 @@ export async function definitions(production: boolean) { return { type: typeTyped, id: toUniqueId(nation, rawId!), - }; + 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; }), ) .flat(); @@ -948,7 +959,7 @@ export async function definitions(production: boolean) { const currentTank = tankDefinitions[tankId]; const successorId = toUniqueId(nation, tankListEntry.id); - tankXps.set(successorId, vehicle.cost); + tankXps.set(successorId, vehicle.cost as number); if (currentTank.successors === undefined) { currentTank.successors = []; @@ -962,7 +973,7 @@ export async function definitions(production: boolean) { case 'gun': { gunXps.set( toUniqueId(nation, gunList.root.ids[vehicle['#text']]), - vehicle.cost, + vehicle.cost as number, ); break; } @@ -970,7 +981,7 @@ export async function definitions(production: boolean) { case 'turret': { turretXps.set( toUniqueId(nation, turretList.root.ids[vehicle['#text']]), - vehicle.cost, + vehicle.cost as number, ); break; } @@ -978,7 +989,7 @@ export async function definitions(production: boolean) { case 'engine': { engineXps.set( toUniqueId(nation, enginesList.root.ids[vehicle['#text']]), - vehicle.cost, + vehicle.cost as number, ); break; } @@ -986,7 +997,7 @@ export async function definitions(production: boolean) { case 'chassis': { trackXps.set( toUniqueId(nation, chassisList.root.ids[vehicle['#text']]), - vehicle.cost, + vehicle.cost as number, ); break; } diff --git a/src/app/tools/tankopedia/[id]/components/Model/ModulesSection.tsx b/src/app/tools/tankopedia/[id]/components/Model/ModulesSection.tsx index 86f1f8784..26bde0dc9 100644 --- a/src/app/tools/tankopedia/[id]/components/Model/ModulesSection.tsx +++ b/src/app/tools/tankopedia/[id]/components/Model/ModulesSection.tsx @@ -1,18 +1,106 @@ -import { Flex, Heading } from '@radix-ui/themes'; +import { Flex, Heading, IconButton, Text } from '@radix-ui/themes'; +import Link from 'next/link'; import { use } from 'react'; -import { ModuleButton } from '../../../../../../components/ModuleButtons/ModuleButton'; import PageWrapper from '../../../../../../components/PageWrapper'; +import { asset } from '../../../../../../core/blitzkit/asset'; import { ModuleDefinition, ModuleType, TankDefinition, tankDefinitions, + Tier, Unlock, } from '../../../../../../core/blitzkit/tankDefinitions'; import { TIER_ROMAN_NUMERALS } from '../../../../../../core/blitzkit/tankDefinitions/constants'; +import { tankIcon } from '../../../../../../core/blitzkit/tankIcon'; import { mutateDuel, useDuel } from '../../../../../../stores/duel'; import { TreeArrow } from './TechTreeSection'; +function ModuleButton({ + tier, + selected, + unlock, + onClick, +}: { + unlock: Unlock; + tier: Tier; + selected: boolean; + onClick: () => void; +}) { + const numberFormat = Intl.NumberFormat(undefined, { + notation: 'compact', + maximumFractionDigits: 0, + }); + const button = ( + + + {TIER_ROMAN_NUMERALS[tier]} + + + {unlock.cost.value > 0 && ( + + + {numberFormat.format(unlock.cost.value)} + + + + + )} + + + + ); + + return unlock.type === 'vehicle' ? ( + {button} + ) : ( + button + ); +} + export function ModulesSection() { const awaitedTankDefinitions = use(tankDefinitions); const tank = useDuel((state) => state.protagonist!.tank); @@ -92,21 +180,17 @@ export function ModulesSection() { turret.guns.some((gun) => gun.id === unlock.id), )! .guns.find((gun) => gun.id === unlock.id)!; + } else if (unlock.type === 'vehicle') { + module = awaitedTankDefinitions[unlock.id]; } if (module === undefined) return null; - const unlocksFiltered = (module as ModuleDefinition).unlocks?.filter( - ({ type }) => type !== 'vehicle', - ); - return ( setByUnlock(unlock)} /> - {unlocksFiltered && unlocksFiltered.length > 0 && ( + {(module as ModuleDefinition).unlocks && ( <> {tree(type, (module as ModuleDefinition).unlocks!)} @@ -141,12 +225,20 @@ export function ModulesSection() { setByUnlock({ id: turret0.id, type: 'turret' })} + onClick={() => + setByUnlock({ + id: turret0.id, + type: 'turret', + cost: { type: 'xp', value: 0 }, + }) + } /> {turret0.unlocks && ( @@ -159,12 +251,20 @@ export function ModulesSection() { setByUnlock({ id: gun0.id, type: 'gun' })} + onClick={() => + setByUnlock({ + id: gun0.id, + type: 'gun', + cost: { type: 'xp', value: 0 }, + }) + } /> {gun0.unlocks && ( @@ -177,12 +277,20 @@ export function ModulesSection() { setByUnlock({ id: engine0.id, type: 'engine' })} + onClick={() => + setByUnlock({ + id: engine0.id, + type: 'engine', + cost: { type: 'xp', value: 0 }, + }) + } /> {engine0.unlocks && ( @@ -195,12 +303,20 @@ export function ModulesSection() { setByUnlock({ id: track0.id, type: 'chassis' })} + onClick={() => + setByUnlock({ + id: track0.id, + type: 'chassis', + cost: { type: 'xp', value: 0 }, + }) + } /> {track0.unlocks && ( @@ -210,16 +326,6 @@ export function ModulesSection() { )} - - {/* gun0 - {tank.turrets[0].guns[0].unlocks && - tree('gun', tank.turrets[0].guns[0].unlocks)} - - engine0 - {tank.engines[0].unlocks && tree('engine', tank.engines[0].unlocks)} - - track0 - {tank.tracks[0].unlocks && tree('chassis', tank.tracks[0].unlocks)} */} ); diff --git a/src/core/blitzkit/tankDefinitions/index.ts b/src/core/blitzkit/tankDefinitions/index.ts index b6b6bc0cb..a80ab8cd6 100644 --- a/src/core/blitzkit/tankDefinitions/index.ts +++ b/src/core/blitzkit/tankDefinitions/index.ts @@ -18,6 +18,11 @@ export type ModuleType = 'vehicle' | 'engine' | 'chassis' | 'turret' | 'gun'; export interface Unlock { type: ModuleType; id: number; + cost: { + // string being the season coins + type: 'xp' | string; + value: number; + }; } export interface Crew { type: CrewMember;