diff options
author | Jakob Stendahl <jakobste@uio.no> | 2021-10-21 14:12:12 +0200 |
---|---|---|
committer | Jakob Stendahl <jakobste@uio.no> | 2021-10-21 14:12:12 +0200 |
commit | f243dc8d7527cde3d5b5a4f6e659cf7604f5ae2a (patch) | |
tree | 143b71f2bb6b84370505473d4624d52f1e264bb0 /src_frontend/Components/MainControls | |
parent | a69d9dbc80dfaa0fc3eef3b5ac48e1c2a25fa08b (diff) | |
download | Luxcena-Neo-f243dc8d7527cde3d5b5a4f6e659cf7604f5ae2a.tar.gz Luxcena-Neo-f243dc8d7527cde3d5b5a4f6e659cf7604f5ae2a.zip |
:sparkles: Make all variable-types changeable from both home and editor
Diffstat (limited to 'src_frontend/Components/MainControls')
-rw-r--r-- | src_frontend/Components/MainControls/ControlComponents.svelte | 6 | ||||
-rw-r--r-- | src_frontend/Components/MainControls/ControlOthers.svelte | 62 |
2 files changed, 54 insertions, 14 deletions
diff --git a/src_frontend/Components/MainControls/ControlComponents.svelte b/src_frontend/Components/MainControls/ControlComponents.svelte index 71c522a..f12ccbb 100644 --- a/src_frontend/Components/MainControls/ControlComponents.svelte +++ b/src_frontend/Components/MainControls/ControlComponents.svelte @@ -59,7 +59,7 @@ if (value.value == null) { delete variables[name]; } else { - variables[name] = value.value; + variables[name] = value; } variables = variables; } @@ -143,5 +143,7 @@ {#if Object.keys(colorVariables).length > 0} <ControlColors on:change={setColor} bind:colorVariables={colorVariables} /> {/if} - <ControlOthers /> + {#if Object.keys(variables).length > 0} + <ControlOthers bind:variables={variables} /> + {/if} </div>
\ No newline at end of file diff --git a/src_frontend/Components/MainControls/ControlOthers.svelte b/src_frontend/Components/MainControls/ControlOthers.svelte index 390daf9..4261c64 100644 --- a/src_frontend/Components/MainControls/ControlOthers.svelte +++ b/src_frontend/Components/MainControls/ControlOthers.svelte @@ -1,13 +1,16 @@ <script> + import { openSocket } from "../../stores/socketStore"; + import Toggle from "../../ComponentLib/Toggle.svelte"; - // This is a list of variables that we can change - export let variables = [ - {id: 1, name: "Speed", type: "range", value: 20, min: 0, max: 100}, - {id: 2, name: "Tingle intensity", type: "range", value: 40, min: 0, max: 255}, - {id: 3, name: "Amount of tingle", type: "range", value: 90, min: 0, max: 100}, - {id: 4, name: "Variable of unknown type", type: "date", value: "January"} - ]; + export let variables = {}; + function setVar(ev) { + if (ev.target.type == "checkbox") { + openSocket.emit("var:set", ev.target.id, ev.target.checked); + } else { + openSocket.emit("var:set", ev.target.id, ev.target.value); + } + }; </script> <style> @@ -19,18 +22,53 @@ padding: 15px; text-align: left; } + label { + width: 100%; + } + .var-group { + display: flex; + margin-top: 5px; + } input { width: 100%; } + button { + width: 100%; + padding: 10px; + background-color: var(--grey-300); + border: none; + border-radius: 15px; + margin-top: 5px; + } + button:hover { filter: brightness(0.9); } + button:active { filter: brightness(0.85); } + </style> <div class="wrapper drop-shadow"> - {#each variables as variable} - <label for={variable.id}>{variable.name}</label> - {#if variable.type == "range"} - <input type="range" id={variable.id} min={variable.min} max={variable.max} value={variable.value}> + {#each Object.entries(variables) as [name, value]} + <div class:var-group={["BOOL"].includes(value.type)}> + {#if !["TRIGGER"].includes(value.type)} + <label for={name}>{name}</label> + {/if} + + {#if value.type == "INT"} + <div class="var-group"> + <input type="range" id={name} min={value.min} max={value.max} bind:value={value.value} on:change={setVar}> + {value.value} + </div> + {:else if value.type == "FLOAT"} + <div class="var-group"> + <input type="range" id={name} min={value.min} max={value.max} step={value.step} bind:value={value.value} on:change={setVar}> + {value.value} + </div> + {:else if value.type == "BOOL"} + <Toggle id="{name}" bind:checked={value.value} on:change={setVar} /> + {:else if value.type == "TRIGGER"} + <button type="button" id="{name}" value="true" on:click={setVar}>Trigger {name}</button> {:else} - <input type="text" id={variable.id} value={variable.value} /> + <input type="text" id={name} bind:value={value.value} on:blur={setVar} /> {/if} + </div> {/each} </div>
\ No newline at end of file |