reset layout in the dux

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

View File

@ -24,9 +24,19 @@ const dux = new Updux({
actions: { actions: {
setShipReqs: null, setShipReqs: null,
setUITransform: 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("setShipMass", (mass) => u({ reqs: { mass } }));
dux.setMutation("setShipReqs", (reqs) => u({ reqs })); dux.setMutation("setShipReqs", (reqs) => u({ reqs }));