From db890905a2ced2ac7587120ad54c4f8fa91be950 Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Mon, 20 May 2024 21:25:03 +0200 Subject: [PATCH] fix: unbreak "fit:v1" links They did have drones and cargo stored, so process them correctly. --- .../ImportEveShipFitHash/DecodeEsfFitV1.tsx | 40 ++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/src/hooks/ImportEveShipFitHash/DecodeEsfFitV1.tsx b/src/hooks/ImportEveShipFitHash/DecodeEsfFitV1.tsx index b008aa0..739a3f0 100644 --- a/src/hooks/ImportEveShipFitHash/DecodeEsfFitV1.tsx +++ b/src/hooks/ImportEveShipFitHash/DecodeEsfFitV1.tsx @@ -1,4 +1,4 @@ -import { EsfFit, EsfModule } from "@/providers/CurrentFitProvider"; +import { EsfCargo, EsfDrone, EsfFit, EsfModule } from "@/providers/CurrentFitProvider"; import { decompress } from "./Decompress"; import { esiFlagToEsfSlot } from "./EsiFlags"; @@ -9,21 +9,49 @@ export async function decodeEsfFitV1(fitCompressed: string): Promise { + const modules = fitLines.slice(1).map((line): EsfModule | undefined => { const item = line.split(","); + const flag = parseInt(item[0]); + if (esiFlagToEsfSlot[flag] === undefined) return undefined; // Skip anything not modules. + return { - slot: esiFlagToEsfSlot[parseInt(item[0])], + slot: esiFlagToEsfSlot[flag], typeId: parseInt(item[1]), state: "Active", }; - }); + }).filter((item): item is EsfModule => item !== undefined); + + const drones = fitLines.slice(1).map((line): EsfDrone | undefined => { + const item = line.split(","); + const flag = parseInt(item[0]); + if (flag != 87) return undefined; // Skip anything not drones. + + return { + typeId: parseInt(item[1]), + states: { + Active: parseInt(item[2]), + Passive: 0, + }, + }; + }).filter((item): item is EsfDrone => item !== undefined); + + const cargo = fitLines.slice(1).map((line): EsfCargo | undefined => { + const item = line.split(","); + const flag = parseInt(item[0]); + if (flag != 5) return undefined; // Skip anything not cargo. + + return { + typeId: parseInt(item[1]), + quantity: parseInt(item[2]), + }; + }).filter((item): item is EsfCargo => item !== undefined); return { shipTypeId: parseInt(fitHeader[0]), name: fitHeader[1], description: fitHeader[2], modules, - drones: [], // v1 didn't store drones. - cargo: [], // v2 didn't store cargo. + drones, + cargo, }; }