Skip to content

Commit

Permalink
feat: show how long it takes for a capacitor to deplete (if not stabl…
Browse files Browse the repository at this point in the history
…e) (#61)
  • Loading branch information
TrueBrain authored Feb 9, 2024
1 parent 2af0a39 commit 11ba97e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"typescript-plugin-css-modules": "^5.0.2"
},
"peerDependencies": {
"@eveshipfit/dogma-engine": "^2.4.0",
"@eveshipfit/dogma-engine": "^2.5.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
Expand Down
7 changes: 7 additions & 0 deletions src/ShipStatistics/ShipStatistics.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,10 @@
.rechargeRateDropdownContent > div:hover {
background-color: #4e4e4e;
}

.capacitorStable {
color: #8dc169;
}
.capacitorUnstable {
color: #ff454b;
}
27 changes: 24 additions & 3 deletions src/ShipStatistics/ShipStatistics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import clsx from "clsx";
import React from "react";

import { ShipAttribute } from '../ShipAttribute';
import { EveDataContext } from "../EveDataProvider";
import { ShipSnapshotContext } from "../ShipSnapshotProvider";

import { Category, CategoryLine } from "./Category";
import { RechargeRate } from "./RechargeRate";
Expand All @@ -14,18 +16,37 @@ import { Icon } from "../Icon";
* Render ship statistics similar to how it is done in-game.
*/
export const ShipStatistics = () => {
const eveData = React.useContext(EveDataContext);
const shipSnapshot = React.useContext(ShipSnapshotContext);

let capacitorState = "Stable";

if (shipSnapshot?.loaded) {
const attributeId = eveData.attributeMapping?.capacitorDepletesIn || 0;
const capacitorDepletesIn = shipSnapshot.hull?.attributes.get(attributeId)?.value;

if (capacitorDepletesIn !== undefined && capacitorDepletesIn > 0) {
const hours = Math.floor(capacitorDepletesIn / 3600);
const minutes = Math.floor((capacitorDepletesIn % 3600) / 60);
const seconds = Math.floor(capacitorDepletesIn % 60);
capacitorState = `Depletes in ${hours.toString().padStart(2, "0")}:${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`;
} else {
capacitorState = "Stable";
}
}

return <div>
<Category headerLabel="Capacitor" headerContent={
<span>?</span>
<span className={clsx({[styles.capacitorStable]: capacitorState === "Stable", [styles.capacitorUnstable]: capacitorState !== "Stable"})}>{capacitorState}</span>
}>
<CategoryLine>
<span>
<ShipAttribute name="capacitorCapacity" fixed={0} /> GJ / <ShipAttribute name="rechargeRate" fixed={2} divideBy={1000} /> s
<ShipAttribute name="capacitorCapacity" fixed={1} /> GJ / <ShipAttribute name="rechargeRate" fixed={2} divideBy={1000} /> s
</span>
</CategoryLine>
<CategoryLine>
<span>
Δ <ShipAttribute name="capacitorPeakDelta" fixed={0} /> GJ/s (<ShipAttribute name="capacitorPeakDeltaPercentage" fixed={1} />%)
Δ <ShipAttribute name="capacitorPeakDelta" fixed={1} /> GJ/s (<ShipAttribute name="capacitorPeakDeltaPercentage" fixed={1} />%)
</span>
</CategoryLine>
</Category>
Expand Down
2 changes: 1 addition & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const defaultDataUrl = "https://data.eveship.fit/v7.0-20231214/";
export const defaultDataUrl = "https://data.eveship.fit/v7.1-20231214/";

0 comments on commit 11ba97e

Please sign in to comment.