From 15495ee84387c0382ddc6aabd8ac96877dea6781 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Fri, 4 Mar 2022 16:31:05 -0500 Subject: [PATCH] streamlining --- src/dux/index.js | 16 -------- .../ShipEdit/Structure/Streamlining.svelte | 41 +++++++++++++++++++ .../ShipEdit/Structure/index.svelte | 3 ++ src/lib/shipDux/structure/index.js | 4 +- src/lib/shipDux/structure/streamlining.js | 33 +++++++++++++++ src/lib/store/ship.js | 3 +- 6 files changed, 82 insertions(+), 18 deletions(-) create mode 100644 src/lib/components/ShipEdit/Structure/Streamlining.svelte create mode 100644 src/lib/shipDux/structure/streamlining.js diff --git a/src/dux/index.js b/src/dux/index.js index 9d83cb5..86acdde 100644 --- a/src/dux/index.js +++ b/src/dux/index.js @@ -66,22 +66,6 @@ dux.addSubscription((store) => createSelector(calc_ship_req, (reqs) => store.dispatch(set_ship_reqs(reqs))) ); -dux.addSubscription((store) => - createSelector( - (store) => store.general.mass, - (store) => store.streamlining.type, - (ship_mass, streamlining) => { - const mass = ceil( - (ship_mass * - (streamlining === "none" ? 0 : streamlining === "partial" ? 5 : 10)) / - 100 - ); - const cost = 2 * mass; - - store.dispatch(dux.actions.set_streamlining_cost_mass({ cost, mass })); - } - ) -); dux.addSubscription((store) => createSelector( diff --git a/src/lib/components/ShipEdit/Structure/Streamlining.svelte b/src/lib/components/ShipEdit/Structure/Streamlining.svelte new file mode 100644 index 0000000..f610be3 --- /dev/null +++ b/src/lib/components/ShipEdit/Structure/Streamlining.svelte @@ -0,0 +1,41 @@ + + +
+ + + +
+
+
+ + + + diff --git a/src/lib/components/ShipEdit/Structure/index.svelte b/src/lib/components/ShipEdit/Structure/index.svelte index 8276ea1..b627975 100644 --- a/src/lib/components/ShipEdit/Structure/index.svelte +++ b/src/lib/components/ShipEdit/Structure/index.svelte @@ -2,6 +2,7 @@ + diff --git a/src/lib/shipDux/structure/index.js b/src/lib/shipDux/structure/index.js index cffeeae..4311ec4 100644 --- a/src/lib/shipDux/structure/index.js +++ b/src/lib/shipDux/structure/index.js @@ -3,8 +3,10 @@ import { Updux } from 'updux'; import hull from './hull.js'; import screens from './screens.js'; import cargo from './cargo.js'; +import streamlining from './streamlining.js'; const dux = new Updux({ - subduxes: { hull, screens, cargo } + subduxes: { hull, screens, cargo, streamlining } }); export default dux; + diff --git a/src/lib/shipDux/structure/streamlining.js b/src/lib/shipDux/structure/streamlining.js new file mode 100644 index 0000000..f05f09f --- /dev/null +++ b/src/lib/shipDux/structure/streamlining.js @@ -0,0 +1,33 @@ +import { Updux } from "updux"; +import u from "updeep"; + +import reqs from "../reqs.js"; +import { calculateDriveReqs } from "../propulsion/drive.js"; + +const dux = new Updux({ + subduxes: { + reqs, + }, + initial: { + type: "none", + }, + actions: { + setStreamlining: null, + }, +}); +export default dux; + +dux.setMutation("setStreamlining", ({ shipMass, type }) => + u({ + type, + reqs: calcStreamliningReqs({ shipMass, type }), + }) +); + +function calcStreamliningReqs({ shipMass, type }) { + const mass = Math.ceil( + (shipMass * (type === "none" ? 0 : type === "partial" ? 5 : 10)) / 100 + ); + + return { mass, cost: 2 * mass }; +} diff --git a/src/lib/store/ship.js b/src/lib/store/ship.js index dcfbe80..7f459d2 100644 --- a/src/lib/store/ship.js +++ b/src/lib/store/ship.js @@ -1,5 +1,5 @@ import { browser } from "$app/env"; -import { readable, get } from "svelte/store"; +import { readable, get, derived } from "svelte/store"; import { compose, applyMiddleware } from "redux"; import shipDux from "../shipDux/index.js"; @@ -28,5 +28,6 @@ export default () => { return { dispatch: duxStore.dispatch, state, + shipMass: derived( state, state => state.reqs.mass ) }; };