Merge branch 'svench'

main
Yanick Champoux 2021-05-17 10:13:22 -04:00
commit 511c93de8a
10 changed files with 167 additions and 105 deletions

1
.gitignore vendored
View File

@ -6,3 +6,4 @@ node_modules
.svelte-kit/ .svelte-kit/
.vercel_build_output/ .vercel_build_output/
package-lock.json package-lock.json
.svench

View File

@ -1,6 +0,0 @@
{
"useTabs": true,
"singleQuote": true,
"trailingComma": "none",
"printWidth": 100
}

View File

@ -1,3 +1,4 @@
## Next ## Next
* Add svench.
* Switch to Sveltekit. * Switch to Sveltekit.

View File

@ -10,13 +10,15 @@
}, },
"devDependencies": { "devDependencies": {
"@sveltejs/kit": "^1.0.0-next.107", "@sveltejs/kit": "^1.0.0-next.107",
"@sveltejs/vite-plugin-svelte": "^1.0.0-next.10",
"eslint": "^7.22.0", "eslint": "^7.22.0",
"eslint-config-prettier": "^8.1.0", "eslint-config-prettier": "^8.1.0",
"eslint-plugin-svelte3": "^3.2.0", "eslint-plugin-svelte3": "^3.2.0",
"prettier": "~2.2.1", "prettier": "~2.2.1",
"prettier-plugin-svelte": "^2.2.0", "prettier-plugin-svelte": "^2.2.0",
"svelte": "^3.34.0", "svelte": "^3.34.0",
"vite": "^2.2.3" "svench": "^0.2.0-14",
"vite": "^2.3.2"
}, },
"type": "module", "type": "module",
"dependencies": { "dependencies": {
@ -29,5 +31,13 @@
"reselect": "^4.0.0", "reselect": "^4.0.0",
"ts-action": "^11.0.0", "ts-action": "^11.0.0",
"updux": "link:/home/yanick/work/javascript/updux/" "updux": "link:/home/yanick/work/javascript/updux/"
},
"prettier": {
"svelteSortOrder": "options-markup-scripts-styles",
"svelteStrictMode": false,
"svelteAllowShorthand": true,
"plugins": [
"prettier-plugin-svelte"
]
} }
} }

View File

@ -24,6 +24,10 @@ h1 {
font-size: var(--font-scale-14); font-size: var(--font-scale-14);
} }
h2 {
font-size: var(--font-scale-12);
}
html, body { html, body {
position: relative; position: relative;
@ -107,3 +111,4 @@ input:focus, select:focus {
input.short { input.short {
width:5em; width:5em;
} }

View File

@ -1,90 +1,93 @@
<Ribbon />
<Header /> <Header />
<nav> <nav>
<input class="reset button small red" type="button" value="reset" on:click={reset} /> <button class="button is-danger" type="button" on:click={reset}>reset</button>
<div class="spacer" /> <div class="spacer" />
<input type="button" class="button small notes" value="notes" on:click={toggle_notes} />
<ul class="button-group"> <button class="button is-info about" on:click={toggle_notes}>about</button>
<input type="button" class="button small green" value="editor"
on:click={() => set_output(null)} /> <div class="field has-addons">
<input type="button" class="button small green" value="json" <p class="control">
on:click={() => set_output('json')} /> <button class="button" on:click={() => set_output(null)}>editor</button>
<input type="button" class="button small green" value="print" </p>
on:click={() => set_output('print')} /> <p class="control">
</ul> <button class="button" on:click={() => set_output("json")}>json</button>
</nav> </p>
<p class="control">
<button class="button" on:click={() => set_output("print")}>print</button>
</p>
</div>
</nav>
{#if show_notes} {#if show_notes}
<Notes show={show_notes} on:close={toggle_notes} /> <Notes show={show_notes} on:close={toggle_notes} />
{/if} {/if}
{#if output === 'json'} {#if output === "json"}
<OutputJson ship={$ship} <OutputJson ship={$ship} on:close={() => set_output(null)} />
on:close={() => set_output(null)}/> {:else if output === "print"}
{:else if output === 'print' } <Print ship={$ship} />
<Print ship={$ship} />
{:else} {:else}
<main>
<ShipSpecs />
<main> <Propulsion
ftl={$ship.ftl}
engine={$ship.engine}
on:change_ftl={change_ftl}
on:change_engine={change_engine}
/>
<ShipSpecs /> <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}
/>
<Propulsion <Section label="weaponry">
ftl={$ship.ftl} <Firecons
engine={$ship.engine} {...$ship.weaponry.firecons}
on:change_ftl={change_ftl} on:change_firecons={change_firecons}
on:change_engine={change_engine} /> />
<Hull <ADFC {...$ship.weaponry.adfc} />
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"> <AddWeapon />
<Firecons
{...$ship.weaponry.firecons}
on:change_firecons={change_firecons} />
<ADFC {...$ship.weaponry.adfc} /> {#each weapons as weapon (weapon.id)}
<Weapon {weapon} id={weapon.id} cost={weapon.cost} mass={weapon.mass} />
{/each}
</Section>
<AddWeapon /> <Carrier {...$ship.carrier} />
</main>
{#each weapons as weapon (weapon.id)}
<Weapon {weapon} id={weapon.id} cost={weapon.cost} mass={weapon.mass} />
{/each}
</Section>
<Carrier {...$ship.carrier} />
</main>
<footer> <footer>
Written by <a href="https://twitter.com/yenzie">Yanick Champoux</a>. Written by <a href="https://twitter.com/yenzie">Yanick Champoux</a>. Code
Code available on <a available on
href="https://github.com/yanick/aotds-shipyard">Github</a> <a href="https://github.com/yanick/aotds-shipyard">Github</a>
</footer> </footer>
{/if} {/if}
<script> <script>
import { setContext } from "svelte"; import { setContext } from "svelte";
import Header from './Header.svelte'; import Header from "./Header.svelte";
import Ribbon from "./Ribbon.svelte";
import shipStore from "../stores/ship"; import shipStore from "../stores/ship";
import OutputJson from './Output/Json.svelte'; import OutputJson from "./Output/Json.svelte";
import Print from './Output/Print/index.svelte'; import Print from "./Output/Print/index.svelte";
import ShipSpecs from './ShipSpecs/index.svelte'; import ShipSpecs from "./ShipSpecs/index.svelte";
import Notes from './Notes.svelte'; import Notes from "./Notes.svelte";
import ShipItem from "./ShipItem/index.svelte"; import ShipItem from "./ShipItem/index.svelte";
import Field from "./Field/index.svelte"; import Field from "./Field/index.svelte";
import Hull from "./Hull/index.svelte"; import Hull from "./Hull/index.svelte";
@ -129,11 +132,11 @@
setContext("ship_change", ship.dispatch); setContext("ship_change", ship.dispatch);
let show_notes = false; let show_notes = false;
const toggle_notes = () => show_notes = !show_notes; const toggle_notes = () => (show_notes = !show_notes);
let output = null; let output = null;
const set_output = value => output = value; const set_output = (value) => (output = value);
</script> </script>
@ -159,7 +162,6 @@
flex: 1; flex: 1;
} }
:global(main > *) { :global(main > *) {
grid-column: 1; grid-column: 1;
} }
@ -174,7 +176,8 @@
text-align: right; text-align: right;
} }
.notes { .about {
margin-right: 2em; margin-right: 2em;
} }
</style> </style>

View File

@ -0,0 +1,13 @@
<Json ship={{potato: 'grande'}}>
</Json>
<script>
import Json from './Json.svelte';
</script>
<style>
div {
background-color: red;
}
</style>

View File

@ -0,0 +1,4 @@
<!-- github ribbon from https://tholman.com/github-corners/ -->
<a href="https://github.com/yanick/aotds-shipyard"
class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>

View File

@ -1,12 +1,13 @@
<div> <div>
<h2>{label}</h2> <h2>{label}</h2>
<hr/> <hr />
</div> </div>
<slot /> <slot />
<script> <script>
export let label; export let label;
</script> </script>
<style> <style>
@ -16,8 +17,12 @@
align-items: baseline; align-items: baseline;
gap: 1em; gap: 1em;
} }
h2 {
font-weight: bold;
}
hr { hr {
flex: 1; flex: 1;
heigth: 0px; background: #333;
} }
</style>
</style>

