Add SCO Module Check (#748)

* Add SCO Module Check

Goes hand-in-hand with https://github.com/EDCD/coriolis-data/pull/98

* [748] Updated Filter Function

This time, readable!
This commit is contained in:
David Sangrey
2024-05-12 07:51:17 -04:00
committed by GitHub
parent 5d54eb8862
commit c3cb2cfa3b

View File

@@ -13,6 +13,19 @@ function filter(arr, maxClass, minClass, mass) {
return arr.filter(m => m.class <= maxClass && m.class >= minClass && (m.maxmass === undefined || mass <= m.maxmass));
}
/**
* Filter SCO Modules to only return legal size.
* @param {Array} arr Array of available FSD modules.
* @param {number} maxSize Maximum allowable size for SCO modules.
* @return {Array} Subset of modules filtered based on legal size amd type.
*/
function sco_filter(arr, maxSize) {
return arr.filter(module => {
return !(module.hasOwnProperty('name') && module['name'] === "Frame Shift Drive (SCO)" && module['class'] < maxSize);
});
}
/**
* The available module set for a specific ship
*/
@@ -41,6 +54,7 @@ export default class ModuleSet {
this.standard[0] = filter(stnd.pp, maxStandardArr[0], 0, mass); // Power Plant
this.standard[2] = filter(stnd.fsd, maxStandardArr[2], 0, mass); // FSD
this.standard[2] = sco_filter(this.standard[2], maxStandardArr[2]) // FSD - Filter SCO Modules
this.standard[4] = filter(stnd.pd, maxStandardArr[4], 0, mass); // Power Distributor
this.standard[6] = filter(stnd.ft, maxStandardArr[6], 0, mass); // Fuel Tank
// Thrusters, filter modules by class only (to show full list of ratings for that class)