From fc5ba2585cd2764f252336255571a755fcc8e97f Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Sat, 25 May 2024 15:10:32 +0200 Subject: [PATCH] feat: allow filtering modules for hull restrictions (#134) --- .../HardwareListing/HardwareListing.tsx | 98 +++++++++++++++++-- src/components/Icon/Icon.tsx | 1 + 2 files changed, 92 insertions(+), 7 deletions(-) diff --git a/src/components/HardwareListing/HardwareListing.tsx b/src/components/HardwareListing/HardwareListing.tsx index 5a0d112..31057cc 100644 --- a/src/components/HardwareListing/HardwareListing.tsx +++ b/src/components/HardwareListing/HardwareListing.tsx @@ -37,8 +37,9 @@ interface Filter { lowslot: boolean; medslot: boolean; hislot: boolean; - rig_subsystem: boolean; + rigSubsystem: boolean; drone: boolean; + hullRestriction: boolean; moduleWithCharge: ModuleCharge | undefined; } @@ -121,8 +122,9 @@ export const HardwareListing = () => { lowslot: false, medslot: false, hislot: false, - rig_subsystem: false, + rigSubsystem: false, drone: false, + hullRestriction: false, moduleWithCharge: undefined, }); const [selection, setSelection] = React.useState<"modules" | "charges">("modules"); @@ -218,13 +220,89 @@ export const HardwareListing = () => { if (slotType === undefined) continue; - if (filter.lowslot || filter.medslot || filter.hislot || filter.rig_subsystem || filter.drone) { + if (filter.lowslot || filter.medslot || filter.hislot || filter.rigSubsystem || filter.drone) { if (slotType === "Low" && !filter.lowslot) continue; if (slotType === "Medium" && !filter.medslot) continue; if (slotType === "High" && !filter.hislot) continue; - if ((slotType === "Rig" || slotType === "SubSystem") && !filter.rig_subsystem) continue; + if ((slotType === "Rig" || slotType === "SubSystem") && !filter.rigSubsystem) continue; if (module.categoryID === 18 && !filter.drone) continue; } + + if (filter.hullRestriction && statistics !== null) { + if (slotType === "Rig") { + const attributeRigSize = eveData.attributeMapping.rigSize; + const moduleRigSize = eveData.typeDogma[typeId]?.dogmaAttributes.find( + (attr) => attr.attributeID === attributeRigSize, + )?.value; + const shipRigSize = statistics.hull.attributes.get(attributeRigSize)?.value; + + if (moduleRigSize !== shipRigSize) continue; + } else if (slotType === "DroneBay") { + if (statistics.hull.attributes.get(eveData.attributeMapping.droneBandwidth)?.value === 0) continue; + } else { + const shipType = statistics.hull.type_id; + + const volume = module.volume ?? 0; + if (volume >= 3500) { + /* Modules with a volume of 3500 are considered capitals. */ + const isCapitalSize = eveData.typeDogma[shipType]?.dogmaAttributes.find( + (attr) => attr.attributeID === eveData.attributeMapping.isCapitalSize, + )?.value; + + if (isCapitalSize === undefined || isCapitalSize === 0) continue; + } + + const shipGroup = eveData.typeIDs[shipType]?.groupID; + + const canFitShipType = eveData.typeDogma[typeId]?.dogmaAttributes.filter( + (attr) => + attr.attributeID === eveData.attributeMapping.fitsToShipType || + attr.attributeID === eveData.attributeMapping.canFitShipType1 || + attr.attributeID === eveData.attributeMapping.canFitShipType2 || + attr.attributeID === eveData.attributeMapping.canFitShipType3 || + attr.attributeID === eveData.attributeMapping.canFitShipType4 || + attr.attributeID === eveData.attributeMapping.canFitShipType5 || + attr.attributeID === eveData.attributeMapping.canFitShipType6 || + attr.attributeID === eveData.attributeMapping.canFitShipType7 || + attr.attributeID === eveData.attributeMapping.canFitShipType8 || + attr.attributeID === eveData.attributeMapping.canFitShipType9 || + attr.attributeID === eveData.attributeMapping.canFitShipType10 || + attr.attributeID === eveData.attributeMapping.canFitShipType11, + ); + /* If there is a restriction, check if this ship matches. */ + if (canFitShipType.length > 0) { + if (canFitShipType.filter((attr) => attr.value === shipType).length === 0) continue; + } + + const canFitShipGroup = eveData.typeDogma[typeId]?.dogmaAttributes.filter( + (attr) => + attr.attributeID === eveData.attributeMapping.canFitShipGroup01 || + attr.attributeID === eveData.attributeMapping.canFitShipGroup02 || + attr.attributeID === eveData.attributeMapping.canFitShipGroup03 || + attr.attributeID === eveData.attributeMapping.canFitShipGroup04 || + attr.attributeID === eveData.attributeMapping.canFitShipGroup05 || + attr.attributeID === eveData.attributeMapping.canFitShipGroup06 || + attr.attributeID === eveData.attributeMapping.canFitShipGroup07 || + attr.attributeID === eveData.attributeMapping.canFitShipGroup08 || + attr.attributeID === eveData.attributeMapping.canFitShipGroup09 || + attr.attributeID === eveData.attributeMapping.canFitShipGroup10 || + attr.attributeID === eveData.attributeMapping.canFitShipGroup11 || + attr.attributeID === eveData.attributeMapping.canFitShipGroup12 || + attr.attributeID === eveData.attributeMapping.canFitShipGroup13 || + attr.attributeID === eveData.attributeMapping.canFitShipGroup14 || + attr.attributeID === eveData.attributeMapping.canFitShipGroup15 || + attr.attributeID === eveData.attributeMapping.canFitShipGroup16 || + attr.attributeID === eveData.attributeMapping.canFitShipGroup17 || + attr.attributeID === eveData.attributeMapping.canFitShipGroup18 || + attr.attributeID === eveData.attributeMapping.canFitShipGroup19 || + attr.attributeID === eveData.attributeMapping.canFitShipGroup20, + ); + /* If there is a restriction, check if this ship matches. */ + if (canFitShipGroup.length > 0) { + if (canFitShipGroup.filter((attr) => attr.value === shipGroup).length === 0) continue; + } + } + } } else { if (filter.moduleWithCharge !== undefined) { /* If the module has size restrictions, ensure the charge matches. */ @@ -340,7 +418,7 @@ export const HardwareListing = () => { charges: newChargeGroups, modules: newModuleGroups, }; - }, [eveData, search, filter]); + }, [eveData, search, filter, statistics]); /* If the moduleWithCharge filter was set, validate if it is still valid. */ if ( @@ -378,8 +456,8 @@ export const HardwareListing = () => { setFilter({ ...filter, rig_subsystem: !filter.rig_subsystem })} + className={clsx({ [styles.selected]: filter.rigSubsystem })} + onClick={() => setFilter({ ...filter, rigSubsystem: !filter.rigSubsystem })} > @@ -389,6 +467,12 @@ export const HardwareListing = () => { > + setFilter({ ...filter, hullRestriction: !filter.hullRestriction })} + > + +
{Object.values(modulesWithCharges) diff --git a/src/components/Icon/Icon.tsx b/src/components/Icon/Icon.tsx index 83186ef..c3d0c78 100644 --- a/src/components/Icon/Icon.tsx +++ b/src/components/Icon/Icon.tsx @@ -20,6 +20,7 @@ const iconMapping = { "fitting-drones": "texture/classes/fitting/filtericondrones.png", "fitting-hislot": "texture/classes/fitting/filtericonhighslot.png", "fitting-hull": "texture/classes/fitting/tabfittings.png", + "fitting-hull-restriction": "texture/classes/fitting/tabfittings.png", "fitting-local": "texture/windowicons/note.png", "fitting-lowslot": "texture/classes/fitting/filtericonlowslot.png", "fitting-medslot": "texture/classes/fitting/filtericonmediumslot.png",