screens
This commit is contained in:
parent
7c17b90d70
commit
607106ed35
@ -118,11 +118,6 @@ dux.addSubscription((store) =>
|
|||||||
(ship) => ship.structure.screens.standard,
|
(ship) => ship.structure.screens.standard,
|
||||||
(ship) => ship.structure.screens.advanced,
|
(ship) => ship.structure.screens.advanced,
|
||||||
(mass, standard, advanced) => {
|
(mass, standard, advanced) => {
|
||||||
console.log({
|
|
||||||
mass,
|
|
||||||
standard,
|
|
||||||
advanced,
|
|
||||||
});
|
|
||||||
const standard_mass = standard * Math.max(3, ceil(0.05 * mass));
|
const standard_mass = standard * Math.max(3, ceil(0.05 * mass));
|
||||||
const advanced_mass = advanced * Math.max(4, ceil(0.075 * mass));
|
const advanced_mass = advanced * Math.max(4, ceil(0.075 * mass));
|
||||||
|
|
||||||
|
@ -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;
|
|
37
src/lib/components/ShipEdit/Structure/Screens.svelte
Normal file
37
src/lib/components/ShipEdit/Structure/Screens.svelte
Normal 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>
|
@ -1,14 +1,16 @@
|
|||||||
<Section label="structure">
|
<Section label="structure">
|
||||||
<Hull {...hull}/>
|
<Hull {...hull}/>
|
||||||
|
<Screens {...screens} />
|
||||||
</Section>
|
</Section>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Section from "$lib/components/Section/index.svelte";
|
import Section from "$lib/components/Section/index.svelte";
|
||||||
import Hull from './Hull.svelte';
|
import Hull from './Hull.svelte';
|
||||||
|
import Screens from './Screens.svelte';
|
||||||
|
|
||||||
export let hull = {};
|
export let hull = {};
|
||||||
|
export let screens = {};
|
||||||
|
|
||||||
$: console.log(hull);
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import identification from "./identification.js";
|
|||||||
import { calculateDriveReqs } from './propulsion/drive.js';
|
import { calculateDriveReqs } from './propulsion/drive.js';
|
||||||
import { ftlReqsReaction } from './propulsion/ftl.js';
|
import { ftlReqsReaction } from './propulsion/ftl.js';
|
||||||
import structure from './structure/index.js';
|
import structure from './structure/index.js';
|
||||||
|
import { screenReqsReaction, screensReqsReaction } from './structure/screens.js'
|
||||||
|
|
||||||
const dux = new Updux({
|
const dux = new Updux({
|
||||||
subduxes: {
|
subduxes: {
|
||||||
@ -24,5 +25,6 @@ dux.setMutation( 'setShipMass', mass => u({reqs: {mass}}) );
|
|||||||
|
|
||||||
dux.addReaction( calculateDriveReqs );
|
dux.addReaction( calculateDriveReqs );
|
||||||
dux.addReaction( ftlReqsReaction );
|
dux.addReaction( ftlReqsReaction );
|
||||||
|
dux.addReaction( screenReqsReaction );
|
||||||
|
|
||||||
export default dux;
|
export default dux;
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import { Updux } from 'updux';
|
import { Updux } from 'updux';
|
||||||
|
|
||||||
import hull from './hull.js';
|
import hull from './hull.js';
|
||||||
|
import screens from './screens.js';
|
||||||
|
|
||||||
const dux = new Updux({
|
const dux = new Updux({
|
||||||
subduxes: { hull }
|
subduxes: { hull, screens }
|
||||||
});
|
});
|
||||||
export default dux;
|
export default dux;
|
||||||
|
40
src/lib/shipDux/structure/screens.js
Normal file
40
src/lib/shipDux/structure/screens.js
Normal 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,
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user