From 4943d36bb82fe29a1375db2471a4fc3981c6bc28 Mon Sep 17 00:00:00 2001 From: Felix Linker Date: Sun, 1 Nov 2020 02:59:37 +0100 Subject: [PATCH] Rework FSD profile --- src/app/components/FSDProfile.jsx | 66 ++++++++----------------------- 1 file changed, 16 insertions(+), 50 deletions(-) diff --git a/src/app/components/FSDProfile.jsx b/src/app/components/FSDProfile.jsx index 2ec4098a..f31f9db3 100644 --- a/src/app/components/FSDProfile.jsx +++ b/src/app/components/FSDProfile.jsx @@ -3,46 +3,21 @@ import PropTypes from 'prop-types'; import TranslatedComponent from './TranslatedComponent'; import LineChart from '../components/LineChart'; import * as Calc from '../shipyard/Calculations'; +import { calculateJumpRange } from 'ed-forge/lib/stats/JumpRangeProfile'; +import { ShipProps } from 'ed-forge'; +const { LADEN_MASS } = ShipProps; /** * FSD profile for a given ship */ export default class FSDProfile extends TranslatedComponent { static propTypes = { + code: PropTypes.string.isRequired, ship: PropTypes.object.isRequired, cargo: PropTypes.number.isRequired, fuel: PropTypes.number.isRequired, - marker: PropTypes.string.isRequired }; - /** - * Constructor - * @param {Object} props React Component properties - * @param {Object} context React Component context - */ - constructor(props, context) { - super(props); - - const ship = this.props.ship; - - this.state = { - calcMaxRangeFunc: this._calcMaxRange.bind(this, ship, this.props.fuel) - }; - } - - /** - * Update the state if our ship changes - * @param {Object} nextProps Incoming/Next properties - * @param {Object} nextContext Incoming/Next conext - * @return {boolean} Returns true if the component should be rerendered - */ - componentWillReceiveProps(nextProps, nextContext) { - if (nextProps.marker != this.props.marker) { - this.setState({ calcMaxRangeFunc: this._calcMaxRange.bind(this, nextProps.ship, nextProps.fuel) }); - } - return true; - } - /** * Calculate the maximum range for this ship across its applicable mass * @param {Object} ship The ship @@ -60,36 +35,27 @@ export default class FSDProfile extends TranslatedComponent { * @return {React.Component} contents */ render() { - const { language, onWindowResize, sizeRatio, tooltip, termtip } = this.context; - const { formats, translate, units } = language; - const { ship, cargo, fuel } = this.props; - - - // Calculate bounds for our line chart - use thruster info for X - const thrusters = ship.standard[1].m; - const fsd = ship.standard[2].m; - const minMass = ship.calcLowestPossibleMass({ th: thrusters }); - const maxMass = thrusters.getMaxMass(); - const mass = ship.unladenMass + fuel + cargo; - const minRange = 0; - const maxRange = Calc.jumpRange(minMass + fsd.getMaxFuelPerJump(), fsd, fsd.getMaxFuelPerJump(), ship); - // Add a mark at our current mass - const mark = Math.min(mass, maxMass); - - const code = ship.name + ship.toString() + '.' + fuel; + const { language } = this.context; + const { translate } = language; + const { code, ship } = this.props; + const minMass = ship.getBaseProperty('hullmass'); + const maxMass = ship.getThrusters().get('enginemaximalmass'); + const mass = ship.get(LADEN_MASS); + const cb = (mass) => calculateJumpRange(ship, mass, Infinity, true); return (