View File

@ -1,10 +1,10 @@
<div><slot /></div> <div><slot /></div>
<div class="mass" bind:this={mass_el}>{ mass }</div> <div class="mass" bind:this={mass_el}>{mass}</div>
<div class="cost" bind:this={cost_el}>{ cost }</div> <div class="cost" bind:this={cost_el}>{cost}</div>
<script> <script>
import { tick } from 'svelte'; import { tick } from "svelte";
export let mass; export let mass;
export let cost; export let cost;
@ -13,40 +13,54 @@
let cost_el; let cost_el;
const update_el = async (el) => { const update_el = async (el) => {
if(!el) return; if (!el) return;
el.classList.remove('updated'); el.classList.remove("updated");
void el.offsetWidth; void el.offsetWidth;
el.classList.add('updated'); el.classList.add("updated");
} };
$: update_el( mass_el, mass ); $: update_el(mass_el, mass);
$: update_el( cost_el, cost ); $: update_el(cost_el, cost);
</script> </script>
<style> <style>
div { div {
margin-bottom: 1em; margin-bottom: 1em;
} }
.cost,.mass { padding: 0px 2em; text-align: right; } .cost,
.cost { grid-column: 3 } .mass {
.mass { grid-column: 2 } padding: 0px 2em;
text-align: right;
}
.cost {
grid-column: 3;
}
.mass {
grid-column: 2;
}
.ship-item { .ship-item {
display: flex; display: flex;
} }
.ship-item :global(> *) { .ship-item :global(> *) {
flex: 1; flex: 1;
} }
img { img {
width: 0.75em; width: 0.75em;
} }
.cost:after { content: '\00A4'; margin-left: 0.5em; } .cost:after {
.mass:after { content: url(mass.svg); width: 0.75em; display: content: "\00A4";
inline-block; margin-left: 0.5em; } margin-left: 0.5em;
}
.mass:after {
content: url(mass.svg);
width: 0.75em;
display: inline-block;
margin-left: 0.5em;
}
:global(.updated) { :global(.updated) {
animation-name: update; animation-name: update;
@ -54,11 +68,23 @@
animation-fill-mode: forwards; animation-fill-mode: forwards;
} }
@keyframes update { @keyframes update {
0% {color:inherit; font-weight: inherit;} 0% {
20% {color:red; font-weight: bold;} color: inherit;
80% {color:red; font-weight: bold;} font-weight: inherit;
100% {color:inherit; font-weight: inherit; } }
} 20% {
color: red;
font-weight: bold;
}
80% {
color: red;
font-weight: bold;
}
100% {
color: inherit;
font-weight: inherit;
}
}
</style> </style>