main
Yanick Champoux 2022-03-06 14:29:40 -05:00
parent f207fa3d3c
commit 161175c3c9
5 changed files with 100 additions and 12 deletions

View File

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

View 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>

View 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>

View 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>

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