2022-03-02 18:42:42 +00:00
|
|
|
import { Updux } from "updux";
|
|
|
|
import u from "updeep";
|
2022-03-02 19:00:18 +00:00
|
|
|
import { createSelector } from "reselect";
|
2022-03-02 18:42:42 +00:00
|
|
|
|
|
|
|
import reqs from "../reqs.js";
|
|
|
|
|
|
|
|
const dux = new Updux({
|
|
|
|
subduxes: { reqs },
|
|
|
|
initial: {
|
|
|
|
rating: 1,
|
|
|
|
advanced: false,
|
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
setDrive: null,
|
|
|
|
setDriveReqs: null,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
dux.setMutation("setDrive", (changes) => u(changes));
|
|
|
|
dux.setMutation("setDriveReqs", (reqs) => u({ reqs }));
|
|
|
|
|
2022-03-02 19:00:18 +00:00
|
|
|
// needs to be at the top level
|
|
|
|
export const calculateDriveReqs = store =>
|
|
|
|
createSelector(
|
|
|
|
[
|
|
|
|
(ship) => ship.reqs.mass,
|
|
|
|
(ship) => ship.propulsion.drive.rating,
|
|
|
|
(ship) => ship.propulsion.drive.advanced,
|
|
|
|
],
|
|
|
|
(ship_mass, rating, advanced) =>
|
|
|
|
store.dispatch.setDriveReqs(calcDriveReqs(ship_mass, rating, advanced))
|
|
|
|
);
|
|
|
|
|
2022-03-02 18:42:42 +00:00
|
|
|
export function calcDriveReqs(shipMass, rating, advanced = false) {
|
|
|
|
const mass = Math.ceil(rating * 0.05 * shipMass);
|
|
|
|
const cost = mass * (advanced ? 3 : 2);
|
|
|
|
|
|
|
|
return { mass, cost };
|
|
|
|
}
|
|
|
|
|
|
|
|
export default dux;
|