mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-09 22:55:35 +00:00
119 lines
4.7 KiB
JavaScript
119 lines
4.7 KiB
JavaScript
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(<tr key={feature} className={featureIsBeneficial ? 'secondary' : 'warning'}><td style={{ textAlign: 'left' }}>{translate(feature)}</td><td style={{ textAlign: 'right' }}>{lowerBound}{symbol}</td><td style={{ textAlign: 'right' }}>{current}{symbol}</td><td style={{ textAlign: 'right' }}>{upperBound}{symbol}</td></tr>);
|
|
} else {
|
|
// We do not have a module, no value
|
|
results.push(<tr key={feature} className={featureIsBeneficial ? 'secondary' : 'warning'}><td style={{ textAlign: 'left' }}>{translate(feature)}</td><td style={{ textAlign: 'right' }}>{lowerBound}{symbol}</td><td style={{ textAlign: 'right' }}>{upperBound}{symbol}</td></tr>);
|
|
}
|
|
}
|
|
}
|
|
|
|
return (
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<td>{translate('feature')}</td>
|
|
<td>{translate('worst')}</td>
|
|
{m ? <td>{translate('current')}</td> : null }
|
|
<td>{translate('best')}</td>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{results}
|
|
</tbody>
|
|
</table>
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
}
|