import React from 'react'; import { Modifications } from 'coriolis-data/dist'; /** * Generate a tooltip with details of a blueprint's effects * @param {Object} features The features of the blueprint * @param {Object} m The module to compare with * @returns {Object} The react components */ export function blueprintTooltip(translate, features, m) { const results = []; for (const feature in features) { const featureIsBeneficial = isBeneficial(feature, features[feature]); const featureDef = Modifications.modifications[feature]; if (!featureDef.hidden) { let symbol = ''; if (feature === 'jitter') { symbol = '°'; } else if (featureDef.type === 'percentage') { symbol = '%'; } let lowerBound = features[feature][0]; let upperBound = features[feature][1]; if (featureDef.type === 'percentage') { lowerBound = Math.round(lowerBound * 1000) / 10; upperBound = Math.round(upperBound * 1000) / 10; } const range = `${lowerBound}${symbol} - ${upperBound}${symbol}`; if (m) { // We have a module - add in the current value let current = m.getModValue(feature); if (featureDef.type === 'percentage') { current = Math.round(current / 10) / 10; } results.push({translate(feature)}{lowerBound}{symbol}{current}{symbol}{upperBound}{symbol}); } else { // We do not have a module, no value results.push({translate(feature)}{lowerBound}{symbol}{upperBound}{symbol}); } } } return ( {m ? : null } {results}
{translate('feature')} {translate('worst')}{translate('current')}{translate('best')}
); } /** * Is this blueprint feature beneficial? * */ export function isBeneficial(feature, values) { const fact = (values[0] < 0 || (values[0] === 0 && values[1] < 0)); if (Modifications.modifications[feature].higherbetter) { return !fact; } else { return fact; } } /** * Get a blueprint with a given name and an optional module * @param {string} name The name of the blueprint * @param {Object} module The module for which to obtain this blueprint * @returns {Object} The matching blueprint */ export function getBlueprint(name, module) { // Start with a copy of the blueprint const blueprint = JSON.parse(JSON.stringify(Modifications.blueprints[name])); if (module) { if (module.grp === 'bh' || module.grp === 'hr') { // Bulkheads and hull reinforcements need to have their resistances altered by the base values for (const grade in blueprint.grades) { for (const feature in blueprint.grades[grade].features) { if (feature === 'explres') { blueprint.grades[grade].features[feature][0] *= (1 - module.explres); blueprint.grades[grade].features[feature][1] *= (1 - module.explres); } if (feature === 'kinres') { blueprint.grades[grade].features[feature][0] *= (1 - module.kinres); blueprint.grades[grade].features[feature][1] *= (1 - module.kinres); } if (feature === 'thermres') { blueprint.grades[grade].features[feature][0] *= (1 - module.thermres); blueprint.grades[grade].features[feature][1] *= (1 - module.thermres); } } } } if (module.grp === 'sb') { // Shield boosters are treated internally as straight modifiers, so rather than (for example) // being a 4% boost they are a 104% multiplier. We need to fix the values here so that they look // accurate as per the information in Elite for (const grade in blueprint.grades) { for (const feature in blueprint.grades[grade].features) { if (feature === 'shieldboost') { blueprint.grades[grade].features[feature][0] = ((1 + blueprint.grades[grade].features[feature][0]) * (1 + module.shieldboost) - 1)/ module.shieldboost - 1; blueprint.grades[grade].features[feature][1] = ((1 + blueprint.grades[grade].features[feature][1]) * (1 + module.shieldboost) - 1)/ module.shieldboost - 1; } } } } } return blueprint; }