〰️ Updates controller layout

This commit is contained in:
Rune Harlyk
2024-08-17 19:27:24 +02:00
committed by Rune Harlyk
parent 6988c61a50
commit d6b3793275
+41 -12
View File
@@ -2,8 +2,16 @@
import nipplejs from 'nipplejs'; import nipplejs from 'nipplejs';
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import { capitalize, throttler, toInt8 } from '$lib/utilities'; import { capitalize, throttler, toInt8 } from '$lib/utilities';
import { input, outControllerData, mode, modes, type Modes, ModesEnum, socket } from '$lib/stores'; import {
input,
outControllerData,
mode,
modes,
type Modes,
ModesEnum
} from '$lib/stores';
import type { vector } from '$lib/models'; import type { vector } from '$lib/models';
import VerticalSlider from '$lib/components/input/vertical-slider.svelte';
let throttle = new throttler(); let throttle = new throttler();
let left: nipplejs.JoystickManager; let left: nipplejs.JoystickManager;
@@ -68,15 +76,15 @@
throttle.throttle(updateData, throttle_timing); throttle.throttle(updateData, throttle_timing);
}; };
const handleRange = (event:Event, key: 'speed' | 'height' | 's1') => { const handleRange = (event: Event, key: 'speed' | 'height' | 's1') => {
const value:number = event.target?.value const value: number = event.target?.value;
input.update((inputData) => { input.update((inputData) => {
inputData[key] = value; inputData[key] = value;
return inputData; return inputData;
}); });
throttle.throttle(updateData, throttle_timing); throttle.throttle(updateData, throttle_timing);
} };
const changeMode = (modeValue: Modes) => { const changeMode = (modeValue: Modes) => {
mode.set(modes.indexOf(modeValue)); mode.set(modes.indexOf(modeValue));
@@ -98,24 +106,45 @@
<kbd class="kbd">S</kbd> <kbd class="kbd">S</kbd>
<kbd class="kbd">D</kbd> <kbd class="kbd">D</kbd>
</div> </div>
<div class="flex justify-center w-full"> <div class="flex justify-center w-full"></div>
</div> </div>
<div class="absolute bottom-0 z-10 flex items-end">
<div class="flex items-center flex-col bg-base-300 bg-opacity-50 p-4 pb-2 gap-2 rounded-tr-xl">
<VerticalSlider min={0} max={100} on:input={(e) => handleRange(e, 'height')} />
<label for="height">Ht</label>
</div> </div>
<div class="absolute bottom-0 z-10 p-4 gap-4 flex items-end"> <div class="flex items-end gap-4 bg-base-300 bg-opacity-50 h-min rounded-tr-xl p-2">
<div class="join">
{#each modes as modeValue} {#each modes as modeValue}
<button class="btn btn-outline" class:btn-active={$mode === modes.indexOf(modeValue)} on:click={() => changeMode(modeValue)}> <button
class="btn join-item"
class:btn-primary={$mode === modes.indexOf(modeValue)}
on:click={() => changeMode(modeValue)}
>
{capitalize(modeValue)} {capitalize(modeValue)}
</button> </button>
{/each} {/each}
<div> </div>
<div class="flex gap-4">
{#if $mode === ModesEnum.Walk || $mode === ModesEnum.Crawl} {#if $mode === ModesEnum.Walk || $mode === ModesEnum.Crawl}
<div>
<label for="s1">S1</label> <label for="s1">S1</label>
<input type="range" name="s1" min="0" max="100" on:input={(e) => handleRange(e, 's1')} class="range range-sm" /> <input
type="range"
name="s1"
min="0"
max="100"
on:input={(e) => handleRange(e, 's1')}
class="range range-sm range-primary"
/>
</div>
<div>
<label for="speed">Speed</label> <label for="speed">Speed</label>
<input type="range" name="speed" min="0" max="100" on:input={(e) => handleRange(e, 'speed')} class="range range-sm" /> <input type="range" name="speed" min="0" max="100" on:input={(e) => handleRange(e, 'speed')} class="range range-sm range-primary" />
</div>
{/if} {/if}
<label for="height">Height</label> </div>
<input type="range" name="height" min="0" max="100" on:input={(e) => handleRange(e, 'height')} class="range range-sm" />
</div> </div>
</div> </div>
</div> </div>