From 809f807da87c8217e2361242c388c3f258358d3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Tue, 13 Feb 2024 09:40:00 -0600 Subject: [PATCH] feat: consumable timings --- scripts/buildAssets/definitions.ts | 31 ++++++++++--- .../components/Consumables.tsx | 11 +++++ .../components/InfoWithDelta.tsx | 10 ++--- .../{Camouflage.tsx => Miscellaneous.tsx} | 28 ++++++------ src/app/tools/tankopedia/[id]/page.tsx | 6 +-- .../ModuleButtons/ConsumableButton.tsx | 45 ++++++++++++++++++- .../GenericTankComponentButton.tsx | 35 ++++++++++----- .../ModuleButtons/TankComponentButton.tsx | 10 ++--- src/core/blitzkrieg/consumableDefinitions.ts | 2 + src/core/blitzkrieg/equipmentDefinitions.ts | 2 + src/hooks/useDelta.ts | 11 +++++ 11 files changed, 145 insertions(+), 46 deletions(-) rename src/app/tools/tankopedia/[id]/components/Characteristics/components/{Camouflage.tsx => Miscellaneous.tsx} (51%) create mode 100644 src/hooks/useDelta.ts diff --git a/scripts/buildAssets/definitions.ts b/scripts/buildAssets/definitions.ts index cdc54b5bd..4b1a90748 100644 --- a/scripts/buildAssets/definitions.ts +++ b/scripts/buildAssets/definitions.ts @@ -254,8 +254,7 @@ interface OptionalDeviceSlots { interface OptionalDeviceSlotRow { [key: string]: { device0: string; device1: string }; } - -export interface ConsumablesProvisionsCommon { +export interface ConsumablesCommon { [key: string]: { id: number; userString: string; @@ -270,8 +269,28 @@ export interface ConsumablesProvisionsCommon { script: { '#text': string; automatic?: boolean; + cooldown: number; duration?: number; - cooldown?: number; + shotEffect?: string; + bonusValues?: { [key: string]: number }; + } & Record; + }; +} +export interface ProvisionsCommon { + [key: string]: { + id: number; + userString: string; + description: string; + icon: string; + category: string; + tags: string; + vehicleFilter?: { + include: { vehicle: ConsumablesVehicleFilter; nations?: string }; + exclude?: { vehicle: ConsumablesVehicleFilter; nations?: string }; + }; + script: { + '#text': string; + automatic?: boolean; shotEffect?: string; bonusValues?: { [key: string]: number }; } & Record; @@ -337,10 +356,10 @@ export async function definitions(production: boolean) { const optionalDeviceSlots = await readXMLDVPL<{ root: OptionalDeviceSlots; }>(`${DATA}/${POI.optionalDeviceSlots}.dvpl`); - const consumables = await readXMLDVPL<{ root: ConsumablesProvisionsCommon }>( + const consumables = await readXMLDVPL<{ root: ConsumablesCommon }>( `${DATA}/${POI.consumablesCommon}.dvpl`, ); - const provisions = await readXMLDVPL<{ root: ConsumablesProvisionsCommon }>( + const provisions = await readXMLDVPL<{ root: ProvisionsCommon }>( `${DATA}/${POI.provisionsCommon}.dvpl`, ); @@ -793,6 +812,8 @@ export async function definitions(production: boolean) { Object.values(consumables.root).forEach((consumable) => { consumableDefinitions[consumable.id] = { id: consumable.id, + cooldown: consumable.script.cooldown, + duration: consumable.script.duration, name: strings[consumable.userString] ?? missingStrings[consumable.userString] ?? diff --git a/src/app/tools/tankopedia/[id]/components/Characteristics/components/Consumables.tsx b/src/app/tools/tankopedia/[id]/components/Characteristics/components/Consumables.tsx index 6f2de5d54..01ccc1d99 100644 --- a/src/app/tools/tankopedia/[id]/components/Characteristics/components/Consumables.tsx +++ b/src/app/tools/tankopedia/[id]/components/Characteristics/components/Consumables.tsx @@ -3,6 +3,7 @@ import { use } from 'react'; import { ConsumableButton } from '../../../../../../../components/ModuleButtons/ConsumableButton'; import { checkConsumableProvisionInclusivity } from '../../../../../../../core/blitzkrieg/checkConsumableProvisionInclusivity'; import { consumableDefinitions } from '../../../../../../../core/blitzkrieg/consumableDefinitions'; +import { useEquipment } from '../../../../../../../core/blitzkrieg/useEquipment'; import { useDuel } from '../../../../../../../stores/duel'; import { mutateTankopediaTemporary, @@ -22,6 +23,8 @@ export function Consumables() { protagonist.gun, ), ); + const hasConsumableDeliverySystem = useEquipment(118); + const hasHighEndConsumables = useEquipment(101); return ( @@ -33,6 +36,14 @@ export function Consumables() { return ( { - lastValue.current = children; - }); + const delta = useDelta(children); return ( - + {children} ); diff --git a/src/app/tools/tankopedia/[id]/components/Characteristics/components/Camouflage.tsx b/src/app/tools/tankopedia/[id]/components/Characteristics/components/Miscellaneous.tsx similarity index 51% rename from src/app/tools/tankopedia/[id]/components/Characteristics/components/Camouflage.tsx rename to src/app/tools/tankopedia/[id]/components/Characteristics/components/Miscellaneous.tsx index 1ea489369..cd4c20ed2 100644 --- a/src/app/tools/tankopedia/[id]/components/Characteristics/components/Camouflage.tsx +++ b/src/app/tools/tankopedia/[id]/components/Characteristics/components/Miscellaneous.tsx @@ -1,4 +1,4 @@ -import { Heading } from '@radix-ui/themes'; +import { Flex, Heading } from '@radix-ui/themes'; import { CamouflageButton } from '../../../../../../../components/ModuleButtons/CamouflageButton'; import { mutateTankopediaTemporary, @@ -6,23 +6,25 @@ import { } from '../../../../../../../stores/tankopedia'; import { ConfigurationChildWrapper } from './ConfigurationChildWrapper'; -export function Camouflage() { +export function Miscellaneous() { const camouflage = useTankopediaTemporary((state) => state.camouflage); return ( - Camouflage + Miscellaneous - { - mutateTankopediaTemporary((draft) => { - draft.camouflage = !camouflage; - }); - }} - /> + + { + mutateTankopediaTemporary((draft) => { + draft.camouflage = !camouflage; + }); + }} + /> + ); } diff --git a/src/app/tools/tankopedia/[id]/page.tsx b/src/app/tools/tankopedia/[id]/page.tsx index de9d28d9f..f0869d9a8 100644 --- a/src/app/tools/tankopedia/[id]/page.tsx +++ b/src/app/tools/tankopedia/[id]/page.tsx @@ -8,10 +8,10 @@ import { mutateDuel, useDuel } from '../../../../stores/duel'; import { mutateTankopediaTemporary } from '../../../../stores/tankopedia'; import { AntagonistBar } from './components/AntagonistBar'; import { Characteristics } from './components/Characteristics'; -import { Camouflage } from './components/Characteristics/components/Camouflage'; import { Consumables } from './components/Characteristics/components/Consumables'; import { Crew } from './components/Characteristics/components/Crew'; import { Equipments } from './components/Characteristics/components/Equipments'; +import { Miscellaneous } from './components/Characteristics/components/Miscellaneous'; import { Modules } from './components/Characteristics/components/Modules'; import { Provisions } from './components/Characteristics/components/Provisions'; import { TankSandbox } from './components/Model/TankSandbox'; @@ -119,11 +119,11 @@ export default function Page({ params }: { params: { id: string } }) { - + - + diff --git a/src/components/ModuleButtons/ConsumableButton.tsx b/src/components/ModuleButtons/ConsumableButton.tsx index 242ae959c..daf0f3cf4 100644 --- a/src/components/ModuleButtons/ConsumableButton.tsx +++ b/src/components/ModuleButtons/ConsumableButton.tsx @@ -1,19 +1,62 @@ +import { ClockIcon, ReloadIcon } from '@radix-ui/react-icons'; +import { Flex, Text } from '@radix-ui/themes'; import { asset } from '../../core/blitzkrieg/asset'; +import { useDelta } from '../../hooks/useDelta'; import { GenericTankComponentButton } from './GenericTankComponentButton'; import { TankComponentButtonProps } from './TankComponentButton'; interface ConsumableButtonProps extends TankComponentButtonProps { consumable: number; + duration?: number; + cooldown: number; } export function ConsumableButton({ consumable, + cooldown, + duration, ...props }: ConsumableButtonProps) { + const cooldownDelta = useDelta(cooldown); + const durationDelta = useDelta(duration ?? 0); + return ( + > + + {duration && ( + 0 + ? 'tomato' + : undefined + } + > + + + {Math.round(duration)}s + + + )} + 0 + ? 'tomato' + : undefined + } + > + + + {Math.round(cooldown)}s + + + + ); } diff --git a/src/components/ModuleButtons/GenericTankComponentButton.tsx b/src/components/ModuleButtons/GenericTankComponentButton.tsx index 6cf4fce8f..c4df4bf6d 100644 --- a/src/components/ModuleButtons/GenericTankComponentButton.tsx +++ b/src/components/ModuleButtons/GenericTankComponentButton.tsx @@ -12,22 +12,35 @@ interface GenericTankComponentButtonProps extends TankComponentButtonProps { export function GenericTankComponentButton({ icon, iconStyles, + children, ...props }: GenericTankComponentButtonProps) { return ( - - +
+ > + +
+ + {children}
); } diff --git a/src/components/ModuleButtons/TankComponentButton.tsx b/src/components/ModuleButtons/TankComponentButton.tsx index 6cc91df77..cbc87affb 100644 --- a/src/components/ModuleButtons/TankComponentButton.tsx +++ b/src/components/ModuleButtons/TankComponentButton.tsx @@ -18,19 +18,17 @@ export function TankComponentButton({ last = false, rowChild, discriminator, - disabled, children, ...props }: TankComponentButtonProps) { return ( ); } diff --git a/src/core/blitzkrieg/consumableDefinitions.ts b/src/core/blitzkrieg/consumableDefinitions.ts index f15523343..76a417488 100644 --- a/src/core/blitzkrieg/consumableDefinitions.ts +++ b/src/core/blitzkrieg/consumableDefinitions.ts @@ -25,6 +25,8 @@ export type TankFilterDefinition = export interface ConsumableEntry { id: number; name: string; + cooldown: number; + duration?: number; include: TankFilterDefinition[]; exclude?: TankFilterDefinition[]; } diff --git a/src/core/blitzkrieg/equipmentDefinitions.ts b/src/core/blitzkrieg/equipmentDefinitions.ts index 65b032f40..ead52a68c 100644 --- a/src/core/blitzkrieg/equipmentDefinitions.ts +++ b/src/core/blitzkrieg/equipmentDefinitions.ts @@ -25,3 +25,5 @@ export interface EquipmentDefinitions { export const equipmentDefinitions = fetchCdonLz4( asset('definitions/equipment.cdon.lz4'), ); + +equipmentDefinitions.then(console.log); diff --git a/src/hooks/useDelta.ts b/src/hooks/useDelta.ts new file mode 100644 index 000000000..5dc606824 --- /dev/null +++ b/src/hooks/useDelta.ts @@ -0,0 +1,11 @@ +import { useEffect, useRef } from 'react'; + +export function useDelta(value: number) { + const lastValue = useRef(value); + + useEffect(() => { + lastValue.current = value; + }); + + return value - lastValue.current; +}