diff --git a/src/ShipFit/ShipFit.tsx b/src/ShipFit/ShipFit.tsx
index a606f0c..3c260ed 100644
--- a/src/ShipFit/ShipFit.tsx
+++ b/src/ShipFit/ShipFit.tsx
@@ -1,6 +1,5 @@
import React from "react";
-import { EveDataContext } from '../EveDataProvider';
import { ShipSnapshotContext } from '../ShipSnapshotProvider';
import { FitLink } from './FitLink';
@@ -19,37 +18,14 @@ export interface ShipFitProps {
export const ShipFit = (props: ShipFitProps) => {
const radius = props.radius ?? 365;
- const eveData = React.useContext(EveDataContext);
const shipSnapshot = React.useContext(ShipSnapshotContext);
+ const slots = shipSnapshot.slots;
const scaleStyle = {
"--radius": `${radius}px`,
"--scale": `${radius / 365}`
} as React.CSSProperties;
- const slots = {
- "hislot": 0,
- "medslot": 0,
- "lowslot": 0,
- "subsystem": 0,
- "rig": 0,
- };
-
- if (shipSnapshot?.loaded) {
- slots.hislot = shipSnapshot.hull?.attributes.get(eveData?.attributeMapping?.hiSlots || 0)?.value || 0;
- slots.medslot = shipSnapshot.hull?.attributes.get(eveData?.attributeMapping?.medSlots || 0)?.value || 0;
- slots.lowslot = shipSnapshot.hull?.attributes.get(eveData?.attributeMapping?.lowSlots || 0)?.value || 0;
- slots.subsystem = shipSnapshot.hull?.attributes.get(eveData?.attributeMapping?.maxSubSystems || 0)?.value || 0;
- slots.rig = shipSnapshot.hull?.attributes.get(eveData?.attributeMapping?.rigSlots || 0)?.value || 0;
-
- const items = shipSnapshot.items || [];
- for (const item of items) {
- slots.hislot += item.attributes.get(eveData?.attributeMapping?.hiSlotModifier || 0)?.value || 0;
- slots.medslot += item.attributes.get(eveData?.attributeMapping?.medSlotModifier || 0)?.value || 0;
- slots.lowslot += item.attributes.get(eveData?.attributeMapping?.lowSlotModifier || 0)?.value || 0;
- }
- }
-
return
@@ -58,41 +34,41 @@ export const ShipFit = (props: ShipFitProps) => {
- = 1} rotation="-125deg" />
- = 2} rotation="-114deg" />
- = 3} rotation="-103deg" />
- = 4} rotation="-92deg" />
+ = 1} rotation="-125deg" />
+ = 2} rotation="-114deg" />
+ = 3} rotation="-103deg" />
+ = 4} rotation="-92deg" />
- = 1} rotation="-73deg" />
- = 2} rotation="-63deg" />
- = 3} rotation="-53deg" />
+ = 1} rotation="-73deg" />
+ = 2} rotation="-63deg" />
+ = 3} rotation="-53deg" />
- = 1} rotation="-34deg" />
- = 2} rotation="-24deg" />
- = 3} rotation="-14deg" />
- = 4} rotation="-4deg" />
- = 5} rotation="6deg" />
- = 6} rotation="16deg" />
- = 7} rotation="26deg" />
- = 8} rotation="36deg" />
+ = 1} rotation="-34deg" />
+ = 2} rotation="-24deg" />
+ = 3} rotation="-14deg" />
+ = 4} rotation="-4deg" />
+ = 5} rotation="6deg" />
+ = 6} rotation="16deg" />
+ = 7} rotation="26deg" />
+ = 8} rotation="36deg" />
- = 1} rotation="55deg" />
- = 2} rotation="65deg" />
- = 3} rotation="75deg" />
- = 4} rotation="85deg" />
- = 5} rotation="95deg" />
- = 6} rotation="105deg" />
- = 7} rotation="115deg" />
- = 8} rotation="125deg" />
+ = 1} rotation="55deg" />
+ = 2} rotation="65deg" />
+ = 3} rotation="75deg" />
+ = 4} rotation="85deg" />
+ = 5} rotation="95deg" />
+ = 6} rotation="105deg" />
+ = 7} rotation="115deg" />
+ = 8} rotation="125deg" />
- = 1} rotation="144deg" />
- = 2} rotation="154deg" />
- = 3} rotation="164deg" />
- = 4} rotation="174deg" />
- = 5} rotation="184deg" />
- = 6} rotation="194deg" />
- = 7} rotation="204deg" />
- = 8} rotation="214deg" />
+ = 1} rotation="144deg" />
+ = 2} rotation="154deg" />
+ = 3} rotation="164deg" />
+ = 4} rotation="174deg" />
+ = 5} rotation="184deg" />
+ = 6} rotation="194deg" />
+ = 7} rotation="204deg" />
+ = 8} rotation="214deg" />
};
diff --git a/src/ShipSnapshotProvider/ShipSnapshotProvider.tsx b/src/ShipSnapshotProvider/ShipSnapshotProvider.tsx
index fbc5492..57ea897 100644
--- a/src/ShipSnapshotProvider/ShipSnapshotProvider.tsx
+++ b/src/ShipSnapshotProvider/ShipSnapshotProvider.tsx
@@ -1,6 +1,7 @@
import React from "react";
import { DogmaEngineContext } from '../DogmaEngineProvider';
+import { EveDataContext } from "../EveDataProvider";
export interface ShipSnapshotItemAttributeEffect {
operator: string,
@@ -38,10 +39,21 @@ export interface EsiFit {
}[];
}
+interface ShipSnapshotSlots {
+ hislot: number;
+ medslot: number;
+ lowslot: number;
+ subsystem: number;
+ rig: number;
+};
+
+export type ShipSnapshotSlotsType = keyof ShipSnapshotSlots;
+
interface ShipSnapshot {
loaded?: boolean;
hull?: ShipSnapshotItem;
items?: ShipSnapshotItem[];
+ slots: ShipSnapshotSlots;
fit?: EsiFit;
@@ -52,6 +64,13 @@ interface ShipSnapshot {
export const ShipSnapshotContext = React.createContext({
loaded: undefined,
+ slots: {
+ "hislot": 0,
+ "medslot": 0,
+ "lowslot": 0,
+ "subsystem": 0,
+ "rig": 0,
+ },
changeHull: () => {},
changeFit: () => {},
setItemState: () => {},
@@ -70,8 +89,16 @@ export interface ShipSnapshotProps {
* Calculates the current attrbitues and applied effects of a ship fit.
*/
export const ShipSnapshotProvider = (props: ShipSnapshotProps) => {
+ const eveData = React.useContext(EveDataContext);
const [shipSnapshot, setShipSnapshot] = React.useState({
loaded: undefined,
+ slots: {
+ "hislot": 0,
+ "medslot": 0,
+ "lowslot": 0,
+ "subsystem": 0,
+ "rig": 0,
+ },
changeHull: () => {},
changeFit: () => {},
setItemState: () => {},
@@ -80,10 +107,10 @@ export const ShipSnapshotProvider = (props: ShipSnapshotProps) => {
const dogmaEngine = React.useContext(DogmaEngineContext);
const setItemState = React.useCallback((flag: number, state: string) => {
- if (!currentFit) return;
+ if (currentFit === undefined) return;
setCurrentFit((oldFit: EsiFit | undefined) => {
- if (!oldFit) return oldFit;
+ if (oldFit === undefined) return undefined;
return {
...oldFit,
@@ -112,20 +139,42 @@ export const ShipSnapshotProvider = (props: ShipSnapshotProps) => {
React.useEffect(() => {
if (!dogmaEngine.loaded) return;
- if (!currentFit || !props.skills) return;
+ if (currentFit === undefined || props.skills === undefined) return;
const snapshot = dogmaEngine.engine?.calculate(currentFit, props.skills);
+ const slots = {
+ "hislot": 0,
+ "medslot": 0,
+ "lowslot": 0,
+ "subsystem": 0,
+ "rig": 0,
+ };
+
+ slots.hislot = snapshot.hull.attributes.get(eveData?.attributeMapping?.hiSlots || 0)?.value || 0;
+ slots.medslot = snapshot.hull.attributes.get(eveData?.attributeMapping?.medSlots || 0)?.value || 0;
+ slots.lowslot = snapshot.hull.attributes.get(eveData?.attributeMapping?.lowSlots || 0)?.value || 0;
+ slots.subsystem = snapshot.hull.attributes.get(eveData?.attributeMapping?.maxSubSystems || 0)?.value || 0;
+ slots.rig = snapshot.hull?.attributes.get(eveData?.attributeMapping?.rigSlots || 0)?.value || 0;
+
+ const items = snapshot.items;
+ for (const item of items) {
+ slots.hislot += item.attributes.get(eveData?.attributeMapping?.hiSlotModifier || 0)?.value || 0;
+ slots.medslot += item.attributes.get(eveData?.attributeMapping?.medSlotModifier || 0)?.value || 0;
+ slots.lowslot += item.attributes.get(eveData?.attributeMapping?.lowSlotModifier || 0)?.value || 0;
+ }
+
setShipSnapshot({
loaded: true,
hull: snapshot.hull,
items: snapshot.items,
+ slots,
fit: currentFit,
changeHull,
changeFit: setCurrentFit,
setItemState,
});
- }, [dogmaEngine, currentFit, props.skills, changeHull, setItemState]);
+ }, [eveData, dogmaEngine, currentFit, props.skills, changeHull, setItemState]);
React.useEffect(() => {
setCurrentFit(props.fit);
diff --git a/src/ShipSnapshotProvider/index.ts b/src/ShipSnapshotProvider/index.ts
index c498879..fb958f9 100644
--- a/src/ShipSnapshotProvider/index.ts
+++ b/src/ShipSnapshotProvider/index.ts
@@ -1,2 +1,2 @@
export { ShipSnapshotContext, ShipSnapshotProvider } from "./ShipSnapshotProvider";
-export type { EsiFit, ShipSnapshotItem, ShipSnapshotItemAttribute, ShipSnapshotItemAttributeEffect } from "./ShipSnapshotProvider";
+export type { EsiFit, ShipSnapshotItem, ShipSnapshotItemAttribute, ShipSnapshotItemAttributeEffect, ShipSnapshotSlotsType } from "./ShipSnapshotProvider";