Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unbreak "fit:v1" links #131

Merged
merged 1 commit into from
May 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 48 additions & 11 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,58 @@ 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 item = line.split(",");
return {
slot: esiFlagToEsfSlot[parseInt(item[0])],
typeId: parseInt(item[1]),
state: "Active",
};
});
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[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,
};
}
Loading