Drive dux
This commit is contained in:
parent
31d48d0926
commit
b350c714c4
@ -3,6 +3,7 @@ import u from 'updeep';
|
||||
|
||||
import propulsion from "./propulsion/index.js";
|
||||
import identification from "./identification.js";
|
||||
import { calculateDriveReqs } from './propulsion/drive.js';
|
||||
|
||||
const dux = new Updux({
|
||||
subduxes: {
|
||||
@ -19,4 +20,6 @@ const dux = new Updux({
|
||||
|
||||
dux.setMutation( 'setShipMass', mass => u({reqs: {mass}}) );
|
||||
|
||||
dux.addReaction( calculateDriveReqs );
|
||||
|
||||
export default dux;
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { Updux } from "updux";
|
||||
import u from "updeep";
|
||||
import { createSelector } from "reselect";
|
||||
|
||||
import reqs from "../reqs.js";
|
||||
|
||||
@ -18,6 +19,18 @@ const dux = new Updux({
|
||||
dux.setMutation("setDrive", (changes) => u(changes));
|
||||
dux.setMutation("setDriveReqs", (reqs) => u({ reqs }));
|
||||
|
||||
// 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))
|
||||
);
|
||||
|
||||
export function calcDriveReqs(shipMass, rating, advanced = false) {
|
||||
const mass = Math.ceil(rating * 0.05 * shipMass);
|
||||
const cost = mass * (advanced ? 3 : 2);
|
||||
|
Loading…
Reference in New Issue
Block a user