feat: add json output

Merge branch 'json-view' into version-2
This commit is contained in:
Yanick Champoux 2022-03-22 10:54:13 -04:00
commit 00a08fce3b
3 changed files with 131 additions and 71 deletions

View File

@ -1,7 +1,16 @@
<Ribbon /> <main>
<Header />
<ShipEdit /> <Ribbon />
<Header on:changeTab={({ detail }) => activeTab = detail}/>
<div class:hide={activeTab !== 'editor'}>
<ShipEdit />
</div>
<div class:hide={activeTab !== 'json'}>
<JsonOutput />
</div>
</main>
<script> <script>
import { Modal, Card, Nav } from "svelte-chota"; import { Modal, Card, Nav } from "svelte-chota";
@ -10,6 +19,10 @@
import Header from "./Header.svelte"; import Header from "./Header.svelte";
import ShipEdit from "./ShipEdit/index.svelte"; import ShipEdit from "./ShipEdit/index.svelte";
import About from "./About.svelte"; import About from "./About.svelte";
import JsonOutput from './Output/Json.svelte';
let activeTab = 'editor';
$: console.log(activeTab);
</script> </script>
<style> <style>
@ -18,4 +31,12 @@
margin-left: auto; margin-left: auto;
margin-right: auto; margin-right: auto;
} }
.hide {
display: none;
}
main {
width: var(--main-width);
margin-right: auto;
margin-left: auto;
}
</style> </style>

View File

@ -1,23 +1,36 @@
<header> <header>
<h1>The Docks</h1> <h1>The Docks</h1>
<h2> <h2>
a <a href="https://shop.groundzerogames.co.uk/rules.html">Full Thrust</a> ship a <a href="https://shop.groundzerogames.co.uk/rules.html"
builder >Full Thrust</a
> ship builder
</h2> </h2>
<a on:click|preventDefault={() => showAbout = true}>about the app</a> <a on:click|preventDefault={() => (showAbout = true)}>about the app</a>
</header> </header>
<Modal bind:open={showAbout}> <div>
<About/> <Tabs bind:active={activeTab}>
</Modal> <Tab tabid="editor">editor</Tab>
<Tab tabid="json">json view</Tab>
<Tab tabid="print">print view</Tab>
</Tabs>
</div>
<script> <Modal bind:open={showAbout}>
import { <About />
Modal, Card, Nav </Modal>
} from 'svelte-chota';
import About from './About.svelte'; <script>
import { createEventDispatcher } from 'svelte';
import { Modal, Card, Nav, Tab, Tabs } from "svelte-chota";
import About from "./About.svelte";
let showAbout = false; let showAbout = false;
let activeTab = 'editor';
const dispatch = createEventDispatcher();
$: dispatch( 'changeTab', activeTab );
</script> </script>
<style> <style>
@ -27,7 +40,7 @@ import About from './About.svelte';
width: var(--main-width); width: var(--main-width);
margin-left: auto; margin-left: auto;
margin-right: auto; margin-right: auto;
margin-bottom: 3em; margin-bottom: 1em;
} }
h1, h1,
h2 { h2 {
@ -39,7 +52,6 @@ import About from './About.svelte';
h1 { h1 {
font-size: var(--font-scale-15); font-size: var(--font-scale-15);
} }
h2 { h2 {
flex: 1; flex: 1;
@ -50,4 +62,15 @@ import About from './About.svelte';
margin: 0px 2em; margin: 0px 2em;
font-size: var(--font-scale-10); font-size: var(--font-scale-10);
} }
div :global(nav) {
margin-left: 2em;
margin-bottom: 2em;
}
div :global(nav span) {
font-weight: bold;
font-family: var(--main-font-family);
font-size: var(--font-scale-12);
margin-right: 1em;
padding-bottom: 0.125em !important;
}
</style> </style>

View File

@ -1,6 +1,10 @@
<aside transition:fade> <div>
<pre><code>{json}</code></pre> <button class="button primary" on:click={handleSave}>save</button>
</aside>
<pre><code>{json}</code></pre>
</div>
<a style:display="none" {href} {download} bind:this={fileDownload} />
<script> <script>
export let ship = {}; export let ship = {};
@ -8,26 +12,38 @@
$: json = JSON.stringify(ship, null, 2); $: json = JSON.stringify(ship, null, 2);
import { fly, fade } from "svelte/transition"; import { fly, fade } from "svelte/transition";
import { createEventDispatcher } from "svelte"; import { createEventDispatcher, getContext } from "svelte";
const { state } = getContext("ship");
$: json = JSON.stringify($state, null, 2);
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();
const close = () => dispatch("close"); const close = () => dispatch("close");
$: href = "data:text/plain;charset=utf-8," + encodeURIComponent(json);
$: download = ($state?.identification?.shipClass ?? "ship") + ".json";
let fileDownload;
function handleSave() {
fileDownload?.click();
}
</script> </script>
<style> <style>
div {
position: relative;
}
button {
position: absolute;
right: 2em;
top: 1em;
}
pre { pre {
font-family: monospace; font-family: monospace;
font-size: var(--font-scale-9); font-size: var(--font-scale-10);
overflow: scroll; overflow: scroll;
height: 90%; height: 90%;
} }
div {
text-align: right;
}
aside {
padding: 1em;
border: 3px solid var(--indigo-dye);
border-radius: 1em;
font-size: var(--font-scale-11);
}
</style> </style>