This commit is contained in:
Yanick Champoux 2022-03-07 14:40:04 -05:00
parent 752330bdf5
commit b3fa0917f3
2 changed files with 14 additions and 12 deletions

View File

@ -1,6 +1,6 @@
<label>needle weapon</label>
<Arcs selected={arcs} on:click_arc={({ detail }) => click_arc(detail)} />
<Arcs selected={[arc]} on:click_arc={({ detail }) => click_arc(detail)} />
<script>
import { getContext } from "svelte";
@ -9,18 +9,13 @@
const all_arcs = ["FS", "F", "FP", "AP", "A", "AS"];
export let arcs = ["F"];
const click_arc = (arc) => {
console.log(arc);
return;
if (arcs[0] === arc) return;
arcs = [arc];
};
export let arc = "F";
const dispatch = createEventDispatcher();
$: dispatch("change", { arcs });
const click_arc = (arc) => {
dispatch("change",{arc});
};
</script>
<style>

View File

@ -8,7 +8,8 @@ export const weaponTypes = [
{ name: 'submunition pack', type: 'submunition', reqs: { mass:1, cost:3 }},
{ name: 'point defence system', type: 'pds', reqs: {mass:1,cost:3}},
{ name: 'scattergun', type: 'scattergun', reqs: { mass:1,cost:4 }},
{ name: 'needle weapon', type: 'needle', reqs: { mass: 2, cost: 6 }},
{ name: 'needle weapon', type: 'needle', reqs: { mass: 2, cost: 6 },
initial: { arc: 'F' }},
];
const dux = new Updux({
@ -16,12 +17,17 @@ const dux = new Updux({
actions: {
addWeapon: null,
removeWeapon: null,
setWeapon: null,
},
});
dux.setMutation('setWeapon', ({id,...rest}) =>
u.map( u.if( (w) => w.id === id, { ...rest }))
);
dux.setMutation('removeWeapon', id => state => [
...state.filter( (w) => w.id !== id )
])
]);
dux.setMutation('addWeapon', type => state => {
return [
@ -30,6 +36,7 @@ dux.setMutation('addWeapon', type => state => {
id: state.length === 0 ? 1 : state[state.length -1]+1,
type,
reqs: weaponReqs({type}),
...weaponTypes.find(w => w.type === type ).initial,
}
]
});