Compare commits
2
Commits
15927216b3
...
7e8a7d7210
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7e8a7d7210 | ||
|
|
fea3401415 |
No files matched your search
@@ -28,6 +28,7 @@ export default function Main() {
|
|||||||
if (!hasAttachedListerner && step > 0) {
|
if (!hasAttachedListerner && step > 0) {
|
||||||
setHasAttachedListener(true);
|
setHasAttachedListener(true);
|
||||||
const doFullscreen = () => {
|
const doFullscreen = () => {
|
||||||
|
if (process.env.NODE_ENV === "development") return;
|
||||||
if (screenfull.isEnabled) {
|
if (screenfull.isEnabled) {
|
||||||
screenfull.request();
|
screenfull.request();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,8 +73,29 @@ export default function Riddle_2({
|
|||||||
const [ isSwordOnline, setIsSwordOnline ] = useState(true);
|
const [ isSwordOnline, setIsSwordOnline ] = useState(true);
|
||||||
const [ wasSwordTakenOffline, setWasSwordTakenOffline ] = useState(false);
|
const [ wasSwordTakenOffline, setWasSwordTakenOffline ] = useState(false);
|
||||||
|
|
||||||
|
|
||||||
|
const [swordStatus, setSwordStatus] = useState<string | null>(null);
|
||||||
|
// lE == true && sE == true
|
||||||
|
const checkSwordStatusForIdealState = (state: string) => {
|
||||||
|
// M:2,snd:true,sS:true,sE:true,sP:false,lE:true,v:50,pD:150s
|
||||||
|
if (state == null) return false;
|
||||||
|
let sE = false;
|
||||||
|
let lE = false;
|
||||||
|
const tokens = state.split(",");
|
||||||
|
for (const token of tokens) {
|
||||||
|
if (token === "sE:true") {
|
||||||
|
sE = true;
|
||||||
|
} else if (token === "lE:true") {
|
||||||
|
lE = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sE && lE;
|
||||||
|
};
|
||||||
|
const [ isSwordIdealState, setIsSwordIdealState ] = useState(false);
|
||||||
|
|
||||||
const [ demoModeStr, ] = useLocalStorage(PREF.demo_mode, "");
|
const [ demoModeStr, ] = useLocalStorage(PREF.demo_mode, "");
|
||||||
const demoMode = useMemo(() => isDemoMode(demoModeStr), [demoModeStr]);
|
const demoMode = useMemo(() => isDemoMode(demoModeStr), [demoModeStr]);
|
||||||
|
//const demoMode = false;
|
||||||
|
|
||||||
const [ playerIndex, setPlayerIndex ] = useState(0);
|
const [ playerIndex, setPlayerIndex ] = useState(0);
|
||||||
const players = useMemo(() => getPlayers(), [playersStr]);
|
const players = useMemo(() => getPlayers(), [playersStr]);
|
||||||
@@ -96,9 +117,16 @@ export default function Riddle_2({
|
|||||||
const isNextIndexLastPlayer = players.length-2 <= playerIndex;
|
const isNextIndexLastPlayer = players.length-2 <= playerIndex;
|
||||||
|
|
||||||
const [status, setStatus] = useState<ConnectionStatus>("disconnected");
|
const [status, setStatus] = useState<ConnectionStatus>("disconnected");
|
||||||
const [swordStatus, setSwordStatus] = useState<string>('N/A');
|
const statusRef = useRef(false);
|
||||||
//const [throneStatus, setThroneStatus] = useState<string>('N/A');
|
|
||||||
const [ soundInput, setSoundInput ] = useState("Chosen");
|
useEffect(() => {
|
||||||
|
if (status === "connected") {
|
||||||
|
statusRef.current = true;
|
||||||
|
} else {
|
||||||
|
statusRef.current = false;
|
||||||
|
}
|
||||||
|
}, [status]);
|
||||||
|
|
||||||
const wsRef = useRef<WebSocket | null>(null);
|
const wsRef = useRef<WebSocket | null>(null);
|
||||||
|
|
||||||
const sendCommand = (topic: string, payload: string) => {
|
const sendCommand = (topic: string, payload: string) => {
|
||||||
@@ -135,6 +163,7 @@ export default function Riddle_2({
|
|||||||
|
|
||||||
if (data.topic === `${TOPIC_PREFIX}/stat`) {
|
if (data.topic === `${TOPIC_PREFIX}/stat`) {
|
||||||
setSwordStatus(data.payload);
|
setSwordStatus(data.payload);
|
||||||
|
setIsSwordIdealState(checkSwordStatusForIdealState(data.payload));
|
||||||
} else if (data.topic.includes('/event')) {
|
} else if (data.topic.includes('/event')) {
|
||||||
console.log(`Event received on ${data.topic}:`, data.payload);
|
console.log(`Event received on ${data.topic}:`, data.payload);
|
||||||
if (data.payload === "pull-denied") {
|
if (data.payload === "pull-denied") {
|
||||||
@@ -170,6 +199,10 @@ export default function Riddle_2({
|
|||||||
if (!isCancelled) {
|
if (!isCancelled) {
|
||||||
setStatus("disconnected");
|
setStatus("disconnected");
|
||||||
reconnectTimeout = setTimeout(connect, 3000);
|
reconnectTimeout = setTimeout(connect, 3000);
|
||||||
|
if (statusRef.current) {
|
||||||
|
setPage(0);
|
||||||
|
alert("Die Internet-Verbindung wurde verloren!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -231,6 +264,10 @@ export default function Riddle_2({
|
|||||||
setPage(3);
|
setPage(3);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!isSwordIdealState) {
|
||||||
|
alert("Eine wahre Prüfung kann erst gestarten werden, wenn das Schwert richtig im Felsen ist!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!sendCommand(`${TOPIC_PREFIX}/set`, 'stayLocked')) {
|
if (!sendCommand(`${TOPIC_PREFIX}/set`, 'stayLocked')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user