Skip to content

Commit 5814d92

Browse files
committed
got it hooked up to new interactive features, update settings
1 parent 75f44e9 commit 5814d92

File tree

9 files changed

+542
-102
lines changed

9 files changed

+542
-102
lines changed

src/components/settings/controls/SettingsButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ export function SettingsButton({ setting }) {
66
</button>
77
</div>
88
)
9-
}
9+
}

src/components/settings/controls/SettingsCheck.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,45 @@
1+
import { runRpc } from "@/util/ws";
2+
import { useEffect, useState } from "react";
3+
14
export function SettingsCheck({ setting }) {
5+
const [value, setValue] = useState(false);
6+
const [floatValue, setFloatValue] = useState(0.0);
7+
8+
useEffect(() => {
9+
runRpc("getcvar", setting.cvar).then((response) => {
10+
if (response !== null && response.length > 0) {
11+
if (setting.mode === "negate") {
12+
const floatVal = parseFloat(response);
13+
setValue(floatVal < 0.0);
14+
setFloatValue(floatVal);
15+
} else {
16+
setValue(response !== "0");
17+
}
18+
}
19+
});
20+
}, []);
21+
22+
const callback = (val: boolean) => {
23+
if (setting.mode === "negate") {
24+
const f = val ? -Math.abs(floatValue) : Math.abs(floatValue);
25+
runRpc("setcvar", `${setting.cvar} ${f}`);
26+
} else {
27+
const b = val ? "1" : "0";
28+
runRpc("setcvar", `${setting.cvar} ${b}`);
29+
}
30+
setValue(val);
31+
};
32+
233
return (
334
<div className="flex gap-3">
435
<div className="flex h-6 shrink-0 items-center">
536
<div className="group grid size-8 grid-cols-1">
637
<input
738
id={setting.cvar}
39+
checked={value}
40+
onChange={(ev) => {
41+
callback(ev.target.checked);
42+
}}
843
type="checkbox"
944
className="col-start-1 row-start-1 appearance-none border border-gray-300 bg-white/5 disabled:bg-white/10 disabled:checked:bg-white/10 checked:border-stone-400 checked:bg-stone-400 indeterminate:border-stone-400 indeterminate:bg-stone-400 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-stone-400 disabled:border-gray-300 forced-colors:appearance-auto"
1045
/>
Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
1+
import { runRpc } from "@/util/ws";
2+
import { useEffect, useState } from "react";
3+
14
export function SettingsSelect({ setting }) {
2-
return (
3-
<div>
4-
<label className="block mb-2 text-white tf2-light text-xl">{setting.label}</label>
5-
<select className="px-4 py-2 mb-2 border text-white">
6-
{setting.options.map((option) => (
7-
<option key={option.value} value={option.value}>
8-
{option.label}
9-
</option>
10-
))}
11-
</select>
12-
</div>
13-
)
14-
}
5+
const [value, setValue] = useState(0);
6+
7+
useEffect(() => {
8+
runRpc("getcvar", setting.cvar).then((response) => {
9+
if (response !== null && response.length > 0) {
10+
setValue(parseFloat(response));
11+
}
12+
});
13+
}, []);
14+
15+
const callback = (val: string) => {
16+
runRpc("setcvar", `${setting.cvar} ${val}`);
17+
setValue(parseInt(val));
18+
};
19+
20+
return (
21+
<div>
22+
<label className="block mb-2 text-white tf2-light text-xl">
23+
{setting.label}
24+
</label>
25+
<select className="px-4 py-2 mb-2 border text-white" value={value} onChange={(ev) => callback(ev.target.value)}>
26+
{setting.options.map((option) => (
27+
<option key={option.value} value={option.value} selected={option.value === value}>
28+
{option.label}
29+
</option>
30+
))}
31+
</select>
32+
</div>
33+
);
34+
}

src/components/settings/controls/SettingsSlider.tsx

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1+
import { runRpc } from "@/util/ws";
2+
import { useCallback, useEffect, useState } from "react";
3+
14
export function SettingsSlider({ setting }) {
5+
const [value, setValue] = useState(0);
6+
7+
useEffect(() => {
8+
runRpc("getcvar", setting.cvar).then((response) => {
9+
if (response !== null && response.length > 0) {
10+
setValue(parseFloat(response));
11+
}
12+
});
13+
}, []);
14+
15+
const callback = (val: string) => {
16+
runRpc("setcvar", `${setting.cvar} ${val}`);
17+
setValue(parseFloat(val));
18+
};
19+
220
return (
321
<div>
422
<label className="mb-2 text-white tf2-light text-xl">
@@ -8,13 +26,24 @@ export function SettingsSlider({ setting }) {
826
<input
927
className="me-4 flex-1"
1028
type="range"
29+
value={value}
30+
onChange={(ev) => {
31+
callback(ev.target.value)
32+
}}
1133
min={setting.min ?? 0}
1234
max={setting.max ?? 100}
1335
step={setting.step ?? 1}
1436
/>
1537
<input
16-
type="number"
1738
className="mb-2 p-2 text-white bg-stone-800 border border-gray-300 w-20"
39+
type="number"
40+
value={value}
41+
onChange={(ev) => {
42+
callback(ev.target.value)
43+
}}
44+
min={setting.min ?? 0}
45+
max={setting.max ?? 100}
46+
step={setting.step ?? 1}
1847
/>
1948
</div>
2049
</div>

0 commit comments

Comments
 (0)