diff --git a/src/app/tools/tankopedia/[id]/components/Model/components/Options.tsx b/src/app/tools/tankopedia/[id]/components/Model/components/Options.tsx index 8bae84ec1..07f99cc7d 100644 --- a/src/app/tools/tankopedia/[id]/components/Model/components/Options.tsx +++ b/src/app/tools/tankopedia/[id]/components/Model/components/Options.tsx @@ -13,6 +13,7 @@ import { Flex, Heading, IconButton, + Popover, Strong, Switch, Tabs, @@ -29,6 +30,7 @@ import { SHELL_NAMES, TIER_ROMAN_NUMERALS, } from '../../../../../../../core/blitzkit/tankDefinitions/constants'; +import { uniqueGuns } from '../../../../../../../core/blitzkit/uniqueGuns'; import { useEquipment } from '../../../../../../../hooks/useEquipment'; import { useFullScreen } from '../../../../../../../hooks/useFullScreen'; import { useFullscreenAvailability } from '../../../../../../../hooks/useFullscreenAvailability'; @@ -77,6 +79,7 @@ export function Options() { const [tab, setTab] = useState('search'); const mutateDuel = Duel.useMutation(); const hasEnhancedArmor = useEquipment(110); + const antagonistUniqueGuns = uniqueGuns(antagonistTank.turrets); useEffect(() => setMode(modeRaw), [modeRaw]); @@ -130,27 +133,85 @@ export function Options() { ).toFixed(0)} mm - + + {antagonistUniqueGuns.length > 1 && ( + + + + + {TIER_ROMAN_NUMERALS[antagonistGun.tier]} + + + Antagonist Gun + + + + + + {[...antagonistUniqueGuns] + .reverse() + .map(({ gun, turret }, index) => ( + + mutateDuel((draft) => { + draft.antagonist.turret = turret; + draft.antagonist.gun = gun; + draft.antagonist.shell = gun.shells[0]; + }) + } + first={index === 0} + last={index === antagonistUniqueGuns.length - 1} + selected={gun.id === antagonistGun.id} + discriminator={TIER_ROMAN_NUMERALS[gun.tier]} + /> + ))} + + + + )} + + {antagonistGun.shells.map((thisShell, shellIndex) => ( { @@ -173,18 +234,20 @@ export function Options() { ))} - + + { mutateDuel((draft) => { draft.antagonist.equipmentMatrix[0][0] = hasCalibratedShells @@ -208,15 +271,9 @@ export function Options() { { mutateDuel((draft) => { draft.protagonist.equipmentMatrix[1][1] = hasEnhancedArmor diff --git a/src/core/blitzkit/uniqueGuns.ts b/src/core/blitzkit/uniqueGuns.ts new file mode 100644 index 000000000..f6af5ac55 --- /dev/null +++ b/src/core/blitzkit/uniqueGuns.ts @@ -0,0 +1,18 @@ +import { forEachRight } from 'lodash'; +import { GunDefinition, TurretDefinition } from './tankDefinitions'; + +export function uniqueGuns(turrets: TurretDefinition[]) { + const gunIds = new Set(); + const guns: { turret: TurretDefinition; gun: GunDefinition }[] = []; + + forEachRight(turrets, (turret) => { + forEachRight(turret.guns, (gun) => { + if (!gunIds.has(gun.id)) { + gunIds.add(gun.id); + guns.push({ turret, gun }); + } + }); + }); + + return guns; +}