diff --git a/src/App.svelte b/src/App.svelte
index 0028902..a3a1d01 100644
--- a/src/App.svelte
+++ b/src/App.svelte
@@ -14,6 +14,7 @@
import Section from '~C/Section';
import Weapon from '~C/Weapon';
import Cargo from '~C/Cargo/index.svelte';
+ import Streamlining from '~C/Streamlining/index.svelte';
const ship = shipStore();
@@ -45,6 +46,8 @@
const ship_dispatch = ({detail}) => ship.dispatch(detail);
+ setContext( 'ship_change', ship.dispatch );
+
@@ -87,8 +90,10 @@
+
diff --git a/src/dux/index.js b/src/dux/index.js
index 0334903..38945b5 100644
--- a/src/dux/index.js
+++ b/src/dux/index.js
@@ -11,6 +11,8 @@ import { calc_ship_req } from "./utils";
import { candidate_ship_types } from './ship_types';
import structure from './structure';
import cargo from './cargo';
+import streamlining from './streamlining';
+import { ceil } from '~/dux/utils';
const set_ship_mass = action("set_ship_mass", payload());
const set_name = action("set_name", payload());
@@ -34,7 +36,7 @@ const initial = {
};
const dux = new Updux({
- subduxes: { ftl, engine, weaponry, structure, cargo },
+ subduxes: { ftl, engine, weaponry, structure, cargo, streamlining },
initial
});
@@ -63,6 +65,22 @@ 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(
store => store.general.mass,
@@ -93,9 +111,6 @@ dux.addSubscription((store) =>
)
);
-// to get around 3.00001 ceiling up to 4
-const ceil = number => Math.ceil( Math.round(10*number)/10 );
-
dux.addSubscription( store => createSelector(
ship => ship.general.mass,
ship => ship.structure.screens.standard,
diff --git a/src/dux/streamlining/index.js b/src/dux/streamlining/index.js
new file mode 100644
index 0000000..8098016
--- /dev/null
+++ b/src/dux/streamlining/index.js
@@ -0,0 +1,22 @@
+import Updux from "updux";
+import { action, payload } from "ts-action";
+import u from "updeep";
+import { createSelector } from "reselect";
+
+const dux = new Updux({
+ initial: {
+ type: 'none',
+ cost: 0,
+ mass: 0,
+ },
+});
+
+const set_streamlining = action('set_streamlining',payload());
+
+dux.addMutation(set_streamlining, type => u({type}) );
+
+const set_streamlining_cost_mass = action('set_streamlining_cost_mass',payload());
+
+dux.addMutation( set_streamlining_cost_mass, reqs => u(reqs) );
+
+export default dux.asDux;
diff --git a/src/dux/utils.js b/src/dux/utils.js
index 69795ad..bff3a0e 100644
--- a/src/dux/utils.js
+++ b/src/dux/utils.js
@@ -28,3 +28,6 @@ export function calc_ship_req(ship) {
cost: fp.sumBy('cost',items),
}
}
+
+// to get around 3.00001 ceiling up to 4
+export const ceil = number => Math.ceil( Math.round(10*number)/10 );