aotds-docks/src/components/App.svelte

182 lines
4.4 KiB
Svelte
Raw Normal View History

2021-05-17 14:07:01 +00:00
<Ribbon />
2020-07-28 16:13:04 +00:00
<Header />
2020-07-28 21:20:30 +00:00
2021-05-17 14:07:01 +00:00
<nav>
<button class="button is-danger" type="button" on:click={reset}>reset</button>
2020-07-28 21:20:30 +00:00
2021-05-17 14:07:01 +00:00
<div class="spacer" />
2020-07-28 22:00:39 +00:00
2021-05-17 14:07:01 +00:00
<button class="button is-info about" on:click={toggle_notes}>about</button>
<div class="field has-addons">
<p class="control">
<button class="button" on:click={() => set_output(null)}>editor</button>
</p>
<p class="control">
<button class="button" on:click={() => set_output("json")}>json</button>
</p>
<p class="control">
<button class="button" on:click={() => set_output("print")}>print</button>
</p>
</div>
</nav>
2020-07-28 15:48:15 +00:00
2020-07-30 00:29:21 +00:00
{#if show_notes}
2021-05-17 14:07:01 +00:00
<Notes show={show_notes} on:close={toggle_notes} />
2020-07-30 00:29:21 +00:00
{/if}
2021-05-17 14:07:01 +00:00
{#if output === "json"}
<OutputJson ship={$ship} on:close={() => set_output(null)} />
{:else if output === "print"}
<Print ship={$ship} />
2020-07-30 00:29:21 +00:00
{:else}
2021-05-17 14:07:01 +00:00
<main>
<ShipSpecs />
<Propulsion
ftl={$ship.ftl}
engine={$ship.engine}
on:change_ftl={change_ftl}
on:change_engine={change_engine}
/>
<Hull
ship_mass={$ship.general.mass}
{...$ship.structure.hull}
on:change_hull={change_hull}
screens={$ship.structure.screens}
armour={$ship.structure.armour}
on:set_screens={set_screens}
cargo={$ship.cargo}
streamlining={$ship.streamlining}
on:set_cargo={ship_dispatch}
on:ship_change={ship_dispatch}
/>
<Section label="weaponry">
<Firecons
{...$ship.weaponry.firecons}
on:change_firecons={change_firecons}
/>
<ADFC {...$ship.weaponry.adfc} />
<AddWeapon />
{#each weapons as weapon (weapon.id)}
<Weapon {weapon} id={weapon.id} cost={weapon.cost} mass={weapon.mass} />
{/each}
</Section>
<Carrier {...$ship.carrier} />
</main>
2020-07-28 21:20:30 +00:00
<footer>
2021-05-17 14:07:01 +00:00
Written by <a href="https://twitter.com/yenzie">Yanick Champoux</a>. Code
available on
<a href="https://github.com/yanick/aotds-shipyard">Github</a>
2020-07-28 21:20:30 +00:00
</footer>
2020-07-30 00:29:21 +00:00
{/if}
2021-05-17 14:07:01 +00:00
2020-07-28 15:48:15 +00:00
<script>
import { setContext } from "svelte";
2021-05-17 14:07:01 +00:00
import Header from "./Header.svelte";
import Ribbon from "./Ribbon.svelte";
2021-05-17 13:48:31 +00:00
import shipStore from "../stores/ship";
2021-05-17 14:07:01 +00:00
import OutputJson from "./Output/Json.svelte";
import Print from "./Output/Print/index.svelte";
2020-07-28 15:48:15 +00:00
2021-05-17 14:07:01 +00:00
import ShipSpecs from "./ShipSpecs/index.svelte";
import Notes from "./Notes.svelte";
2020-07-28 15:48:15 +00:00
import ShipItem from "./ShipItem/index.svelte";
import Field from "./Field/index.svelte";
2021-05-17 13:48:31 +00:00
import Hull from "./Hull/index.svelte";
2020-07-28 15:48:15 +00:00
import Firecons from "./Firecons.svelte";
import Propulsion from "./Propulsion/index.svelte";
2021-05-17 13:48:31 +00:00
import Section from "./Section/index.svelte";
import Weapon from "./Weapon/index.svelte";
import Carrier from "./Carrier/index.svelte";
import ADFC from "./Weaponry/ADFC/index.svelte";
import AddWeapon from "./Weaponry/AddWeapon/index.svelte";
2020-07-28 15:48:15 +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;
const set_screens = ({ detail }) => ship.dispatch.set_screens(detail);
const ship_dispatch = ({ detail }) => ship.dispatch(detail);
2020-07-28 22:00:39 +00:00
let show_notes = false;
2021-05-17 14:07:01 +00:00
const toggle_notes = () => (show_notes = !show_notes);
2020-07-28 22:00:39 +00:00
let output = null;
2021-05-17 14:07:01 +00:00
const set_output = (value) => (output = value);
2020-07-28 22:00:39 +00:00
2020-07-28 15:48:15 +00:00
</script>
<style>
main {
display: grid;
2020-07-28 18:38:40 +00:00
grid-template-columns: 1fr 14em 8em;
2020-07-30 00:29:21 +00:00
width: 60em;
2020-07-28 17:26:08 +00:00
margin-left: auto;
margin-right: auto;
2020-07-28 15:48:15 +00:00
}
2020-07-28 21:20:30 +00:00
nav {
grid-column: 1 / span 3 !important;
display: flex;
2020-07-30 00:29:21 +00:00
width: 60em;
margin-left: auto;
margin-right: auto;
margin-bottom: 1em;
2020-07-28 21:20:30 +00:00
}
nav .spacer {
flex: 1;
}
:global(main > *) {
2020-07-28 15:48:15 +00:00
grid-column: 1;
}
input.reset {
grid-column: 2;
}
2020-07-28 21:20:30 +00:00
footer {
width: var(--main-width);
margin: 0 auto;
text-align: right;
}
2020-07-28 22:00:39 +00:00
2021-05-17 14:07:01 +00:00
.about {
2020-07-28 22:00:39 +00:00
margin-right: 2em;
}
2021-05-17 14:07:01 +00:00
2020-07-28 15:48:15 +00:00
</style>