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

+1
View File
@@ -25,6 +25,7 @@ export default function Main() {
const step = Number.parseInt(stepStr) || 0; const step = Number.parseInt(stepStr) || 0;
useEffect(() => { useEffect(() => {
return;
if (!hasAttachedListerner && step > 0) { if (!hasAttachedListerner && step > 0) {
const doFullscreen = () => { const doFullscreen = () => {
if (screenfull.isEnabled) { if (screenfull.isEnabled) {
+18 -2
View File
@@ -69,6 +69,7 @@ export default function Riddle_2({
const [ isSwordBackIn, setIsSwordBackIn ] = useState(true); const [ isSwordBackIn, setIsSwordBackIn ] = useState(true);
const [ playersStr, ] = useLocalStorage(PREF.players, ""); const [ playersStr, ] = useLocalStorage(PREF.players, "");
const [ tourCode, ] = useLocalStorage(PREF.code, ""); const [ tourCode, ] = useLocalStorage(PREF.code, "");
const [ isSystemLockOn, setIsSystemLockOn] = useState<boolean | undefined>(undefined);
const [ isSwordOnline, setIsSwordOnline ] = useState(true); const [ isSwordOnline, setIsSwordOnline ] = useState(true);
const [ wasSwordTakenOffline, setWasSwordTakenOffline ] = useState(false); const [ wasSwordTakenOffline, setWasSwordTakenOffline ] = useState(false);
@@ -153,10 +154,19 @@ export default function Riddle_2({
if (data.payload === "abortTry") { if (data.payload === "abortTry") {
awaitTryAbort = true; 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 = () => { ws.onclose = () => {
setIsSystemLockOn(undefined);
if (!isCancelled) { if (!isCancelled) {
setStatus("disconnected"); setStatus("disconnected");
reconnectTimeout = setTimeout(connect, 3000); reconnectTimeout = setTimeout(connect, 3000);
@@ -165,6 +175,7 @@ export default function Riddle_2({
ws.onerror = () => { ws.onerror = () => {
ws.close(); ws.close();
setIsSystemLockOn(undefined);
}; };
}; };
@@ -173,6 +184,7 @@ export default function Riddle_2({
return () => { return () => {
isCancelled = true; isCancelled = true;
clearTimeout(reconnectTimeout); clearTimeout(reconnectTimeout);
setIsSystemLockOn(undefined);
wsRef.current?.close(); wsRef.current?.close();
}; };
}, [tourCode]); }, [tourCode]);
@@ -187,6 +199,7 @@ export default function Riddle_2({
await waitUntilTrue(() => { await waitUntilTrue(() => {
return awaitTryAbort return awaitTryAbort
}); });
sendCommand("system/swordLock", "giveLock");
} }
return true; return true;
}; };
@@ -210,7 +223,7 @@ export default function Riddle_2({
</div> </div>
<div className={styles["buttons"]}> <div className={styles["buttons"]}>
<OldButton red={false} onAction={() => { <OldButton red={false} onAction={() => {
if (!isSwordOnline) { if (!isSwordOnline && !demoMode) {
addPoints(riddle.points); addPoints(riddle.points);
setWasSwordTakenOffline(true); setWasSwordTakenOffline(true);
addCompletedRiddle(riddle.step); addCompletedRiddle(riddle.step);
@@ -221,9 +234,10 @@ export default function Riddle_2({
if (!sendCommand(`${TOPIC_PREFIX}/set`, 'stayLocked')) { if (!sendCommand(`${TOPIC_PREFIX}/set`, 'stayLocked')) {
return; return;
} }
sendCommand("system/swordLock", "takeLock");
setCanGoNext(false); setCanGoNext(false);
setPage(1); setPage(1);
}}>PRÜFUNG STARTEN</OldButton> }} disabled={(isSystemLockOn !== false) && !demoMode && isSwordOnline} >PRÜFUNG STARTEN</OldButton>
</div> </div>
</div> </div>
), ),
@@ -242,6 +256,7 @@ export default function Riddle_2({
setPage(2); setPage(2);
addPoints(riddle.points); addPoints(riddle.points);
addCompletedRiddle(riddle.step); addCompletedRiddle(riddle.step);
sendCommand("system/swordLock", "giveLock");
} else { } else {
if (isNextIndexLastPlayer) { if (isNextIndexLastPlayer) {
if (!sendCommand(`${TOPIC_PREFIX}/set`, 'releaseLock')) { if (!sendCommand(`${TOPIC_PREFIX}/set`, 'releaseLock')) {
@@ -266,6 +281,7 @@ export default function Riddle_2({
await waitUntilTrue(() => { await waitUntilTrue(() => {
return awaitTryAbort; return awaitTryAbort;
}); });
sendCommand("system/swordLock", "giveLock");
setPage(0); setPage(0);
}} className={styles["backButton"]}>ZURÜCK</OldButton> : null} }} className={styles["backButton"]}>ZURÜCK</OldButton> : null}
</div> </div>
+1 -1
View File
@@ -16,4 +16,4 @@ const isDev = process.env.NODE_ENV === "development";
export const HTTP_SCHEME = isDev ? "http" : "https"; export const HTTP_SCHEME = isDev ? "http" : "https";
export const WS_SCHEME = isDev ? "ws" : "wss"; export const WS_SCHEME = isDev ? "ws" : "wss";
export const API_PREFIX = isDev ? "localhost:8080" : "api.excaliburs-erben.de"; export const API_PREFIX = isDev ? "10.8.0.23:8080" : "api.excaliburs-erben.de";