swordLock

This commit is contained in:
LionTion committed 2026-10-23 19:42:54 +02:00
1 parent 4c968d4caa
commit 5724560171
3 files changed
+20 -3

No files matched your search

+18 -2
View File
@@ -69,6 +69,7 @@ export default function Riddle_2({
const [ isSwordBackIn, setIsSwordBackIn ] = useState(true);
const [ playersStr, ] = useLocalStorage(PREF.players, "");
const [ tourCode, ] = useLocalStorage(PREF.code, "");
const [ isSystemLockOn, setIsSystemLockOn] = useState<boolean | undefined>(undefined);
const [ isSwordOnline, setIsSwordOnline ] = useState(true);
const [ wasSwordTakenOffline, setWasSwordTakenOffline ] = useState(false);
@@ -153,10 +154,19 @@ export default function Riddle_2({
if (data.payload === "abortTry") {
awaitTryAbort = true;
}
} else if (data.topic.startsWith("system/")) {
if (data.topic === "system/swordLock") {
if (data.payload === "locked") {
setIsSystemLockOn(true);
} else if (data.payload === "unlocked") {
setIsSystemLockOn(false);
}
}
}
};
ws.onclose = () => {
setIsSystemLockOn(undefined);
if (!isCancelled) {
setStatus("disconnected");
reconnectTimeout = setTimeout(connect, 3000);
@@ -165,6 +175,7 @@ export default function Riddle_2({
ws.onerror = () => {
ws.close();
setIsSystemLockOn(undefined);
};
};
@@ -173,6 +184,7 @@ export default function Riddle_2({
return () => {
isCancelled = true;
clearTimeout(reconnectTimeout);
setIsSystemLockOn(undefined);
wsRef.current?.close();
};
}, [tourCode]);
@@ -187,6 +199,7 @@ export default function Riddle_2({
await waitUntilTrue(() => {
return awaitTryAbort
});
sendCommand("system/swordLock", "giveLock");
}
return true;
};
@@ -210,7 +223,7 @@ export default function Riddle_2({
</div>
<div className={styles["buttons"]}>
<OldButton red={false} onAction={() => {
if (!isSwordOnline) {
if (!isSwordOnline && !demoMode) {
addPoints(riddle.points);
setWasSwordTakenOffline(true);
addCompletedRiddle(riddle.step);
@@ -221,9 +234,10 @@ export default function Riddle_2({
if (!sendCommand(`${TOPIC_PREFIX}/set`, 'stayLocked')) {
return;
}
sendCommand("system/swordLock", "takeLock");
setCanGoNext(false);
setPage(1);
}}>PRÜFUNG STARTEN</OldButton>
}} disabled={(isSystemLockOn !== false) && !demoMode && isSwordOnline} >PRÜFUNG STARTEN</OldButton>
</div>
</div>
),
@@ -242,6 +256,7 @@ export default function Riddle_2({
setPage(2);
addPoints(riddle.points);
addCompletedRiddle(riddle.step);
sendCommand("system/swordLock", "giveLock");
} else {
if (isNextIndexLastPlayer) {
if (!sendCommand(`${TOPIC_PREFIX}/set`, 'releaseLock')) {
@@ -266,6 +281,7 @@ export default function Riddle_2({
await waitUntilTrue(() => {
return awaitTryAbort;
});
sendCommand("system/swordLock", "giveLock");
setPage(0);
}} className={styles["backButton"]}>ZURÜCK</OldButton> : null}
</div>