streamlining

main
Yanick Champoux 2022-03-04 16:31:05 -05:00
parent 9596ae9922
commit 15495ee843
6 changed files with 82 additions and 18 deletions

View File

@ -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(

View File

@ -0,0 +1,41 @@
<ShipItem {...reqs}>
<Field label="streamlining">
<div>
<label>
<input type="radio" bind:group={type} value="none" />
none</label
>
<label>
<input type="radio" bind:group={type} value="partial" />
partial</label
>
<label>
<input type="radio" bind:group={type} value="full" />
full</label
>
</div>
</Field>
</ShipItem>
<script>
import ShipItem from "$lib/components/ShipItem/index.svelte";
import Field from "$lib/components/Field/index.svelte";
import { getContext } from "svelte";
export let type = "none";
export let reqs = {};
export let {dispatch, shipMass} = getContext("ship");
$: dispatch.setStreamlining({type, shipMass: $shipMass});
</script>
<style>
div {
display: flex;
}
label {
margin-left: 1em;
}
</style>

View File

@ -2,6 +2,7 @@
<Hull {...hull}/>
<Screens {...screens} />
<Cargo {...cargo} />
<Streamlining {...streamlining} />
</Section>
<script>
@ -9,10 +10,12 @@
import Hull from './Hull.svelte';
import Screens from './Screens.svelte';
import Cargo from './Cargo.svelte';
import Streamlining from './Streamlining.svelte';
export let hull = {};
export let screens = {};
export let cargo = {};
export let streamlining = {};
</script>

View File

@ -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;

View File

@ -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 };
}

View File

@ -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 )
};
};