aotds-docks/src/App.svelte

115 lines
3.1 KiB
Svelte
Raw Normal View History

2020-07-19 20:21:28 +00:00
<script>
import { setContext } from 'svelte';
import shipStore from './stores/ship';
2020-07-26 16:02:15 +00:00
import ShipItem from './components/ShipItem/index.svelte';
2020-07-19 20:21:28 +00:00
import ShipCost from './components/ShipCost.svelte';
2020-07-26 16:02:15 +00:00
import Field from './components/Field/index.svelte';
2020-07-19 20:21:28 +00:00
import Hull from './components/Hull.svelte';
import Identification from './components/Identification.svelte';
import Firecons from './components/Firecons.svelte';
import Propulsion from './components/Propulsion/index.svelte';
import Section from '~C/Section';
import Weapon from '~C/Weapon';
2020-07-26 16:02:15 +00:00
import Cargo from '~C/Cargo/index.svelte';
2020-07-26 22:22:05 +00:00
import Streamlining from '~C/Streamlining/index.svelte';
2020-07-27 17:42:19 +00:00
import Carrier from '~C/Carrier';
2020-07-27 18:14:05 +00:00
import ADFC from '~C/Weaponry/ADFC';
2020-07-27 22:17:55 +00:00
import AddWeapon from '~C/Weaponry/AddWeapon';
2020-07-19 20:21:28 +00:00
const ship = shipStore();
setContext('ship',ship);
let ship_name = $ship.general.name;
const change_name = event => ship.dispatch(
ship.actions.set_name( event.target.value) );
const change_mass = ({target: {value}}) => ship.dispatch(ship.actions.set_ship_mass(parseInt(value)));
const add_weapon = () => ship.dispatch.add_weapon();
const change_ftl = ({detail}) => ship.dispatch.set_ftl(detail);
const change_engine = ({detail}) => ship.dispatch.set_engine(detail);
const change_hull = ({detail}) => ship.dispatch.set_hull(detail);
const change_firecons = ({detail}) => ship.dispatch.set_firecons(detail);
const change_weapon = ({detail}) => ship.dispatch.set_weapon(detail);
let weapons = [];
$: console.log(weapons);
$: weapons= $ship.weaponry.weapons;
const reset = ship.dispatch.reset;
2020-07-24 18:11:18 +00:00
const set_screens = ({detail}) => ship.dispatch.set_screens(detail);
2020-07-19 20:21:28 +00:00
2020-07-26 16:19:52 +00:00
const ship_dispatch = ({detail}) => ship.dispatch(detail);
2020-07-26 22:22:05 +00:00
setContext( 'ship_change', ship.dispatch );
2020-07-19 20:21:28 +00:00
</script>
<main>
2020-07-19 20:41:36 +00:00
<input class="reset" type="button" value="reset" on:click={reset} />
2020-07-19 20:21:28 +00:00
<Identification />
<ShipCost />
2020-07-24 18:11:18 +00:00
<Propulsion
ftl={$ship.ftl}
2020-07-19 20:21:28 +00:00
engine={$ship.engine}
2020-07-24 18:11:18 +00:00
on:change_ftl={change_ftl}
2020-07-19 20:21:28 +00:00
on:change_engine={change_engine}
/>
<Hull ship_mass={$ship.general.mass}
{ ... $ship.structure.hull }
on:change_hull={change_hull}
screens={ $ship.structure.screens}
2020-07-26 21:55:51 +00:00
armour={$ship.structure.armour}
2020-07-24 18:11:18 +00:00
on:set_screens={set_screens}
2020-07-26 21:55:51 +00:00
on:ship_change={ship_dispatch}
2020-07-19 20:21:28 +00:00
/>
<Section label="weaponry">
<Firecons { ... $ship.weaponry.firecons }
on:change_firecons={ change_firecons }/>
2020-07-27 18:14:05 +00:00
<ADFC {...$ship.weaponry.adfc } />
2020-07-27 22:17:55 +00:00
<AddWeapon />
2020-07-19 20:21:28 +00:00
{#each weapons as weapon (weapon.id)}
2020-07-27 20:19:08 +00:00
<Weapon {weapon} id={weapon.id} cost={weapon.cost} mass={weapon.mass} />
2020-07-19 20:21:28 +00:00
{/each}
</Section>
2020-07-26 16:02:15 +00:00
<Section label="misc">
2020-07-26 16:19:52 +00:00
<Cargo {...$ship.cargo} on:set_cargo={ship_dispatch}/>
2020-07-26 22:22:05 +00:00
<Streamlining {...$ship.streamlining} />
2020-07-26 16:02:15 +00:00
</Section>
2020-07-27 17:42:19 +00:00
<Carrier {...$ship.carrier} />
2020-07-26 22:22:05 +00:00
2020-07-19 20:21:28 +00:00
</main>
<style>
main {
display: grid;
width: 60em;
grid-template-columns: 4fr 1fr 1fr;
}
main :global(> *) {
grid-column: 1;
}
2020-07-19 20:41:36 +00:00
input.reset { grid-column: 2 }
2020-07-19 20:21:28 +00:00
</style>