-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: import/show/change cargobay (#143)
- Loading branch information
Showing
13 changed files
with
383 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
.cargoBay { | ||
background-color: #111111; | ||
border: 1px solid #333333; | ||
color: #c5c5c5; | ||
font-size: 15px; | ||
padding: 5px; | ||
position: relative; | ||
} | ||
|
||
.cargoBayEntry { | ||
display: flex; | ||
height: 32px; | ||
padding: 4px; | ||
} | ||
.cargoBayEntry:hover { | ||
background-color: #321d1d; | ||
} | ||
|
||
.cargoBayEntry > div { | ||
margin-right: 8px; | ||
} | ||
|
||
.cargoBayEntry .middle { | ||
flex-grow: 1; | ||
} | ||
|
||
.cargoBayEntry .amount { | ||
line-height: 32px; | ||
text-align: right; | ||
width: 50px; | ||
} | ||
|
||
.cargoBayEntry .name { | ||
line-height: 32px; | ||
text-align: center; | ||
} | ||
|
||
.cargoBayEntry .close { | ||
color: #909090; | ||
cursor: pointer; | ||
line-height: 32px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import React from "react"; | ||
|
||
import { fitArgType } from "../../../.storybook/fits"; | ||
import { useFitSelection, withDecoratorFull } from "../../../.storybook/helpers"; | ||
|
||
import { EsfFit } from "@/providers/CurrentFitProvider"; | ||
|
||
import { CargoBay } from "./"; | ||
|
||
type StoryProps = React.ComponentProps<typeof CargoBay> & { fit: EsfFit | null; width: number }; | ||
|
||
const meta: Meta<StoryProps> = { | ||
component: CargoBay, | ||
tags: ["autodocs"], | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<StoryProps>; | ||
|
||
export const Default: Story = { | ||
argTypes: { | ||
fit: fitArgType, | ||
}, | ||
args: { | ||
fit: null, | ||
width: 730, | ||
}, | ||
decorators: [withDecoratorFull], | ||
render: ({ fit, width, ...args }) => { | ||
useFitSelection(fit); | ||
|
||
return ( | ||
<div style={{ width: width, height: width }}> | ||
<CargoBay {...args} /> | ||
</div> | ||
); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import React from "react"; | ||
|
||
import { useFitManager } from "@/providers/FitManagerProvider"; | ||
import { useEveData } from "@/providers/EveDataProvider"; | ||
import { EsfCargo, useCurrentFit } from "@/providers/CurrentFitProvider"; | ||
import { CalculationSlotType } from "@/providers/DogmaEngineProvider"; | ||
|
||
import styles from "./CargoBay.module.css"; | ||
|
||
const OnItemDragStart = ( | ||
typeId: number, | ||
slotType?: CalculationSlotType, | ||
): ((e: React.DragEvent<HTMLDivElement>) => void) => { | ||
return (e: React.DragEvent<HTMLDivElement>) => { | ||
const img = new Image(); | ||
img.src = `https://images.evetech.net/types/${typeId}/icon?size=64`; | ||
e.dataTransfer.setDragImage(img, 32, 32); | ||
e.dataTransfer.setData("application/esf-type-id", typeId.toString()); | ||
if (slotType !== undefined) { | ||
e.dataTransfer.setData("application/esf-slot-type", slotType); | ||
} | ||
}; | ||
}; | ||
|
||
const CargoBayEntry = ({ name, cargo }: { name: string; cargo: EsfCargo }) => { | ||
const eveData = useEveData(); | ||
const fitManager = useFitManager(); | ||
|
||
const onRemove = React.useCallback(() => { | ||
fitManager.removeCargo(cargo.typeId); | ||
}, [fitManager, cargo]); | ||
|
||
let slotType: CalculationSlotType | undefined = undefined; | ||
if (eveData?.typeIDs[cargo.typeId]?.categoryID === 18) { | ||
slotType = "DroneBay"; | ||
} else if (eveData?.typeIDs[cargo.typeId]?.categoryID === 8) { | ||
slotType = "Charge"; | ||
} else { | ||
slotType = eveData?.typeDogma[cargo.typeId]?.dogmaEffects | ||
.map((effect) => { | ||
switch (effect.effectID) { | ||
case eveData.effectMapping.loPower: | ||
return "Low"; | ||
case eveData.effectMapping.medPower: | ||
return "Medium"; | ||
case eveData.effectMapping.hiPower: | ||
return "High"; | ||
case eveData.effectMapping.rigSlot: | ||
return "Rig"; | ||
case eveData.effectMapping.subSystem: | ||
return "SubSystem"; | ||
} | ||
}) | ||
.filter((slot) => slot !== undefined)[0]; | ||
} | ||
|
||
return ( | ||
<div className={styles.cargoBayEntry} onDragStart={OnItemDragStart(cargo.typeId, slotType)} draggable> | ||
<div className={styles.amount}>{cargo.quantity} x</div> | ||
<div> | ||
<img src={`https://images.evetech.net/types/${cargo.typeId}/icon?size=32`} /> | ||
</div> | ||
<div className={styles.middle}> | ||
<div className={styles.name}>{name}</div> | ||
</div> | ||
<div className={styles.close} onClick={onRemove}> | ||
X | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export const CargoBay = () => { | ||
const eveData = useEveData(); | ||
const currentFit = useCurrentFit(); | ||
|
||
if (eveData === null || currentFit?.fit === null) return <></>; | ||
|
||
/* Fetch name of all cargo items. */ | ||
const cargoList: { name: string; item: EsfCargo }[] = []; | ||
for (const item of currentFit.fit.cargo) { | ||
const name = eveData.typeIDs?.[item.typeId].name ?? ""; | ||
|
||
cargoList.push({ | ||
name, | ||
item, | ||
}); | ||
} | ||
|
||
return ( | ||
<div className={styles.cargoBay}> | ||
{Object.values(cargoList) | ||
.sort((a, b) => a.name.localeCompare(b.name)) | ||
.map(({ name, item }) => { | ||
return <CargoBayEntry key={name} name={name} cargo={item} />; | ||
})} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { CargoBay } from "./CargoBay"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.