firecons
This commit is contained in:
parent
f207fa3d3c
commit
161175c3c9
@ -129,18 +129,6 @@ dux.addSubscription((store) =>
|
||||
)
|
||||
);
|
||||
|
||||
const calc_firecons_reqs = (nbr) => ({
|
||||
cost: 4 * nbr,
|
||||
mass: nbr,
|
||||
});
|
||||
|
||||
const set_firecons = action("set_firecons", payload());
|
||||
dux.addMutation(set_firecons, (nbr) =>
|
||||
u.updateIn("weaponry.firecons", {
|
||||
nbr,
|
||||
...calc_firecons_reqs(nbr),
|
||||
})
|
||||
);
|
||||
|
||||
export default dux.asDux;
|
||||
|
||||
|
21
src/lib/components/ShipEdit/Weaponry/Firecons.svelte
Normal file
21
src/lib/components/ShipEdit/Weaponry/Firecons.svelte
Normal file
@ -0,0 +1,21 @@
|
||||
<ShipItem {...reqs}>
|
||||
<Field label="firecons">
|
||||
<input type="number" class="short" bind:value={stations} />
|
||||
</Field>
|
||||
</ShipItem>
|
||||
|
||||
<script>
|
||||
import { getContext } from 'svelte';
|
||||
import ShipItem from "$lib/components/ShipItem/index.svelte";
|
||||
import Field from "$lib/components/Field/index.svelte";
|
||||
|
||||
export let stations = 0;
|
||||
export let reqs = {};
|
||||
|
||||
const { dispatch } = getContext('ship');
|
||||
|
||||
$: dispatch.setFirecons(stations);
|
||||
</script>
|
||||
|
||||
<style>
|
||||
</style>
|
33
src/lib/components/ShipEdit/Weaponry/Weaponry.stories.svelte
Normal file
33
src/lib/components/ShipEdit/Weaponry/Weaponry.stories.svelte
Normal file
@ -0,0 +1,33 @@
|
||||
<Meta title="ShipEdit/Weaponry" component={Weaponry} argTypes={{}} />
|
||||
|
||||
<Story name="Primary" args={{}} />
|
||||
|
||||
<Template let:args>
|
||||
<div style="width: 50em">
|
||||
<Weaponry {...args} {...$state}/>
|
||||
</div>
|
||||
</Template>
|
||||
|
||||
<script>
|
||||
import { Meta, Template, Story } from "@storybook/addon-svelte-csf";
|
||||
import { action } from "@storybook/addon-actions";
|
||||
|
||||
import { setContext } from "svelte";
|
||||
import { readable, get, derived } from "svelte/store";
|
||||
|
||||
import Weaponry from "./index.svelte";
|
||||
import weaponryDux from '$lib/shipDux/weaponry/index.js';
|
||||
|
||||
const store = weaponryDux.createStore();
|
||||
const state = readable(store.getState(), (set) => {
|
||||
store.subscribe(() => {
|
||||
set(store.getState());
|
||||
});
|
||||
});
|
||||
|
||||
setContext("ship", {
|
||||
dispatch: store.dispatch,
|
||||
shipMass: readable(50),
|
||||
state,
|
||||
});
|
||||
</script>
|
16
src/lib/components/ShipEdit/Weaponry/index.svelte
Normal file
16
src/lib/components/ShipEdit/Weaponry/index.svelte
Normal file
@ -0,0 +1,16 @@
|
||||
<Section label="weaponry">
|
||||
<Firecons {...firecons} />
|
||||
</Section>
|
||||
|
||||
<script>
|
||||
import Section from "$lib/components/Section/index.svelte";
|
||||
|
||||
import Firecons from './Firecons.svelte';
|
||||
|
||||
export let firecons = {};
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<style>
|
||||
</style>
|
30
src/lib/shipDux/weaponry/index.js
Normal file
30
src/lib/shipDux/weaponry/index.js
Normal file
@ -0,0 +1,30 @@
|
||||
import { Updux } from "updux";
|
||||
import u from "updeep";
|
||||
|
||||
const reqs = { cost: 0, mass: 0 };
|
||||
|
||||
const dux = new Updux({
|
||||
initial: {
|
||||
firecons: {
|
||||
stations: 0,
|
||||
reqs,
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
setFirecons: null,
|
||||
},
|
||||
});
|
||||
|
||||
dux.setMutation("setFirecons", (stations) =>
|
||||
u({
|
||||
firecons: {
|
||||
stations,
|
||||
reqs: {
|
||||
cost: 4 * stations,
|
||||
mass: stations,
|
||||
},
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
export default dux;
|
Loading…
Reference in New Issue
Block a user