reset layout in the dux

main
Yanick Champoux 2022-04-10 18:21:24 -04:00
parent ebddbf3ae8
commit 423ac25a90
2 changed files with 16 additions and 1 deletions

View File

@ -2,7 +2,7 @@
<label>
<input type="checkbox" bind:checked={isMovable} /> edit layout
</label>
<button class="button error">reset layout</button>
<button class="button error" on:click={resetLayout}>reset layout</button>
</div>
<div class="print-output">
@ -41,6 +41,7 @@
<div class="notice">Printing this page will only prints the ship sheet.</div>
<script>
import { getContext } from 'svelte';
import Identification from "./Identification/index.svelte";
import MainSystems from "./MainSystems/index.svelte";
import Hull from "./Hull/index.svelte";
@ -49,6 +50,10 @@
export let ship = {};
export let isMovable = false;
const { dispatch } = getContext('ship');
const resetLayout = () => { isMovable = false; dispatch.resetLayout(); }
</script>
<style>

View File

@ -24,9 +24,19 @@ const dux = new Updux({
actions: {
setShipReqs: null,
setUITransform: null,
resetLayout: null,
},
});
function resetUITransform(thing) {
if(typeof thing !== 'object') return thing;
return u.map((v,k) => k === 'uiTransform' ? '' : resetUITransform(v) , thing )
}
dux.setMutation( 'resetLayout', () => resetUITransform );
dux.setMutation("setShipMass", (mass) => u({ reqs: { mass } }));
dux.setMutation("setShipReqs", (reqs) => u({ reqs }));