holy shit
This commit is contained in:
1 parent
a526a24e7c
commit
b5e5cc502d
20 files changed
+286
-209
No files matched your search
@@ -14,6 +14,7 @@ import RiddleHintPage from "../RiddleHintPage";
|
||||
import { Player } from "@/types/player";
|
||||
import { getSwordState } from "@/utils/swordTalk";
|
||||
import GameController from "../GameController";
|
||||
import { addCompletedRiddle } from "@/utils/completedRiddles";
|
||||
|
||||
export type ConnectionStatus = "disconnected" | "connected";
|
||||
|
||||
@@ -62,6 +63,16 @@ export default function Riddle_2({
|
||||
const wsRef = useRef<WebSocket | null>(null);
|
||||
const [ showControls, setShowControls ] = useState(false);
|
||||
|
||||
const sendCommand = (topic: string, payload: string) => {
|
||||
if (wsRef.current && wsRef.current.readyState === WebSocket.OPEN) {
|
||||
wsRef.current.send(JSON.stringify({ topic, payload }));
|
||||
return true;
|
||||
} else {
|
||||
alert('WebSocket is not connected.');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const tourCode = "TESTTEST!";
|
||||
wsRef.current = new WebSocket(`ws://localhost:8080/ws/bridge?tourCode=${tourCode}`);
|
||||
@@ -79,11 +90,11 @@ export default function Riddle_2({
|
||||
//setThroneStatus(data.payload);
|
||||
} else if (data.topic.includes('/event')) {
|
||||
console.log(`Event received on ${data.topic}:`, data.payload);
|
||||
if (data.payload === "pull") {
|
||||
if (data.payload === "pull-denied") {
|
||||
setCanGoNext(true);
|
||||
} else if (data.payload === "pulled-out") {
|
||||
setIsSwordBackIn(false);
|
||||
} else if (data.payload === "put-in") {
|
||||
} else if (data.payload === "locked") {
|
||||
setIsSwordBackIn(true);
|
||||
} else if (data.payload === "ceremonyDone") {
|
||||
setCanGoNext(true);
|
||||
@@ -92,6 +103,7 @@ export default function Riddle_2({
|
||||
};
|
||||
|
||||
wsRef.current.onclose = () => {
|
||||
sendCommand('outdoor/king-arthur/sword/set', 'abortTry');
|
||||
setStatus("disconnected");
|
||||
};
|
||||
|
||||
@@ -100,16 +112,6 @@ export default function Riddle_2({
|
||||
};
|
||||
}, []);
|
||||
|
||||
const sendCommand = (topic: string, payload: string) => {
|
||||
if (wsRef.current && wsRef.current.readyState === WebSocket.OPEN) {
|
||||
wsRef.current.send(JSON.stringify({ topic, payload }));
|
||||
return true;
|
||||
} else {
|
||||
alert('WebSocket is not connected.');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const currentPlayer: Player = players[playerOrder[playerIndex]];
|
||||
|
||||
const pages = [
|
||||
@@ -140,10 +142,10 @@ export default function Riddle_2({
|
||||
(
|
||||
<div key={1}>
|
||||
<div className={styles["content"]}>
|
||||
<div className="center-flex">
|
||||
{ currentPlayer !== undefined ? <div className="center-flex">
|
||||
<p style={{fontWeight: "bold", fontSize: "3rem", marginTop: "2rem", marginBottom: "0"}}>{currentPlayer.name},</p>
|
||||
<p style={{textAlign: "center"}}>zieh nun am Schwert und finde heraus, ob du Excaliburs {currentPlayer.gender === "female" ? "Erbin" : "Erbe"} bist!</p>
|
||||
</div>
|
||||
</div> : null }
|
||||
<div style={{ padding: '20px', fontFamily: 'sans-serif', fontSize: '0.6rem', display: showControls ? "" : "none"}}>
|
||||
<h2 style={{ fontSize: '1rem', marginBottom: '10px' }}>King Arthur - Station Control Dashboard</h2>
|
||||
<p style={{ fontSize: '0.6rem' }}><strong>Connection State:</strong> {status}</p>
|
||||
@@ -197,6 +199,7 @@ export default function Riddle_2({
|
||||
if (playerIndex >= players.length-1) {
|
||||
setPage(2);
|
||||
addPoints(riddle.points);
|
||||
addCompletedRiddle(riddle.step);
|
||||
} else {
|
||||
if (isNextIndexLastPlayer) {
|
||||
if (!sendCommand('outdoor/king-arthur/sword/set', 'releaseLock')) {
|
||||
@@ -236,5 +239,8 @@ export default function Riddle_2({
|
||||
)
|
||||
];
|
||||
|
||||
return requestingHint ? <RiddleHintPage riddle={riddle} dismissHintPage={dismissHint} voiceOverMode={voiceOverMode} onSkip={() => setPage(2)}/> : pages[page];
|
||||
return requestingHint ? <RiddleHintPage riddle={riddle} dismissHintPage={dismissHint} voiceOverMode={voiceOverMode} onSkip={() => {
|
||||
addCompletedRiddle(riddle.step);
|
||||
setPage(2);
|
||||
}}/> : pages[page];
|
||||
}
|
||||
Reference in new issue
Block a user