Files
wanderer/assets/js/hooks/Mapper/components/contexts/hooks/useJumpPlannerMenu/useJumpPlannerMenu.tsx
Aleksei Chichenkov d8222d83f0 Refactoring and fixing problems (#317)
* fix(Map): fix design of kills widget, fix design of signatures widget - refactor a lot of code, fixed problem with tooltip blinking

* fix(Map): refactor Tracking dialog, refactor Activity tracker, refactor codebase and some styles

* fix(Core): don't count character passage on manual add connection

* refactor(Core): improved characters tracking API

* fix(Core): fixed link signature to system on 'leads to' set

* fix(Map): Refactor map settings and prepared it to easier using

* fix(Map): Add support new command for following update

* fix(Map): Add support new command for main update

* refactor(Core): Reduce map init data by using cached system static data

* refactor(Core): Reduce map init data by extract signatures loading to a separate event

* fix(Core): adjusted IP rate limits

* fix(Map): Update design of tracking characters. Added icons for following and main. Added ability to see that character on the station or structure

---------

Co-authored-by: achichenkov <aleksei.chichenkov@telleqt.ai>
Co-authored-by: Dmitry Popov <dmitriypopovsamara@gmail.com>
2025-04-11 23:17:53 +04:00

130 lines
4.5 KiB
TypeScript

import { MenuItem } from 'primereact/menuitem';
import { PrimeIcons } from 'primereact/api';
import { useCallback } from 'react';
import { isPossibleSpace } from '@/hooks/Mapper/components/map/helpers/isKnownSpace.ts';
import { Route } from '@/hooks/Mapper/types/routes.ts';
import { SolarSystemRawType, SolarSystemStaticInfoRaw } from '@/hooks/Mapper/types';
import { SOLAR_SYSTEM_CLASS_IDS } from '@/hooks/Mapper/components/map/constants.ts';
import { getSystemStaticInfo } from '@/hooks/Mapper/mapRootProvider/hooks/useLoadSystemStatic';
const imperialSpace = [SOLAR_SYSTEM_CLASS_IDS.hs, SOLAR_SYSTEM_CLASS_IDS.ls, SOLAR_SYSTEM_CLASS_IDS.ns];
const criminalSpace = [SOLAR_SYSTEM_CLASS_IDS.ls, SOLAR_SYSTEM_CLASS_IDS.ns];
enum JUMP_SHIP_TYPE {
BLACK_OPS = 'Marshal',
JUMP_FREIGHTER = 'Anshar',
RORQUAL = 'Rorqual',
CAPITAL = 'Thanatos',
SUPER_CAPITAL = 'Avatar',
}
export const openJumpPlan = (jumpShipType: JUMP_SHIP_TYPE, from: string, to: string) => {
return window.open(`https://evemaps.dotlan.net/jump/${jumpShipType},544/${from}:${to}`, '_blank');
};
const BRACKET_ICONS = {
npcsuperCarrier_32: '/icons/brackets/npcsuperCarrier_32.png',
carrier_32: '/icons/brackets/carrier_32.png',
battleship_32: '/icons/brackets/battleship_32.png',
freighter_32: '/icons/brackets/freighter_32.png',
};
const renderIcon = (icon: string) => {
return (
<div className="flex justify-center items-center mr-1.5 pt-px">
<img src={icon} style={{ width: 20, height: 20 }} />
</div>
);
};
export const useJumpPlannerMenu = (
systems: SolarSystemRawType[],
systemIdFrom?: string | undefined,
): ((systemId: SolarSystemStaticInfoRaw, routes: Route[]) => MenuItem[]) => {
return useCallback(
(destination: SolarSystemStaticInfoRaw) => {
if (!destination || !systemIdFrom) {
return [];
}
const origin = getSystemStaticInfo(systemIdFrom);
if (!origin) {
return [];
}
const isShowBOorJumpFreighter =
isPossibleSpace(imperialSpace, origin.system_class) && isPossibleSpace(criminalSpace, destination.system_class);
const isShowCapital =
isPossibleSpace(criminalSpace, origin.system_class) && isPossibleSpace(criminalSpace, destination.system_class);
if (!isShowBOorJumpFreighter && !isShowCapital) {
return [];
}
return [
{
label: 'In Jump Planner',
icon: PrimeIcons.SEND,
items: [
...(isShowBOorJumpFreighter
? [
{
label: 'Black Ops',
icon: renderIcon(BRACKET_ICONS.battleship_32),
command: () => {
openJumpPlan(JUMP_SHIP_TYPE.BLACK_OPS, origin.solar_system_name, destination.solar_system_name);
},
},
{
label: 'Jump Freighter',
icon: renderIcon(BRACKET_ICONS.freighter_32),
command: () => {
openJumpPlan(
JUMP_SHIP_TYPE.JUMP_FREIGHTER,
origin.solar_system_name,
destination.solar_system_name,
);
},
},
{
label: 'Rorqual',
icon: renderIcon(BRACKET_ICONS.freighter_32),
command: () => {
openJumpPlan(JUMP_SHIP_TYPE.RORQUAL, origin.solar_system_name, destination.solar_system_name);
},
},
]
: []),
...(isShowCapital
? [
{
label: 'Capital',
icon: renderIcon(BRACKET_ICONS.carrier_32),
command: () => {
openJumpPlan(JUMP_SHIP_TYPE.CAPITAL, origin.solar_system_name, destination.solar_system_name);
},
},
{
label: 'Super Capital',
icon: renderIcon(BRACKET_ICONS.npcsuperCarrier_32),
command: () => {
openJumpPlan(
JUMP_SHIP_TYPE.SUPER_CAPITAL,
origin.solar_system_name,
destination.solar_system_name,
);
},
},
]
: []),
],
},
];
},
[systems, systemIdFrom],
);
};