diff --git a/assets/js/hooks/Mapper/components/map/constants.ts b/assets/js/hooks/Mapper/components/map/constants.ts index bd39c233..8e9c7bbf 100644 --- a/assets/js/hooks/Mapper/components/map/constants.ts +++ b/assets/js/hooks/Mapper/components/map/constants.ts @@ -750,6 +750,14 @@ export const SHIP_SIZES_SIZE = { [ShipSizeStatus.capital]: '2M', }; +export const SHIP_MASSES_SIZE: Record = { + 5_000_000: ShipSizeStatus.small, + 62_000_000: ShipSizeStatus.medium, + 375_000_000: ShipSizeStatus.large, + 1_000_000_000: ShipSizeStatus.freight, + 2_000_000_000: ShipSizeStatus.capital, +}; + export const SHIP_SIZES_DESCRIPTION = { [ShipSizeStatus.small]: 'Frigate wormhole - up to Destroyer | 5K t.', [ShipSizeStatus.medium]: 'Cruise wormhole - up to Battlecruiser | 62K t.', diff --git a/assets/js/hooks/Mapper/components/mapInterface/components/SystemLinkSignatureDialog/SystemLinkSignatureDialog.tsx b/assets/js/hooks/Mapper/components/mapInterface/components/SystemLinkSignatureDialog/SystemLinkSignatureDialog.tsx index 9d9ae43e..cd5f06bd 100644 --- a/assets/js/hooks/Mapper/components/mapInterface/components/SystemLinkSignatureDialog/SystemLinkSignatureDialog.tsx +++ b/assets/js/hooks/Mapper/components/mapInterface/components/SystemLinkSignatureDialog/SystemLinkSignatureDialog.tsx @@ -2,7 +2,7 @@ import { useCallback, useEffect, useRef } from 'react'; import { Dialog } from 'primereact/dialog'; import { OutCommand } from '@/hooks/Mapper/types/mapHandlers.ts'; -import { SystemSignature } from '@/hooks/Mapper/types'; +import { SystemSignature, TimeStatus } from '@/hooks/Mapper/types'; import { useMapRootState } from '@/hooks/Mapper/mapRootProvider'; import { CommandLinkSignatureToSystem } from '@/hooks/Mapper/types'; import { SystemSignaturesContent } from '@/hooks/Mapper/components/mapInterface/widgets/SystemSignatures/SystemSignaturesContent'; @@ -12,6 +12,8 @@ import { COSMIC_SIGNATURE, } from '@/hooks/Mapper/components/mapInterface/widgets/SystemSignatures/SystemSignatureSettingsDialog'; import { SignatureGroup } from '@/hooks/Mapper/types'; +import { parseSignatureCustomInfo } from '@/hooks/Mapper/helpers/parseSignatureCustomInfo'; +import { getWhSize } from '@/hooks/Mapper/helpers/getWhSize'; interface SystemLinkSignatureDialogProps { data: CommandLinkSignatureToSystem; @@ -25,7 +27,10 @@ const signatureSettings: Setting[] = [ ]; export const SystemLinkSignatureDialog = ({ data, setVisible }: SystemLinkSignatureDialogProps) => { - const { outCommand } = useMapRootState(); + const { + outCommand, + data: { wormholes }, + } = useMapRootState(); const ref = useRef({ outCommand }); ref.current = { outCommand }; @@ -35,20 +40,44 @@ export const SystemLinkSignatureDialog = ({ data, setVisible }: SystemLinkSignat }, [setVisible]); const handleSelect = useCallback( - (signature: SystemSignature) => { + async (signature: SystemSignature) => { if (!signature) { return; } const { outCommand } = ref.current; - outCommand({ + await outCommand({ type: OutCommand.linkSignatureToSystem, data: { ...data, signature_eve_id: signature.eve_id, }, }); + + if (parseSignatureCustomInfo(signature.custom_info).isEOL === true) { + await outCommand({ + type: OutCommand.updateConnectionTimeStatus, + data: { + source: data.solar_system_source, + target: data.solar_system_target, + value: TimeStatus.eol, + }, + }); + } + + const whShipSize = getWhSize(wormholes, signature.type); + if (whShipSize) { + await outCommand({ + type: OutCommand.updateConnectionShipSizeType, + data: { + source: data.solar_system_source, + target: data.solar_system_target, + value: whShipSize, + }, + }); + } + setVisible(false); }, [data, setVisible], diff --git a/assets/js/hooks/Mapper/components/mapRootContent/components/SignatureSettings/SignatureSettings.tsx b/assets/js/hooks/Mapper/components/mapRootContent/components/SignatureSettings/SignatureSettings.tsx index 2755595b..e17cf428 100644 --- a/assets/js/hooks/Mapper/components/mapRootContent/components/SignatureSettings/SignatureSettings.tsx +++ b/assets/js/hooks/Mapper/components/mapRootContent/components/SignatureSettings/SignatureSettings.tsx @@ -1,6 +1,6 @@ import { Dialog } from 'primereact/dialog'; import { useCallback, useEffect } from 'react'; -import { OutCommand, SignatureGroup, SystemSignature } from '@/hooks/Mapper/types'; +import { OutCommand, SignatureGroup, SystemSignature, TimeStatus } from '@/hooks/Mapper/types'; import { Controller, FormProvider, useForm } from 'react-hook-form'; import { SignatureGroupContent, @@ -10,6 +10,7 @@ import { InputText } from 'primereact/inputtext'; import { SystemsSettingsProvider } from '@/hooks/Mapper/components/mapRootContent/components/SignatureSettings/Provider.tsx'; import { Button } from 'primereact/button'; import { useMapRootState } from '@/hooks/Mapper/mapRootProvider'; +import { getWhSize } from '@/hooks/Mapper/helpers/getWhSize'; type SystemSignaturePrepared = Omit & { linked_system: string }; @@ -21,7 +22,10 @@ export interface MapSettingsProps { } export const SignatureSettings = ({ systemId, show, onHide, signatureData }: MapSettingsProps) => { - const { outCommand } = useMapRootState(); + const { + outCommand, + data: { wormholes }, + } = useMapRootState(); const handleShow = async () => {}; const signatureForm = useForm>({}); @@ -47,6 +51,31 @@ export const SignatureSettings = ({ systemId, show, onHide, signatureData }: Map solar_system_target: values.linked_system, }, }); + + if (values.isEOL) { + await outCommand({ + type: OutCommand.updateConnectionTimeStatus, + data: { + source: systemId, + target: values.linked_system, + value: TimeStatus.eol, + }, + }); + } + + if (values.type) { + const whShipSize = getWhSize(wormholes, values.type); + if (whShipSize) { + outCommand({ + type: OutCommand.updateConnectionShipSizeType, + data: { + source: systemId, + target: values.linked_system, + value: whShipSize, + }, + }); + } + } } out = { diff --git a/assets/js/hooks/Mapper/helpers/getWhSize.ts b/assets/js/hooks/Mapper/helpers/getWhSize.ts new file mode 100644 index 00000000..1c35a32a --- /dev/null +++ b/assets/js/hooks/Mapper/helpers/getWhSize.ts @@ -0,0 +1,13 @@ +import { SHIP_MASSES_SIZE } from '../components/map/constants'; +import { ShipSizeStatus } from '../types/connection'; +import { WormholeDataRaw } from '../types/wormholes'; + +export const getWhSize = (whDatas: WormholeDataRaw[], whType: string): ShipSizeStatus | null => { + if (whType === 'K162' || whType == null) return null; + + const wormholeData = whDatas.find(wh => wh.name === whType); + + if (!wormholeData?.max_mass_per_jump) return null; + + return SHIP_MASSES_SIZE[wormholeData.max_mass_per_jump] ?? ShipSizeStatus.large; +};