mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-10 15:15:34 +00:00
Rework FSD profile
This commit is contained in:
@@ -3,46 +3,21 @@ import PropTypes from 'prop-types';
|
|||||||
import TranslatedComponent from './TranslatedComponent';
|
import TranslatedComponent from './TranslatedComponent';
|
||||||
import LineChart from '../components/LineChart';
|
import LineChart from '../components/LineChart';
|
||||||
import * as Calc from '../shipyard/Calculations';
|
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
|
* FSD profile for a given ship
|
||||||
*/
|
*/
|
||||||
export default class FSDProfile extends TranslatedComponent {
|
export default class FSDProfile extends TranslatedComponent {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
|
code: PropTypes.string.isRequired,
|
||||||
ship: PropTypes.object.isRequired,
|
ship: PropTypes.object.isRequired,
|
||||||
cargo: PropTypes.number.isRequired,
|
cargo: PropTypes.number.isRequired,
|
||||||
fuel: 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
|
* Calculate the maximum range for this ship across its applicable mass
|
||||||
* @param {Object} ship The ship
|
* @param {Object} ship The ship
|
||||||
@@ -60,36 +35,27 @@ export default class FSDProfile extends TranslatedComponent {
|
|||||||
* @return {React.Component} contents
|
* @return {React.Component} contents
|
||||||
*/
|
*/
|
||||||
render() {
|
render() {
|
||||||
const { language, onWindowResize, sizeRatio, tooltip, termtip } = this.context;
|
const { language } = this.context;
|
||||||
const { formats, translate, units } = language;
|
const { translate } = language;
|
||||||
const { ship, cargo, fuel } = this.props;
|
const { code, ship } = 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 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 (
|
return (
|
||||||
<LineChart
|
<LineChart
|
||||||
xMin={minMass}
|
xMin={minMass}
|
||||||
xMax={maxMass}
|
xMax={maxMass}
|
||||||
yMin={minRange}
|
yMin={0}
|
||||||
yMax={maxRange}
|
yMax={cb(minMass)}
|
||||||
xMark={mark}
|
// Add a mark at our current mass
|
||||||
|
xMark={Math.min(mass, maxMass)}
|
||||||
xLabel={translate('mass')}
|
xLabel={translate('mass')}
|
||||||
xUnit={translate('T')}
|
xUnit={translate('T')}
|
||||||
yLabel={translate('maximum range')}
|
yLabel={translate('maximum range')}
|
||||||
yUnit={translate('LY')}
|
yUnit={translate('LY')}
|
||||||
func={this.state.calcMaxRangeFunc}
|
func={cb}
|
||||||
points={200}
|
points={200}
|
||||||
code={code}
|
code={code}
|
||||||
aspect={0.7}
|
aspect={0.7}
|
||||||
|
|||||||
Reference in New Issue
Block a user