import React from 'react'; import cn from 'classnames'; import TranslatedComponent from './TranslatedComponent'; import { jumpRange } from '../shipyard/Calculations'; import { diffDetails } from '../utils/SlotFunctions'; import AvailableModulesMenu from './AvailableModulesMenu'; import ModificationsMenu from './ModificationsMenu'; import { ListModifications } from './SvgIcons'; import { Modifications } from 'coriolis-data/dist'; import { stopCtxPropagation } from '../utils/UtilityFunctions'; /** * Standard Slot */ export default class StandardSlot extends TranslatedComponent { static propTypes = { slot: React.PropTypes.object, modules: React.PropTypes.array.isRequired, onSelect: React.PropTypes.func.isRequired, onOpen: React.PropTypes.func.isRequired, onChange: React.PropTypes.func.isRequired, ship: React.PropTypes.object.isRequired, selected: React.PropTypes.bool, warning: React.PropTypes.func, }; /** * Construct the slot * @param {object} props Object properties */ constructor(props) { super(props); this._modificationsSelected = false; } /** * Render the slot * @return {React.Component} Slot component */ render() { let { termtip, tooltip } = this.context; let { translate, formats, units } = this.context.language; let { modules, slot, selected, warning, onSelect, onChange, ship } = this.props; let m = slot.m; let classRating = m.class + m.rating; let menu; let validMods = m == null ? [] : (Modifications.validity[m.grp] || []); let mass = m.getMass() || m.cargo || m.fuel || 0; if (!selected) { // If not selected then sure that modifications flag is unset this._modificationsSelected = false; } if (selected) { if (this._modificationsSelected) { menu = ; } else { menu = ; } } return (
{slot.maxClass}
{classRating} {translate(m.grp == 'bh' ? m.grp : m.name || m.grp)}
{formats.round(mass)}{units.T}
{ m.grp == 'bh' && m.name ?
{translate(m.name)}
: null } { m.getOptimalMass() ?
{translate('optimal mass')}: {formats.int(m.getOptimalMass())}{units.T}
: null } { m.getMaxMass() ?
{translate('max mass')}: {formats.int(m.getMaxMass())}{units.T}
: null } { m.getRange() ?
{translate('range')}: {formats.f2(m.getRange())}{units.km}
: null } { m.time ?
{translate('time')}: {formats.time(m.time)}
: null } { m.getThermalEfficiency() ?
{translate('efficiency')}: {formats.f2(m.getThermalEfficiency())}
: null } { m.getPowerGeneration() > 0 ?
{translate('pgen')}: {formats.f1(m.getPowerGeneration())}{units.MW}
: null } { m.getMaxFuelPerJump() ?
{translate('max')} {translate('fuel')}: {formats.f1(m.getMaxFuelPerJump())}{units.T}
: null } { m.getWeaponsCapacity() ?
{translate('WEP')}: {formats.f1(m.getWeaponsCapacity())}{units.MJ} / {formats.f1(m.getWeaponsRechargeRate())}{units.MW}
: null } { m.getSystemsCapacity() ?
{translate('SYS')}: {formats.f1(m.getSystemsCapacity())}{units.MJ} / {formats.f1(m.getSystemsRechargeRate())}{units.MW}
: null } { m.getEnginesCapacity() ?
{translate('ENG')}: {formats.f1(m.getEnginesCapacity())}{units.MJ} / {formats.f1(m.getEnginesRechargeRate())}{units.MW}
: null } { validMods.length > 0 ?
: null }
{menu}
); } /** * Toggle the modifications flag when selecting the modifications icon */ _toggleModifications() { this._modificationsSelected = !this._modificationsSelected; } }