mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-08 22:33:24 +00:00
Add stats mapper to show certain synthetic props in ModificationsMenu
This commit is contained in:
@@ -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}
|
||||
|
||||
33
src/app/shipyard/StatsMapping.js
Normal file
33
src/app/shipyard/StatsMapping.js
Normal 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,
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user