2024-04-04 10:46:48 -05:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
import { PlusIcon } from '@radix-ui/react-icons';
|
|
|
|
|
import { Button, Dialog, Flex, Table, Text } from '@radix-ui/themes';
|
2024-04-04 13:51:07 -05:00
|
|
|
import { useSearchParams } from 'next/navigation';
|
|
|
|
|
import { use, useState } from 'react';
|
2024-04-04 10:21:37 -05:00
|
|
|
import PageWrapper from '../../../components/PageWrapper';
|
2024-04-04 13:51:07 -05:00
|
|
|
import { tankCharacteristics } from '../../../core/blitzkrieg/tankCharacteristics';
|
2024-04-04 10:46:48 -05:00
|
|
|
import { tankIcon } from '../../../core/blitzkrieg/tankIcon';
|
2024-04-04 13:51:07 -05:00
|
|
|
import mutateCompare, { useCompare } from '../../../stores/compare';
|
|
|
|
|
import { genericDefaultEquipmentMatrix } from '../../../stores/duel/constants';
|
2024-04-04 10:46:48 -05:00
|
|
|
import { TankSearch } from '../tankopedia/components/TankSearch';
|
2024-04-04 10:21:37 -05:00
|
|
|
|
|
|
|
|
export default function Page() {
|
2024-04-04 10:46:48 -05:00
|
|
|
const searchParams = useSearchParams();
|
2024-04-04 13:51:07 -05:00
|
|
|
const tanks = useCompare((state) => state.tanks);
|
2024-04-04 10:46:48 -05:00
|
|
|
const [addTankDialogOpen, setAddTankDialogOpen] = useState(false);
|
2024-04-04 13:51:07 -05:00
|
|
|
const stats = use(
|
|
|
|
|
Promise.all(
|
|
|
|
|
tanks.map((item) =>
|
|
|
|
|
tankCharacteristics({
|
|
|
|
|
...item,
|
|
|
|
|
stockEngine: item.tank.engines[0],
|
|
|
|
|
stockGun: item.tank.turrets[0].guns[0],
|
|
|
|
|
stockTrack: item.tank.tracks[0],
|
|
|
|
|
stockTurret: item.tank.turrets[0],
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
),
|
2024-04-04 10:46:48 -05:00
|
|
|
);
|
|
|
|
|
|
2024-04-04 13:51:07 -05:00
|
|
|
function Row({
|
|
|
|
|
value,
|
|
|
|
|
decimals,
|
|
|
|
|
name,
|
|
|
|
|
}: {
|
|
|
|
|
name: string;
|
|
|
|
|
value: (member: Awaited<ReturnType<typeof tankCharacteristics>>) => number;
|
|
|
|
|
decimals?: number;
|
|
|
|
|
}) {
|
|
|
|
|
const values = stats.map(value);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Table.Row>
|
|
|
|
|
<Table.RowHeaderCell>{name}</Table.RowHeaderCell>
|
|
|
|
|
|
|
|
|
|
{values.map((value, index) => (
|
2024-04-04 13:51:39 -05:00
|
|
|
<Table.Cell key={index} justify="center">
|
2024-04-04 13:51:07 -05:00
|
|
|
<Text
|
|
|
|
|
color={
|
|
|
|
|
index === 0 ? undefined : value > values[0] ? 'green' : 'red'
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
{decimals === undefined ? value : value.toFixed(decimals)}
|
|
|
|
|
</Text>
|
|
|
|
|
</Table.Cell>
|
|
|
|
|
))}
|
|
|
|
|
</Table.Row>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-04 10:46:48 -05:00
|
|
|
return (
|
2024-04-04 11:04:27 -05:00
|
|
|
<PageWrapper color="crimson" size="100%">
|
2024-04-04 10:46:48 -05:00
|
|
|
<Flex justify="center">
|
|
|
|
|
<Dialog.Root
|
|
|
|
|
open={addTankDialogOpen}
|
|
|
|
|
onOpenChange={setAddTankDialogOpen}
|
|
|
|
|
>
|
|
|
|
|
<Dialog.Trigger>
|
|
|
|
|
<Button>
|
|
|
|
|
<PlusIcon /> Add
|
|
|
|
|
</Button>
|
|
|
|
|
</Dialog.Trigger>
|
|
|
|
|
|
|
|
|
|
<Dialog.Content>
|
|
|
|
|
<Flex gap="4" direction="column">
|
|
|
|
|
<Flex
|
|
|
|
|
direction="column"
|
|
|
|
|
gap="4"
|
|
|
|
|
style={{ flex: 1 }}
|
|
|
|
|
justify="center"
|
|
|
|
|
>
|
|
|
|
|
<TankSearch
|
|
|
|
|
compact
|
|
|
|
|
onSelect={(tank) => {
|
2024-04-04 13:51:07 -05:00
|
|
|
mutateCompare((draft) => {
|
|
|
|
|
draft.tanks.push({
|
|
|
|
|
camouflage: true,
|
|
|
|
|
consumables: [],
|
|
|
|
|
equipmentMatrix: genericDefaultEquipmentMatrix,
|
|
|
|
|
cooldownBooster: 0,
|
|
|
|
|
crewMastery: 1,
|
|
|
|
|
provisions: [],
|
|
|
|
|
engine: tank.engines.at(-1)!,
|
|
|
|
|
gun: tank.turrets.at(-1)!.guns.at(-1)!,
|
|
|
|
|
shell: tank.turrets.at(-1)!.guns.at(-1)!.shells[0],
|
|
|
|
|
tank,
|
|
|
|
|
track: tank.tracks.at(-1)!,
|
|
|
|
|
yaw: 0,
|
|
|
|
|
pitch: 0,
|
|
|
|
|
turret: tank.turrets.at(-1)!,
|
|
|
|
|
crewSkills: {},
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2024-04-04 10:46:48 -05:00
|
|
|
setAddTankDialogOpen(false);
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</Flex>
|
|
|
|
|
</Flex>
|
|
|
|
|
</Dialog.Content>
|
|
|
|
|
</Dialog.Root>
|
|
|
|
|
</Flex>
|
|
|
|
|
|
2024-04-04 11:04:27 -05:00
|
|
|
{tanks.length > 0 && (
|
|
|
|
|
<Flex justify="center">
|
|
|
|
|
<Table.Root
|
|
|
|
|
variant="surface"
|
|
|
|
|
style={{
|
|
|
|
|
maxWidth: '100%',
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Table.Header>
|
|
|
|
|
<Table.Row>
|
2024-04-04 13:51:07 -05:00
|
|
|
<Table.ColumnHeaderCell />
|
2024-04-04 10:46:48 -05:00
|
|
|
|
2024-04-04 13:51:07 -05:00
|
|
|
{tanks.map(({ tank }) => {
|
2024-04-04 11:04:27 -05:00
|
|
|
return (
|
2024-04-04 13:51:07 -05:00
|
|
|
<Table.ColumnHeaderCell width="0" key={tank.id}>
|
2024-04-04 11:04:27 -05:00
|
|
|
<Flex direction="column" align="center">
|
|
|
|
|
<img
|
2024-04-04 13:51:07 -05:00
|
|
|
src={tankIcon(tank.id)}
|
2024-04-04 11:04:27 -05:00
|
|
|
width={64}
|
|
|
|
|
height={64}
|
|
|
|
|
style={{
|
|
|
|
|
objectFit: 'contain',
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2024-04-04 13:51:07 -05:00
|
|
|
<Text style={{ textAlign: 'center' }}>{tank.name}</Text>
|
2024-04-04 11:04:27 -05:00
|
|
|
</Flex>
|
|
|
|
|
</Table.ColumnHeaderCell>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</Table.Row>
|
|
|
|
|
</Table.Header>
|
2024-04-04 10:46:48 -05:00
|
|
|
|
2024-04-04 11:04:27 -05:00
|
|
|
<Table.Body>
|
2024-04-04 13:51:07 -05:00
|
|
|
<Row name="DPM" value={(stats) => stats.dpm} decimals={0} />
|
2024-04-04 11:04:27 -05:00
|
|
|
</Table.Body>
|
|
|
|
|
</Table.Root>
|
|
|
|
|
</Flex>
|
|
|
|
|
)}
|
2024-04-04 10:46:48 -05:00
|
|
|
</PageWrapper>
|
|
|
|
|
);
|
2024-04-04 10:21:37 -05:00
|
|
|
}
|