Add a mounting rotation button to the GUI (#22)

* Add support for mounting reset

* Add reset mounting button

* Don't display negative timer on reset buttons

* Fix reset button timer going negative

* Update package-lock.json
This commit is contained in:
Butterscotch! authored and GitHub committed 2022-11-03 21:35:25 +01:00
1 parent eed7dd98af
commit 2f2f57a46f
4 files changed
+71 -21

No files matched your search

+2 -2
View File
@@ -14786,7 +14786,7 @@
},
"node_modules/solarxr-protocol": {
"version": "1.0.0",
"resolved": "git+ssh://[email protected]/SlimeVR/SolarXR-Protocol.git#f588c2e4adc70480d7dfe23f77621d1f2183ed47",
"resolved": "git+ssh://[email protected]/SlimeVR/SolarXR-Protocol.git#c6db24ca7f99dea8c093106cd30e36a3451d9f7c",
"license": "(MIT OR Apache-2.0)",
"dependencies": {
"flatbuffers": "^2.0.6"
@@ -25346,7 +25346,7 @@
}
},
"solarxr-protocol": {
"version": "git+ssh://[email protected]/SlimeVR/SolarXR-Protocol.git#f588c2e4adc70480d7dfe23f77621d1f2183ed47",
"version": "git+ssh://[email protected]/SlimeVR/SolarXR-Protocol.git#c6db24ca7f99dea8c093106cd30e36a3451d9f7c",
"from": "solarxr-protocol@github:SlimeVR/SolarXR-Protocol",
"requires": {
"flatbuffers": "^2.0.6"
+1
View File
@@ -44,6 +44,7 @@ export function MainLayoutRoute({
<div className="grid grid-cols-3 gap-2 w-full">
<ResetButton type={ResetType.Quick}></ResetButton>
<ResetButton type={ResetType.Full}></ResetButton>
<ResetButton type={ResetType.Mounting}></ResetButton>
<BVHButton></BVHButton>
</div>
<div className="w-full">
+26
View File
@@ -54,3 +54,29 @@ export function QuickResetIcon({ width = 33 }: { width?: number }) {
</svg>
);
}
export function MountingResetIcon({ width = 33 }: { width?: number }) {
return (
<svg
width={width}
viewBox="0 0 33 29"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M2.39801 3.061V11.524H10.861"
stroke="white"
strokeWidth="3"
strokeLinecap="round"
strokeLinejoin="round"
/>
<path
d="M5.93801 18.576C6.85461 21.1713 8.58991 23.3983 10.8824 24.9215C13.1749 26.4447 15.9003 27.1816 18.648 27.021C21.3957 26.8604 24.0168 25.8111 26.1162 24.0312C28.2157 22.2514 29.6797 19.8373 30.2878 17.153C30.8958 14.4686 30.6149 11.6593 29.4874 9.14845C28.3599 6.63762 26.4468 4.56127 24.0365 3.23233C21.6262 1.90339 18.8493 1.39384 16.1242 1.7805C13.3991 2.16715 10.8735 3.42904 8.92801 5.376L2.39301 11.523"
stroke="white"
strokeWidth="3"
strokeLinecap="round"
strokeLinejoin="round"
/>
</svg>
);
}
+42 -19
View File
@@ -2,7 +2,11 @@ import { useRef, useState } from 'react';
import { ResetRequestT, ResetType, RpcMessage } from 'solarxr-protocol';
import { useWebsocketAPI } from '../../hooks/websocket-api';
import { BigButton } from '../commons/BigButton';
import { QuickResetIcon, ResetIcon } from '../commons/icon/ResetIcon';
import {
MountingResetIcon,
QuickResetIcon,
ResetIcon,
} from '../commons/icon/ResetIcon';
export function ResetButton({ type }: { type: ResetType }) {
const timerid = useRef<NodeJS.Timer | null>(null);
@@ -10,21 +14,52 @@ export function ResetButton({ type }: { type: ResetType }) {
const [timer, setTimer] = useState(0);
const { sendRPCPacket } = useWebsocketAPI();
const getText = () => {
switch (type) {
case ResetType.Quick:
return 'Quick Reset';
case ResetType.Mounting:
return 'Reset Mounting';
}
return 'Reset';
};
const getIcon = () => {
switch (type) {
case ResetType.Quick:
return <QuickResetIcon width={20} />;
case ResetType.Mounting:
return <MountingResetIcon width={20} />;
}
return <ResetIcon width={20} />;
};
const reset = () => {
const req = new ResetRequestT();
req.resetType = type;
setReseting(true);
setTimer(0);
if (type !== ResetType.Quick) {
if (timerid.current) clearInterval(timerid.current);
timerid.current = setInterval(() => {
setTimer((timer) => {
if (timer + 1 === 3) {
const newTimer = timer + 1;
if (newTimer >= 3) {
// Stop the current interval
if (timerid.current) clearInterval(timerid.current);
sendRPCPacket(RpcMessage.ResetRequest, req);
setTimer(0);
// Only actually reset on exactly 0 so it doesn't repeatedly reset if bugged
if (newTimer === 3) sendRPCPacket(RpcMessage.ResetRequest, req);
else
console.warn(
`Reset timer is still running after 3 seconds (newTimer = ${newTimer})`
);
// Reset the state
// Don't reset the timer in-case the interval keeps running
setReseting(false);
}
return timer + 1;
return newTimer;
});
}, 1000);
} else {
@@ -35,20 +70,8 @@ export function ResetButton({ type }: { type: ResetType }) {
return (
<BigButton
text={
!reseting
? type === ResetType.Quick
? 'Quick Reset'
: 'Reset'
: `${3 - timer}`
}
icon={
type === ResetType.Quick ? (
<QuickResetIcon width={20} />
) : (
<ResetIcon width={20} />
)
}
text={!reseting || timer >= 3 ? getText() : `${3 - timer}`}
icon={getIcon()}
onClick={reset}
disabled={reseting}
></BigButton>