Zwischenspeicher
This commit is contained in:
1 parent
ff5efa0423
commit
a6c476e385
6 files changed
+158
-3
No files matched your search
@@ -0,0 +1,134 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import React, { useEffect, useState, useRef } from 'react';
|
||||||
|
|
||||||
|
interface MQTTMessage {
|
||||||
|
topic: string;
|
||||||
|
payload: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function GameController() {
|
||||||
|
const [status, setStatus] = useState<string>('Connecting...');
|
||||||
|
const [swordStatus, setSwordStatus] = useState<string>('N/A');
|
||||||
|
const [throneStatus, setThroneStatus] = useState<string>('N/A');
|
||||||
|
const [ soundInput, setSoundInput ] = useState("Chosen");
|
||||||
|
const wsRef = useRef<WebSocket | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const tourCode = "TESTTEST!";
|
||||||
|
wsRef.current = new WebSocket(`ws://localhost:8080/ws/bridge?tourCode=${tourCode}`);
|
||||||
|
|
||||||
|
wsRef.current.onopen = () => {
|
||||||
|
setStatus('Connected to Server Bridge');
|
||||||
|
};
|
||||||
|
|
||||||
|
wsRef.current.onmessage = (event) => {
|
||||||
|
const data: MQTTMessage = JSON.parse(event.data);
|
||||||
|
|
||||||
|
// Handle incoming messages based on specifications
|
||||||
|
if (data.topic === 'outdoor/king-arthur/sword/stat') {
|
||||||
|
setSwordStatus(data.payload);
|
||||||
|
} else if (data.topic === 'outdoor/king-arthur/throne/stat') {
|
||||||
|
setThroneStatus(data.payload);
|
||||||
|
} else if (data.topic.includes('/event')) {
|
||||||
|
console.log(`Event received on ${data.topic}:`, data.payload);
|
||||||
|
if (data.payload === "pull") {
|
||||||
|
alert("PULL EVENT!");
|
||||||
|
} else if (data.payload === "pulled-out") {
|
||||||
|
alert("PULLED OUT");
|
||||||
|
} else if (data.payload === "put-in") {
|
||||||
|
alert("PUT IN EVENT!");
|
||||||
|
} else if (data.payload === "ceremonyDone") {
|
||||||
|
alert("ceremonyDone");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
wsRef.current.onclose = () => {
|
||||||
|
setStatus('Disconnected from Server Bridge');
|
||||||
|
};
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
wsRef.current?.close();
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// Function to send commands (Set Data)
|
||||||
|
const sendCommand = (topic: string, payload: string) => {
|
||||||
|
if (wsRef.current && wsRef.current.readyState === WebSocket.OPEN) {
|
||||||
|
wsRef.current.send(JSON.stringify({ topic, payload }));
|
||||||
|
} else {
|
||||||
|
alert('WebSocket is not connected.');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ padding: '20px', fontFamily: 'sans-serif', fontSize: '0.6rem' }}>
|
||||||
|
<h2 style={{ fontSize: '1rem', marginBottom: '10px' }}>King Arthur - Station Control Dashboard</h2>
|
||||||
|
<p style={{ fontSize: '0.6rem' }}><strong>Connection State:</strong> {status}</p>
|
||||||
|
|
||||||
|
<div style={{ display: 'flex', gap: '20px', marginTop: '20px' }}>
|
||||||
|
{/* Sword Controls (Excalibur) */}
|
||||||
|
<div style={{ border: '1px solid #ccc', padding: '15px', borderRadius: '8px', flex: 1 }}>
|
||||||
|
<h3 style={{ fontSize: '0.8rem', marginTop: 0 }}>Excalibur (Sword)</h3>
|
||||||
|
<p style={{ fontSize: '0.6rem' }}><strong>Stat:<br></br></strong> {swordStatus}</p>
|
||||||
|
<button
|
||||||
|
style={{ fontSize: '0.6rem', padding: '4px 8px' }}
|
||||||
|
onClick={() => sendCommand('outdoor/king-arthur/sword/set', 'releaseLock')}
|
||||||
|
>
|
||||||
|
Release Lock
|
||||||
|
</button>
|
||||||
|
<br/><br/>
|
||||||
|
<button
|
||||||
|
style={{ fontSize: '0.6rem', padding: '4px 8px' }}
|
||||||
|
onClick={() => sendCommand('outdoor/king-arthur/sword/set', 'stayLocked')}
|
||||||
|
>
|
||||||
|
Stay Locked
|
||||||
|
</button>
|
||||||
|
<br/><br/>
|
||||||
|
<button
|
||||||
|
style={{ fontSize: '0.6rem', padding: '4px 8px' }}
|
||||||
|
onClick={() => sendCommand('outdoor/king-arthur/sword/set', 'gameStarted')}
|
||||||
|
>
|
||||||
|
Game Started
|
||||||
|
</button>
|
||||||
|
<br/><br/>
|
||||||
|
<button
|
||||||
|
style={{ fontSize: '0.6rem', padding: '4px 8px' }}
|
||||||
|
onClick={() => sendCommand('outdoor/king-arthur/sword/set', 'gameFinished')}
|
||||||
|
>
|
||||||
|
Game Stopped
|
||||||
|
</button>
|
||||||
|
<br/><br/>
|
||||||
|
<input type='text' placeholder='sound' value={soundInput} onChange={(e) => setSoundInput(e.target.value)}/>
|
||||||
|
<br/><br/>
|
||||||
|
<button
|
||||||
|
style={{ fontSize: '0.6rem', padding: '4px 8px' }}
|
||||||
|
onClick={() => sendCommand('outdoor/king-arthur/sword/cfg', 'playSound:' + soundInput)}
|
||||||
|
>
|
||||||
|
Play Sound
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Throne Controls */}
|
||||||
|
{ /*<div style={{ border: '1px solid #ccc', padding: '15px', borderRadius: '8px', flex: 1 }}>
|
||||||
|
<h3 style={{ fontSize: '0.8rem', marginTop: 0 }}>Throne (Coronation)</h3>
|
||||||
|
<p style={{ fontSize: '0.6rem' }}><strong>Stat:</strong> {throneStatus}</p>
|
||||||
|
<button
|
||||||
|
style={{ fontSize: '0.6rem', padding: '4px 8px' }}
|
||||||
|
onClick={() => sendCommand('outdoor/king-arthur/throne/set', 'openCoinSlot')}
|
||||||
|
>
|
||||||
|
Open Coin Slot[cite: 10]
|
||||||
|
</button>
|
||||||
|
<br/><br/>
|
||||||
|
<button
|
||||||
|
style={{ fontSize: '0.6rem', padding: '4px 8px' }}
|
||||||
|
onClick={() => sendCommand('outdoor/king-arthur/throne/set', 'closeCoinSlot')}
|
||||||
|
>
|
||||||
|
Close Coin Slot[cite: 10]
|
||||||
|
</button>
|
||||||
|
</div> */ }
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useMemo, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import OldButton from "../OldButton";
|
import OldButton from "../OldButton";
|
||||||
import styles from "@/css/RiddleStyles.module.css";
|
import styles from "@/css/RiddleStyles.module.css";
|
||||||
import { useLocalStorage } from "@/hooks/useLocalStorage";
|
import { useLocalStorage } from "@/hooks/useLocalStorage";
|
||||||
@@ -12,6 +12,8 @@ import { getPlayers } from "@/utils/players";
|
|||||||
import VoiceOver from "../VoiceOver";
|
import VoiceOver from "../VoiceOver";
|
||||||
import RiddleHintPage from "../RiddleHintPage";
|
import RiddleHintPage from "../RiddleHintPage";
|
||||||
import { Player } from "@/types/player";
|
import { Player } from "@/types/player";
|
||||||
|
import { getSwordState } from "@/utils/swordTalk";
|
||||||
|
import GameController from "../GameController";
|
||||||
|
|
||||||
export default function Riddle_2({
|
export default function Riddle_2({
|
||||||
page,
|
page,
|
||||||
@@ -70,6 +72,7 @@ export default function Riddle_2({
|
|||||||
<p style={{fontWeight: "bold", fontSize: "3rem", marginTop: "2rem", marginBottom: "0"}}>{currentPlayer.name},</p>
|
<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>
|
<p style={{textAlign: "center"}}>zieh nun am Schwert und finde heraus, ob du Excaliburs {currentPlayer.gender === "female" ? "Erbin" : "Erbe"} bist!</p>
|
||||||
</div>
|
</div>
|
||||||
|
<GameController></GameController>
|
||||||
</div>
|
</div>
|
||||||
<div className={styles["buttons"]}>
|
<div className={styles["buttons"]}>
|
||||||
<OldButton red={false} onAction={() => {
|
<OldButton red={false} onAction={() => {
|
||||||
|
|||||||
@@ -176,8 +176,8 @@ export default function Tour() {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const [ stepStr, setStep ] = useLocalStorage(PREF.step, "0");
|
const [ stepStr, setStep ] = useLocalStorage(PREF.step, "0");
|
||||||
const [ activeRiddle, setActiveRiddle ] = useState<Riddle | null>(null);
|
const [ activeRiddle, setActiveRiddle ] = useState<Riddle | null>(riddleData["riddles"][1]);
|
||||||
const [ clickedMarker, setClickedMarker ] = useState<number | null>(null);
|
const [ clickedMarker, setClickedMarker ] = useState<number | null>(2);
|
||||||
const [ tourCode, setTourCode ] = useLocalStorage(PREF.code, "");
|
const [ tourCode, setTourCode ] = useLocalStorage(PREF.code, "");
|
||||||
const [ completedRiddlesStr, setCompletedRiddles ] = useLocalStorage(PREF.completed_riddles, "");
|
const [ completedRiddlesStr, setCompletedRiddles ] = useLocalStorage(PREF.completed_riddles, "");
|
||||||
const [ , setPlayers ] = useLocalStorage(PREF.players, "");
|
const [ , setPlayers ] = useLocalStorage(PREF.players, "");
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
// TODO: CodeChecker
|
||||||
@@ -10,3 +10,5 @@ export enum PREF {
|
|||||||
voiceover = "PREF_VOICEOVER_STATE",
|
voiceover = "PREF_VOICEOVER_STATE",
|
||||||
boughtHints = "PREF_BOUGHT_HINTS"
|
boughtHints = "PREF_BOUGHT_HINTS"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const API_PREFIX = "http://localhost:8080";
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
// TODO: THISSSSS
|
||||||
|
|
||||||
|
import { API_PREFIX } from "./const";
|
||||||
|
|
||||||
|
export async function getSwordState() {
|
||||||
|
const response = await fetch(API_PREFIX + "/sword", {
|
||||||
|
"method": "GET",
|
||||||
|
"cache": "no-cache"
|
||||||
|
});
|
||||||
|
console.log(response);
|
||||||
|
if (response.ok) {
|
||||||
|
console.log(`${await response.text()}`);
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user