Merge branch 'streamlining' into main

This commit is contained in:
Yanick Champoux 2020-07-27 10:58:54 -04:00
commit 8e7bf85beb
5 changed files with 83 additions and 4 deletions

View File

@ -14,6 +14,7 @@
import Section from '~C/Section'; import Section from '~C/Section';
import Weapon from '~C/Weapon'; import Weapon from '~C/Weapon';
import Cargo from '~C/Cargo/index.svelte'; import Cargo from '~C/Cargo/index.svelte';
import Streamlining from '~C/Streamlining/index.svelte';
const ship = shipStore(); const ship = shipStore();
@ -45,6 +46,8 @@
const ship_dispatch = ({detail}) => ship.dispatch(detail); const ship_dispatch = ({detail}) => ship.dispatch(detail);
setContext( 'ship_change', ship.dispatch );
</script> </script>
<main> <main>
@ -87,8 +90,10 @@
<Section label="misc"> <Section label="misc">
<Cargo {...$ship.cargo} on:set_cargo={ship_dispatch}/> <Cargo {...$ship.cargo} on:set_cargo={ship_dispatch}/>
<Streamlining {...$ship.streamlining} />
</Section> </Section>
</main> </main>
<style> <style>

View File

@ -0,0 +1,34 @@
<ShipItem {cost} {mass}>
<Field label="streamlining">
<div>
<input type="radio" bind:group={type} value="none" />
<label>none</label>
<input type="radio" bind:group={type} value="partial" />
<label>partial</label>
<input type="radio" bind:group={type} value="full" />
<label>full</label>
</div>
</Field>
</ShipItem>
<script>
import get from 'lodash/get';
import ShipItem from '~C/ShipItem/index.svelte';
import Field from '~C/Field/index.svelte';
import dux from '~/dux/streamlining';
import {getContext } from 'svelte';
export let type = 'none';
export let cost = 0;
export let mass = 0;
export let ship_change = getContext('ship_change') || ( () => {} );
$: ship_change( dux.actions.set_streamlining(type));
</script>
<style>
div { display: flex }
</style>

View File

@ -11,6 +11,8 @@ import { calc_ship_req } from "./utils";
import { candidate_ship_types } from './ship_types'; import { candidate_ship_types } from './ship_types';
import structure from './structure'; import structure from './structure';
import cargo from './cargo'; import cargo from './cargo';
import streamlining from './streamlining';
import { ceil } from '~/dux/utils';
const set_ship_mass = action("set_ship_mass", payload()); const set_ship_mass = action("set_ship_mass", payload());
const set_name = action("set_name", payload()); const set_name = action("set_name", payload());
@ -34,7 +36,7 @@ const initial = {
}; };
const dux = new Updux({ const dux = new Updux({
subduxes: { ftl, engine, weaponry, structure, cargo }, subduxes: { ftl, engine, weaponry, structure, cargo, streamlining },
initial initial
}); });
@ -63,6 +65,22 @@ dux.addSubscription((store) =>
createSelector(calc_ship_req, (reqs) => store.dispatch(set_ship_reqs(reqs))) 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) => dux.addSubscription((store) =>
createSelector( createSelector(
store => store.general.mass, 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( dux.addSubscription( store => createSelector(
ship => ship.general.mass, ship => ship.general.mass,
ship => ship.structure.screens.standard, ship => ship.structure.screens.standard,

View File

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

View File

@ -28,3 +28,6 @@ export function calc_ship_req(ship) {
cost: fp.sumBy('cost',items), 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 );