import React from 'react'; import PropTypes from 'prop-types'; import cn from 'classnames'; import Persist from '../stores/Persist'; import TranslatedComponent from './TranslatedComponent'; import { diffDetails } from '../utils/SlotFunctions'; import AvailableModulesMenu from './AvailableModulesMenu'; import ModificationsMenu from './ModificationsMenu'; import * as ModuleUtils from '../shipyard/ModuleUtils'; import { ListModifications, Modified } from './SvgIcons'; import { Modifications } from 'coriolis-data/dist'; import { stopCtxPropagation } from '../utils/UtilityFunctions'; import { blueprintTooltip } from '../utils/BlueprintFunctions'; /** * Standard Slot */ export default class StandardSlot extends TranslatedComponent { static propTypes = { slot: PropTypes.object, modules: PropTypes.array.isRequired, onSelect: PropTypes.func.isRequired, onOpen: PropTypes.func.isRequired, onChange: PropTypes.func.isRequired, ship: PropTypes.object.isRequired, selected: PropTypes.bool, warning: PropTypes.func, }; /** * Construct the slot * @param {object} props Object properties */ constructor(props) { super(props); this._modificationsSelected = false; this._keyDown = this._keyDown.bind(this); this.modButton = null; this.slotDiv = null; } /** * Handle Enter key * @param {SyntheticEvent} event KeyDown event */ _keyDown(event) { if (event.key == 'Enter') { if(event.target.className == 'r') { this._toggleModifications(); } this.props.onOpen(event); } } /** * 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.modules[m.grp] ? [] : (Modifications.modules[m.grp].modifications || []); if (m && m.name && m.name === 'Guardian Hybrid Power Plant') { validMods = []; } if (m && m.name && m.name === 'Guardian Power Distributor') { validMods = []; } let showModuleResistances = Persist.showModuleResistances(); let mass = m.getMass() || m.cargo || m.fuel || 0; // Modifications tooltip shows blueprint and grade, if available let modTT = translate('modified'); if (m && m.blueprint && m.blueprint.name) { modTT = translate(m.blueprint.name) + ' ' + translate('grade') + ' ' + m.blueprint.grade; if (m.blueprint.special && m.blueprint.special.id >= 0) { modTT += ', ' + translate(m.blueprint.special.name); } modTT = (
{modTT}
{blueprintTooltip(translate, m.blueprint.grades[m.blueprint.grade], null, m.grp, m)}
); } if (!selected) { // If not selected then sure that modifications flag is unset this._modificationsSelected = false; } // If this is a missing module, therefore has the 'info' field, set the warning value on the module to be true when loaded. if (m.info) { warning = () => true; } const modificationsMarker = JSON.stringify(m); if (selected) { if (this._modificationsSelected) { menu = ; } else { menu = ; } } return (
this.slotDiv = slotDiv }>
{m.grp == 'bh' ? m.name.charAt(0) : slot.maxClass}
{classRating} {m.getInfo() ? translate(m.ukName) : translate(m.name || m.grp)}{m.mods && Object.keys(m.mods).length > 0 ? : null }
{formats.round(mass)}{units.T}
{ m.getMinMass() ?
{translate('minimum mass')}: {formats.int(m.getMinMass())}{units.T}
: null } { m.getOptMass() ?
{translate('optimal mass')}: {formats.int(m.getOptMass())}{units.T}
: null } { m.getMaxMass() ?
{translate('max mass')}: {formats.int(m.getMaxMass())}{units.T}
: null } { m.getOptMul() ?
{translate('optimal multiplier')}: {formats.rPct(m.getOptMul())}
: null } { m.getRange() ?
{translate('range', m.grp)}: {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 } { showModuleResistances && m.getExplosiveResistance() ?
{translate('explres')}: {formats.pct(m.getExplosiveResistance())}
: null } { showModuleResistances && m.getKineticResistance() ?
{translate('kinres')}: {formats.pct(m.getKineticResistance())}
: null } { showModuleResistances && m.getThermalResistance() ?
{translate('thermres')}: {formats.pct(m.getThermalResistance())}
: null } { m.getIntegrity() ?
{translate('integrity')}: {formats.int(m.getIntegrity())}
: null } { m.getInfo() ?
{translate(m.getInfo())}
: null } { m.getInfo() ?
: validMods.length > 0 ?
this.modButton = modButton }>
: null }
{menu}
); } /** * Toggle the modifications flag when selecting the modifications icon */ _toggleModifications() { this._modificationsSelected = !this._modificationsSelected; } }