-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathSimpleControlModule.svelte
More file actions
55 lines (48 loc) · 1.63 KB
/
SimpleControlModule.svelte
File metadata and controls
55 lines (48 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<script lang="ts">
import type { ShockerResponse } from '$lib/api/internal/v1';
import { getConnection } from '$lib/signalr/index.svelte';
import { ControlType } from '$lib/signalr/models/ControlType';
import { serializeControlMessages } from '$lib/signalr/serializers/Control';
import ControlListener from './ControlListener.svelte';
import ActionButtons from './impl/ActionButtons.svelte';
interface Props {
shocker: ShockerResponse;
shockIntensity: number;
vibrationIntensity: number;
duration: number;
disabled?: boolean;
}
let { shocker, shockIntensity, vibrationIntensity, duration, disabled }: Props = $props();
let active = $state<ControlType | null>(null);
function ctrl(type: ControlType) {
let intensity: number;
switch (type) {
case ControlType.Stop:
intensity = 0;
break;
case ControlType.Shock:
intensity = shockIntensity;
break;
case ControlType.Vibrate:
intensity = vibrationIntensity;
break;
case ControlType.Sound:
intensity = 0;
break;
default:
return;
}
const conn = getConnection();
if (!conn) return;
serializeControlMessages(conn, [{ id: shocker.id, type, intensity, duration }]);
}
</script>
<ControlListener shockerId={shocker.id} bind:active />
<div
class="border-surface-400-500-token flex flex-col items-center justify-center gap-2 overflow-hidden rounded-md border p-2"
>
<!-- Title -->
<h2 class="w-full truncate px-4 text-center text-lg font-bold">{shocker.name}</h2>
<!-- Buttons -->
<ActionButtons {ctrl} {duration} {active} {disabled} />
</div>