Drive dux

This commit is contained in:
Yanick Champoux 2022-03-02 14:00:18 -05:00
parent 31d48d0926
commit b350c714c4
2 changed files with 16 additions and 0 deletions

View File

@ -3,6 +3,7 @@ import u from 'updeep';
import propulsion from "./propulsion/index.js"; import propulsion from "./propulsion/index.js";
import identification from "./identification.js"; import identification from "./identification.js";
import { calculateDriveReqs } from './propulsion/drive.js';
const dux = new Updux({ const dux = new Updux({
subduxes: { subduxes: {
@ -19,4 +20,6 @@ const dux = new Updux({
dux.setMutation( 'setShipMass', mass => u({reqs: {mass}}) ); dux.setMutation( 'setShipMass', mass => u({reqs: {mass}}) );
dux.addReaction( calculateDriveReqs );
export default dux; export default dux;

View File

@ -1,5 +1,6 @@
import { Updux } from "updux"; import { Updux } from "updux";
import u from "updeep"; import u from "updeep";
import { createSelector } from "reselect";
import reqs from "../reqs.js"; import reqs from "../reqs.js";
@ -18,6 +19,18 @@ const dux = new Updux({
dux.setMutation("setDrive", (changes) => u(changes)); dux.setMutation("setDrive", (changes) => u(changes));
dux.setMutation("setDriveReqs", (reqs) => u({ reqs })); 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) { export function calcDriveReqs(shipMass, rating, advanced = false) {
const mass = Math.ceil(rating * 0.05 * shipMass); const mass = Math.ceil(rating * 0.05 * shipMass);
const cost = mass * (advanced ? 3 : 2); const cost = mass * (advanced ? 3 : 2);