From 3fb959d9f3c4199d5608e09a4d20d6894564ef78 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Sat, 8 Apr 2023 13:47:00 -0400 Subject: [PATCH] wip --- src/lib/components/Field.svelte | 2 +- .../components/ShipEdit/Weaponry.story.svelte | 17 +++ src/lib/components/ShipEdit/Weaponry.svelte | 19 +-- .../ShipEdit/Weaponry/AddWeapon.svelte | 38 ++++-- .../Weaponry/Weapon/Arcs.story.svelte | 8 ++ .../ShipEdit/Weaponry/Weapon/Arcs.svelte | 10 +- .../Weaponry/Weapon/Beam/index.svelte | 121 ++++++++++-------- .../ShipEdit/Weaponry/Weapon/Needle.svelte | 19 +-- .../Weaponry/Weapon/Submunition.svelte | 9 +- .../ShipEdit/Weaponry/Weapon/index.svelte | 47 +++---- src/lib/store/ship.test.ts | 7 + src/lib/store/ship.ts | 38 ++++-- src/lib/store/ship/weaponry/rules.ts | 56 ++++++-- src/lib/store/ship/weaponry/weapons.test.ts | 39 ++++++ src/lib/store/ship/weaponry/weapons.ts | 50 +++++--- 15 files changed, 304 insertions(+), 176 deletions(-) create mode 100644 src/lib/components/ShipEdit/Weaponry.story.svelte create mode 100644 src/lib/components/ShipEdit/Weaponry/Weapon/Arcs.story.svelte create mode 100644 src/lib/store/ship/weaponry/weapons.test.ts diff --git a/src/lib/components/Field.svelte b/src/lib/components/Field.svelte index 68c73cc..506ea34 100644 --- a/src/lib/components/Field.svelte +++ b/src/lib/components/Field.svelte @@ -1,4 +1,4 @@ -
+
{#if label} {/if} diff --git a/src/lib/components/ShipEdit/Weaponry.story.svelte b/src/lib/components/ShipEdit/Weaponry.story.svelte new file mode 100644 index 0000000..f62f327 --- /dev/null +++ b/src/lib/components/ShipEdit/Weaponry.story.svelte @@ -0,0 +1,17 @@ + + + + + diff --git a/src/lib/components/ShipEdit/Weaponry.svelte b/src/lib/components/ShipEdit/Weaponry.svelte index 5d133ab..6ff4423 100644 --- a/src/lib/components/ShipEdit/Weaponry.svelte +++ b/src/lib/components/ShipEdit/Weaponry.svelte @@ -2,14 +2,12 @@ - + {#each weapons as weapon (weapon.id)} + + {/each} diff --git a/src/lib/components/ShipEdit/Weaponry/Weapon/Arcs.story.svelte b/src/lib/components/ShipEdit/Weaponry/Weapon/Arcs.story.svelte new file mode 100644 index 0000000..59dc606 --- /dev/null +++ b/src/lib/components/ShipEdit/Weaponry/Weapon/Arcs.story.svelte @@ -0,0 +1,8 @@ + + + + + diff --git a/src/lib/components/ShipEdit/Weaponry/Weapon/Arcs.svelte b/src/lib/components/ShipEdit/Weaponry/Weapon/Arcs.svelte index 6657c21..effd42c 100644 --- a/src/lib/components/ShipEdit/Weaponry/Weapon/Arcs.svelte +++ b/src/lib/components/ShipEdit/Weaponry/Weapon/Arcs.svelte @@ -1,10 +1,10 @@ - {#each all_arcs as arc (arc)} + {#each arcs as arc (arc)} click_arc(arc)} + on:click={() => clickArc(arc)} /> {/each} @@ -12,17 +12,17 @@ diff --git a/src/lib/components/ShipEdit/Weaponry/Weapon/Submunition.svelte b/src/lib/components/ShipEdit/Weaponry/Weapon/Submunition.svelte index 070b55a..584d318 100644 --- a/src/lib/components/ShipEdit/Weaponry/Weapon/Submunition.svelte +++ b/src/lib/components/ShipEdit/Weaponry/Weapon/Submunition.svelte @@ -1,19 +1,16 @@ - click_arc(detail)} /> + clickArc(detail)} /> diff --git a/src/lib/components/ShipEdit/Weaponry/Weapon/index.svelte b/src/lib/components/ShipEdit/Weaponry/Weapon/index.svelte index 0f799df..adb081d 100644 --- a/src/lib/components/ShipEdit/Weaponry/Weapon/index.svelte +++ b/src/lib/components/ShipEdit/Weaponry/Weapon/index.svelte @@ -1,15 +1,8 @@
- + - +
@@ -19,34 +12,33 @@ import Arc from "./Arc.svelte"; import ShipItem from "$lib/components/ShipItem.svelte"; import Field from "$lib/components/Field.svelte"; - import Beam from "./Beam/index.svelte"; - import Submunition from "./Submunition.svelte"; - import PointDefenceSystem from "./PDS.svelte"; - import Scattergun from "./Scattergun.svelte"; + import Beam from "./Beam/index.svelte"; + import Submunition from "./Submunition.svelte"; + import PointDefenceSystem from "./PDS.svelte"; + import Scattergun from "./Scattergun.svelte"; import Needle from "./Needle.svelte"; const component = { - beam: Beam, - submunition: Submunition, - pds: PointDefenceSystem, - scattergun: Scattergun, - needle: Needle, + beam: Beam, + submunition: Submunition, + pds: PointDefenceSystem, + scattergun: Scattergun, + needle: Needle, }; - export let weapon = {}; - $: reqs = weapon.reqs; + export let reqs = {}; + export let specs = {}; export let id; - const ship = getContext("ship"); + const api = getContext("api"); - $: type = weapon.type; + $: type = specs.type; - const remove = () => ship.dispatch.removeWeapon(id); + const remove = () => api?.dispatch?.removeWeapon?.(id); const update = ({ detail }) => { - console.log({id,type}) - ship.dispatch.setWeapon({ - id, + console.log({ id, type }); + api?.dispatch?.setWeapon?.(id, { type, ...detail, }); @@ -54,6 +46,9 @@