From 0b5c2e42fb237d422b1b27dfdee8c876d0114137 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Mon, 22 Jan 2024 18:04:13 -0600 Subject: [PATCH] feat: isolated duel --- .../[id]/components/AntagonistBar/index.tsx | 82 ++++++---------- .../tankopedia/[id]/components/Configure.tsx | 51 ++++------ .../tankopedia/[id]/components/Control.tsx | 23 ++--- .../tankopedia/[id]/components/Lighting.tsx | 11 +-- .../[id]/components/Model/TankSandbox.tsx | 31 +++--- .../components/ArmorHighlighting.tsx | 20 ++-- .../components/ExternalModuleMask.tsx | 20 ++-- .../TankArmor/components/SpacedArmorDepth.tsx | 20 ++-- .../Model/components/TankArmor/index.tsx | 13 +-- .../components/Model/components/TankModel.tsx | 10 +- .../[id]/components/QuickInputs/index.tsx | 9 +- .../tankopedia/[id]/components/Title.tsx | 12 +-- src/app/tools/tankopedia/[id]/page.tsx | 97 +++++++++---------- .../ArmorMesh/components/Armor/index.tsx | 51 +++++++--- src/stores/duel.ts | 17 ++++ 15 files changed, 218 insertions(+), 249 deletions(-) create mode 100644 src/stores/duel.ts diff --git a/src/app/tools/tankopedia/[id]/components/AntagonistBar/index.tsx b/src/app/tools/tankopedia/[id]/components/AntagonistBar/index.tsx index 0c4e7a74c..6436fab6d 100644 --- a/src/app/tools/tankopedia/[id]/components/AntagonistBar/index.tsx +++ b/src/app/tools/tankopedia/[id]/components/AntagonistBar/index.tsx @@ -9,25 +9,17 @@ import { Text, Tooltip, } from '@radix-ui/themes'; -import { produce } from 'immer'; -import { Dispatch, SetStateAction, useState } from 'react'; +import { useState } from 'react'; import { ModuleButton } from '../../../../../../components/ModuleButton'; import { SmallTankIcon } from '../../../../../../components/SmallTankIcon'; import { resolveNearPenetration } from '../../../../../../core/blitz/resolveNearPenetration'; import { SHELL_NAMES } from '../../../../../../core/blitzkrieg/tankDefinitions'; +import { mutateDuel, useDuel } from '../../../../../../stores/duel'; import { useTankopediaTemporary } from '../../../../../../stores/tankopedia'; import { TankSearch } from '../../../components/TankSearch'; -import { Duel } from '../../page'; -interface AntagonistBarProps { - duel: Duel; - setDuel: Dispatch>; -} - -export function AntagonistBar({ - duel: { antagonist }, - setDuel, -}: AntagonistBarProps) { +export function AntagonistBar() { + const antagonist = useDuel((state) => state.antagonist!); const mode = useTankopediaTemporary((state) => state.mode); const [tab, setTab] = useState('search'); const [antagonistSelectorOpen, setAntagonistSelectorVisible] = @@ -50,11 +42,9 @@ export function AntagonistBar({ key={shell.id} last={index === antagonist.gun.shells.length - 1} onClick={() => { - setDuel( - produce((draft) => { - draft.antagonist.shell = shell; - }), - ); + mutateDuel((draft) => { + draft.antagonist!.shell = shell; + }); }} /> ); @@ -109,16 +99,14 @@ export function AntagonistBar({ { - setDuel( - produce((draft) => { - draft.antagonist.tank = tank; - draft.antagonist.turret = tank.turrets.at(-1)!; - draft.antagonist.gun = - draft.antagonist.turret.guns.at(-1)!; - draft.antagonist.shell = - draft.antagonist.gun.shells[0]; - }), - ); + mutateDuel((draft) => { + draft.antagonist!.tank = tank; + draft.antagonist!.turret = tank.turrets.at(-1)!; + draft.antagonist!.gun = + draft.antagonist!.turret.guns.at(-1)!; + draft.antagonist!.shell = + draft.antagonist!.gun.shells[0]; + }); setAntagonistSelectorVisible(false); }} /> @@ -144,15 +132,13 @@ export function AntagonistBar({ } key={turret.id} onClick={() => { - setDuel( - produce((draft) => { - draft.antagonist.turret = turret; - draft.antagonist.gun = - turret.guns.at(-1)!; - draft.antagonist.shell = - draft.antagonist.gun.shells[0]; - }), - ); + mutateDuel((draft) => { + draft.antagonist!.turret = turret; + draft.antagonist!.gun = + turret.guns.at(-1)!; + draft.antagonist!.shell = + draft.antagonist!.gun.shells[0]; + }); }} selected={antagonist.turret.id === turret.id} tier={turret.tier} @@ -172,12 +158,10 @@ export function AntagonistBar({ index === antagonist.turret.guns.length - 1 } onClick={() => { - setDuel( - produce((draft) => { - draft.antagonist.gun = gun; - draft.antagonist.shell = gun.shells[0]; - }), - ); + mutateDuel((draft) => { + draft.antagonist!.gun = gun; + draft.antagonist!.shell = gun.shells[0]; + }); }} selected={antagonist.gun.id === gun.id} tier={gun.tier} @@ -226,14 +210,12 @@ export function AntagonistBar({