aotds-docks/src/dux/utils.js

39 lines
949 B
JavaScript
Raw Normal View History

2021-05-17 13:48:31 +00:00
import flow from 'lodash/fp/flow.js';
import sumBy from 'lodash/fp/sumBy.js';
import pick from 'lodash/fp/pick.js';
import filter from 'lodash/fp/filter.js';
import flattenDeep from 'lodash/fp/flattenDeep.js';
import has from 'lodash/fp/has.js';
2020-07-19 20:21:28 +00:00
const expand_cost_mass = (obj={}) => ([
2021-05-17 13:48:31 +00:00
pick(['cost','mass'],obj),
2020-07-19 20:21:28 +00:00
...Object.values(obj || {}).filter( val => typeof val === 'object' ).map(
val => expand_cost_mass(val)
)
]);
export function calc_ship_req(ship) {
console.log(ship);
let { general, ...rest } = ship;
//if(!general) general = {};
2021-05-17 13:48:31 +00:00
const items = flow(
2020-07-19 20:21:28 +00:00
expand_cost_mass,
2021-05-17 13:48:31 +00:00
flattenDeep,
filter(has('cost'))
2020-07-19 20:21:28 +00:00
)({
...rest,
cost: general.mass, mass: 0
})
return {
2021-05-17 13:48:31 +00:00
mass: sumBy('mass',items),
cost: sumBy('cost',items),
2020-07-19 20:21:28 +00:00
}
}
2020-07-26 22:22:05 +00:00
// to get around 3.00001 ceiling up to 4
export const ceil = number => Math.ceil( Math.round(10*number)/10 );