Merge branch 'screens' into version-2

This commit is contained in:
Yanick Champoux 2022-03-03 21:11:40 -05:00
commit 683f8bba93
7 changed files with 84 additions and 25 deletions

View File

@ -118,11 +118,6 @@ dux.addSubscription((store) =>
(ship) => ship.structure.screens.standard,
(ship) => ship.structure.screens.advanced,
(mass, standard, advanced) => {
console.log({
mass,
standard,
advanced,
});
const standard_mass = standard * Math.max(3, ceil(0.05 * mass));
const advanced_mass = advanced * Math.max(4, ceil(0.075 * mass));

View File

@ -1,18 +0,0 @@
import Updux from "updux";
import { action, payload } from "ts-action";
import u from "@yanick/updeep";
import { createSelector } from "reselect";
const dux = new Updux({
initial: {
standard: 0, advanced: 0, cost: 0, mass: 0,
}
});
const set_screens = action('set_screens', payload() );
dux.addMutation(set_screens, payload => u.update(payload) );
const set_screens_reqs = action('set_screens_reqs', payload() );
dux.addMutation(set_screens_reqs, payload => u.update(payload) );
export default dux.asDux;

View File

@ -0,0 +1,37 @@
<ShipItem {...reqs}>
<div>
<Field label="screens">
<input type="number" bind:value={standard} min="0" />
</Field>
<Field label="advanced screens">
<input type="number" bind:value={advanced} min="0" />
</Field>
</div>
</ShipItem>
<script>
import { getContext } from "svelte";
import Section from "$lib/components/Section/index.svelte";
import Field from "$lib/components/Field/index.svelte";
import ShipItem from "$lib/components/ShipItem/index.svelte";
export let reqs = {};
export let standard = 0;
export let advanced = 0;
const ship = getContext('ship');
$: ship.dispatch.setScreens({ standard, advanced });
</script>
<style>
input {
width: 3em;
}
div {
display: flex;
gap: 2em;
}
</style>

View File

@ -1,14 +1,16 @@
<Section label="structure">
<Hull {...hull}/>
<Screens {...screens} />
</Section>
<script>
import Section from "$lib/components/Section/index.svelte";
import Hull from './Hull.svelte';
import Screens from './Screens.svelte';
export let hull = {};
export let screens = {};
$: console.log(hull);
</script>

View File

@ -6,6 +6,7 @@ import identification from "./identification.js";
import { calculateDriveReqs } from './propulsion/drive.js';
import { ftlReqsReaction } from './propulsion/ftl.js';
import structure from './structure/index.js';
import { screenReqsReaction, screensReqsReaction } from './structure/screens.js'
const dux = new Updux({
subduxes: {
@ -24,5 +25,6 @@ dux.setMutation( 'setShipMass', mass => u({reqs: {mass}}) );
dux.addReaction( calculateDriveReqs );
dux.addReaction( ftlReqsReaction );
dux.addReaction( screenReqsReaction );
export default dux;

View File

@ -1,8 +1,9 @@
import { Updux } from 'updux';
import hull from './hull.js';
import screens from './screens.js';
const dux = new Updux({
subduxes: { hull }
subduxes: { hull, screens }
});
export default dux;

View File

@ -0,0 +1,40 @@
import { Updux } from "updux";
import u from 'updeep';
import { createSelector } from 'reselect';
import reqs from '../reqs.js';
const dux = new Updux({
subduxes: {
reqs
},
initial: {
standard: 0, advanced: 0,
},
actions: {
setScreens: null,
setScreensReqs: null,
}
});
export default dux;
dux.setMutation('setScreens', payload => u(payload));
dux.setMutation('setScreensReqs', reqs => u({reqs}));
export const screenReqsReaction = store => createSelector(
(ship) => ship.reqs.mass,
(ship) => ship.structure.screens.standard,
(ship) => ship.structure.screens.advanced,
(...args) => store.dispatch.setScreensReqs(calcScreensReqs(...args)),
);
function calcScreensReqs(mass,standard,advanced) {
const standard_mass = standard * Math.max(3, Math.ceil(0.05 * mass));
const advanced_mass = advanced * Math.max(4, Math.ceil(0.075 * mass));
return {
mass: standard_mass + advanced_mass,
cost: 3 * standard_mass + 4 * advanced_mass,
}
}