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