Add stats mapper to show certain synthetic props in ModificationsMenu

This commit is contained in:
Felix Linker
2021-01-10 22:01:21 +01:00
parent 53c40ac9c4
commit 5c63afd96c
2 changed files with 38 additions and 6 deletions

View File

@@ -11,6 +11,7 @@ import {
} from '../utils/BlueprintFunctions';
import { getBlueprintInfo, getExperimentalInfo } from 'ed-forge/lib/data/blueprints';
import { getModuleInfo } from 'ed-forge/lib/data/items';
import { SHOW } from '../shipyard/StatsMapping';
/**
* Modifications menu
@@ -149,12 +150,10 @@ export default class ModificationsMenu extends TranslatedComponent {
let onSet = m.set.bind(m);
// Show resistance instead of effectiveness
if (property.endsWith('effectiveness')) {
const oldProperty = property;
property = property.replace('effectiveness', 'resistance');
onSet = (_, v) => {
m.set(oldProperty, 1 - v / 100);
};
const mapped = SHOW[property];
if (mapped) {
property = mapped.as;
onSet = mapped.setter.bind(undefined, m);
}
return <Modification key={property} m={m} property={property}

View File

@@ -0,0 +1,33 @@
import { Module } from 'ed-forge';
/**
* Sets a resistance value of a module as
* @param {Module} module Module to set the property
* @param {string} prop Property name; must end with 'resistance'
* @param {number} val Resistance value to set
*/
function setterResToEff(module, prop, val) {
module.set(
prop.replace('resistance', 'effectiveness'),
1 - val / 100,
);
}
export const SHOW = {
causticeffectiveness: {
as: 'causticresistance',
setter: setterResToEff,
},
explosiveeffectiveness: {
as: 'explosiveresistance',
setter: setterResToEff,
},
kineticeffectiveness: {
as: 'kineticresistance',
setter: setterResToEff,
},
thermiceffectiveness: {
as: 'thermicresistance',
setter: setterResToEff,
},
};