Skip to content

Commit

Permalink
fix: unbreak "fit:v1" links
Browse files Browse the repository at this point in the history
They did have drones and cargo stored, so process them correctly.
  • Loading branch information
TrueBrain committed May 20, 2024
1 parent e070121 commit db89090
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions src/hooks/ImportEveShipFitHash/DecodeEsfFitV1.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -9,21 +9,49 @@ export async function decodeEsfFitV1(fitCompressed: string): Promise<EsfFit | nu
const fitLines = fitEncoded.trim().split("\n");
const fitHeader = fitLines[0].split(",");

const modules = fitLines.slice(1).map((line): EsfModule => {
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,
};
}

0 comments on commit db89090

Please sign in to comment.